From 28beb46e19bd32c8b59c5cde2749519171a17fb7 Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Wed, 23 Jul 2014 14:38:28 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 77080: Merged PLATFORM1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 72874: More for ACE-1034 SOLR 4 - Data model - Impl - part 2 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@77929 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- ...lfrescoClientDataModelServicesFactory.java | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 search-services/alfresco-solrclient-lib/source/java/org/alfresco/solr/AlfrescoClientDataModelServicesFactory.java diff --git a/search-services/alfresco-solrclient-lib/source/java/org/alfresco/solr/AlfrescoClientDataModelServicesFactory.java b/search-services/alfresco-solrclient-lib/source/java/org/alfresco/solr/AlfrescoClientDataModelServicesFactory.java new file mode 100644 index 000000000..58b4dac67 --- /dev/null +++ b/search-services/alfresco-solrclient-lib/source/java/org/alfresco/solr/AlfrescoClientDataModelServicesFactory.java @@ -0,0 +1,165 @@ +package org.alfresco.solr; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.opencmis.dictionary.CMISAbstractDictionaryService; +import org.alfresco.opencmis.dictionary.CMISStrictDictionaryService; +import org.alfresco.opencmis.dictionary.FilteredDictionaryComponent; +import org.alfresco.opencmis.dictionary.QNameFilter; +import org.alfresco.opencmis.mapping.CMISMapping; +import org.alfresco.opencmis.mapping.RuntimePropertyLuceneBuilderMapping; +import org.alfresco.repo.cache.MemoryCache; +import org.alfresco.repo.dictionary.DictionaryComponent; +import org.alfresco.repo.dictionary.DictionaryDAO; +import org.alfresco.repo.dictionary.DictionaryDAOImpl; +import org.alfresco.repo.dictionary.DictionaryNamespaceComponent; +import org.alfresco.repo.dictionary.NamespaceDAO; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.apache.chemistry.opencmis.commons.enums.CmisVersion; + +/** + * Basic Factory for creating services for the AlfrescoSolrDataMode. It always creates a default + * + * @author Gethin James + */ +public class AlfrescoClientDataModelServicesFactory +{ + public static final String DICTIONARY_FILTERED_WITH_EXCLUSIONS = "cmisWithExclusions"; + + /** + * Constructs a dictionary by default. + * + * @param cmisMapping + * @param dictionaryService + * @param dictionaryDAO + * @return Map + */ + public static Map constructDictionaries(QNameFilter qnameFilter, NamespaceDAO namespaceDAO, + DictionaryComponent dictionaryService, DictionaryDAO dictionaryDAO) + { + DictionaryNamespaceComponent namespaceService = new DictionaryNamespaceComponent(); + namespaceService.setNamespaceDAO(namespaceDAO); + + CMISMapping cmisMapping = new CMISMapping(); + cmisMapping.setCmisVersion(CmisVersion.CMIS_1_0); + cmisMapping.setFilter(qnameFilter); + cmisMapping.setNamespaceService(namespaceService); + cmisMapping.setDictionaryService(dictionaryService); + cmisMapping.afterPropertiesSet(); + + CMISMapping cmisMapping11 = new CMISMapping(); + cmisMapping11.setCmisVersion(CmisVersion.CMIS_1_1); + cmisMapping11.setFilter(qnameFilter); + cmisMapping11.setNamespaceService(namespaceService); + cmisMapping11.setDictionaryService(dictionaryService); + cmisMapping11.afterPropertiesSet(); + + Map dictionaries = new HashMap(); + + DictionaryKey key = new DictionaryKey(CmisVersion.CMIS_1_0, CMISStrictDictionaryService.DEFAULT); + dictionaries.put(key, newInstance(cmisMapping, dictionaryService, dictionaryDAO)); + CMISMapping mappingWithExclusions = newInstanceOfExcludedCMISMapping(cmisMapping, qnameFilter); + key = new DictionaryKey(CmisVersion.CMIS_1_0, DICTIONARY_FILTERED_WITH_EXCLUSIONS); + dictionaries.put(key, newInstance(mappingWithExclusions, dictionaryService, dictionaryDAO)); + + key = new DictionaryKey(CmisVersion.CMIS_1_1, CMISStrictDictionaryService.DEFAULT); + dictionaries.put(key, newInstance(cmisMapping11, dictionaryService, dictionaryDAO)); + CMISMapping mappingWithExclusions11 = newInstanceOfExcludedCMISMapping(cmisMapping11, qnameFilter); + key = new DictionaryKey(CmisVersion.CMIS_1_1, DICTIONARY_FILTERED_WITH_EXCLUSIONS); + dictionaries.put(key, newInstance(mappingWithExclusions11, dictionaryService, dictionaryDAO)); + + return dictionaries; + } + + /** + * Constructs a dictionary by default. + * + * @param dictionaryDAO + * @return Map + */ + public static Map constructDictionaryServices(QNameFilter qnameFilter, DictionaryDAOImpl dictionaryDAO) + { + Map dictionaries = new HashMap(); + DictionaryComponent compo = new DictionaryComponent(); + compo.setDictionaryDAO(dictionaryDAO); + dictionaries.put(CMISStrictDictionaryService.DEFAULT, compo); + FilteredDictionaryComponent fdc = new FilteredDictionaryComponent(); + fdc.setDictionaryDAO(dictionaryDAO); + fdc.setFilter(qnameFilter); + dictionaries.put(DICTIONARY_FILTERED_WITH_EXCLUSIONS, fdc); + return dictionaries; + + } + + private static CMISMapping newInstanceOfExcludedCMISMapping(CMISMapping cmisMapping, QNameFilter filter) + { + CMISMapping cmisMappingWithExcl = new CMISMapping(); + cmisMappingWithExcl.setNamespaceService(cmisMapping.getNamespaceService()); + cmisMappingWithExcl.setDictionaryService(cmisMapping.getDictionaryService()); + cmisMappingWithExcl.setFilter(filter); + cmisMappingWithExcl.setCmisVersion(cmisMapping.getCmisVersion()); + cmisMappingWithExcl.afterPropertiesSet(); + return cmisMappingWithExcl; + } + + protected static CMISStrictDictionaryService newInstance(CMISMapping cmisMapping, DictionaryService dictionaryService, DictionaryDAO dictionaryDAO) + { + CMISStrictDictionaryService cmisDictionaryService = new CMISStrictDictionaryService(); + cmisDictionaryService.setCmisMapping(cmisMapping); + cmisDictionaryService.setDictionaryService(dictionaryService); + cmisDictionaryService.setDictionaryDAO(dictionaryDAO); + cmisDictionaryService.setSingletonCache(new MemoryCache()); + + RuntimePropertyLuceneBuilderMapping luceneBuilderMapping = new RuntimePropertyLuceneBuilderMapping(); + luceneBuilderMapping.setDictionaryService(dictionaryService); + luceneBuilderMapping.setCmisDictionaryService(cmisDictionaryService); + cmisDictionaryService.setPropertyLuceneBuilderMapping(luceneBuilderMapping); + luceneBuilderMapping.afterPropertiesSet(); + return cmisDictionaryService; + } + + public static class DictionaryKey + { + private CmisVersion cmisVersion; + private String key; + public DictionaryKey(CmisVersion cmisVersion, String key) { + super(); + this.cmisVersion = cmisVersion; + this.key = key; + } + public CmisVersion getCmisVersion() { + return cmisVersion; + } + public String getKey() { + return key; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((cmisVersion == null) ? 0 : cmisVersion.hashCode()); + result = prime * result + ((key == null) ? 0 : key.hashCode()); + return result; + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DictionaryKey other = (DictionaryKey) obj; + if (cmisVersion != other.cmisVersion) + return false; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equals(other.key)) + return false; + return true; + } + } +}