cancel
Showing results for 
Search instead for 
Did you mean: 

Create Site in alfresco using open cmis extension

smita
Champ in-the-making
Champ in-the-making
Hi

I want to create a alfresco site using open cmis extension. I researched and found an object type 'F:st:sites' and its properties like 'st:siteVisibility'  and 'st:sitePreset'. But I am not very sure that using this we can create a site in alfresco and I am not able to find any method for creating a site. It could be something like

      Map<String, Object> properties = new HashMap<String, Object>();
       properties.put(PropertyIds.NAME, "mySiteName");
       properties.put(PropertyIds.OBJECT_TYPE_ID, "F:st:sites");
       properties.put("cmisSmiley Tongueath", "/Sites");
       .
   .
       properties.put("cmis:createdBy", date);
       properties.put("st:siteVisibility", ScriptSiteService.PUBLIC_SITE);
   
   // TODO: add method for creating site with session object

Please reply.

   Also, if there is any other way to create a site other than apache's Http api, Please share.

Thanks,
Smita
9 REPLIES 9

kaynezhang
World-Class Innovator
World-Class Innovator
It seems CMIS cannot be used to create site,I think simply create a node of  object type 'F:st:sites' will not work.
I think  your only option is to use  web script api url(/api/sites/{shortname})


smita
Champ in-the-making
Champ in-the-making
Hi kaynezhang,

    Thank you for you reply. I have to use java, so should I use 'org.apache.http' api. Could you please provide me some example code snippet for your suggestion 'web script api'.

Thanks in advance.

Regards,
Smita

kaynezhang
World-Class Innovator
World-Class Innovator
Create Web site
POST /alfresco/service/api/sites

Creates a new Web site based on the site preset and details provided. The following properties may be set.
shortName:the shortName of the web site, mandatory, must be unique
sitePreset:the sitePreset
title:the title of the web site
description:the description for the web site
visibility:he site visibility, one of (PUBLIC,MODERATED,PRIVATE), defaults to PUBLIC
type:the type of site to create, optional

Great answer; where is this documented?

kaynezhang
World-Class Innovator
World-Class Innovator
Plese  visit this address –http://localhost:8080/alfresco/service/index/all,and search with key word "POST /alfresco/service/api/site" in the page,you will get something like below that introduce this webscript api

Create Web site
POST /alfresco/service/api/sites

Creates a new Web site based on the site preset and details provided.
Note: this method only creates a site at the repository level, it does not create a fully functional site. It should be considered for internal use only at the moment. Currently, creating a site programmatically needs to be done in the Share context, using the create-site module. Further information can be found at the address http://your_domain:8080/share/page/index/uri/modules/create-site.post within your Alfresco installation.
The following properties may be set.
shortName
the shortName of the web site, mandatory, must be unique
sitePreset
the sitePreset
title
the title of the web site
description
the description for the web site
visibility
the site visibility, one of (PUBLIC,MODERATED,PRIVATE), defaults to PUBLIC
type
the type of site to create, optional

kaynezhang
World-Class Innovator
World-Class Innovator
package com.kayne.cmis.webscript;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.json.JSONObject;

public class CreateSiteTest {
   
   public static void main(String[] args){
      HttpClient client = new HttpClient();
      client.getState().setCredentials(
            new AuthScope("localhost", 8080, "Alfresco"),
            new UsernamePasswordCredentials("admin", "admin"));



      
       
      String apiurl ="http://localhost:8080/alfresco/service/api/sites";
      PostMethod post = new PostMethod(apiurl);
      try {
         JSONObject site = new JSONObject();
         site.put("shortName", "kaynezhang");
         site.put("visibility", "PUBLIC");
          site.put("sitePreset", "site-dashboard");

         
         System.out.println(site.toString());
         post.setDoAuthentication(true);
         post.setRequestHeader("Content-Type", "application/json");
         post.setRequestEntity(new StringRequestEntity(site.toString(), "application/json",  "UTF-8"));
             
             
         int status = client.executeMethod(post);
             if (status != HttpStatus.SC_OK) {
                System.err.println("Method failed: " + post.getStatusLine());
                 }
         String resultString = post.getResponseBodyAsString();
         System.out.println(resultString);
      } catch (Exception e) {
         e.printStackTrace();
      } finally {
         post.releaseConnection();
      }
   }
}

jocylincouch
Champ in-the-making
Champ in-the-making
I'm trying to POST to the sites api to create a site (obviously :-))
I'm posting the following: payload={'description':'This categorises the meat', 'visibility':'PUBLIC', 'site-preset':'site-dashboard','title':'Meat Patch', "site.shortName":'meat-patch'}

as: requests.post('http://<my url>:8080/alfresco/service/api/sites', auth=('admin','XXXXX'), data=json.dumps(payload))

