View Javadoc

1   /*
2    * Copyright 2007-2009 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.form;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.kim.util.KimConstants;
21  import org.kuali.rice.kns.bo.Parameter;
22  import org.kuali.rice.kns.service.KNSServiceLocator;
23  import org.kuali.rice.kns.util.KNSConstants;
24  import org.kuali.rice.kns.util.PagingBannerUtils;
25  import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata;
26  import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
27  
28  import javax.servlet.http.HttpServletRequest;
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  /**
33   * This is a description of what this class does - kellerj don't forget to fill this in. 
34   * 
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   *
37   */
38  @SuppressWarnings("serial")
39  public abstract class IdentityManagementDocumentFormBase extends KualiTransactionalDocumentFormBase {
40  	protected static final Logger LOG = Logger.getLogger(IdentityManagementDocumentFormBase.class);
41      protected static final String MAX_MEMBERS_PER_PAGE_PARM = "MAX_MEMBERS_PER_PAGE";
42  	protected transient KualiTableRenderFormMetadata memberTableMetadata;
43      protected int recordsPerPage = -1;
44      protected boolean inquiry = false;
45      
46  	protected static final String CHANGE_NAMESPACE_METHOD_TO_CALL = "methodToCall.changeNamespace";
47  	protected static final String CHANGE_MEMBER_TYPE_CODE_METHOD_TO_CALL = "methodToCall.changeMemberTypeCode";
48  	protected static final String CHANGE_DEL_ROLE_MEMBER_METHOD_TO_CALL = "methodToCall.changeDelegationRoleMember";
49  
50      /**
51       * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#populate(javax.servlet.http.HttpServletRequest)
52       */
53      @SuppressWarnings("unchecked")
54  	@Override
55      public void populate(HttpServletRequest request) {
56          super.populate(request);
57  
58          if (memberTableMetadata == null)
59          	memberTableMetadata = new KualiTableRenderFormMetadata();
60  
61          if (KNSConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD.equals(getMethodToCall())) {
62              final String paramPrefix = KNSConstants.DISPATCH_REQUEST_PARAMETER + "." + KNSConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD + ".";
63              memberTableMetadata.setSwitchToPageNumber(PagingBannerUtils.getNumbericalValueAfterPrefix(paramPrefix, request.getParameterNames()));
64              if (memberTableMetadata.getSwitchToPageNumber() == -1) {
65                  throw new RuntimeException("Couldn't find page number");
66              }
67          } else if (KNSConstants.TableRenderConstants.SORT_METHOD.equals(getMethodToCall())) {
68              final String paramPrefix = KNSConstants.DISPATCH_REQUEST_PARAMETER + "." + KNSConstants.TableRenderConstants.SORT_METHOD + ".";
69              memberTableMetadata.setColumnToSortIndex(PagingBannerUtils.getNumbericalValueAfterPrefix(paramPrefix, request.getParameterNames()));
70              if (memberTableMetadata.getColumnToSortIndex() == -1) {
71                  memberTableMetadata.setColumnToSortName(PagingBannerUtils.getStringValueAfterPrefix(paramPrefix, request.getParameterNames()));
72              }
73          }
74      }
75  
76  	public KualiTableRenderFormMetadata getMemberTableMetadata() {
77  		return this.memberTableMetadata;
78  	}
79  
80  	public void setMemberTableMetadata(
81  			KualiTableRenderFormMetadata memberTableMetadata) {
82  		this.memberTableMetadata = memberTableMetadata;
83  	}
84  
85  	public int getRecordsPerPage() {
86  		if ( recordsPerPage == -1 ) {
87  			Parameter param = KNSServiceLocator.getParameterService().retrieveParameter(KimConstants.NAMESPACE_CODE, KNSConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, MAX_MEMBERS_PER_PAGE_PARM);
88  			if ( param != null ) {
89  				try {
90  					recordsPerPage = Integer.parseInt( param.getParameterValue() );
91  				} catch ( NumberFormatException ex ) {
92  					LOG.error( "Unable to parse parameter " + KimConstants.NAMESPACE_CODE+"/"+KNSConstants.DetailTypes.DOCUMENT_DETAIL_TYPE+"/"+MAX_MEMBERS_PER_PAGE_PARM + "(+"+param.getParameterValue()+") as an int - defaulting to 1." );
93  					recordsPerPage = 1;
94  				}
95  			} else {
96  				LOG.error( "Unable to find " + KimConstants.NAMESPACE_CODE+"/"+KNSConstants.DetailTypes.DOCUMENT_DETAIL_TYPE+"/"+MAX_MEMBERS_PER_PAGE_PARM + " - defaulting to 1." );
97  				recordsPerPage = 1;
98  			}
99  		}
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 }