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.group.Group;
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.IdentityManagementGroupDocumentForm;
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 IdentityManagementGroupInquiry extends IdentityManagementBaseInquiryAction {
44  	private static final Logger LOG = Logger.getLogger(IdentityManagementGroupInquiry.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, IdentityManagementDocumentFormBase form) {
53          IdentityManagementGroupDocumentForm groupDocumentForm = (IdentityManagementGroupDocumentForm) form;
54          String id = request.getParameter(KimConstants.PrimaryKeyConstants.GROUP_ID);
55          String altId = request.getParameter(KimConstants.AttributeConstants.GROUP_ID);
56  
57          String groupId = StringUtils.isNotEmpty(id) ? id : altId;
58          Group group = null;
59          if (StringUtils.isNotEmpty(groupId)) {
60          	group = KimApiServiceLocator.getGroupService().getGroup(groupId);
61          } else {
62          	String namespaceCode = request.getParameter(KimConstants.UniqueKeyConstants.NAMESPACE_CODE);
63          	String groupName = request.getParameter(KimConstants.UniqueKeyConstants.GROUP_NAME);
64          	
65          	if (!StringUtils.isBlank(namespaceCode) && !StringUtils.isBlank(groupName)) {
66          		group = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(namespaceCode, groupName);
67              }
68          }
69          if (group != null) {
70          	getUiDocumentService().loadGroupDoc(groupDocumentForm.getGroupDocument(), group);
71          } else {
72          	LOG.error("No records found for Group Inquiry.");
73              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INQUIRY);
74          }
75  	}
76  
77  
78      @Override
79      public ActionForward execute(ActionMapping mapping, ActionForm form,
80              HttpServletRequest request, HttpServletResponse response) throws Exception {
81  
82          IdentityManagementGroupDocumentForm groupDocumentForm = (IdentityManagementGroupDocumentForm) form;
83  
84          ActionForward forward = super.execute(mapping, form, request, response);
85  
86          String previouslySortedColumnName = (String)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_SORT_PREV_COL_NM);
87          Boolean sortDescending = ((Boolean)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_SORT_DESC_VALUE));
88  
89          KualiTableRenderFormMetadata memberTableMetadata =  groupDocumentForm.getMemberTableMetadata();
90          memberTableMetadata.setPreviouslySortedColumnName(previouslySortedColumnName);
91          if (sortDescending != null) {
92              memberTableMetadata.setSortDescending(sortDescending.booleanValue());
93          }
94          if (groupDocumentForm.getMemberRows() != null) {
95              memberTableMetadata.sort(groupDocumentForm.getMemberRows(), groupDocumentForm.getRecordsPerPage());
96              memberTableMetadata.jumpToPage(memberTableMetadata.getSwitchToPageNumber(), groupDocumentForm.getMemberRows().size(), groupDocumentForm.getRecordsPerPage());
97          }
98  
99          GlobalVariables.getUserSession().addObject(KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_SORT_PREV_COL_NM, memberTableMetadata.getPreviouslySortedColumnName());
100         GlobalVariables.getUserSession().addObject(KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_SORT_DESC_VALUE, memberTableMetadata.isSortDescending());
101 
102         return forward;
103     }
104 
105 
106     public ActionForward sort(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
107         return mapping.findForward(RiceConstants.MAPPING_BASIC);
108     }
109 }