View Javadoc

1   package org.kuali.ole.batch.rule;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.batch.bo.OLEBatchProcessProfileBo;
6   import org.kuali.ole.batch.bo.OLEBatchProcessProfileConstantsBo;
7   import org.kuali.ole.batch.bo.OLEBatchProcessProfileDataMappingOptionsBo;
8   import org.kuali.ole.batch.bo.OLEBatchProcessProfileMappingOptionsBo;
9   import org.kuali.ole.select.bo.OleAgreementMethod;
10  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
11  import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
12  import org.kuali.rice.krad.util.GlobalVariables;
13  import org.kuali.rice.krad.util.KRADConstants;
14  
15  import java.util.*;
16  
17  /**
18   * Created with IntelliJ IDEA.
19   * User: ?
20   * Date: 3/21/13
21   * Time: 1:16 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  public class OleBatchProcessProfileRule extends MaintenanceDocumentRuleBase {
25  
26      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
27          boolean isValid = true;
28          OLEBatchProcessProfileBo oleBatchProcessProfileBo = (OLEBatchProcessProfileBo) document.getNewMaintainableObject().getDataObject();
29          if (oleBatchProcessProfileBo.getBatchProcessProfileType().equalsIgnoreCase("Order Record Import")) {
30              if(oleBatchProcessProfileBo.getMarcOnly()){
31                  isValid &= validateForOrderRecordImport(oleBatchProcessProfileBo);
32              }
33          }
34          return isValid;
35      }
36  
37      /**
38       * This method  validates duplicate Agreement Method Id and return boolean value.
39       *
40       * @param
41       * @return boolean
42       */
43      private boolean validateForOrderRecordImport(OLEBatchProcessProfileBo oleBatchProcessProfileBo) {
44          Set<String> mandatoryFields = new HashSet<>();
45          List<OLEBatchProcessProfileMappingOptionsBo> oleBatchProcessProfileMappingOptionsBoList = oleBatchProcessProfileBo.getOleBatchProcessProfileMappingOptionsList();
46          for (OLEBatchProcessProfileMappingOptionsBo oleBatchProcessProfileMappingOptionsBo : oleBatchProcessProfileMappingOptionsBoList) {
47              List<OLEBatchProcessProfileDataMappingOptionsBo> oleBatchProcessProfileDataMappingOptionsBoList = oleBatchProcessProfileMappingOptionsBo.getOleBatchProcessProfileDataMappingOptionsBoList();
48              for (int dataMapCount = 0;dataMapCount<oleBatchProcessProfileDataMappingOptionsBoList.size();dataMapCount++) {
49                  if (StringUtils.isNotBlank(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDataType()) && StringUtils.isNotBlank(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDataTypeDestinationField()) &&
50                          StringUtils.isNotBlank(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getSourceField()) && StringUtils.isNotBlank(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
51                      if(OLEConstants.OLEBatchProcess.LIST_PRICE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
52                          mandatoryFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
53                      }
54                      else if(OLEConstants.OLEBatchProcess.FUND_CODE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
55                          mandatoryFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
56                      }
57                      else if(OLEConstants.OLEBatchProcess.VENDOR_NUMBER.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
58                          mandatoryFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
59                      }
60                      else if(OLEConstants.OLEBatchProcess.QUANTITY.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
61                          mandatoryFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
62                      }
63                  }
64              }
65          }
66          List<OLEBatchProcessProfileConstantsBo> oleBatchProcessProfileConstantsBoList = oleBatchProcessProfileBo.getOleBatchProcessProfileConstantsList();
67          for (OLEBatchProcessProfileConstantsBo oleBatchProcessProfileConstantsBo : oleBatchProcessProfileConstantsBoList) {
68              if (StringUtils.isNotBlank(oleBatchProcessProfileConstantsBo.getDataType()) && OLEConstants.OLEBatchProcess.ORDER_IMPORT.equalsIgnoreCase(oleBatchProcessProfileConstantsBo.getDataType())
69                      && StringUtils.isNotBlank(oleBatchProcessProfileConstantsBo.getAttributeValue()) && StringUtils.isNotBlank(oleBatchProcessProfileConstantsBo.getAttributeName())) {
70                  for(int constantCount = 0;constantCount < oleBatchProcessProfileConstantsBoList.size();constantCount++ )  {
71                      if(OLEConstants.OLEBatchProcess.LIST_PRICE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
72                          mandatoryFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
73                      }
74                      else if(OLEConstants.OLEBatchProcess.FUND_CODE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
75                          mandatoryFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
76                      }
77                      else if(OLEConstants.OLEBatchProcess.VENDOR_NUMBER.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
78                          mandatoryFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
79                      }
80                      else if(OLEConstants.OLEBatchProcess.QUANTITY.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
81                          mandatoryFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
82                      }
83                  }
84              }
85          }
86          if(mandatoryFields.size() == 4){
87              return true;
88          }
89          else {
90              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.MANDATORY_VALUES_FOR_ORDER_RECORD_IMPORT);
91          }
92          return false;
93      }
94  
95  }