cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the personService?

sail
Champ in-the-making
Champ in-the-making
How can I get the personService??

It seems that the personService was not accessible from the ServiceRegistry.

I want to get a Person's homeSpaceRef after authenticate. I think the following code should fulfil my purpose:

        AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
        authenticationService.authenticate("admin", "admin".toCharArray());

        NodeRef homeSpaceRef = (NodeRef) nodeService.getProperty(personService.getPerson("admin"), ContentModel.PROP_HOMEFOLDER);

but I don't know how to get the personService.
Thank you in adv.
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
If you are writing a Spring managed Bean then you can use dependancy injection to set the PersonService instance as a member variable of your bean e.g.

<bean id="myBeanID" class="org.mycompany.MyBeanClass">  
        <property name="personService">
            <ref bean="personService" />
        </property>
</bean>

and create the appropriate setter method in your bean class code:

   /**
    * @param personService             The personService to set.
    */
   public void setPersonService(PersonService personService)
   {
      this.personService = personService;
   }

The service will then be set for you when you bean is initialised.

Hope this helps,

Kevin

sail
Champ in-the-making
Champ in-the-making
Thank you!

But I am not familiar with Spring.

I am writing a servlet base on Alfresco web application.

I get the serviceRegistry like this

WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
then I get some services (nodeService, contentService, authenticationService ….) from serviceRegistry.

Is there any API like this to get the personService ??

Thank you in adv.

kevinr
Star Contributor
Star Contributor
I see - that's no problem. When we have similar code in our servlets, we use this pattern:

WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
PersonService personService = (PersonService)wc.getBean("personService");
Any named bean can be retrieved from the WebApplicationContext - that is the hook into the Spring managed bean factory.

Thanks,

Kevin

sail
Champ in-the-making
Champ in-the-making
thank you !

It seems that I should learn more about Spring. Smiley Happy