View Javadoc
1   package org.kuali.ole.select.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.select.bo.OleLicenseRequestLocation;
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 with IntelliJ IDEA.
14   * User: ?
15   * Date: 3/22/13
16   * Time: 12:36 PM
17   * To change this template use File | Settings | File Templates.
18   */
19  public class OleLicenseRequestLocationRule extends MaintenanceDocumentRuleBase {
20      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
21          boolean isValid = true;
22          OleLicenseRequestLocation oleLicenseRequestLocation = (OleLicenseRequestLocation) document.getNewMaintainableObject().getDataObject();
23  
24          isValid &= validateOleLicenseRequestLocation(oleLicenseRequestLocation);
25          return isValid;
26      }
27  
28      /**
29       * This method  validates duplicate Agreement Type Id and return boolean value.
30       *
31       * @param oleLicenseRequestLocation
32       * @return boolean
33       */
34      private boolean validateOleLicenseRequestLocation(OleLicenseRequestLocation oleLicenseRequestLocation) {
35  
36          if (oleLicenseRequestLocation.getName() != null) {
37              Map<String, String> criteria = new HashMap<String, String>();
38              criteria.put(OLEConstants.NAME, oleLicenseRequestLocation.getName());
39              List<OleLicenseRequestLocation> savedOleLicenseRequestLocation = (List<OleLicenseRequestLocation>) getBoService().findMatching(OleLicenseRequestLocation.class, criteria);
40              if ((savedOleLicenseRequestLocation.size() > 0)) {
41                  for (OleLicenseRequestLocation location : savedOleLicenseRequestLocation) {
42                      String licenseId = location.getId();
43                      if (null == oleLicenseRequestLocation.getId() || (!oleLicenseRequestLocation.getId().equalsIgnoreCase(licenseId))) {
44                          this.putFieldError(OLEConstants.NAME_FIELD, OLEConstants.ERROR_DUPLICATE_CODE);
45                          return false;
46                      }
47                  }
48              }
49          }
50          return true;
51      }
52  }