Package org.activiti.engine.task

Examples of org.activiti.engine.task.Attachment


    try {
      Task task = taskService.newTask();
      taskService.saveTask(task);

      // Create URL-attachment
      Attachment urlAttachment = taskService.createAttachment("simpleType", task.getId(), null, "Simple attachment", "Simple attachment description",
              "http://activiti.org");
      taskService.saveAttachment(urlAttachment);

      // Get attachment content for non-binary attachment
      closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, task.getId(), urlAttachment.getId())), HttpStatus.SC_NOT_FOUND));
     
    } finally {
      // Clean adhoc-tasks even if test fails
      List<Task> tasks = taskService.createTaskQuery().list();
      for (Task task : tasks) {
View Full Code Here


     
      // Check if attachment is created
      List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
      assertEquals(1, attachments.size());
     
      Attachment urlAttachment = attachments.get(0);
     
      JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
      closeResponse(response);
      assertEquals(urlAttachment.getId(), responseNode.get("id").textValue());
      assertEquals("simpleType", responseNode.get("type").textValue());
      assertEquals("Simple attachment", responseNode.get("name").textValue());
      assertEquals("Simple attachment description", responseNode.get("description").textValue());
      assertEquals("http://activiti.org", responseNode.get("externalUrl").textValue());
      assertTrue(responseNode.get("url").textValue()
              .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())));
      assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));

      assertTrue(responseNode.get("contentUrl").isNull());
      assertTrue(responseNode.get("processInstanceUrl").isNull());
     
View Full Code Here

     
      // Check if attachment is created
      List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
      assertEquals(1, attachments.size());
     
      Attachment binaryAttachment = attachments.get(0);
      assertEquals("This is binary content", IOUtils.toString(taskService.getAttachmentContent(binaryAttachment.getId())));
     
      JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
      closeResponse(response);
      assertEquals(binaryAttachment.getId(), responseNode.get("id").textValue());
      assertEquals("myType", responseNode.get("type").textValue());
      assertEquals("An attachment", responseNode.get("name").textValue());
      assertEquals("An attachment description", responseNode.get("description").textValue());
      assertTrue(responseNode.get("url").textValue()
              .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), binaryAttachment.getId())));
      assertTrue(responseNode.get("contentUrl").textValue()
              .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, task.getId(), binaryAttachment.getId())));
      assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));

      assertTrue(responseNode.get("externalUrl").isNull());
      assertTrue(responseNode.get("processInstanceUrl").isNull());
     
View Full Code Here

    try {
      Task task = taskService.newTask();
      taskService.saveTask(task);

      // Create URL-attachment
      Attachment urlAttachment = taskService.createAttachment("simpleType", task.getId(), null, "Simple attachment", "Simple attachment description",
              "http://activiti.org");
      taskService.saveAttachment(urlAttachment);

      // Delete the attachment
      HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId()));
      closeResponse(executeBinaryRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
     
      // Check if attachment is really deleted
      assertNull(taskService.getAttachment(urlAttachment.getId()));
     
      // Deleting again should result in 404
      closeResponse(executeBinaryRequest(httpDelete, HttpStatus.SC_NOT_FOUND));
     
    } finally {
View Full Code Here

    try {
      Task task = taskService.newTask();
      taskService.saveTask(task);

      // Create URL-attachment
      Attachment urlAttachment = taskService.createAttachment("simpleType", task.getId(), null, "Simple attachment", "Simple attachment description",
              "http://activiti.org");
      taskService.saveAttachment(urlAttachment);

      // Create Binary-attachment
      Attachment binaryAttachment = taskService.createAttachment("binaryType", task.getId(), null, "Binary attachment", "Binary attachment description",
              new ByteArrayInputStream("This is binary content".getBytes()));
      taskService.saveAttachment(binaryAttachment);
     
      taskService.complete(task.getId());

      // Get external url attachment
      CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())), HttpStatus.SC_OK);
     
      JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
      closeResponse(response);
      assertEquals(urlAttachment.getId(), responseNode.get("id").textValue());
      assertEquals("simpleType", responseNode.get("type").textValue());
      assertEquals("Simple attachment", responseNode.get("name").textValue());
      assertEquals("Simple attachment description", responseNode.get("description").textValue());
      assertEquals("http://activiti.org", responseNode.get("externalUrl").textValue());
      assertTrue(responseNode.get("url").textValue()
              .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())));
      assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));

      assertTrue(responseNode.get("contentUrl").isNull());
      assertTrue(responseNode.get("processInstanceUrl").isNull());
     
     
      // Get binary attachment
      response = executeRequest(new HttpGet(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), binaryAttachment.getId())), HttpStatus.SC_OK);
      responseNode = objectMapper.readTree(response.getEntity().getContent());
      closeResponse(response);
      assertEquals(binaryAttachment.getId(), responseNode.get("id").textValue());
      assertEquals("binaryType", responseNode.get("type").textValue());
      assertEquals("Binary attachment", responseNode.get("name").textValue());
      assertEquals("Binary attachment description", responseNode.get("description").textValue());
      assertTrue(responseNode.get("url").textValue()
              .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), binaryAttachment.getId())));
      assertTrue(responseNode.get("contentUrl").textValue()
              .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, task.getId(), binaryAttachment.getId())));
      assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));

      assertTrue(responseNode.get("externalUrl").isNull());
      assertTrue(responseNode.get("processInstanceUrl").isNull());
     
