Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)

125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
      125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Raluca Munteanu
2016-04-26 13:03:25 +00:00
parent d6f9f50c39
commit dead3c3825
265 changed files with 44099 additions and 44099 deletions

View File

@@ -1,165 +1,165 @@
package org.alfresco.web.bean.workflow;
import java.text.MessageFormat;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.service.cmr.workflow.WorkflowInstance;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation for the "Cancel Workflow" dialog
*
* @author gavinc
*/
public class CancelWorkflowDialog extends BaseDialogBean
{
private static final long serialVersionUID = -7875582893750792200L;
transient private WorkflowInstance workflowInstance;
transient private WorkflowService workflowService;
private static final Log logger = LogFactory.getLog(CancelWorkflowDialog.class);
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// make sure the workflow instance id has been passed
String workflowInstanceId = this.parameters.get("workflow-instance-id");
if (workflowInstanceId == null || workflowInstanceId.length() == 0)
{
throw new IllegalArgumentException("Cancel workflow dialog called without workflow instance id");
}
this.workflowInstance = getWorkflowService().getWorkflowById(workflowInstanceId);
if (this.workflowInstance == null)
{
throw new IllegalArgumentException("Failed to find workflow instance for id: " + workflowInstanceId);
}
}
@Override
protected String finishImpl(FacesContext context, String outcome)
throws Exception
{
if (logger.isDebugEnabled())
logger.debug("Cancelling workflow with id: " + this.getWorkflowInstance().getId());
WorkflowInstance instance = this.getWorkflowInstance();
if(instance.isActive()) {
// cancel the workflow
this.getWorkflowService().cancelWorkflow(this.getWorkflowInstance().getId());
}
else
{
// delete the workflow
this.getWorkflowService().deleteWorkflow(this.getWorkflowInstance().getId());
}
if (logger.isDebugEnabled())
logger.debug("Cancelled workflow with id: " + this.getWorkflowInstance().getId());
return outcome;
}
@Override
protected String getErrorMessageId()
{
return "error_cancel_workflow";
}
@Override
public boolean getFinishButtonDisabled()
{
return false;
}
@Override
public String getCancelButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "no");
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "yes");
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Returns the confirmation to display to the user before deleting the content.
*
* @return The formatted message to display
*/
public String getConfirmMessage()
{
String confirmMsg = Application.getMessage(FacesContext.getCurrentInstance(),
"cancel_workflow_confirm");
String workflowLabel = this.getWorkflowInstance().getDefinition().getTitle();
if (this.getWorkflowInstance().getDescription() != null && this.getWorkflowInstance().getDescription().length() > 0)
{
workflowLabel = workflowLabel + " (" + this.getWorkflowInstance().getDescription() + ")";
}
return MessageFormat.format(confirmMsg, new Object[] {workflowLabel});
}
/**
* Returns the workflow service instance
*
* @return WorkflowService instance
*/
public WorkflowService getWorkflowService()
{
if (workflowService == null)
{
workflowService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWorkflowService();
}
return workflowService;
}
/**
* Sets the workflow service to use
*
* @param workflowService The WorkflowService instance
*/
public void setWorkflowService(WorkflowService workflowService)
{
this.workflowService = workflowService;
}
protected WorkflowInstance getWorkflowInstance()
{
if (workflowInstance == null)
{
String workflowInstanceId = this.parameters.get("workflow-instance-id");
if (workflowInstanceId == null || workflowInstanceId.length() == 0)
{
throw new IllegalArgumentException("Cancel workflow dialog called without workflow instance id");
}
this.workflowInstance = getWorkflowService().getWorkflowById(workflowInstanceId);
if (this.workflowInstance == null)
{
throw new IllegalArgumentException("Failed to find workflow instance for id: " + workflowInstanceId);
}
}
return workflowInstance;
}
}
package org.alfresco.web.bean.workflow;
import java.text.MessageFormat;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.service.cmr.workflow.WorkflowInstance;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation for the "Cancel Workflow" dialog
*
* @author gavinc
*/
public class CancelWorkflowDialog extends BaseDialogBean
{
private static final long serialVersionUID = -7875582893750792200L;
transient private WorkflowInstance workflowInstance;
transient private WorkflowService workflowService;
private static final Log logger = LogFactory.getLog(CancelWorkflowDialog.class);
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// make sure the workflow instance id has been passed
String workflowInstanceId = this.parameters.get("workflow-instance-id");
if (workflowInstanceId == null || workflowInstanceId.length() == 0)
{
throw new IllegalArgumentException("Cancel workflow dialog called without workflow instance id");
}
this.workflowInstance = getWorkflowService().getWorkflowById(workflowInstanceId);
if (this.workflowInstance == null)
{
throw new IllegalArgumentException("Failed to find workflow instance for id: " + workflowInstanceId);
}
}
@Override
protected String finishImpl(FacesContext context, String outcome)
throws Exception
{
if (logger.isDebugEnabled())
logger.debug("Cancelling workflow with id: " + this.getWorkflowInstance().getId());
WorkflowInstance instance = this.getWorkflowInstance();
if(instance.isActive()) {
// cancel the workflow
this.getWorkflowService().cancelWorkflow(this.getWorkflowInstance().getId());
}
else
{
// delete the workflow
this.getWorkflowService().deleteWorkflow(this.getWorkflowInstance().getId());
}
if (logger.isDebugEnabled())
logger.debug("Cancelled workflow with id: " + this.getWorkflowInstance().getId());
return outcome;
}
@Override
protected String getErrorMessageId()
{
return "error_cancel_workflow";
}
@Override
public boolean getFinishButtonDisabled()
{
return false;
}
@Override
public String getCancelButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "no");
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "yes");
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Returns the confirmation to display to the user before deleting the content.
*
* @return The formatted message to display
*/
public String getConfirmMessage()
{
String confirmMsg = Application.getMessage(FacesContext.getCurrentInstance(),
"cancel_workflow_confirm");
String workflowLabel = this.getWorkflowInstance().getDefinition().getTitle();
if (this.getWorkflowInstance().getDescription() != null && this.getWorkflowInstance().getDescription().length() > 0)
{
workflowLabel = workflowLabel + " (" + this.getWorkflowInstance().getDescription() + ")";
}
return MessageFormat.format(confirmMsg, new Object[] {workflowLabel});
}
/**
* Returns the workflow service instance
*
* @return WorkflowService instance
*/
public WorkflowService getWorkflowService()
{
if (workflowService == null)
{
workflowService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWorkflowService();
}
return workflowService;
}
/**
* Sets the workflow service to use
*
* @param workflowService The WorkflowService instance
*/
public void setWorkflowService(WorkflowService workflowService)
{
this.workflowService = workflowService;
}
protected WorkflowInstance getWorkflowInstance()
{
if (workflowInstance == null)
{
String workflowInstanceId = this.parameters.get("workflow-instance-id");
if (workflowInstanceId == null || workflowInstanceId.length() == 0)
{
throw new IllegalArgumentException("Cancel workflow dialog called without workflow instance id");
}
this.workflowInstance = getWorkflowService().getWorkflowById(workflowInstanceId);
if (this.workflowInstance == null)
{
throw new IllegalArgumentException("Failed to find workflow instance for id: " + workflowInstanceId);
}
}
return workflowInstance;
}
}

