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.kpme.pm.util;
17  
18  import java.util.List;
19  
20  import org.apache.commons.collections.CollectionUtils;
21  import org.apache.commons.lang.StringUtils;
22  import org.joda.time.LocalDate;
23  import org.kuali.kpme.core.paygrade.PayGrade;
24  import org.kuali.kpme.core.service.HrServiceLocator;
25  import org.kuali.kpme.core.util.HrConstants;
26  import org.kuali.kpme.core.util.ValidationUtils;
27  import org.kuali.kpme.pm.PMConstants;
28  import org.kuali.kpme.pm.positiondepartmentaffiliation.PositionDepartmentAffiliation;
29  import org.kuali.kpme.pm.positionreportcat.PositionReportCategory;
30  import org.kuali.kpme.pm.positionreportgroup.PositionReportGroup;
31  import org.kuali.kpme.pm.positionreportsubcat.PositionReportSubCategory;
32  import org.kuali.kpme.pm.positionreporttype.PositionReportType;
33  import org.kuali.kpme.pm.positiontype.PositionType;
34  import org.kuali.kpme.pm.pstnqlfctnvl.PositionQualificationValue;
35  import org.kuali.kpme.pm.service.base.PmServiceLocator;
36  import org.kuali.rice.location.api.campus.Campus;
37  import org.kuali.rice.location.api.services.LocationApiServiceLocator;
38  
39  public class PmValidationUtils {
40  	
41  	/**
42  	 * Validate if there exists Campus that matches given campusCode 
43  	 * Wild card is allowed 
44  	 * @param campusCode
45  	 * @return
46  	 */
47  	public static boolean validateCampus(String campusCode) {
48  		boolean valid = false;
49  		if (ValidationUtils.isWildCard(campusCode)) {
50  			valid = true;
51  		} else {
52  			Campus campusObj = LocationApiServiceLocator.getCampusService().getCampus(campusCode);
53  			valid = (campusObj != null);
54  		}
55  		return valid;
56  	}
57  	
58  	/**
59  	 * Validate if there exists Position Report Type that matches given postionReportType, institution, campus and exists before given date 
60  	 * Wild card is allowed for String parameters
61  	 * @param positionReportType
62  	 * @param institution
63  	 * @param location
64  	 * @param asOfDate
65  	 * @return
66  	 */
67  	public static boolean validatePositionReportType(String positionReportType, String institution, String location, LocalDate asOfDate) {
68  		boolean valid = false;
69  		if (asOfDate != null) {
70  			List<PositionReportType> prtList = PmServiceLocator.getPositionReportTypeService().getPositionReportTypeList(positionReportType, institution, location, asOfDate);
71  			valid = (CollectionUtils.isNotEmpty(prtList));
72  		} 
73  		return valid;
74  	}	
75  	
76  	/** 
77  	 * Validate if the institution is consistent with given Position Report Type 
78  	 * Wild card is allowed for String parameters
79  	 * @param positionReportType
80  	 * @param institutionCode
81  	 * @param asOfDate
82  	 * @return
83  	 */
84  	public static boolean validateInstitutionWithPRT(String positionReportType, String institutionCode, LocalDate asOfDate) {
85  		if (asOfDate != null) {
86  			List<PositionReportType> prtList = PmServiceLocator.getPositionReportTypeService()
87  				.getPositionReportTypeList(positionReportType, institutionCode, PMConstants.WILDCARD_CHARACTER, asOfDate);
88  			return CollectionUtils.isNotEmpty(prtList);
89  		} 
90  		return false;
91  	}
92  	
93  	/**
94  	 * Validate if the campus is consistent with given positonReportType
95  	 * Wild card is allowed for String parameters
96  	 * @param positionReportType
97  	 * @param campus
98  	 * @param asOfDate
99  	 * @return
100 	 */
101 	public static boolean validateCampusWithPRT(String positionReportType, String campus, LocalDate asOfDate) {
102 		if (asOfDate != null) {
103 			List<PositionReportType> prtList = PmServiceLocator.getPositionReportTypeService()
104 				.getPositionReportTypeList(positionReportType, HrConstants.WILDCARD_CHARACTER, campus, asOfDate);
105 			return CollectionUtils.isNotEmpty(prtList);
106 		} 
107 		return false;
108 	}
109 	
110 	public static boolean validatePayGradeWithSalaryGroup(String salaryGroup, String payGrade, LocalDate asOfDate) {
111 		if (asOfDate != null) {
112 			PayGrade grade = HrServiceLocator.getPayGradeService().getPayGrade(payGrade, salaryGroup, asOfDate);
113 			if(grade != null && StringUtils.isNotBlank(grade.getSalGroup())) 
114 				return StringUtils.equals(grade.getSalGroup(), salaryGroup);
115 		}
116 		return false;
117 	}
118 	/**
119 	 * Validate if there exists Position Report Category that matches given postionReportCat, positionReportType , institution, campus and exists before given date 
120 	 * Wild card allowed
121 	 * @param positionReportCat
122 	 * @param positionReportType
123 	 * @param institution
124 	 * @param campus
125 	 * @param asOfDate
126 	 * @return
127 	 */
128 	public static boolean validatePositionReportCategory(String positionReportCat, String positionReportType, String institution, String campus, LocalDate asOfDate) {
129 		if (StringUtils.isNotEmpty(positionReportCat) && asOfDate != null) {
130 			List<PositionReportCategory> prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(positionReportCat, positionReportType, institution, campus, asOfDate);
131 			return CollectionUtils.isNotEmpty(prcList);
132 		}
133 		return false;
134 	}
135 	
136 	/**
137 	 * Validate if there exists Position Report Sub Categories that match given pstnRptSubCat, institution, campus and exists before given date 
138 	 * Wild card allowed
139 	 * @param pstnRptSubCat
140 	 * @param institution
141 	 * @param campus
142 	 * @param asOfDate
143 	 * @return
144 	 */
145 	
146 	public static boolean validatePositionReportSubCat(String pstnRptSubCat, String institution, String location, LocalDate asOfDate) {
147 		if(asOfDate != null) {
148 			List<PositionReportSubCategory> prscList = PmServiceLocator.getPositionReportSubCatService().getPositionReportSubCat(pstnRptSubCat, institution, location, asOfDate);
149 			return CollectionUtils.isNotEmpty(prscList);
150 		}
151 		return false;
152 	}
153 	
154 	public static boolean validatePstnRptGrp(String PstnRptGrp, String institution, String location, LocalDate asOfDate) {
155 		if(asOfDate != null) {
156 			List<PositionReportGroup> prgList = PmServiceLocator.getPositionReportGroupService().getPositionReportGroupList(PstnRptGrp, institution, location, asOfDate);
157 			return CollectionUtils.isNotEmpty(prgList);
158 		}
159 		return false;
160 	}
161 	
162 	public static boolean validatePositionQualificationValue(String qValue) {
163 		if(StringUtils.isNotEmpty(qValue)) {
164 			PositionQualificationValue aPqv = PmServiceLocator.getPositionQualificationValueService().getPositionQualificationValueByValue(qValue);
165 			if(aPqv != null) {
166 				return true;
167 			}
168 		}
169 		return false;
170 	}
171 	
172 	public static boolean validateAffiliation(String positionDeptAffl,  LocalDate asOfDate) {
173 		if (asOfDate != null) {
174 			List<PositionDepartmentAffiliation> pdaList = PmServiceLocator.getPositionDepartmentAffiliationService().getPositionDepartmentAffiliationList(positionDeptAffl, asOfDate);
175 			return CollectionUtils.isNotEmpty(pdaList);
176 		}
177 		return false;
178 	}
179 
180 	public static boolean validatePositionType(String pType, String institution, String campus, LocalDate asOfDate) {
181 		if(asOfDate != null) {
182 			List<PositionType> ptList = PmServiceLocator.getPositionTypeService().getPositionTypeList(pType, institution, campus, asOfDate);
183 			return CollectionUtils.isNotEmpty(ptList);
184 		}
185 		return false;
186 	}
187 		
188 }