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.form;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.coreservice.api.parameter.Parameter;
20  import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
21  import org.kuali.rice.kim.api.KimConstants;
22  import org.kuali.rice.kns.util.PagingBannerUtils;
23  import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata;
24  import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
25  import org.kuali.rice.krad.util.KRADConstants;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  /**
32   * This is a description of what this class does - kellerj don't forget to fill this in. 
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   *
36   */
37  @SuppressWarnings("serial")
38  public abstract class IdentityManagementDocumentFormBase extends KualiTransactionalDocumentFormBase {
39  	protected static final Logger LOG = Logger.getLogger(IdentityManagementDocumentFormBase.class);
40      protected static final String MAX_MEMBERS_PER_PAGE_PARM = "MAX_MEMBERS_PER_PAGE";
41  	protected transient KualiTableRenderFormMetadata memberTableMetadata;
42      protected int recordsPerPage = -1;
43      protected boolean inquiry = false;
44      
45  	protected static final String CHANGE_NAMESPACE_METHOD_TO_CALL = "methodToCall.changeNamespace";
46  	protected static final String CHANGE_MEMBER_TYPE_CODE_METHOD_TO_CALL = "methodToCall.changeMemberTypeCode";
47  	protected static final String CHANGE_DEL_ROLE_MEMBER_METHOD_TO_CALL = "methodToCall.changeDelegationRoleMember";
48  
49      /**
50       * @see org.kuali.rice.krad.web.struts.form.KualiDocumentFormBase#populate(javax.servlet.http.HttpServletRequest)
51       */
52      @SuppressWarnings("unchecked")
53  	@Override
54      public void populate(HttpServletRequest request) {
55          super.populate(request);
56  
57          if (memberTableMetadata == null)
58          	memberTableMetadata = new KualiTableRenderFormMetadata();
59  
60          if (KRADConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD.equals(getMethodToCall())) {
61              final String paramPrefix = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD + ".";
62              memberTableMetadata.setSwitchToPageNumber(
63                      PagingBannerUtils.getNumbericalValueAfterPrefix(paramPrefix, request.getParameterNames()));
64              if (memberTableMetadata.getSwitchToPageNumber() == -1) {
65                  throw new RuntimeException("Couldn't find page number");
66              }
67          } else if (KRADConstants.TableRenderConstants.SORT_METHOD.equals(getMethodToCall())) {
68              final String paramPrefix = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.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 = CoreFrameworkServiceLocator.getParameterService().getParameter(KimConstants.NAMESPACE_CODE, KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, MAX_MEMBERS_PER_PAGE_PARM);
88  			if ( param != null ) {
89  				try {
90  					recordsPerPage = Integer.parseInt( param.getValue() );
91  				} catch ( NumberFormatException ex ) {
92  					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." );
93  					recordsPerPage = 1;
94  				}
95  			} else {
96  				LOG.error( "Unable to find " + KimConstants.NAMESPACE_CODE+"/"+ KRADConstants.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 }