View Javadoc

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