1 package org.kuali.ole.select.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.select.bo.OlePurchaseOrderPurpose;
5 import org.kuali.rice.core.api.criteria.QueryByCriteria;
6 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
8 import org.kuali.rice.krad.service.KRADServiceLocator;
9
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13
14
15
16
17 public class OlePurchaseOrderPurposeRule extends MaintenanceDocumentRuleBase {
18
19
20 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
21 boolean isValid = true;
22 OlePurchaseOrderPurpose olePurchaseOrderPurpose = (org.kuali.ole.select.bo.OlePurchaseOrderPurpose) document.getNewMaintainableObject().getDataObject();
23
24 isValid &= validateOlePurposeCode(olePurchaseOrderPurpose, document);
25
26 return isValid;
27 }
28
29
30
31 private boolean validateOlePurposeCode(OlePurchaseOrderPurpose olePurchaseOrderPurpose, MaintenanceDocument document ) {
32
33 if (olePurchaseOrderPurpose.getPurchaseOrderPurposeCode() != null) {
34 Map<String, String> criteria = new HashMap<String, String>();
35 criteria.put(OLEConstants.OlePurchaseOrderPurpose.PURCHASE_ORDER_PURPOSE_CODE, olePurchaseOrderPurpose.getPurchaseOrderPurposeCode());
36 List<OlePurchaseOrderPurpose> savedOlePurchaseOrderPurpose = (List<OlePurchaseOrderPurpose>) KRADServiceLocator.getBusinessObjectService().findMatching(org.kuali.ole.select.bo.OlePurchaseOrderPurpose.class, criteria);
37 if ((savedOlePurchaseOrderPurpose.size() > 0)) {
38 for (org.kuali.ole.select.bo.OlePurchaseOrderPurpose purchaseOrderPurpose : savedOlePurchaseOrderPurpose) {
39 String purposeId = purchaseOrderPurpose.getPurchaseOrderPurposeId();
40 if (null == olePurchaseOrderPurpose.getPurchaseOrderPurposeId() || (!olePurchaseOrderPurpose.getPurchaseOrderPurposeId().equalsIgnoreCase(purposeId))) {
41 this.putFieldError(OLEConstants.OlePurchaseOrderPurpose.PURCHASE_ORDER_PURPOSE_CODE, OLEConstants.OlePurchaseOrderPurpose.ERROR_PURCHASE_ORDER_PURPOSE_CODE);
42 return false;
43 }
44 }
45 }
46 }
47 return true;
48 }
49 }
50
51
52