Ejemplo n.º 1
0
 public void testEndTask() {
   WorkflowDefinition workflowDef = getTestDefinition();
   Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
   parameters.put(
       QName.createQName(NamespaceService.DEFAULT_URI, "reviewer"),
       AuthenticationUtil.getAdminUserName());
   parameters.put(QName.createQName(NamespaceService.DEFAULT_URI, "testNode"), rootNodeRef);
   parameters.put(
       QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "package"),
       packageComponent.createPackage(null));
   WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), parameters);
   assertNotNull(path);
   List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
   assertNotNull(tasks1);
   assertEquals(1, tasks1.size());
   assertEquals(WorkflowTaskState.IN_PROGRESS, tasks1.get(0).getState());
   WorkflowTask updatedTask = taskComponent.endTask(tasks1.get(0).getId(), null);
   assertNotNull(updatedTask);
   assertEquals(WorkflowTaskState.COMPLETED, updatedTask.getState());
   List<WorkflowTask> completedTasks =
       taskComponent.getAssignedTasks(
           AuthenticationUtil.getAdminUserName(), WorkflowTaskState.COMPLETED);
   assertNotNull(completedTasks);
   completedTasks = filterTasksByWorkflowInstance(completedTasks, path.getInstance().getId());
   assertEquals(1, completedTasks.size());
   assertEquals(WorkflowTaskState.COMPLETED, completedTasks.get(0).getState());
 }
Ejemplo n.º 2
0
 private void signalStartTask(WorkflowPath path) {
   List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
   if (tasks.size() == 1) {
     WorkflowTask startTask = tasks.get(0);
     workflowService.endTask(startTask.getId(), null);
   } else {
     throw new WorkflowException(
         "Start task not found! Expected 1 task but found: " + tasks.size());
   }
 }
Ejemplo n.º 3
0
 /**
  * Filter task list by workflow instance
  *
  * @param tasks
  * @param processInstanceId
  * @return
  */
 private List<WorkflowTask> filterTasksByWorkflowInstance(
     List<WorkflowTask> tasks, String workflowInstanceId) {
   List<WorkflowTask> filteredTasks = new ArrayList<WorkflowTask>();
   for (WorkflowTask task : tasks) {
     if (task.getPath().getInstance().getId().equals(workflowInstanceId)) {
       filteredTasks.add(task);
     }
   }
   return filteredTasks;
 }
  private String getMessageValue(WorkflowTask task) {
    String message = I18NUtil.getMessage(MessageFieldProcessor.MSG_VALUE_NONE);

    String description = (String) task.getProperties().get(WorkflowModel.PROP_DESCRIPTION);
    if (description != null) {
      String taskTitle = task.getTitle();
      if (taskTitle == null || !taskTitle.equals(description)) {
        message = description;
      }
    }

    return message;
  }
 /**
  * @param task
  * @return
  */
 private Object getPackageItemValues(WorkflowTask task) {
   List<NodeRef> items = workflowService.getPackageContents(task.getId());
   ArrayList<String> results = new ArrayList<String>(items.size());
   for (NodeRef item : items) {
     results.add(item.toString());
   }
   return results;
 }
Ejemplo n.º 6
0
 public void testGetTask() {
   WorkflowDefinition workflowDef = getTestDefinition();
   Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
   parameters.put(
       QName.createQName(NamespaceService.DEFAULT_URI, "reviewer"),
       AuthenticationUtil.getAdminUserName());
   parameters.put(QName.createQName(NamespaceService.DEFAULT_URI, "testNode"), rootNodeRef);
   WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), parameters);
   assertNotNull(path);
   assertNotNull(path);
   List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
   assertNotNull(tasks1);
   assertEquals(1, tasks1.size());
   WorkflowTask getTask = taskComponent.getTaskById(tasks1.get(0).getId());
   assertNotNull(getTask);
   assertEquals(getTask.getId(), tasks1.get(0).getId());
 }
  private String getTransitionValues(WorkflowTask item) {
    WorkflowTransition[] transitions = item.getDefinition().getNode().getTransitions();

    if (transitions == null || transitions.length == 0) {
      return "";
    }

    return buildTransitionString(item, transitions);
  }
  private String getTaskOwnerValue(WorkflowTask task) {
    String owner = (String) task.getProperties().get(ContentModel.PROP_OWNER);

    if (owner == null || owner.length() == 0) {
      return null;
    }

    return buildTaskOwnerString(owner);
  }