View File

@@ -1,89 +1,89 @@
package org.alfresco.web.bean.workflow;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.ui.common.component.UIGenericPicker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation for the "Reassign Task" dialog
*
* @author gavinc
*/
public class ReassignTaskDialog extends BaseReassignDialog
{
private static final long serialVersionUID = 5804171557325189475L;
protected String taskId;
private static final Log logger = LogFactory.getLog(ReassignTaskDialog.class);
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.taskId = this.parameters.get("id");
if (this.taskId == null || this.taskId.length() == 0)
{
throw new IllegalArgumentException("Reassign task dialog called without task id");
}
}
@Override
protected String finishImpl(FacesContext context, String outcome)
throws Exception
{
if (logger.isDebugEnabled())
logger.debug("Reassigning task with id: " + this.taskId);
UIComponent picker = context.getViewRoot().findComponent("dialog:dialog-body:user-picker");
if (picker != null && picker instanceof UIGenericPicker)
{
UIGenericPicker userPicker = (UIGenericPicker)picker;
String[] user = userPicker.getSelectedResults();
if (user != null && user.length > 0)
{
// create a map to hold the new owner property then update the task
String userName = user[0];
Map<QName, Serializable> params = new HashMap<QName, Serializable>(1);
params.put(ContentModel.PROP_OWNER, userName);
this.getWorkflowService().updateTask(this.taskId, params, null, null);
}
else
{
if (logger.isWarnEnabled())
logger.warn("Failed to find selected user, reassign was unsuccessful");
}
}
else
{
if (logger.isWarnEnabled())
logger.warn("Failed to find user-picker component, reassign was unsuccessful");
}
if (logger.isDebugEnabled())
logger.debug("Reassigning task with id: " + this.taskId);
return outcome;
}
@Override
protected String getErrorMessageId()
{
return "error_reassign_task";
}
}
package org.alfresco.web.bean.workflow;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.ui.common.component.UIGenericPicker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation for the "Reassign Task" dialog
*
* @author gavinc
*/
public class ReassignTaskDialog extends BaseReassignDialog
{
private static final long serialVersionUID = 5804171557325189475L;
protected String taskId;
private static final Log logger = LogFactory.getLog(ReassignTaskDialog.class);
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.taskId = this.parameters.get("id");
if (this.taskId == null || this.taskId.length() == 0)
{
throw new IllegalArgumentException("Reassign task dialog called without task id");
}
}
@Override
protected String finishImpl(FacesContext context, String outcome)
throws Exception
{
if (logger.isDebugEnabled())
logger.debug("Reassigning task with id: " + this.taskId);
UIComponent picker = context.getViewRoot().findComponent("dialog:dialog-body:user-picker");
if (picker != null && picker instanceof UIGenericPicker)
{
UIGenericPicker userPicker = (UIGenericPicker)picker;
String[] user = userPicker.getSelectedResults();
if (user != null && user.length > 0)
{
// create a map to hold the new owner property then update the task
String userName = user[0];
Map<QName, Serializable> params = new HashMap<QName, Serializable>(1);
params.put(ContentModel.PROP_OWNER, userName);
this.getWorkflowService().updateTask(this.taskId, params, null, null);
}
else
{
if (logger.isWarnEnabled())
logger.warn("Failed to find selected user, reassign was unsuccessful");
}
}
else
{
if (logger.isWarnEnabled())
logger.warn("Failed to find user-picker component, reassign was unsuccessful");
}
if (logger.isDebugEnabled())
logger.debug("Reassigning task with id: " + this.taskId);
return outcome;
}
@Override
protected String getErrorMessageId()
{
return "error_reassign_task";
}
}

