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 public class OleElectronicLocationAndAccessRelationshipRule extends MaintenanceDocumentRuleBase {
16
17 @Override
18 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19 boolean isValid = true;
20 OleElectronicLocationAndAccessRelationship oleElectronicLocationAndAccessRelationship = (OleElectronicLocationAndAccessRelationship) document.getNewMaintainableObject().getDataObject();
21
22 isValid &= validateElectronicLocationAndAccessRelationshipCode(oleElectronicLocationAndAccessRelationship);
23 return isValid;
24 }
25
26
27
28
29
30
31 private boolean validateElectronicLocationAndAccessRelationshipCode(OleElectronicLocationAndAccessRelationship oleElectronicLocationAndAccessRelationship) {
32
33 if (oleElectronicLocationAndAccessRelationship.getElaRelationshipCode() != null) {
34
35 Map<String, String> criteria = new HashMap<String, String>();
36
37 criteria.put(OLEConstants.OleElectronicLocationAndAccessRelationship.ELECTRONIC_LOCATION_AND_ACCESS_RELATIONSHIP_CD, oleElectronicLocationAndAccessRelationship.getElaRelationshipCode());
38
39
40 List<OleElectronicLocationAndAccessRelationship> electronicLocationAndAccessRelationshipInDatabase = (List<OleElectronicLocationAndAccessRelationship>) getBoService().findMatching(OleElectronicLocationAndAccessRelationship.class, criteria);
41
42 if ((electronicLocationAndAccessRelationshipInDatabase.size() > 0)) {
43 for(OleElectronicLocationAndAccessRelationship oleElAObject: electronicLocationAndAccessRelationshipInDatabase){
44 Integer elaRelationshipId = oleElAObject.getElaRelationshipId();
45 if(null==oleElectronicLocationAndAccessRelationship.getElaRelationshipId() || oleElectronicLocationAndAccessRelationship.getElaRelationshipId().intValue()!=elaRelationshipId){
46 this.putFieldError(OLEConstants.OleElectronicLocationAndAccessRelationship.ELECTRONIC_LOCATION_AND_ACCESS_RELATIONSHIP_CODE, "error.duplicate.code");
47 return false;
48 }
49 }
50 }
51 }
52
53 return true;
54 }
55 }