Ejemplo n.º 9
0
  /**
   * See Alf-2764 in Jira.
   *
   * @throws Exception
   */
  public void testCancelForEachFork() throws Exception {
    // Deploy Parallel Loop Review process definition.
    ClassPathResource processDef =
        new ClassPathResource("test/alfresco/parallel_loop_review_processdefinition.xml");
    WorkflowDeployment deployment =
        workflowComponent.deployDefinition(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
    WorkflowDefinition parallelDef = deployment.getDefinition();
    assertNotNull(parallelDef);

    // Set Current User to USER1.
    AuthenticationUtil.setFullyAuthenticatedUser(USER1);

    // Set up parameters
    QName approvePercentName =
        QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "requiredApprovePercent");
    NodeRef pckgNode = packageComponent.createPackage(null);
    List<NodeRef> assignees = Arrays.asList(person1, person2, person3);
    Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
    parameters.put(WorkflowModel.ASSOC_ASSIGNEES, (Serializable) assignees);
    parameters.put(WorkflowModel.ASSOC_PACKAGE, pckgNode);
    parameters.put(approvePercentName, 60f);

    // Start workflow
    WorkflowPath path = workflowComponent.startWorkflow(parallelDef.getId(), parameters);
    WorkflowTask startTask = workflowComponent.getTasksForWorkflowPath(path.getId()).get(0);
    taskComponent.endTask(startTask.getId(), null);
    checkInstanceExists(path.getInstance().getId(), parallelDef.getId(), true);

    // Set all users to reject document.
    ParallelReject(USER1);
    ParallelReject(USER2);
    ParallelReject(USER3);

    // Send review back round the loop.
    List<WorkflowTask> tasks = workflowComponent.getTasksForWorkflowPath(path.getId());
    assertEquals(1, tasks.size());
    taskComponent.endTask(tasks.get(0).getId(), "again");

    // Try to cancel workflow
    WorkflowInstance cancelledWf = workflowComponent.cancelWorkflow(path.getInstance().getId());
    checkInstanceExists(cancelledWf.getId(), parallelDef.getId(), false);
  }
Ejemplo n.º 10
0
  public void testStartWorkflowParameters() {
    WorkflowDefinition workflowDef = getTestDefinition();

    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.PROP_TASK_ID, 3); // protected - shouldn't be written
    params.put(WorkflowModel.PROP_DUE_DATE, new Date()); // task instance field
    params.put(WorkflowModel.PROP_PRIORITY, 1); // task instance field
    params.put(WorkflowModel.PROP_PERCENT_COMPLETE, 10); // context variable
    params.put(
        QName.createQName("", "Message"),
        "Hello World"); // context variable outside of task definition
    params.put(
        QName.createQName("", "Array"),
        new String[] {"one", "two"}); // context variable outside of task definition
    params.put(
        QName.createQName("", "NodeRef"),
        new NodeRef("workspace://1/1001")); // context variable outside of task definition
    params.put(ContentModel.PROP_OWNER, AuthenticationUtil.getAdminUserName()); // task assignment

    WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
    assertNotNull(path);
    assertTrue(path.getId().endsWith("-@"));
    assertNotNull(path.getNode());
    assertNotNull(path.getInstance());
    assertEquals(workflowDef.getId(), path.getInstance().getDefinition().getId());
    List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());

    WorkflowTask task = tasks1.get(0);
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_TASK_ID));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_DUE_DATE));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_PRIORITY));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_PERCENT_COMPLETE));
    assertTrue(task.getProperties().containsKey(ContentModel.PROP_OWNER));

    NodeRef initiator = path.getInstance().getInitiator();
    String initiatorUsername =
        (String) nodeService.getProperty(initiator, ContentModel.PROP_USERNAME);
    assertEquals(AuthenticationUtil.getAdminUserName(), initiatorUsername);
  }
 @SuppressWarnings("unchecked")
 private List<String> getHiddenTransitions(WorkflowTask task) {
   Serializable hiddenValues = task.getProperties().get(WorkflowModel.PROP_HIDDEN_TRANSITIONS);
   if (hiddenValues != null) {
     if (hiddenValues instanceof List<?>) {
       return (List<String>) hiddenValues;
     } else if (hiddenValues instanceof String && ((String) hiddenValues).length() > 0) {
       return Arrays.asList(((String) hiddenValues).split(","));
     }
   }
   return Collections.emptyList();
 }
 @Override
 protected TypeDefinition getBaseType(WorkflowTask task) {
   return task.getDefinition().getMetadata();
 }
 /** {@inheritDoc} */
 @Override
 protected String getItemType(WorkflowTask item) {
   TypeDefinition typeDef = item.getDefinition().getMetadata();
   return typeDef.getName().toPrefixString(namespaceService);
 }
 @Override
 protected Map<QName, Serializable> getPropertyValues(WorkflowTask task) {
   return task.getProperties();
 }
