cancel
Showing results for 
Search instead for 
Did you mean: 

Creating space during bootstarp within init spring bean

younis15
Champ in-the-making
Champ in-the-making
I am trying to create space during bootstrap within an init of a spring bean. however, an exception is thrown.

The code:

return AuthenticationUtil.runAs(new RunAsWork<NodeRef>(){
public NodeRef doWork() throws Exception {
UserTransaction tx = null;

NodeRef childNodeRef = null;
try {
tx = transactionService.getUserTransaction();
tx.begin();

Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_NAME, spaceName);

childNodeRef = nodeService.createNode(
container,
ContentModel.ASSOC_CONTAINS,
QName.createQName(Constants.DIGITAL_SERIES_SECURITY_MODEL_NAMEPSACE_PREFIX_STRING,spaceName),
ContentModel.TYPE_FOLDER,props).getChildRef();

                                      tx.commit();

} catch (Throwable e) {

e.printStackTrace();
try {
tx.rollback();

} catch (SystemException e1) {

}
log.error(e.getMessage());

}

log.debug("Space "+ spaceName+ " created "+ childNodeRef);

return childNodeRef;
}

}, AuthenticationUtil.getAdminUserName());



The Exception:

java.lang.NullPointerException
at org.alfresco.repo.search.IndexerComponent.createNode(IndexerComponent.java:67)
at org.alfresco.repo.node.index.NodeIndexer.indexCreateNode(NodeIndexer.java:91)
at org.alfresco.repo.node.db.DbNodeServiceImpl.createNode(DbNodeServiceImpl.java:349)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.alfresco.repo.tenant.MultiTNodeServiceInterceptor.invoke(MultiTNodeServiceInterceptor.java:104)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy7.createNode(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxyFactory.java:215)
at $Proxy8.createNode(Unknown Source)
at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:276)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy7.createNode(Unknown Source)
at com.tts.mersal.business.ApplicationAttachmentManager$1.doWork(ApplicationAttachmentManager.java:130)
at com.tts.mersal.business.ApplicationAttachmentManager$1.doWork(ApplicationAttachmentManager.java:1)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
at com.tts.mersal.business.ApplicationAttachmentManager.createSpace(ApplicationAttachmentManager.java:112)
at com.tts.mersal.business.ApplicationAttachmentManager.createAttSpaceHierarchy(ApplicationAttachmentManager.java:386)
at com.tts.mersal.business.ApplicationAttachmentManager.storeAttachment(ApplicationAttachmentManager.java:309)
at com.tts.mersal.business.ApplicationAttachmentManager.init(ApplicationAttachmentManager.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1468)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:192)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:63)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

We are already use an .amp file and by default this file contains the module-context.xml.
Also, the services in that spring bean are injected successfully, so we must be able to use the createNode.

FYI, the same issue is posted into alfresco issues, and they replied that this is not a bug.

please follow link,

https://issues.alfresco.com/jira/browse/ALF-10600?focusedCommentId=126842#comment-126842

Your replies are highly appreciated.

Younis Alomoush.
Team Manager
Digital Series Co.

Thanks.
6 REPLIES 6

smicyk
Champ in-the-making
Champ in-the-making
Hi,

If you want to just create a space its better to use boostrap mechanism which alfresco uses during creation of its own spaces. For example I add boostrap-contenxt.xml with boostrap bean definition:


         <bean id="my.bootstrapSpaces" class="org.alfresco.repo.module.ImporterModuleComponent"
      parent="module.baseComponent">
      <property name="moduleId" value="my.moduleId" />
      <property name="name" value="My Spaces Bootstrap" />
      <property name="description" value="Initial data requirements" />
      <property name="sinceVersion" value="0.0.0" />
      <property name="appliesFromVersion" value="0.0.0" />
      <property name="importer" ref="spacesBootstrap" />
      <property name="bootstrapViews">
         <list>
            <props>
               <prop key="encoding">UTF-8</prop>
               <prop key="path">/${spaces.company_home.childname}</prop>
               <prop key="location">alfresco/module/my.moduleId/bootstrap/spaces-structure.xml</prop>
            </props>
         </list>
      </property>
   </bean>

Where spaces-structure.xml is the similar file to the export/import alfresco file:


<?xml version="1.0" encoding="UTF-8"?>
<view:view xmlns:view="http://www.alfresco.org/view/repository/1.0" xmlns:cm="http://www.alfresco.org/model/content/1.0" xmlns:app="http://www.alfresco.org/model/application/1.0" xmlns:sys="http://www.alfresco.org/model/system/1.0" >
   <cm:folder view:childName="cm:myFolder">
      <view:acl view:inherit="true" />
      <view:properties>
         <cm:name>myFolder</cm:name>
         <cm:title>myFolder Title</cm:title>
         <cm:description>myFolder description</cm:description>
      </view:properties>
       </cm:folder>
</view:view>


I hope it can help you.

mohammed_amr
Champ in-the-making
Champ in-the-making
Thanks for your reply,

I work with my colleague upon this problem, and i need to notice some of issues:

- Our folders will be created under dictionary folder.
- Our folder will contains created nodes in the bootstrap phase.

