06-30-2020 07:36 AM
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);
}
}
07-03-2020 08:43 AM
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,
07-03-2020 08:55 AM
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
07-03-2020 09:11 AM
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,
07-05-2020 02:50 AM
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
07-06-2020 05:01 AM
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
07-06-2020 05:49 AM
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.
07-06-2020 06:00 AM
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
07-06-2020 08:06 AM
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.
Thanks,
Piyush
07-06-2020 08:29 AM
You can use alternate way to create site. api-explorer
07-06-2020 08:49 AM
hii @sanjaybandhniya ,
I have requirement to create it through dynamic Abstract webscript.
Thanks,
Piyush
Explore our Alfresco products with the links below. Use labels to filter content by product module.