View Javadoc
1   package org.kuali.ole.describe.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.deliver.bo.OleCirculationDesk;
5   import org.kuali.ole.deliver.bo.OleCirculationDeskDetail;
6   import org.kuali.ole.describe.bo.OleDiscoveryExportMappingFields;
7   import org.kuali.ole.describe.bo.OleDiscoveryExportProfile;
8   import org.kuali.ole.describe.bo.OleLocation;
9   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
10  import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
11  
12  import java.util.ArrayList;
13  import java.util.HashMap;
14  import java.util.List;
15  import java.util.Map;
16  
17  /**
18   * Created with IntelliJ IDEA.
19   * User: ?
20   * Date: 2/8/13
21   * Time: 3:09 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  public class OleDiscoveryExportProfileRule extends MaintenanceDocumentRuleBase {
25  
26      /**
27       * This method validates the duplicate entry in ITEm and MARC field
28       *
29       * @param document
30       * @return boolean
31       */
32  
33      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
34          boolean isValid = true;
35          OleDiscoveryExportProfile oleDiscoveryExportProfile = (OleDiscoveryExportProfile) document.getNewMaintainableObject().getDataObject();
36          isValid &= validateForDuplicateMARCField(oleDiscoveryExportProfile);
37          isValid &= validateForDuplicateItemField(oleDiscoveryExportProfile);
38          return isValid;
39      }
40  
41      /**
42       * This method restrict the MARC Field duplicate values and restrict the document to submit without adding an item
43       *
44       * @param oleDiscoveryExportProfile
45       * @return true if there is no duplication in the MARC Field value and there should be atleast one item added to the document otherwise return false
46       */
47      private boolean validateForDuplicateMARCField(OleDiscoveryExportProfile oleDiscoveryExportProfile) {
48          List<String> MARCItemlist = new ArrayList<String>();
49          if (oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields() == null || oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size() == 0) {
50              this.putFieldError(OLEConstants.OleDiscoveryExportProfile.OLE_EXP_ADD_ITEM, OLEConstants.OleDiscoveryExportProfile.OLE_EXP_ADD_ITEM_ERROR);
51              return false;
52          }
53          for (int i = 0; i < oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size(); i++) {
54              MARCItemlist.add(oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().get(i).getMarcField());
55          }
56          for (int j = 0; j < oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size(); j++) {
57              int count = 0;
58              for (int k = 0; k < MARCItemlist.size(); k++) {
59                  if (oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().get(j).getMarcField().equalsIgnoreCase(MARCItemlist.get(k))) {
60                      count++;
61                  }
62              }
63              if (count > 1) {
64                  this.putFieldError(OLEConstants.OleDiscoveryExportProfile.OLE_EXP_MARC_FIELD, OLEConstants.OleDiscoveryExportProfile.OLE_EXP_MARC_DUPLICATE_ERROR);
65                  return false;
66              }
67          }
68          return true;
69      }
70  
71      /**
72       * This method restrict the Item Field duplicate values
73       *
74       * @param oleDiscoveryExportProfile
75       * @return true if there is no duplication in the Item Field value otherwise return false
76       */
77      private boolean validateForDuplicateItemField(OleDiscoveryExportProfile oleDiscoveryExportProfile) {
78          List<String> MARCItemlist = new ArrayList<String>();
79          for (int i = 0; i < oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size(); i++) {
80              MARCItemlist.add(oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().get(i).getItemField());
81          }
82          for (int j = 0; j < oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size(); j++) {
83              int count = 0;
84              for (int k = 0; k < MARCItemlist.size(); k++) {
85                  if (oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().get(j).getItemField().equalsIgnoreCase(MARCItemlist.get(k))) {
86                      count++;
87                  }
88              }
89              if (count > 1) {
90                  this.putFieldError(OLEConstants.OleDiscoveryExportProfile.OLE_EXP_ITEM_FIELD, OLEConstants.OleDiscoveryExportProfile.OLE_EXP_ITEM_DUPLICATE_ERROR);
91                  return false;
92              }
93          }
94          return true;
95      }
96  }
97  
98