cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Site using Webscript

piyush48
Star Contributor
Star Contributor

Hii All,

I want to create Site through webscript and i have created one but it doesnt work correctly.Hereby i am attaching code  please do help out.

package com.abc.repo.web;


import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.NamespaceServiceMemoryImpl;
import org.alfresco.service.namespace.QName;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteMemberInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.springframework.extensions.surf.util.ParameterCheck;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;

public class siteCreation extends AbstractWebScript {

    private static Logger LOGGER = Logger.getLogger(siteCreation.class);
    
    private SiteInfo siteInfo;
    private SiteService siteService;
    private ServiceRegistry serviceRegistry;
    
    public void setServiceRegistry(ServiceRegistry serviceRegistry)
    {
    	this.serviceRegistry = serviceRegistry;
    }
        
    public void setSiteService(SiteService siteService)
    {
        this.siteService = siteService;
    }
    
    @Override
    public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {

    	JSONObject reqData = (JSONObject) req.parseContent();
    	String shortName, visibility, sitePreset, title, description = null;
     
    try {
        shortName= (String) reqData.get("shortName");
        sitePreset= (String) reqData.get("sitePreset");
        title= (String) reqData.get("title");
        description= (String) reqData.get("description");
        visibility= (String) reqData.get("visibility");
        
    }
    catch (JSONException err) {
        err.printStackTrace();
    } 
    
  }
    public SiteInfo createSite(String sitePreset, String shortName, String title, String description, String visibility)
    { 
        ParameterCheck.mandatoryString("visibility", visibility);
        SiteVisibility siteVisibility = SiteVisibility.valueOf(visibility);
        SiteInfo siteInfo = this.siteService.createSite(sitePreset, shortName, title, description, siteVisibility);
        return new SiteInfo(siteInfo, this.serviceRegistry, this.siteService);
    }
}
21 REPLIES 21

EddieMay
World-Class Innovator
World-Class Innovator

Hi @piyush48,

I don't think you can have whitespace in your site preset value

Aviva Dashboard

 It needs to be along these lines:

<preset id="site-dashboard">

Also, I think a preset has to be setup in Share site presets before you can start using it.

To test, can you swap "Aviva Dashboard" for "site-dashboard" and try your webscript again?

Thanks,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!

Hi @EddieMay ,

Thanks for constantly helping me solving my issue.

I have tried and tested by changing Aviva Dashboard to site-dashboard but it still dont allow me to access customize site and also no dashboard is seen.

{
"sitePreset":"site-dashboard",
"shortName":"Aviva-Test1",
"title":"AvivaTestNew1",
"description":"Demo Aviva Site",
"visibility":"PRIVATE"
}

Please find the JSON value which i change as suggested.

Thanks,

Piyush

EddieMay
World-Class Innovator
World-Class Innovator

Hi @piyush48,

It didn't work - that's a shame! 

OK, can you check what the presents are called in tomcat/webapps/share/WEB-INF/classes/alfresco/site-data/presets/presets.xml - it could be that the default has been changed.

Thanks,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!

Hii @EddieMay ,

I am using SDK 4.1 on my device, so please could tell me equivalent path for it because I didn't find tomcat anywhere.

Thanks,

Piyush

Hi @EddieMay ,

I got the path in my SDK in share in sitedata but there is no file called presets.xml. So would i have to create one and check??

Thanks,

Piyush

EddieMay
World-Class Innovator
World-Class Innovator

Hi @piyush48,

The file should be there at tomcat/webapps/share/WEB-INF/classes/alfresco/site-data/presets/presets.xml. I've just expanded the share.war file that comes with the community 6.2 distribution zip & that's where I found presets.xml.

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!

Hi @EddieMay ,

I am Using SDK 4.1(Enterprise edition) but didnt found any presets.xml on path C:\Users\ABCD\alfresco.contentservices\project\project-acs-share\src\main\resources\alfresco\web-extension\site-data\extensions which is path for presets.xml right??

Thanks,

Piyush

Hi @EddieMay , @sanjaybandhniya , @abhinavmishra14 ,

I think i have similar Problem as given in below link as i cannot access customize site page and my noderef is not getting this page i think. I have same issue as him if anyone of you could help me out.

https://hub.alfresco.com/t5/alfresco-content-services-forum/i-am-can-not-goto-dashboard-of-site/td-p... 

Thanks,

Piyush

You can use alternate way  to create site.  api-explorer 

hii @sanjaybandhniya ,

I have requirement to create it through dynamic Abstract webscript.

Thanks,

Piyush