AnsweredAssumed Answered

How to get Alfresco services in workflow service task

Question asked by pnature on Feb 6, 2017
Latest reply on Feb 7, 2017 by pnature

Hi,

I am new on Alfresco community version 5.2 

I need use Alfresco services (NodeService, ContentService, ServiceRegistry) inside class used for workflow service task.

I created class but I cannot use Alfresco Services. All methods returns null. What I do wrong?

 

Thanks in advance.

My class and reference are here:

 

public class myClass implements JavaDelegate {

    private NodeService nodeService;

    private ServiceRegistry serviceRegistry;

    private ContentService contentService;
    private ApplicationContext applicationContext;

 

    @Override
      public void execute(DelegateExecution execution) throws Exception {

        System.out.println("getContentService() " + getContentService());
        System.out.println("getServiceRegistry() " + getServiceRegistry());

  }

 

    public ContentReader getContentReader(NodeRef docref) {
        ContentReader reader = contentService.getReader(docref, ContentModel.PROP_CONTENT);
        return reader;
    }

 

    public void setContentService(ContentService contentService)  {
        this.contentService = contentService;
    }
    
    public ContentService getContentService() {
        return this.contentService;
    }

 

    public void setNodeService(NodeService nodeService) {
        this.nodeService = nodeService;
    }
    
    public void setServiceRegistry(ServiceRegistry serviceRegistry) {
        //this.serviceRegistry=(ServiceRegistry)applicationContext.getBean("serviceRegistry");   //this line cause error on deploy
        this.serviceRegistry = serviceRegistry;
    }
    
    public ServiceRegistry getServiceRegistry() {
        return this.serviceRegistry;
    }

 

}

 

I created file my-class-context.xml on path /myProject/src/main/amp/config/alfresco/extension

I have tried tu put referencies to service-context.xml too.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="myClass" class="com.demo.myProject.task.myClass">
      <property name="contentService">
          <ref bean="ContentService" />
      </property>
      <property name="nodeService">
          <ref bean="NodeService" />
      </property>
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"></ref>
        </property>
</bean>
</beans>

Outcomes