View Javadoc
1   package org.kuali.ole.select.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.deliver.bo.OleDeliverRequestType;
5   import org.kuali.ole.select.bo.OLEMarcUpdateFrequency;
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   * Created by maheswarang on 5/12/15.
15   */
16  public class OLEMarcUpdateFrequencyRule extends MaintenanceDocumentRuleBase {
17  
18      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19          boolean isValid = true;
20          OLEMarcUpdateFrequency oleMarcUpdateFrequency = (OLEMarcUpdateFrequency) document.getNewMaintainableObject().getDataObject();
21  
22          isValid &= validateMarcUpdateFrequency(oleMarcUpdateFrequency);
23          return isValid;
24      }
25  
26      /**
27       * This method  validates duplicate completeness Id and return boolean value.
28       *
29       * @param oleMarcUpdateFrequency
30       * @return boolean
31       */
32      private boolean validateMarcUpdateFrequency(OLEMarcUpdateFrequency oleMarcUpdateFrequency) {
33  
34          if (oleMarcUpdateFrequency.getMarcUpdateFrequencyCode() != null) {
35              Map<String, String> criteria = new HashMap<String, String>();
36              criteria.put("marcUpdateFrequencyCode", oleMarcUpdateFrequency.getMarcUpdateFrequencyCode());
37              List<OLEMarcUpdateFrequency> oleMarcUpdateFrequencyCodeInDatabase = (List<OLEMarcUpdateFrequency>) getBoService().findMatching(OLEMarcUpdateFrequency.class, criteria);
38              if ((oleMarcUpdateFrequencyCodeInDatabase.size() > 0)) {
39                  for (OLEMarcUpdateFrequency oleMarcUpdateFrequencyOjb : oleMarcUpdateFrequencyCodeInDatabase) {
40                      if (null == oleMarcUpdateFrequencyOjb.getMarcUpdateFrequencyId() || (!oleMarcUpdateFrequency.getMarcUpdateFrequencyId().equals(oleMarcUpdateFrequencyOjb.getMarcUpdateFrequencyId()))) {
41                          this.putFieldError("marcUpdateFrequencyCode", "error.duplicate.code");
42                          return false;
43                      }
44                  }
45              }
46          }
47          return true;
48      }
49  
50  }