View File

@@ -1,89 +1,89 @@
package org.alfresco.web.bean.workflow;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.ui.common.component.UIGenericPicker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation for the "Reassign Work Item" dialog
*
* @author gavinc
*/
public class ReassignWorkItemDialog extends BaseReassignDialog
{
private static final long serialVersionUID = 6501900045849920148L;
protected String workItemId;
private static final Log logger = LogFactory.getLog(ReassignWorkItemDialog.class);
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.workItemId = this.parameters.get("workitem-id");
if (this.workItemId == null || this.workItemId.length() == 0)
{
throw new IllegalArgumentException("Reassign workitem dialog called without task id");
}
}
@Override
protected String finishImpl(FacesContext context, String outcome)
throws Exception
{
if (logger.isDebugEnabled())
logger.debug("Reassigning work item with id: " + this.workItemId);
UIComponent picker = context.getViewRoot().findComponent("dialog:dialog-body:user-picker");
if (picker != null && picker instanceof UIGenericPicker)
{
UIGenericPicker userPicker = (UIGenericPicker)picker;
String[] user = userPicker.getSelectedResults();
if (user != null && user.length > 0)
{
// create a map to hold the new owner property then update the task
String userName = user[0];
Map<QName, Serializable> params = new HashMap<QName, Serializable>(1);
params.put(ContentModel.PROP_OWNER, userName);
this.getWorkflowService().updateTask(this.workItemId, params, null, null);
}
else
{
if (logger.isWarnEnabled())
logger.warn("Failed to find selected user, reassign was unsuccessful");
}
}
else
{
if (logger.isWarnEnabled())
logger.warn("Failed to find user-picker component, reassign was unsuccessful");
}
if (logger.isDebugEnabled())
logger.debug("Reassigning work item with id: " + this.workItemId);
return outcome;
}
@Override
protected String getErrorMessageId()
{
return "error_reassign_workitem";
}
}
package org.alfresco.web.bean.workflow;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.ui.common.component.UIGenericPicker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation for the "Reassign Work Item" dialog
*
* @author gavinc
*/
public class ReassignWorkItemDialog extends BaseReassignDialog
{
private static final long serialVersionUID = 6501900045849920148L;
protected String workItemId;
private static final Log logger = LogFactory.getLog(ReassignWorkItemDialog.class);
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.workItemId = this.parameters.get("workitem-id");
if (this.workItemId == null || this.workItemId.length() == 0)
{
throw new IllegalArgumentException("Reassign workitem dialog called without task id");
}
}
@Override
protected String finishImpl(FacesContext context, String outcome)
throws Exception
{
if (logger.isDebugEnabled())
logger.debug("Reassigning work item with id: " + this.workItemId);
UIComponent picker = context.getViewRoot().findComponent("dialog:dialog-body:user-picker");
if (picker != null && picker instanceof UIGenericPicker)
{
UIGenericPicker userPicker = (UIGenericPicker)picker;
String[] user = userPicker.getSelectedResults();
if (user != null && user.length > 0)
{
// create a map to hold the new owner property then update the task
String userName = user[0];
Map<QName, Serializable> params = new HashMap<QName, Serializable>(1);
params.put(ContentModel.PROP_OWNER, userName);
this.getWorkflowService().updateTask(this.workItemId, params, null, null);
}
else
{
if (logger.isWarnEnabled())
logger.warn("Failed to find selected user, reassign was unsuccessful");
}
}
else
{
if (logger.isWarnEnabled())
logger.warn("Failed to find user-picker component, reassign was unsuccessful");
}
if (logger.isDebugEnabled())
logger.debug("Reassigning work item with id: " + this.workItemId);
return outcome;
}
@Override
protected String getErrorMessageId()
{
return "error_reassign_workitem";
}
}

