View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.pm.positionappointment.validation;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.kpme.core.util.ValidationUtils;
20  import org.kuali.kpme.pm.positionappointment.PositionAppointment;
21  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
22  import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
23  
24  public class PositionAppointmentValidation extends MaintenanceDocumentRuleBase {
25  
26  	@Override
27  	protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
28  		boolean valid = false;
29  		LOG.debug("entering custom validation for position appointment");
30  		PositionAppointment pa = (PositionAppointment) this.getNewDataObject();
31  		
32  		if (pa != null) {
33  			valid = true;
34  			valid &= this.validateInstitution(pa);
35  			valid &= this.validateLocation(pa);
36  		}
37  		return valid;
38  	}
39  	
40  	private boolean validateInstitution(PositionAppointment pa) {
41  		if (StringUtils.isNotEmpty(pa.getInstitution()) && !ValidationUtils.validateInstitution(pa.getInstitution(), pa.getEffectiveLocalDate())) {
42  			this.putFieldError("dataObject.institution", "error.existence", "Instituion '" + pa.getInstitution() + "'");
43  			return false;
44  		} else {
45  			return true;
46  		}
47  	}
48  	
49  	private boolean validateLocation(PositionAppointment pa) {
50  		if (StringUtils.isNotEmpty(pa.getLocation()) && !ValidationUtils.validateLocation(pa.getLocation(), pa.getEffectiveLocalDate())) {
51  			this.putFieldError("dataObject.location", "error.existence", "Location '" + pa.getLocation() + "'");
52  			return false;
53  		} else {
54  			return true;
55  		}
56  	}
57  	
58  }