mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Dynamic models - validate message resource bundle exists (when reloading)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7680 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -98,7 +98,7 @@ ok> reload messages <resourceBundleBaseName>
|
|||||||
|
|
||||||
Reload message resource bundle from repository into runtime message service.
|
Reload message resource bundle from repository into runtime message service.
|
||||||
|
|
||||||
e.g. undeploy messages lifecycle-messages
|
e.g. reload messages lifecycle-messages
|
||||||
|
|
||||||
##
|
##
|
||||||
## end
|
## end
|
||||||
|
@@ -40,6 +40,7 @@ import org.alfresco.repo.dictionary.DictionaryDAO;
|
|||||||
import org.alfresco.repo.dictionary.M2Model;
|
import org.alfresco.repo.dictionary.M2Model;
|
||||||
import org.alfresco.repo.dictionary.RepositoryLocation;
|
import org.alfresco.repo.dictionary.RepositoryLocation;
|
||||||
import org.alfresco.repo.i18n.MessageService;
|
import org.alfresco.repo.i18n.MessageService;
|
||||||
|
import org.alfresco.repo.i18n.MessageServiceImpl;
|
||||||
import org.alfresco.service.cmr.admin.RepoAdminService;
|
import org.alfresco.service.cmr.admin.RepoAdminService;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||||
@@ -553,33 +554,26 @@ public class RepoAdminServiceImpl implements RepoAdminService
|
|||||||
// Check that all the passed values are not null
|
// Check that all the passed values are not null
|
||||||
ParameterCheck.mandatory("ResourceClasspath", resourceClasspath);
|
ParameterCheck.mandatory("ResourceClasspath", resourceClasspath);
|
||||||
|
|
||||||
String bundleBaseName = null;
|
String bundleBaseName = resourceClasspath;
|
||||||
|
|
||||||
// note: resource path should be in form path1/path2/path3/bundlebasename
|
// note: resource path should be in form path1/path2/path3/bundlebasename
|
||||||
int idx = resourceClasspath.lastIndexOf("/");
|
int idx = resourceClasspath.lastIndexOf("/");
|
||||||
|
|
||||||
if ((idx != -1) && (idx < (resourceClasspath.length()-1)))
|
if (idx != -1)
|
||||||
{
|
{
|
||||||
bundleBaseName = resourceClasspath.substring(idx+1);
|
if (idx < (resourceClasspath.length()-1))
|
||||||
|
{
|
||||||
|
bundleBaseName = resourceClasspath.substring(idx+1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bundleBaseName = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bundleBaseName == null)
|
checkBundleBaseName(bundleBaseName);
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Message deployment failed - missing bundle base name (path = " + resourceClasspath + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bundleBaseName.indexOf("_") != -1)
|
String pattern = "classpath*:" + resourceClasspath + "*" + MessageServiceImpl.PROPERTIES_FILE_SUFFIX;
|
||||||
{
|
|
||||||
// currently limited due to parser in DictionaryRepositoryBootstrap
|
|
||||||
throw new AlfrescoRuntimeException("Message deployment failed - bundle base name '" + bundleBaseName + "' should not contain '_' (underscore)");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bundleBaseName.indexOf(".") != -1)
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Message deployment failed - bundle base name '" + bundleBaseName + "' should not contain '.' (period)");
|
|
||||||
}
|
|
||||||
|
|
||||||
String pattern = "classpath*:" + resourceClasspath + "*.properties";
|
|
||||||
|
|
||||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||||
|
|
||||||
@@ -625,7 +619,7 @@ public class RepoAdminServiceImpl implements RepoAdminService
|
|||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Message resource bundle deployment failed ", e);
|
throw new AlfrescoRuntimeException("Message resource bundle deployment failed for resource classpath " + resourceClasspath, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bundleBaseName;
|
return bundleBaseName;
|
||||||
@@ -653,12 +647,12 @@ public class RepoAdminServiceImpl implements RepoAdminService
|
|||||||
|
|
||||||
if (nodeRefs.size() == 0)
|
if (nodeRefs.size() == 0)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Could not find custom labels location " + repoMessagesLocation.getPath());
|
throw new AlfrescoRuntimeException("Could not find messages location " + repoMessagesLocation.getPath());
|
||||||
}
|
}
|
||||||
else if (nodeRefs.size() > 1)
|
else if (nodeRefs.size() > 1)
|
||||||
{
|
{
|
||||||
// unexpected: should not find multiple nodes with same name
|
// unexpected: should not find multiple nodes with same name
|
||||||
throw new AlfrescoRuntimeException("Found multiple custom labels location " + repoMessagesLocation.getPath());
|
throw new AlfrescoRuntimeException("Found multiple messages location " + repoMessagesLocation.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeRef customLabelsNodeRef = nodeRefs.get(0);
|
NodeRef customLabelsNodeRef = nodeRefs.get(0);
|
||||||
@@ -721,8 +715,7 @@ public class RepoAdminServiceImpl implements RepoAdminService
|
|||||||
*/
|
*/
|
||||||
public void undeployMessageBundle(String bundleBaseName)
|
public void undeployMessageBundle(String bundleBaseName)
|
||||||
{
|
{
|
||||||
// Check that all the passed values are not null
|
checkBundleBaseName(bundleBaseName);
|
||||||
ParameterCheck.mandatory("bundleBaseName", bundleBaseName);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -751,7 +744,7 @@ public class RepoAdminServiceImpl implements RepoAdminService
|
|||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (Throwable t)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Messages undeployment failed ", t);
|
throw new AlfrescoRuntimeException("Message resource bundle undeployment failed ", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -761,8 +754,7 @@ public class RepoAdminServiceImpl implements RepoAdminService
|
|||||||
*/
|
*/
|
||||||
public void reloadMessageBundle(String bundleBaseName)
|
public void reloadMessageBundle(String bundleBaseName)
|
||||||
{
|
{
|
||||||
// Check that all the passed values are not null
|
checkBundleBaseName(bundleBaseName);
|
||||||
ParameterCheck.mandatory("bundleBaseName", bundleBaseName);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -772,14 +764,56 @@ public class RepoAdminServiceImpl implements RepoAdminService
|
|||||||
|
|
||||||
String repoBundlePath = storeRef.toString() + repoMessagesLocation.getPath() + "/cm:" + bundleBaseName;
|
String repoBundlePath = storeRef.toString() + repoMessagesLocation.getPath() + "/cm:" + bundleBaseName;
|
||||||
|
|
||||||
messageService.unregisterResourceBundle(repoBundlePath);
|
NodeRef rootNode = nodeService.getRootNode(storeRef);
|
||||||
messageService.registerResourceBundle(repoBundlePath);
|
|
||||||
|
|
||||||
logger.info("Message resources re-loaded: " + bundleBaseName);
|
List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, repoMessagesLocation.getPath()+CRITERIA_ALL, null, namespaceService, false);
|
||||||
|
|
||||||
|
boolean found = false;
|
||||||
|
for (NodeRef nodeRef : nodeRefs)
|
||||||
|
{
|
||||||
|
String customLabelName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
||||||
|
|
||||||
|
if (customLabelName.startsWith(bundleBaseName))
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
messageService.unregisterResourceBundle(repoBundlePath);
|
||||||
|
messageService.registerResourceBundle(repoBundlePath);
|
||||||
|
|
||||||
|
logger.info("Message resources re-loaded: " + bundleBaseName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Could not find message resource bundle " + repoBundlePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Message resource re-load failed", e);
|
throw new AlfrescoRuntimeException("Message resource re-load failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkBundleBaseName(String bundleBaseName)
|
||||||
|
{
|
||||||
|
if ((bundleBaseName == null) || (bundleBaseName.equals("")))
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Message deployment failed - missing bundle base name");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bundleBaseName.indexOf("_") != -1)
|
||||||
|
{
|
||||||
|
// currently limited due to parser in DictionaryRepositoryBootstrap
|
||||||
|
throw new AlfrescoRuntimeException("Message deployment failed - bundle base name '" + bundleBaseName + "' should not contain '_' (underscore)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bundleBaseName.indexOf(".") != -1)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Message deployment failed - bundle base name '" + bundleBaseName + "' should not contain '.' (period)");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,6 +46,8 @@ public class MessageServiceImpl implements MessageService
|
|||||||
{
|
{
|
||||||
private static final Log logger = LogFactory.getLog(MessageServiceImpl.class);
|
private static final Log logger = LogFactory.getLog(MessageServiceImpl.class);
|
||||||
|
|
||||||
|
public static final String PROPERTIES_FILE_SUFFIX = ".properties";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock objects
|
* Lock objects
|
||||||
*/
|
*/
|
||||||
@@ -542,12 +544,12 @@ public class MessageServiceImpl implements MessageService
|
|||||||
NodeRef rootNode = serviceRegistry.getNodeService().getRootNode(storeRef);
|
NodeRef rootNode = serviceRegistry.getNodeService().getRootNode(storeRef);
|
||||||
|
|
||||||
// first attempt - with locale
|
// first attempt - with locale
|
||||||
List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, path+"_"+locale+".properties", null, resolver, false);
|
List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, path+"_"+locale+PROPERTIES_FILE_SUFFIX, null, resolver, false);
|
||||||
|
|
||||||
if ((nodeRefs == null) || (nodeRefs.size() == 0))
|
if ((nodeRefs == null) || (nodeRefs.size() == 0))
|
||||||
{
|
{
|
||||||
// second attempt - basename
|
// second attempt - basename
|
||||||
nodeRefs = searchService.selectNodes(rootNode, path+".properties", null, resolver, false);
|
nodeRefs = searchService.selectNodes(rootNode, path+PROPERTIES_FILE_SUFFIX, null, resolver, false);
|
||||||
|
|
||||||
if ((nodeRefs == null) || (nodeRefs.size() == 0))
|
if ((nodeRefs == null) || (nodeRefs.size() == 0))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user