Error occurs while creating a site in java

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

Error occurs while creating a site in java

Hi, My problem occured during the creation of a site using java webscript . I can create a site with this code.

    protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {

    	String siteID =  "site_test";
    	SiteInfo siteinfo = null;
    	try {
    		siteinfo = createSite(siteID);
        	System.out.println(siteinfo);
    	}
		catch (SiteServiceException e2 ) {
			
			//e2.printStackTrace();
	    	System.out.println("SITE: " + siteID + " already exists!");
		}
    	
    	Map<String, Object> model = new HashMap<String, Object>();
        model.put("result", "true");
        
    	//System.out.println("end");
        
        return model;

    }

After the execution of the webscript, using above code, site is created but only in repo.

Problem is that when I sign in into alfresco share this error occures in command line:2.PNG

 

 

 

 

 

 

 

 

and this appers in share:1.PNG

 

 

 

 

 

 

 

 

 

 

and the site I created in repo did not show up in share.

I am using Alfresco 6.2. Can somebody help me fix this error and create a functional site in share as well as in repo ? 

Do I need to add some code to different files?

Or is there any other way to create a site in java that will appear in alfresco share?  

3 Replies
Highlighted
Moderator
Moderator

Re: Error occurs while creating a site in java

The error is expected as site also expect surf objects based on the site preset you are using. These are also called site data.

Creating site via java backed webscript would create the site node but would setup site data for the site you just created. 

Take a look at this thread and see if it helps:

https://hub.alfresco.com/t5/alfresco-content-services-forum/creating-site-using-webscript/m-p/300165...

~Abhinav
(ACSCE, AWS SAA-C02, GAIQ)
Highlighted
Active Member

Re: Error occurs while creating a site in java

Thanks @abhinavmishra14  for your answer. I read more about it and I decided to have repo webscript.

In link you sent me I found what to do  in case I chose surf webscript, but It is not clear to me what to do when I want to use repo webscript. Can you help me? 

Thanks. 

Highlighted
Moderator
Moderator

Re: Error occurs while creating a site in java

You would have to write logic to import the surf-config from within your java backed webscript. SiteService allows to create site but it doesn't setup surf-config which is required for every site.

Check the surf config used for default site preset here: https://github.com/Alfresco/alfresco-repository/tree/master/src/main/resources/alfresco/bootstrap/si...

Make sure you have appropriate surf-config setup for your site presets. Check the link given above. If you use the above given surf-config as is, it will setup surf config for default site preset always. so make sure you make changes accordingly and bootstrap the surf-config. 

Check this class and bean definition which is used to import surf-config for default site.

https://github.com/Alfresco/alfresco-remote-api/blob/master/src/main/java/org/alfresco/rest/api/impl...

https://github.com/Alfresco/alfresco-remote-api/blob/master/src/main/resources/alfresco/public-rest-...

 

If you are using default site preset (i.e. 'site-dashboard') provided by alfresco, you can use this OOTB rest api which creates the site and setup surf-config by default.  If you are using default site preset, then writing a custom webscript for creating site is not required. 

https://docs.alfresco.com/6.1/concepts/dev-api-by-language-alf-rest-manage-sites-create.html

Example:

POST: http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/sites?alf_ticket=TICKET_4ad80403182aac65b38d69efa88998814c6d80be

 Payload:

{
  "id": "test-site",
  "title": "Test site",
  "description": "Test site desc",
  "visibility": "PUBLIC"
}

 

 

 

 

~Abhinav
(ACSCE, AWS SAA-C02, GAIQ)