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.position.validation;
017    
018    import java.sql.Date;
019    
020    import org.kuali.hr.time.position.Position;
021    import org.kuali.hr.time.service.base.TkServiceLocator;
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    
026    public class PositionValidation extends MaintenanceDocumentRuleBase {
027    
028            protected boolean validatePositionWorkarea(Position position) {
029                    
030                    boolean workAreaValidity = true;
031                    
032                    if (position.getWorkArea() != null) {
033                            Long WANumbr = position.getWorkArea();
034                            Date effDate = position.getEffectiveDate();
035    
036                            if (TkServiceLocator.getWorkAreaService().getWorkArea(WANumbr,
037                                            effDate) != null) {
038                                    return workAreaValidity;
039                            } else {
040                                    this.putFieldError("workArea", "pos.workArea.invalid",
041                                                    "work area '" + position.getWorkArea() + "'");
042                                    workAreaValidity = false;
043                            }
044                    }
045                    return workAreaValidity;
046            }
047    
048            @Override
049            protected boolean processCustomRouteDocumentBusinessRules(
050                            MaintenanceDocument document) {
051                    boolean valid = false;
052                    LOG.debug("entering custom validation for Position");
053                    PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
054    
055                    if (pbo instanceof Position) {
056                            Position position = (Position) pbo;
057                            if (position != null) {
058                                    valid = true;
059                                    valid &= this.validatePositionWorkarea(position);
060                            }
061                    }
062                    return valid;
063            }
064    }