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.principal.validation; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.hr.time.principal.PrincipalHRAttributes; 020 import org.kuali.hr.time.util.ValidationUtils; 021 import org.kuali.rice.kns.document.MaintenanceDocument; 022 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; 023 import org.kuali.rice.krad.bo.PersistableBusinessObject; 024 025 public class PrincipalHRAttributesRule extends MaintenanceDocumentRuleBase { 026 027 private boolean validatePrincipalId(PrincipalHRAttributes principalHRAttr) { 028 if (principalHRAttr.getPrincipalId() != null 029 && !ValidationUtils.validatePrincipalId(principalHRAttr 030 .getPrincipalId())) { 031 this.putFieldError("principalId", "error.existence", 032 "principalId '" + principalHRAttr.getPrincipalId() + "'"); 033 return false; 034 } else { 035 return true; 036 } 037 } 038 039 private boolean validatePayCalendar(PrincipalHRAttributes principalHRAttr) { 040 if (principalHRAttr.getPayCalendar() != null 041 && !ValidationUtils.validateCalendarByType(principalHRAttr.getPayCalendar(), "Pay")) { 042 this.putFieldError("payCalendar", "error.existence", 043 "Pay Calendar '" + principalHRAttr.getPayCalendar() + "'"); 044 return false; 045 } else { 046 return true; 047 } 048 } 049 050 private boolean validateLeaveCalendar(PrincipalHRAttributes principalHRAttr) { 051 if (principalHRAttr.getLeaveCalendar() != null 052 && !ValidationUtils.validateCalendarByType(principalHRAttr.getLeaveCalendar(), "Leave")) { 053 this.putFieldError("leaveCalendar", "error.existence", 054 "Leave Calendar '" + principalHRAttr.getLeaveCalendar() + "'"); 055 return false; 056 } else { 057 return true; 058 } 059 } 060 061 062 private boolean validateLeavePlan(PrincipalHRAttributes principalHRAttr) { 063 if (principalHRAttr.getLeavePlan() != null 064 && !ValidationUtils.validateLeavePlan(principalHRAttr.getLeavePlan(), null)) { 065 this.putFieldError("leavePlan", "error.existence", 066 "leavePlan '" + principalHRAttr.getLeavePlan() + "'"); 067 return false; 068 } else { 069 return true; 070 } 071 } 072 073 private boolean validateServiceDate(PrincipalHRAttributes principalHRAttr) { 074 if (StringUtils.isNotEmpty(principalHRAttr.getLeavePlan()) 075 && principalHRAttr.getServiceDate() == null) { 076 this.putFieldError("leavePlan", "validation.prerequisite", "'Service Date'"); 077 return false; 078 } 079 return true; 080 } 081 082 boolean validateEffectiveDate(PrincipalHRAttributes principalHRAttr) { 083 boolean valid = true; 084 if (principalHRAttr.getEffectiveDate() != null && !ValidationUtils.validateOneYearFutureDate(principalHRAttr.getEffectiveDate())) { 085 this.putFieldError("effectiveDate", "error.date.exceed.year", "Effective Date"); 086 valid = false; 087 } 088 return valid; 089 } 090 091 @Override 092 protected boolean processCustomRouteDocumentBusinessRules( 093 MaintenanceDocument document) { 094 boolean valid = false; 095 096 097 LOG.debug("entering custom validation for Job"); 098 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo(); 099 if (pbo instanceof PrincipalHRAttributes) { 100 PrincipalHRAttributes principalHRAttr = (PrincipalHRAttributes) pbo; 101 if (principalHRAttr != null) { 102 valid = true; 103 valid &= this.validatePrincipalId(principalHRAttr); 104 // KPME-1442 Kagata 105 //valid &= this.validateEffectiveDate(principalHRAttr); 106 valid &= this.validatePayCalendar(principalHRAttr); 107 valid &= this.validateLeaveCalendar(principalHRAttr); 108 valid &= this.validateLeavePlan(principalHRAttr); 109 valid &= this.validateServiceDate(principalHRAttr); 110 } 111 } 112 return valid; 113 } 114 115 }