001package org.kuali.ole.docstore.common.document.config; 002 003import org.kuali.ole.docstore.common.document.content.enums.DocFormat; 004import org.kuali.ole.docstore.common.document.content.enums.DocType; 005import org.kuali.rice.krad.service.BusinessObjectService; 006import org.kuali.rice.krad.service.KRADServiceLocator; 007 008import java.util.*; 009 010/** 011 * Created with IntelliJ IDEA. 012 * User: chandrasekharag 013 * Date: 4/3/14 014 * Time: 6:17 PM 015 * 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>(); 016 * ngs | File Templates. 017 */ 018public class DocumentSearchConfig { 019 020 private List<DocTypeConfig> docTypeConfigs = new ArrayList<>(); // bib ,holdings …. 021 private static List<Integer> pageSizes = new ArrayList<>(); 022 private int facetPageSizeShort = 0; 023 private int facetPageSizeLong = 0; 024 private static DocumentSearchConfig documentSearchConfig; 025 public static Map<String, String> FIELDS_TO_TAGS_2_INCLUDE_MAP = new HashMap<String, String>(); 026 public static Map<String, String> FIELDS_TO_TAGS_2_INCLUDE_MAP_SELECTED = new HashMap<String, String>(); 027 public static Map<String, String> FIELDS_TO_TAGS_2_EXCLUDE_MAP = new HashMap<String, String>(); 028 public static Map<String, String> FIELDS_TO_TAGS_2_EXCLUDE_MAP_SELECTED = new HashMap<String, String>(); 029 030 private DocumentSearchConfig() { 031 032 033 } 034 035 public static List<Integer> getPageSizes() { 036 return pageSizes; 037 } 038 039 public void setPageSizes(List<Integer> pageSizes) { 040 DocumentSearchConfig.pageSizes = pageSizes; 041 } 042 043 public static DocumentSearchConfig getDocumentSearchConfig() { 044 if (documentSearchConfig == null) { 045 documentSearchConfig = new DocumentSearchConfig(); 046 reloadDocumentConfig(); 047 } 048 049 return documentSearchConfig; 050 } 051 052 public static DocumentSearchConfig reloadDocumentConfig() { 053 List<DocTypeConfig> docTypeConfigList = (List<DocTypeConfig>) KRADServiceLocator.getBusinessObjectService().findAll(DocTypeConfig.class); 054 055 for (DocTypeConfig docTypeConfig : docTypeConfigList) { 056 Map typeMap = new HashMap(); 057 typeMap.put("docTypeId", docTypeConfig.getId()); 058 List<DocFormatConfig> docFormatConfigList = (List<DocFormatConfig>) KRADServiceLocator.getBusinessObjectService().findMatching(DocFormatConfig.class, typeMap); 059 for (DocFormatConfig docFormatConfig : docFormatConfigList) { 060 Map formatMap = new HashMap(); 061 formatMap.put("docTypeId", docTypeConfig.getId()); 062 formatMap.put("docFormatId", docFormatConfig.getId()); 063 List<DocFieldConfig> docFieldConfigList = (List<DocFieldConfig>) KRADServiceLocator.getBusinessObjectService().findMatching(DocFieldConfig.class, formatMap); 064 if (docFieldConfigList.size() > 0) { 065 DocFormatConfig docFormat = docFieldConfigList.get(0).getDocFormat(); 066 DocTypeConfig docType = docFieldConfigList.get(0).getDocType(); 067 for (DocFieldConfig docFieldConfig : docFieldConfigList) { 068 if (docFieldConfig.getDocFormat() != null) 069 continue; 070 docFieldConfig.setDocFormat(docFormat); 071 docFieldConfig.setDocType(docType); 072 } 073 } 074 docFormatConfig.setDocFieldConfigList(docFieldConfigList); 075 } 076 docTypeConfig.setDocFormatConfigList(docFormatConfigList); 077 } 078 079 documentSearchConfig.setDocTypeConfigs(docTypeConfigList); 080 081 List<SearchResultPage> searchResultPageList = (List<SearchResultPage>) KRADServiceLocator.getBusinessObjectService().findAll(SearchResultPage.class); 082 List<SearchFacetPage> searchFacetPageList = (List<SearchFacetPage>) KRADServiceLocator.getBusinessObjectService().findAll(SearchFacetPage.class); 083 List<Integer> pageSizeList = new ArrayList<>(); 084 for (SearchResultPage searchResultPage : searchResultPageList) { 085 Integer pageSize = searchResultPage.getSize(); 086 pageSizeList.add(pageSize); 087 } 088 Collections.sort(pageSizeList); 089 documentSearchConfig.setPageSizes(pageSizeList); 090 if (searchFacetPageList.size() > 0) { 091 documentSearchConfig.setFacetPageSizeLong(searchFacetPageList.get(0).getLongSize()); 092 documentSearchConfig.setFacetPageSizeShort(searchFacetPageList.get(0).getShotSize()); 093 } 094 buildIncludeAndExcludeMapping(); 095 096 return documentSearchConfig; 097 } 098 099 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}