View Javadoc

1   /**
2    * Copyright 2004-2013 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.tklm.time.rules.timecollection.validation;
17  
18  import org.apache.cxf.common.util.StringUtils;
19  import org.kuali.kpme.core.util.HrConstants;
20  import org.kuali.kpme.core.util.ValidationUtils;
21  import org.kuali.kpme.tklm.time.rules.timecollection.TimeCollectionRule;
22  import org.kuali.rice.kns.document.MaintenanceDocument;
23  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
24  import org.kuali.rice.krad.bo.PersistableBusinessObject;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  public class TimeCollectionRuleValidation extends MaintenanceDocumentRuleBase {
28  
29  	boolean validateWorkArea(TimeCollectionRule ruleObj) {
30  		if (!ValidationUtils.validateWorkArea(ruleObj.getWorkArea(), ruleObj.getDept(), ruleObj.getEffectiveLocalDate())) {
31  			this.putFieldError("workArea", "error.existence", "workarea '" + ruleObj.getWorkArea() + "'");
32  			return false;
33  		} else {
34  			return true;
35  		}
36  	}
37  
38  	boolean validateDepartment(TimeCollectionRule ruleObj) {
39  		if (!ValidationUtils.validateDepartment(ruleObj.getDept(), ruleObj.getEffectiveLocalDate())) {
40  			this.putFieldError("dept", "error.existence", "department '" + ruleObj.getDept() + "'");
41  			return false;
42  		} else {
43  			return true;
44  		}
45  	}
46  	
47  	// JIRA1152
48  	boolean validatePayType(TimeCollectionRule ruleObj) {
49  		if(!StringUtils.isEmpty(ruleObj.getPayType()) && ruleObj.getPayType().equals(HrConstants.WILDCARD_CHARACTER)) {
50  			return true;
51  		}		
52  		if (!ValidationUtils.validatePayType(ruleObj.getPayType(), ruleObj.getEffectiveLocalDate())) {
53  			this.putFieldError("payType", "error.existence", "payType '" + ruleObj.getPayType() + "'");
54  			return false;
55  		} else {
56  			return true;
57  		}
58  	}
59  
60  	/**
61  	 * It looks like the method that calls this class doesn't actually care
62  	 * about the return type.
63  	 */
64  	@Override
65  	protected boolean processCustomRouteDocumentBusinessRules(
66  			MaintenanceDocument document) {
67  		boolean valid = false;
68  		LOG.debug("entering custom validation for TimeCollectionRule");
69  		PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
70  
71  
72  
73  		if (pbo instanceof TimeCollectionRule) {
74  			TimeCollectionRule timeCollectionRule = (TimeCollectionRule) pbo;
75  			timeCollectionRule.setUserPrincipalId(GlobalVariables.getUserSession().getLoggedInUserPrincipalName());
76  			if (timeCollectionRule != null) {
77  				valid = true;
78  				valid &= this.validateDepartment(timeCollectionRule);
79  				valid &= this.validateWorkArea(timeCollectionRule);
80  				valid &= this.validatePayType(timeCollectionRule);
81  			}
82  		}
83  
84  		return valid;
85  	}
86  
87  }