001    /**
002     * Copyright 2004-2012 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.kuali.hr.time.principal.PrincipalHRAttributes;
019    import org.kuali.hr.time.util.ValidationUtils;
020    import org.kuali.rice.kns.document.MaintenanceDocument;
021    import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
022    import org.kuali.rice.krad.bo.PersistableBusinessObject;
023    
024    public class PrincipalHRAttributesRule extends MaintenanceDocumentRuleBase {
025    
026            private boolean validatePrincipalId(PrincipalHRAttributes principalHRAttr) {
027                    if (principalHRAttr.getPrincipalId() != null
028                                    && !ValidationUtils.validatePrincipalId(principalHRAttr
029                                                    .getPrincipalId())) {
030                            this.putFieldError("principalId", "error.existence",
031                                            "principalId '" + principalHRAttr.getPrincipalId() + "'");
032                            return false;
033                    } else {
034                            return true;
035                    }
036            }
037            
038            private boolean validatePayCalendar(PrincipalHRAttributes principalHRAttr) {
039                    if (principalHRAttr.getPayCalendar() != null
040                                    && !ValidationUtils.validateCalendarByType(principalHRAttr.getPayCalendar(), "Pay")) {
041                            this.putFieldError("payCalendar", "error.existence",
042                                            "Pay Calendar '" + principalHRAttr.getPayCalendar() + "'");
043                            return false;
044                    } else {
045                            return true;
046                    }
047            }
048    
049            
050            boolean validateEffectiveDate(PrincipalHRAttributes principalHRAttr) {
051                    boolean valid = true;
052                    if (principalHRAttr.getEffectiveDate() != null && !ValidationUtils.validateOneYearFutureDate(principalHRAttr.getEffectiveDate())) {
053                            this.putFieldError("effectiveDate", "error.date.exceed.year", "Effective Date");
054                            valid = false;
055                    }
056                    return valid;
057            }
058            
059            @Override
060            protected boolean processCustomRouteDocumentBusinessRules(
061                            MaintenanceDocument document) {
062                    boolean valid = false;
063    
064                    LOG.debug("entering custom validation for Job");
065                    PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
066                    if (pbo instanceof PrincipalHRAttributes) {
067                            PrincipalHRAttributes principalHRAttr = (PrincipalHRAttributes) pbo;
068                            if (principalHRAttr != null) {
069                                    valid = true;
070                                    valid &= this.validatePrincipalId(principalHRAttr);
071                                    // KPME-1442 Kagata
072                                    //valid &= this.validateEffectiveDate(principalHRAttr);
073                                    valid &= this.validatePayCalendar(principalHRAttr);
074                            }
075                    }
076                    return valid;
077            }
078    
079    }