View Javadoc

1   package org.kuali.ole.catalog.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.catalog.bo.OleCountryCodes;
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: meenau
15   * Date: 6/11/12
16   * Time: 3:59 PM
17   * To change this template use File | Settings | File Templates.
18   */
19  public class OleCountryCodesRule extends MaintenanceDocumentRuleBase {
20  
21      @Override
22      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
23          boolean isValid = true;
24          OleCountryCodes oleCountryCodes = (OleCountryCodes) document.getNewMaintainableObject().getDataObject();
25  
26          isValid &= validateCountryCode(oleCountryCodes);
27          return isValid;
28      }
29  
30      private boolean validateCountryCode(OleCountryCodes oleCountryCodes) {
31  
32          if (oleCountryCodes.getCountryCode() != null) {
33  
34              Map<String, String> criteria = new HashMap<String, String>();
35  
36              criteria.put("countryCode", oleCountryCodes.getCountryCode());
37  
38  
39              List<OleCountryCodes> countryCodeInDatabase = (List<OleCountryCodes>) getBoService().findMatching(OleCountryCodes.class, criteria);
40  
41              if ((countryCodeInDatabase.size() > 0)) {
42                  if(null==oleCountryCodes.getCountryCodeId()){
43                      this.putFieldError(OLEConstants.OleCountryCodes.COUNTRY_CODE, "error.duplicate.code");
44                      return false;
45                  }
46              }
47          }
48  
49          return true;
50      }
51  }