So, still we are waiting your replies about how to handle this issue in the .amp file.

Mohammed Amr
Senior System Developer
Digital Series Co.

smicyk
Champ in-the-making
Champ in-the-making
Hi,

if you want to put your folders to some specific location it is enough to change (in your case):


<prop key="path">/${spaces.company_home.childname}</prop>
to

<prop key="path">/${spaces.company_home.childname}/app:dictionary</prop>

Concerning second problem, if I understand correct you want to insert some hierarchy of folders in to repository? Right? If so you should change spaces-structure.xml to something like this:


<?xml version="1.0" encoding="UTF-8"?>
<view:view xmlns:view="http://www.alfresco.org/view/repository/1.0" xmlns:cm="http://www.alfresco.org/model/content/1.0" xmlns:app="http://www.alfresco.org/model/application/1.0" xmlns:sys="http://www.alfresco.org/model/system/1.0" >
   <cm:folder view:childName="cm:myFolder">
      <view:acl view:inherit="true" />
      <view:properties>
         <cm:name>myFolder</cm:name>
         <cm:title>myFolder Title</cm:title>
         <cm:description>myFolder description</cm:description>
      </view:properties>
      <view:association>
              <cm:contains>
            <cm:folder view:childName="cm:mySubFolder">
               <view:acl view:inherit="true" />
               <view:properties>
                  <cm:name>mySubFolder</cm:name>
                  <cm:title>mySubFolder title</cm:title>
                  <cm:description>mySubFolder description</cm:description>
               </view:properties>
                  </cm:folder>
                </cm:contains>
      </view:association>
       </cm:folder>
</view:view>

Of course you can add as many folders in cm:contains as you like and add new levels in subfolders.

I hope it helps.

mohammed_amr
Champ in-the-making
Champ in-the-making
Thanks,

About second point, i'm trying to create a sequence nodes of custom type built in-house.

You can imagine the structure as follow

/dictionary/Sequences/ORG_SEQ where ORG_SEQ is a node of a custom type inherit sys:base.
/dictionary/Organizations/organizations where organizations is a set of nodes created under Organizations folder which are of custom type inherit sys:base.

Thanks.

smicyk
Champ in-the-making
Champ in-the-making
Hi,

well actually you can change cm:folder tag to name of your custom name type. It is not restricted to folders or any other type as far as it is type from defined model.

smicyk

mohammed_amr
Champ in-the-making
Champ in-the-making
I use your way, but an exception has been thrown


13:32:59,074 User:System INFO  [repo.module.ModuleServiceImpl] Installing module 'com.tts.mersal.module.extensions.Core' version 1.1.
13:32:59,128  ERROR [web.context.ContextLoader] Context initialization failed
org.alfresco.error.AlfrescoRuntimeException: 09100004 Failed to start modules
   at org.alfresco.repo.module.ModuleComponentHelper$1.doWork(ModuleComponentHelper.java:302)
   at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
   at org.alfresco.repo.module.ModuleComponentHelper.startModules(ModuleComponentHelper.java:196)
   at org.alfresco.repo.module.ModuleServiceImpl.startModules(ModuleServiceImpl.java:137)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy101.startModules(Unknown Source)
   at org.alfresco.repo.module.ModuleStarter$1.execute(ModuleStarter.java:66)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:381)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:272)
   at org.alfresco.repo.module.ModuleStarter$2.doWork(ModuleStarter.java:76)
   at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
   at org.alfresco.repo.module.ModuleStarter.onBootstrap(ModuleStarter.java:71)
   at org.springframework.extensions.surf.util.AbstractLifecycleBean.onApplicationEvent(AbstractLifecycleBean.java:56)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
   at org.alfresco.repo.management.SafeApplicationEventMulticaster.multicastEvent(SafeApplicationEventMulticaster.java:78)
   at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:294)
   at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:858)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:419)
   at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
   at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:192)
   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
   at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:63)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
   at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
   at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
   at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
   at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
   at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
   at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
   at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
   at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
   at org.apache.catalina.core.StandardService.start(StandardService.java:519)
   at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
   at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.alfresco.error.AlfrescoRuntimeException: 09100003 The module component has already been executed: com.tts.mersal.module.extensions.Core.mersalBootstrap
   at org.alfresco.error.AlfrescoRuntimeException.create(AlfrescoRuntimeException.java:46)
   at org.alfresco.repo.module.AbstractModuleComponent.execute(AbstractModuleComponent.java:346)
   at org.alfresco.repo.module.ModuleComponentHelper.executeComponent(ModuleComponentHelper.java:645)
   at org.alfresco.repo.module.ModuleComponentHelper.startModule(ModuleComponentHelper.java:564)
   at org.alfresco.repo.module.ModuleComponentHelper.access$400(ModuleComponentHelper.java:57)
   at org.alfresco.repo.module.ModuleComponentHelper$1$1.execute(ModuleComponentHelper.java:239)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:381)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:272)
   at org.alfresco.repo.module.ModuleComponentHelper$1.doWork(ModuleComponentHelper.java:260)
   … 54 more
log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository.
Exception in thread "JobAcquisitionThread" java.lang.NullPointerException

Thanks