1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.web.struts.action;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.apache.struts.action.ActionForm;
21 import org.apache.struts.action.ActionForward;
22 import org.apache.struts.action.ActionMapping;
23 import org.kuali.rice.core.api.util.RiceConstants;
24 import org.kuali.rice.core.api.util.RiceKeyConstants;
25 import org.kuali.rice.kim.api.identity.IdentityService;
26 import org.kuali.rice.kim.api.responsibility.ResponsibilityService;
27 import org.kuali.rice.kim.api.role.Role;
28 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
29 import org.kuali.rice.kim.api.type.KimType;
30 import org.kuali.rice.kim.framework.role.RoleTypeService;
31 import org.kuali.rice.kim.framework.type.KimTypeService;
32 import org.kuali.rice.kim.impl.type.KimTypeLookupableHelperServiceImpl;
33 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
34 import org.kuali.rice.kim.service.UiDocumentService;
35 import org.kuali.rice.kim.util.KimCommonUtilsInternal;
36 import org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase;
37 import org.kuali.rice.kns.web.struts.action.KualiTransactionalDocumentActionBase;
38 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
39 import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata;
40 import org.kuali.rice.krad.util.GlobalVariables;
41 import org.kuali.rice.krad.util.KRADConstants;
42
43 import javax.servlet.http.HttpServletRequest;
44 import javax.servlet.http.HttpServletResponse;
45
46
47
48
49
50
51 abstract public class IdentityManagementDocumentActionBase extends KualiTransactionalDocumentActionBase {
52
53 private static final Logger LOG = Logger.getLogger( IdentityManagementDocumentActionBase.class );
54
55 protected static final String CHANGE_MEMBER_TYPE_CODE_METHOD_TO_CALL = "changeMemberTypeCode";
56 protected static final String CHANGE_NAMESPACE_METHOD_TO_CALL = "changeNamespace";
57
58 protected IdentityService identityService;
59 protected ResponsibilityService responsibilityService;
60 protected UiDocumentService uiDocumentService;
61
62 @Override
63 public ActionForward performLookup(ActionMapping mapping, ActionForm form,
64 HttpServletRequest request, HttpServletResponse response)
65 throws Exception {
66 ActionForward forward = super.performLookup(mapping, form, request, response);
67 String path = forward.getPath();
68
69 forward.setPath(KimCommonUtilsInternal.getPathWithKimContext(path, getActionName()));
70 return forward;
71 }
72
73 protected abstract String getActionName();
74
75 protected IdentityService getIdentityService() {
76 if ( identityService == null ) {
77 identityService = KimApiServiceLocator.getIdentityService();
78 }
79 return identityService;
80 }
81
82 protected ResponsibilityService getResponsibilityService() {
83 if ( responsibilityService == null ) {
84 responsibilityService = KimApiServiceLocator.getResponsibilityService();
85 }
86 return responsibilityService;
87 }
88
89 protected UiDocumentService getUiDocumentService() {
90 if ( uiDocumentService == null ) {
91 uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService();
92 }
93 return uiDocumentService;
94 }
95
96 @Override
97 protected String getReturnLocation(HttpServletRequest request, ActionMapping mapping){
98 String returnLocation = super.getReturnLocation(request, mapping);
99 return KimCommonUtilsInternal.getPathWithKimContext(returnLocation, getActionName());
100 }
101
102 @Override
103 protected ActionForward returnToSender(HttpServletRequest request, ActionMapping mapping, KualiDocumentFormBase form) {
104 ActionForward dest;
105 if (form.isReturnToActionList()) {
106 String workflowBase = getKualiConfigurationService().getPropertyValueAsString(
107 KRADConstants.WORKFLOW_URL_KEY);
108 String actionListUrl = workflowBase + "/ActionList.do";
109
110 dest = new ActionForward(actionListUrl, true);
111 } else if (StringUtils.isNotBlank(form.getBackLocation())){
112 dest = new ActionForward(form.getBackLocation(), true);
113 } else {
114 dest = mapping.findForward(KRADConstants.MAPPING_PORTAL);
115 ActionForward newDest = new ActionForward();
116
117 KimCommonUtilsInternal.copyProperties(newDest, dest);
118 newDest.setPath(getApplicationBaseUrl());
119 return newDest;
120 }
121
122 setupDocumentExit();
123 return dest;
124 }
125
126 protected ActionForward getBasePathForward(HttpServletRequest request, ActionForward forward){
127 ActionForward newDest = new ActionForward();
128 KimCommonUtilsInternal.copyProperties(newDest, forward);
129 newDest.setPath(getApplicationBaseUrl());
130 return newDest;
131 }
132
133 public ActionForward switchToPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
134 IdentityManagementDocumentFormBase idmForm = (IdentityManagementDocumentFormBase) form;
135
136 KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata();
137 memberTableMetadata.jumpToPage(memberTableMetadata.getSwitchToPageNumber(), idmForm.getMemberRows().size(), idmForm.getRecordsPerPage());
138 memberTableMetadata.setColumnToSortIndex(memberTableMetadata.getPreviouslySortedColumnIndex());
139 return mapping.findForward(RiceConstants.MAPPING_BASIC);
140 }
141
142 protected void applyPagingAndSortingFromPreviousPageView(IdentityManagementDocumentFormBase idmForm) {
143 KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata();
144
145 memberTableMetadata.jumpToPage(memberTableMetadata.getViewedPageNumber(), idmForm.getMemberRows().size(), idmForm.getRecordsPerPage());
146 }
147
148 protected boolean validateRole( String roleId, Role role, String propertyName, String message){
149 if ( role == null ) {
150 GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_INVALID_ROLE, roleId );
151 return false;
152 }
153 KimType typeInfo = KimApiServiceLocator.getKimTypeInfoService().getKimType(role.getKimTypeId());
154
155 if(KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(typeInfo)){
156 GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_CANT_ADD_DERIVED_ROLE, message);
157 return false;
158 }
159 return true;
160 }
161
162 public ActionForward changeNamespace(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
163 return refresh(mapping, form, request, response);
164 }
165
166 protected KimTypeService getKimTypeService( KimType typeInfo ) {
167 String serviceName = typeInfo.getServiceName();
168 if ( StringUtils.isNotBlank(serviceName) ) {
169 try {
170 KimTypeService service = (KimTypeService) KIMServiceLocatorInternal.getService(serviceName);
171 if ( service != null && service instanceof RoleTypeService) {
172 return service;
173 } else {
174 return (RoleTypeService) KIMServiceLocatorInternal.getService("kimNoMembersRoleTypeService");
175 }
176 } catch ( Exception ex ) {
177 LOG.error( "Unable to find role type service with name: " + serviceName, ex );
178 return (RoleTypeService) KIMServiceLocatorInternal.getService("kimNoMembersRoleTypeService");
179 }
180 }
181 return null;
182 }
183
184 }