View Javadoc
1   package org.kuali.ole.describe.rule;
2   
3   import org.kuali.ole.describe.bo.OleLocationStatus;
4   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
5   import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
6   
7   import java.util.HashMap;
8   import java.util.List;
9   import java.util.Map;
10  
11  /**
12   * OleLocationStatusRule validates maintenance object for Location Status Maintenance Document
13   */
14  public class OleLocationStatusRule extends MaintenanceDocumentRuleBase {
15  
16      /**
17       * @param document
18       * @return
19       */
20  
21      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
22          boolean isValid = true;
23          OleLocationStatus oleLocationStatus = (OleLocationStatus) document.getNewMaintainableObject().getDataObject();
24  
25          isValid &= validateLocationStatusCode(oleLocationStatus);
26          return isValid;
27      }
28  
29      /**
30       * This method  validates duplicate locationStatus Id and return boolean value.
31       *
32       * @param oleLocationStatus
33       * @return boolean
34       */
35      private boolean validateLocationStatusCode(OleLocationStatus oleLocationStatus) {
36  
37          if (oleLocationStatus.getLocationStatusCode() != null) {
38  
39              Map<String, String> criteria = new HashMap<String, String>();
40  
41              //    criteria.put(OLEConstants.OleLocationStatus.LOCATION_STATUS_CD, oleLocationStatus.getLocationStatusCode());
42  
43              List<OleLocationStatus> locationStatusCodeInDatabase = (List<OleLocationStatus>) getBoService().findMatching(OleLocationStatus.class, criteria);
44  
45              if ((locationStatusCodeInDatabase.size() > 0)) {
46  
47                  for (OleLocationStatus locationStatusObj : locationStatusCodeInDatabase) {
48                      String locationStatusId = locationStatusObj.getLocationStatusId();
49                      if (null == oleLocationStatus.getLocationStatusId() ||
50                              !(oleLocationStatus.getLocationStatusId().equalsIgnoreCase(locationStatusId))) {
51                          //         this.putFieldError(OLEConstants.OleLocationStatus.LOCATION_STATUS_CODE, "error.duplicate.code");
52                          return false;
53                      }
54                  }
55              }
56              return true;
57          }
58          return false;
59      }
60  }