001 /** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kim.web.struts.action; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.apache.log4j.Logger; 020 import org.apache.struts.action.ActionForm; 021 import org.apache.struts.action.ActionForward; 022 import org.apache.struts.action.ActionMapping; 023 import org.kuali.rice.core.api.util.RiceConstants; 024 import org.kuali.rice.core.api.util.RiceKeyConstants; 025 import org.kuali.rice.kim.api.KimConstants; 026 import org.kuali.rice.kim.api.group.Group; 027 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 028 import org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase; 029 import org.kuali.rice.kim.web.struts.form.IdentityManagementGroupDocumentForm; 030 import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata; 031 import org.kuali.rice.krad.util.GlobalVariables; 032 import org.kuali.rice.krad.util.KRADConstants; 033 034 import javax.servlet.http.HttpServletRequest; 035 import javax.servlet.http.HttpServletResponse; 036 037 /** 038 * This is a description of what this class does - jonathan don't forget to fill this in. 039 * 040 * @author Kuali Rice Team (rice.collab@kuali.org) 041 * 042 */ 043 public class IdentityManagementGroupInquiry extends IdentityManagementBaseInquiryAction { 044 private static final Logger LOG = Logger.getLogger(IdentityManagementGroupInquiry.class); 045 046 /** 047 * This overridden method ... 048 * 049 * @see org.kuali.rice.kim.web.struts.action.IdentityManagementBaseInquiryAction#loadKimObject(javax.servlet.http.HttpServletRequest, org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase) 050 */ 051 @Override 052 protected void loadKimObject(HttpServletRequest request, IdentityManagementDocumentFormBase form) { 053 IdentityManagementGroupDocumentForm groupDocumentForm = (IdentityManagementGroupDocumentForm) form; 054 String id = request.getParameter(KimConstants.PrimaryKeyConstants.GROUP_ID); 055 String altId = request.getParameter(KimConstants.AttributeConstants.GROUP_ID); 056 057 String groupId = StringUtils.isNotEmpty(id) ? id : altId; 058 Group group = null; 059 if (StringUtils.isNotEmpty(groupId)) { 060 group = KimApiServiceLocator.getGroupService().getGroup(groupId); 061 } else { 062 String namespaceCode = request.getParameter(KimConstants.UniqueKeyConstants.NAMESPACE_CODE); 063 String groupName = request.getParameter(KimConstants.UniqueKeyConstants.GROUP_NAME); 064 065 if (!StringUtils.isBlank(namespaceCode) && !StringUtils.isBlank(groupName)) { 066 group = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(namespaceCode, groupName); 067 } 068 } 069 if (group != null) { 070 getUiDocumentService().loadGroupDoc(groupDocumentForm.getGroupDocument(), group); 071 } else { 072 LOG.error("No records found for Group Inquiry."); 073 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INQUIRY); 074 } 075 } 076 077 078 @Override 079 public ActionForward execute(ActionMapping mapping, ActionForm form, 080 HttpServletRequest request, HttpServletResponse response) throws Exception { 081 082 IdentityManagementGroupDocumentForm groupDocumentForm = (IdentityManagementGroupDocumentForm) form; 083 084 ActionForward forward = super.execute(mapping, form, request, response); 085 086 String previouslySortedColumnName = (String)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_SORT_PREV_COL_NM); 087 Boolean sortDescending = ((Boolean)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_SORT_DESC_VALUE)); 088 089 KualiTableRenderFormMetadata memberTableMetadata = groupDocumentForm.getMemberTableMetadata(); 090 memberTableMetadata.setPreviouslySortedColumnName(previouslySortedColumnName); 091 if (sortDescending != null) { 092 memberTableMetadata.setSortDescending(sortDescending.booleanValue()); 093 } 094 if (groupDocumentForm.getMemberRows() != null) { 095 memberTableMetadata.sort(groupDocumentForm.getMemberRows(), groupDocumentForm.getRecordsPerPage()); 096 memberTableMetadata.jumpToPage(memberTableMetadata.getSwitchToPageNumber(), groupDocumentForm.getMemberRows().size(), groupDocumentForm.getRecordsPerPage()); 097 } 098 099 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 }