use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class ManageTaskDialog method takeOwnership.
// ------------------------------------------------------------------------------
// Event handlers
@SuppressWarnings("deprecation")
public String takeOwnership() {
String outcome = getDefaultFinishOutcome();
if (LOGGER.isDebugEnabled())
LOGGER.debug("Taking ownership of task: " + this.getWorkflowTask().id);
FacesContext context = FacesContext.getCurrentInstance();
// before taking ownership check the task still exists and is not
// completed
WorkflowTask checkTask = this.getWorkflowService().getTaskById(this.getWorkflowTask().id);
if (checkTask == null || checkTask.state == WorkflowTaskState.COMPLETED) {
Utils.addErrorMessage(Application.getMessage(context, "invalid_task"));
return outcome;
}
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context);
tx.begin();
// prepare the edited parameters for saving
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(ContentModel.PROP_OWNER, userName);
// update the task with the updated parameters and resources
updateResources();
this.getWorkflowService().updateTask(this.getWorkflowTask().id, params, null, null);
// commit the changes
tx.commit();
} catch (Throwable e) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception ex) {
}
Utils.addErrorMessage(formatErrorMessage(e), e);
outcome = this.getErrorOutcome(e);
}
return outcome;
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class ManageTaskDialog method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Saving task: " + this.getWorkflowTask().id);
// before updating the task still exists and is not completed
WorkflowTask checkTask = this.getWorkflowService().getTaskById(this.getWorkflowTask().id);
if (checkTask == null || checkTask.state == WorkflowTaskState.COMPLETED) {
Utils.addErrorMessage(Application.getMessage(context, "invalid_task"));
return outcome;
}
// prepare the edited parameters for saving
Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.taskNode);
if (LOGGER.isDebugEnabled())
LOGGER.debug("Saving task with parameters: " + params);
// update the task with the updated parameters and resources
updateResources();
this.getWorkflowService().updateTask(this.getWorkflowTask().id, params, null, null);
return outcome;
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class WorkflowBean method getAllActiveTasks.
// ------------------------------------------------------------------------------
// 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;
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class CancelWorkflowEvaluator method evaluate.
/**
* @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
*/
public boolean evaluate(Node node) {
boolean result = false;
FacesContext context = FacesContext.getCurrentInstance();
// get the task from the node
WorkflowTask task = (WorkflowTask) node.getProperties().get("workflowTask");
if (task != null) {
NodeRef initiator = task.path.instance.initiator;
if (initiator != null) {
// find the current username
User user = Application.getCurrentUser(context);
String currentUserName = user.getUserName();
// get the username of the initiator
NodeService nodeSvc = Repository.getServiceRegistry(context).getNodeService();
String userName = (String) nodeSvc.getProperty(initiator, ContentModel.PROP_USERNAME);
// if the current user started the workflow allow the cancel action
if (currentUserName.equals(userName)) {
result = true;
}
}
}
return result;
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class TaskInstanceGet method buildModel.
@Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
Map<String, String> params = req.getServiceMatch().getTemplateVars();
// getting task id from request parameters
String taskId = params.get("task_instance_id");
// searching for task in repository
WorkflowTask workflowTask = workflowService.getTaskById(taskId);
// task was not found -> return 404
if (workflowTask == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find workflow task with id: " + taskId);
}
Map<String, Object> model = new HashMap<String, Object>();
// build the model for ftl
model.put("workflowTask", modelBuilder.buildDetailed(workflowTask));
return model;
}
Aggregations