08-12-2015 09:28 AM
08-12-2015 08:55 PM
09-18-2017 04:02 AM
Hello,
Its grate example to know how call activiti works.
In the above example you are passing parent process uploaded content to child process but I want in reverse way like from child process uploaded content to parent process. How can I achieve this?
Thanks
07-26-2019 02:31 AM
Hi Ciju,
I am trying to fetch the user task form attachments in task listener in the same process, using the activiti-6.0 (not the enterprise version) and using the activit-ap-logic-6.0.
I kept the task listener in com.activiti.extension.bean package and the below code returns the null.
page = relatedContentRepository.findAllByProcessInstanceIdAndField(
delegateTask.getProcessInstanceId().toString(), "selectbpmnfiles", null);
the "selectbpmnfiles" is the attachment field id in user task.
here is the complete code tried with different ways but none of them worked.
package com.activiti.extension.bean;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import org.activiti.app.domain.runtime.RelatedContent;
import org.activiti.app.repository.runtime.RelatedContentRepository;
import org.activiti.app.service.runtime.RelatedContentService;
import org.activiti.app.service.runtime.RelatedContentStreamProvider;
import org.activiti.content.storage.api.ContentObject;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.runtime.Execution;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;
//com.activiti.extension.bean.FileAttachmentTaskListener
@Component
public class FileAttachmentTaskListener implements TaskListener{
@Autowired
private RelatedContentService relatedContentService;
@Autowired
private RelatedContentRepository relatedContentRepository;
@Autowired
private UserDetailsService userService;
@Override
public void notify(DelegateTask delegateTask) {
// TODO Auto-generated method stub
System.out.println("FileAttachmentTaskListener start");
DelegateExecution execution = delegateTask.getExecution();
System.out.println("delegateTask.getProcessInstanceId() >>>>>>"+delegateTask.getProcessInstanceId());
System.out.println("execution.getProcessInstanceId() >>>>>>"+execution.getProcessInstanceId());
List<RelatedContent> relatedContent = new ArrayList<RelatedContent>();
Page<RelatedContent> page = null;
try {
//System.out.println("rcp - findAllByProcessInstanceIdAndField =>"+page.getContent().get(0).getField().toString());
if(relatedContentRepository.findAllByTaskIdAndField(delegateTask.getId().toString(), "selectbpmnfiles", null) != null)
System.out.println("rcp - findAllByTaskIdAndField =>"+relatedContentRepository.findAllByTaskIdAndField(delegateTask.getId().toString(), "selectbpmnfiles", null));
if(relatedContentRepository.findAllByTaskIdAndField(execution.getProcessInstanceId().toString(), "selectbpmnfiles", null) != null)
System.out.println("rcp - findAllByTaskIdAndField =>"+relatedContentRepository.findAllByTaskIdAndField(execution.getProcessInstanceId().toString(), "selectbpmnfiles", null));
if(relatedContentRepository.findAllContentByProcessInstanceId(delegateTask.getProcessInstanceId().toString(), null) != null)
System.out.println("rcp - findAllContentByProcessInstanceId =>"+relatedContentRepository.findAllContentByProcessInstanceId(delegateTask.getProcessInstanceId().toString(), null));
if(relatedContentRepository.findAllContentByProcessInstanceId(execution.getProcessInstanceId(), null) !=null)
System.out.println("rcp - findAllContentByProcessInstanceId =>"+relatedContentRepository.findAllContentByProcessInstanceId(execution.getProcessInstanceId(), null));
if(relatedContentRepository.findAllFieldBasedContentByTaskId(delegateTask.getId(), null) !=null)
System.out.println("rcp - findAllFieldBasedContentByTaskId =>"+relatedContentRepository.findAllFieldBasedContentByTaskId(delegateTask.getId(), null));
if(relatedContentRepository.findAllByProcessInstanceIdAndField(execution.getProcessInstanceId(), "selectbpmnfiles", null)!=null)
page = relatedContentRepository.findAllByProcessInstanceIdAndField(execution.getProcessInstanceId(), "selectbpmnfiles", null);
if(page !=null)
relatedContent.addAll(page.getContent());
} catch (Exception e) {
// TODO: handle exception
System.out.println("rcp - "+e);
}
try {
System.out.println("Try 2==>"+relatedContentService.getFieldContentForProcessInstance(delegateTask.getProcessInstanceId(), "selectbpmnfiles", 1, 0));
if(relatedContentService.getFieldContentForProcessInstance(delegateTask.getProcessInstanceId(), "selectbpmnfiles", 1, 0) !=null) {
List<RelatedContent> contentList = relatedContentService.getFieldContentForProcessInstance(
delegateTask.getProcessInstanceId(), "selectbpmnfiles", 1, 0).getContent();
System.out.println("contentList ==>"+contentList);
if (contentList != null) {
System.out.println("contentList ==>"+contentList.size());
for (RelatedContent relCon : contentList) {
System.out.println("Content file: " + relCon.getName() + ", created: " + relCon.getCreated());
ContentObject co = relatedContentService.getContentStorage().getContentObject(
relCon.getContentStoreId());
InputStream is =co.getContent();
String result = IOUtils.toString(is, StandardCharsets.UTF_8);
System.out.println("GDH:" + result);
// Get the InputStream and do stuff with the file
// co.getContent()
}
}
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("catch 1st exce==>"+e);
}
System.out.println("WHILE loop start");
while ((page == null) || (page.hasNext())) {
page = relatedContentRepository.findAllByProcessInstanceIdAndField(
delegateTask.getProcessInstanceId().toString(), "selectbpmnfiles", null);
System.out.println("Whle page ==>"+page);
if(page !=null)
relatedContent.addAll(page.getContent());
}
System.out.println("FileAttachmentTaskListener end");
}
}
Can you help me to fix this issue.
Regards,
Sekhar
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.