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.util.RiceConstants; |
24 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
25 | |
import org.kuali.rice.kim.api.services.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().getPropertyString(KRADConstants.WORKFLOW_URL_KEY); |
113 | 0 | String actionListUrl = workflowBase + "/ActionList.do"; |
114 | |
|
115 | 0 | dest = new ActionForward(actionListUrl, true); |
116 | 0 | } else if (StringUtils.isNotBlank(form.getBackLocation())){ |
117 | 0 | dest = new ActionForward(form.getBackLocation(), true); |
118 | |
} else { |
119 | 0 | dest = mapping.findForward(KRADConstants.MAPPING_PORTAL); |
120 | 0 | ActionForward newDest = new ActionForward(); |
121 | |
|
122 | 0 | KimCommonUtilsInternal.copyProperties(newDest, dest); |
123 | 0 | newDest.setPath(getApplicationBaseUrl()); |
124 | 0 | return newDest; |
125 | |
} |
126 | |
|
127 | 0 | setupDocumentExit(); |
128 | 0 | return dest; |
129 | |
} |
130 | |
|
131 | |
protected ActionForward getBasePathForward(HttpServletRequest request, ActionForward forward){ |
132 | 0 | ActionForward newDest = new ActionForward(); |
133 | 0 | KimCommonUtilsInternal.copyProperties(newDest, forward); |
134 | 0 | newDest.setPath(getApplicationBaseUrl()); |
135 | 0 | return newDest; |
136 | |
} |
137 | |
|
138 | |
public ActionForward switchToPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
139 | 0 | IdentityManagementDocumentFormBase idmForm = (IdentityManagementDocumentFormBase) form; |
140 | |
|
141 | 0 | KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata(); |
142 | 0 | memberTableMetadata.jumpToPage(memberTableMetadata.getSwitchToPageNumber(), idmForm.getMemberRows().size(), idmForm.getRecordsPerPage()); |
143 | 0 | memberTableMetadata.setColumnToSortIndex(memberTableMetadata.getPreviouslySortedColumnIndex()); |
144 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
145 | |
} |
146 | |
|
147 | |
protected void applyPagingAndSortingFromPreviousPageView(IdentityManagementDocumentFormBase idmForm) { |
148 | 0 | KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata(); |
149 | |
|
150 | 0 | memberTableMetadata.jumpToPage(memberTableMetadata.getViewedPageNumber(), idmForm.getMemberRows().size(), idmForm.getRecordsPerPage()); |
151 | 0 | } |
152 | |
|
153 | |
protected boolean validateRole( String roleId, Role role, String propertyName, String message){ |
154 | 0 | if ( role == null ) { |
155 | 0 | GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_INVALID_ROLE, roleId ); |
156 | 0 | return false; |
157 | |
} |
158 | 0 | KimType typeInfo = KimApiServiceLocator.getKimTypeInfoService().getKimType(role.getKimTypeId()); |
159 | |
|
160 | 0 | if(KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(typeInfo)){ |
161 | 0 | GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_CANT_ADD_DERIVED_ROLE, message); |
162 | 0 | return false; |
163 | |
} |
164 | 0 | return true; |
165 | |
} |
166 | |
|
167 | |
public ActionForward changeNamespace(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
168 | 0 | return refresh(mapping, form, request, response); |
169 | |
} |
170 | |
|
171 | |
protected KimTypeService getKimTypeService( KimType typeInfo ) { |
172 | 0 | String serviceName = typeInfo.getServiceName(); |
173 | 0 | if ( StringUtils.isNotBlank(serviceName) ) { |
174 | |
try { |
175 | 0 | KimTypeService service = (KimTypeService) KIMServiceLocatorInternal.getService(serviceName); |
176 | 0 | if ( service != null && service instanceof KimRoleTypeService ) { |
177 | 0 | return service; |
178 | |
} else { |
179 | 0 | return (KimRoleTypeService) KIMServiceLocatorInternal.getService("kimNoMembersRoleTypeService"); |
180 | |
} |
181 | 0 | } catch ( Exception ex ) { |
182 | 0 | LOG.error( "Unable to find role type service with name: " + serviceName, ex ); |
183 | 0 | return (KimRoleTypeService) KIMServiceLocatorInternal.getService("kimNoMembersRoleTypeService"); |
184 | |
} |
185 | |
} |
186 | 0 | return null; |
187 | |
} |
188 | |
|
189 | |
} |