in python. I get back a 500 error detailed below. What else do I need to add to the request to get this to work? I can't find the docs which define the headers further than http://docs.alfresco.com/3.4/references/RESTful-SiteSitesPost.html and I've been using this example:https://forums.alfresco.com/forum/developer-discussions/alfresco-api/create-site-alfresco-using-open... however defining much more than is there.

The below clearly states that site.shortName is not defined, therefore how should I define shortName in the json I pass to the sites api so that the alfresco sites api pick it up? References to docs are also very very welcome.

Error log below:
{u'callstack': [u'',
  u'freemarker.core.InvalidReferenceException: Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.',
  u'freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)',
  u'freemarker.core.Expression.getStringValue(Expression.java:118)',
  u'freemarker.core.AddConcatExpression._getAsTemplateModel(AddConcatExpression.java:98)',
  u'freemarker.core.Expression.getAsTemplateModel(Expression.java:89)',
  u'freemarker.core.ListLiteral.getModelList(ListLiteral.java:119)',
  u'freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:91)',
  u'freemarker.core.Expression.getAsTemplateModel(Expression.java:89)',
  u'freemarker.core.Expression.getStringValue(Expression.java:93)',
  u'freemarker.core.DollarVariable.accept(DollarVariable.java:76)',
  u'freemarker.core.Environment.visit(Environment.java:221)',
  u'freemarker.core.MixedContent.accept(MixedContent.java:92)',
  u'freemarker.core.Environment.visit(Environment.java:221)',
  u'freemarker.core.EscapeBlock.accept(EscapeBlock.java:84)',
  u'freemarker.core.Environment.visit(Environment.java:221)',
  u'freemarker.core.MixedContent.accept(MixedContent.java:92)',
  u'freemarker.core.Environment.visit(Environment.java:221)',
  u'freemarker.core.Macro$Context.runMacro(Macro.java:172)',
  u'freemarker.core.Environment.visit(Environment.java:614)',
  u'freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)',
  u'freemarker.core.Environment.visit(Environment.java:221)',
  u'freemarker.core.Macro$Context.runMacro(Macro.java:172)',
  u'freemarker.core.Environment.visit(Environment.java:614)',
  u'freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)',
  u'freemarker.core.Environment.visit(Environment.java:221)',
  u'freemarker.core.MixedContent.accept(MixedContent.java:92)',
  u'freemarker.core.Environment.visit(Environment.java:221)',
  u'freemarker.core.Environment.process(Environment.java:199)',
  u'org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:218)',
  u'org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:896)',
  u'org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:267)',
  u'org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147)',
  u'org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:429)',
  u'org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:452)',
  u'org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:491)',
  u'org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:529)',
  u'org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:341)',
  u'org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)',
  u'org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)',
  u'org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)',
  u'javax.servlet.http.HttpServlet.service(HttpServlet.java:727)',
u'org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)',
  u'org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)',
  u'org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)',
  u'org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)',
  u'org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)',
  u'org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)',
  u'org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)',
  u'org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)',
  u'org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)',
  u'org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)',
  u'org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)',
  u'org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)',
  u'org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)',
  u'org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)',
  u'org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)',
  u'org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)',
  u'org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)',
  u'org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)',
  u'org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)',
  u'java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)',
  u'java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)',
  u'java.lang.Thread.run(Thread.java:724)',
  u"org.alfresco.service.cmr.repository.TemplateException: 06020108 Error during processing of the template 'Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.'. Please contact your system administrator.",
  u'org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:222)',
  u"org.springframework.extensions.webscripts.WebScriptException: 06020018 Wrapped Exception (with status template): 06020108 Error during processing of the template 'Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.'. Please contact your system administrator.",
  u'org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1067)'],
u'exception': u"org.springframework.extensions.webscripts.WebScriptException - 06020018 Wrapped Exception (with status template): 06020108 Error during processing of the template 'Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.'. Please contact your system administrator.",
u'message': u"06020018 Wrapped Exception (with status template): 06020108 Error during processing of the template 'Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.'. Please contact your system administrator.",
u'server': u'Community v4.2.0 (r63893-b12) schema 6,033',
u'status': {u'code': 500,
  u'description': u'An error inside the HTTP server which prevented it from fulfilling the request.',
  u'name': u'Internal Error'},
u'time': u'02-Jul-2014 15:15:01'}

mrogers
Star Contributor
Star Contributor
it's not site.shortName

ishaan
Champ in-the-making
Champ in-the-making
Hi All,

Can any one help me out to find out what the site Preset is?!! is it the default freemarker template, or something else?, can any one help me out to find out how can I customise the directory structure after creation of site(space) and where to find the templates for these!!!!!(Java).