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 javax.servlet.http.HttpServletRequest; |
19 | |
import javax.servlet.http.HttpServletResponse; |
20 | |
|
21 | |
import org.apache.commons.lang.StringUtils; |
22 | |
import org.apache.struts.action.ActionForm; |
23 | |
import org.apache.struts.action.ActionForward; |
24 | |
import org.apache.struts.action.ActionMapping; |
25 | |
import org.kuali.rice.core.util.RiceConstants; |
26 | |
import org.kuali.rice.kim.bo.Role; |
27 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
28 | |
import org.kuali.rice.kim.lookup.KimTypeLookupableHelperServiceImpl; |
29 | |
import org.kuali.rice.kim.service.IdentityService; |
30 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
31 | |
import org.kuali.rice.kim.service.ResponsibilityService; |
32 | |
import org.kuali.rice.kim.service.UiDocumentService; |
33 | |
import org.kuali.rice.kim.service.support.KimRoleTypeService; |
34 | |
import org.kuali.rice.kim.service.support.KimTypeService; |
35 | |
import org.kuali.rice.kim.util.KimCommonUtils; |
36 | |
import org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase; |
37 | |
import org.kuali.rice.kns.question.ConfirmationQuestion; |
38 | |
import org.kuali.rice.kns.util.GlobalVariables; |
39 | |
import org.kuali.rice.kns.util.KNSConstants; |
40 | |
import org.kuali.rice.kns.util.RiceKeyConstants; |
41 | |
import org.kuali.rice.kns.web.struts.action.KualiTransactionalDocumentActionBase; |
42 | |
import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase; |
43 | |
import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 0 | abstract public class IdentityManagementDocumentActionBase extends KualiTransactionalDocumentActionBase { |
51 | |
|
52 | |
protected static final String CHANGE_MEMBER_TYPE_CODE_METHOD_TO_CALL = "changeMemberTypeCode"; |
53 | |
protected static final String CHANGE_NAMESPACE_METHOD_TO_CALL = "changeNamespace"; |
54 | |
|
55 | |
protected IdentityService identityService; |
56 | |
protected ResponsibilityService responsibilityService; |
57 | |
protected UiDocumentService uiDocumentService; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
@Override |
66 | |
public ActionForward performLookup(ActionMapping mapping, ActionForm form, |
67 | |
HttpServletRequest request, HttpServletResponse response) |
68 | |
throws Exception { |
69 | 0 | ActionForward forward = super.performLookup(mapping, form, request, response); |
70 | 0 | String path = forward.getPath(); |
71 | |
|
72 | 0 | forward.setPath(KimCommonUtils.getPathWithKimContext(path, getActionName())); |
73 | 0 | return forward; |
74 | |
} |
75 | |
|
76 | |
protected abstract String getActionName(); |
77 | |
|
78 | |
protected IdentityService getIdentityService() { |
79 | 0 | if ( identityService == null ) { |
80 | 0 | identityService = KIMServiceLocator.getIdentityService(); |
81 | |
} |
82 | 0 | return identityService; |
83 | |
} |
84 | |
|
85 | |
protected ResponsibilityService getResponsibilityService() { |
86 | 0 | if ( responsibilityService == null ) { |
87 | 0 | responsibilityService = KIMServiceLocator.getResponsibilityService(); |
88 | |
} |
89 | 0 | return responsibilityService; |
90 | |
} |
91 | |
|
92 | |
protected UiDocumentService getUiDocumentService() { |
93 | 0 | if ( uiDocumentService == null ) { |
94 | 0 | uiDocumentService = KIMServiceLocator.getUiDocumentService(); |
95 | |
} |
96 | 0 | return uiDocumentService; |
97 | |
} |
98 | |
|
99 | |
@Override |
100 | |
protected String getReturnLocation(HttpServletRequest request, ActionMapping mapping){ |
101 | 0 | String returnLocation = super.getReturnLocation(request, mapping); |
102 | 0 | return KimCommonUtils.getPathWithKimContext(returnLocation, getActionName()); |
103 | |
} |
104 | |
|
105 | |
@Override |
106 | |
protected ActionForward returnToSender(HttpServletRequest request, ActionMapping mapping, KualiDocumentFormBase form) { |
107 | 0 | ActionForward dest = null; |
108 | 0 | if (form.isReturnToActionList()) { |
109 | 0 | String workflowBase = getKualiConfigurationService().getPropertyString(KNSConstants.WORKFLOW_URL_KEY); |
110 | 0 | String actionListUrl = workflowBase + "/ActionList.do"; |
111 | |
|
112 | 0 | dest = new ActionForward(actionListUrl, true); |
113 | 0 | } else if (StringUtils.isNotBlank(form.getBackLocation())){ |
114 | 0 | dest = new ActionForward(form.getBackLocation(), true); |
115 | |
} else { |
116 | 0 | dest = mapping.findForward(KNSConstants.MAPPING_PORTAL); |
117 | 0 | ActionForward newDest = new ActionForward(); |
118 | |
|
119 | 0 | KimCommonUtils.copyProperties(newDest, dest); |
120 | 0 | newDest.setPath(getApplicationBaseUrl()); |
121 | 0 | return newDest; |
122 | |
} |
123 | |
|
124 | 0 | setupDocumentExit(); |
125 | 0 | return dest; |
126 | |
} |
127 | |
|
128 | |
protected ActionForward getBasePathForward(HttpServletRequest request, ActionForward forward){ |
129 | 0 | ActionForward newDest = new ActionForward(); |
130 | 0 | KimCommonUtils.copyProperties(newDest, forward); |
131 | 0 | newDest.setPath(getApplicationBaseUrl()); |
132 | 0 | return newDest; |
133 | |
} |
134 | |
|
135 | |
|
136 | |
|
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 | KimTypeInfo typeInfo = KIMServiceLocator.getTypeInfoService().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( KimTypeInfo typeInfo ) { |
173 | 0 | String serviceName = typeInfo.getKimTypeServiceName(); |
174 | 0 | if ( StringUtils.isNotBlank(serviceName) ) { |
175 | |
try { |
176 | 0 | KimTypeService service = (KimTypeService)KIMServiceLocator.getService( serviceName ); |
177 | 0 | if ( service != null && service instanceof KimRoleTypeService ) { |
178 | 0 | return (KimRoleTypeService)service; |
179 | |
} else { |
180 | 0 | return (KimRoleTypeService)KIMServiceLocator.getService( "kimNoMembersRoleTypeService" ); |
181 | |
} |
182 | 0 | } catch ( Exception ex ) { |
183 | |
|
184 | 0 | return (KimRoleTypeService)KIMServiceLocator.getService( "kimNoMembersRoleTypeService" ); |
185 | |
} |
186 | |
} |
187 | 0 | return null; |
188 | |
} |
189 | |
|
190 | |
} |