mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V1.4 to HEAD
svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3987 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4133 . Removed LicenseComponent reference from projects\repository\source\java\org\alfresco\repo\descriptor\DescriptorServiceImpl.java git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4135 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -136,7 +136,7 @@ public class ManageTaskDialog extends BaseDialogBean
|
||||
logger.debug("Saving task: " + this.task.id);
|
||||
|
||||
// prepare the edited parameters for saving
|
||||
Map<QName, Serializable> params = WorkflowBean.prepareTaskParams(this.taskNode);
|
||||
Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.taskNode);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Saving task with parameters: " + params);
|
||||
@@ -262,7 +262,7 @@ public class ManageTaskDialog extends BaseDialogBean
|
||||
tx.begin();
|
||||
|
||||
// prepare the edited parameters for saving
|
||||
Map<QName, Serializable> params = WorkflowBean.prepareTaskParams(this.taskNode);
|
||||
Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.taskNode);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Transitioning task with parameters: " + params);
|
||||
@@ -399,7 +399,7 @@ public class ManageTaskDialog extends BaseDialogBean
|
||||
*/
|
||||
public void togglePackageItemComplete(ActionEvent event)
|
||||
{
|
||||
// TODO: implement this!
|
||||
// TODO: not supported yet
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
@@ -119,7 +119,7 @@ public class StartWorkflowWizard extends BaseWizardBean
|
||||
logger.debug("Starting workflow: " + this.selectedWorkflow);
|
||||
|
||||
// prepare the parameters from the current state of the property sheet
|
||||
Map<QName, Serializable> params = WorkflowBean.prepareTaskParams(this.startTaskNode);
|
||||
Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.startTaskNode);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Starting workflow with parameters: " + params);
|
||||
|
@@ -1,17 +1,13 @@
|
||||
package org.alfresco.web.bean.workflow;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
@@ -19,7 +15,6 @@ import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTransition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ISO9075;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
@@ -31,7 +26,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Managed bean used for handling workflow related features
|
||||
* Managed bean used for providing support for the workflow task dashlets
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
@@ -55,40 +50,43 @@ public class WorkflowBean
|
||||
*/
|
||||
public List<Node> getTasksToDo()
|
||||
{
|
||||
// get the current username
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
User user = Application.getCurrentUser(context);
|
||||
String userName = ISO9075.encode(user.getUserName());
|
||||
|
||||
UserTransaction tx = null;
|
||||
try
|
||||
if (this.tasks == null)
|
||||
{
|
||||
tx = Repository.getUserTransaction(context, true);
|
||||
tx.begin();
|
||||
// get the current username
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
User user = Application.getCurrentUser(context);
|
||||
String userName = ISO9075.encode(user.getUserName());
|
||||
|
||||
// get the current in progress tasks for the current user
|
||||
List<WorkflowTask> tasks = this.workflowService.getAssignedTasks(
|
||||
userName, WorkflowTaskState.IN_PROGRESS);
|
||||
|
||||
// create a list of transient nodes to represent
|
||||
this.tasks = new ArrayList<Node>(tasks.size());
|
||||
for (WorkflowTask task : tasks)
|
||||
UserTransaction tx = null;
|
||||
try
|
||||
{
|
||||
Node node = createTask(task);
|
||||
this.tasks.add(node);
|
||||
tx = Repository.getUserTransaction(context, true);
|
||||
tx.begin();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Added to do task: " + node);
|
||||
// get the current in progress tasks for the current user
|
||||
List<WorkflowTask> tasks = this.workflowService.getAssignedTasks(
|
||||
userName, WorkflowTaskState.IN_PROGRESS);
|
||||
|
||||
// create a list of transient nodes to represent
|
||||
this.tasks = new ArrayList<Node>(tasks.size());
|
||||
for (WorkflowTask task : tasks)
|
||||
{
|
||||
Node node = createTask(task);
|
||||
this.tasks.add(node);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Added to do task: " + node);
|
||||
}
|
||||
|
||||
// commit the changes
|
||||
tx.commit();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
// rollback the transaction
|
||||
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
|
||||
Utils.addErrorMessage("Failed to get to do tasks: " + e.toString(), e);
|
||||
}
|
||||
|
||||
// commit the changes
|
||||
tx.commit();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
// rollback the transaction
|
||||
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
|
||||
Utils.addErrorMessage("Failed to get to do tasks: " + e.toString(), e);
|
||||
}
|
||||
|
||||
return this.tasks;
|
||||
@@ -102,40 +100,43 @@ public class WorkflowBean
|
||||
*/
|
||||
public List<Node> getTasksCompleted()
|
||||
{
|
||||
// get the current username
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
User user = Application.getCurrentUser(context);
|
||||
String userName = ISO9075.encode(user.getUserName());
|
||||
|
||||
UserTransaction tx = null;
|
||||
try
|
||||
if (this.completedTasks == null)
|
||||
{
|
||||
tx = Repository.getUserTransaction(context, true);
|
||||
tx.begin();
|
||||
// get the current username
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
User user = Application.getCurrentUser(context);
|
||||
String userName = ISO9075.encode(user.getUserName());
|
||||
|
||||
// get the current in progress tasks for the current user
|
||||
List<WorkflowTask> tasks = this.workflowService.getAssignedTasks(
|
||||
userName, WorkflowTaskState.COMPLETED);
|
||||
|
||||
// create a list of transient nodes to represent
|
||||
this.completedTasks = new ArrayList<Node>(tasks.size());
|
||||
for (WorkflowTask task : tasks)
|
||||
UserTransaction tx = null;
|
||||
try
|
||||
{
|
||||
Node node = createTask(task);
|
||||
this.completedTasks.add(node);
|
||||
tx = Repository.getUserTransaction(context, true);
|
||||
tx.begin();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Added completed task: " + node);
|
||||
// get the current in progress tasks for the current user
|
||||
List<WorkflowTask> tasks = this.workflowService.getAssignedTasks(
|
||||
userName, WorkflowTaskState.COMPLETED);
|
||||
|
||||
// create a list of transient nodes to represent
|
||||
this.completedTasks = new ArrayList<Node>(tasks.size());
|
||||
for (WorkflowTask task : tasks)
|
||||
{
|
||||
Node node = createTask(task);
|
||||
this.completedTasks.add(node);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Added completed task: " + node);
|
||||
}
|
||||
|
||||
// commit the changes
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
// commit the changes
|
||||
tx.commit();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
// rollback the transaction
|
||||
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
|
||||
Utils.addErrorMessage("Failed to get completed tasks: " + e.toString(), e);
|
||||
catch (Throwable e)
|
||||
{
|
||||
// rollback the transaction
|
||||
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
|
||||
Utils.addErrorMessage("Failed to get completed tasks: " + e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return this.completedTasks;
|
||||
@@ -163,47 +164,6 @@ public class WorkflowBean
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Helper methods
|
||||
|
||||
public static Map<QName, Serializable> prepareTaskParams(Node node)
|
||||
{
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
|
||||
// marshal the properties and associations captured by the property sheet
|
||||
// back into a Map to pass to the workflow service
|
||||
|
||||
// go through all the properties in the transient node and add them to
|
||||
// params map
|
||||
Map<String, Object> props = node.getProperties();
|
||||
for (String propName : props.keySet())
|
||||
{
|
||||
QName propQName = Repository.resolveToQName(propName);
|
||||
params.put(propQName, (Serializable)props.get(propName));
|
||||
}
|
||||
|
||||
// go through any associations that have been added to the start task
|
||||
// and build a list of NodeRefs representing the targets
|
||||
Map<String, Map<String, AssociationRef>> assocs = node.getAddedAssociations();
|
||||
for (String assocName : assocs.keySet())
|
||||
{
|
||||
QName assocQName = Repository.resolveToQName(assocName);
|
||||
|
||||
// get the associations added and create list of targets
|
||||
Map<String, AssociationRef> addedAssocs = assocs.get(assocName);
|
||||
List<NodeRef> targets = new ArrayList<NodeRef>(addedAssocs.size());
|
||||
for (AssociationRef assoc : addedAssocs.values())
|
||||
{
|
||||
targets.add(assoc.getTargetRef());
|
||||
}
|
||||
|
||||
// add the targets for this particular association
|
||||
if (targets.size() > 0)
|
||||
{
|
||||
params.put(assocQName, (Serializable)targets);
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and populates a TransientNode to represent the given
|
||||
@@ -260,6 +220,9 @@ public class WorkflowBean
|
||||
|
||||
// add the workflow instance id and name this taks belongs to
|
||||
node.getProperties().put("workflowInstanceId", task.path.instance.id);
|
||||
|
||||
// add the task itself as a property
|
||||
node.getProperties().put("workflowTask", task);
|
||||
}
|
||||
|
||||
return node;
|
||||
|
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.bean.workflow;
|
||||
|
||||
import org.alfresco.repo.workflow.WorkflowInterpreter;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
|
||||
|
||||
/**
|
||||
* Backing bean to support the Workflow Console
|
||||
*/
|
||||
public class WorkflowConsoleBean
|
||||
{
|
||||
// command
|
||||
private String command = "";
|
||||
private String submittedCommand = "none";
|
||||
private long duration = 0L;
|
||||
private String result = null;
|
||||
|
||||
// supporting repository services
|
||||
private WorkflowInterpreter workflowInterpreter;
|
||||
|
||||
|
||||
/**
|
||||
* @param nodeService node service
|
||||
*/
|
||||
public void setWorkflowInterpreter(WorkflowInterpreter workflowInterpreter)
|
||||
{
|
||||
this.workflowInterpreter = workflowInterpreter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command result
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
public String getResult()
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
interpretCommand("help");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command result
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
public void setResult(String result)
|
||||
{
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current query
|
||||
*
|
||||
* @return query statement
|
||||
*/
|
||||
public String getCommand()
|
||||
{
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current query
|
||||
*
|
||||
* @param query query statement
|
||||
*/
|
||||
public void setCommand(String command)
|
||||
{
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the submitted command
|
||||
*
|
||||
* @return submitted command
|
||||
*/
|
||||
public String getSubmittedCommand()
|
||||
{
|
||||
return submittedCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current query
|
||||
*
|
||||
* @param query query statement
|
||||
*/
|
||||
public void setSubmittedCommand(String submittedCommand)
|
||||
{
|
||||
this.submittedCommand = submittedCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last command duration
|
||||
*
|
||||
* @return command duration
|
||||
*/
|
||||
public long getDuration()
|
||||
{
|
||||
return duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current query
|
||||
*
|
||||
* @param query query statement
|
||||
*/
|
||||
public void setDuration(long duration)
|
||||
{
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to submit command
|
||||
*
|
||||
* @return next action
|
||||
*/
|
||||
public String submitCommand()
|
||||
{
|
||||
interpretCommand(command);
|
||||
return "success";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current user name
|
||||
*
|
||||
* @return user name
|
||||
*/
|
||||
public String getCurrentUserName()
|
||||
{
|
||||
return workflowInterpreter.getCurrentUserName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current workflow definition
|
||||
*
|
||||
* @return workflow definition
|
||||
*/
|
||||
public String getCurrentWorkflowDef()
|
||||
{
|
||||
WorkflowDefinition def = workflowInterpreter.getCurrentWorkflowDef();
|
||||
return (def == null) ? "None" : def.title + " v" + def.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpret workflow console command
|
||||
*
|
||||
* @param command command
|
||||
*/
|
||||
private void interpretCommand(String command)
|
||||
{
|
||||
try
|
||||
{
|
||||
long startms = System.currentTimeMillis();
|
||||
String result = workflowInterpreter.interpretCommand(command);
|
||||
setDuration(System.currentTimeMillis() - startms);
|
||||
setResult(result);
|
||||
setCommand("");
|
||||
setSubmittedCommand(command);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
setResult(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
222
source/java/org/alfresco/web/bean/workflow/WorkflowUtil.java
Normal file
222
source/java/org/alfresco/web/bean/workflow/WorkflowUtil.java
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.bean.workflow;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.CopyService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Helper class for common Workflow functionality.
|
||||
* <p>
|
||||
* This class should be replaced with calls to a WorkflowService once it is available.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class WorkflowUtil
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(WorkflowUtil.class);
|
||||
|
||||
/**
|
||||
* Execute the Approve step for the Simple Workflow on a node.
|
||||
*
|
||||
* @param ref NodeRef to the node with the workflow
|
||||
* @param nodeService NodeService instance
|
||||
* @param copyService CopyService instance
|
||||
*
|
||||
* @throws AlfrescoRuntimeException
|
||||
*/
|
||||
public static void approve(NodeRef ref, NodeService nodeService, CopyService copyService)
|
||||
throws AlfrescoRuntimeException
|
||||
{
|
||||
Node docNode = new Node(ref);
|
||||
|
||||
if (docNode.hasAspect(ContentModel.ASPECT_SIMPLE_WORKFLOW) == false)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Cannot approve a node that is not part of a workflow.");
|
||||
}
|
||||
|
||||
// get the simple workflow aspect properties
|
||||
Map<String, Object> props = docNode.getProperties();
|
||||
|
||||
Boolean approveMove = (Boolean)props.get(ContentModel.PROP_APPROVE_MOVE.toString());
|
||||
NodeRef approveFolder = (NodeRef)props.get(ContentModel.PROP_APPROVE_FOLDER.toString());
|
||||
|
||||
// first we need to take off the simpleworkflow aspect
|
||||
nodeService.removeAspect(ref, ContentModel.ASPECT_SIMPLE_WORKFLOW);
|
||||
|
||||
if (approveMove.booleanValue())
|
||||
{
|
||||
// move the node to the specified folder
|
||||
String qname = QName.createValidLocalName(docNode.getName());
|
||||
nodeService.moveNode(ref, approveFolder, ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname));
|
||||
}
|
||||
else
|
||||
{
|
||||
// copy the node to the specified folder
|
||||
String name = docNode.getName();
|
||||
String qname = QName.createValidLocalName(name);
|
||||
NodeRef newNode = copyService.copy(ref, approveFolder, ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname), true);
|
||||
|
||||
// the copy service does not copy the name of the node so we
|
||||
// need to update the property on the copied item
|
||||
nodeService.setProperty(newNode, ContentModel.PROP_NAME, name);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String movedCopied = approveMove ? "moved" : "copied";
|
||||
logger.debug("Node has been approved and " + movedCopied + " to folder with id of " +
|
||||
approveFolder.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the Reject step for the Simple Workflow on a node.
|
||||
*
|
||||
* @param ref NodeRef to the node with the workflow
|
||||
* @param nodeService NodeService instance
|
||||
* @param copyService CopyService instance
|
||||
*
|
||||
* @throws AlfrescoRuntimeException
|
||||
*/
|
||||
public static void reject(NodeRef ref, NodeService nodeService, CopyService copyService)
|
||||
throws AlfrescoRuntimeException
|
||||
{
|
||||
Node docNode = new Node(ref);
|
||||
|
||||
if (docNode.hasAspect(ContentModel.ASPECT_SIMPLE_WORKFLOW) == false)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Cannot reject a node that is not part of a workflow.");
|
||||
}
|
||||
|
||||
// get the simple workflow aspect properties
|
||||
Map<String, Object> props = docNode.getProperties();
|
||||
|
||||
String rejectStep = (String)props.get(ContentModel.PROP_REJECT_STEP.toString());
|
||||
Boolean rejectMove = (Boolean)props.get(ContentModel.PROP_REJECT_MOVE.toString());
|
||||
NodeRef rejectFolder = (NodeRef)props.get(ContentModel.PROP_REJECT_FOLDER.toString());
|
||||
|
||||
if (rejectStep == null && rejectMove == null && rejectFolder == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The workflow does not have a reject step defined.");
|
||||
}
|
||||
|
||||
// first we need to take off the simpleworkflow aspect
|
||||
nodeService.removeAspect(ref, ContentModel.ASPECT_SIMPLE_WORKFLOW);
|
||||
|
||||
if (rejectMove != null && rejectMove.booleanValue())
|
||||
{
|
||||
// move the document to the specified folder
|
||||
String qname = QName.createValidLocalName(docNode.getName());
|
||||
nodeService.moveNode(ref, rejectFolder, ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname));
|
||||
}
|
||||
else
|
||||
{
|
||||
// copy the document to the specified folder
|
||||
String name = docNode.getName();
|
||||
String qname = QName.createValidLocalName(name);
|
||||
NodeRef newNode = copyService.copy(ref, rejectFolder, ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname), true);
|
||||
|
||||
// the copy service does not copy the name of the node so we
|
||||
// need to update the property on the copied item
|
||||
nodeService.setProperty(newNode, ContentModel.PROP_NAME, name);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String movedCopied = rejectMove ? "moved" : "copied";
|
||||
logger.debug("Node has been rejected and " + movedCopied + " to folder with id of " +
|
||||
rejectFolder.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the given node for persistence in the workflow engine.
|
||||
*
|
||||
* @param node The node to package up for persistence
|
||||
* @return The map of data representing the node
|
||||
*/
|
||||
public static Map<QName, Serializable> prepareTaskParams(Node node)
|
||||
{
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
|
||||
// marshal the properties and associations captured by the property sheet
|
||||
// back into a Map to pass to the workflow service
|
||||
|
||||
// go through all the properties in the transient node and add them to
|
||||
// params map
|
||||
Map<String, Object> props = node.getProperties();
|
||||
for (String propName : props.keySet())
|
||||
{
|
||||
QName propQName = Repository.resolveToQName(propName);
|
||||
params.put(propQName, (Serializable)props.get(propName));
|
||||
}
|
||||
|
||||
// go through any associations that have been added to the start task
|
||||
// and build a list of NodeRefs representing the targets
|
||||
Map<String, Map<String, AssociationRef>> assocs = node.getAddedAssociations();
|
||||
for (String assocName : assocs.keySet())
|
||||
{
|
||||
QName assocQName = Repository.resolveToQName(assocName);
|
||||
|
||||
// get the associations added and create list of targets
|
||||
Map<String, AssociationRef> addedAssocs = assocs.get(assocName);
|
||||
List<NodeRef> targets = new ArrayList<NodeRef>(addedAssocs.size());
|
||||
for (AssociationRef assoc : addedAssocs.values())
|
||||
{
|
||||
targets.add(assoc.getTargetRef());
|
||||
}
|
||||
|
||||
// add the targets for this particular association
|
||||
if (targets.size() > 0)
|
||||
{
|
||||
params.put(assocQName, (Serializable)targets);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Deal with child associations if and when we need to support
|
||||
// them for workflow tasks, for now warn that they are being used
|
||||
Map childAssocs = node.getAddedChildAssociations();
|
||||
if (childAssocs.size() > 0)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
logger.warn("Child associations are present but are not supported for workflow tasks, ignoring...");
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user