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.api.type.KimTypeService; |
31 | |
import org.kuali.rice.kim.framework.type.KimRoleTypeService; |
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 | 0 | abstract public class IdentityManagementDocumentActionBase extends KualiTransactionalDocumentActionBase { |
52 | |
|
53 | 0 | 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 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
@Override |
69 | |
public ActionForward performLookup(ActionMapping mapping, ActionForm form, |
70 | |
HttpServletRequest request, HttpServletResponse response) |
71 | |
throws Exception { |
72 | 0 | ActionForward forward = super.performLookup(mapping, form, request, response); |
73 | 0 | String path = forward.getPath(); |
74 | |
|
75 | 0 | forward.setPath(KimCommonUtilsInternal.getPathWithKimContext(path, getActionName())); |
76 | 0 | return forward; |
77 | |
} |
78 | |
|
79 | |
protected abstract String getActionName(); |
80 | |
|
81 | |
protected IdentityService getIdentityService() { |
82 | 0 | if ( identityService == null ) { |
83 | 0 | identityService = KimApiServiceLocator.getIdentityService(); |
84 | |
} |
85 | 0 | return identityService; |
86 | |
} |
87 | |
|
88 | |
protected ResponsibilityService getResponsibilityService() { |
89 | 0 | if ( responsibilityService == null ) { |
90 | 0 | responsibilityService = KimApiServiceLocator.getResponsibilityService(); |
91 | |
} |
92 | 0 | return responsibilityService; |
93 | |
} |
94 | |
|
95 | |
protected UiDocumentService getUiDocumentService() { |
96 | 0 | if ( uiDocumentService == null ) { |
97 | 0 | uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService(); |
98 | |
} |
99 | 0 | return uiDocumentService; |
100 | |
} |
101 | |
|
102 | |
@Override |
103 | |
protected String getReturnLocation(HttpServletRequest request, ActionMapping mapping){ |
104 | 0 | String returnLocation = super.getReturnLocation(request, mapping); |
105 | 0 | return KimCommonUtilsInternal.getPathWithKimContext(returnLocation, getActionName()); |
106 | |
} |
107 | |
|
108 | |
@Override |
109 | |
protected ActionForward returnToSender(HttpServletRequest request, ActionMapping mapping, KualiDocumentFormBase form) { |
110 | |
ActionForward dest; |
111 | 0 | if (form.isReturnToActionList()) { |
112 | 0 | String workflowBase = getKualiConfigurationService().getPropertyValueAsString( |
113 | |
KRADConstants.WORKFLOW_URL_KEY); |
114 | 0 | String actionListUrl = workflowBase + "/ActionList.do"; |
115 | |
|
116 | 0 | dest = new ActionForward(actionListUrl, true); |
117 | 0 | } else if (StringUtils.isNotBlank(form.getBackLocation())){ |
118 | 0 | dest = new ActionForward(form.getBackLocation(), true); |
119 | |
} else { |
120 | 0 | dest = mapping.findForward(KRADConstants.MAPPING_PORTAL); |
121 | 0 | ActionForward newDest = new ActionForward(); |
122 | |
|
123 | 0 | KimCommonUtilsInternal.copyProperties(newDest, dest); |
124 | 0 | newDest.setPath(getApplicationBaseUrl()); |
125 | 0 | return newDest; |
126 | |
} |
127 | |
|
128 | 0 | setupDocumentExit(); |
129 | 0 | return dest; |
130 | |
} |
131 | |
|
132 | |
protected ActionForward getBasePathForward(HttpServletRequest request, ActionForward forward){ |
133 | 0 | ActionForward newDest = new ActionForward(); |
134 | 0 | KimCommonUtilsInternal.copyProperties(newDest, forward); |
135 | 0 | newDest.setPath(getApplicationBaseUrl()); |
136 | 0 | return newDest; |
137 | |
} |
138 | |
|
139 | |
public ActionForward switchToPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
140 | 0 | IdentityManagementDocumentFormBase idmForm = (IdentityManagementDocumentFormBase) form; |
141 | |
|
142 | 0 | KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata(); |
143 | 0 | memberTableMetadata.jumpToPage(memberTableMetadata.getSwitchToPageNumber(), idmForm.getMemberRows().size(), idmForm.getRecordsPerPage()); |
144 | 0 | memberTableMetadata.setColumnToSortIndex(memberTableMetadata.getPreviouslySortedColumnIndex()); |
145 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
146 | |
} |
147 | |
|
148 | |
protected void applyPagingAndSortingFromPreviousPageView(IdentityManagementDocumentFormBase idmForm) { |
149 | 0 | KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata(); |
150 | |
|
151 | 0 | memberTableMetadata.jumpToPage(memberTableMetadata.getViewedPageNumber(), idmForm.getMemberRows().size(), idmForm.getRecordsPerPage()); |
152 | 0 | } |
153 | |
|
154 | |
protected boolean validateRole( String roleId, Role role, String propertyName, String message){ |
155 | 0 | if ( role == null ) { |
156 | 0 | GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_INVALID_ROLE, roleId ); |
157 | 0 | return false; |
158 | |
} |
159 | 0 | KimType typeInfo = KimApiServiceLocator.getKimTypeInfoService().getKimType(role.getKimTypeId()); |
160 | |
|
161 | 0 | if(KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(typeInfo)){ |
162 | 0 | GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_CANT_ADD_DERIVED_ROLE, message); |
163 | 0 | return false; |
164 | |
} |
165 | 0 | return true; |
166 | |
} |
167 | |
|
168 | |
public ActionForward changeNamespace(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
169 | 0 | return refresh(mapping, form, request, response); |
170 | |
} |
171 | |
|
172 | |
protected KimTypeService getKimTypeService( KimType typeInfo ) { |
173 | 0 | String serviceName = typeInfo.getServiceName(); |
174 | 0 | if ( StringUtils.isNotBlank(serviceName) ) { |
175 | |
try { |
176 | 0 | KimTypeService service = (KimTypeService) KIMServiceLocatorInternal.getService(serviceName); |
177 | 0 | if ( service != null && service instanceof KimRoleTypeService ) { |
178 | 0 | return service; |
179 | |
} else { |
180 | 0 | return (KimRoleTypeService) KIMServiceLocatorInternal.getService("kimNoMembersRoleTypeService"); |
181 | |
} |
182 | 0 | } catch ( Exception ex ) { |
183 | 0 | LOG.error( "Unable to find role type service with name: " + serviceName, ex ); |
184 | 0 | return (KimRoleTypeService) KIMServiceLocatorInternal.getService("kimNoMembersRoleTypeService"); |
185 | |
} |
186 | |
} |
187 | 0 | return null; |
188 | |
} |
189 | |
|
190 | |
} |