First updates following code review on RM-1945 & RM-1946. Thanks Roy & Tom!

Renamed a public service method to getClassificationLevels.
Removed a redundant test method.
Code tidying.
Various internal renames to help readability.
Slight javadoc improvements.
Also some trivial changes like fixing typos and copyright years etc.
Removing warnings from within AuthenticationUtil blocks allows IntelliJ to fold them to Java 8 closure format. (fistpump).  


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@100020 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2015-03-24 21:15:22 +00:00
parent ff4fb3b7d0
commit 0cfc1a98bf
6 changed files with 33 additions and 49 deletions

View File

@@ -46,7 +46,7 @@
<property name="authenticationUtil" ref="rm.authenticationUtil"/>
</bean>
<!-- Bootstap the message property files -->
<!-- Bootstrap the message property files -->
<bean id="org_alfresco_module_rm_resourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>

View File

@@ -42,7 +42,7 @@
<property name="objectDefinitionSource">
<value>
<![CDATA[
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService.getApplicableLevels=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService.getClassificationLevels=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService.*=RM_DENY
]]>
</value>

View File

@@ -32,7 +32,9 @@ public interface ClassificationService
{
/**
* Returns an immutable list of the defined classification levels.
* @return classification levels in descending order from highest to lowest.
* @return classification levels in descending order from highest to lowest
* (where fewer users have access to the highest classification levels
* and therefore access to the most restricted documents).
*/
public List<ClassificationLevel> getApplicableLevels();
public List<ClassificationLevel> getClassificationLevels();
}

View File

@@ -38,7 +38,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
{
private static Log logger = LogFactory.getLog(ClassificationServiceImpl.class);
private static final String[] ATTRIBUTE_KEYS = new String[] { "org.alfresco",
private static final String[] LEVELS_KEY = new String[] { "org.alfresco",
"module.org_alfresco_module_rm",
"classification.levels" };
@@ -57,23 +57,23 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
void initConfiguredClassificationLevels()
{
final List<ClassificationLevel> allPersistedLevels = getPersistedLevels();
final List<ClassificationLevel> configuredLevels = getConfiguredLevels();
final List<ClassificationLevel> configurationLevels = getConfigurationLevels();
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("Configured classification levels: " + loggableStatusOf(configuredLevels));
logger.debug("Classpath classification levels: " + loggableStatusOf(configurationLevels));
}
if (configuredLevels == null || configuredLevels.isEmpty())
if (configurationLevels == null || configurationLevels.isEmpty())
{
throw new MissingConfiguration("Classification level configuration is missing.");
}
else if ( !configuredLevels.equals(allPersistedLevels))
else if ( !configurationLevels.equals(allPersistedLevels))
{
attributeService.setAttribute((Serializable) configuredLevels, ATTRIBUTE_KEYS);
this.configuredLevels = configuredLevels;
attributeService.setAttribute((Serializable) configurationLevels, LEVELS_KEY);
this.configuredLevels = configurationLevels;
}
else
{
@@ -96,21 +96,23 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
List<ClassificationLevel> getPersistedLevels() {
return authenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork<List<ClassificationLevel>>()
{
@Override public List<ClassificationLevel> doWork() throws Exception
@Override
@SuppressWarnings("unchecked")
public List<ClassificationLevel> doWork() throws Exception
{
return (List<ClassificationLevel>) attributeService.getAttribute(ATTRIBUTE_KEYS);
return (List<ClassificationLevel>) attributeService.getAttribute(LEVELS_KEY);
}
});
}
/** Gets the list (in descending order) of classification levels - as defined in the system configuration. */
List<ClassificationLevel> getConfiguredLevels()
List<ClassificationLevel> getConfigurationLevels()
{
return config.getConfiguredLevels();
}
@Override
public List<ClassificationLevel> getApplicableLevels()
public List<ClassificationLevel> getClassificationLevels()
{
return configuredLevels == null ? Collections.<ClassificationLevel>emptyList() :
Collections.unmodifiableList(configuredLevels);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -65,7 +65,8 @@ class Configuration
result = new ArrayList<>(jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
for (int i = 0; i < jsonArray.length(); i++)
{
final JSONObject nextObj = jsonArray.getJSONObject(i);
final String name = nextObj.getString("name");
final String displayLabelKey = nextObj.getString("displayLabel");

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -31,7 +31,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
/**
* Unit tests for {@link ClassificationServiceImpl}.
*
@@ -63,21 +62,11 @@ public class ClassificationServiceImplUnitTest extends BaseUnitTest
ClassificationLevel.class.getSimpleName(), idsAndLabels.length));
}
final int resultLength = idsAndLabels.length / 2;
final String[] ids = new String[resultLength];
final String[] labels = new String[resultLength];
final List<ClassificationLevel> levels = new ArrayList<>(idsAndLabels.length / 2);
for (int i = 0; i < idsAndLabels.length; i++)
for (int i = 0; i < idsAndLabels.length; i += 2)
{
if (i % 2 == 0) { ids[i / 2] = idsAndLabels[i]; }
else { labels[(i - 1) / 2] = idsAndLabels[i]; }
}
final List<ClassificationLevel> levels = new ArrayList<>(resultLength);
for (int i = 0; i < resultLength; i++)
{
levels.add(new ClassificationLevel(ids[i], labels[i]));
levels.add(new ClassificationLevel(idsAndLabels[i], idsAndLabels[i+1]));
}
return levels;
@@ -94,17 +83,7 @@ public class ClassificationServiceImplUnitTest extends BaseUnitTest
classificationService.initConfiguredClassificationLevels();
assertEquals(DEFAULT_CLASSIFICATION_LEVELS, classificationService.getApplicableLevels());
}
@Test public void alternativeConfigurationVanillaSystem()
{
classificationService = new TestClassificationService(null, ALT_CLASSIFICATION_LEVELS);
classificationService.setAttributeService(mockedAttributeService);
classificationService.initConfiguredClassificationLevels();
assertEquals(ALT_CLASSIFICATION_LEVELS, classificationService.getApplicableLevels());
assertEquals(DEFAULT_CLASSIFICATION_LEVELS, classificationService.getClassificationLevels());
}
@Test public void alternativeConfigurationPreviouslyStartedSystem()
@@ -114,7 +93,7 @@ public class ClassificationServiceImplUnitTest extends BaseUnitTest
classificationService.initConfiguredClassificationLevels();
assertEquals(ALT_CLASSIFICATION_LEVELS, classificationService.getApplicableLevels());
assertEquals(ALT_CLASSIFICATION_LEVELS, classificationService.getClassificationLevels());
}
@Test (expected=MissingConfiguration.class)
@@ -141,6 +120,6 @@ public class ClassificationServiceImplUnitTest extends BaseUnitTest
}
@Override List<ClassificationLevel> getPersistedLevels() { return persisted; }
@Override List<ClassificationLevel> getConfiguredLevels() { return configured; }
@Override List<ClassificationLevel> getConfigurationLevels() { return configured; }
}
}