001 /**
002 * Copyright 2004-2013 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 */
016 package org.kuali.hr.time.roles;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import org.kuali.hr.time.util.TKContext;
022 import org.kuali.hr.time.util.TKUser;
023 import org.kuali.hr.time.util.TkConstants;
024 import org.kuali.rice.core.api.util.ConcreteKeyValue;
025 import org.kuali.rice.core.api.util.KeyValue;
026 import org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm;
027 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
028
029 public class TkRoleValuesFinder extends KeyValuesBase {
030
031 private KualiMaintenanceForm kualiForm = null;
032
033 public KualiMaintenanceForm getKualiForm() {
034 return kualiForm;
035 }
036
037 public void setKualiForm(KualiMaintenanceForm kualiForm) {
038 this.kualiForm = kualiForm;
039 }
040
041 @Override
042 public List<KeyValue> getKeyValues() {
043 //Filter this list based on your roles for this user
044 List<KeyValue> filteredLabels = new ArrayList<KeyValue>();
045 KualiMaintenanceForm kualiForm = null;
046 if (TKContext.getHttpServletRequest() != null) {
047 if(TKContext.getHttpServletRequest().getAttribute("KualiForm") instanceof KualiMaintenanceForm){
048 kualiForm = (KualiMaintenanceForm)TKContext.getHttpServletRequest().getAttribute("KualiForm");
049 setKualiForm(kualiForm);
050 }
051 }
052
053 if(kualiForm == null || kualiForm.getDocTypeName().equals("RoleGroupMaintenanceDocumentType")){
054 if(TKUser.isSystemAdmin()){
055 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_SYS_ADMIN, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_SYS_ADMIN)));
056 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_GLOBAL_VO, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_GLOBAL_VO)));
057 }
058
059 if(TKUser.isSystemAdmin() || TKUser.isLocationAdmin()){
060 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_LOCATION_ADMIN, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_LOCATION_ADMIN)));
061 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_LOCATION_VO, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_LOCATION_VO)));
062 }
063 }
064
065 if(kualiForm == null || kualiForm.getDocTypeName().equals("DepartmentMaintenanceDocumentType")){
066 if (TKUser.isSystemAdmin() || TKUser.isLocationAdmin() || TKUser.isDepartmentAdmin()) {
067 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_DEPT_ADMIN, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_DEPT_ADMIN)));
068 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_DEPT_VO, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_DEPT_VO)));
069
070 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_LV_DEPT_ADMIN, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_LV_DEPT_ADMIN)));
071 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_LV_DEPT_VO, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_LV_DEPT_VO)));
072 }
073 }
074
075 if(kualiForm == null || kualiForm.getDocTypeName().equals("WorkAreaMaintenanceDocumentType")){
076 if(TKUser.isSystemAdmin() || TKUser.isLocationAdmin() || TKUser.isDepartmentAdmin()){
077 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_APPROVER, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_APPROVER)));
078 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_APPROVER_DELEGATE, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_APPROVER_DELEGATE)));
079 filteredLabels.add(new ConcreteKeyValue(TkConstants.ROLE_TK_REVIEWER, TkConstants.ALL_ROLES_MAP.get(TkConstants.ROLE_TK_REVIEWER)));
080 }
081 }
082
083
084
085 return filteredLabels;
086 }
087 }