mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Overview:
--------- Overhaul of some areas of Workflow JavaScript API implementation after 2nd review - see details. Details: -------- - Fleshed out some of the JavaDocs that needed more detail - Package changed from org.alfresco.repo.workflow.jsapi to org.alfresco.repo.workflow.jscript - Prefixed class names of Bean classes with Jscript to keep them distinct from the names of similar classes in org.alfresco.service.cmr.workflow (no longer have to namespace these latter classes everywhere in the code) - Added JscriptWorkflowTransition and JscriptWorkflowNode classes - fixing code in various backing beans where instance variables exposed as public by mistake and not as they should using getters - fixing up problems with some collections/objects being passed back not being scriptable - Converting backing beans to all be Serializable and having UID set to appropriate values given by using serialver utility - Changing code so that all Java List to JavaScript array conversions use ValueConvertor.convertValueForScript(...) helper method (much cleaner code) - Fixing code so that root scripting scope reference available in all backing beans and retro-fitting all their contructors to receive the scope as a parameter so that it is available if needed - Change constructors of backing beans to be consistent with each other i.e. all of them receiving Service Registry as parameter, and not a mixture of Service Registry for some and Workflow Service for others - Fixed places where Map was being passed back instead of ScriptableQNameMap - Some of the member variables in JscriptWorkflowNode and JscriptWorkflowTransition were not exposed as properties - this was fixed up - Changed WorkflowManager so that WorkflowService is no longer injected. It does not need to be injected as it can be derived from the RegistryService which is already being injected Files: ------ M – Repository/config/alfresco/script-services-context.xml M – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowManager.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/ D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowDefinition.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowInstance.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowManager.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowPath.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowTask.java A – Repository/source/java/org/alfreco/repo/workflow/jscript/ A – Repository/source/java/org/alfreco/repo/workflow/jscript/JscriptWorkflowDefinition.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowInstance.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowNode.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowPath.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowTask.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowTransition.java D – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowDefinition.java D – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowInstance.java D – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowPath.java D – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowTask.java git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6904 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* 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 received 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.jscript.ScriptableQNameMap;
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowInstance;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
public class JscriptWorkflowDefinition implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = 1641614201321129544L;
|
||||
|
||||
/** Service Registry */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
/** Workflow definition id */
|
||||
private final String id;
|
||||
|
||||
/** Workflow definition name */
|
||||
private final String name;
|
||||
|
||||
/** Workflow definition version */
|
||||
private final String version;
|
||||
|
||||
/** Workflow definition title */
|
||||
private final String title;
|
||||
|
||||
/** Workflow definition description */
|
||||
private final String description;
|
||||
|
||||
/** Root scripting scope for this object */
|
||||
private final Scriptable scope;
|
||||
|
||||
/**
|
||||
* Create a new instance of <code>WorkflowDefinition</code> from a
|
||||
* CMR workflow object model WorkflowDefinition instance
|
||||
*
|
||||
* @param cmrWorkflowDefinition an instance of WorkflowDefinition from the CMR workflow object model
|
||||
* @param serviceRegistry reference to the Service Registry
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
JscriptWorkflowDefinition(final WorkflowDefinition cmrWorkflowDefinition,
|
||||
final ServiceRegistry serviceRegistry, final Scriptable scope)
|
||||
{
|
||||
this.id = cmrWorkflowDefinition.id;
|
||||
this.name = cmrWorkflowDefinition.name;
|
||||
this.version = cmrWorkflowDefinition.version;
|
||||
this.title = cmrWorkflowDefinition.title;
|
||||
this.description = cmrWorkflowDefinition.description;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of WorkflowDefinition from scratch
|
||||
*
|
||||
* @param id workflow definition ID
|
||||
* @param name name of workflow definition
|
||||
* @param version version of workflow definition
|
||||
* @param title title of workflow definition
|
||||
* @param description description of workflow definition
|
||||
* @param serviceRegistry reference to the Service Registry
|
||||
* @param scope root scripting scope for this object
|
||||
*/
|
||||
JscriptWorkflowDefinition(final String id, final String name, final String version,
|
||||
final String title, final String description, ServiceRegistry serviceRegistry,
|
||||
final Scriptable scope)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of <code>id</code> property
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of <code>name</code> property
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of <code>version</code> property
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of <code>title</code> property
|
||||
*
|
||||
* @return the title
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of <code>description</code> property
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start workflow instance from workflow definition
|
||||
*
|
||||
* @param workflowPackage workflow package object to 'attach' to the new workflow
|
||||
* instance
|
||||
* @param properties properties (map of key-value pairs) used to populate the
|
||||
* start task properties
|
||||
* @return the initial workflow path
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public JscriptWorkflowPath startWorkflow(ScriptNode workflowPackage,
|
||||
ScriptableQNameMap<String, Serializable> properties)
|
||||
{
|
||||
WorkflowService workflowService = this.serviceRegistry.getWorkflowService();
|
||||
|
||||
properties.put(WorkflowModel.ASPECT_WORKFLOW_PACKAGE, workflowPackage);
|
||||
|
||||
WorkflowPath cmrWorkflowPath =
|
||||
workflowService.startWorkflow(id, properties);
|
||||
return new JscriptWorkflowPath(cmrWorkflowPath, this.serviceRegistry, this.scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active workflow instances of this workflow definition
|
||||
*
|
||||
* @return the active workflow instances spawned from this workflow definition
|
||||
*/
|
||||
public synchronized Scriptable getActiveInstances()
|
||||
{
|
||||
WorkflowService workflowService = this.serviceRegistry.getWorkflowService();
|
||||
|
||||
List<WorkflowInstance> cmrWorkflowInstances = workflowService.getActiveWorkflows(this.id);
|
||||
ArrayList<Serializable> activeInstances = new ArrayList<Serializable>();
|
||||
for (WorkflowInstance cmrWorkflowInstance : cmrWorkflowInstances)
|
||||
{
|
||||
activeInstances.add(new JscriptWorkflowInstance(cmrWorkflowInstance, this.serviceRegistry, this.scope));
|
||||
}
|
||||
|
||||
Scriptable activeInstancesScriptable =
|
||||
(Scriptable)new ValueConverter().convertValueForScript(this.serviceRegistry, this.scope, null, activeInstances);
|
||||
|
||||
return activeInstancesScriptable;
|
||||
}
|
||||
}
|
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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 received 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowInstance;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Class representing an active or in-flight workflow
|
||||
*
|
||||
* @author glenj
|
||||
*
|
||||
*/
|
||||
public class JscriptWorkflowInstance implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = 1015996328908978487L;
|
||||
|
||||
/** Service Registry object */
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
|
||||
/** Root scripting scope for this object */
|
||||
private final Scriptable scope;
|
||||
|
||||
/** Workflow instance id */
|
||||
private final String id;
|
||||
|
||||
/** Workflow instance description */
|
||||
private final String description;
|
||||
|
||||
/** Workflow instance start date */
|
||||
private final Date startDate;
|
||||
|
||||
/** Workflow instance end date */
|
||||
private final Date endDate;
|
||||
|
||||
/** Flag this Workflow instance as active-'true' or complete-'false' */
|
||||
private final boolean active;
|
||||
|
||||
/**
|
||||
* Creates a new instance of <code>WorkflowInstance</code> from
|
||||
* scratch
|
||||
*
|
||||
* @param id ID of new workflow instance object
|
||||
* @param description Description of new workflow instance object
|
||||
* @param startDate Start Date of new workflow instance object
|
||||
* @param serviceRegistry Service Registry instance
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
JscriptWorkflowInstance(final String id, final String description, final Date startDate,
|
||||
final ServiceRegistry serviceRegistry, final Scriptable scope)
|
||||
{
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
this.active = true;
|
||||
this.startDate = startDate;
|
||||
this.endDate = null;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of <code>WorkflowInstance</code> from a
|
||||
* WorkflowInstance object from the CMR workflow object model
|
||||
*
|
||||
* @param cmrWorkflowInstance CMR workflow instance
|
||||
* @param serviceRegistry Service Registry instance
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
JscriptWorkflowInstance(final WorkflowInstance
|
||||
cmrWorkflowInstance, final ServiceRegistry serviceRegistry, final Scriptable scope)
|
||||
{
|
||||
this.id = cmrWorkflowInstance.id;
|
||||
this.description = cmrWorkflowInstance.description;
|
||||
this.active = cmrWorkflowInstance.active;
|
||||
this.startDate = cmrWorkflowInstance.startDate;
|
||||
this.endDate = cmrWorkflowInstance.endDate;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all paths for the specified workflow instance
|
||||
*/
|
||||
public Scriptable getPaths()
|
||||
{
|
||||
WorkflowService workflowService = serviceRegistry.getWorkflowService();
|
||||
|
||||
List<WorkflowPath> cmrPaths = workflowService.getWorkflowPaths(this.id);
|
||||
ArrayList<Serializable> paths = new ArrayList<Serializable>();
|
||||
for (WorkflowPath cmrPath : cmrPaths)
|
||||
{
|
||||
paths.add(new JscriptWorkflowPath(cmrPath, this.serviceRegistry, this.scope));
|
||||
}
|
||||
|
||||
Scriptable pathsScriptable =
|
||||
(Scriptable)new ValueConverter().convertValueForScript(this.serviceRegistry, this.scope, null, paths);
|
||||
|
||||
return pathsScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>id</code> property
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>description</code> property
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get state for <code>active</code> property
|
||||
*
|
||||
* @return the active
|
||||
*/
|
||||
public boolean isActive()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>startDate</code> property
|
||||
*
|
||||
* @return the startDate
|
||||
*/
|
||||
public Scriptable getStartDate()
|
||||
{
|
||||
return (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.serviceRegistry, this.scope, null, this.startDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>endDate</code> property
|
||||
*
|
||||
* @return the endDate
|
||||
*/
|
||||
public Scriptable getEndDate()
|
||||
{
|
||||
return (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.serviceRegistry, this.scope, null, this.endDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel workflow instance
|
||||
*/
|
||||
public void cancel()
|
||||
{
|
||||
serviceRegistry.getWorkflowService().cancelWorkflow(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete workflow instance
|
||||
*/
|
||||
public void delete()
|
||||
{
|
||||
serviceRegistry.getWorkflowService().deleteWorkflow(this.id);
|
||||
}
|
||||
}
|
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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 received 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowNode;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTransition;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Represents a Workflow Node within the Workflow Definition.
|
||||
*/
|
||||
public class JscriptWorkflowNode implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = 6785972019256246499L;
|
||||
|
||||
/** Name of workflow node */
|
||||
private final String name;
|
||||
|
||||
/** Localised title of workflow node */
|
||||
private final String title;
|
||||
|
||||
/** Localised description of workflow node */
|
||||
private final String description;
|
||||
|
||||
/** <code>true</code> if this workflow node is associated with a workflow task */
|
||||
private final boolean isTaskNode;
|
||||
|
||||
/** The transitions leaving this node (or null, if none) */
|
||||
private final ArrayList<JscriptWorkflowTransition> transitions;
|
||||
|
||||
/** Root scripting scope for this object */
|
||||
private final Scriptable scope;
|
||||
|
||||
/** Service Registry */
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
|
||||
/**
|
||||
* Constructor to create a new instance of this class
|
||||
*
|
||||
* @param name Name of workflow node
|
||||
* @param title Title of workflow node
|
||||
* @param description Description of workflow node
|
||||
* @param isTaskNode <code>true</code> if this node is a task node
|
||||
* @param transitions transitions leaving this node (null if none)
|
||||
* @param scope root scripting scope for this object
|
||||
* @param serviceRegistry service registry object
|
||||
*/
|
||||
JscriptWorkflowNode(String name, String title, String description,
|
||||
boolean isTaskNode, ArrayList<JscriptWorkflowTransition> transitions,
|
||||
Scriptable scope, ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.name = name;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.isTaskNode = isTaskNode;
|
||||
this.transitions = transitions;
|
||||
this.scope = scope;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to create a new instance of this class from an
|
||||
* existing instance of WorkflowNode from the CMR workflow
|
||||
* object model
|
||||
*
|
||||
* @param workflowNode CMR workflow node object to create
|
||||
* new <code>JscriptWorkflowNode</code> from
|
||||
* @param scope root scripting scope for this newly instantiated object
|
||||
* @param serviceRegistry service registry object
|
||||
*/
|
||||
JscriptWorkflowNode(WorkflowNode workflowNode, Scriptable scope, ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.name = workflowNode.name;
|
||||
this.title = workflowNode.title;
|
||||
this.description = workflowNode.description;
|
||||
this.isTaskNode = workflowNode.isTaskNode;
|
||||
this.transitions = new ArrayList<JscriptWorkflowTransition>();
|
||||
WorkflowTransition[] cmrWorkflowTransitions = workflowNode.transitions;
|
||||
for (WorkflowTransition cmrWorkflowTransition : cmrWorkflowTransitions)
|
||||
{
|
||||
transitions.add(new JscriptWorkflowTransition(cmrWorkflowTransition));
|
||||
}
|
||||
this.scope = scope;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>name</code> property
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>title</code> property
|
||||
*
|
||||
* @return the title
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>description</code> property
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>isTaskNode</code> property
|
||||
*
|
||||
* @return the isTaskNode
|
||||
*/
|
||||
public boolean isTaskNode()
|
||||
{
|
||||
return isTaskNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>transitions</code> property
|
||||
*
|
||||
* @return the transitions
|
||||
*/
|
||||
public Scriptable getTransitions()
|
||||
{
|
||||
Scriptable transitionsScriptable = (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.serviceRegistry, this.scope, null, this.transitions);
|
||||
|
||||
return transitionsScriptable;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
String transitionsList = "{";
|
||||
for (JscriptWorkflowTransition transition : this.transitions)
|
||||
{
|
||||
transitionsList += ", '" + transition + "'";
|
||||
}
|
||||
transitionsList += "}";
|
||||
return "WorkflowNode[title=" + title + ",transitions=" + transitionsList + "]";
|
||||
}
|
||||
}
|
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* 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 received 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowNode;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Class that represents a path of execution through a workflow.
|
||||
*
|
||||
* A simple workflow consists of only one root path of execution.
|
||||
* That path may branch at some subsequent transition, so that execution
|
||||
* follows multiple paths through the workflow.
|
||||
*
|
||||
* @author glenj
|
||||
*
|
||||
*/
|
||||
public class JscriptWorkflowPath implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = 8271566861210368614L;
|
||||
|
||||
/** Unique ID for workflow path */
|
||||
private final String id;
|
||||
|
||||
/** State of workflow path 'true':active 'false':complete */
|
||||
private boolean active;
|
||||
|
||||
/** Workflow node that the path has reached */
|
||||
private WorkflowNode node;
|
||||
|
||||
/** Workflow instance path is part of */
|
||||
private JscriptWorkflowInstance instance;
|
||||
|
||||
/** Service Registry object */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
/** Root scripting scope for this object */
|
||||
private final Scriptable scope;
|
||||
|
||||
/**
|
||||
* Creates a new instance of a workflow path
|
||||
*
|
||||
* @param id workflow path ID
|
||||
* @param node workflow node the path has reached
|
||||
* @param instance instance to which the workflow path belongs
|
||||
* @param serviceRegistry Service Registry object
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
JscriptWorkflowPath(final String id, final WorkflowNode node, final JscriptWorkflowInstance instance,
|
||||
final ServiceRegistry serviceRegistry, final Scriptable scope)
|
||||
{
|
||||
this.id = id;
|
||||
this.node = node;
|
||||
this.instance = instance;
|
||||
this.active = false;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of WorkflowPath from an instance of the WorkflowPath
|
||||
* class provided by the CMR workflow model
|
||||
*
|
||||
* @param cmrWorkflowPath an instance of WorkflowPath from the CMR
|
||||
* workflow object model
|
||||
* @param serviceRegistry Service Registry object
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
JscriptWorkflowPath(final WorkflowPath cmrWorkflowPath,
|
||||
final ServiceRegistry serviceRegistry, Scriptable scope)
|
||||
{
|
||||
this.id = cmrWorkflowPath.id;
|
||||
this.node = cmrWorkflowPath.node;
|
||||
this.instance = new JscriptWorkflowInstance(cmrWorkflowPath.instance, serviceRegistry, scope);
|
||||
this.active = cmrWorkflowPath.active;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a workflow path from
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>id</code> property
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>active</code> property
|
||||
*
|
||||
* @return the active
|
||||
*/
|
||||
public boolean isActive()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>node</code> property
|
||||
*
|
||||
* @return the node
|
||||
*/
|
||||
public WorkflowNode getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>instance</code> property
|
||||
*
|
||||
* @return the instance
|
||||
*/
|
||||
public JscriptWorkflowInstance getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all tasks associated with this workflow path
|
||||
*
|
||||
* @return all the tasks associated with this workflow path instance
|
||||
*/
|
||||
public Scriptable getTasks()
|
||||
{
|
||||
WorkflowService workflowService = serviceRegistry.getWorkflowService();
|
||||
|
||||
List<WorkflowTask> cmrTasks = workflowService.getTasksForWorkflowPath(id);
|
||||
ArrayList<Serializable> tasks = new ArrayList<Serializable>();
|
||||
for (WorkflowTask cmrTask : cmrTasks)
|
||||
{
|
||||
tasks.add(new JscriptWorkflowTask(cmrTask, this.serviceRegistry));
|
||||
}
|
||||
|
||||
Scriptable tasksScriptable =
|
||||
(Scriptable)new ValueConverter().convertValueForScript(this.serviceRegistry, scope, null, tasks);
|
||||
|
||||
return tasksScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal a transition to another node in the workflow
|
||||
*
|
||||
* @param transitionId ID of the transition to follow (or null, for the default transition)
|
||||
* @return the updated workflow path
|
||||
*/
|
||||
public JscriptWorkflowPath signal(String transitionId)
|
||||
{
|
||||
WorkflowPath path = serviceRegistry.getWorkflowService().signal(this.id, transitionId);
|
||||
return new JscriptWorkflowPath(path, this.serviceRegistry, this.scope);
|
||||
}
|
||||
}
|
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* 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 received 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.jscript.ScriptableQNameMap;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* This class represents a workflow task (an instance of a workflow
|
||||
* task definition)
|
||||
*
|
||||
* @author glenj
|
||||
*
|
||||
*/
|
||||
public class JscriptWorkflowTask implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = -8285971359421912313L;
|
||||
|
||||
/** Unique ID for workflow task */
|
||||
private final String id;
|
||||
|
||||
/** Name for workflow task */
|
||||
private final String name;
|
||||
|
||||
/** Title for workflow task */
|
||||
private final String title;
|
||||
|
||||
/** Description of workflow task */
|
||||
private final String description;
|
||||
|
||||
/** Properties (key/value pairs) for this Workflow Task */
|
||||
private ScriptableQNameMap<String, Serializable> properties;
|
||||
|
||||
/** Whether task is complete or not - 'true':complete, 'false':in-progress */
|
||||
private boolean complete = false;
|
||||
|
||||
/** Whether task is pooled or not */
|
||||
private boolean pooled = false;
|
||||
|
||||
/** Service Registry object */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
/**
|
||||
* Creates a new instance of a workflow task (instance of a workflow task definition)
|
||||
*
|
||||
* @param id workflow task ID
|
||||
* @param name workflow task name
|
||||
* @param title workflow task title
|
||||
* @param description workflow task description
|
||||
* @param serviceRegistry Service Registry object
|
||||
*/
|
||||
JscriptWorkflowTask(final String id, final String name, final String title,
|
||||
final String description, final ServiceRegistry serviceRegistry,
|
||||
final ScriptableQNameMap<String, Serializable> properties)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a workflow task from a WorkflowTask from the CMR
|
||||
* workflow object model
|
||||
*
|
||||
* @param cmrWorkflowTask an instance of WorkflowTask from CMR workflow object model
|
||||
* @param serviceRegistry Service Registry object
|
||||
*/
|
||||
JscriptWorkflowTask(final WorkflowTask cmrWorkflowTask,
|
||||
final ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.id = cmrWorkflowTask.id;
|
||||
this.name = cmrWorkflowTask.name;
|
||||
this.title = cmrWorkflowTask.title;
|
||||
this.description = cmrWorkflowTask.description;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
|
||||
// instantiate ScriptableQNameMap<String, Serializable> properties
|
||||
// from WorkflowTasks's Map<QName, Serializable> properties
|
||||
this.properties = new ScriptableQNameMap<String, Serializable>(
|
||||
serviceRegistry.getNamespaceService());
|
||||
|
||||
Set<QName> keys = cmrWorkflowTask.properties.keySet();
|
||||
for (QName key : keys)
|
||||
{
|
||||
Serializable value = cmrWorkflowTask.properties.get(key);
|
||||
this.properties.put(key.toString(), value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>id</code> property
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>name</code> property
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>title</code> property
|
||||
*
|
||||
* @return the title
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>description</code> property
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>properties</code> property
|
||||
*
|
||||
* @return the properties
|
||||
*/
|
||||
public Scriptable getProperties()
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the <code>properties</code> property
|
||||
*
|
||||
* @param properties the properties to set
|
||||
*/
|
||||
public void setProperties(ScriptableQNameMap<String, Serializable> properties)
|
||||
{
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the task is complete
|
||||
* 'true':complete, 'false':in-progress
|
||||
*
|
||||
* @return the complete
|
||||
*/
|
||||
public boolean isComplete()
|
||||
{
|
||||
return complete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this task is pooled or not
|
||||
*
|
||||
* @return 'true': task is pooled, 'false': task is not pooled
|
||||
*/
|
||||
public boolean isPooled()
|
||||
{
|
||||
return pooled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether task is pooled('true') or not('false')
|
||||
*
|
||||
* @param pooled the pooled to set
|
||||
*/
|
||||
public void setPooled(boolean pooled)
|
||||
{
|
||||
this.pooled = pooled;
|
||||
}
|
||||
|
||||
/**
|
||||
* End the task
|
||||
*
|
||||
* @param transition transition to end the task for
|
||||
*/
|
||||
public void endTask(String transitionId)
|
||||
{
|
||||
serviceRegistry.getWorkflowService().endTask(this.id, transitionId);
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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 received 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTransition;
|
||||
|
||||
public class JscriptWorkflowTransition implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = 8370298400161156357L;
|
||||
|
||||
/** Workflow transition id */
|
||||
private String id;
|
||||
|
||||
/** Localised workflow transition title */
|
||||
private String title;
|
||||
|
||||
/** Localised workflow transition description */
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Constructor to create a new instance of this class
|
||||
* from scratch
|
||||
*
|
||||
* @param id Workflow transition ID
|
||||
* @param title Workflow transition title
|
||||
* @param description Workflow transition description
|
||||
*/
|
||||
JscriptWorkflowTransition(String id, String title, String description)
|
||||
{
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to create a new instance of this class from an existing
|
||||
* instance of WorkflowTransition from the CMR workflow object model
|
||||
*
|
||||
* @param transition CMR WorkflowTransition object from which
|
||||
* to create a new instance of this class
|
||||
*/
|
||||
JscriptWorkflowTransition(WorkflowTransition transition)
|
||||
{
|
||||
this.id = transition.id;
|
||||
this.title = transition.title;
|
||||
this.description = transition.description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>id</code> property
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>title</code> property
|
||||
*
|
||||
* @return the title
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>description</code> property
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return "JscriptWorkflowTransition[id=" + id + ",title=" + title + ",description=" + description + "]";
|
||||
}
|
||||
}
|
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* 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 received 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowInstance;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* The Workflow Manager serves as the main entry point for scripts
|
||||
* to create and interact with workflows.
|
||||
* It is made available in the root scripting scope
|
||||
*
|
||||
* @author glenj
|
||||
*
|
||||
*/
|
||||
public class WorkflowManager extends BaseScopableProcessorExtension
|
||||
{
|
||||
/** Registry Service property */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/**
|
||||
* Sets the Service Registry property
|
||||
*
|
||||
* @param services the service registry
|
||||
*/
|
||||
public void setServiceRegistry(ServiceRegistry services)
|
||||
{
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get deployed workflow definition by ID
|
||||
*
|
||||
* @param id the workflow definition ID
|
||||
* @return the workflow definition matching the given ID
|
||||
*/
|
||||
public JscriptWorkflowDefinition getDefinition(String id)
|
||||
{
|
||||
WorkflowDefinition cmrWorkflowDefinition =
|
||||
this.services.getWorkflowService().getDefinitionById(id);
|
||||
return new JscriptWorkflowDefinition(cmrWorkflowDefinition, this.services, getScope());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tasks assigned to the current user. Note that this will only return in-progress
|
||||
* tasks.
|
||||
*
|
||||
* @return the list of assigned (in-progress) tasks
|
||||
*/
|
||||
public Scriptable getAssignedTasks()
|
||||
{
|
||||
return getAssignedTasksByState(WorkflowTaskState.IN_PROGRESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get completed tasks assigned to the current user.
|
||||
*
|
||||
* @return the list of completed tasks
|
||||
*/
|
||||
public Scriptable getCompletedTasks()
|
||||
{
|
||||
return getAssignedTasksByState(WorkflowTaskState.COMPLETED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Workflow Instance by ID
|
||||
*
|
||||
* @param workflowInstanceID ID of the workflow instance to retrieve
|
||||
* @return the workflow instance for the given ID
|
||||
*/
|
||||
public JscriptWorkflowInstance getInstance(String workflowInstanceID)
|
||||
{
|
||||
WorkflowInstance cmrWorkflowInstance = this.services.getWorkflowService().getWorkflowById(
|
||||
workflowInstanceID);
|
||||
return new JscriptWorkflowInstance(cmrWorkflowInstance, this.services, getScope());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pooled tasks
|
||||
*
|
||||
* @param authority the authority
|
||||
* @return the list of assigned tasks
|
||||
*/
|
||||
public Scriptable getPooledTasks(final String authority)
|
||||
{
|
||||
List<WorkflowTask> cmrPooledTasks = this.services.getWorkflowService().getPooledTasks(
|
||||
authority);
|
||||
ArrayList<Serializable> pooledTasks = new ArrayList<Serializable>();
|
||||
for (WorkflowTask cmrPooledTask : cmrPooledTasks)
|
||||
{
|
||||
pooledTasks.add(new JscriptWorkflowTask(cmrPooledTask, this.services));
|
||||
}
|
||||
|
||||
Scriptable pooledTasksScriptable = (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.services, getScope(), null, pooledTasks);
|
||||
return pooledTasksScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task by id
|
||||
*
|
||||
* @param id task id
|
||||
* @return the task (null if not found)
|
||||
*/
|
||||
public JscriptWorkflowTask getTask(String id)
|
||||
{
|
||||
WorkflowTask cmrWorkflowTask = this.services.getWorkflowService().getTaskById(id);
|
||||
return new JscriptWorkflowTask(cmrWorkflowTask, this.services);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task by id. Alternative method signature to <code>getTask(String id)</code> for
|
||||
* those used to the Template API
|
||||
*
|
||||
* @param id task id
|
||||
* @return the task (null if not found)
|
||||
*/
|
||||
public JscriptWorkflowTask getTaskById(String id)
|
||||
{
|
||||
return getTask(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the latest versions of the deployed, workflow definitions
|
||||
*
|
||||
* @return the latest versions of the deployed workflow definitions
|
||||
*/
|
||||
public Scriptable getLatestDefinitions()
|
||||
{
|
||||
List<WorkflowDefinition> cmrDefinitions = this.services.getWorkflowService().getDefinitions();
|
||||
ArrayList<Serializable> workflowDefs = new ArrayList<Serializable>();
|
||||
for (WorkflowDefinition cmrDefinition : cmrDefinitions)
|
||||
{
|
||||
workflowDefs.add(new JscriptWorkflowDefinition(cmrDefinition, this.services, getScope()));
|
||||
}
|
||||
|
||||
Scriptable workflowDefsScriptable = (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.services, this.getScope(), null, workflowDefs);
|
||||
return workflowDefsScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all versions of the deployed workflow definitions
|
||||
*
|
||||
* @return all versions of the deployed workflow definitions
|
||||
*/
|
||||
public Scriptable getAllDefinitions()
|
||||
{
|
||||
List<WorkflowDefinition> cmrDefinitions = this.services.getWorkflowService().getAllDefinitions();
|
||||
ArrayList<Serializable> workflowDefs = new ArrayList<Serializable>();
|
||||
for (WorkflowDefinition cmrDefinition : cmrDefinitions)
|
||||
{
|
||||
workflowDefs.add(new JscriptWorkflowDefinition(cmrDefinition, this.services, getScope()));
|
||||
}
|
||||
|
||||
Scriptable workflowDefsScriptable = (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.services, this.getScope(), null, workflowDefs);
|
||||
return workflowDefsScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a workflow package (a container of content to route through a workflow)
|
||||
*
|
||||
* @return the created workflow package
|
||||
*/
|
||||
public ScriptNode createPackage()
|
||||
{
|
||||
NodeRef node = this.services.getWorkflowService().createPackage(null);
|
||||
return new ScriptNode(node, services);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tasks assigned to the current user, filtered by workflow task state.
|
||||
* Only tasks having the specified state will be returned.
|
||||
*
|
||||
* @param state workflow task state to filter assigned tasks by
|
||||
* @return the list of assigned tasks, filtered by state
|
||||
*/
|
||||
private Scriptable getAssignedTasksByState(WorkflowTaskState state)
|
||||
{
|
||||
List<WorkflowTask> cmrAssignedTasks = this.services.getWorkflowService().getAssignedTasks(
|
||||
services.getAuthenticationService().getCurrentUserName(), state);
|
||||
ArrayList<Serializable> assignedTasks = new ArrayList<Serializable>();
|
||||
for (WorkflowTask cmrTask : cmrAssignedTasks)
|
||||
{
|
||||
assignedTasks.add(new JscriptWorkflowTask(cmrTask, this.services));
|
||||
}
|
||||
|
||||
Scriptable assignedTasksScriptable =
|
||||
(Scriptable)new ValueConverter().convertValueForScript(this.services, getScope(), null, assignedTasks);
|
||||
|
||||
return assignedTasksScriptable;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user