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