如何在引导阶段在存储库中创建节点
让我需要在引导阶段在露天存储库中创建一个节点以便稍后使用它们,我该怎么做?
我使用 .amp 文件将扩展自定义安装到 alfresco.war 中,所以我有 module-context.xml 并在其中编写一条导入语句,引用 bootstrap-context.xml,其中有一个像这样的 bean
<bean id="com.ds.module.extensions.Core.securityRequirementBootstrap"
class="com.ds.ui.bean.dialog.module.SecurityRequirementBootstrap"
init-method="init">
<property name="nodeService">
<ref bean="NodeService" />
</property>
<property name="searchService">
<ref bean="SearchService" />
</property>
<property name="authenticationService">
<ref bean="AuthenticationService" />
</property>
<property name="transactionService">
<ref bean="transactionService" />
</property>
<property name="personService">
<ref bean="PersonService" />
</property>
</bean>
,正如您所看到的,该 bean 具有从 spring 框架注入的一组属性。
SecurityRequirementBoostrap 是一个类,它就像这个
public class SecurityRequirementBootstrap {
public void init() throws Exception{
AuthenticationUtil.runAs(new RunAsWork<String>() {
public String doWork() throws Exception {
try {
transaction = transactionService.getUserTransaction();
transaction.begin();
if(!authenticationService.authenticationExists("admin")){
authenticationService.createAuthentication("admin", new char [] {'a','d','m','i','n'});
}
if(!personService.personExists("admin")){
personService.createPerson(createDefaultProperties("admin", "admin", "admin", "admin@localhost", "admin"));
}
authenticationService.authenticate("admin", new char [] {'a','d','m','i','n'});
NodeUtil.checkSecurityPreRequesite(searchService,nodeService);
transaction.commit();
return "";
}
catch(Throwable e){
transaction.rollback();
e.printStackTrace();
}
return "";
}
}, "admin");
}
private Map<QName, Serializable> createDefaultProperties(String userName, String firstName, String lastName,
String email, String password) {
HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(ContentModel.PROP_USERNAME, userName);
properties.put(ContentModel.PROP_FIRSTNAME, firstName);
properties.put(ContentModel.PROP_LASTNAME, lastName);
properties.put(ContentModel.PROP_EMAIL, email);
properties.put(ContentModel.PROP_PASSWORD, password);
return properties;
}
private NodeService nodeService;
private SearchService searchService;
private UserTransaction transaction;
private TransactionService transactionService;
private MutableAuthenticationService authenticationService;
private PersonService personService;
public static Logger LOGGER = Logger.getLogger(SecurityRequirementBootstrap.class);
public PersonService getPersonService() {
return personService;
}
public void setPersonService(PersonService personService) {
this.personService = personService;
}
public MutableAuthenticationService getAuthenticationService() {
return authenticationService;
}
public void setAuthenticationService(
MutableAuthenticationService authenticationService) {
this.authenticationService = authenticationService;
}
public TransactionService getTransactionService() {
return transactionService;
}
public void setTransactionService(TransactionService transactionService) {
this.transactionService = transactionService;
}
public NodeService getNodeService() {
return nodeService;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public SearchService getSearchService() {
return searchService;
}
public void setSearchService(SearchService searchService) {
this.searchService = searchService;
}
}
正如您在 init 方法中看到的那样,我的目的是对管理员用户进行身份验证,之后我将使用 NodeUtil 类来创建所需的节点。 NodeUtil 是一个大类,但无论引导如何,它都可以正常工作。
在所有情况下,一旦露天引导,我都会遇到异常,并且异常看起来像这样
$ org.alfresco.repo.audit.model.AuditModelException: 07220000 No registered audit data extractor exists for 'org_alfresco_module_dod5015_userRolesExtractor'.
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState.cacheAuditElements(AuditModelRegistryImpl.java:524)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState.access$500(AuditModelRegistryImpl.java:240)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState$1.execute(AuditModelRegistryImpl.java:389)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState$1.execute(AuditModelRegistryImpl.java:375)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:381)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState$2.doWork(AuditModelRegistryImpl.java:416)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState$2.doWork(AuditModelRegistryImpl.java:413)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState.start(AuditModelRegistryImpl.java:412)
at org.alfresco.repo.management.subsystems.AbstractPropertyBackedBean.start(AbstractPropertyBackedBean.java:458)
at org.alfresco.repo.management.subsystems.AbstractPropertyBackedBean.start(AbstractPropertyBackedBean.java:440)
at org.alfresco.repo.management.subsystems.AbstractPropertyBackedBean.getState(AbstractPropertyBackedBean.java:221)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl.getState(AuditModelRegistryImpl.java:165)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl.getAuditPathMapper(AuditModelRegistryImpl.java:201)
at org.alfresco.repo.audit.AuditComponentImpl.areAuditValuesRequired(AuditComponentImpl.java:232)
at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:129)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
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 $Proxy56.authenticationExists(Unknown Source)
at com.ds.ui.bean.dialog.module.SecurityRequirementBootstrap$1.doWork(SecurityRequirementBootstrap.java:29)
at com.ds.ui.bean.dialog.module.SecurityRequirementBootstrap$1.doWork(SecurityRequirementBootstrap.java:1)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
at com.ds.ui.bean.dialog.module.SecurityRequirementBootstrap.init(SecurityRequirementBootstrap.java:24)
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:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
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:443)
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)
所以,任何人都可以帮助我解决这个问题。
谢谢 穆罕默德·阿米尔 |数码系列|高级系统开发人员
Let i need to create a nodes in the alfresco repository at the bootstrap phase to use them later, how can i do that?
I use the .amp file to install the extension customization into alfresco.war, so i have
module-context.xml and inside it i write an import statement refer to the bootstrap-context.xml which have a bean like this
<bean id="com.ds.module.extensions.Core.securityRequirementBootstrap"
class="com.ds.ui.bean.dialog.module.SecurityRequirementBootstrap"
init-method="init">
<property name="nodeService">
<ref bean="NodeService" />
</property>
<property name="searchService">
<ref bean="SearchService" />
</property>
<property name="authenticationService">
<ref bean="AuthenticationService" />
</property>
<property name="transactionService">
<ref bean="transactionService" />
</property>
<property name="personService">
<ref bean="PersonService" />
</property>
</bean>
and as you see the bean have set of properties injected from a spring framework.
SecurityRequirementBoostrap is a class and it like as this
public class SecurityRequirementBootstrap {
public void init() throws Exception{
AuthenticationUtil.runAs(new RunAsWork<String>() {
public String doWork() throws Exception {
try {
transaction = transactionService.getUserTransaction();
transaction.begin();
if(!authenticationService.authenticationExists("admin")){
authenticationService.createAuthentication("admin", new char [] {'a','d','m','i','n'});
}
if(!personService.personExists("admin")){
personService.createPerson(createDefaultProperties("admin", "admin", "admin", "admin@localhost", "admin"));
}
authenticationService.authenticate("admin", new char [] {'a','d','m','i','n'});
NodeUtil.checkSecurityPreRequesite(searchService,nodeService);
transaction.commit();
return "";
}
catch(Throwable e){
transaction.rollback();
e.printStackTrace();
}
return "";
}
}, "admin");
}
private Map<QName, Serializable> createDefaultProperties(String userName, String firstName, String lastName,
String email, String password) {
HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(ContentModel.PROP_USERNAME, userName);
properties.put(ContentModel.PROP_FIRSTNAME, firstName);
properties.put(ContentModel.PROP_LASTNAME, lastName);
properties.put(ContentModel.PROP_EMAIL, email);
properties.put(ContentModel.PROP_PASSWORD, password);
return properties;
}
private NodeService nodeService;
private SearchService searchService;
private UserTransaction transaction;
private TransactionService transactionService;
private MutableAuthenticationService authenticationService;
private PersonService personService;
public static Logger LOGGER = Logger.getLogger(SecurityRequirementBootstrap.class);
public PersonService getPersonService() {
return personService;
}
public void setPersonService(PersonService personService) {
this.personService = personService;
}
public MutableAuthenticationService getAuthenticationService() {
return authenticationService;
}
public void setAuthenticationService(
MutableAuthenticationService authenticationService) {
this.authenticationService = authenticationService;
}
public TransactionService getTransactionService() {
return transactionService;
}
public void setTransactionService(TransactionService transactionService) {
this.transactionService = transactionService;
}
public NodeService getNodeService() {
return nodeService;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public SearchService getSearchService() {
return searchService;
}
public void setSearchService(SearchService searchService) {
this.searchService = searchService;
}
}
As you can see in the init method i aimed to authenticate the admin user and after that i will use a NodeUtil class to create the nodes required. NodeUtil is a big class but it is work fine regardless of bootstrapping.
In all cases i have an exception once the alfresco bootstrapped and the exception look like this
$ org.alfresco.repo.audit.model.AuditModelException: 07220000 No registered audit data extractor exists for 'org_alfresco_module_dod5015_userRolesExtractor'.
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState.cacheAuditElements(AuditModelRegistryImpl.java:524)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState.access$500(AuditModelRegistryImpl.java:240)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState$1.execute(AuditModelRegistryImpl.java:389)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState$1.execute(AuditModelRegistryImpl.java:375)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:381)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState$2.doWork(AuditModelRegistryImpl.java:416)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState$2.doWork(AuditModelRegistryImpl.java:413)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl$AuditModelRegistryState.start(AuditModelRegistryImpl.java:412)
at org.alfresco.repo.management.subsystems.AbstractPropertyBackedBean.start(AbstractPropertyBackedBean.java:458)
at org.alfresco.repo.management.subsystems.AbstractPropertyBackedBean.start(AbstractPropertyBackedBean.java:440)
at org.alfresco.repo.management.subsystems.AbstractPropertyBackedBean.getState(AbstractPropertyBackedBean.java:221)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl.getState(AuditModelRegistryImpl.java:165)
at org.alfresco.repo.audit.model.AuditModelRegistryImpl.getAuditPathMapper(AuditModelRegistryImpl.java:201)
at org.alfresco.repo.audit.AuditComponentImpl.areAuditValuesRequired(AuditComponentImpl.java:232)
at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:129)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
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 $Proxy56.authenticationExists(Unknown Source)
at com.ds.ui.bean.dialog.module.SecurityRequirementBootstrap$1.doWork(SecurityRequirementBootstrap.java:29)
at com.ds.ui.bean.dialog.module.SecurityRequirementBootstrap$1.doWork(SecurityRequirementBootstrap.java:1)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
at com.ds.ui.bean.dialog.module.SecurityRequirementBootstrap.init(SecurityRequirementBootstrap.java:24)
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:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
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:443)
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)
So, can anyone help me to solve this problem.
Thanks
Mohammed Amr | Digital Series | Senior System Developer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议不要使用节点服务来执行此操作。
如果您查看如何将新系统文件夹添加到 Alfresco 中(在升级和全新安装期间),您会发现它们通常作为 ACP 完成。通过使用 ACP,您无需在引导阶段处理特殊情况(当并非所有存储库都已准备好,并且并非所有服务都完全可用时)。相反,您只需将引导上下文文件指向 ACP,其中包含内容和节点,然后就可以了。
如果您想要一个创建文件夹的简单示例,您可以尝试在标准安装中查看
/config/alfresco/bootstrap/scheduledActionsFolder.xml
以获得简单指南。I'd suggest not using the Node Service to do this.
If you look at how new system folders are added into Alfresco (during upgrades and fresh installs), they're normally done as ACPs. By using an ACP, you don't need to take care of the special cases during the bootstrap phase (when not all of the repo is ready, and not all the services are fully available). Instead, you just point your bootstrap context file at an ACP, which has the content and nodes, and away you go.
If you want a simple example for creating a folder, you could try looking at
/config/alfresco/bootstrap/scheduledActionsFolder.xml
in a standard install for a simple guide.