From afc0c675bda835883afe7b85c2633dbc0a6e9e82 Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Tue, 18 Mar 2008 11:16:45 +0000 Subject: [PATCH] Fix AR-2179 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8556 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/repo-admin-context.xml | 6 + .../DictionaryRepositoryBootstrap.java | 123 +++++++++--------- .../DictionaryRepositoryBootstrapTest.java | 1 + .../repo/dictionary/RepositoryLocation.java | 8 +- 4 files changed, 73 insertions(+), 65 deletions(-) diff --git a/config/alfresco/repo-admin-context.xml b/config/alfresco/repo-admin-context.xml index 1111bac9d8..5c88aefced 100755 --- a/config/alfresco/repo-admin-context.xml +++ b/config/alfresco/repo-admin-context.xml @@ -44,6 +44,9 @@ /app:company_home/app:dictionary/app:models + + lucene + @@ -51,6 +54,9 @@ /app:company_home/app:dictionary/app:messages + + lucene + diff --git a/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java b/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java index 798231a2f9..8ac7b43b54 100644 --- a/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java +++ b/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2008 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -43,6 +43,7 @@ import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.transaction.TransactionService; @@ -233,40 +234,40 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme { logger.warn("StoreRef '"+ storeRef+"' does not exist"); continue; // skip this location - } + } - if (repositoryLocation.getQueryLanguage().equals( - SearchService.LANGUAGE_XPATH)) + if (repositoryLocation.getQueryLanguage().equals(SearchService.LANGUAGE_LUCENE)) { - NodeRef rootNode = nodeService.getRootNode(storeRef); - - List nodeRefs = searchService.selectNodes(rootNode, - repositoryLocation.getXPathQueryStatement(ContentModel.TYPE_DICTIONARY_MODEL.getPrefixedQName(namespaceService)), - null, - namespaceService, - false); - - for (NodeRef dictionaryModel : nodeRefs) - { - // Ignore if the node is a working copy or if its inactive - if (nodeService.hasAspect(dictionaryModel, ContentModel.ASPECT_WORKING_COPY) == false) + ResultSet rs = searchService.query(storeRef, + SearchService.LANGUAGE_LUCENE, + repositoryLocation.getLuceneQueryStatement(ContentModel.TYPE_DICTIONARY_MODEL.getPrefixedQName(namespaceService))); + if (rs.length() > 0) + { + for (NodeRef dictionaryModel : rs.getNodeRefs()) { - Boolean isActive = (Boolean)nodeService.getProperty(dictionaryModel, ContentModel.PROP_MODEL_ACTIVE); - - if ((isActive != null) && (isActive.booleanValue() == true)) - { - M2Model model = createM2Model(dictionaryModel); - if (model != null) - { - for (M2Namespace namespace : model.getNamespaces()) - { - modelMap.put(namespace.getUri(), model); - } - } + // Ignore if the node is a working copy or if its inactive + if (nodeService.hasAspect(dictionaryModel, ContentModel.ASPECT_WORKING_COPY) == false) + { + Boolean isActive = (Boolean)nodeService.getProperty(dictionaryModel, ContentModel.PROP_MODEL_ACTIVE); + if ((isActive != null) && (isActive.booleanValue() == true)) + { + M2Model model = createM2Model(dictionaryModel); + if (model != null) + { + for (M2Namespace namespace : model.getNamespaces()) + { + modelMap.put(namespace.getUri(), model); + } + } + } } } } } + else + { + logger.error("Unsupported query language for models location: " + repositoryLocation.getQueryLanguage()); + } } // Load the models ensuring that they are loaded in the correct order @@ -292,43 +293,43 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme { logger.warn("StoreRef '"+ storeRef+"' does not exist"); continue; // skip this location - } - - if (repositoryLocation.getQueryLanguage().equals( - SearchService.LANGUAGE_XPATH)) + } + + if (repositoryLocation.getQueryLanguage().equals(SearchService.LANGUAGE_LUCENE)) { - NodeRef rootNode = nodeService.getRootNode(storeRef); - - List nodeRefs = searchService.selectNodes(rootNode, - repositoryLocation.getXPathQueryStatement(ContentModel.TYPE_CONTENT.getPrefixedQName(namespaceService)), - null, - namespaceService, - false); - - List resourceBundleBaseNames = new ArrayList(); - - for (NodeRef messageResource : nodeRefs) - { - String resourceName = (String) nodeService.getProperty( - messageResource, ContentModel.PROP_NAME); - - String bundleBaseName = messageService.getBaseBundleName(resourceName); - - if (!resourceBundleBaseNames.contains(bundleBaseName)) + ResultSet rs = searchService.query(storeRef, + SearchService.LANGUAGE_LUCENE, + repositoryLocation.getLuceneQueryStatement(ContentModel.TYPE_CONTENT.getPrefixedQName(namespaceService))); + if (rs.length() > 0) + { + List resourceBundleBaseNames = new ArrayList(); + for (NodeRef messageResource : rs.getNodeRefs()) { - resourceBundleBaseNames.add(bundleBaseName); + String resourceName = (String) nodeService.getProperty( + messageResource, ContentModel.PROP_NAME); + + String bundleBaseName = messageService.getBaseBundleName(resourceName); + + if (!resourceBundleBaseNames.contains(bundleBaseName)) + { + resourceBundleBaseNames.add(bundleBaseName); + } + } + + // Only need to register resource bundle names + for (String resourceBundleBaseName : resourceBundleBaseNames) + { + logger.info("Register bundle: " + resourceBundleBaseName); + + messageService.registerResourceBundle(storeRef.toString() + path + "/cm:" + resourceBundleBaseName); + } } - - // Only need to register resource bundle names - for (String resourceBundleBaseName : resourceBundleBaseNames) - { - logger.info("Register bundle: " + resourceBundleBaseName); - - messageService.registerResourceBundle(storeRef.toString() + path + "/cm:" + resourceBundleBaseName); - - } - } + } + else + { + logger.error("Unsupported query language for messages location: " + repositoryLocation.getQueryLanguage()); + } } } } diff --git a/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrapTest.java b/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrapTest.java index 7b678be265..5481365a96 100644 --- a/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrapTest.java +++ b/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrapTest.java @@ -110,6 +110,7 @@ public class DictionaryRepositoryBootstrapTest extends BaseAlfrescoSpringTest RepositoryLocation location = new RepositoryLocation(); location.setStoreProtocol(this.storeRef.getProtocol()); location.setStoreId(this.storeRef.getIdentifier()); + location.setQueryLanguage(SearchService.LANGUAGE_LUCENE); // NOTE: we are not setting the path for now .. in doing so we are searching the whole dictionary List locations = new ArrayList(); diff --git a/source/java/org/alfresco/repo/dictionary/RepositoryLocation.java b/source/java/org/alfresco/repo/dictionary/RepositoryLocation.java index d3f2fac672..2742cbd9c8 100755 --- a/source/java/org/alfresco/repo/dictionary/RepositoryLocation.java +++ b/source/java/org/alfresco/repo/dictionary/RepositoryLocation.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2008 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -104,7 +104,7 @@ public class RepositoryLocation } /** - * Set the queru language + * Set the query language * * @param path the search language */ @@ -159,7 +159,7 @@ public class RepositoryLocation { String result = "+TYPE:\"" + contentModelType.toString() + "\""; - if (this.path != null) + if ((this.path != null) && (! this.path.equals(""))) { result += " +PATH:\"" + this.path + "\""; } @@ -176,7 +176,7 @@ public class RepositoryLocation { String result = "/*[subtypeOf('" + prefixResolvedContentModelType.toPrefixString() + "')]"; // immediate children only - if (this.path != null) + if ((this.path != null) && (! this.path.equals(""))) { result = this.path + result; }