1 package org.kuali.ole.select.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.select.bo.OLEDonor;
5 import org.kuali.ole.select.bo.OLEPaymentType;
6 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
8 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
9 import org.kuali.rice.krad.service.LookupService;
10
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14
15
16
17
18
19
20
21
22 public class OLEDonorRule extends MaintenanceDocumentRuleBase {
23
24 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
25 boolean isValid = true;
26 OLEDonor oleDonor = (OLEDonor) document.getNewMaintainableObject().getDataObject();
27 isValid &= validateDonorCode(oleDonor);
28 return isValid;
29 }
30
31 private boolean validateDonorCode(OLEDonor oleDonor) {
32 if (oleDonor.getDonorCode() != null) {
33 Map<String, String> criteria = new HashMap<String, String>();
34 criteria.put(OLEConstants.DONOR_CODE, oleDonor.getDonorCode());
35 List<OLEDonor> oleDonorList = (List<OLEDonor>) getLookupService().findCollectionBySearch(OLEDonor.class, criteria);
36 if ((oleDonorList.size() > 0)) {
37 for (OLEDonor donor : oleDonorList) {
38 String donorId = donor.getDonorId();
39 if (null == oleDonor.getDonorId() || (!oleDonor.getDonorId().equalsIgnoreCase(donorId))) {
40 this.putFieldError(OLEConstants.DONOR_CODE_FIELD, OLEConstants.ERROR_DONOR_CODE);
41 return false;
42 }
43 }
44 }
45 }
46 return true;
47 }
48
49 private LookupService getLookupService() {
50 return KRADServiceLocatorWeb.getLookupService();
51 }
52 }