View File

@@ -1,50 +1,50 @@
package org.alfresco.web.bean.workflow;
import java.util.List;
import javax.faces.context.FacesContext;
import org.alfresco.web.app.Application;
import org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig;
/**
* Bean implementation for the "View Completed Task" dialog.
*
* @author gavinc
*/
public class ViewCompletedTaskDialog extends ManageTaskDialog
{
// ------------------------------------------------------------------------------
// Dialog implementation
private static final long serialVersionUID = 1568710712589201055L;
@Override
protected String finishImpl(FacesContext context, String outcome)
throws Exception
{
// nothing to do as the finish button is not shown and the dialog is read only
return outcome;
}
@Override
public String getCancelButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "close");
}
@Override
public List<DialogButtonConfig> getAdditionalButtons()
{
return null;
}
@Override
public String getContainerTitle()
{
String titleStart = Application.getMessage(FacesContext.getCurrentInstance(), "view_completed_task_title");
return titleStart + ": " + this.getWorkflowTask().title;
}
}
package org.alfresco.web.bean.workflow;
import java.util.List;
import javax.faces.context.FacesContext;
import org.alfresco.web.app.Application;
import org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig;
/**
* Bean implementation for the "View Completed Task" dialog.
*
* @author gavinc
*/
public class ViewCompletedTaskDialog extends ManageTaskDialog
{
// ------------------------------------------------------------------------------
// Dialog implementation
private static final long serialVersionUID = 1568710712589201055L;
@Override
protected String finishImpl(FacesContext context, String outcome)
throws Exception
{
// nothing to do as the finish button is not shown and the dialog is read only
return outcome;
}
@Override
public String getCancelButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "close");
}
@Override
public List<DialogButtonConfig> getAdditionalButtons()
{
return null;
}
@Override
public String getContainerTitle()
{
String titleStart = Application.getMessage(FacesContext.getCurrentInstance(), "view_completed_task_title");
return titleStart + ": " + this.getWorkflowTask().title;
}
}

View File

