mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-16 17:55:15 +00:00
Workflow updates to support deployment of a workflow definition sourced from the repository (ie. node of type bpm:workflowDefinition)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6770 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
parent
e99a9a0d3d
commit
f161572b1e
@ -216,7 +216,12 @@
|
||||
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}</prop>
|
||||
<prop key="location">alfresco/bootstrap/customWebClientExtensionSpace.xml</prop>
|
||||
</props>
|
||||
|
||||
|
||||
<props>
|
||||
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}</prop>
|
||||
<prop key="location">alfresco/bootstrap/customWorkflowDefsSpace.acp</prop>
|
||||
</props>
|
||||
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
BIN
config/alfresco/bootstrap/customWorkflowDefsSpace.acp
Normal file
BIN
config/alfresco/bootstrap/customWorkflowDefsSpace.acp
Normal file
Binary file not shown.
@ -174,4 +174,6 @@ patch.AVMProperties.result=Properties were moved.
|
||||
|
||||
patch.customModels.description=Adds Models space to Data Dictionary.
|
||||
patch.customMessages.description=Adds Messages space to Data Dictionary.
|
||||
patch.customWebClientExtension.description=Adds Web Client Extension space to Data Dictionary.
|
||||
patch.customWebClientExtension.description=Adds Web Client Extension space to Data Dictionary.
|
||||
|
||||
patch.customWorkflowDefs.description=Adds Workflow Definitions space to Data Dictionary.
|
||||
|
@ -269,6 +269,32 @@
|
||||
</overrides>
|
||||
|
||||
</type>
|
||||
|
||||
<!-- -->
|
||||
<!-- Workflow Definition -->
|
||||
<!-- -->
|
||||
|
||||
<type name="bpm:workflowDefinition">
|
||||
<title>Workflow Process Definition</title>
|
||||
<parent>cm:content</parent>
|
||||
<properties>
|
||||
<property name="bpm:definitionName">
|
||||
<title>Workflow Name</title>
|
||||
<type>d:text</type>
|
||||
</property>
|
||||
<property name="bpm:engineId">
|
||||
<title>Workflow Engine Id</title>
|
||||
<type>d:text</type>
|
||||
<mandatory>true</mandatory>
|
||||
<default>jbpm</default>
|
||||
</property>
|
||||
<property name="bpm:definitionDeployed">
|
||||
<title>Workflow Deployed</title>
|
||||
<type>d:boolean</type>
|
||||
<default>false</default>
|
||||
</property>
|
||||
</properties>
|
||||
</type>
|
||||
|
||||
</types>
|
||||
|
||||
|
@ -1017,4 +1017,25 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="patch.customWorkflowDefs" class="org.alfresco.repo.admin.patch.impl.GenericBootstrapPatch" parent="basePatch" >
|
||||
<property name="id"><value>patch.customWorkflowDefs</value></property>
|
||||
<property name="description"><value>patch.customWorkflowDefs.description</value></property>
|
||||
<property name="fixesFromSchema"><value>0</value></property>
|
||||
<property name="fixesToSchema"><value>105</value></property>
|
||||
<property name="targetSchema"><value>106</value></property>
|
||||
<!-- bootstrap view -->
|
||||
<property name="importerBootstrap">
|
||||
<ref bean="spacesBootstrap" />
|
||||
</property>
|
||||
<property name="checkPath">
|
||||
<value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/app:workflow_defs</value>
|
||||
</property>
|
||||
<property name="bootstrapView">
|
||||
<props>
|
||||
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}</prop>
|
||||
<prop key="location">alfresco/bootstrap/customWorkflowDefsSpace.acp</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@ -19,4 +19,4 @@ version.build=@build-number@
|
||||
|
||||
# Schema number
|
||||
|
||||
version.schema=105
|
||||
version.schema=106
|
||||
|
@ -21,6 +21,8 @@
|
||||
<property name="authorityService" ref="authorityService"/>
|
||||
<property name="BPMEngineRegistry" ref="bpm_engineRegistry"/>
|
||||
<property name="workflowPackageComponent" ref="workflowPackageImpl"/>
|
||||
<property name="nodeService" ref="nodeService"/>
|
||||
<property name="contentService" ref="contentService"/>
|
||||
</bean>
|
||||
|
||||
<bean id="workflowPackageImpl" class="org.alfresco.repo.workflow.WorkflowPackageImpl">
|
||||
@ -106,5 +108,12 @@
|
||||
|
||||
<!-- Workflow Patch Deployer -->
|
||||
<bean id="workflowPatchDeployer" parent="workflowDeployer" singleton="false"/>
|
||||
|
||||
|
||||
<!-- Workflow Definition Type (bpm:workflowDefinition) -->
|
||||
<bean id="workflowDefinitionType" class="org.alfresco.repo.workflow.WorkflowDefinitionType" init-method="init">
|
||||
<property name="nodeService" ref="NodeService"/>
|
||||
<property name="policyComponent" ref="policyComponent"/>
|
||||
<property name="workflowService" ref="WorkflowService"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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.workflow;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.ContentServicePolicies;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDeployment;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Workflow Definition type behaviour.
|
||||
*
|
||||
* @author JanV
|
||||
*/
|
||||
public class WorkflowDefinitionType implements ContentServicePolicies.OnContentUpdatePolicy,
|
||||
NodeServicePolicies.OnUpdatePropertiesPolicy,
|
||||
NodeServicePolicies.BeforeDeleteNodePolicy
|
||||
{
|
||||
// logger
|
||||
private static Log logger = LogFactory.getLog(WorkflowDefinitionType.class);
|
||||
|
||||
/** The node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** The policy component */
|
||||
private PolicyComponent policyComponent;
|
||||
|
||||
/** The workflow service */
|
||||
private WorkflowService workflowService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the node service
|
||||
*
|
||||
* @param nodeService the node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the policy component
|
||||
*
|
||||
* @param policyComponent the policy component
|
||||
*/
|
||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||
{
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the workflow service
|
||||
*
|
||||
* @param workflowService the workflow service
|
||||
*/
|
||||
public void setWorkflowService(WorkflowService workflowService)
|
||||
{
|
||||
this.workflowService = workflowService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The initialise method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
// Register interest in the onContentUpdate policy for the workflow definition type
|
||||
policyComponent.bindClassBehaviour(
|
||||
ContentServicePolicies.ON_CONTENT_UPDATE,
|
||||
WorkflowModel.TYPE_WORKFLOW_DEF,
|
||||
new JavaBehaviour(this, "onContentUpdate"));
|
||||
|
||||
// Register interest in the onPropertyUpdate policy for the workflow definition type
|
||||
policyComponent.bindClassBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"),
|
||||
WorkflowModel.TYPE_WORKFLOW_DEF,
|
||||
new JavaBehaviour(this, "onUpdateProperties"));
|
||||
|
||||
// Register interest in the node delete policy
|
||||
policyComponent.bindClassBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
|
||||
WorkflowModel.TYPE_WORKFLOW_DEF,
|
||||
new JavaBehaviour(this, "beforeDeleteNode"));
|
||||
}
|
||||
|
||||
/**
|
||||
* On content update behaviour implementation
|
||||
*
|
||||
* @param nodeRef the node reference whose content has been updated
|
||||
*/
|
||||
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
|
||||
{
|
||||
deploy(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* On update properties behaviour implementation
|
||||
*
|
||||
* @param nodeRef the node reference
|
||||
* @param before the values of the properties before update
|
||||
* @param after the values of the properties after the update
|
||||
*/
|
||||
public void onUpdateProperties(
|
||||
NodeRef nodeRef,
|
||||
Map<QName, Serializable> before,
|
||||
Map<QName, Serializable> after)
|
||||
{
|
||||
Boolean beforeValue = (Boolean)before.get(WorkflowModel.PROP_WORKFLOW_DEF_DEPLOYED);
|
||||
Boolean afterValue = (Boolean)after.get(WorkflowModel.PROP_WORKFLOW_DEF_DEPLOYED);
|
||||
|
||||
if (afterValue != null &&
|
||||
(beforeValue == null || (beforeValue != null && afterValue != null && beforeValue.equals(afterValue) == false)))
|
||||
{
|
||||
if (afterValue.booleanValue() == true)
|
||||
{
|
||||
deploy(nodeRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
undeploy(nodeRef);
|
||||
}
|
||||
}
|
||||
else if (afterValue == null && beforeValue != null)
|
||||
{
|
||||
// Undeploy the definition since the value has been cleared
|
||||
undeploy(nodeRef);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void beforeDeleteNode(NodeRef nodeRef)
|
||||
{
|
||||
// Ignore if the node is a working copy
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) == false)
|
||||
{
|
||||
undeploy(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
private void deploy(NodeRef nodeRef)
|
||||
{
|
||||
// deploy / re-deploy
|
||||
WorkflowDeployment deployment = workflowService.deployDefinition(nodeRef);
|
||||
|
||||
if (deployment != null)
|
||||
{
|
||||
WorkflowDefinition def = deployment.definition;
|
||||
|
||||
// Update the meta data for the model
|
||||
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
|
||||
|
||||
props.put(WorkflowModel.PROP_WORKFLOW_DEF_NAME, def.getName());
|
||||
|
||||
// TODO - ability to return and handle deployment problems / warnings
|
||||
if (deployment.problems.length > 0)
|
||||
{
|
||||
for (String problem : deployment.problems)
|
||||
{
|
||||
logger.warn(problem);
|
||||
}
|
||||
}
|
||||
|
||||
nodeService.setProperties(nodeRef, props);
|
||||
}
|
||||
}
|
||||
|
||||
private void undeploy(NodeRef nodeRef)
|
||||
{
|
||||
String defName = (String)nodeService.getProperty(nodeRef, WorkflowModel.PROP_WORKFLOW_DEF_NAME);
|
||||
if (defName != null)
|
||||
{
|
||||
// Undeploy the workflow definition - all versions in JBPM
|
||||
List<WorkflowDefinition> defs = workflowService.getAllDefinitionsByName(defName);
|
||||
for (WorkflowDefinition def: defs)
|
||||
{
|
||||
logger.info("Undeploying workflow '" + defName + "' ...");
|
||||
workflowService.undeployDefinition(def.getId());
|
||||
logger.info("... undeployed '" + def.getId() + "' v" + def.getVersion());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -74,4 +74,10 @@ public interface WorkflowModel
|
||||
static final QName PROP_WORKFLOW_DEFINITION_NAME = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "workflowDefinitionName");
|
||||
static final QName PROP_WORKFLOW_INSTANCE_ID = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "workflowInstanceId");
|
||||
|
||||
// workflow definition
|
||||
static final QName TYPE_WORKFLOW_DEF = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "workflowDefinition");
|
||||
static final QName PROP_WORKFLOW_DEF_ENGINE_ID = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "engineId");
|
||||
static final QName PROP_WORKFLOW_DEF_NAME = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "definitionName");
|
||||
static final QName PROP_WORKFLOW_DEF_DEPLOYED = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "definitionDeployed");
|
||||
|
||||
}
|
@ -32,7 +32,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
@ -66,6 +70,8 @@ public class WorkflowServiceImpl implements WorkflowService
|
||||
private AuthorityService authorityService;
|
||||
private BPMEngineRegistry registry;
|
||||
private WorkflowPackageComponent workflowPackageComponent;
|
||||
private NodeService nodeService;
|
||||
private ContentService contentService;
|
||||
|
||||
|
||||
/**
|
||||
@ -98,6 +104,26 @@ public class WorkflowServiceImpl implements WorkflowService
|
||||
this.workflowPackageComponent = workflowPackageComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Node Service
|
||||
*
|
||||
* @param nodeService
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Content Service
|
||||
*
|
||||
* @param contentService
|
||||
*/
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.workflow.WorkflowService#deployDefinition(java.lang.String, java.io.InputStream, java.lang.String)
|
||||
@ -132,8 +158,15 @@ public class WorkflowServiceImpl implements WorkflowService
|
||||
*/
|
||||
public WorkflowDeployment deployDefinition(NodeRef definitionContent)
|
||||
{
|
||||
// TODO
|
||||
throw new UnsupportedOperationException();
|
||||
if (! nodeService.getType(definitionContent).equals(WorkflowModel.TYPE_WORKFLOW_DEF))
|
||||
{
|
||||
throw new WorkflowException("Node " + definitionContent + " is not of type 'bpm:workflowDefinition'");
|
||||
}
|
||||
|
||||
String engineId = (String)nodeService.getProperty(definitionContent, WorkflowModel.PROP_WORKFLOW_DEF_ENGINE_ID);
|
||||
ContentReader contentReader = contentService.getReader(definitionContent, ContentModel.PROP_CONTENT);
|
||||
|
||||
return deployDefinition(engineId, contentReader.getContentInputStream(), contentReader.getMimetype());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -321,7 +321,7 @@ public class JBPMEngine extends BPMEngine
|
||||
}
|
||||
catch(JbpmException e)
|
||||
{
|
||||
throw new WorkflowException("Failed to deploy workflow definition", e);
|
||||
throw new WorkflowException("Failed to deploy workflow definition - " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -380,7 +380,7 @@ public class JBPMEngine extends BPMEngine
|
||||
}
|
||||
catch(JbpmException e)
|
||||
{
|
||||
throw new WorkflowException("Failed to undeploy workflow definition", e);
|
||||
throw new WorkflowException("Failed to undeploy workflow definition - " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1801,8 +1801,13 @@ public class JBPMEngine extends BPMEngine
|
||||
throw new JbpmException("Failed to parse process definition from jBPM xml stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
throw new JbpmException("Failed to parse process definition - unsupported mime type '" + mimetype + "'");
|
||||
}
|
||||
|
||||
if (tenantService.isEnabled())
|
||||
if ((compiledDef != null) && tenantService.isEnabled())
|
||||
{
|
||||
compiledDef.def.setName(tenantService.getName(compiledDef.def.getName()));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user