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