use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class TaskInstancePut 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");
JSONObject json = null;
try {
WorkflowTask workflowTask = workflowService.getTaskById(taskId);
String currentUser = authenticationService.getCurrentUserName();
// read request json
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// update task properties
workflowTask = workflowService.updateTask(taskId, parseTaskProperties(json, workflowTask), null, null);
// task was not found -> return 404
if (workflowTask == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Failed to find workflow task with id: " + taskId);
}
// build the model for ftl
Map<String, Object> model = new HashMap<String, Object>();
model.put("workflowTask", modelBuilder.buildDetailed(workflowTask));
return model;
} catch (IOException iox) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je);
} catch (AccessDeniedException ade) {
throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Failed to update workflow task with id: " + taskId, ade);
} catch (WorkflowException we) {
throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Failed to update workflow task with id: " + taskId, we);
}
}
use of org.alfresco.service.cmr.workflow.WorkflowTask 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.WorkflowTask in project alfresco-remote-api by Alfresco.
the class InviteByTicket method getInvitationStatus.
private String getInvitationStatus(NominatedInvitation invitation) {
String invitee = invitation.getInviteeUserName();
String site = invitation.getResourceName();
// check is invitee is site member
boolean isUserMember = serviceRegistry.getSiteService().isMember(site, invitee);
WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setTaskName(WorkflowModelNominatedInvitation.WF_TASK_ACTIVIT_INVITE_PENDING);
query.setProcessId(invitation.getInviteId());
// query current workflow's task activitiInvitePendingTask
List<WorkflowTask> pendingInvitationTasks = serviceRegistry.getWorkflowService().queryTasks(query, false);
// if it's here - pending invitation
if (!pendingInvitationTasks.isEmpty()) {
return InviteInfo.INVITATION_STATUS_PENDING;
} else if (isUserMember) {
return InviteInfo.INVITATION_STATUS_ACCEPTED;
} else {
return InviteInfo.INVITATION_STATUS_REJECTED;
}
}
use of org.alfresco.service.cmr.workflow.WorkflowTask 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()));
}
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testWorkflowPermissions.
public void testWorkflowPermissions() throws Exception {
// Start workflow as USER1 and assign task to USER1.
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER1));
Calendar dueDateCal = Calendar.getInstance();
Date dueDate = dueDateCal.getTime();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
String workflowId = adhocPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getStartTask(workflowId);
workflowService.endTask(startTask.getId(), null);
// Check tasks of USER1 from behalf of USER2
personManager.setUser(USER2);
Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER1)), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
JSONArray results = json.getJSONArray("data");
assertNotNull(results);
assertTrue("User2 should not see any tasks if he is not initiator or assignee", results.length() == 0);
}
Aggregations