View Javadoc
1   package org.kuali.ole.select.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.select.bo.OLEPlatformStatus;
5   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
6   import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
7   import org.kuali.rice.krad.service.KRADServiceLocator;
8   import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
9   
10  import java.util.HashMap;
11  import java.util.List;
12  import java.util.Map;
13  
14  /**
15   * Created by chenchulakshmig on 9/16/14.
16   * OLEPlatformStatusRule validates maintenance object for Platform Status Maintenance Document
17   */
18  public class OLEPlatformStatusRule extends MaintenanceDocumentRuleBase {
19  
20      /**
21       * @param document
22       * @return boolean
23       */
24      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
25          boolean isValid = true;
26          OLEPlatformStatus olePlatformStatus = (OLEPlatformStatus) document.getNewMaintainableObject().getDataObject();
27          isValid &= validatePlatformStatusName(olePlatformStatus);
28          return isValid;
29      }
30  
31      /**
32       * * This method  validates duplicate platform status name and return boolean value.
33       *
34       * @param olePlatformStatus
35       * @return boolean
36       */
37      private boolean validatePlatformStatusName(OLEPlatformStatus olePlatformStatus) {
38          if (olePlatformStatus.getPlatformStatusName() != null) {
39              Map<String, String> criteria = new HashMap<String, String>();
40              criteria.put(OLEConstants.PLATFORM_STATUS_NAME, olePlatformStatus.getPlatformStatusName());
41              List<OLEPlatformStatus> authenticationMethodInDatabase = (List<OLEPlatformStatus>) KRADServiceLocator.getBusinessObjectService().findMatching(OLEPlatformStatus.class, criteria);
42              if ((authenticationMethodInDatabase.size() > 0)) {
43                  for (OLEPlatformStatus authenticationMethodObj : authenticationMethodInDatabase) {
44                      String platformStatusId = authenticationMethodObj.getPlatformStatusId();
45                      if (null == olePlatformStatus.getPlatformStatusId() || (!olePlatformStatus.getPlatformStatusId().equals(platformStatusId))) {
46                          this.putFieldError(OLEConstants.PLATFORM_STATUS_NAM_FIELD, OLEConstants.DUPLICATE);
47                          return false;
48                      }
49                  }
50              }
51          }
52          return true;
53      }
54  }