Merge DEV/V3.4-BUG-FIX to HEAD (28799-28800,28864,28875,28879,28916,28941,28956,28970,28993)

28993: HomeFolderProviderSynchronizer: Provider used for LDAP to continue to use username as home folder name directly under .../app:company_home/app:user_homes
   Property spaces.user_homes.regex.pattern now set to "" rather than "^(..)" which would have given a single level hash structure.
   28970: Merge DEV/ALAN/HOME_FOLDER to DEV/V3.4-BUG-FIX
      28947: - Introduction of version 2 HomeFolderProvider2 and re-factor of version 1
        so that the code used to create the folders is now in the HomeFolderManager.
      - Re-factor homeFolderProviderSynchronizer to handle HomeFolderProvider2.
      - Addition of AbstractHomeFolderProvider.V2Adaptor to allow external providers
        that extend AbstractHomeFolderPathProvider to be handled by
        homeFolderProviderSynchronizer.
      28860: Minor change to class comment and removed unused imports
      28858: ALF-4727 Hashed home folder provider added and used by default for LDAP sync users  - based on Romain Guinot work.
      ALF-7797 HomeFolderProviderSynchronizer added to move existing users (normally those added by LDAP sync) into location preferred by home folder provider.
      - HomeFolderProviderSynchronizer bug fixes
        - tenant accounts supported for first time
        - addition of a phase to create parent folders before moving home folder to avoid a race condition
        - check for conditions that would result in FileExistExceptions as we don't want a the transaction to be discarded as this results in retries.  
      - HomeFolderProviderSynchronizerTest integration test including tenant services
      - HomeFolderManager now sets the HOME_FOLDER_PROVIDER if it uses a default when HOME_FOLDER_PROVIDER is not set.
      - AbstractHomeFolderProvider clears cache when path reset as it will be invalid.
      - UIDBasedHomeFolderProvider.createNewParent creates its own mutable List as the one passed in may not be mutable.
      28580: Save code changes - added comments to do with LDAP syn overriding the HFP value and related to this added a global property to keep empty parent folders. 
      28347: HomeFolderProviderSynchronizer
      - issue to do with new run of sync having created a user via UI that has a home folder as one of the parent folders.
      - issue to do with catching exception when creating temporary folder - transaction is gone
      - give up if error in any phase
      28298: Addition of HomeFolderPathProvider (based on Romain's work) and addition of HomeFolderProviderSynchronizer.
   28956: Merged DEV to V3.4-BUG-FIX
      ALF-9428: Multitenancy users not preserved after upgrade from 3.2.2.7 to 3.4.2
                - Provide correct RunAs context in FixUserQNamesPatch batching.
   28941: ALF-9361 : CLONE -sync Flat IMAP client with Alfresco is slow and inaccurate
   28916: ALF-9421 The AlfrescoJavaScript action now includes company home in the JavaScript scope.
   28879: Fixed ALF-9296: Alfresco Dashboard: Impossible to approve/reject task from My Tasks dashlet on My Alfresco
   28875: Fixed ALF-6329: SPANISH - Share, translation on Transfer Target configuration
   28864: Message:
   ALF-9430: RuntimeExec waitForCompletion logic is obscure
    - Only a single flag 'isCompleted'
    - Set flag in try-finally
    - Added notify()
   However, the wait() code doesn't, in practice, get called because the waitForCompletion is synchronized with the run()
   and is called a while after the reading thread is triggered.  So the logic is less obscure and safer for the finally.
   28800: File for rev 28799: ALF-9240
   28799: Merged DEV to V3.4-BUG-FIX
      28797: ALF-9240: Issue with adding an aspect with large multivalued list
             Added unit test to stress, but could not reproduce

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28995 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2011-07-13 16:47:03 +00:00
parent aa700571db
commit 86f9dfea17
31 changed files with 3836 additions and 293 deletions

View File

@@ -87,7 +87,7 @@ public class AlfrescoAssignment extends JBPMSpringAssignmentHandler
if (actorValStr.startsWith("#{"))
{
String expression = actorValStr.substring(2, actorValStr.length() -1);
Object eval = AlfrescoJavaScript.executeScript(executionContext, services, expression, null);
Object eval = AlfrescoJavaScript.executeScript(executionContext, services, expression, null, null);
if (eval == null)
{
throw new WorkflowException("actor expression '" + actorValStr + "' evaluates to null");
@@ -128,7 +128,7 @@ public class AlfrescoAssignment extends JBPMSpringAssignmentHandler
if (pooledactorValStr.startsWith("#{"))
{
String expression = pooledactorValStr.substring(2, pooledactorValStr.length() -1);
Object eval = AlfrescoJavaScript.executeScript(executionContext, services, expression, null);
Object eval = AlfrescoJavaScript.executeScript(executionContext, services, expression, null, null);
if (eval == null)
{
throw new WorkflowException("pooledactors expression '" + pooledactorValStr + "' evaluates to null");

View File

@@ -20,16 +20,17 @@ package org.alfresco.repo.workflow.jbpm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.model.Repository;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.cmr.workflow.WorkflowException;
import org.dom4j.Element;
@@ -65,16 +66,19 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
private static JpdlXmlReader jpdlReader = new JpdlXmlReader((InputSource)null);
private ServiceRegistry services;
private NodeRef companyHome;
private Element script;
private String runas;
/* (non-Javadoc)
* @see org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler#initialiseHandler(org.springframework.beans.factory.BeanFactory)
/**
* {@inheritDoc}
*/
@Override
protected void initialiseHandler(BeanFactory factory)
{
services = (ServiceRegistry)factory.getBean(ServiceRegistry.SERVICE_REGISTRY);
this.services = (ServiceRegistry)factory.getBean(ServiceRegistry.SERVICE_REGISTRY);
Repository repositoryHelper = (Repository)factory.getBean("repositoryHelper");
this.companyHome = repositoryHelper.getCompanyHome();
}
/* (non-Javadoc)
@@ -122,7 +126,7 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
String user = AuthenticationUtil.getFullyAuthenticatedUser();
if (runas == null && user !=null)
{
return executeScript(executionContext, services, expression, variableAccesses);
return executeScript(executionContext, services, expression, variableAccesses, companyHome);
}
else
{
@@ -134,21 +138,20 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
{
validateRunAsUser();
}
return executeScriptAs(runAsUser, expression, executionContext, services, variableAccesses);
return executeScriptAs(runAsUser, expression, executionContext, variableAccesses);
}
}
private static Object executeScriptAs(String runAsUser,
private Object executeScriptAs(String runAsUser,
final String expression,
final ExecutionContext executionContext,
final ServiceRegistry services,
final List<VariableAccess> variableAccesses) {
// execute as specified runAsUser
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
{
public Object doWork() throws Exception
{
return executeScript(executionContext, services, expression, variableAccesses);
return executeScript(executionContext, services, expression, variableAccesses,companyHome);
}
}, runAsUser);
}
@@ -252,11 +255,12 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
* @param services Alfresco service registry
* @param expression script to execute
* @param variableAccesses (optional) list of jBPM variables to map into script (all, if not supplied)
* @param companyHome TODO
* @return script result
*/
public static Object executeScript(ExecutionContext context, ServiceRegistry services, String expression, List<VariableAccess> variableAccesses)
public static Object executeScript(ExecutionContext context, ServiceRegistry services, String expression, List<VariableAccess> variableAccesses, NodeRef companyHome)
{
Map<String, Object> inputMap = createInputMap(context, services, variableAccesses);
Map<String, Object> inputMap = createInputMap(services, companyHome, context, variableAccesses);
ScriptService scriptService = services.getScriptService();
scriptService.buildCoreModel(inputMap);
Object result = scriptService.executeScriptString(expression, inputMap);
@@ -329,26 +333,25 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
* Construct map of arguments to pass to script
*
* Based on the <variable> elements of the action configuration.
*
* @param companyHome TODO
* @param executionContext the execution context
* @param variableAccesses the variable configuration
*
* @return the map of script arguments
*/
private static Map<String, Object> createInputMap(ExecutionContext executionContext, ServiceRegistry services, List<VariableAccess> variableAccesses)
private static Map<String, Object> createInputMap(ServiceRegistry services, NodeRef companyHome, ExecutionContext executionContext, List<VariableAccess> variableAccesses)
{
Map<String, Object> inputMap = new HashMap<String, Object>();
ScriptService scriptService = services.getScriptService();
// initialise global script variables
JBPMNode personNode = getPersonNode(executionContext, services);
if (personNode != null)
NodeRef person = getPersonNode(services);
NodeRef userHome = null;
if (person != null)
{
inputMap.put("person", personNode );
NodeRef homeSpace = (NodeRef)services.getNodeService().getProperty(personNode.getNodeRef(), ContentModel.PROP_HOMEFOLDER);
if (homeSpace != null)
{
inputMap.put("userhome", new JBPMNode(homeSpace, services));
}
NodeService nodeService = services.getNodeService();
userHome = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
}
Map<String, Object> inputMap = scriptService.buildDefaultModel(person, companyHome, userHome, null, null, null);
// initialise process variables
Token token = executionContext.getToken();
@@ -405,15 +408,12 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
}
private static JBPMNode getPersonNode(ExecutionContext executionContext, ServiceRegistry services) {
private static NodeRef getPersonNode(ServiceRegistry services) {
String userName = AuthenticationUtil.getFullyAuthenticatedUser();
if(userName != null)
{
NodeRef person = services.getPersonService().getPerson(userName);
if(person !=null)
{
return new JBPMNode(person, services);
}
return person;
}
return null;
}

View File

@@ -1,12 +1,16 @@
package org.alfresco.repo.workflow.jbpm;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.Serializable;
import java.util.HashMap;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.jscript.ScriptNode;
import org.alfresco.repo.model.Repository;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.scripts.ScriptException;
@@ -30,6 +34,8 @@ import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
{
@@ -193,6 +199,39 @@ public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
assertEquals(docLibB, nodeService.getPrimaryParent(doc).getParentRef());
}
public void testScopeVariables() throws Exception
{
String admin = AuthenticationUtil.getAdminUserName();
AuthenticationUtil.setFullyAuthenticatedUser(admin);
NodeRef person = personService.getPerson(admin);
Serializable userHome = nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
String key = "result";
// Check person node set.
Element script = buildScript("executionContext.setVariable('" + key + "', person)");
scriptHandler.setScript(script);
scriptHandler.execute(context);
ScriptNode value = (ScriptNode) variables.get(key);
assertEquals(person, value.getNodeRef());
// Check user home set.
script = buildScript("executionContext.setVariable('" + key + "', userhome)");
scriptHandler.setScript(script);
scriptHandler.execute(context);
value = (ScriptNode) variables.get(key);
assertEquals(userHome, value.getNodeRef());
// Check company home set.
NodeRef companyHome = repository.getCompanyHome();
script = buildScript("executionContext.setVariable('" + key + "', companyhome)");
scriptHandler.setScript(script);
scriptHandler.execute(context);
value = (ScriptNode) variables.get(key);
assertEquals(companyHome, value.getNodeRef());
}
private Element buildScript(String expression) {
Element script = DocumentHelper.createElement("script");
script.setText(expression);
@@ -203,7 +242,8 @@ public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
@SuppressWarnings("deprecation")
protected void onSetUp() throws Exception {
super.onSetUp();
services = (ServiceRegistry) applicationContext.getBean("ServiceRegistry");
this.services = (ServiceRegistry) applicationContext.getBean("ServiceRegistry");
repository = (Repository) applicationContext.getBean("repositoryHelper");
personService = services.getPersonService();
createUser(BASIC_USER);
@@ -214,7 +254,25 @@ public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
when(context.getContextInstance()).thenReturn(contextInstance);
variables = new HashMap<String, Object>();
when(contextInstance.getVariables()).thenReturn(variables);
when(contextInstance.getVariables((Token) any())).thenReturn(variables);
when(contextInstance.getVariables( any(Token.class))).thenReturn(variables);
when(context.getVariable(anyString())).thenAnswer(new Answer<Object>()
{
public Object answer(InvocationOnMock invocation) throws Throwable
{
String key = (String)invocation.getArguments()[0];
return variables.get(key);
}
});
doAnswer(new Answer<Void>()
{
public Void answer(InvocationOnMock invocation) throws Throwable
{
String key = (String)invocation.getArguments()[0];
Object value= invocation.getArguments()[1];
variables.put(key, value);
return null;
}
}).when(context).setVariable(anyString(), any());
}
private void createUser(String userName)
@@ -236,9 +294,9 @@ public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
public static class TestUserStore {
private String runAsUser;
private String fullUser;
private JBPMNode person = null;
private ScriptNode person = null;
public void storeUsers(JBPMNode user)
public void storeUsers(ScriptNode user)
{
fullUser = AuthenticationUtil.getFullyAuthenticatedUser();
runAsUser = AuthenticationUtil.getRunAsUser();

View File

@@ -148,7 +148,7 @@ public class ForEachFork extends JBPMSpringActionHandler
private Collection<?> evaluateForEachExpression(final ExecutionContext executionContext, String forEachText)
{
String expression = forEachText.substring(2, forEachText.length() -1);
Object result = AlfrescoJavaScript.executeScript(executionContext, services, expression, null);
Object result = AlfrescoJavaScript.executeScript(executionContext, services, expression, null, null);
if (result == null)
{
throw new WorkflowException("forEach expression '" + forEachText + "' evaluates to null");