Added tests to ensure multi-tenancy works and fixed several multi-tenancy issues in workflow.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30563 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
N Smith
2011-09-16 09:34:02 +00:00
parent 8e9f5be725
commit 6d46ef90ec
29 changed files with 1047 additions and 403 deletions

View File

@@ -54,7 +54,6 @@ import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowAdminService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowDeployment;
import org.alfresco.service.cmr.workflow.WorkflowException;
@@ -70,6 +69,8 @@ import org.alfresco.service.cmr.workflow.WorkflowTransition;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID;
import org.alfresco.util.collections.CollectionUtils;
import org.alfresco.util.collections.Function;
import org.hibernate.CacheMode;
import org.hibernate.Criteria;
import org.hibernate.FlushMode;
@@ -127,7 +128,6 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
protected AuthorityDAO authorityDAO;
protected JbpmTemplate jbpmTemplate;
protected SearchService unprotectedSearchService;
protected WorkflowAdminService workflowAdminService;
// Company Home
protected StoreRef companyHomeStore;
@@ -283,16 +283,6 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
this.unprotectedSearchService = unprotectedSearchService;
}
/**
* Sets the Workflow Admin Service
*
* @param workflowAdminService
*/
public void setWorkflowAdminService(WorkflowAdminService workflowAdminService)
{
this.workflowAdminService = workflowAdminService;
}
//
// Workflow Definition...
//
@@ -355,9 +345,9 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
// retrieve process definition from Alfresco Repository
GraphSession graphSession = context.getGraphSession();
ProcessDefinition existingDefinition = graphSession
.findLatestProcessDefinition(processDefinition.def.getName());
return (existingDefinition == null) ? false : true;
String definitionName = processDefinition.def.getName();
ProcessDefinition existingDefinition = graphSession.findLatestProcessDefinition(definitionName);
return existingDefinition != null;
}
});
}
@@ -405,61 +395,54 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.repo.workflow.WorkflowDefinitionComponent#getDefinitions()
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public List<WorkflowDefinition> getDefinitions()
{
if (workflowAdminService.isJBPMWorkflowDefinitionsVisible())
try
{
try
return (List<WorkflowDefinition>) jbpmTemplate.execute(new JbpmCallback()
{
return (List<WorkflowDefinition>)jbpmTemplate.execute(new JbpmCallback()
public Object doInJbpm(JbpmContext context)
{
public Object doInJbpm(JbpmContext context)
{
GraphSession graphSession = context.getGraphSession();
List<ProcessDefinition> processDefs = 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);
}
return workflowDefs;
}
});
}
catch (JbpmException e)
{
String msg = messageService.getMessage(ERR_GET_WORKFLOW_DEF);
throw new WorkflowException(msg, e);
}
GraphSession graphSession = context.getGraphSession();
List<ProcessDefinition> processDefs = graphSession.findLatestProcessDefinitions();
return getValidDefinitions(processDefs);
}
});
}
else
catch (JbpmException e)
{
return Collections.<WorkflowDefinition>emptyList();
String msg = messageService.getMessage(ERR_GET_WORKFLOW_DEF);
throw new WorkflowException(msg, e);
}
}
private List<WorkflowDefinition> getValidDefinitions(Collection<ProcessDefinition> definitions)
{
List<ProcessDefinition> filteredDefs = factory.filterByDomain(definitions, new Function<ProcessDefinition, String>()
{
public String apply(ProcessDefinition definition)
{
return definition.getName();
}
});
return convertDefinitions(filteredDefs);
}
private List<WorkflowDefinition> convertDefinitions(Collection<ProcessDefinition> definitions)
{
return CollectionUtils.transform(definitions, new Function<ProcessDefinition, WorkflowDefinition>()
{
public WorkflowDefinition apply(ProcessDefinition value)
{
return createWorkflowDefinition(value);
}
});
}
/*
* (non-Javadoc)
*
@@ -469,49 +452,22 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
@SuppressWarnings("unchecked")
public List<WorkflowDefinition> getAllDefinitions()
{
if (workflowAdminService.isJBPMWorkflowDefinitionsVisible())
try
{
try
return (List<WorkflowDefinition>) jbpmTemplate.execute(new JbpmCallback()
{
return (List<WorkflowDefinition>)jbpmTemplate.execute(new JbpmCallback()
public Object doInJbpm(JbpmContext context)
{
public Object doInJbpm(JbpmContext context)
{
GraphSession graphSession = context.getGraphSession();
List<ProcessDefinition> processDefs = graphSession.findAllProcessDefinitions();
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);
}
return workflowDefs;
}
});
}
catch (JbpmException e)
{
String msg = messageService.getMessage(ERR_GET_WORKFLOW_DEF);
throw new WorkflowException(msg, e);
}
GraphSession graphSession = context.getGraphSession();
List<ProcessDefinition> processDefs = graphSession.findAllProcessDefinitions();
return getValidDefinitions(processDefs);
}
});
}
else
catch (JbpmException e)
{
return Collections.<WorkflowDefinition>emptyList();
String msg = messageService.getMessage(ERR_GET_WORKFLOW_DEF);
throw new WorkflowException(msg, e);
}
}
@@ -533,7 +489,7 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
// retrieve process
GraphSession graphSession = context.getGraphSession();
ProcessDefinition processDefinition = getProcessDefinition(graphSession, workflowDefinitionId);
return processDefinition == null ? null : createWorkflowDefinition(processDefinition);
return createWorkflowDefinition(processDefinition);
}
});
}
@@ -557,12 +513,11 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
{
return (WorkflowDefinition)jbpmTemplate.execute(new JbpmCallback()
{
@SuppressWarnings("synthetic-access")
public Object doInJbpm(JbpmContext context)
{
GraphSession graphSession = context.getGraphSession();
ProcessDefinition processDef = graphSession.findLatestProcessDefinition(tenantService
.getName(createLocalId(workflowName)));
String definitionName = tenantService.getName(createLocalId(workflowName));
ProcessDefinition processDef = graphSession.findLatestProcessDefinition(definitionName);
return processDef == null ? null : createWorkflowDefinition(processDef);
}
});
@@ -592,15 +547,9 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
public Object doInJbpm(JbpmContext context)
{
GraphSession graphSession = context.getGraphSession();
List<ProcessDefinition> processDefs = graphSession.findAllProcessDefinitionVersions(tenantService
.getName(createLocalId(workflowName)));
List<WorkflowDefinition> workflowDefs = new ArrayList<WorkflowDefinition>(processDefs.size());
for (ProcessDefinition processDef : processDefs)
{
WorkflowDefinition workflowDef = createWorkflowDefinition(processDef);
workflowDefs.add(workflowDef);
}
return workflowDefs;
String definitionName = tenantService.getName(createLocalId(workflowName));
List<ProcessDefinition> processDefs = graphSession.findAllProcessDefinitionVersions(definitionName);
return convertDefinitions(processDefs);
}
});
}
@@ -1624,6 +1573,7 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
{
return (List<WorkflowTask>) jbpmTemplate.execute(new JbpmCallback()
{
@SuppressWarnings("deprecation")
public List<WorkflowTask> doInJbpm(JbpmContext context)
{
Session session = context.getSession();
@@ -1632,12 +1582,6 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
{
query.setProcessName(tenantService.getName(query.getProcessName()));
}
if ((query.getWorkflowDefinitionName() != null) && (tenantService.isEnabled()))
{
query.setWorkflowDefinitionName(tenantService.getName(query.getWorkflowDefinitionName()));
}
Criteria criteria = createTaskQueryCriteria(session, query);
List<TaskInstance> tasks = criteria.list();
return getWorkflowTasks(tasks);
@@ -1932,42 +1876,22 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
process.add(Restrictions.eq("id", getJbpmId(query.getProcessId())));
}
// process name
if (query.getProcessName() != null)
// process definition name
String definitionName = query.getWorkflowDefinitionName();
if(definitionName!=null)
{
process = (process == null) ? root.createCriteria("processInstance") : process;
Criteria processDef = process.createCriteria("processDefinition");
String processName = null;
if (tenantService.isEnabled())
{
QName baseProcessName = tenantService.getBaseName(query.getProcessName(), true);
processName = tenantService.getName(baseProcessName.toPrefixString(namespaceService));
}
else
{
processName = query.getProcessName().toPrefixString(namespaceService);
}
processDef.add(Restrictions.eq("name", processName));
definitionName = createLocalId(definitionName);
}
// Process definition name
if (query.getWorkflowDefinitionName() != null)
if(definitionName == null)
{
QName qName = query.getProcessName();
definitionName= qName == null ? null : qName.toPrefixString(namespaceService);
}
if (definitionName != null)
{
process = (process == null) ? root.createCriteria("processInstance") : process;
Criteria processDef = process.createCriteria("processDefinition");
String processName = null;
if (tenantService.isEnabled())
{
String baseProcessName = tenantService.getBaseName(query.getWorkflowDefinitionName(), true);
processName = tenantService.getName(baseProcessName);
}
else
{
processName = query.getWorkflowDefinitionName();
}
String processName = tenantService.getName(definitionName);
processDef.add(Restrictions.eq("name", processName));
}

View File

@@ -32,13 +32,11 @@ import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.workflow.BPMEngineRegistry;
import org.alfresco.repo.workflow.TaskComponent;
import org.alfresco.repo.workflow.WorkflowAdminServiceImpl;
import org.alfresco.repo.workflow.WorkflowComponent;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.repo.workflow.WorkflowPackageComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowAdminService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowDeployment;
import org.alfresco.service.cmr.workflow.WorkflowException;
@@ -70,7 +68,6 @@ public class JBPMEngineTest extends BaseAlfrescoSpringTest
private WorkflowPackageComponent packageComponent;
private PersonService personService;
private WorkflowDefinition testWorkflowDef;
private WorkflowAdminServiceImpl workflowAdminService;
private NodeRef person1;
private NodeRef person2;
private NodeRef person3;
@@ -91,10 +88,6 @@ public class JBPMEngineTest extends BaseAlfrescoSpringTest
taskComponent = registry.getTaskComponent(JBPMEngine.ENGINE_ID);
packageComponent = (WorkflowPackageComponent)applicationContext.getBean("workflowPackageImpl");
// for the purposes of the tests make sure JBPM workflow definitions are visible
this.workflowAdminService = (WorkflowAdminServiceImpl) applicationContext.getBean("workflowAdminService");
this.workflowAdminService.setJBPMWorkflowDefinitionsVisible(true);
// deploy test process messages
I18NUtil.registerResourceBundle("jbpmresources/test-messages");
@@ -573,23 +566,8 @@ public class JBPMEngineTest extends BaseAlfrescoSpringTest
List<WorkflowDefinition> defs = workflowComponent.getDefinitions();
List<WorkflowDefinition> allDefs = workflowComponent.getAllDefinitions();
// make sure both lists are populated (only if the JBPM engine is enabled)
if (workflowAdminService.isEngineEnabled(JBPMEngine.ENGINE_ID))
{
assertFalse(defs.isEmpty());
assertFalse(allDefs.isEmpty());
}
// turn off workflow definition visibility
this.workflowAdminService.setJBPMWorkflowDefinitionsVisible(false);
// retrieve workflow definitions again
defs = workflowComponent.getDefinitions();
allDefs = workflowComponent.getAllDefinitions();
// ensure the list of workflow definitions are empty
assertTrue(defs.isEmpty());
assertTrue(allDefs.isEmpty());
assertFalse(defs.isEmpty());
assertFalse(allDefs.isEmpty());
}
// public void testAssignTaskVariablesWithScript() throws Exception

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.workflow.jbpm;
import org.alfresco.repo.workflow.AbstractMultitenantWorkflowTest;
/**
* @author Nick Smith
* @since 4.0
*
*/
public class JbpmMultitenantWorkflowTest extends AbstractMultitenantWorkflowTest
{
@Override
protected String getEngine()
{
return JBPMEngine.ENGINE_ID;
}
@Override
protected String getTestDefinitionPath()
{
return "jbpmresources/test_simple_processdefinition.xml";
}
@Override
protected String getTestDefinitionKey()
{
return "jbpm$test";
}
protected String getAdhocDefinitionPath()
{
return "alfresco/workflow/adhoc_processdefinition.xml";
}
@Override
protected String getAdhocDefinitionKey()
{
return "jbpm$wf:adhoc";
}
}