1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.position.validation;
17
18 import java.math.BigDecimal;
19
20 import org.apache.commons.collections.CollectionUtils;
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.kpme.core.util.ValidationUtils;
23 import org.kuali.kpme.pm.classification.Classification;
24 import org.kuali.kpme.pm.classification.duty.ClassificationDuty;
25 import org.kuali.kpme.pm.position.Position;
26 import org.kuali.kpme.pm.position.PositionDuty;
27 import org.kuali.kpme.pm.position.funding.PositionFunding;
28 import org.kuali.rice.krad.bo.PersistableBusinessObject;
29 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
30 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
31 import org.kuali.rice.krad.util.GlobalVariables;
32 import org.kuali.rice.krad.util.KRADConstants;
33 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
34
35 public class PositionValidation extends MaintenanceDocumentRuleBase {
36 @Override
37 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
38 boolean valid = false;
39 LOG.debug("entering custom validation for Position");
40 Position aPosition = (Position) this.getNewDataObject();
41
42 if (aPosition != null) {
43 valid = true;
44 valid &= this.validateDutyListPercentage(aPosition);
45 }
46 return valid;
47 }
48
49 private boolean validateDutyListPercentage(Position aPosition) {
50 if(CollectionUtils.isNotEmpty(aPosition.getDutyList())) {
51 BigDecimal sum = BigDecimal.ZERO;
52 for(PositionDuty aDuty : aPosition.getDutyList()) {
53 if(aDuty != null && aDuty.getPercentage() != null) {
54 sum = sum.add(aDuty.getPercentage());
55 }
56 }
57 if(sum.compareTo(new BigDecimal(100)) > 0) {
58 String[] parameters = new String[1];
59 parameters[0] = sum.toString();
60 this.putFieldError("dataObject.dutyList", "duty.percentage.exceedsMaximum", parameters);
61 return false;
62 }
63 }
64 return true;
65 }
66
67 }