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