View Javadoc
1   package org.kuali.ole.docstore.common.document.config;
2   
3   import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
4   import org.kuali.ole.docstore.common.document.content.enums.DocType;
5   import org.kuali.rice.krad.service.BusinessObjectService;
6   import org.kuali.rice.krad.service.KRADServiceLocator;
7   
8   import java.util.*;
9   
10  /**
11   * Created with IntelliJ IDEA.
12   * User: chandrasekharag
13   * Date: 4/3/14
14   * Time: 6:17 PM
15   * To change this template use File | Setti    public static Map<String, String> FIELDS_TO_TAGS_2_INCLUDE_MAP = new HashMap<String, String>();    public static Map<String, String> FIELDS_TO_TAGS_2_EXCLUDE_MAP = new HashMap<String, String>();
16   * ngs | File Templates.
17   */
18  public class DocumentSearchConfig {
19  
20      private List<DocTypeConfig> docTypeConfigs = new ArrayList<>();   // bib ,holdings ….
21      private static List<Integer> pageSizes = new ArrayList<>();
22      private int facetPageSizeShort = 0;
23      private int facetPageSizeLong = 0;
24      private static DocumentSearchConfig documentSearchConfig;
25      public static Map<String, String> FIELDS_TO_TAGS_2_INCLUDE_MAP = new HashMap<String, String>();
26      public static Map<String, String> FIELDS_TO_TAGS_2_INCLUDE_MAP_SELECTED = new HashMap<String, String>();
27      public static Map<String, String> FIELDS_TO_TAGS_2_EXCLUDE_MAP = new HashMap<String, String>();
28      public static Map<String, String> FIELDS_TO_TAGS_2_EXCLUDE_MAP_SELECTED = new HashMap<String, String>();
29  
30      private DocumentSearchConfig() {
31  
32  
33      }
34  
35      public static List<Integer> getPageSizes() {
36          return pageSizes;
37      }
38  
39      public void setPageSizes(List<Integer> pageSizes) {
40          DocumentSearchConfig.pageSizes = pageSizes;
41      }
42  
43      public static DocumentSearchConfig getDocumentSearchConfig() {
44          if (documentSearchConfig == null) {
45              documentSearchConfig = new DocumentSearchConfig();
46              reloadDocumentConfig();
47          }
48  
49          return documentSearchConfig;
50      }
51  
52      public static DocumentSearchConfig reloadDocumentConfig() {
53          List<DocTypeConfig> docTypeConfigList = (List<DocTypeConfig>) KRADServiceLocator.getBusinessObjectService().findAll(DocTypeConfig.class);
54  
55          for (DocTypeConfig docTypeConfig : docTypeConfigList) {
56              Map typeMap = new HashMap();
57              typeMap.put("docTypeId", docTypeConfig.getId());
58              List<DocFormatConfig> docFormatConfigList = (List<DocFormatConfig>) KRADServiceLocator.getBusinessObjectService().findMatching(DocFormatConfig.class, typeMap);
59              for (DocFormatConfig docFormatConfig : docFormatConfigList) {
60                  Map formatMap = new HashMap();
61                  formatMap.put("docTypeId", docTypeConfig.getId());
62                  formatMap.put("docFormatId", docFormatConfig.getId());
63                  List<DocFieldConfig> docFieldConfigList = (List<DocFieldConfig>) KRADServiceLocator.getBusinessObjectService().findMatching(DocFieldConfig.class, formatMap);
64                  if (docFieldConfigList.size() > 0) {
65                      DocFormatConfig docFormat = docFieldConfigList.get(0).getDocFormat();
66                      DocTypeConfig docType = docFieldConfigList.get(0).getDocType();
67                      for (DocFieldConfig docFieldConfig : docFieldConfigList) {
68                          if (docFieldConfig.getDocFormat() != null)
69                              continue;
70                          docFieldConfig.setDocFormat(docFormat);
71                          docFieldConfig.setDocType(docType);
72                      }
73                  }
74                  docFormatConfig.setDocFieldConfigList(docFieldConfigList);
75              }
76              docTypeConfig.setDocFormatConfigList(docFormatConfigList);
77          }
78  
79          documentSearchConfig.setDocTypeConfigs(docTypeConfigList);
80  
81          List<SearchResultPage> searchResultPageList = (List<SearchResultPage>) KRADServiceLocator.getBusinessObjectService().findAll(SearchResultPage.class);
82          List<SearchFacetPage> searchFacetPageList = (List<SearchFacetPage>) KRADServiceLocator.getBusinessObjectService().findAll(SearchFacetPage.class);
83          List<Integer> pageSizeList = new ArrayList<>();
84          for (SearchResultPage searchResultPage : searchResultPageList) {
85              Integer pageSize = searchResultPage.getSize();
86              pageSizeList.add(pageSize);
87          }
88          Collections.sort(pageSizeList);
89          documentSearchConfig.setPageSizes(pageSizeList);
90          if (searchFacetPageList.size() > 0) {
91              documentSearchConfig.setFacetPageSizeLong(searchFacetPageList.get(0).getLongSize());
92              documentSearchConfig.setFacetPageSizeShort(searchFacetPageList.get(0).getShotSize());
93          }
94          buildIncludeAndExcludeMapping();
95  
96          return documentSearchConfig;
97      }
98  
99      public static void buildIncludeAndExcludeMapping() {
100         for (DocTypeConfig docTypeConfig : documentSearchConfig.getDocTypeConfigs()) {
101             for (DocFormatConfig docFormatConfig : docTypeConfig.getDocFormatConfigList()) {
102                 if (DocType.BIB.isEqualTo(docTypeConfig.getName()) && DocFormat.MARC.isEqualTo(docFormatConfig.getName())) {
103                     for (DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
104                         FIELDS_TO_TAGS_2_INCLUDE_MAP.put(docFieldConfig.getName(), docFieldConfig.getIncludePath());
105                         FIELDS_TO_TAGS_2_EXCLUDE_MAP.put(docFieldConfig.getName(), docFieldConfig.getExcludePath());
106                     }
107                 }
108             }
109         }
110     }
111 
112     public static void buildIncludeAndExcludeMapping(List<String> fieldsNames) {
113         for (DocTypeConfig docTypeConfig : documentSearchConfig.getDocTypeConfigs()) {
114             for (DocFormatConfig docFormatConfig : docTypeConfig.getDocFormatConfigList()) {
115                 if (DocType.BIB.isEqualTo(docTypeConfig.getName()) && DocFormat.MARC.isEqualTo(docFormatConfig.getName())) {
116                     for (DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
117                         if(fieldsNames.contains(docFieldConfig.getName())) {
118                             String includePath = docFieldConfig.getIncludePath();
119                             String excludePath = docFieldConfig.getExcludePath();
120                             if(includePath == null) {
121                                 includePath = "";
122                             }
123                             if (excludePath == null) {
124                                 excludePath = "";
125                             }
126                             FIELDS_TO_TAGS_2_INCLUDE_MAP_SELECTED.put(docFieldConfig.getName(), includePath);
127                             FIELDS_TO_TAGS_2_EXCLUDE_MAP_SELECTED.put(docFieldConfig.getName(), excludePath);
128                         }
129                     }
130                 }
131             }
132         }
133     }
134 
135     public List<DocTypeConfig> getDocTypeConfigs() {
136         return docTypeConfigs;
137     }
138 
139     public void setDocTypeConfigs(List<DocTypeConfig> docTypeConfigs) {
140         this.docTypeConfigs = docTypeConfigs;
141     }
142 
143     public int getFacetPageSizeShort() {
144         return facetPageSizeShort;
145     }
146 
147     public void setFacetPageSizeShort(int facetPageSizeShort) {
148         this.facetPageSizeShort = facetPageSizeShort;
149     }
150 
151     public int getFacetPageSizeLong() {
152         return facetPageSizeLong;
153     }
154 
155     public void setFacetPageSizeLong(int facetPageSizeLong) {
156         this.facetPageSizeLong = facetPageSizeLong;
157     }
158 }