use of org.alfresco.service.cmr.workflow.WorkflowInstance in project acs-community-packaging by Alfresco.
the class UIWorkflowSummary method encodeBegin.
@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
if (!isRendered())
return;
WorkflowInstance wi = getValue();
if (wi != null) {
ResponseWriter out = context.getResponseWriter();
ResourceBundle bundle = Application.getBundle(context);
// output surrounding table and style if necessary
out.write("<table");
if (this.getAttributes().get("style") != null) {
out.write(" style=\"");
out.write((String) this.getAttributes().get("style"));
out.write("\"");
}
if (this.getAttributes().get("styleClass") != null) {
out.write(" class=\"");
out.write((String) this.getAttributes().get("styleClass"));
out.write("\"");
}
out.write(">");
// output the title and description
out.write("<tr><td>");
out.write(bundle.getString("title"));
out.write(":</td><td>");
out.write(wi.definition.title);
if (wi.definition.description != null && wi.definition.description.length() > 0) {
out.write(" (");
out.write(Utils.encode(wi.definition.description));
out.write(")");
}
out.write("</td></tr><tr><td>");
out.write(bundle.getString("initiated_by"));
out.write(":</td><td>");
NodeService nodeService = getNodeService(context);
if (wi.initiator != null) {
if (nodeService.exists(wi.initiator)) {
out.write(Utils.encode(User.getFullName(Repository.getServiceRegistry(context).getNodeService(), wi.initiator)));
} else {
out.write("<");
out.write(bundle.getString("unknown"));
out.write(">");
}
}
out.write("</td></tr><tr><td>");
out.write(bundle.getString("started_on"));
out.write(":</td><td>");
if (wi.startDate != null) {
out.write(Utils.getDateFormat(context).format(wi.startDate));
}
out.write("</td></tr><tr><td>");
out.write(bundle.getString("completed_on"));
out.write(":</td><td>");
if (wi.endDate != null) {
out.write(Utils.getDateFormat(context).format(wi.endDate));
} else {
out.write("<");
out.write(bundle.getString("in_progress"));
out.write(">");
}
out.write("</td></tr></table>");
}
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class WorkflowInstanceDelete method canUserEndWorkflow.
/**
* Determines if the current user can cancel or delete the
* workflow instance with the given id. Throws a WebscriptException
* with status-code 404 if workflow-instance to delete wasn't found.
*
* @param instanceId The id of the workflow instance to check
* @return true if the user can end the workflow, false otherwise
*/
private boolean canUserEndWorkflow(String instanceId) {
boolean canEnd = false;
// get the initiator
WorkflowInstance wi = workflowService.getWorkflowById(instanceId);
if (wi == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "The workflow instance to delete/cancel with id " + instanceId + " doesn't exist: ");
}
String currentUserName = authenticationService.getCurrentUserName();
// ALF-17405: Admin can always delete/cancel workflows, regardless of the initiator
if (authorityService.isAdminAuthority(currentUserName)) {
canEnd = true;
} else {
String ownerName = null;
// Determine if the current user is the initiator of the workflow.
// Get the username of the initiator.
NodeRef initiator = wi.getInitiator();
if (initiator != null && nodeService.exists(initiator)) {
ownerName = (String) nodeService.getProperty(initiator, ContentModel.PROP_USERNAME);
} else {
/*
* Fix for MNT-14411 : Re-created user can't cancel created task.
* If owner value can't be found on workflow properties
* because initiator nodeRef no longer exists get owner from
* initiatorhome nodeRef owner property.
*/
WorkflowTask startTask = workflowService.getStartTask(wi.getId());
Map<QName, Serializable> props = startTask.getProperties();
ownerName = (String) props.get(ContentModel.PROP_OWNER);
if (ownerName == null) {
NodeRef initiatorHomeNodeRef = (NodeRef) props.get(QName.createQName("", WorkflowConstants.PROP_INITIATOR_HOME));
if (initiatorHomeNodeRef != null) {
ownerName = (String) nodeService.getProperty(initiatorHomeNodeRef, ContentModel.PROP_OWNER);
}
}
}
// if the current user started the workflow allow the cancel action
if (currentUserName.equals(ownerName)) {
canEnd = true;
}
}
return canEnd;
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class WorkflowInstanceDiagramGet method execute.
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
Map<String, String> params = req.getServiceMatch().getTemplateVars();
// getting workflow instance id from request parameters
String workflowInstanceId = params.get("workflow_instance_id");
WorkflowInstance workflowInstance = workflowService.getWorkflowById(workflowInstanceId);
// workflow instance was not found -> return 404
if (workflowInstance == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find workflow instance with id: " + workflowInstanceId);
}
// check whether there is a diagram available
if (!workflowService.hasWorkflowImage(workflowInstanceId)) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find diagram for workflow instance with id: " + workflowInstanceId);
}
// copy image data into temporary file
File file = TempFileProvider.createTempFile("workflow-diagram-", ".png");
InputStream imageData = workflowService.getWorkflowImage(workflowInstanceId);
OutputStream os = new FileOutputStream(file);
FileCopyUtils.copy(imageData, os);
// stream temporary file back to client
streamContent(req, res, file);
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class WorkflowInstancesForNodeGet method buildModel.
@Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
Map<String, String> params = req.getServiceMatch().getTemplateVars();
// get nodeRef from request
NodeRef nodeRef = new NodeRef(params.get(PARAM_STORE_TYPE), params.get(PARAM_STORE_ID), params.get(PARAM_NODE_ID));
// list all active workflows for nodeRef
List<WorkflowInstance> workflows = workflowService.getWorkflowsForContent(nodeRef, true);
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(workflows.size());
for (WorkflowInstance workflow : workflows) {
results.add(modelBuilder.buildSimple(workflow));
}
Map<String, Object> model = new HashMap<String, Object>();
// build the model for ftl
model.put("workflowInstances", results);
return model;
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testWorkflowInstanceDeleteAsAdministrator.
public void testWorkflowInstanceDeleteAsAdministrator() throws Exception {
// Start workflow as USER1
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
Date dueDate = new Date();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
params.put(WorkflowModel.PROP_CONTEXT, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
startTask = workflowService.endTask(startTask.getId(), null);
WorkflowInstance adhocInstance = startTask.getPath().getInstance();
// Run next request as admin
String admin = authenticationComponent.getDefaultAdministratorUserNames().iterator().next();
AuthenticationUtil.setFullyAuthenticatedUser(admin);
sendRequest(new DeleteRequest(URL_WORKFLOW_INSTANCES + "/" + adhocInstance.getId()), Status.STATUS_OK);
WorkflowInstance instance = workflowService.getWorkflowById(adhocInstance.getId());
if (instance != null) {
assertFalse("The deleted workflow is still active!", instance.isActive());
}
List<WorkflowInstance> instances = workflowService.getActiveWorkflows(adhocInstance.getDefinition().getId());
for (WorkflowInstance activeInstance : instances) {
assertFalse(adhocInstance.getId().equals(activeInstance.getId()));
}
}
Aggregations