From bb20d042cf648c41a35a84dd959ef3fef1901407 Mon Sep 17 00:00:00 2001 From: Neil McErlean Date: Fri, 27 Mar 2015 09:27:20 +0000 Subject: [PATCH] Work on RM-2027. Addition of the Java API code to retrieve classification reasons and some of the test code associated with that. WIP. Test code not complete. +review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@100255 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../classification/ClassificationService.java | 6 +++ .../ClassificationServiceImpl.java | 41 +++++++++++------ .../classification/Configuration.java | 2 +- .../ClassificationServiceImplUnitTest.java | 45 +++++++++++++++++++ 4 files changed, 79 insertions(+), 15 deletions(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationService.java index e2393986bd..8d26d3572e 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationService.java @@ -37,4 +37,10 @@ public interface ClassificationService * and therefore access to the most restricted documents). */ List getClassificationLevels(); + + /** + * Returns an immutable list of the defined classification reasons. + * @return classification reasons in the order that they are defined. + */ + List getClassificationReasons(); } 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 2e2f467d59..0904d2787f 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 @@ -98,28 +98,36 @@ public class ClassificationServiceImpl extends ServiceBaseImpl } void initConfiguredClassificationReasons() { - final List allPersistedReasons = getPersistedReasons(); - final List configurationReasons = getConfigurationReasons(); + final List persistedReasons = getPersistedReasons(); + final List classpathReasons = getConfigurationReasons(); - // Note! We cannot log the reasons or even the size of these lists for security reasons. - LOGGER.debug("Persisted classification reasons: {}", loggableStatusOf(allPersistedReasons)); - LOGGER.debug("Classpath classification reasons: {}", loggableStatusOf(configurationReasons)); + // Note! We cannot log the reasons or even the size of these lists for security reasons. + LOGGER.debug("Persisted classification reasons: {}", loggableStatusOf(persistedReasons)); + LOGGER.debug("Classpath classification reasons: {}", loggableStatusOf(classpathReasons)); - if (configurationReasons == null || configurationReasons.isEmpty()) + if (isEmpty(persistedReasons)) { - throw new MissingConfiguration("Classification reason configuration is missing."); - } - else if ( !configurationReasons.equals(allPersistedReasons)) - { - attributeService.setAttribute((Serializable) configurationReasons, REASONS_KEY); - this.configuredReasons = configurationReasons; + if (isEmpty(classpathReasons)) + { + throw new MissingConfiguration("Classification reason configuration is missing."); + } + attributeService.setAttribute((Serializable) classpathReasons, REASONS_KEY); + this.configuredReasons = classpathReasons; } else { - this.configuredReasons = allPersistedReasons; + if (isEmpty(classpathReasons) || !classpathReasons.equals(persistedReasons)) + { + LOGGER.warn("Classification reasons configured in classpath do not match those stored in Alfresco." + + "Alfresco will use the unchanged values stored in the database."); + // RM-2073 says that we should log a warning and proceed normally. + } + this.configuredReasons = persistedReasons; } } + private static boolean isEmpty(List l) { return l == null || l.isEmpty(); } + /** Helper method for debug-logging of sensitive lists. */ private String loggableStatusOf(List l) { @@ -178,4 +186,9 @@ public class ClassificationServiceImpl extends ServiceBaseImpl return configuredLevels == null ? Collections.emptyList() : Collections.unmodifiableList(configuredLevels); } -} + + @Override public List getClassificationReasons() + { + return configuredReasons == null ? Collections.emptyList() : + Collections.unmodifiableList(configuredReasons); + }} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/Configuration.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/Configuration.java index 405dccc61f..a658bdb45c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/Configuration.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/Configuration.java @@ -84,7 +84,7 @@ class Configuration } /** - * Gets the list of classification reasons as defined in the system configuration. + * Gets the list of classification reasons as defined in the classpath. * * @return the configured classification reasons in descending order, or an empty list if there are none. */ diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java index 9c1786f773..5f2555b759 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java @@ -22,6 +22,7 @@ import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationS import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; import org.alfresco.service.cmr.attributes.AttributeService; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -36,9 +37,13 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import static org.junit.Assert.*; +import static java.util.Arrays.asList; /** * Unit tests for {@link ClassificationServiceImpl}. @@ -56,6 +61,8 @@ public class ClassificationServiceImplUnitTest "Executive Management", "EM", "Employee", "E", "Public", "P"); + private static final List PLACEHOLDER_CLASSIFICATION_REASONS = asList(new ClassificationReason("r1", "l1"), + new ClassificationReason("r2", "l2")); /** * A convenience method for turning lists of level id Strings into lists * of {@code ClassificationLevel} objects. @@ -145,4 +152,42 @@ public class ClassificationServiceImplUnitTest classificationService.initConfiguredClassificationLevels(); } + + @Test public void pristineSystemShouldBootstrapReasonsConfiguration() + { + // There are no classification reasons stored in the AttributeService. + when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(null); + + // We'll use a small set of placeholder classification reasons. + when(mockConfig.getConfiguredReasons()).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS); + + classificationService.initConfiguredClassificationReasons(); + + verify(mockedAttributeService).setAttribute(eq((Serializable)PLACEHOLDER_CLASSIFICATION_REASONS), + anyString(), anyString(), anyString()); + } + + @Ignore ("This test is currently failing. Needs to be fixed.") // FIXME + @Test public void previouslyStartedSystemShouldProceedNormallyIfConfiguredReasonsHaveNotChanged() + { + // There are existing classification reasons stored in the AttributeService. + when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn((Serializable)PLACEHOLDER_CLASSIFICATION_REASONS); + + // We'll use a small set of placeholder classification reasons. + when(mockConfig.getConfiguredReasons()).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS); + + classificationService.initConfiguredClassificationReasons(); + + // This line added to try and work out what the interaction *is*. + verifyZeroInteractions(mockedAttributeService); + + verify(mockedAttributeService, never()).setAttribute(any(Serializable.class), + anyString(), anyString(), anyString()); + } + + @Ignore ("To be implemented") // TODO + @Test public void previouslyStartedSystemShouldWarnIfConfiguredReasonsHaveChanged() + { + fail("TODO"); + } }