How do you access an uploaded file in a downstream service task?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2016 11:30 PM
Thanks!
Jon
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2016 12:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2016 03:32 PM
@Autowired
protected RelatedContentService contentService;
I am sure it is something simple that I am missing, just need a little direction to understand how things actually come together. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2016 09:59 PM
<java>
public void execute(DelegateExecution execution) {
try {
String fileVariableName = "myfile"; // Id of 'upload file field' from form in previous User Task
Class<?> theClass = Class.forName("com.activiti.conf.ApplicationConfiguration");
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(theClass);
RelatedContentService relatedContentService = applicationContext.getBean(RelatedContentService.class);
List<RelatedContent> contentList = relatedContentService.getFieldContentForProcessInstance(
execution.getProcessInstanceId(), fileVariableName, 1, 0).getContent();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
</java>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2016 06:01 AM
Are you sure it's in the right package, so it can be found by component scanning?
getting the application context is quite a heavy operation and shouldn't be needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2016 02:10 PM
I finally cycled back around to this, and as I was putting together an example your comment was very helpful in clueing me to look into component scanning. That led me to the secret sauce… needing package com.activiti.extension.bean. Once I did that, the @Autowiring worked. I'm pasting in a working delegate for the next wandering soul…
<java>
package com.activiti.extension.bean;
import com.activiti.service.runtime.RelatedContentService;
import org.activiti.engine.delegate.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SomeActivitiDelegate implements JavaDelegate {
@Autowired
RelatedContentService relatedContentService;
@Bean
public SomeActivitiDelegate someActivitiDelegate() {
return new SomeActivitiDelegate();
}
public void execute(DelegateExecution execution) {
if (relatedContentService == null) {
System.out.println("Source of great pain.");
} else {
System.out.println("Oh, sweet victory!");
}
}
}
</java>
Also, it is important to note that in order to use this, you must use the Delegate Expression property in your Service Task definition. In this example, setting the field to <code>${someActivitiDelegate}</code> did the trick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 07:21 AM
Hi,
thank you for your answer. I am new to alfresco.
I need some more help regarding this.
Let me be clear.
Suppose this upload file form. Its id is uploadurl
below is the method for execution listener.
@Override
public void notify(DelegateExecution arg0) throws Exception {
File f = new File("D:/some_file.zip");
// I want to get that zip file in f
}
Hope you got my question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2016 02:33 PM
Update: While I am not exactly sure the subtleties at play, I was able to work through my issue. Apparently the transaction was not yet committed before a custom task I defined using AbstractBpmnActivityBehavior was invoked as the next task in the process. The AbstractBpmnActivityBehavior task was needing the related content, but was not finding it. I simply refactored the latter task to also be a class implementing JavaDelegate using the same approach with an @Autowired RelatedContentService as the SomeActvitiDelegate mentioned previously, and all was well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 08:28 AM
Your analysis is correct: Activiti won't flush to the database until the transaction is committed. If you really want that, you can make your next task asynchronous.
Side remark: change @Configuration to @Component to be more correct (on your JavaDelegate).
