1 package org.kuali.ole.catalog.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.catalog.bo.OleElectronicLocationAndAccessRelationship;
5 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
6 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
7
8 import java.util.HashMap;
9 import java.util.List;
10 import java.util.Map;
11
12
13
14
15
16
17
18
19 public class OleElectronicLocationAndAccessRelationshipRule extends MaintenanceDocumentRuleBase {
20
21 @Override
22 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
23 boolean isValid = true;
24 OleElectronicLocationAndAccessRelationship oleElectronicLocationAndAccessRelationship = (OleElectronicLocationAndAccessRelationship) document.getNewMaintainableObject().getDataObject();
25
26 isValid &= validateElectronicLocationAndAccessRelationshipCode(oleElectronicLocationAndAccessRelationship);
27 return isValid;
28 }
29
30
31
32
33
34
35 private boolean validateElectronicLocationAndAccessRelationshipCode(OleElectronicLocationAndAccessRelationship oleElectronicLocationAndAccessRelationship) {
36
37 if (oleElectronicLocationAndAccessRelationship.getElaRelationshipCode() != null) {
38
39 Map<String, String> criteria = new HashMap<String, String>();
40
41 criteria.put(OLEConstants.OleElectronicLocationAndAccessRelationship.ELECTRONIC_LOCATION_AND_ACCESS_RELATIONSHIP_CD, oleElectronicLocationAndAccessRelationship.getElaRelationshipCode());
42
43
44 List<OleElectronicLocationAndAccessRelationship> electronicLocationAndAccessRelationshipInDatabase = (List<OleElectronicLocationAndAccessRelationship>) getBoService().findMatching(OleElectronicLocationAndAccessRelationship.class, criteria);
45
46 if ((electronicLocationAndAccessRelationshipInDatabase.size() > 0)) {
47 for(OleElectronicLocationAndAccessRelationship oleElAObject: electronicLocationAndAccessRelationshipInDatabase){
48 Integer elaRelationshipId = oleElAObject.getElaRelationshipId();
49 if(null==oleElectronicLocationAndAccessRelationship.getElaRelationshipId() || oleElectronicLocationAndAccessRelationship.getElaRelationshipId().intValue()!=elaRelationshipId){
50 this.putFieldError(OLEConstants.OleElectronicLocationAndAccessRelationship.ELECTRONIC_LOCATION_AND_ACCESS_RELATIONSHIP_CODE, "error.duplicate.code");
51 return false;
52 }
53 }
54 }
55 }
56
57 return true;
58 }
59 }