001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kim.web.struts.action; 017 018import org.apache.commons.lang.StringUtils; 019import org.apache.log4j.Logger; 020import org.apache.struts.action.ActionForm; 021import org.apache.struts.action.ActionForward; 022import org.apache.struts.action.ActionMapping; 023import org.kuali.rice.core.api.util.RiceConstants; 024import org.kuali.rice.core.api.util.RiceKeyConstants; 025import org.kuali.rice.kim.api.KimConstants; 026import org.kuali.rice.kim.api.role.Role; 027import org.kuali.rice.kim.api.services.KimApiServiceLocator; 028import org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase; 029import org.kuali.rice.kim.web.struts.form.IdentityManagementRoleDocumentForm; 030import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata; 031import org.kuali.rice.krad.util.GlobalVariables; 032import org.kuali.rice.krad.util.KRADConstants; 033 034import javax.servlet.http.HttpServletRequest; 035import 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 */ 043public class IdentityManagementRoleInquiry extends IdentityManagementBaseInquiryAction { 044 private static final Logger LOG = Logger.getLogger(IdentityManagementRoleInquiry.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, 053 IdentityManagementDocumentFormBase form) { 054 IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; 055 String id = request.getParameter(KimConstants.PrimaryKeyConstants.ROLE_ID); 056 String altId = request.getParameter(KimConstants.PrimaryKeyConstants.SUB_ROLE_ID); 057 058 String roleId = StringUtils.isNotEmpty(id) ? id : altId; 059 Role role = KimApiServiceLocator.getRoleService().getRole(roleId); 060 if (role != null) { 061 getUiDocumentService().loadRoleDoc(roleDocumentForm.getRoleDocument(), role); 062 } else { 063 LOG.error("No records found for Role Inquiry: " + request.getParameterMap()); 064 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INQUIRY); 065 } 066 } 067 068 @Override 069 public ActionForward execute(ActionMapping mapping, ActionForm form, 070 HttpServletRequest request, HttpServletResponse response) throws Exception { 071 072 IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; 073 074 ActionForward forward = super.execute(mapping, form, request, response); 075 076 String previouslySortedColumnName = (String)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_SORT_PREV_COL_NM); 077 Boolean sortDescending = ((Boolean)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_SORT_DESC_VALUE)); 078 079 KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata(); 080 memberTableMetadata.setPreviouslySortedColumnName(previouslySortedColumnName); 081 String columnToSort = memberTableMetadata.getColumnToSortName(); 082 if (previouslySortedColumnName != null && StringUtils.isEmpty(columnToSort)) { 083 memberTableMetadata.setColumnToSortName(previouslySortedColumnName); 084 } 085 if (sortDescending != null && !StringUtils.isEmpty(columnToSort)) { 086 memberTableMetadata.setSortDescending(sortDescending.booleanValue()); 087 } 088 if (roleDocumentForm.getMemberRows() != null) { 089 memberTableMetadata.sort(roleDocumentForm.getMemberRows(), roleDocumentForm.getRecordsPerPage()); 090 memberTableMetadata.jumpToPage(memberTableMetadata.getSwitchToPageNumber(), roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage()); 091 } 092 093 GlobalVariables.getUserSession().addObject(KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_SORT_PREV_COL_NM, memberTableMetadata.getPreviouslySortedColumnName()); 094 GlobalVariables.getUserSession().addObject(KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_SORT_DESC_VALUE, memberTableMetadata.isSortDescending()); 095 096 return forward; 097 } 098 099 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}