View Javadoc
1   /**
2    * Copyright 2004-2014 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.api.departmentaffiliation.DepartmentAffiliationContract;
24  import org.kuali.kpme.core.api.paygrade.PayGrade;
25  import org.kuali.kpme.core.service.HrServiceLocator;
26  import org.kuali.kpme.core.util.ValidationUtils;
27  import org.kuali.kpme.pm.api.positionappointment.PositionAppointmentContract;
28  import org.kuali.kpme.pm.api.positionreportcat.PositionReportCategoryContract;
29  import org.kuali.kpme.pm.api.positionreportsubcat.PositionReportSubCategoryContract;
30  import org.kuali.kpme.pm.api.positionreporttype.PositionReportTypeContract;
31  import org.kuali.kpme.pm.api.positiontype.PositionTypeContract;
32  import org.kuali.kpme.pm.api.pstncontracttype.PstnContractTypeContract;
33  import org.kuali.kpme.pm.api.pstnqlfctnvl.PositionQualificationValueContract;
34  import org.kuali.kpme.pm.service.base.PmServiceLocator;
35  import org.kuali.rice.location.api.campus.Campus;
36  import org.kuali.rice.location.api.services.LocationApiServiceLocator;
37  
38  public class PmValidationUtils {
39  	
40  	/**
41  	 * Validate if there exists Campus that matches given campusCode 
42  	 * Wild card is allowed 
43  	 * @param campusCode
44  	 * @return
45  	 */
46  	public static boolean validateCampus(String campusCode) {
47  		boolean valid = false;
48  		if (ValidationUtils.isWildCard(campusCode)) {
49  			valid = true;
50  		} else {
51  			Campus campusObj = LocationApiServiceLocator.getCampusService().getCampus(campusCode);
52  			valid = (campusObj != null);
53  		}
54  		return valid;
55  	}
56  	
57  	/**
58  	 * Validate if there exists Position Report Type that matches given postionReportType, institution, campus and exists before given date 
59  	 * Wild card is allowed for String parameters
60  	 * @param positionReportType
61  	 * @param institution
62  	 * @param location
63  	 * @param asOfDate
64  	 * @return
65  	 */
66  	public static boolean validatePositionReportType(String positionReportType, LocalDate asOfDate) {
67  		boolean valid = false;
68  		if (asOfDate != null) {
69  			List<? extends PositionReportTypeContract> prtList = PmServiceLocator.getPositionReportTypeService().getPositionReportTypeList(positionReportType, asOfDate);
70  			valid = (CollectionUtils.isNotEmpty(prtList));
71  		} 
72  		return valid;
73  	}	
74  
75  	public static boolean validatePayGradeWithSalaryGroup(String salaryGroup, String payGrade, LocalDate asOfDate) {
76  		if (asOfDate != null) {
77  			PayGrade grade = HrServiceLocator.getPayGradeService().getPayGrade(payGrade, salaryGroup, asOfDate);
78  			if(grade != null && StringUtils.isNotBlank(grade.getSalGroup())) 
79  				return StringUtils.equals(grade.getSalGroup(), salaryGroup);
80  		}
81  		return false;
82  	}
83  	/**
84  	 * Validate if there exists Position Report Category that matches given postionReportCat, positionReportType , groupKeyCode and exists before given date 
85  	 * Wild card allowed
86  	 * @param positionReportCat
87  	 * @param positionReportType
88  	 * @param groupKeyCode
89  	 * @param asOfDate
90  	 * @return
91  	 */
92  	public static boolean validatePositionReportCategory(String positionReportCat, String positionReportType,  LocalDate asOfDate) {
93  		if (StringUtils.isNotEmpty(positionReportCat) && asOfDate != null) {
94  			List<? extends PositionReportCategoryContract> prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(positionReportCat, positionReportType, asOfDate);
95  			return CollectionUtils.isNotEmpty(prcList);
96  		}
97  		return false;
98  	}
99  	
100 	/**
101 	 * Validate if there exists Position Report Sub Categories that match given pstnRptSubCat, institution, campus and exists before given date 
102 	 * Wild card allowed
103 	 * @param pstnRptSubCat
104 	 * @param institution
105 	 * @param campus
106 	 * @param asOfDate
107 	 * @return
108 	 */
109 	
110 	public static boolean validatePositionReportSubCat(String pstnRptSubCat, LocalDate asOfDate) {
111 		if(asOfDate != null) {
112 			List<? extends PositionReportSubCategoryContract> prscList = PmServiceLocator.getPositionReportSubCatService().getPositionReportSubCat(pstnRptSubCat, asOfDate);
113 			return CollectionUtils.isNotEmpty(prscList);
114 		}
115 		return false;
116 	}
117 	
118 	public static boolean validatePositionQualificationValue(String qValue) {
119 		if(StringUtils.isNotEmpty(qValue)) {
120 			PositionQualificationValueContract aPqv = PmServiceLocator.getPositionQualificationValueService().getPositionQualificationValueByValue(qValue);
121 			if(aPqv != null) {
122 				return true;
123 			}
124 		}
125 		return false;
126 	}
127 	
128 	public static boolean validateAffiliation(String deptAffl,  LocalDate asOfDate) {
129 		if (asOfDate != null) {
130 			List<? extends DepartmentAffiliationContract> pdaList = HrServiceLocator.getDepartmentAffiliationService().getDepartmentAffiliationList(deptAffl, asOfDate);
131 			return CollectionUtils.isNotEmpty(pdaList);
132 		}
133 		return false;
134 	}
135 
136 	public static boolean validatePositionType(String pType, LocalDate asOfDate) {
137 		if(asOfDate != null) {
138 			List<? extends PositionTypeContract> ptList = PmServiceLocator.getPositionTypeService().getPositionTypeList(pType, asOfDate);
139 			return CollectionUtils.isNotEmpty(ptList);
140 		}
141 		return false;
142 	}
143 	
144 	public static boolean validatePositionAppointmentType(String positionAppointment, String groupKeyCode, LocalDate asOfDate) {
145 		if (StringUtils.isNotEmpty(positionAppointment) && asOfDate != null) {
146 			List<? extends PositionAppointmentContract> ptList = PmServiceLocator.getPositionAppointmentService().getPositionAppointmentList(positionAppointment, groupKeyCode, asOfDate);
147 			return CollectionUtils.isNotEmpty(ptList);
148 		}
149 		return false;
150 	}
151 
152 	public static boolean validatePositionContractType(String name, String groupKeyCode, LocalDate asOfDate) {
153 		if (StringUtils.isNotEmpty(name) && asOfDate != null) {
154 			List<? extends PstnContractTypeContract> ptList = PmServiceLocator.getPstnContractTypeService().getPstnContractTypeList(name, groupKeyCode, asOfDate);
155 			return CollectionUtils.isNotEmpty(ptList);
156 		}
157 		return false;
158 	}
159 	
160 }