View Javadoc

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   * Created by IntelliJ IDEA.
14   * User: syedk
15   * Date: 6/11/12
16   * Time: 4:21 PM
17   * To change this template use File | Settings | File Templates.
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       *  This method  validates duplicate elaRelationship Id and return boolean value.
32       * @param oleElectronicLocationAndAccessRelationship
33       * @return boolean
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  }