@@ -1,363 +1,363 @@
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.faces.event.ActionEvent;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition;
import org.alfresco.service.cmr.workflow.WorkflowTaskQuery;
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
import org.alfresco.service.cmr.workflow.WorkflowTransition;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.config.ClientConfigElement;
import org.springframework.extensions.surf.util.ParameterCheck;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.TransientMapNode;
import org.alfresco.web.bean.repository.TransientNode;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Managed bean used for providing support for the workflow task dashlets
*
* @author gavinc
*/
public class WorkflowBean implements Serializable
{
private static final long serialVersionUID = 2950475254440425384L;
protected NavigationBean navigationBean;
transient private NodeService nodeService;
transient private WorkflowService workflowService;
protected List<Node> tasks;
protected List<Node> activeTasks;
protected List<Node> pooledTasks;
protected List<Node> completedTasks;
private static final Log logger = LogFactory.getLog(WorkflowBean.class);
public static final String BEAN_NAME = "WorkflowBean";
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Returns a list of nodes representing the "all" active tasks.
*
* @return List of all active tasks
*/
public List<Node> getAllActiveTasks()
{
if (this.activeTasks == null)
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// query for all active tasks
WorkflowTaskQuery query = new WorkflowTaskQuery();
List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
// create a list of transient nodes to represent
this.activeTasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks)
{
Node node = createTask(task);
this.activeTasks.add(node);
if (logger.isDebugEnabled())
logger.debug("Added active 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 all active tasks: " + e.toString(), e);
}
}
return this.activeTasks;
}
/**
* Returns a list of nodes representing the "pooled" to do tasks the
* current user has.
*
* @return List of to do tasks
*/
public List<Node> getPooledTasks()
{
if (this.pooledTasks == null)
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current pooled tasks for the current user
List<WorkflowTask> tasks = this.getWorkflowService().getPooledTasks(userName, true);
// create a list of transient nodes to represent
this.pooledTasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks)
{
Node node = createTask(task);
this.pooledTasks.add(node);
if (logger.isDebugEnabled())
logger.debug("Added pooled 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 pooled tasks: " + e.toString(), e);
}
}
return this.pooledTasks;
}
/**
* Returns a list of nodes representing the to do tasks the
* current user has.
*
* @return List of to do tasks
*/
public List<Node> getTasksToDo()
{
if (this.tasks == null)
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current in progress tasks for the current user
List<WorkflowTask> tasks = this.getWorkflowService().getAssignedTasks(
userName, WorkflowTaskState.IN_PROGRESS, true);
// 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);
}
}
return this.tasks;
}
/**
* Returns a list of nodes representing the completed tasks the
* current user has.
*
* @return List of completed tasks
*/
public List<Node> getTasksCompleted()
{
if (this.completedTasks == null)
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current in progress tasks for the current user
ClientConfigElement clientConfig = (ClientConfigElement)Application.getConfigService(context).getGlobalConfig().getConfigElement(
ClientConfigElement.CONFIG_ELEMENT_ID);
WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setActive(null);
query.setActorId(userName);
query.setTaskState(WorkflowTaskState.COMPLETED);
query.setLimit(clientConfig.getTasksCompletedMaxResults());
List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
// 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();
}
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;
}
/**
* Sets the navigation bean to use
*
* @param navigationBean The NavigationBean to set.
*/
public void setNavigationBean(NavigationBean navigationBean)
{
this.navigationBean = navigationBean;
}
/**
* Sets the workflow service to use
*
* @param workflowService WorkflowService instance
*/
public void setWorkflowService(WorkflowService workflowService)
{
this.workflowService = workflowService;
}
protected WorkflowService getWorkflowService()
{
if (this.workflowService == null)
{
this.workflowService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWorkflowService();
}
return this.workflowService;
}
/**
* Sets the node service to use
*
* @param nodeService NodeService instance
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
protected NodeService getNodeService()
{
if (this.nodeService == null)
{
this.nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
}
return this.nodeService;
}
// ------------------------------------------------------------------------------
// Navigation handlers
public void setupTaskDialog(ActionEvent event)
{
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
String type = params.get("type");
// setup the dispatch context with the task we're opening a dialog for
TransientNode node = new TransientNode(QName.createQName(type), id, null);
this.navigationBean.setupDispatchContext(node);
// pass on parameters for the dialog
Application.getDialogManager().setupParameters(event);
}
public void setupTaskDialog(String id, String type)
{
ParameterCheck.mandatoryString("Task ID", id);
ParameterCheck.mandatoryString("Task Type", type);
// setup the dispatch context with the task we're opening a dialog for
TransientNode node = new TransientNode(QName.createQName(type), id, null);
this.navigationBean.setupDispatchContext(node);
// pass on parameters for the dialog
Map<String, String> params = new HashMap<String, String>(2, 1.0f);
params.put("id", id);
params.put("type", type);
Application.getDialogManager().setupParameters(params);
}
// ------------------------------------------------------------------------------
// Helper methods
/**
* Creates and populates a TransientNode to represent the given
* workflow task from the repository workflow engine
*
* @param task The task to create a representation of
*/
protected TransientMapNode createTask(WorkflowTask task)
{
return new WorkflowTaskNode(task);
}
}
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.faces.event.ActionEvent;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition;
import org.alfresco.service.cmr.workflow.WorkflowTaskQuery;
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
import org.alfresco.service.cmr.workflow.WorkflowTransition;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.config.ClientConfigElement;
import org.springframework.extensions.surf.util.ParameterCheck;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.TransientMapNode;
import org.alfresco.web.bean.repository.TransientNode;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Managed bean used for providing support for the workflow task dashlets
*
* @author gavinc
*/
public class WorkflowBean implements Serializable
{
private static final long serialVersionUID = 2950475254440425384L;
protected NavigationBean navigationBean;
transient private NodeService nodeService;
transient private WorkflowService workflowService;
protected List<Node> tasks;
protected List<Node> activeTasks;
protected List<Node> pooledTasks;
protected List<Node> completedTasks;
private static final Log logger = LogFactory.getLog(WorkflowBean.class);
public static final String BEAN_NAME = "WorkflowBean";
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Returns a list of nodes representing the "all" active tasks.
*
* @return List of all active tasks
*/
public List<Node> getAllActiveTasks()
{
if (this.activeTasks == null)
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// query for all active tasks
WorkflowTaskQuery query = new WorkflowTaskQuery();
List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
// create a list of transient nodes to represent
this.activeTasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks)
{
Node node = createTask(task);
this.activeTasks.add(node);
if (logger.isDebugEnabled())
logger.debug("Added active 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 all active tasks: " + e.toString(), e);
}
}
return this.activeTasks;
}
/**
* Returns a list of nodes representing the "pooled" to do tasks the
* current user has.
*
* @return List of to do tasks
*/
public List<Node> getPooledTasks()
{
if (this.pooledTasks == null)
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current pooled tasks for the current user
List<WorkflowTask> tasks = this.getWorkflowService().getPooledTasks(userName, true);
// create a list of transient nodes to represent
this.pooledTasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks)
{
Node node = createTask(task);
this.pooledTasks.add(node);
if (logger.isDebugEnabled())
logger.debug("Added pooled 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 pooled tasks: " + e.toString(), e);
}
}
return this.pooledTasks;
}
/**
* Returns a list of nodes representing the to do tasks the
* current user has.
*
* @return List of to do tasks
*/
public List<Node> getTasksToDo()
{
if (this.tasks == null)
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current in progress tasks for the current user
List<WorkflowTask> tasks = this.getWorkflowService().getAssignedTasks(
userName, WorkflowTaskState.IN_PROGRESS, true);
// 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);
}
}
return this.tasks;
}
/**
* Returns a list of nodes representing the completed tasks the
* current user has.
*
* @return List of completed tasks
*/
public List<Node> getTasksCompleted()
{
if (this.completedTasks == null)
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current in progress tasks for the current user
ClientConfigElement clientConfig = (ClientConfigElement)Application.getConfigService(context).getGlobalConfig().getConfigElement(
ClientConfigElement.CONFIG_ELEMENT_ID);
WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setActive(null);
query.setActorId(userName);
query.setTaskState(WorkflowTaskState.COMPLETED);
query.setLimit(clientConfig.getTasksCompletedMaxResults());
List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
// 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();
}
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;
}
/**
* Sets the navigation bean to use
*
* @param navigationBean The NavigationBean to set.
*/
public void setNavigationBean(NavigationBean navigationBean)
{
this.navigationBean = navigationBean;
}
/**
* Sets the workflow service to use
*
* @param workflowService WorkflowService instance
*/
public void setWorkflowService(WorkflowService workflowService)
{
this.workflowService = workflowService;
}
protected WorkflowService getWorkflowService()
{
if (this.workflowService == null)
{
this.workflowService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWorkflowService();
}
return this.workflowService;
}
/**
* Sets the node service to use
*
* @param nodeService NodeService instance
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
protected NodeService getNodeService()
{
if (this.nodeService == null)
{
this.nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
}
return this.nodeService;
}
// ------------------------------------------------------------------------------
// Navigation handlers
public void setupTaskDialog(ActionEvent event)
{
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
String type = params.get("type");
// setup the dispatch context with the task we're opening a dialog for
TransientNode node = new TransientNode(QName.createQName(type), id, null);
this.navigationBean.setupDispatchContext(node);
// pass on parameters for the dialog
Application.getDialogManager().setupParameters(event);
}
public void setupTaskDialog(String id, String type)
{
ParameterCheck.mandatoryString("Task ID", id);
ParameterCheck.mandatoryString("Task Type", type);
// setup the dispatch context with the task we're opening a dialog for
TransientNode node = new TransientNode(QName.createQName(type), id, null);
this.navigationBean.setupDispatchContext(node);
// pass on parameters for the dialog
Map<String, String> params = new HashMap<String, String>(2, 1.0f);
params.put("id", id);
params.put("type", type);
Application.getDialogManager().setupParameters(params);
}
// ------------------------------------------------------------------------------
// Helper methods
/**
* Creates and populates a TransientNode to represent the given
* workflow task from the repository workflow engine
*
* @param task The task to create a representation of
*/
protected TransientMapNode createTask(WorkflowTask task)
{
return new WorkflowTaskNode(task);
}
}