Ejemplo n.º 15
0
 private void ParallelReject(String user) {
   List<WorkflowTask> tasks = taskComponent.getAssignedTasks(user, WorkflowTaskState.IN_PROGRESS);
   assertEquals(1, tasks.size());
   WorkflowTask task = tasks.get(0);
   taskComponent.endTask(task.getId(), "reject");
 }
 @Override
 protected Map<QName, Serializable> getAssociationValues(WorkflowTask item) {
   return item.getProperties();
 }
Ejemplo n.º 17
0
  public void testUpdateTask() {
    WorkflowDefinition workflowDef = getTestDefinition();

    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.PROP_TASK_ID, 3); // protected - shouldn't be written
    params.put(WorkflowModel.PROP_DUE_DATE, new Date()); // task instance field
    params.put(WorkflowModel.PROP_PRIORITY, 1); // task instance field
    params.put(WorkflowModel.PROP_PERCENT_COMPLETE, 10); // context variable
    params.put(
        QName.createQName("", "Message"),
        "Hello World"); // context variable outside of task definition
    params.put(
        QName.createQName("", "Array"),
        new String[] {"one", "two"}); // context variable outside of task definition
    params.put(
        QName.createQName("", "NodeRef"),
        new NodeRef("workspace://1/1001")); // context variable outside of task definition
    params.put(ContentModel.PROP_OWNER, AuthenticationUtil.getAdminUserName()); // task assignment

    WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
    assertNotNull(path);
    assertTrue(path.getId().endsWith("-@"));
    assertNotNull(path.getNode());
    assertNotNull(path.getInstance());
    assertEquals(workflowDef.getId(), path.getInstance().getDefinition().getId());
    List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());

    WorkflowTask task = tasks1.get(0);
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_TASK_ID));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_DUE_DATE));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_PRIORITY));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_PERCENT_COMPLETE));
    assertTrue(task.getProperties().containsKey(ContentModel.PROP_OWNER));

    // update with null parameters
    try {
      WorkflowTask taskU1 = taskComponent.updateTask(task.getId(), null, null, null);
      assertNotNull(taskU1);
    } catch (Throwable e) {
      fail("Task update failed with null parameters");
    }

    // update property value
    Map<QName, Serializable> updateProperties2 = new HashMap<QName, Serializable>();
    updateProperties2.put(WorkflowModel.PROP_PERCENT_COMPLETE, 100);
    WorkflowTask taskU2 = taskComponent.updateTask(task.getId(), updateProperties2, null, null);
    assertEquals(100, taskU2.getProperties().get(WorkflowModel.PROP_PERCENT_COMPLETE));

    // add to assocation
    QName assocName = QName.createQName("", "TestAssoc");
    List<NodeRef> toAdd = new ArrayList<NodeRef>();
    toAdd.add(new NodeRef("workspace://1/1001"));
    toAdd.add(new NodeRef("workspace://1/1002"));
    toAdd.add(new NodeRef("workspace://1/1003"));
    Map<QName, List<NodeRef>> addAssocs = new HashMap<QName, List<NodeRef>>();
    addAssocs.put(assocName, toAdd);
    WorkflowTask taskU3 = taskComponent.updateTask(task.getId(), null, addAssocs, null);
    assertNotNull(taskU3.getProperties().get(assocName));
    assertEquals(3, ((List<?>) taskU3.getProperties().get(assocName)).size());

    // add to assocation again
    List<NodeRef> toAddAgain = new ArrayList<NodeRef>();
    toAddAgain.add(new NodeRef("workspace://1/1004"));
    toAddAgain.add(new NodeRef("workspace://1/1005"));
    Map<QName, List<NodeRef>> addAssocsAgain = new HashMap<QName, List<NodeRef>>();
    addAssocsAgain.put(assocName, toAddAgain);
    WorkflowTask taskU4 = taskComponent.updateTask(task.getId(), null, addAssocsAgain, null);
    assertNotNull(taskU4.getProperties().get(assocName));
    assertEquals(5, ((List<?>) taskU4.getProperties().get(assocName)).size());

    // remove assocation
    List<NodeRef> toRemove = new ArrayList<NodeRef>();
    toRemove.add(new NodeRef("workspace://1/1002"));
    toRemove.add(new NodeRef("workspace://1/1003"));
    Map<QName, List<NodeRef>> removeAssocs = new HashMap<QName, List<NodeRef>>();
    removeAssocs.put(assocName, toRemove);
    WorkflowTask taskU5 = taskComponent.updateTask(task.getId(), null, null, removeAssocs);
    assertNotNull(taskU5.getProperties().get(assocName));
    assertEquals(3, ((List<?>) taskU5.getProperties().get(assocName)).size());
  }
 /** {@inheritDoc} */
 @Override
 protected String getItemURI(WorkflowTask item) {
   return "api/task-instances/" + item.getId();
 }