NickAth
NickAth

Reputation: 1112

How to obtain a file stored in alfresco repository from JavaDelegate - serviceTask?

Greetings to the community! I am using alfresco community edition 6.0.0 and currently I am trying to implement a workflow where i have a serviceTask calling a custom class implementing the JavaDelegate class.

serviceTask in bpmn code:

<serviceTask id="delegate"
                 activiti:class="org.nick.java.GenerateDocument"
                 name="Get the document">
</serviceTask>

Java Delegate class

public class GenerateDocument implements JavaDelegate {
    @Autowired
    RelatedContentService relatedContentService;

    public void execute(DelegateExecution execution) throws Exception {
        ProcessEngine p = ProcessEngines.getDefaultProcessEngine();

    }
}

what I would like to do is the service task calls the GenerateDocument class, I could somehow retrieve a document that is stored inside my alfresco repository (I know it's name and it's id in case there is a method needed).

Ideally, if I retrieve this file, I would like to perform changes on it and save it as a new file in the alfresco repository? Is the above scenario feasible? According to my so-far search on the web i will may need this RelatedContentService relatedContentService to do this, is this correct?

Thanks in advance for any help :)

Upvotes: 0

Views: 429

Answers (1)

Jeff Potts
Jeff Potts

Reputation: 10538

Something that is cool about JavaDelegates running in Activiti embedded within Alfresco is that you have access to the ServiceRegistry. From there you can get any bean you might need.

For example, suppose your JavaDelegate needed to run an Alfresco action. You can use the ServiceRegistry to get the ActionService, and away you go:

    ActionService actionService = getServiceRegistry().getActionService();
    Action mailAction = actionService.createAction(MailActionExecuter.NAME);
    mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, SUBJECT);
    mailAction.setParameterValue(MailActionExecuter.PARAM_TO, notificationEmailAddress);

In your case, if you want to find a node, you probably want to use the SearchService to run a query or to find a node using its node reference.

Take a look at the Alfresco foundational Java API to see the collection of services that are available for finding, updating, and creating nodes.

Upvotes: 4

Related Questions