View Full Code Here

     
      Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
      assertNotNull(task);
     
      // Create link-attachment
      Attachment attachment = taskService.createAttachment("test", task.getId(), processInstance.getId(), "attachment name", "description", "http://activiti.org");
      assertNull(attachment.getUserId());
      assertEquals(2, listener.getEventsReceived().size());
      ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
      assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
      assertEquals(processInstance.getId(), event.getProcessInstanceId());
      assertEquals(processInstance.getId(), event.getExecutionId());
      assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
      Attachment attachmentFromEvent = (Attachment) event.getEntity();
      assertEquals(attachment.getId(), attachmentFromEvent.getId());
      event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
      assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
      assertEquals(processInstance.getId(), event.getProcessInstanceId());
      assertEquals(processInstance.getId(), event.getExecutionId());
      assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
      attachmentFromEvent = (Attachment) event.getEntity();
      assertEquals(attachment.getId(), attachmentFromEvent.getId());
      listener.clearEventsReceived();
     
      // Create binary attachment
      Authentication.setAuthenticatedUserId("testuser");
      attachment = taskService.createAttachment("test", task.getId(), processInstance.getId(), "attachment name", "description", new ByteArrayInputStream("test".getBytes()));
      assertNotNull(attachment.getUserId());
      assertEquals("testuser", attachment.getUserId());
      assertEquals(2, listener.getEventsReceived().size());
      event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
      assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
      assertEquals(processInstance.getId(), event.getProcessInstanceId());
      assertEquals(processInstance.getId(), event.getExecutionId());
      assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
      attachmentFromEvent = (Attachment) event.getEntity();
      assertEquals(attachment.getId(), attachmentFromEvent.getId());
     
      event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
      assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
      listener.clearEventsReceived();
     
      // Update attachment
      attachment = taskService.getAttachment(attachment.getId());
      attachment.setDescription("Description");
      taskService.saveAttachment(attachment);
     
      assertEquals(1, listener.getEventsReceived().size());
      event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
      assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
      assertEquals(processInstance.getId(), event.getProcessInstanceId());
      assertEquals(processInstance.getId(), event.getExecutionId());
      assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
      attachmentFromEvent = (Attachment) event.getEntity();
      assertEquals(attachment.getId(), attachmentFromEvent.getId());
      assertEquals("Description", attachmentFromEvent.getDescription());
      listener.clearEventsReceived();
     
      // Finally, delete attachment
      taskService.deleteAttachment(attachment.getId());
      assertEquals(1, listener.getEventsReceived().size());
      event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
      assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
      assertEquals(processInstance.getId(), event.getProcessInstanceId());
      assertEquals(processInstance.getId(), event.getExecutionId());
      assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
      attachmentFromEvent = (Attachment) event.getEntity();
      assertEquals(attachment.getId(), attachmentFromEvent.getId());
    }
  }
