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.positionreportgroup.validation;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.kpme.core.util.ValidationUtils;
20  import org.kuali.kpme.pm.positionreportgroup.PositionReportGroup;
21  import org.kuali.rice.kns.document.MaintenanceDocument;
22  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
23  
24  @SuppressWarnings("deprecation")
25  public class PositionReportGroupValidation extends MaintenanceDocumentRuleBase  {
26  	@Override
27  	protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
28  		boolean valid = false;
29  		LOG.debug("entering custom validation for Position Report Group");
30  		PositionReportGroup prg = (PositionReportGroup) this.getNewBo();
31  		
32  		if (prg != null) {
33  			valid = true;
34  			valid &= this.validateInstitution(prg);
35  			valid &= this.validateLocation(prg);
36  		}
37  		return valid;
38  	}
39  	
40  	private boolean validateInstitution(PositionReportGroup prg) {
41  		if (StringUtils.isNotEmpty(prg.getInstitution())
42  				&& !ValidationUtils.validateInstitution(prg.getInstitution(), prg.getEffectiveLocalDate())) {
43  			this.putFieldError("institution", "error.existence", "Instituion '"
44  					+ prg.getInstitution() + "'");
45  			return false;
46  		} else {
47  			return true;
48  		}
49  	}
50  	
51  	private boolean validateLocation(PositionReportGroup prg) {
52  		if (StringUtils.isNotEmpty(prg.getLocation())
53  				&& !ValidationUtils.validateLocation(prg.getLocation(), prg.getEffectiveLocalDate())) {
54  			this.putFieldError("location", "error.existence", "Location '"
55  					+ prg.getLocation() + "'");
56  			return false;
57  		} else {
58  			return true;
59  		}
60  	}
61  }