cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Activiti-App: showing attached process and task documents

mikeblum
Champ in-the-making
Champ in-the-making
Hi,

I'm attempting to programatically attach a file to an Activiti Process Instance. I've proved out that I can set the text of a form field but am not able to attach a document yet.

My first attempt was to add a byte array of the file to the properties ultimately being sent to the process before calling

FileInputStream fs;
      try {
          fs = new FileInputStream("test-doc.pdf");
          //attach it to the process at large
          //TODO: get the attachment mimetype
          workflowData.put("workflowdocument", IOUtils.toByteArray(fs));
          logger.info("Attaching file as workflowdocument to process");
      } catch (Exception e) {
         logger.error("Failed to attach mock file to process", e);
      }

ProcessInstance newInstance = runtimeService.startProcessInstanceById(processId, workflowData);


My second attempt was to attach the attachment using the TaskService after the task had been created:


logger.info("Started workflow " + newInstance.getId() + " with process: " + processId);
        FileInputStream fs;
      try {
         fs = new FileInputStream("test-doc.pdf");
         //attach it to the process at large
         //TODO: get the attachment mimetype
         Attachment attachment = taskService.createAttachment("application/pdf", null, newInstance.getId(), "workflowdocument", "test doc", fs);
      } catch (FileNotFoundException e) {
         logger.error("Failed to attach file to process: " +  newInstance.getId(), e);
      }


But neither show in the activiti-app when viewing that task. But they are successfully being attached when I cross-check with the Task Service.

I can't seem to embed my screenshots here so here's an imgur link:

http://imgur.com/a/NvFkB#RDqfi4S

What is the proper way for attaching a document (a content item I believe?) to have it show up in the activiti-app interface?

Thanks,
Mike
8 REPLIES 8

trademak
Star Contributor
Star Contributor
Hi Mike,

You are working with the Alfresco Activiti Enterprise application right?
There's a different API in enterprise to add attachments / related content to a task or process instance.
This API is part of the RelatedContentService.

Best regards,

mikeblum
Champ in-the-making
Champ in-the-making
Hi Tijs,
Correct I'm using the enterprise Activiti application. I wasn't able to find any documentation on the related content service in the public activiti api docs (http://activiti.org/javadocs).  Is this an alfresco specific service?


Thanks,
Mike

http://activiti.org/javadocs/

mikeblum
Champ in-the-making
Champ in-the-making
Hi Tijs,

I found the necessary endpoints in the bundled documentation with the Alfresco Enterprise Activiti Suite 1.2 installer.

Thanks,
Mike

mikeblum
Champ in-the-making
Champ in-the-making
Hi Tijs,

I've created a service that uploads content to the process but its not showing up in the activiti-app:

To add content to a process instance:

POST api/enterprise/process-instances/{processInstanceId}/content-raw

and I see the content was successfully attached with:

GET api/enterprise/process-instances/{processInstanceId}/content

Do I need to do anything else to get the document to show up on the task? I don't see the document on the process either in the activiti-app.

Thanks.
Mike

mikeblum
Champ in-the-making
Champ in-the-making
here's the result of the {processInstanceId}/content GET call:

<javascript>
{
  "size": 1,
  "total": 1,
  "start": 0,
  "data": [
    {
      "id": 7016,
      "name": "test-doc.pdf",
      "created": "2015-07-09T19:15:02.984+0000",
      "createdBy": {
        "id": 1,
        "firstName": "",
        "lastName": "Administrator",
        "email": "test@localhost"
      },
      "contentAvailable": true,
      "link": false,
      "mimeType": "application/octet-stream",
      "simpleType": "content",
      "previewStatus": "queued",
      "thumbnailStatus": "queued"
    }
  ]
}
</javascript>
It there something ewlse I need to do to get the document to show up on the process and/or task in the activiti-app?

jbarrez
Star Contributor
Star Contributor
Hi Mike,

I'm not sure if the UI already displays the related content for a process.

For a task it should work though, the same method: POST /enterprise/tasks/{taskId}/raw-content with the file in multipart/form-data.
There is an optional request parameter isRelatedContent that you can use to kick off renditions (thumbnail, preview) in the UI automatically.

jbarrez
Star Contributor
Star Contributor
(Moved this to the Enterprise forum)

mikeblum
Champ in-the-making
Champ in-the-making
Hi,

From my screenshot I can see we can add content to the process instance, just not the tasks. For some reason the POST /enterprise/tasks/{taskId}/raw-content endpoint is not documented in the Alfresco Activiti api docs - it says to use POST /enterprise/process-isntances/{taskId}/raw-content. I've raised this as a case with Alfresco.

Thanks,
Mike