From 5451568517060820db9effbf000c104889016f64 Mon Sep 17 00:00:00 2001 From: Neil McErlean Date: Tue, 24 Mar 2015 11:32:44 +0000 Subject: [PATCH] Tidyup as part of RM-1945 and RM-1946. Attempt to fix the failing build. Although the Alfresco server starts fine on my machine, there is a timing/dependency issue which means that on Bamboo, ClassificationServiceImpl.initConfiguredClassificationLevels attempts to use the Alfresco DB before it is fully ready. This check-in changes the service startup so that instead of using a spring init-method, it uses a LifecycleBean to run the initialisation after the server has fully started up. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@99962 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rm-classified-records-context.xml | 7 ++ .../ClassificationServiceBootstrap.java | 72 +++++++++++++++++++ .../ClassificationServiceImpl.java | 4 +- 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrap.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-classified-records-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-classified-records-context.xml index e42ba76443..6ed0851f8a 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-classified-records-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-classified-records-context.xml @@ -49,4 +49,11 @@ + + + + + + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrap.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrap.java new file mode 100644 index 0000000000..8a5c712471 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrap.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2005-2015 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm.classification; + +import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.transaction.TransactionService; +import org.springframework.context.ApplicationEvent; +import org.springframework.extensions.surf.util.AbstractLifecycleBean; + +/** + * This class is responsible for initialising any Classification-specific data on server bootstrap. + * + * @author Neil Mc Erlean + * @since 3.0 + */ +public class ClassificationServiceBootstrap extends AbstractLifecycleBean +{ + private final AuthenticationUtil authenticationUtil; + private final ClassificationServiceImpl classificationService; + private final TransactionService transactionService; + + public ClassificationServiceBootstrap(AuthenticationUtil authUtil, + ClassificationServiceImpl cService, + TransactionService txService) + { + this.authenticationUtil = authUtil; + this.classificationService = cService; + this.transactionService = txService; + } + + @Override protected void onBootstrap(ApplicationEvent event) + { + authenticationUtil.runAsSystem(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork() + { + public Void doWork() + { + RetryingTransactionCallback callback = new RetryingTransactionCallback() + { + public Void execute() + { + classificationService.initConfiguredClassificationLevels(); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(callback); + return null; + } + }); + } + + @Override protected void onShutdown(ApplicationEvent event) + { + // Intentionally empty. + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java index bb744d2a5e..affc7b89cc 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java @@ -54,7 +54,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl public void setAttributeService(AttributeService service) { this.attributeService = service; } - public void initConfiguredClassificationLevels() + void initConfiguredClassificationLevels() { final List allPersistedLevels = getPersistedLevels(); final List configuredLevels = getConfiguredLevels(); @@ -62,7 +62,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl if (logger.isDebugEnabled()) { // Note! We cannot log the level names or even the size of these lists for security reasons. - logger.debug("Persisted classification levels: " + loggableStatusOf(allPersistedLevels)); + logger.debug("Persisted classification levels: " + loggableStatusOf(allPersistedLevels)); logger.debug("Configured classification levels: " + loggableStatusOf(configuredLevels)); }