View Javadoc
1   package org.kuali.ole.describe.rule;
2   
3   
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.describe.bo.OleAcquisitionMethod;
6   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7   import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
8   
9   import java.util.HashMap;
10  import java.util.List;
11  import java.util.Map;
12  
13  /**
14   * OleAcquisitionMethodsRule validates maintenance object for Acquisition Method Maintenance Document
15   */
16  public class OleAcquisitionMethodsRule extends MaintenanceDocumentRuleBase {
17  
18  
19      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
20          boolean isValid = true;
21          OleAcquisitionMethod acquisitionMethod = (OleAcquisitionMethod) document.getNewMaintainableObject().getDataObject();
22  
23          isValid &= validateAcquisitionCodeMethod(acquisitionMethod);
24          return isValid;
25      }
26  
27      /**
28       * This method  validates duplicate acquisitionMethod Id and return boolean value.
29       *
30       * @param acquisitionMethod
31       * @return boolean
32       */
33      private boolean validateAcquisitionCodeMethod(OleAcquisitionMethod acquisitionMethod) {
34  
35          if (acquisitionMethod.getAcquisitionMethodCode() != null) {
36              Map<String, String> criteria = new HashMap<String, String>();
37              criteria.put(OLEConstants.OleAcquisitionMethod.ACQUISITION_METHOD_CD, acquisitionMethod.getAcquisitionMethodCode());
38              List<OleAcquisitionMethod> acquisitionMethodInDatabase = (List<OleAcquisitionMethod>) getBoService().findMatching(OleAcquisitionMethod.class, criteria);
39              if ((acquisitionMethodInDatabase.size() > 0)) {
40                  for (OleAcquisitionMethod acquisitionObj : acquisitionMethodInDatabase) {
41                      Integer acquisitionMethodId = acquisitionObj.getAcquisitionMethodId();
42                      if (null == acquisitionMethod.getAcquisitionMethodId() || (acquisitionMethod.getAcquisitionMethodId().intValue() != acquisitionMethodId.intValue())) {
43                          this.putFieldError(OLEConstants.OleAcquisitionMethod.ACQUISITION_METHOD_CODE, "error.duplicate.code");
44                          return false;
45                      }
46                  }
47              }
48          }
49          return true;
50      }
51  }