Bootstrap the creation of a site does not work

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

Bootstrap the creation of a site does not work

Jump to solution

Hi,

I would like to bootstrap the creation of a site through Java code:

SiteInfo siteInfo = siteService.createSite("site-dashboard", "my-site", "Site", "This site", SiteVisibility.PRIVATE);

However, when the bootstrap is executed I get the following error for the creation of the site:

2017-05-23 13:28:48,861 ERROR [admin.patch.PatchExecuter] [main] 04230011 org.alfresco.repo.security.authority.UnknownAuthorityException: 04230010 An authority was not found for System
at org.alfresco.repo.security.authority.AuthorityDAOImpl.addAuthority(AuthorityDAOImpl.java:346)
at org.alfresco.repo.security.authority.AuthorityServiceImpl.addAuthority(AuthorityServiceImpl.java:456)
at org.alfresco.repo.security.authority.AuthorityServiceImpl.addAuthority(AuthorityServiceImpl.java:448)
at org.alfresco.repo.site.SiteServiceImpl$3.doWork(SiteServiceImpl.java:705)
at org.alfresco.repo.site.SiteServiceImpl$3.doWork(SiteServiceImpl.java:1)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:548)
at org.alfresco.repo.site.SiteServiceImpl.setupSitePermissions(SiteServiceImpl.java:609)
at org.alfresco.repo.site.SiteServiceImpl.setupSitePermissions(SiteServiceImpl.java:599)
at org.alfresco.repo.site.SiteServiceImpl.createSite(SiteServiceImpl.java:567)
at org.alfresco.repo.site.SiteServiceImpl.createSite(SiteServiceImpl.java:478)

From what I understand from the source code, the code adds the current user "System" as a Site Manager.  The code runs that portion of code as "System".

My version of Alfresco is Community Edition 201602.

Any idea how I could make this working?

Thanks in advance,

Philippe

1 Solution

Accepted Solutions
douglascrp
Advanced II

Re: Bootstrap the creation of a site does not work

Jump to solution

I guess the problem is happening because you are not setting an authentication context in your code.

You can see how the addon I shared before does that by looking at the source code here SiteBootstrapAlfresco/SiteLoadBootstrap.java at master · rouxemmanuel/SiteBootstrapAlfresco · GitHub 

Notice the run as admin part.

View solution in original post

4 Replies
douglascrp
Advanced II

Re: Bootstrap the creation of a site does not work

Jump to solution

Hello.

Can you share a bit more of your code in order to help us understand the problem you are facing?

How are you configuring your bootstrap? The XML would also be useful here.

You can a sample project using the site bootstrap here GitHub - rouxemmanuel/SiteBootstrapAlfresco: Enable site bootstrap in Alfresco not only on Alfresco ... 

pkhazzaka
Active Member

Re: Bootstrap the creation of a site does not work

Jump to solution

Hi Douglas,

I know this approach, but I prefer to use Java to avoid to have to export the site when I change it, and to have more control on the creation of the site.

These are my bootstrap-context.xml and the associated Java class.

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
>

    <!-- The bootstrap-context.xml file is used for patch definitions, importers
,          workflow, and loading custom content models.  -->
 
<bean id="site.creation.patch" class="test.demoamp.SiteCreationPatch" parent="basePatch">
      <property name="id"><value>site.creation.patch</value></property>
      <property name="description"><value>site.creation.patch.description</value></property>
      <property name="fixesFromSchema"><value>0</value></property>
      <property name="fixesToSchema"><value>${version.schema}</value></property>
      <property name="targetSchema"><value>10000</value></property>
      <property name="siteService" ref="siteService" />
    </bean></beans>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

package test.demoamp;

import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;

public class SiteCreationPatch extends AbstractPatch {
     private SiteService siteService;

     public void setSiteService(SiteService siteService) {
          this.siteService = siteService;
     }

     public void createSite() {
          SiteInfo siteInfo = siteService.createSite("site-dashboard", "my-site", "My test site", "This is a test site",
                    SiteVisibility.PRIVATE);
     }

     protected String applyInternal() throws Exception {
          createSite();

          return "SiteCreationPatch success";
     }

}

Thanks in advance for you help

douglascrp
Advanced II

Re: Bootstrap the creation of a site does not work

Jump to solution

I guess the problem is happening because you are not setting an authentication context in your code.

You can see how the addon I shared before does that by looking at the source code here SiteBootstrapAlfresco/SiteLoadBootstrap.java at master · rouxemmanuel/SiteBootstrapAlfresco · GitHub 

Notice the run as admin part.

View solution in original post

pkhazzaka
Active Member

Re: Bootstrap the creation of a site does not work

Jump to solution

Great! It is working. Thanks a lot.