View Javadoc
1   package org.kuali.ole.select.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.select.bo.OleSubscriptionStatus;
5   import org.kuali.rice.core.api.criteria.QueryByCriteria;
6   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7   import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
8   import org.kuali.rice.krad.service.KRADServiceLocator;
9   
10  import java.util.HashMap;
11  import java.util.List;
12  import java.util.Map;
13  
14  /**
15   * Created by jating on 24/9/14.
16   * To add additional rules for the Subscription Status Maintenance Document
17   */
18  public class OleSubscriptionStatusRule extends MaintenanceDocumentRuleBase {
19  
20  
21          protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
22              boolean isValid = true;
23              OleSubscriptionStatus oleSubscriptionStatus = (OleSubscriptionStatus) document.getNewMaintainableObject().getDataObject();
24  
25              isValid &= validateOlePurposeCode(oleSubscriptionStatus, document);
26  
27              return isValid;
28          }
29  
30  
31  
32      /**
33       * To validate duplicate values for the field SubscriptionStatusCode
34       *
35       * @param oleSubscriptionStatus
36       * @param document
37       * @return
38       */
39          private boolean validateOlePurposeCode(OleSubscriptionStatus oleSubscriptionStatus, MaintenanceDocument document ) {
40  
41                  if (oleSubscriptionStatus.getSubscriptionStatusCode() != null) {
42                  Map<String, String> criteria = new HashMap<String, String>();
43                  criteria.put(OLEConstants.OleSubscriptionStatus.SUBSCRIPTION_STATUS_CODE, oleSubscriptionStatus.getSubscriptionStatusCode());
44                  List<OleSubscriptionStatus> savedOleSubscriptionStatus = (List<OleSubscriptionStatus>) KRADServiceLocator.getDataObjectService().findMatching(OleSubscriptionStatus.class, QueryByCriteria.Builder.andAttributes(criteria).build()).getResults();
45                  if ((savedOleSubscriptionStatus.size() > 0)) {
46                      for (OleSubscriptionStatus subscriptionStatus : savedOleSubscriptionStatus) {
47                          String purposeId = subscriptionStatus.getSubscriptionStatusId();
48                          if (null == oleSubscriptionStatus.getSubscriptionStatusId() || (!oleSubscriptionStatus.getSubscriptionStatusId().equalsIgnoreCase(purposeId))) {//
49                              this.putFieldError(OLEConstants.OleSubscriptionStatus.SUBSCRIPTION_STATUS_CODE, OLEConstants.OleSubscriptionStatus.ERROR_SUBSCRIPTION_STATUS_CODE);
50                              return false;
51                          }
52                      }
53                  }
54              }
55              return true;
56          }
57      }
58  
59  
60