mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
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
This commit is contained in:
@@ -37,4 +37,10 @@ public interface ClassificationService
|
||||
* and therefore access to the most restricted documents).
|
||||
*/
|
||||
List<ClassificationLevel> getClassificationLevels();
|
||||
|
||||
/**
|
||||
* Returns an immutable list of the defined classification reasons.
|
||||
* @return classification reasons in the order that they are defined.
|
||||
*/
|
||||
List<ClassificationReason> getClassificationReasons();
|
||||
}
|
||||
|
@@ -98,28 +98,36 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
|
||||
}
|
||||
|
||||
void initConfiguredClassificationReasons() {
|
||||
final List<ClassificationReason> allPersistedReasons = getPersistedReasons();
|
||||
final List<ClassificationReason> configurationReasons = getConfigurationReasons();
|
||||
final List<ClassificationReason> persistedReasons = getPersistedReasons();
|
||||
final List<ClassificationReason> 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.<ClassificationLevel>emptyList() :
|
||||
Collections.unmodifiableList(configuredLevels);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public List<ClassificationReason> getClassificationReasons()
|
||||
{
|
||||
return configuredReasons == null ? Collections.<ClassificationReason>emptyList() :
|
||||
Collections.unmodifiableList(configuredReasons);
|
||||
}}
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
@@ -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<ClassificationReason> 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");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user