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.form; 017 018import org.apache.log4j.Logger; 019import org.kuali.rice.coreservice.api.parameter.Parameter; 020import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator; 021import org.kuali.rice.kim.api.KimConstants; 022import org.kuali.rice.kns.util.PagingBannerUtils; 023import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata; 024import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase; 025import org.kuali.rice.krad.util.KRADConstants; 026 027import javax.servlet.http.HttpServletRequest; 028import java.util.ArrayList; 029import java.util.List; 030 031/** 032 * This is a description of what this class does - kellerj don't forget to fill this in. 033 * 034 * @author Kuali Rice Team (rice.collab@kuali.org) 035 * 036 */ 037@SuppressWarnings("serial") 038public abstract class IdentityManagementDocumentFormBase extends KualiTransactionalDocumentFormBase { 039 protected static final Logger LOG = Logger.getLogger(IdentityManagementDocumentFormBase.class); 040 protected static final String MAX_MEMBERS_PER_PAGE_PARM = "MAX_MEMBERS_PER_PAGE"; 041 protected transient KualiTableRenderFormMetadata memberTableMetadata; 042 protected int recordsPerPage = -1; 043 protected boolean inquiry = false; 044 045 protected static final String CHANGE_NAMESPACE_METHOD_TO_CALL = "methodToCall.changeNamespace"; 046 protected static final String CHANGE_MEMBER_TYPE_CODE_METHOD_TO_CALL = "methodToCall.changeMemberTypeCode"; 047 protected static final String CHANGE_DEL_ROLE_MEMBER_METHOD_TO_CALL = "methodToCall.changeDelegationRoleMember"; 048 049 /** 050 * @see org.kuali.rice.krad.web.struts.form.KualiDocumentFormBase#populate(javax.servlet.http.HttpServletRequest) 051 */ 052 @SuppressWarnings("unchecked") 053 @Override 054 public void populate(HttpServletRequest request) { 055 super.populate(request); 056 057 if (memberTableMetadata == null) 058 memberTableMetadata = new KualiTableRenderFormMetadata(); 059 060 if (KRADConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD.equals(getMethodToCall())) { 061 final String paramPrefix = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD + "."; 062 memberTableMetadata.setSwitchToPageNumber( 063 PagingBannerUtils.getNumbericalValueAfterPrefix(paramPrefix, request.getParameterNames())); 064 if (memberTableMetadata.getSwitchToPageNumber() == -1) { 065 throw new RuntimeException("Couldn't find page number"); 066 } 067 } else if (KRADConstants.TableRenderConstants.SORT_METHOD.equals(getMethodToCall())) { 068 final String paramPrefix = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.TableRenderConstants.SORT_METHOD + "."; 069 memberTableMetadata.setColumnToSortIndex(PagingBannerUtils.getNumbericalValueAfterPrefix(paramPrefix, request.getParameterNames())); 070 if (memberTableMetadata.getColumnToSortIndex() == -1) { 071 memberTableMetadata.setColumnToSortName(PagingBannerUtils.getStringValueAfterPrefix(paramPrefix, request.getParameterNames())); 072 } 073 } 074 } 075 076 public KualiTableRenderFormMetadata getMemberTableMetadata() { 077 return this.memberTableMetadata; 078 } 079 080 public void setMemberTableMetadata( 081 KualiTableRenderFormMetadata memberTableMetadata) { 082 this.memberTableMetadata = memberTableMetadata; 083 } 084 085 public int getRecordsPerPage() { 086 if ( recordsPerPage == -1 ) { 087 Parameter param = CoreFrameworkServiceLocator.getParameterService().getParameter(KimConstants.NAMESPACE_CODE, KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, MAX_MEMBERS_PER_PAGE_PARM); 088 if ( param != null ) { 089 try { 090 recordsPerPage = Integer.parseInt( param.getValue() ); 091 } catch ( NumberFormatException ex ) { 092 LOG.error( "Unable to parse parameter " + KimConstants.NAMESPACE_CODE+"/"+ KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE+"/"+MAX_MEMBERS_PER_PAGE_PARM + "(+"+param.getValue()+") as an int - defaulting to 1." ); 093 recordsPerPage = 1; 094 } 095 } else { 096 LOG.error( "Unable to find " + KimConstants.NAMESPACE_CODE+"/"+ KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE+"/"+MAX_MEMBERS_PER_PAGE_PARM + " - defaulting to 1." ); 097 recordsPerPage = 1; 098 } 099 } 100 return recordsPerPage; 101 } 102 103 // support for the inquiryControls tag since using same form 104 public boolean isCanExport() { 105 return false; 106 } 107 108 @SuppressWarnings("unchecked") 109 public List getMemberRows() { 110 return new ArrayList(); 111 } 112 113 /** 114 * @return the inquiry 115 */ 116 public boolean isInquiry() { 117 return this.inquiry; 118 } 119 120 /** 121 * @param inquiry the inquiry to set 122 */ 123 public void setInquiry(boolean inquiry) { 124 this.inquiry = inquiry; 125 } 126}