cancel
Showing results for 
Search instead for 
Did you mean: 

How to inject SiteService in my custom class?

mbel
Star Contributor
Star Contributor

Hello,

I would like to use some of the methods in Alfresco's SiteService and respectively its implementation.

For example - I want to list all currently created Sites in Alfresco system in a Java code.

What exactly should I inject in my code and what bean should I include.....Its not exactly clear for me.

Thank you in advance.

1 ACCEPTED ANSWER

You also need to add the setter, ie.

public void setSiteService(SiteService siteService)  

   this.siteService = siteService

}

Regards,

Jan

View answer in original post

22 REPLIES 22

mbel
Star Contributor
Star Contributor

well....as an other option. The SiteService is now working and I use the method findSites() to list all sites, however the returned object is different than this one in the /api/sites, so if I want to get the json object from /api/sites, I don't know other option....

If you know, I will be glad if you share it.

mbel
Star Contributor
Star Contributor
Douglas C. R. Paes​, yes but I dont want to hard code it as a property and change it when the host changes.

I think SysAdminParams service is what I was looking for.

kaynezhang
World-Class Innovator
World-Class Innovator

Yes,you need to add setter method in your xxx.demoamp.CustomWebScript class as @Jan Vonka said

janv
Employee
Employee

Alternatively, you can also inject the ServiceRegistry into your custom bean XML extension file:

<property name="serviceRegistry" ref="ServiceRegistry"/>

and then get the SiteService locally (or other public services, as needed):

private ServiceRegistry serviceRegistry;

public void setServiceRegistry(ServiceRegistry serviceRegistry)

{

   this.serviceRegistry = serviceRegistry;
}

public void myMethod()

{

     SiteService siteService = serviceRegistry.getSiteService();

     // ... more here

}

Regards,

Jan

angelborroy
Community Manager Community Manager
Community Manager

Jan Vonka​ is this a safe method as ServiceRegistry is providing lower case service beans?

Hyland Developer Evangelist

Angel Borroy Are you sure ? In general, ServiceRegistry returns upper-case public service beans.

angelborroy
Community Manager Community Manager
Community Manager

Jan Vonka​ You are right: community-edition/ServiceRegistry.java at master · Alfresco/community-edition · GitHub

My mistake, thanks for the clarification!

Hyland Developer Evangelist

kaynezhang
World-Class Innovator
World-Class Innovator

ServiceRegistry do return upper-case public service beans,but  but getting some service bean via the ServiceRegistry is not recommended any more.

I have the following code:

  String query = "SELECT * FROM cmis:document";

  OperationContext oc = session.createOperationContext();

   oc.setMaxItemsPerPage(1000000);

   resultado = session.query(query.toString(), false, oc);

But I have more than 5 thousand documents and the cmis returns me only a thousand. How do I increase the number of pages that it searches? I believe he is bringing a page with only his maximum (thousand documents).