How get nodeService in project All-in-One?

cancel
Showing results for 
Search instead for 
Did you mean: 
javajunior
Active Member

How get nodeService in project All-in-One?

hello.

I try to create additional module for Alfresco.

I created project All-in-One by instruction https://github.com/Alfresco/alfresco-sdk/blob/master/docs/getting-started.md

SDK 4.0, Alfresco 6.1

in class DemoComponent

import org.alfresco.repo.nodelocator.NodeLocatorService;

import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;

       private NodeService nodeService;
       private NodeLocatorService nodeLocatorService;

       public NodeRef getCompanyHome(){
              return nodeLocatorService.getNode("companyhome", null, null);
       }

in service-context.xml

<bean id="testpackage.DemoComponent" class="testpackage.platformsample.DemoComponent" parent="module.baseComponent" >
       <property name="moduleId" value="testartifact-platform" /> <!-- See module.properties -->
       <property name="name" value="DemoComponent" />
       <property name="description" value="A demonstration component" />
       <property name="sinceVersion" value="2.0" />
       <property name="appliesFromVersion" value="2.0" /> <!-- 1.0 would not work here when using SNAPSHOT version in project -->
       <property name="nodeService" ref="nodeService" />
       <property name="nodeLocatorService" ref="nodeLocatorService" />
</bean>

I run project (./run.sh build_start),  but line getCompanyHome() take me error

java.lang.NullPointerException
       at testpackage.platformsample.DemoComponent.getCompanyHome(DemoComponent.java:93)
       at testpackage.platformsample.DemoComponent.executeInternal(DemoComponent.java:61)
       at testpackage.platformsample.HelloWorldWebScript.executeImpl(HelloWorldWebScript.java:129)
       at                             testpackage.platformsample.HelloWorldWebScriptControllerTest.testController(HelloWorldWebScriptControllerTest.java:47)

How can I get nodeService, nodeLocatorService?

Maybe anybody link me to example project, please.

I would be very grateful for the information. Thanks to all.

Tetyana

 

 

12 Replies
angelborroy
Alfresco Employee

Re: How get nodeService in project All-in-One?

Do you have a setter service for NodeService and NodeServiceLocator beans in your Java class?

Hyland Developer Evangelist
javajunior
Active Member

Re: How get nodeService in project All-in-One?

only this

in DemoComponent:

public void setNodeService(NodeService nodeService) {
       this.nodeService = nodeService;
}

public void setNodeLocatorService(NodeLocatorService nodeLocatorService) {
       this.nodeLocatorService = nodeLocatorService;
}

ssciacca
Active Member II

Re: How get nodeService in project All-in-One?

Remember to write the setter method

public void setNodeService(NodeService nodeService)
{
  this.nodeService = nodeService;
}

... for each Spring injected field.

If the method is missing you will get null exception!

ssciacca
Active Member II

Re: How get nodeService in project All-in-One?

Ok I saw now that methods are there.
Maybe the problem is the property injection on xml.
The correct way is

<property name="nodeService" ref="NodeService" />

Note the initial uppercase on ref attribute.

javajunior
Active Member

Re: How get nodeService in project All-in-One?

it`s not solution

abhinavmishra14
Advanced

Re: How get nodeService in project All-in-One?

Is it possible for you to share the project you have created using SDK4.x? You can zip it and attach here.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
javajunior
Active Member

Re: How get nodeService in project All-in-One?

javajunior
Active Member

Re: How get nodeService in project All-in-One?

 
fedorow
Senior Member II

Re: How get nodeService in project All-in-One?

The project is on GitHub

https://github.com/LobanTM/All-in-One