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