View Javadoc

1   /**
2    * Copyright 2004-2012 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.hr.time.roles;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.hr.time.util.TKContext;
22  import org.kuali.hr.time.util.TkConstants;
23  import org.kuali.rice.core.api.util.ConcreteKeyValue;
24  import org.kuali.rice.core.api.util.KeyValue;
25  import org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm;
26  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
27  
28  public class TkRoleValuesFinder extends KeyValuesBase {
29  
30  	private KualiMaintenanceForm kualiForm = null;
31  	
32  	public KualiMaintenanceForm getKualiForm() {
33  		return kualiForm;
34  	}
35  
36  	public void setKualiForm(KualiMaintenanceForm kualiForm) {
37  		this.kualiForm = kualiForm;
38  	}
39  
40  	@Override
41  	public List<KeyValue> getKeyValues() {
42  		//Filter this list based on your roles for this user
43  		List<KeyValue> filteredLabels = new ArrayList<KeyValue>();
44  		KualiMaintenanceForm kualiForm = null;
45          if (TKContext.getHttpServletRequest() != null) {
46              if(TKContext.getHttpServletRequest().getAttribute("KualiForm") instanceof KualiMaintenanceForm){
47                  kualiForm = (KualiMaintenanceForm)TKContext.getHttpServletRequest().getAttribute("KualiForm");
48                  setKualiForm(kualiForm);
49              }
50          }
51          
52  		if(kualiForm == null || kualiForm.getDocTypeName().equals("RoleGroupMaintenanceDocumentType")){
53  			if(TKContext.getUser().isSystemAdmin()){
54  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_SYS_ADMIN, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_SYS_ADMIN)));
55  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_GLOBAL_VO, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_GLOBAL_VO)));
56  			} 
57  			
58  			if(TKContext.getUser().isSystemAdmin() || TKContext.getUser().isLocationAdmin()){
59  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_LOCATION_ADMIN, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_LOCATION_ADMIN)));
60  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_LOCATION_VO, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_LOCATION_VO)));
61  			}
62  		}
63  
64  		if(kualiForm == null || kualiForm.getDocTypeName().equals("DepartmentMaintenanceDocumentType")){
65  			if(TKContext.getUser().isSystemAdmin() || TKContext.getUser().isLocationAdmin()){
66  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_DEPT_ADMIN, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_DEPT_ADMIN)));
67  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_DEPT_VO, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_DEPT_VO)));
68  				
69  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_LV_DEPT_ADMIN, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_LV_DEPT_ADMIN)));
70  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_LV_DEPT_VO, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_LV_DEPT_VO)));
71  			}
72  		}
73  		
74  		if(kualiForm == null || kualiForm.getDocTypeName().equals("WorkAreaMaintenanceDocumentType")){
75  			if(TKContext.getUser().isSystemAdmin() || TKContext.getUser().isLocationAdmin() || TKContext.getUser().isDepartmentAdmin()){
76  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_APPROVER, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_APPROVER)));
77  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_APPROVER_DELEGATE, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_APPROVER_DELEGATE)));
78  				filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_REVIEWER, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_REVIEWER)));
79  			}
80  		}
81  		
82  	
83  
84  		return filteredLabels;
85  	}
86  }