View Full Code Here

        task = taskService.newTask();
        taskService.saveTask(task);
        assertNotNull(task);
       
        // Create link-attachment
        Attachment attachment = taskService.createAttachment("test", task.getId(), null, "attachment name", "description", "http://activiti.org");
        assertEquals(2, listener.getEventsReceived().size());
        ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
        assertNull(event.getProcessInstanceId());
        assertNull(event.getExecutionId());
        assertNull(event.getProcessDefinitionId());
        Attachment attachmentFromEvent = (Attachment) event.getEntity();
        assertEquals(attachment.getId(), attachmentFromEvent.getId());
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
        assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
        listener.clearEventsReceived();
       
        // Create binary attachment
        attachment = taskService.createAttachment("test", task.getId(), null, "attachment name", "description", new ByteArrayInputStream("test".getBytes()));
        assertEquals(2, listener.getEventsReceived().size());
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
        assertNull(event.getProcessInstanceId());
        assertNull(event.getExecutionId());
        assertNull(event.getProcessDefinitionId());
        attachmentFromEvent = (Attachment) event.getEntity();
        assertEquals(attachment.getId(), attachmentFromEvent.getId());
       
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
        assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
        listener.clearEventsReceived();
       
        // Update attachment
        attachment = taskService.getAttachment(attachment.getId());
        attachment.setDescription("Description");
        taskService.saveAttachment(attachment);
       
        assertEquals(1, listener.getEventsReceived().size());
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
        assertNull(event.getProcessInstanceId());
        assertNull(event.getExecutionId());
        assertNull(event.getProcessDefinitionId());
        attachmentFromEvent = (Attachment) event.getEntity();
        assertEquals(attachment.getId(), attachmentFromEvent.getId());
        assertEquals("Description", attachmentFromEvent.getDescription());
        listener.clearEventsReceived();
       
        // Finally, delete attachment
        taskService.deleteAttachment(attachment.getId());
        assertEquals(1, listener.getEventsReceived().size());
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
        assertNull(event.getProcessInstanceId());
        assertNull(event.getExecutionId());
        assertNull(event.getProcessDefinitionId());
        attachmentFromEvent = (Attachment) event.getEntity();
        assertEquals(attachment.getId(), attachmentFromEvent.getId());
       
      } finally {
        if(task != null && task.getId() != null) {
          taskService.deleteTask(task.getId());
          historyService.deleteHistoricTaskInstance(task.getId());
View Full Code Here

        task = taskService.newTask();
        taskService.saveTask(task);
        assertNotNull(task);
       
        // Create link-attachment
        Attachment attachment = taskService.createAttachment("test", task.getId(), null, "attachment name", "description", "http://activiti.org");
        listener.clearEventsReceived();
       
        // Delete task and historic task
        taskService.deleteTask(task.getId());
        historyService.deleteHistoricTaskInstance(task.getId());
       
        assertEquals(1, listener.getEventsReceived().size());
        ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
        assertNull(event.getProcessInstanceId());
        assertNull(event.getExecutionId());
        assertNull(event.getProcessDefinitionId());
        Attachment attachmentFromEvent = (Attachment) event.getEntity();
        assertEquals(attachment.getId(), attachmentFromEvent.getId());
       
      } finally {
        if(task != null && task.getId() != null) {
          taskService.deleteTask(task.getId());
          historyService.deleteHistoricTaskInstance(task.getId());
View Full Code Here

      taskService.saveTask(task);
      String taskId = task.getId();
      identityService.setAuthenticatedUserId("johndoe");
      // Fetch the task again and update
      taskService.createAttachment("web page", taskId, null, "weatherforcast", "temperatures and more", "http://weather.com");
      Attachment attachment = taskService.getTaskAttachments(taskId).get(0);
      assertEquals("weatherforcast", attachment.getName());
      assertEquals("temperatures and more", attachment.getDescription());
      assertEquals("web page", attachment.getType());
      assertEquals(taskId, attachment.getTaskId());
      assertNull(attachment.getProcessInstanceId());
      assertEquals("http://weather.com", attachment.getUrl());
      assertNull(taskService.getAttachmentContent(attachment.getId()));
     
      // Finally, clean up
      taskService.deleteTask(taskId);
     
      assertEquals(0, taskService.getTaskComments(taskId).size());
View Full Code Here

  public AttachmentResponse getAttachment(@PathVariable("taskId") String taskId,
      @PathVariable("attachmentId") String attachmentId, HttpServletRequest request) {
   
    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
   
    Attachment attachment = taskService.getAttachment(attachmentId);
    if (attachment == null || !task.getId().equals(attachment.getTaskId())) {
      throw new ActivitiObjectNotFoundException("Task '" + task.getId() +"' doesn't have an attachment with id '" + attachmentId + "'.", Comment.class);
    }
   
    String serverRootUrl = request.getRequestURL().toString();
    serverRootUrl = serverRootUrl.substring(0, serverRootUrl.indexOf("/runtime/tasks/"));
View Full Code Here

TOP

Related Classes of org.activiti.engine.task.Attachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.