AnsweredAssumed Answered

Creating Attachment in Java Service Task: says task not found

Question asked by pbhat on Nov 5, 2013
Following code Creating Attachment in Java Service Task throws exception.
Any help is appreciated.
Thanks


public boolean attachRelatedContent( DelegateExecution execution, String uncompFolderName) {
      String INPUT_FILE_DIREC_UNCOMPR = "landing_uncompr";
      boolean retCode=true;

      //http://forums.activiti.org/content/how-retrieve-task-id-and-name-service-task
      ExecutionEntity ee = (ExecutionEntity) execution;
      String name = (String) ee.getActivity().getProperties().get("name");
      String id = ee.getActivity().getId();
      System.out.println(name);
      System.out.println(id); // This line prints id properly

      
      //  RuntimeService runtimeService = execution.getEngineServices().getRuntimeService();
       TaskService taskService = execution.getEngineServices().getTaskService();
      
       InputStream htmlStream=null;
      try {
         htmlStream = new FileInputStream(INPUT_FILE_DIREC_UNCOMPR+uncompFolderName+"/manifest.html");
      } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
       //Following statements cause exceptions which says task not found
       taskService.createAttachment("application/html", 
             id, null, "Score",
       "Score Details", htmlStream);
       taskService.createAttachment("application/html", 
             execution.getProcessInstanceId(), null, "Score",
       "Score Details", htmlStream);
   
       taskService.createAttachment("url", id, 
       null, "Alfresco site", "A Alfresco site for Activiti",
       "http://localhost:9090/share/page/site/activiti/" +
       "document-details?nodeRef=workspace://SpacesStore/" +
       "007df67f-28a8-4973-a39b-459c835c0712");
      
        List<Attachment> attachmentList = taskService
       .getTaskAttachments(id);
        System.out.println("attachments:"+attachmentList.toString());
       
      return retCode;
   }

Outcomes