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.shiftdiff.rule.validation;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.hr.time.shiftdiff.rule.ShiftDifferentialRule;
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 ShiftDifferentialRuleRule extends MaintenanceDocumentRuleBase {
028
029 boolean validateSalGroup(ShiftDifferentialRule shiftDifferentialRule) {
030 if (shiftDifferentialRule.getHrSalGroup() != null
031 && !StringUtils.equals(shiftDifferentialRule.getHrSalGroup(),
032 TkConstants.WILDCARD_CHARACTER)
033 && !ValidationUtils.validateSalGroup(shiftDifferentialRule
034 .getHrSalGroup(), shiftDifferentialRule
035 .getEffectiveDate())) {
036 this.putFieldError("hrSalGroup", "error.existence", "Salgroup '"
037 + shiftDifferentialRule.getHrSalGroup() + "'");
038 return false;
039 } else {
040 return true;
041 }
042 }
043
044 boolean validateEarnCode(ShiftDifferentialRule shiftDifferentialRule) {
045 if (shiftDifferentialRule.getEarnCode() != null
046 && !ValidationUtils.validateEarnCode(shiftDifferentialRule
047 .getEarnCode(), shiftDifferentialRule
048 .getEffectiveDate())) {
049 this.putFieldError("earnCode", "error.existence", "earnCode '"
050 + shiftDifferentialRule.getEarnCode() + "'");
051 return false;
052 } else {
053 return true;
054 }
055 }
056
057 boolean validateLocation(ShiftDifferentialRule shiftDifferentialRule) {
058 if (shiftDifferentialRule.getLocation() != null
059 && !StringUtils.equals(shiftDifferentialRule.getLocation(),
060 TkConstants.WILDCARD_CHARACTER)
061 && !ValidationUtils.validateLocation(shiftDifferentialRule
062 .getLocation(), shiftDifferentialRule
063 .getEffectiveDate())) {
064 this.putFieldError("location", "error.existence", "location '"
065 + shiftDifferentialRule.getLocation() + "'");
066 return false;
067 } else {
068 return true;
069 }
070 }
071
072 boolean validatePayGrade(ShiftDifferentialRule shiftDifferentialRule) {
073 if (shiftDifferentialRule.getPayGrade() != null
074 && !StringUtils.equals(shiftDifferentialRule.getPayGrade(),
075 TkConstants.WILDCARD_CHARACTER)
076 && !ValidationUtils.validatePayGrade(shiftDifferentialRule
077 .getPayGrade(), shiftDifferentialRule.getHrSalGroup(), shiftDifferentialRule
078 .getEffectiveDate())) {
079 this.putFieldError("payGrade", "error.existence", "pay grade '"
080 + shiftDifferentialRule.getPayGrade() + "'");
081 return false;
082 } else {
083 return true;
084 }
085 }
086
087 /**
088 * It looks like the method that calls this class doesn't actually care
089 * about the return type.
090 */
091 @Override
092 protected boolean processCustomRouteDocumentBusinessRules(
093 MaintenanceDocument document) {
094 boolean valid = false;
095 LOG.debug("entering custom validation for TimeCollectionRule");
096 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
097 if (pbo instanceof ShiftDifferentialRule) {
098 ShiftDifferentialRule shiftDifferentialRule = (ShiftDifferentialRule) pbo;
099 shiftDifferentialRule.setUserPrincipalId(GlobalVariables
100 .getUserSession().getLoggedInUserPrincipalName());
101 if (shiftDifferentialRule != null) {
102 valid = true;
103 valid &= this.validateLocation(shiftDifferentialRule);
104 valid &= this.validateSalGroup(shiftDifferentialRule);
105 valid &= this.validatePayGrade(shiftDifferentialRule);
106 valid &= this.validateEarnCode(shiftDifferentialRule);
107 }
108 }
109
110 return valid;
111 }
112
113 }