mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- add new Message Service + hook into Workflow Service
- add Tenant Service hooks to Workflow Service - MT bootstrap ordering fix git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6476 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
40
source/java/org/alfresco/repo/i18n/MessageDeployer.java
Normal file
40
source/java/org/alfresco/repo/i18n/MessageDeployer.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.i18n;
|
||||
|
||||
|
||||
/**
|
||||
* Message Deployer interface.
|
||||
* <p>
|
||||
* This interface allows the MessageService to be re-initialised, if for example the internal caches are invalidated in a cluster.
|
||||
* Message Deployer components will register with the MessageService.
|
||||
*
|
||||
*/
|
||||
|
||||
public interface MessageDeployer
|
||||
{
|
||||
// callback for re-initialising the message caches (from the repository)
|
||||
public void initMessages();
|
||||
}
|
155
source/java/org/alfresco/repo/i18n/MessageService.java
Normal file
155
source/java/org/alfresco/repo/i18n/MessageService.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package org.alfresco.repo.i18n;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.tenant.TenantDeployer;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
|
||||
/**
|
||||
* Utility class providing methods to access the Locale of the current thread and to get
|
||||
* Localised strings. These strings may be loaded from resource bundles deployed in the Repository.
|
||||
*/
|
||||
public interface MessageService extends TenantDeployer
|
||||
{
|
||||
/**
|
||||
* Set the locale for the current thread.
|
||||
*
|
||||
* @param locale the locale
|
||||
*/
|
||||
public void setLocale(Locale locale);
|
||||
|
||||
/**
|
||||
* Get the general local for the current thread, will revert to the default locale if none
|
||||
* specified for this thread.
|
||||
*
|
||||
* @return the general locale
|
||||
*/
|
||||
public Locale getLocale();
|
||||
|
||||
/**
|
||||
* Set the <b>content locale</b> for the current thread.
|
||||
*
|
||||
* @param locale the content locale
|
||||
*/
|
||||
public void setContentLocale(Locale locale);
|
||||
|
||||
|
||||
/**
|
||||
* Get the content local for the current thread.<br/>
|
||||
* This will revert to {@link #getLocale()} if no value has been defined.
|
||||
*
|
||||
* @return Returns the content locale
|
||||
*/
|
||||
public Locale getContentLocale();
|
||||
|
||||
/**
|
||||
* Searches for the nearest locale from the available options. To match any locale, pass in
|
||||
* <tt>null</tt>.
|
||||
*
|
||||
* @param templateLocale the template to search for or <tt>null</tt> to match any locale
|
||||
* @param options the available locales to search from
|
||||
* @return Returns the best match from the available options, or the <tt>null</tt> if
|
||||
* all matches fail
|
||||
*/
|
||||
public Locale getNearestLocale(Locale templateLocale, Set<Locale> options);
|
||||
|
||||
/**
|
||||
* Factory method to create a Locale from a <tt>lang_country_variant</tt> string.
|
||||
*
|
||||
* @param localeStr e.g. fr_FR
|
||||
* @return Returns the locale instance, or the {@link Locale#getDefault() default} if the
|
||||
* string is invalid
|
||||
*/
|
||||
public Locale parseLocale(String localeStr);
|
||||
|
||||
/**
|
||||
* Register a resource bundle.
|
||||
* <p>
|
||||
* This should be the bundle base path
|
||||
* eg, alfresco/messages/errors
|
||||
* or, workspace://SpaceStore/app:company_home/app:dictionary/app:labels/cm:errors
|
||||
* <p>
|
||||
* Once registered the messages will be available via getMessage, assuming the
|
||||
* bundle resource exists at the given path location.
|
||||
*
|
||||
* @param bundleBaseName the bundle base path
|
||||
*/
|
||||
public void registerResourceBundle(String bundleBasePath);
|
||||
|
||||
/**
|
||||
* Get message from registered resource bundle.
|
||||
*
|
||||
* @param messageKey message key
|
||||
* @return localised message string, null if not found
|
||||
*/
|
||||
public String getMessage(String messageKey);
|
||||
|
||||
/**
|
||||
* Get a localised message string
|
||||
*
|
||||
* @param messageKey the message key
|
||||
* @param locale override the current locale
|
||||
* @return the localised message string, null if not found
|
||||
*/
|
||||
public String getMessage(final String messageKey, final Locale locale);
|
||||
|
||||
/**
|
||||
* Get a localised message string, parameterized using standard MessageFormatter.
|
||||
*
|
||||
* @param messageKey message key
|
||||
* @param params format parameters
|
||||
* @return the localised string, null if not found
|
||||
*/
|
||||
public String getMessage(String messageKey, Object ... params);
|
||||
|
||||
/**
|
||||
* Get a localised message string, parameterized using standard MessageFormatter.
|
||||
*
|
||||
* @param messageKey the message key
|
||||
* @param locale override current locale
|
||||
* @param params the localised message string
|
||||
* @return the localised string, null if not found
|
||||
*/
|
||||
public String getMessage(String messageKey, Locale locale, Object ... params);
|
||||
|
||||
/**
|
||||
* Unregister a resource bundle
|
||||
* <p>
|
||||
* This should be the bundle base path
|
||||
* eg alfresco/messages/errors
|
||||
* or workspace://SpaceStore/app:company_home/app:dictionary/app:labels/cm:errors
|
||||
* <p>
|
||||
* Once unregistered the messages will no longer be available via getMessage
|
||||
*
|
||||
* @param bundleBaseName the bundle base path
|
||||
*/
|
||||
public void unregisterResourceBundle(String resBundlePath);
|
||||
|
||||
/**
|
||||
* Get message resource bundle from the repository
|
||||
*
|
||||
* note: also used by Web Client (ResourceBundleWrapper)
|
||||
*
|
||||
* @param storeRef store ref
|
||||
* @param path repository path (XPath)
|
||||
* @param locale locale
|
||||
* @return input stream
|
||||
*/
|
||||
public InputStream getRepoResourceBundle(StoreRef storeRef, String path, Locale locale);
|
||||
|
||||
/**
|
||||
* Get set of registered message resource bundles
|
||||
*
|
||||
* @return set of registered bundles
|
||||
*/
|
||||
public Set<String> getRegisteredBundles();
|
||||
|
||||
/**
|
||||
* Register message deployer with message service
|
||||
*
|
||||
* @param messageDeployer
|
||||
*/
|
||||
public void register(MessageDeployer messageDeployer);
|
||||
}
|
839
source/java/org/alfresco/repo/i18n/MessageServiceImpl.java
Normal file
839
source/java/org/alfresco/repo/i18n/MessageServiceImpl.java
Normal file
@@ -0,0 +1,839 @@
|
||||
package org.alfresco.repo.i18n;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.PropertyResourceBundle;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Message Service to get localised messages/strings which have been loaded from resource bundles either dynamically
|
||||
* deployed in the Repository and/or statically loaded from the Classpath.
|
||||
*
|
||||
* Also provides methods (delegated to core utility class) to access the Locale of the current thread.
|
||||
*/
|
||||
public class MessageServiceImpl implements MessageService
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(MessageServiceImpl.class);
|
||||
|
||||
/**
|
||||
* Lock objects
|
||||
*/
|
||||
private ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
private Lock readLock = lock.readLock();
|
||||
private Lock writeLock = lock.writeLock();
|
||||
|
||||
// dependencies
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private TenantService tenantService;
|
||||
|
||||
/**
|
||||
* List of registered bundles
|
||||
*/
|
||||
private SimpleCache<String, Set<String>> resourceBundleBaseNamesCache;
|
||||
|
||||
/**
|
||||
* Map of loaded bundles by Locale
|
||||
*/
|
||||
private SimpleCache<String, Map<Locale, Set<String>>> loadedResourceBundlesCache;
|
||||
|
||||
/**
|
||||
* Map of cached messaged by Locale
|
||||
*/
|
||||
private SimpleCache<String, Map<Locale, Map<String, String>>> messagesCache;
|
||||
|
||||
|
||||
private List<MessageDeployer> messageDeployers = new ArrayList<MessageDeployer>();
|
||||
|
||||
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
public void setTenantService(TenantService tenantService)
|
||||
{
|
||||
this.tenantService = tenantService;
|
||||
}
|
||||
|
||||
public void setResourceBundleBaseNamesCache(SimpleCache<String, Set<String>> resourceBundleBaseNamesCache)
|
||||
{
|
||||
this.resourceBundleBaseNamesCache = resourceBundleBaseNamesCache;
|
||||
}
|
||||
|
||||
public void setLoadedResourceBundlesCache(SimpleCache<String, Map<Locale, Set<String>>> loadedResourceBundlesCache)
|
||||
{
|
||||
this.loadedResourceBundlesCache = loadedResourceBundlesCache;
|
||||
}
|
||||
|
||||
public void setMessagesCache(SimpleCache<String, Map<Locale, Map<String, String>>>messagesCache)
|
||||
{
|
||||
this.messagesCache = messagesCache;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#setLocale(java.util.Locale)
|
||||
*/
|
||||
public void setLocale(Locale locale)
|
||||
{
|
||||
I18NUtil.setLocale(locale);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#getLocale()
|
||||
*/
|
||||
public Locale getLocale()
|
||||
{
|
||||
return I18NUtil.getLocale();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#setContentLocale(java.util.Locale)
|
||||
*/
|
||||
public void setContentLocale(Locale locale)
|
||||
{
|
||||
I18NUtil.setContentLocale(locale);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#getContentLocale()
|
||||
*/
|
||||
public Locale getContentLocale()
|
||||
{
|
||||
return I18NUtil.getContentLocale();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#getNearestLocale(java.util.Locale, java.util.Set)
|
||||
*/
|
||||
public Locale getNearestLocale(Locale templateLocale, Set<Locale> options)
|
||||
{
|
||||
return I18NUtil.getNearestLocale(templateLocale, options);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#parseLocale(java.lang.String)
|
||||
*/
|
||||
public Locale parseLocale(String localeStr)
|
||||
{
|
||||
return I18NUtil.parseLocale(localeStr);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#registerResourceBundle(java.lang.String)
|
||||
*/
|
||||
public void registerResourceBundle(String resBundlePath)
|
||||
{
|
||||
String tenantDomain = getTenantDomain();
|
||||
Set<String> tenantResourceBundleBaseNames = null;
|
||||
|
||||
try
|
||||
{
|
||||
readLock.lock();
|
||||
tenantResourceBundleBaseNames = getResourceBundleBaseNames(tenantDomain);
|
||||
}
|
||||
finally
|
||||
{
|
||||
readLock.unlock();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
writeLock.lock();
|
||||
tenantResourceBundleBaseNames.add(resBundlePath);
|
||||
|
||||
logger.info("Registered message bundle '" + resBundlePath + "'");
|
||||
|
||||
clearLoadedResourceBundles(tenantDomain); // force re-load of message cache
|
||||
}
|
||||
finally
|
||||
{
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#getMessage(java.lang.String)
|
||||
*/
|
||||
public String getMessage(String messageKey)
|
||||
{
|
||||
return getMessage(messageKey, getLocale());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#getMessage(java.lang.String, java.util.Locale)
|
||||
*/
|
||||
public String getMessage(final String messageKey, final Locale locale)
|
||||
{
|
||||
String message = null;
|
||||
|
||||
// look for message, within context of tenant if applicable
|
||||
Map<String, String> props = getLocaleProperties(locale);
|
||||
if (props != null)
|
||||
{
|
||||
// get runtime/repo managed message (if it exists)
|
||||
message = props.get(messageKey);
|
||||
}
|
||||
|
||||
if (message == null)
|
||||
{
|
||||
if (tenantService.isTenantUser())
|
||||
{
|
||||
// tenant user, with no tenant-specific message
|
||||
|
||||
//look for non-tenant-specific message
|
||||
message = AuthenticationUtil.runAs(new RunAsWork<String>()
|
||||
{
|
||||
public String doWork() throws Exception
|
||||
{
|
||||
String message = null;
|
||||
Map<String, String> props = getLocaleProperties(locale);
|
||||
if (props != null)
|
||||
{
|
||||
// get default runtime/repo managed message (if it exists)
|
||||
message = props.get(messageKey);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
|
||||
if (message == null)
|
||||
{
|
||||
// get default static message (if it exists)
|
||||
message = I18NUtil.getMessage(tenantService.getBaseName(messageKey));
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#getMessage(java.lang.String, java.lang.Object[])
|
||||
*/
|
||||
public String getMessage(String messageKey, Object ... params)
|
||||
{
|
||||
return getMessage(messageKey, getLocale(), params);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#getMessage(java.lang.String, java.util.Locale, java.lang.Object[])
|
||||
*/
|
||||
public String getMessage(String messageKey, Locale locale, Object ... params)
|
||||
{
|
||||
String message = getMessage(messageKey, locale);
|
||||
if (message != null && params != null)
|
||||
{
|
||||
message = MessageFormat.format(message, params);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#unregisterResourceBundle(java.lang.String)
|
||||
*/
|
||||
public void unregisterResourceBundle(String resBundlePath)
|
||||
{
|
||||
Map<Locale, Set<String>> loadedResourceBundlesForAllLocales;
|
||||
Map<Locale, Map<String, String>> cachedMessagesForAllLocales;
|
||||
Set<String> resourceBundleBaseNamesForAllLocales;
|
||||
|
||||
String tenantDomain = getTenantDomain();
|
||||
|
||||
try
|
||||
{
|
||||
readLock.lock();
|
||||
|
||||
// all locales
|
||||
loadedResourceBundlesForAllLocales = getLoadedResourceBundles(tenantDomain);
|
||||
cachedMessagesForAllLocales = getMessages(tenantDomain);
|
||||
resourceBundleBaseNamesForAllLocales = getResourceBundleBaseNames(tenantDomain);
|
||||
}
|
||||
finally
|
||||
{
|
||||
readLock.unlock();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
writeLock.lock();
|
||||
|
||||
// unload resource bundles for each locale (by tenant, if applicable)
|
||||
if ((loadedResourceBundlesForAllLocales != null) && (cachedMessagesForAllLocales != null))
|
||||
{
|
||||
Iterator<Locale> itr = loadedResourceBundlesForAllLocales.keySet().iterator();
|
||||
|
||||
while (itr.hasNext())
|
||||
{
|
||||
Locale locale = itr.next();
|
||||
|
||||
Set<String> loadedBundles = loadedResourceBundlesForAllLocales.get(locale);
|
||||
Map<String, String> props = cachedMessagesForAllLocales.get(locale);
|
||||
|
||||
if ((loadedBundles != null) && (props != null))
|
||||
{
|
||||
if (loadedBundles.contains(resBundlePath))
|
||||
{
|
||||
ResourceBundle resourcebundle = null;
|
||||
|
||||
int idx1 = resBundlePath.indexOf(StoreRef.URI_FILLER);
|
||||
|
||||
if (idx1 != -1)
|
||||
{
|
||||
// load from repository
|
||||
int idx2 = resBundlePath.indexOf("/", idx1+3);
|
||||
|
||||
String store = resBundlePath.substring(0, idx2);
|
||||
String path = resBundlePath.substring(idx2);
|
||||
|
||||
StoreRef storeRef = tenantService.getName(new StoreRef(store));
|
||||
|
||||
InputStream resBundleStream = getRepoResourceBundle(storeRef, path, locale);
|
||||
|
||||
try
|
||||
{
|
||||
resourcebundle = new PropertyResourceBundle(resBundleStream);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
throw new RuntimeException("Failed to read message resource bundle from repository " + resBundlePath + " : " + ioe);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// load from classpath
|
||||
resourcebundle = ResourceBundle.getBundle(resBundlePath, locale);
|
||||
}
|
||||
|
||||
// unload from the cached messages
|
||||
Enumeration<String> enumKeys = resourcebundle.getKeys();
|
||||
while (enumKeys.hasMoreElements() == true)
|
||||
{
|
||||
String key = enumKeys.nextElement();
|
||||
props.remove(key);
|
||||
}
|
||||
|
||||
loadedBundles.remove(resBundlePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unregister resource bundle
|
||||
if (resourceBundleBaseNamesForAllLocales != null)
|
||||
{
|
||||
resourceBundleBaseNamesForAllLocales.remove(resBundlePath);
|
||||
logger.info("Unregistered message bundle '" + resBundlePath + "'");
|
||||
}
|
||||
|
||||
clearLoadedResourceBundles(tenantDomain); // force re-load of message cache
|
||||
}
|
||||
finally
|
||||
{
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the messages for a locale.
|
||||
* <p>
|
||||
* Will use cache where available otherwise will load into cache from bundles.
|
||||
*
|
||||
* @param locale the locale
|
||||
* @return message map
|
||||
*/
|
||||
private Map<String, String> getLocaleProperties(Locale locale)
|
||||
{
|
||||
Set<String> loadedBundles = null;
|
||||
Map<String, String> props = null;
|
||||
|
||||
int loadedBundleCount = 0;
|
||||
|
||||
String tenantDomain = getTenantDomain();
|
||||
boolean init = false;
|
||||
|
||||
Map<Locale, Set<String>> tenantLoadedResourceBundles = null;
|
||||
Map<Locale, Map<String, String>> tenantCachedMessages = null;
|
||||
Set<String> tenantResourceBundleBaseNames = null;
|
||||
|
||||
try
|
||||
{
|
||||
readLock.lock();
|
||||
|
||||
tenantLoadedResourceBundles = getLoadedResourceBundles(tenantDomain);
|
||||
loadedBundles = tenantLoadedResourceBundles.get(locale);
|
||||
|
||||
tenantCachedMessages = getMessages(tenantDomain);
|
||||
props = tenantCachedMessages.get(locale);
|
||||
|
||||
tenantResourceBundleBaseNames = getResourceBundleBaseNames(tenantDomain);
|
||||
loadedBundleCount = tenantResourceBundleBaseNames.size();
|
||||
}
|
||||
finally
|
||||
{
|
||||
readLock.unlock();
|
||||
}
|
||||
|
||||
if (loadedBundles == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
writeLock.lock();
|
||||
loadedBundles = new HashSet<String>();
|
||||
tenantLoadedResourceBundles.put(locale, loadedBundles);
|
||||
init = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
if (props == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
writeLock.lock();
|
||||
|
||||
props = new HashMap<String, String>();
|
||||
tenantCachedMessages.put(locale, props);
|
||||
init = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
if ((loadedBundles.size() != loadedBundleCount) || (init == true))
|
||||
{
|
||||
try
|
||||
{
|
||||
writeLock.lock();
|
||||
|
||||
// get registered resource bundles
|
||||
Set<String> resBundleBaseNames = getResourceBundleBaseNames(tenantDomain);
|
||||
|
||||
int count = 0;
|
||||
|
||||
// load resource bundles for given locale (by tenant, if applicable)
|
||||
for (String resBundlePath : resBundleBaseNames)
|
||||
{
|
||||
if (loadedBundles.contains(resBundlePath) == false)
|
||||
{
|
||||
ResourceBundle resourcebundle = null;
|
||||
|
||||
int idx1 = resBundlePath.indexOf(StoreRef.URI_FILLER);
|
||||
|
||||
if (idx1 != -1)
|
||||
{
|
||||
// load from repository
|
||||
int idx2 = resBundlePath.indexOf("/", idx1+3);
|
||||
|
||||
String store = resBundlePath.substring(0, idx2);
|
||||
String path = resBundlePath.substring(idx2);
|
||||
|
||||
StoreRef storeRef = tenantService.getName(new StoreRef(store));
|
||||
|
||||
InputStream resBundleStream = getRepoResourceBundle(storeRef, path, locale);
|
||||
|
||||
try
|
||||
{
|
||||
resourcebundle = new PropertyResourceBundle(resBundleStream);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
throw new RuntimeException("Failed to read message resource bundle from repository " + resBundlePath + " : " + ioe);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// load from classpath
|
||||
resourcebundle = ResourceBundle.getBundle(resBundlePath, locale);
|
||||
}
|
||||
|
||||
Enumeration<String> enumKeys = resourcebundle.getKeys();
|
||||
while (enumKeys.hasMoreElements() == true)
|
||||
{
|
||||
String key = enumKeys.nextElement();
|
||||
props.put(key, resourcebundle.getString(key));
|
||||
}
|
||||
|
||||
loadedBundles.add(resBundlePath);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Message bundles (x " + count + ") loaded for locale " + locale);
|
||||
}
|
||||
finally
|
||||
{
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#getRepoResourceBundle(org.alfresco.service.cmr.repository.StoreRef, java.lang.String, java.util.Locale)
|
||||
*/
|
||||
public InputStream getRepoResourceBundle(StoreRef storeRef, String path, Locale locale)
|
||||
{
|
||||
InputStream resBundleStream = null;
|
||||
|
||||
// TODO - need to replace basic strategy with a more complete
|
||||
// search & instantiation strategy similar to ResourceBundle.getBundle()
|
||||
// Consider search query with basename* and then apply strategy ...
|
||||
|
||||
SearchService searchService = serviceRegistry.getSearchService();
|
||||
NamespaceService resolver = serviceRegistry.getNamespaceService();
|
||||
|
||||
NodeRef rootNode = serviceRegistry.getNodeService().getRootNode(storeRef);
|
||||
|
||||
// first attempt - with locale
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, path+"_"+locale+".properties", null, resolver, false);
|
||||
|
||||
if ((nodeRefs == null) || (nodeRefs.size() == 0))
|
||||
{
|
||||
// second attempt - basename
|
||||
nodeRefs = searchService.selectNodes(rootNode, path+".properties", null, resolver, false);
|
||||
|
||||
if ((nodeRefs == null) || (nodeRefs.size() == 0))
|
||||
{
|
||||
throw new RuntimeException("Could not find message resource bundle " + storeRef + path);
|
||||
}
|
||||
}
|
||||
|
||||
if (nodeRefs.size() > 1)
|
||||
{
|
||||
throw new RuntimeException("Found more than one message resource bundle " + storeRef + path);
|
||||
}
|
||||
else
|
||||
{
|
||||
NodeRef messageResourceNodeRef = nodeRefs.get(0);
|
||||
|
||||
ContentReader cr = serviceRegistry.getContentService().getReader(messageResourceNodeRef, ContentModel.PROP_CONTENT);
|
||||
resBundleStream = cr.getContentInputStream();
|
||||
}
|
||||
|
||||
return resBundleStream;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.tenant.TenantDeployer#onEnableTenant()
|
||||
*/
|
||||
public void onEnableTenant()
|
||||
{
|
||||
// NOOP - refer to DictionaryRepositoryBootstrap
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.tenant.TenantDeployer#onDisableTenant()
|
||||
*/
|
||||
public void onDisableTenant()
|
||||
{
|
||||
destroy(); // will be called in context of tenant
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.tenant.TenantDeployer#init()
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
// initialise empty message service
|
||||
String tenantDomain = getTenantDomain();
|
||||
|
||||
putResourceBundleBaseNames(tenantDomain, new HashSet<String>());
|
||||
putLoadedResourceBundles(tenantDomain, new HashMap<Locale, Set<String>>());
|
||||
putMessages(tenantDomain, new HashMap<Locale, Map<String, String>>());
|
||||
|
||||
logger.info("Empty message service initialised");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.tenant.TenantDeployer#destroy()
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
// used by reset and also as callback when destroying tenant(s) during shutdown
|
||||
String tenantDomain = getTenantDomain();
|
||||
|
||||
removeLoadedResourceBundles(tenantDomain);
|
||||
removeMessages(tenantDomain);
|
||||
removeResourceBundleBaseNames(tenantDomain);
|
||||
|
||||
logger.info("Messages cache destroyed (all locales)");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#getRegisteredBundles()
|
||||
*/
|
||||
public Set<String> getRegisteredBundles()
|
||||
{
|
||||
try
|
||||
{
|
||||
readLock.lock();
|
||||
return getResourceBundleBaseNames(getTenantDomain());
|
||||
}
|
||||
finally
|
||||
{
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> getResourceBundleBaseNames(String tenantDomain)
|
||||
{
|
||||
Set<String> resourceBundleBaseNames = resourceBundleBaseNamesCache.get(tenantDomain);
|
||||
|
||||
if (resourceBundleBaseNames == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// assume caller has read lock - upgrade lock manually
|
||||
readLock.unlock();
|
||||
writeLock.lock();
|
||||
|
||||
reset(tenantDomain); // reset caches - may have been invalidated (e.g. in a cluster)
|
||||
resourceBundleBaseNames = resourceBundleBaseNamesCache.get(tenantDomain);
|
||||
}
|
||||
finally
|
||||
{
|
||||
readLock.lock(); // reacquire read without giving up write lock
|
||||
writeLock.unlock(); // unlock write, still hold read - caller must unlock the read
|
||||
}
|
||||
|
||||
if (resourceBundleBaseNames == null)
|
||||
{
|
||||
// unexpected
|
||||
throw new AlfrescoRuntimeException("Failed to re-initialise resourceBundleBaseNamesCache " + tenantDomain);
|
||||
}
|
||||
}
|
||||
|
||||
return resourceBundleBaseNames;
|
||||
}
|
||||
|
||||
private void putResourceBundleBaseNames(String tenantDomain, Set<String> resourceBundleBaseNames)
|
||||
{
|
||||
resourceBundleBaseNamesCache.put(tenantDomain, resourceBundleBaseNames);
|
||||
}
|
||||
|
||||
private void removeResourceBundleBaseNames(String tenantDomain)
|
||||
{
|
||||
if (resourceBundleBaseNamesCache.get(tenantDomain) != null)
|
||||
{
|
||||
resourceBundleBaseNamesCache.get(tenantDomain).clear();
|
||||
resourceBundleBaseNamesCache.remove(tenantDomain);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Locale, Set<String>> getLoadedResourceBundles(String tenantDomain)
|
||||
{
|
||||
Map<Locale, Set<String>> loadedResourceBundles = loadedResourceBundlesCache.get(tenantDomain);
|
||||
|
||||
if (loadedResourceBundles == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// assume caller has read lock - upgrade lock manually
|
||||
readLock.unlock();
|
||||
writeLock.lock();
|
||||
|
||||
reset(tenantDomain); // reset caches - may have been invalidated (e.g. in a cluster)
|
||||
loadedResourceBundles = loadedResourceBundlesCache.get(tenantDomain);
|
||||
}
|
||||
finally
|
||||
{
|
||||
readLock.lock(); // reacquire read without giving up write lock
|
||||
writeLock.unlock(); // unlock write, still hold read - caller must unlock the read
|
||||
}
|
||||
|
||||
if (loadedResourceBundles == null)
|
||||
{
|
||||
// unexpected
|
||||
throw new AlfrescoRuntimeException("Failed to re-initialise loadedResourceBundlesCache " + tenantDomain);
|
||||
}
|
||||
}
|
||||
|
||||
return loadedResourceBundles;
|
||||
}
|
||||
|
||||
private void putLoadedResourceBundles(String tenantDomain, Map<Locale, Set<String>> loadedResourceBundles)
|
||||
{
|
||||
loadedResourceBundlesCache.put(tenantDomain, loadedResourceBundles);
|
||||
}
|
||||
|
||||
private void removeLoadedResourceBundles(String tenantDomain)
|
||||
{
|
||||
if (loadedResourceBundlesCache.get(tenantDomain) != null)
|
||||
{
|
||||
loadedResourceBundlesCache.get(tenantDomain).clear();
|
||||
loadedResourceBundlesCache.remove(tenantDomain);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearLoadedResourceBundles(String tenantDomain)
|
||||
{
|
||||
if (loadedResourceBundlesCache.get(tenantDomain) != null)
|
||||
{
|
||||
loadedResourceBundlesCache.get(tenantDomain).clear();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Locale, Map<String, String>> getMessages(String tenantDomain)
|
||||
{
|
||||
Map<Locale, Map<String, String>> messages = messagesCache.get(tenantDomain);
|
||||
|
||||
if (messages == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// assume caller has read lock - upgrade lock manually
|
||||
readLock.unlock();
|
||||
writeLock.lock();
|
||||
|
||||
reset(tenantDomain); // reset caches - may have been invalidated (e.g. in a cluster)
|
||||
messages = messagesCache.get(tenantDomain);
|
||||
}
|
||||
finally
|
||||
{
|
||||
readLock.lock(); // reacquire read without giving up write lock
|
||||
writeLock.unlock(); // unlock write, still hold read - caller must unlock the read
|
||||
}
|
||||
|
||||
if (messages == null)
|
||||
{
|
||||
// unexpected
|
||||
throw new AlfrescoRuntimeException("Failed to re-initialise messagesCache " + tenantDomain);
|
||||
}
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
private void putMessages(String tenantDomain, Map<Locale, Map<String, String>> messages)
|
||||
{
|
||||
messagesCache.put(tenantDomain, messages);
|
||||
}
|
||||
|
||||
private void removeMessages(String tenantDomain)
|
||||
{
|
||||
if (messagesCache.get(tenantDomain) != null)
|
||||
{
|
||||
messagesCache.get(tenantDomain).clear();
|
||||
messagesCache.remove(tenantDomain);
|
||||
}
|
||||
}
|
||||
|
||||
// local helper - returns tenant domain (or empty string if default non-tenant)
|
||||
private String getTenantDomain()
|
||||
{
|
||||
return tenantService.getCurrentUserDomain();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.i18n.MessageService#register(org.alfresco.repo.i18n.MessageDeployer)
|
||||
*/
|
||||
public void register(MessageDeployer messageDeployer)
|
||||
{
|
||||
if (! messageDeployers.contains(messageDeployer))
|
||||
{
|
||||
messageDeployers.add(messageDeployer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the message service
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
reset(getTenantDomain());
|
||||
}
|
||||
|
||||
private void reset(String tenantDomain)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Resetting messages ...");
|
||||
}
|
||||
|
||||
String userName;
|
||||
if (tenantDomain == "")
|
||||
{
|
||||
userName = AuthenticationUtil.getSystemUserName();
|
||||
}
|
||||
else
|
||||
{
|
||||
userName = tenantService.getDomainUser(TenantService.ADMIN_BASENAME, tenantDomain);
|
||||
}
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork()
|
||||
{
|
||||
destroy();
|
||||
init();
|
||||
|
||||
for (final MessageDeployer messageDeployer : messageDeployers)
|
||||
{
|
||||
messageDeployer.initMessages();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}, userName);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("... resetting messages completed");
|
||||
}
|
||||
}
|
||||
}
|
356
source/java/org/alfresco/repo/i18n/MessageServiceImplTest.java
Normal file
356
source/java/org/alfresco/repo/i18n/MessageServiceImplTest.java
Normal file
@@ -0,0 +1,356 @@
|
||||
package org.alfresco.repo.i18n;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
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.security.AuthenticationService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
|
||||
/**
|
||||
* Message Service unit tests
|
||||
*
|
||||
*/
|
||||
public class MessageServiceImplTest extends BaseSpringTest implements MessageDeployer
|
||||
{
|
||||
private MessageService messageService;
|
||||
private NodeService nodeService;
|
||||
private AuthenticationService authenticationService;
|
||||
private MutableAuthenticationDao authenticationDAO;
|
||||
private ContentService contentService;
|
||||
|
||||
private static final String BASE_BUNDLE_NAME = "testMessages";
|
||||
private static final String BASE_RESOURCE_CLASSPATH = "org/alfresco/repo/i18n/";
|
||||
|
||||
|
||||
private static final String PARAM_VALUE = "television";
|
||||
private static final String MSG_YES = "msg_yes";
|
||||
private static final String MSG_NO = "msg_no";
|
||||
private static final String MSG_PARAMS = "msg_params";
|
||||
private static final String VALUE_YES = "Yes";
|
||||
private static final String VALUE_NO = "No";
|
||||
private static final String VALUE_PARAMS = "What no " + PARAM_VALUE + "?";
|
||||
private static final String VALUE_FR_YES = "Oui";
|
||||
private static final String VALUE_FR_NO = "Non";
|
||||
private static final String VALUE_FR_PARAMS = "Que non " + PARAM_VALUE + "?";
|
||||
|
||||
/**
|
||||
* Test user details
|
||||
*/
|
||||
private static final String PWD = "admin";
|
||||
private static final String USER_NAME = "admin";
|
||||
|
||||
/**
|
||||
* Test store ref
|
||||
*/
|
||||
private StoreRef testStoreRef;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
// Get the services by name from the application context
|
||||
messageService = (MessageService)applicationContext.getBean("messageService");
|
||||
nodeService = (NodeService)applicationContext.getBean("nodeService");
|
||||
authenticationService = (AuthenticationService)applicationContext.getBean("authenticationService");
|
||||
authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("alfDaoImpl");
|
||||
contentService = (ContentService) applicationContext.getBean("contentService");
|
||||
|
||||
// Re-set the current locale to be the default
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
messageService.setLocale(Locale.getDefault());
|
||||
}
|
||||
|
||||
private void setupRepo() throws Exception
|
||||
{
|
||||
authenticationService.clearCurrentSecurityContext();
|
||||
|
||||
// Create a test workspace
|
||||
this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
|
||||
|
||||
// Get a reference to the root node
|
||||
NodeRef rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
|
||||
|
||||
// Create an authenticate the user
|
||||
if(!authenticationDAO.userExists(USER_NAME))
|
||||
{
|
||||
authenticationService.createAuthentication(USER_NAME, PWD.toCharArray());
|
||||
}
|
||||
|
||||
// Store test messages in repo
|
||||
String pattern = "classpath*:" + BASE_RESOURCE_CLASSPATH + BASE_BUNDLE_NAME + "*";
|
||||
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
|
||||
Resource[] resources = resolver.getResources(pattern);
|
||||
|
||||
if (resources != null)
|
||||
{
|
||||
for (int i = 0; i < resources.length; i++)
|
||||
{
|
||||
String filename = resources[i].getFilename();
|
||||
addMessageResource(rootNodeRef, filename, resources[i].getInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
// Authenticate
|
||||
authenticationService.authenticate(USER_NAME, PWD.toCharArray());
|
||||
}
|
||||
|
||||
private void addMessageResource(NodeRef rootNodeRef, String name, InputStream resourceStream) throws Exception
|
||||
{
|
||||
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
|
||||
contentProps.put(ContentModel.PROP_NAME, name);
|
||||
|
||||
ChildAssociationRef association = nodeService.createNode(rootNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
|
||||
ContentModel.TYPE_CONTENT,
|
||||
contentProps);
|
||||
|
||||
NodeRef content = association.getChildRef();
|
||||
|
||||
ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
|
||||
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.setEncoding("UTF-8");
|
||||
|
||||
writer.putContent(resourceStream);
|
||||
resourceStream.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the set and get methods
|
||||
*/
|
||||
public void testSetAndGet()
|
||||
{
|
||||
// Check that the default locale is returned
|
||||
assertEquals(Locale.getDefault(), messageService.getLocale());
|
||||
|
||||
// Set the locals
|
||||
messageService.setLocale(Locale.CANADA_FRENCH);
|
||||
assertEquals(Locale.CANADA_FRENCH, messageService.getLocale());
|
||||
|
||||
// Reset the locale
|
||||
messageService.setLocale(null);
|
||||
assertEquals(Locale.getDefault(), messageService.getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get message from repository
|
||||
*/
|
||||
public void testGetMessagesLoadedFromRepo() throws Exception
|
||||
{
|
||||
setupRepo();
|
||||
|
||||
// Check with no bundles loaded
|
||||
assertNull(messageService.getMessage(MSG_NO));
|
||||
|
||||
// Register the bundle
|
||||
messageService.registerResourceBundle(testStoreRef + "/cm:" + BASE_BUNDLE_NAME);
|
||||
|
||||
getMessages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting a parameterised message from repository
|
||||
*/
|
||||
public void testGetMessagesWithParamsLoadedFromRepo() throws Exception
|
||||
{
|
||||
setupRepo();
|
||||
|
||||
// Check with no bundles loaded
|
||||
assertNull(messageService.getMessage(MSG_PARAMS, new Object[]{PARAM_VALUE}));
|
||||
|
||||
// Register the bundle
|
||||
messageService.registerResourceBundle(testStoreRef + "/cm:" + BASE_BUNDLE_NAME);
|
||||
|
||||
getMessagesWithParams();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test get message from classpath
|
||||
*/
|
||||
public void testGetMessagesLoadedFromClasspath() throws Exception
|
||||
{
|
||||
// Check with no bundles loaded
|
||||
assertNull(messageService.getMessage(MSG_NO));
|
||||
|
||||
// Register the bundle
|
||||
messageService.registerResourceBundle(BASE_RESOURCE_CLASSPATH + BASE_BUNDLE_NAME);
|
||||
|
||||
getMessages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting a parameterised message from classpath
|
||||
*/
|
||||
public void testGetMessagesWithParamsLoadedFromClasspath() throws Exception
|
||||
{
|
||||
// Check with no bundles loaded
|
||||
assertNull(messageService.getMessage(MSG_PARAMS, new Object[]{PARAM_VALUE}));
|
||||
|
||||
// Register the bundle
|
||||
messageService.registerResourceBundle(BASE_RESOURCE_CLASSPATH + BASE_BUNDLE_NAME);
|
||||
|
||||
getMessagesWithParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test register bundle (using a repository location) with uninitialised cache
|
||||
*/
|
||||
public void testRegisterBundleFromRepo() throws Exception
|
||||
{
|
||||
setupRepo();
|
||||
|
||||
// Register the bundle
|
||||
messageService.registerResourceBundle(testStoreRef + "/cm:" + BASE_BUNDLE_NAME);
|
||||
|
||||
// Test getting a message
|
||||
assertEquals(VALUE_YES, messageService.getMessage(MSG_YES));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test register bundle (using a classpath location) with uninitialised cache
|
||||
*/
|
||||
public void testRegisterBundleFromClasspath() throws Exception
|
||||
{
|
||||
// Register the bundle
|
||||
messageService.registerResourceBundle(BASE_RESOURCE_CLASSPATH + BASE_BUNDLE_NAME);
|
||||
|
||||
// Test getting a message
|
||||
assertEquals(VALUE_YES, messageService.getMessage(MSG_YES));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test forced reset
|
||||
*/
|
||||
public void testReset() throws Exception
|
||||
{
|
||||
// Check with no bundles loaded
|
||||
assertNull(messageService.getMessage(MSG_YES));
|
||||
|
||||
messageService.register(this); // register with message service to allow reset (via initMessages callback)
|
||||
|
||||
initMessages();
|
||||
|
||||
// Test getting a message
|
||||
assertEquals(VALUE_YES, messageService.getMessage(MSG_YES));
|
||||
|
||||
// Force a reset
|
||||
((MessageServiceImpl)messageService).reset();
|
||||
|
||||
// Test getting a message
|
||||
assertEquals(VALUE_YES, messageService.getMessage(MSG_YES));
|
||||
}
|
||||
|
||||
public void initMessages()
|
||||
{
|
||||
// Register the bundle
|
||||
messageService.registerResourceBundle(BASE_RESOURCE_CLASSPATH + BASE_BUNDLE_NAME);
|
||||
}
|
||||
|
||||
public void testLocaleMatching()
|
||||
{
|
||||
Set<Locale> options = new HashSet<Locale>(13);
|
||||
options.add(Locale.FRENCH); // fr
|
||||
options.add(Locale.FRANCE); // fr_FR
|
||||
options.add(Locale.CANADA); // en_CA
|
||||
options.add(Locale.CANADA_FRENCH); // fr_CA
|
||||
options.add(Locale.CHINESE); // zh
|
||||
options.add(Locale.TRADITIONAL_CHINESE); // zh_TW
|
||||
options.add(Locale.SIMPLIFIED_CHINESE); // zh_CN
|
||||
// add some variants
|
||||
Locale fr_FR_1 = new Locale("fr", "FR", "1");
|
||||
Locale zh_CN_1 = new Locale("zh", "CN", "1");
|
||||
Locale zh_CN_2 = new Locale("zh", "CN", "2");
|
||||
Locale zh_CN_3 = new Locale("zh", "CN", "3");
|
||||
options.add(zh_CN_1); // zh_CN_1
|
||||
options.add(zh_CN_2); // zh_CN_2
|
||||
|
||||
Set<Locale> chineseMatches = new HashSet<Locale>(3);
|
||||
chineseMatches.add(Locale.SIMPLIFIED_CHINESE);
|
||||
chineseMatches.add(zh_CN_1);
|
||||
chineseMatches.add(zh_CN_2);
|
||||
|
||||
Set<Locale> frenchMatches = new HashSet<Locale>(3);
|
||||
frenchMatches.add(Locale.FRANCE);
|
||||
|
||||
// check
|
||||
assertEquals(Locale.CHINA, messageService.getNearestLocale(Locale.CHINA, options));
|
||||
assertEquals(Locale.CHINESE, messageService.getNearestLocale(Locale.CHINESE, options));
|
||||
assertEquals(zh_CN_1, messageService.getNearestLocale(zh_CN_1, options));
|
||||
assertEquals(zh_CN_2, messageService.getNearestLocale(zh_CN_2, options));
|
||||
assertTrue(chineseMatches.contains(messageService.getNearestLocale(zh_CN_3, options))); // must match the last variant - but set can have any order an IBM JDK differs!
|
||||
assertEquals(Locale.FRANCE, messageService.getNearestLocale(fr_FR_1, options)); // same here
|
||||
|
||||
// now test the match for just anything
|
||||
Locale na_na_na = new Locale("", "", "");
|
||||
Locale check = messageService.getNearestLocale(na_na_na, options);
|
||||
assertNotNull("Expected some kind of value back", check);
|
||||
}
|
||||
|
||||
public void testLocaleParsing()
|
||||
{
|
||||
assertEquals(Locale.FRANCE, messageService.parseLocale("fr_FR"));
|
||||
assertEquals(new Locale("en", "GB", "cockney"), messageService.parseLocale("en_GB_cockney"));
|
||||
assertEquals(new Locale("en", "GB", ""), messageService.parseLocale("en_GB"));
|
||||
assertEquals(new Locale("en", "", ""), messageService.parseLocale("en"));
|
||||
assertEquals(Locale.getDefault(), messageService.parseLocale(""));
|
||||
}
|
||||
|
||||
private void getMessages()
|
||||
{
|
||||
// Check default values
|
||||
assertEquals(VALUE_YES, messageService.getMessage(MSG_YES));
|
||||
assertEquals(VALUE_NO, messageService.getMessage(MSG_NO));
|
||||
|
||||
// Check not existant value
|
||||
assertNull(messageService.getMessage("bad_key"));
|
||||
|
||||
// Change the locale and re-test
|
||||
messageService.setLocale(new Locale("fr", "FR"));
|
||||
|
||||
// Check values
|
||||
assertEquals(VALUE_FR_YES, messageService.getMessage(MSG_YES));
|
||||
assertEquals(VALUE_FR_NO, messageService.getMessage(MSG_NO));
|
||||
|
||||
// Check values when overriding the locale
|
||||
assertEquals(VALUE_YES, messageService.getMessage(MSG_YES, Locale.getDefault()));
|
||||
assertEquals(VALUE_NO, messageService.getMessage(MSG_NO, Locale.getDefault()));
|
||||
}
|
||||
|
||||
private void getMessagesWithParams()
|
||||
{
|
||||
// Check the default value
|
||||
assertEquals(VALUE_PARAMS, messageService.getMessage(MSG_PARAMS, new Object[]{PARAM_VALUE}));
|
||||
|
||||
// Change the locale and re-test
|
||||
messageService.setLocale(new Locale("fr", "FR"));
|
||||
|
||||
// Check the default value
|
||||
assertEquals(VALUE_FR_PARAMS, messageService.getMessage(MSG_PARAMS, new Object[]{PARAM_VALUE}));
|
||||
|
||||
// Check values when overriding the locale
|
||||
assertEquals(VALUE_PARAMS, messageService.getMessage(MSG_PARAMS, Locale.getDefault(), new Object[]{PARAM_VALUE}));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
msg_yes=Yes
|
||||
msg_no=No
|
||||
msg_params=What no {0}?
|
||||
msg_error=This is an error message. \n This is on a new line.
|
@@ -0,0 +1,4 @@
|
||||
msg_yes=Oui
|
||||
msg_no=Non
|
||||
msg_params=Que non {0}?
|
||||
msg_error=C'est un message d'erreur. \n C'est sur une nouvelle ligne.
|
@@ -29,6 +29,7 @@ import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
@@ -58,6 +59,7 @@ public class WorkflowPackageImpl implements WorkflowPackageComponent
|
||||
private NamespaceService namespaceService;
|
||||
private PermissionService permissionService;
|
||||
private NodeRef systemWorkflowContainer = null;
|
||||
private TenantService tenantService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -96,6 +98,14 @@ public class WorkflowPackageImpl implements WorkflowPackageComponent
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tenantService tenant service
|
||||
*/
|
||||
public void setTenantService(TenantService tenantService)
|
||||
{
|
||||
this.tenantService = tenantService;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -197,16 +207,31 @@ public class WorkflowPackageImpl implements WorkflowPackageComponent
|
||||
*/
|
||||
private NodeRef getSystemWorkflowContainer()
|
||||
{
|
||||
if (systemWorkflowContainer == null)
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
NodeRef systemContainer = findSystemContainer();
|
||||
systemWorkflowContainer = findSystemWorkflowContainer(systemContainer);
|
||||
if (systemWorkflowContainer == null)
|
||||
NodeRef tenantSystemWorkflowContainer = findSystemWorkflowContainer(systemContainer);
|
||||
if (tenantSystemWorkflowContainer == null)
|
||||
{
|
||||
throw new WorkflowException("Unable to find system workflow folder - does not exist.");
|
||||
}
|
||||
|
||||
return tenantSystemWorkflowContainer;
|
||||
}
|
||||
return systemWorkflowContainer;
|
||||
else
|
||||
{
|
||||
if (systemWorkflowContainer == null)
|
||||
{
|
||||
NodeRef systemContainer = findSystemContainer();
|
||||
systemWorkflowContainer = findSystemWorkflowContainer(systemContainer);
|
||||
if (systemWorkflowContainer == null)
|
||||
{
|
||||
throw new WorkflowException("Unable to find system workflow folder - does not exist.");
|
||||
}
|
||||
}
|
||||
return systemWorkflowContainer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,11 +248,24 @@ public class WorkflowPackageImpl implements WorkflowPackageComponent
|
||||
throw new WorkflowException("Unable to locate workflow system container - path not specified");
|
||||
}
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(systemContainer, path, null, namespaceService, false);
|
||||
if (nodeRefs != null && nodeRefs.size() > 0)
|
||||
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
systemWorkflowContainer = nodeRefs.get(0);
|
||||
NodeRef tenantSystemWorkflowContainer = null;
|
||||
if (nodeRefs != null && nodeRefs.size() > 0)
|
||||
{
|
||||
tenantSystemWorkflowContainer = nodeRefs.get(0);
|
||||
}
|
||||
return tenantSystemWorkflowContainer;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nodeRefs != null && nodeRefs.size() > 0)
|
||||
{
|
||||
systemWorkflowContainer = nodeRefs.get(0);
|
||||
}
|
||||
return systemWorkflowContainer;
|
||||
}
|
||||
return systemWorkflowContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -37,11 +37,12 @@ import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.i18n.MessageService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authority.AuthorityDAO;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.repo.workflow.BPMEngine;
|
||||
import org.alfresco.repo.workflow.TaskComponent;
|
||||
import org.alfresco.repo.workflow.WorkflowComponent;
|
||||
@@ -128,6 +129,8 @@ public class JBPMEngine extends BPMEngine
|
||||
protected DictionaryService dictionaryService;
|
||||
protected NamespaceService namespaceService;
|
||||
protected NodeService nodeService;
|
||||
private TenantService tenantService;
|
||||
private MessageService messageService;
|
||||
protected ServiceRegistry serviceRegistry;
|
||||
protected PersonService personService;
|
||||
protected AuthorityDAO authorityDAO;
|
||||
@@ -203,6 +206,26 @@ public class JBPMEngine extends BPMEngine
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Tenant Service
|
||||
*
|
||||
* @param tenantService
|
||||
*/
|
||||
public void setTenantService(TenantService tenantService)
|
||||
{
|
||||
this.tenantService = tenantService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Message Service
|
||||
*
|
||||
* @param messageService
|
||||
*/
|
||||
public void setMessageService(MessageService messageService)
|
||||
{
|
||||
this.messageService = messageService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Person Service
|
||||
@@ -343,7 +366,7 @@ public class JBPMEngine extends BPMEngine
|
||||
}
|
||||
catch(JbpmException e)
|
||||
{
|
||||
throw new WorkflowException("Failed to deploy workflow definition", e);
|
||||
throw new WorkflowException("Failed to undeploy workflow definition", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,7 +386,20 @@ public class JBPMEngine extends BPMEngine
|
||||
List<ProcessDefinition> processDefs = (List<ProcessDefinition>)graphSession.findLatestProcessDefinitions();
|
||||
List<WorkflowDefinition> workflowDefs = new ArrayList<WorkflowDefinition>(processDefs.size());
|
||||
for (ProcessDefinition processDef : processDefs)
|
||||
{
|
||||
{
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
try
|
||||
{
|
||||
tenantService.checkDomain(processDef.getName());
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
// deliberately skip this one - due to domain mismatch
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
WorkflowDefinition workflowDef = createWorkflowDefinition(processDef);
|
||||
workflowDefs.add(workflowDef);
|
||||
}
|
||||
@@ -394,6 +430,19 @@ public class JBPMEngine extends BPMEngine
|
||||
List<WorkflowDefinition> workflowDefs = new ArrayList<WorkflowDefinition>(processDefs.size());
|
||||
for (ProcessDefinition processDef : processDefs)
|
||||
{
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
try
|
||||
{
|
||||
tenantService.checkDomain(processDef.getName());
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
// deliberately skip this one - due to domain mismatch
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
WorkflowDefinition workflowDef = createWorkflowDefinition(processDef);
|
||||
workflowDefs.add(workflowDef);
|
||||
}
|
||||
@@ -420,7 +469,7 @@ public class JBPMEngine extends BPMEngine
|
||||
{
|
||||
// retrieve process
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.getProcessDefinition(getJbpmId(workflowDefinitionId));
|
||||
ProcessDefinition processDefinition = getProcessDefinition(graphSession, workflowDefinitionId);
|
||||
return processDefinition == null ? null : createWorkflowDefinition(processDefinition);
|
||||
}
|
||||
});
|
||||
@@ -443,8 +492,8 @@ public class JBPMEngine extends BPMEngine
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDef = graphSession.findLatestProcessDefinition(createLocalId(workflowName));
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDef = graphSession.findLatestProcessDefinition(tenantService.getName(createLocalId(workflowName)));
|
||||
return processDef == null ? null : createWorkflowDefinition(processDef);
|
||||
}
|
||||
});
|
||||
@@ -469,7 +518,7 @@ public class JBPMEngine extends BPMEngine
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
List<ProcessDefinition> processDefs = (List<ProcessDefinition>)graphSession.findAllProcessDefinitionVersions(createLocalId(workflowName));
|
||||
List<ProcessDefinition> processDefs = (List<ProcessDefinition>)graphSession.findAllProcessDefinitionVersions(tenantService.getName(createLocalId(workflowName)));
|
||||
List<WorkflowDefinition> workflowDefs = new ArrayList<WorkflowDefinition>(processDefs.size());
|
||||
for (ProcessDefinition processDef : processDefs)
|
||||
{
|
||||
@@ -521,6 +570,19 @@ public class JBPMEngine extends BPMEngine
|
||||
protected ProcessDefinition getProcessDefinition(GraphSession graphSession, String workflowDefinitionId)
|
||||
{
|
||||
ProcessDefinition processDefinition = graphSession.getProcessDefinition(getJbpmId(workflowDefinitionId));
|
||||
|
||||
if ((processDefinition != null) && (tenantService.isEnabled()))
|
||||
{
|
||||
try
|
||||
{
|
||||
tenantService.checkDomain(processDefinition.getName()); // throws exception if domain mismatch
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
processDefinition = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (processDefinition == null)
|
||||
{
|
||||
throw new WorkflowException("Workflow definition '" + workflowDefinitionId + "' does not exist");
|
||||
@@ -528,7 +590,7 @@ public class JBPMEngine extends BPMEngine
|
||||
return processDefinition;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Workflow Instance Management...
|
||||
//
|
||||
@@ -641,7 +703,7 @@ public class JBPMEngine extends BPMEngine
|
||||
{
|
||||
// retrieve workflow
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessInstance processInstance = graphSession.getProcessInstance(getJbpmId(workflowId));
|
||||
ProcessInstance processInstance = getProcessInstance(graphSession, workflowId);
|
||||
return processInstance == null ? null : createWorkflowInstance(processInstance);
|
||||
}
|
||||
});
|
||||
@@ -661,6 +723,19 @@ public class JBPMEngine extends BPMEngine
|
||||
protected ProcessInstance getProcessInstance(GraphSession graphSession, String workflowId)
|
||||
{
|
||||
ProcessInstance processInstance = graphSession.getProcessInstance(getJbpmId(workflowId));
|
||||
|
||||
if ((processInstance != null) && (tenantService.isEnabled()))
|
||||
{
|
||||
try
|
||||
{
|
||||
tenantService.checkDomain(processInstance.getProcessDefinition().getName()); // throws exception if domain mismatch
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
processInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (processInstance == null)
|
||||
{
|
||||
throw new WorkflowException("Workflow instance '" + workflowId + "' does not exist");
|
||||
@@ -1132,6 +1207,19 @@ public class JBPMEngine extends BPMEngine
|
||||
List<WorkflowTask> workflowTasks = new ArrayList<WorkflowTask>(tasks.size());
|
||||
for (TaskInstance task : tasks)
|
||||
{
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
try
|
||||
{
|
||||
tenantService.checkDomain(task.getTask().getProcessDefinition().getName());
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
// deliberately skip this one - due to domain mismatch
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
WorkflowTask workflowTask = createWorkflowTask(task);
|
||||
workflowTasks.add(workflowTask);
|
||||
}
|
||||
@@ -1352,6 +1440,19 @@ public class JBPMEngine extends BPMEngine
|
||||
protected TaskInstance getTaskInstance(TaskMgmtSession taskSession, String taskId)
|
||||
{
|
||||
TaskInstance taskInstance = taskSession.getTaskInstance(getJbpmId(taskId));
|
||||
|
||||
if ((taskInstance != null) && (tenantService.isEnabled()))
|
||||
{
|
||||
try
|
||||
{
|
||||
tenantService.checkDomain(taskInstance.getTask().getProcessDefinition().getName()); // throws exception if domain mismatch
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
taskInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (taskInstance == null)
|
||||
{
|
||||
throw new WorkflowException("Task instance '" + taskId + "' does not exist");
|
||||
@@ -1550,7 +1651,7 @@ public class JBPMEngine extends BPMEngine
|
||||
{
|
||||
// retrieve task
|
||||
TaskMgmtSession taskSession = context.getTaskMgmtSession();
|
||||
TaskInstance taskInstance = taskSession.getTaskInstance(getJbpmId(taskId));
|
||||
TaskInstance taskInstance = getTaskInstance(taskSession, taskId);
|
||||
return taskInstance == null ? null : createWorkflowTask(taskInstance);
|
||||
}
|
||||
});
|
||||
@@ -1641,6 +1742,11 @@ public class JBPMEngine extends BPMEngine
|
||||
throw new JbpmException("Failed to parse process definition from jBPM xml stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
compiledDef.def.setName(tenantService.getName(compiledDef.def.getName()));
|
||||
}
|
||||
|
||||
return compiledDef;
|
||||
}
|
||||
@@ -2423,7 +2529,8 @@ public class JBPMEngine extends BPMEngine
|
||||
{
|
||||
String key = StringUtils.replace(displayId, ":", "_");
|
||||
key += "." + labelKey;
|
||||
String label = I18NUtil.getMessage(key);
|
||||
String label = messageService.getMessage(key);
|
||||
|
||||
return (label == null) ? defaultLabel : label;
|
||||
}
|
||||
|
||||
@@ -2434,13 +2541,26 @@ public class JBPMEngine extends BPMEngine
|
||||
*/
|
||||
private NodeRef getCompanyHome()
|
||||
{
|
||||
// TODO: Determine if caching is required
|
||||
List<NodeRef> refs = serviceRegistry.getSearchService().selectNodes(nodeService.getRootNode(companyHomeStore), companyHomePath, null, namespaceService, false);
|
||||
if (refs.size() != 1)
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
throw new IllegalStateException("Invalid company home path: " + companyHomePath + " - found: " + refs.size());
|
||||
try
|
||||
{
|
||||
return tenantService.getRootNode(nodeService, serviceRegistry.getSearchService(), namespaceService, companyHomePath, nodeService.getRootNode(companyHomeStore));
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
throw new IllegalStateException("Invalid company home path: " + companyHomePath + ": " + re.getMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
List<NodeRef> refs = serviceRegistry.getSearchService().selectNodes(nodeService.getRootNode(companyHomeStore), companyHomePath, null, namespaceService, false);
|
||||
if (refs.size() != 1)
|
||||
{
|
||||
throw new IllegalStateException("Invalid company home path: " + companyHomePath + " - found: " + refs.size());
|
||||
}
|
||||
return refs.get(0);
|
||||
}
|
||||
return refs.get(0);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -2474,6 +2594,12 @@ public class JBPMEngine extends BPMEngine
|
||||
protected WorkflowNode createWorkflowNode(Node node)
|
||||
{
|
||||
String processName = node.getProcessDefinition().getName();
|
||||
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
tenantService.checkDomain(processName); // throws exception if domain mismatch
|
||||
}
|
||||
|
||||
WorkflowNode workflowNode = new WorkflowNode();
|
||||
workflowNode.name = node.getName();
|
||||
workflowNode.title = getLabel(processName + ".node." + workflowNode.name, TITLE_LABEL, workflowNode.name);
|
||||
@@ -2502,6 +2628,11 @@ public class JBPMEngine extends BPMEngine
|
||||
*/
|
||||
protected WorkflowTransition createWorkflowTransition(Transition transition)
|
||||
{
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
tenantService.checkDomain(transition.getProcessDefinition().getName()); // throws exception if domain mismatch
|
||||
}
|
||||
|
||||
WorkflowTransition workflowTransition = new WorkflowTransition();
|
||||
workflowTransition.id = transition.getName();
|
||||
Node node = transition.getFrom();
|
||||
@@ -2529,6 +2660,11 @@ public class JBPMEngine extends BPMEngine
|
||||
*/
|
||||
protected WorkflowInstance createWorkflowInstance(ProcessInstance instance)
|
||||
{
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
tenantService.checkDomain(instance.getProcessDefinition().getName()); // throws exception if domain mismatch
|
||||
}
|
||||
|
||||
WorkflowInstance workflowInstance = new WorkflowInstance();
|
||||
workflowInstance.id = createGlobalId(new Long(instance.getId()).toString());
|
||||
workflowInstance.description = (String)instance.getContextInstance().getVariable(mapQNameToName(WorkflowModel.PROP_WORKFLOW_DESCRIPTION));
|
||||
@@ -2562,8 +2698,13 @@ public class JBPMEngine extends BPMEngine
|
||||
*/
|
||||
protected WorkflowDefinition createWorkflowDefinition(ProcessDefinition definition)
|
||||
{
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
tenantService.checkDomain(definition.getName()); // throws exception if domain mismatch
|
||||
}
|
||||
|
||||
final Task startTask = definition.getTaskMgmtDefinition().getStartTask();
|
||||
final String name = definition.getName();
|
||||
String name = tenantService.getBaseName(definition.getName());
|
||||
final String title = getLabel(name + ".workflow", TITLE_LABEL, name);
|
||||
final String description = getLabel(name + ".workflow", DESC_LABEL, title);
|
||||
return new WorkflowDefinition(createGlobalId(new Long(definition.getId()).toString()),
|
||||
@@ -2585,7 +2726,12 @@ public class JBPMEngine extends BPMEngine
|
||||
protected WorkflowTask createWorkflowTask(TaskInstance task)
|
||||
{
|
||||
String processName = task.getTask().getProcessDefinition().getName();
|
||||
|
||||
|
||||
if (tenantService.isEnabled())
|
||||
{
|
||||
tenantService.checkDomain(processName); // throws exception if domain mismatch
|
||||
}
|
||||
|
||||
WorkflowTask workflowTask = new WorkflowTask();
|
||||
workflowTask.id = createGlobalId(new Long(task.getId()).toString());
|
||||
workflowTask.name = task.getName();
|
||||
|
Reference in New Issue
Block a user