View Javadoc
1   package org.kuali.ole.describe.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.describe.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   * OleElectronicLocationAndAccessRelationshipRule validates maintenance object for Electronic Location And Access Relationship Maintenance Document
14   */
15  public class OleElectronicLocationAndAccessRelationshipRule extends MaintenanceDocumentRuleBase {
16  
17  
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       * This method  validates duplicate elaRelationship Id and return boolean value.
28       *
29       * @param oleElectronicLocationAndAccessRelationship
30       *
31       * @return boolean
32       */
33      private boolean validateElectronicLocationAndAccessRelationshipCode(OleElectronicLocationAndAccessRelationship oleElectronicLocationAndAccessRelationship) {
34  
35          if (oleElectronicLocationAndAccessRelationship.getElaRelationshipCode() != null) {
36  
37              Map<String, String> criteria = new HashMap<String, String>();
38  
39              criteria.put(OLEConstants.OleElectronicLocationAndAccessRelationship.ELECTRONIC_LOCATION_AND_ACCESS_RELATIONSHIP_CD, oleElectronicLocationAndAccessRelationship.getElaRelationshipCode());
40  
41  
42              List<OleElectronicLocationAndAccessRelationship> electronicLocationAndAccessRelationshipInDatabase = (List<OleElectronicLocationAndAccessRelationship>) getBoService().findMatching(OleElectronicLocationAndAccessRelationship.class, criteria);
43  
44              if ((electronicLocationAndAccessRelationshipInDatabase.size() > 0)) {
45                  for (OleElectronicLocationAndAccessRelationship oleElAObject : electronicLocationAndAccessRelationshipInDatabase) {
46                      Integer elaRelationshipId = oleElAObject.getElaRelationshipId();
47                      if (null == oleElectronicLocationAndAccessRelationship.getElaRelationshipId() || oleElectronicLocationAndAccessRelationship.getElaRelationshipId().intValue() != elaRelationshipId) {
48                          this.putFieldError(OLEConstants.OleElectronicLocationAndAccessRelationship.ELECTRONIC_LOCATION_AND_ACCESS_RELATIONSHIP_CODE, "error.duplicate.code");
49                          return false;
50                      }
51                  }
52              }
53          }
54  
55          return true;
56      }
57  }