Fix AR-2179

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8556 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-03-18 11:16:45 +00:00
parent caa03b12b9
commit afc0c675bd
4 changed files with 73 additions and 65 deletions

View File

@@ -44,6 +44,9 @@
<property name="path"> <property name="path">
<value>/app:company_home/app:dictionary/app:models</value> <value>/app:company_home/app:dictionary/app:models</value>
</property> </property>
<property name="queryLanguage">
<value>lucene</value>
</property>
</bean> </bean>
<bean id="customMessagesRepositoryLocation" class="org.alfresco.repo.dictionary.RepositoryLocation"> <bean id="customMessagesRepositoryLocation" class="org.alfresco.repo.dictionary.RepositoryLocation">
@@ -51,6 +54,9 @@
<property name="path"> <property name="path">
<value>/app:company_home/app:dictionary/app:messages</value> <value>/app:company_home/app:dictionary/app:messages</value>
</property> </property>
<property name="queryLanguage">
<value>lucene</value>
</property>
</bean> </bean>
</beans> </beans>

View File

@@ -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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; 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.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
@@ -235,38 +236,38 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme
continue; // skip this location continue; // skip this location
} }
if (repositoryLocation.getQueryLanguage().equals( if (repositoryLocation.getQueryLanguage().equals(SearchService.LANGUAGE_LUCENE))
SearchService.LANGUAGE_XPATH))
{ {
NodeRef rootNode = nodeService.getRootNode(storeRef); ResultSet rs = searchService.query(storeRef,
SearchService.LANGUAGE_LUCENE,
List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, repositoryLocation.getLuceneQueryStatement(ContentModel.TYPE_DICTIONARY_MODEL.getPrefixedQName(namespaceService)));
repositoryLocation.getXPathQueryStatement(ContentModel.TYPE_DICTIONARY_MODEL.getPrefixedQName(namespaceService)), if (rs.length() > 0)
null,
namespaceService,
false);
for (NodeRef dictionaryModel : nodeRefs)
{ {
// Ignore if the node is a working copy or if its inactive for (NodeRef dictionaryModel : rs.getNodeRefs())
if (nodeService.hasAspect(dictionaryModel, ContentModel.ASPECT_WORKING_COPY) == false)
{ {
Boolean isActive = (Boolean)nodeService.getProperty(dictionaryModel, ContentModel.PROP_MODEL_ACTIVE); // Ignore if the node is a working copy or if its inactive
if (nodeService.hasAspect(dictionaryModel, ContentModel.ASPECT_WORKING_COPY) == false)
if ((isActive != null) && (isActive.booleanValue() == true))
{ {
M2Model model = createM2Model(dictionaryModel); Boolean isActive = (Boolean)nodeService.getProperty(dictionaryModel, ContentModel.PROP_MODEL_ACTIVE);
if (model != null) if ((isActive != null) && (isActive.booleanValue() == true))
{ {
for (M2Namespace namespace : model.getNamespaces()) M2Model model = createM2Model(dictionaryModel);
{ if (model != null)
modelMap.put(namespace.getUri(), model); {
} 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 // Load the models ensuring that they are loaded in the correct order
@@ -294,40 +295,40 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme
continue; // skip this location continue; // skip this location
} }
if (repositoryLocation.getQueryLanguage().equals( if (repositoryLocation.getQueryLanguage().equals(SearchService.LANGUAGE_LUCENE))
SearchService.LANGUAGE_XPATH))
{ {
NodeRef rootNode = nodeService.getRootNode(storeRef); ResultSet rs = searchService.query(storeRef,
SearchService.LANGUAGE_LUCENE,
List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, repositoryLocation.getLuceneQueryStatement(ContentModel.TYPE_CONTENT.getPrefixedQName(namespaceService)));
repositoryLocation.getXPathQueryStatement(ContentModel.TYPE_CONTENT.getPrefixedQName(namespaceService)), if (rs.length() > 0)
null,
namespaceService,
false);
List<String> resourceBundleBaseNames = new ArrayList<String>();
for (NodeRef messageResource : nodeRefs)
{ {
String resourceName = (String) nodeService.getProperty( List<String> resourceBundleBaseNames = new ArrayList<String>();
messageResource, ContentModel.PROP_NAME); for (NodeRef messageResource : rs.getNodeRefs())
String bundleBaseName = messageService.getBaseBundleName(resourceName);
if (!resourceBundleBaseNames.contains(bundleBaseName))
{ {
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 else
for (String resourceBundleBaseName : resourceBundleBaseNames) {
{ logger.error("Unsupported query language for messages location: " + repositoryLocation.getQueryLanguage());
logger.info("Register bundle: " + resourceBundleBaseName);
messageService.registerResourceBundle(storeRef.toString() + path + "/cm:" + resourceBundleBaseName);
}
} }
} }
} }

View File

@@ -110,6 +110,7 @@ public class DictionaryRepositoryBootstrapTest extends BaseAlfrescoSpringTest
RepositoryLocation location = new RepositoryLocation(); RepositoryLocation location = new RepositoryLocation();
location.setStoreProtocol(this.storeRef.getProtocol()); location.setStoreProtocol(this.storeRef.getProtocol());
location.setStoreId(this.storeRef.getIdentifier()); 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 // NOTE: we are not setting the path for now .. in doing so we are searching the whole dictionary
List<RepositoryLocation> locations = new ArrayList<RepositoryLocation>(); List<RepositoryLocation> locations = new ArrayList<RepositoryLocation>();

View File

@@ -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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * @param path the search language
*/ */
@@ -159,7 +159,7 @@ public class RepositoryLocation
{ {
String result = "+TYPE:\"" + contentModelType.toString() + "\""; String result = "+TYPE:\"" + contentModelType.toString() + "\"";
if (this.path != null) if ((this.path != null) && (! this.path.equals("")))
{ {
result += " +PATH:\"" + this.path + "\""; result += " +PATH:\"" + this.path + "\"";
} }
@@ -176,7 +176,7 @@ public class RepositoryLocation
{ {
String result = "/*[subtypeOf('" + prefixResolvedContentModelType.toPrefixString() + "')]"; // immediate children only String result = "/*[subtypeOf('" + prefixResolvedContentModelType.toPrefixString() + "')]"; // immediate children only
if (this.path != null) if ((this.path != null) && (! this.path.equals("")))
{ {
result = this.path + result; result = this.path + result;
} }