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.collection.rule.validation; 017 018 import org.apache.cxf.common.util.StringUtils; 019 import org.kuali.hr.time.collection.rule.TimeCollectionRule; 020 import org.kuali.hr.time.util.TkConstants; 021 import org.kuali.hr.time.util.ValidationUtils; 022 import org.kuali.rice.kns.document.MaintenanceDocument; 023 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; 024 import org.kuali.rice.krad.bo.PersistableBusinessObject; 025 import org.kuali.rice.krad.util.GlobalVariables; 026 027 public class TimeCollectionRuleRule extends MaintenanceDocumentRuleBase { 028 029 boolean validateWorkArea(TimeCollectionRule ruleObj) { 030 if (!ValidationUtils.validateWorkArea(ruleObj.getWorkArea(), ruleObj.getDept(), ruleObj.getEffectiveDate())) { 031 this.putFieldError("workArea", "error.existence", "workarea '" + ruleObj.getWorkArea() + "'"); 032 return false; 033 } else { 034 return true; 035 } 036 } 037 038 boolean validateDepartment(TimeCollectionRule ruleObj) { 039 if (!ValidationUtils.validateDepartment(ruleObj.getDept(), ruleObj.getEffectiveDate())) { 040 this.putFieldError("dept", "error.existence", "department '" + ruleObj.getDept() + "'"); 041 return false; 042 } else { 043 return true; 044 } 045 } 046 047 // JIRA1152 048 boolean validatePayType(TimeCollectionRule ruleObj) { 049 if(!StringUtils.isEmpty(ruleObj.getPayType()) && ruleObj.getPayType().equals(TkConstants.WILDCARD_CHARACTER)) { 050 return true; 051 } 052 if (!ValidationUtils.validatePayType(ruleObj.getPayType(), ruleObj.getEffectiveDate())) { 053 this.putFieldError("payType", "error.existence", "payType '" + ruleObj.getPayType() + "'"); 054 return false; 055 } else { 056 return true; 057 } 058 } 059 060 boolean validateClockUserAndHrsDistFlags(TimeCollectionRule ruleObj) { 061 if (!ruleObj.isClockUserFl() && ruleObj.isHrsDistributionF()) { 062 this.putFieldError("hrsDistributionF", "timecollRule.hrDistribution.invalid"); 063 return false; 064 } 065 return true; 066 } 067 068 /** 069 * It looks like the method that calls this class doesn't actually care 070 * about the return type. 071 */ 072 @Override 073 protected boolean processCustomRouteDocumentBusinessRules( 074 MaintenanceDocument document) { 075 boolean valid = false; 076 LOG.debug("entering custom validation for TimeCollectionRule"); 077 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo(); 078 079 080 081 if (pbo instanceof TimeCollectionRule) { 082 TimeCollectionRule timeCollectionRule = (TimeCollectionRule) pbo; 083 timeCollectionRule.setUserPrincipalId(GlobalVariables.getUserSession().getLoggedInUserPrincipalName()); 084 if (timeCollectionRule != null) { 085 valid = true; 086 valid &= this.validateDepartment(timeCollectionRule); 087 valid &= this.validateWorkArea(timeCollectionRule); 088 valid &= this.validatePayType(timeCollectionRule); 089 valid &= this.validateClockUserAndHrsDistFlags(timeCollectionRule); 090 } 091 } 092 093 return valid; 094 } 095 096 }