View File

@@ -1,184 +1,184 @@
package org.alfresco.web.bean.workflow;
import java.io.Serializable;
import javax.faces.context.FacesContext;
import org.alfresco.repo.workflow.WorkflowInterpreter;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.web.app.servlet.FacesHelper;
/**
* Backing bean to support the Workflow Console
*/
public class WorkflowConsoleBean implements Serializable
{
private static final long serialVersionUID = -7531838393180855185L;
// command
private String command = "";
private String submittedCommand = "none";
private long duration = 0L;
private String result = null;
// supporting repository services
transient private WorkflowInterpreter workflowInterpreter;
/**
* @param workflowInterpreter workflow interpreter
*/
public void setWorkflowInterpreter(WorkflowInterpreter workflowInterpreter)
{
this.workflowInterpreter = workflowInterpreter;
}
private WorkflowInterpreter getWorkflowInterpreter()
{
if (this.workflowInterpreter == null)
{
this.workflowInterpreter = (WorkflowInterpreter) FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "workflowInterpreter");
}
return this.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 command
*
* @param command command
*/
public void setCommand(String command)
{
this.command = command;
}
/**
* Gets the submitted command
*
* @return submitted command
*/
public String getSubmittedCommand()
{
return submittedCommand;
}
/**
* Set the submitted command
*
* @param submittedCommand The submitted command
*/
public void setSubmittedCommand(String submittedCommand)
{
this.submittedCommand = submittedCommand;
}
/**
* Gets the last command duration
*
* @return command duration
*/
public long getDuration()
{
return duration;
}
/**
* Set the duration
*
* @param duration The duration
*/
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 getWorkflowInterpreter().getCurrentUserName();
}
/**
* Gets the current workflow definition
*
* @return workflow definition
*/
public String getCurrentWorkflowDef()
{
WorkflowDefinition def = getWorkflowInterpreter().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 = getWorkflowInterpreter().interpretCommand(command);
setDuration(System.currentTimeMillis() - startms);
setResult(result);
setCommand("");
setSubmittedCommand(command);
}
catch (Exception e)
{
setResult(e.toString());
}
}
}
package org.alfresco.web.bean.workflow;
import java.io.Serializable;
import javax.faces.context.FacesContext;
import org.alfresco.repo.workflow.WorkflowInterpreter;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.web.app.servlet.FacesHelper;
/**
* Backing bean to support the Workflow Console
*/
public class WorkflowConsoleBean implements Serializable
{
private static final long serialVersionUID = -7531838393180855185L;
// command
private String command = "";
private String submittedCommand = "none";
private long duration = 0L;
private String result = null;
// supporting repository services
transient private WorkflowInterpreter workflowInterpreter;
/**
* @param workflowInterpreter workflow interpreter
*/
public void setWorkflowInterpreter(WorkflowInterpreter workflowInterpreter)
{
this.workflowInterpreter = workflowInterpreter;
}
private WorkflowInterpreter getWorkflowInterpreter()
{
if (this.workflowInterpreter == null)
{
this.workflowInterpreter = (WorkflowInterpreter) FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "workflowInterpreter");
}
return this.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 command
*
* @param command command
*/
public void setCommand(String command)
{
this.command = command;
}
/**
* Gets the submitted command
*
* @return submitted command
*/
public String getSubmittedCommand()
{
return submittedCommand;
}
/**
* Set the submitted command
*
* @param submittedCommand The submitted command
*/
public void setSubmittedCommand(String submittedCommand)
{
this.submittedCommand = submittedCommand;
}
/**
* Gets the last command duration
*
* @return command duration
*/
public long getDuration()
{
return duration;
}
/**
* Set the duration
*
* @param duration The duration
*/
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 getWorkflowInterpreter().getCurrentUserName();
}
/**
* Gets the current workflow definition
*
* @return workflow definition
*/
public String getCurrentWorkflowDef()
{
WorkflowDefinition def = getWorkflowInterpreter().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 = getWorkflowInterpreter().interpretCommand(command);
setDuration(System.currentTimeMillis() - startms);
setResult(result);
setCommand("");
setSubmittedCommand(command);
}
catch (Exception e)
{
setResult(e.toString());
}
}
}

