View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.KimConstants;
26  import org.kuali.rice.kim.api.role.Role;
27  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
28  import org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase;
29  import org.kuali.rice.kim.web.struts.form.IdentityManagementRoleDocumentForm;
30  import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata;
31  import org.kuali.rice.krad.util.GlobalVariables;
32  import org.kuali.rice.krad.util.KRADConstants;
33  
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.http.HttpServletResponse;
36  
37  /**
38   * This is a description of what this class does - jonathan don't forget to fill this in. 
39   * 
40   * @author Kuali Rice Team (rice.collab@kuali.org)
41   *
42   */
43  public class IdentityManagementRoleInquiry extends IdentityManagementBaseInquiryAction {
44  	private static final Logger LOG = Logger.getLogger(IdentityManagementRoleInquiry.class);	
45  	
46  	/**
47  	 * This overridden method ...
48  	 * 
49  	 * @see org.kuali.rice.kim.web.struts.action.IdentityManagementBaseInquiryAction#loadKimObject(javax.servlet.http.HttpServletRequest, org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase)
50  	 */
51  	@Override
52  	protected void loadKimObject(HttpServletRequest request,
53  			IdentityManagementDocumentFormBase form) {
54          IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
55          String id = request.getParameter(KimConstants.PrimaryKeyConstants.ROLE_ID);
56          String altId =  request.getParameter(KimConstants.PrimaryKeyConstants.SUB_ROLE_ID);
57  
58          String roleId = StringUtils.isNotEmpty(id) ? id : altId;
59          Role role = KimApiServiceLocator.getRoleService().getRole(roleId);
60          if (role != null) {
61          	getUiDocumentService().loadRoleDoc(roleDocumentForm.getRoleDocument(), role);
62          } else {
63          	LOG.error("No records found for Role Inquiry.");
64              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INQUIRY);
65          }
66  	}
67  
68      @Override
69      public ActionForward execute(ActionMapping mapping, ActionForm form,
70              HttpServletRequest request, HttpServletResponse response) throws Exception {
71  
72          IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
73  
74          ActionForward forward = super.execute(mapping, form, request, response);
75  
76          String previouslySortedColumnName = (String)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_SORT_PREV_COL_NM);
77          Boolean sortDescending = ((Boolean)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_SORT_DESC_VALUE));
78  
79          KualiTableRenderFormMetadata memberTableMetadata =  roleDocumentForm.getMemberTableMetadata();
80          memberTableMetadata.setPreviouslySortedColumnName(previouslySortedColumnName);
81          String columnToSort = memberTableMetadata.getColumnToSortName();
82          if  (previouslySortedColumnName != null && StringUtils.isEmpty(columnToSort)) {
83              memberTableMetadata.setColumnToSortName(previouslySortedColumnName);
84          }
85          if (sortDescending != null && !StringUtils.isEmpty(columnToSort)) {
86              memberTableMetadata.setSortDescending(sortDescending.booleanValue());
87          }
88          if (roleDocumentForm.getMemberRows() != null) {
89              memberTableMetadata.sort(roleDocumentForm.getMemberRows(), roleDocumentForm.getRecordsPerPage());
90              memberTableMetadata.jumpToPage(memberTableMetadata.getSwitchToPageNumber(), roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage());
91          }
92  
93          GlobalVariables.getUserSession().addObject(KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_SORT_PREV_COL_NM, memberTableMetadata.getPreviouslySortedColumnName());
94          GlobalVariables.getUserSession().addObject(KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_SORT_DESC_VALUE, memberTableMetadata.isSortDescending());
95  
96          return forward;
97      }
98  
99      public ActionForward sort(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
100         return mapping.findForward(RiceConstants.MAPPING_BASIC);
101     }
102 
103     public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
104         IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
105         String memberSearchValue = roleDocumentForm.getMemberSearchValue();
106         if (memberSearchValue != null && !memberSearchValue.isEmpty()) {
107             memberSearchValue = memberSearchValue.replaceAll("[%*]","");
108             getUiDocumentService().loadRoleMembersBasedOnSearch(roleDocumentForm.getRoleDocument(), memberSearchValue);
109         } else {
110             clear(mapping, form, request, response);
111         }
112         return mapping.findForward(RiceConstants.MAPPING_BASIC);
113     }
114 
115     public ActionForward clear(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
116         IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
117         roleDocumentForm.setMemberSearchValue("");
118         getUiDocumentService().clearRestrictedRoleMembersSearchResults(roleDocumentForm.getRoleDocument());
119 
120         KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata();
121         if (roleDocumentForm.getMemberRows() != null) {
122             memberTableMetadata.jumpToFirstPage(roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage());
123         }
124         return mapping.findForward(RiceConstants.MAPPING_BASIC);
125     }
126 }