View File

@@ -1,277 +1,277 @@
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.servlet.ServletContext;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.ServiceRegistry;
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.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
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(final NodeRef ref, final NodeService nodeService, final CopyService copyService)
throws AlfrescoRuntimeException
{
Node docNode = new Node(ref);
if (docNode.hasAspect(ApplicationModel.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(ApplicationModel.PROP_APPROVE_MOVE.toString());
NodeRef approveFolder = (NodeRef)props.get(ApplicationModel.PROP_APPROVE_FOLDER.toString());
if (approveMove.booleanValue())
{
// first we need to take off the simpleworkflow aspect
nodeService.removeAspect(ref, ApplicationModel.ASPECT_SIMPLE_WORKFLOW);
// 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
{
// first we need to take off the simpleworkflow aspect
// NOTE: run as system to allow Consumers to copy an item
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
{
public String doWork() throws Exception
{
nodeService.removeAspect(ref, ApplicationModel.ASPECT_SIMPLE_WORKFLOW);
return null;
}
}, AuthenticationUtil.getSystemUserName());
// 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(ApplicationModel.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(ApplicationModel.PROP_REJECT_STEP.toString());
Boolean rejectMove = (Boolean)props.get(ApplicationModel.PROP_REJECT_MOVE.toString());
NodeRef rejectFolder = (NodeRef)props.get(ApplicationModel.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, ApplicationModel.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
*/
@SuppressWarnings("unchecked")
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<AssociationRef> originalAssocRefs = (List<AssociationRef>) node.getAssociations().get(assocName);
List<NodeRef> targets = new ArrayList<NodeRef>(addedAssocs.size());
if (originalAssocRefs != null)
{
for (AssociationRef assoc : originalAssocRefs)
{
targets.add(assoc.getTargetRef());
}
}
for (AssociationRef assoc : addedAssocs.values())
{
targets.add(assoc.getTargetRef());
}
params.put(assocQName, (Serializable)targets);
}
// go through the removed associations and either setup or adjust the
// parameters map accordingly
assocs = node.getRemovedAssociations();
for (String assocName : assocs.keySet())
{
QName assocQName = Repository.resolveToQName(assocName);
// get the associations removed and create list of targets
Map<String, AssociationRef> removedAssocs = assocs.get(assocName);
List<NodeRef> targets = (List<NodeRef>)params.get(assocQName);
if (targets == null)
{
// if there weren't any assocs of this type added get the current
// set of assocs from the node
List<AssociationRef> originalAssocRefs = (List<AssociationRef>)node.getAssociations().get(assocName);
targets = new ArrayList<NodeRef>(originalAssocRefs.size());
for (AssociationRef assoc : originalAssocRefs)
{
targets.add(assoc.getTargetRef());
}
}
// remove the assocs the user deleted
for (AssociationRef assoc : removedAssocs.values())
{
targets.remove(assoc.getTargetRef());
}
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;
}
public static boolean isTaskEditable(String taskId, ServletContext sc)
{
if(taskId ==null|| taskId.isEmpty())
{
return false;
}
ServiceRegistry serviceRegistry = Repository.getServiceRegistry(sc);
String username = serviceRegistry.getAuthenticationService().getCurrentUserName();
WorkflowService workflowService = serviceRegistry.getWorkflowService();
WorkflowTask task = workflowService.getTaskById(taskId);
return workflowService.isTaskEditable(task, username);
}
}
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.servlet.ServletContext;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.ServiceRegistry;
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.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
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(final NodeRef ref, final NodeService nodeService, final CopyService copyService)
throws AlfrescoRuntimeException
{
Node docNode = new Node(ref);
if (docNode.hasAspect(ApplicationModel.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(ApplicationModel.PROP_APPROVE_MOVE.toString());
NodeRef approveFolder = (NodeRef)props.get(ApplicationModel.PROP_APPROVE_FOLDER.toString());
if (approveMove.booleanValue())
{
// first we need to take off the simpleworkflow aspect
nodeService.removeAspect(ref, ApplicationModel.ASPECT_SIMPLE_WORKFLOW);
// 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
{
// first we need to take off the simpleworkflow aspect
// NOTE: run as system to allow Consumers to copy an item
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
{
public String doWork() throws Exception
{
nodeService.removeAspect(ref, ApplicationModel.ASPECT_SIMPLE_WORKFLOW);
return null;
}
}, AuthenticationUtil.getSystemUserName());
// 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(ApplicationModel.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(ApplicationModel.PROP_REJECT_STEP.toString());
Boolean rejectMove = (Boolean)props.get(ApplicationModel.PROP_REJECT_MOVE.toString());
NodeRef rejectFolder = (NodeRef)props.get(ApplicationModel.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, ApplicationModel.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
*/
@SuppressWarnings("unchecked")
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<AssociationRef> originalAssocRefs = (List<AssociationRef>) node.getAssociations().get(assocName);
List<NodeRef> targets = new ArrayList<NodeRef>(addedAssocs.size());
if (originalAssocRefs != null)
{
for (AssociationRef assoc : originalAssocRefs)
{
targets.add(assoc.getTargetRef());
}
}
for (AssociationRef assoc : addedAssocs.values())
{
targets.add(assoc.getTargetRef());
}
params.put(assocQName, (Serializable)targets);
}
// go through the removed associations and either setup or adjust the
// parameters map accordingly
assocs = node.getRemovedAssociations();
for (String assocName : assocs.keySet())
{
QName assocQName = Repository.resolveToQName(assocName);
// get the associations removed and create list of targets
Map<String, AssociationRef> removedAssocs = assocs.get(assocName);
List<NodeRef> targets = (List<NodeRef>)params.get(assocQName);
if (targets == null)
{
// if there weren't any assocs of this type added get the current
// set of assocs from the node
List<AssociationRef> originalAssocRefs = (List<AssociationRef>)node.getAssociations().get(assocName);
targets = new ArrayList<NodeRef>(originalAssocRefs.size());
for (AssociationRef assoc : originalAssocRefs)
{
targets.add(assoc.getTargetRef());
}
}
// remove the assocs the user deleted
for (AssociationRef assoc : removedAssocs.values())
{
targets.remove(assoc.getTargetRef());
}
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;
}
public static boolean isTaskEditable(String taskId, ServletContext sc)
{
if(taskId ==null|| taskId.isEmpty())
{
return false;
}
ServiceRegistry serviceRegistry = Repository.getServiceRegistry(sc);
String username = serviceRegistry.getAuthenticationService().getCurrentUserName();
WorkflowService workflowService = serviceRegistry.getWorkflowService();
WorkflowTask task = workflowService.getTaskById(taskId);
return workflowService.isTaskEditable(task, username);
}
}