mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Wire the ClassificationServiceDAO using Spring injection.
Also small change to lower visibility of ClassificationServiceDAO member variables from public to private. +review RM @nmcerlean @rwetherall git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@100721 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -3,12 +3,18 @@
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="classificationServiceDAO">
|
||||
<property name="levelConfigLocation" value="/alfresco/module/org_alfresco_module_rm/classification/rm-classification-levels.json" />
|
||||
<property name="reasonConfigLocation" value="/alfresco/module/org_alfresco_module_rm/classification/rm-classification-reasons.json" />
|
||||
</bean>
|
||||
|
||||
<!-- Classification Service -->
|
||||
|
||||
<bean id="classificationService"
|
||||
class="org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceImpl"
|
||||
parent="baseService">
|
||||
<property name="attributeService" ref="AttributeService"/>
|
||||
<property name="classificationServiceDAO" ref="classificationServiceDAO"/>
|
||||
</bean>
|
||||
|
||||
<bean id="ClassificationService" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
|
@@ -40,14 +40,14 @@ import org.json.JSONTokener;
|
||||
*/
|
||||
class ClassificationServiceDAO
|
||||
{
|
||||
public final String levelConfigLocation;
|
||||
public final String reasonConfigLocation;
|
||||
private String levelConfigLocation;
|
||||
private String reasonConfigLocation;
|
||||
|
||||
public ClassificationServiceDAO(String levelConfigLocation, String reasonConfigLocation)
|
||||
{
|
||||
this.levelConfigLocation = levelConfigLocation;
|
||||
this.reasonConfigLocation = reasonConfigLocation;
|
||||
}
|
||||
/** Set the location of the level configuration file relative to the classpath. */
|
||||
public void setLevelConfigLocation(String levelConfigLocation) { this.levelConfigLocation = levelConfigLocation; }
|
||||
|
||||
/** Set the location of the reasons configuration file relative to the classpath. */
|
||||
public void setReasonConfigLocation(String reasonConfigLocation) { this.reasonConfigLocation = reasonConfigLocation; }
|
||||
|
||||
/**
|
||||
* Gets the list (in descending order) of classification levels - as defined in the classpath.
|
||||
|
@@ -44,36 +44,19 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
|
||||
"classification.reasons" };
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationServiceImpl.class);
|
||||
|
||||
static final String DEFAULT_CONFIG_DIRECTORY = "/alfresco/module/org_alfresco_module_rm/classification/";
|
||||
static final String DEFAULT_LEVELS_FILE = DEFAULT_CONFIG_DIRECTORY + "rm-classification-levels.json";
|
||||
static final String DEFAULT_REASONS_FILE = DEFAULT_CONFIG_DIRECTORY + "rm-classification-reasons.json";
|
||||
|
||||
private AttributeService attributeService; // TODO What about other code (e.g. REST API) accessing the AttrService?
|
||||
private ClassificationServiceDAO classificationServiceDao;
|
||||
|
||||
/** The classification levels currently configured in this server. */
|
||||
private List<ClassificationLevel> configuredLevels;
|
||||
/** The classification reasons currently configured in this server. */
|
||||
private List<ClassificationReason> configuredReasons;
|
||||
|
||||
private final ClassificationServiceDAO classificationServiceDao;
|
||||
|
||||
public ClassificationServiceImpl()
|
||||
{
|
||||
this.classificationServiceDao = new ClassificationServiceDAO(DEFAULT_LEVELS_FILE, DEFAULT_REASONS_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Package protected constructor, primarily for unit testing purposes.
|
||||
*
|
||||
* @param classificationServiceDao The object from which configuration options will be read.
|
||||
*/
|
||||
ClassificationServiceImpl(ClassificationServiceDAO classificationServiceDao)
|
||||
{
|
||||
this.classificationServiceDao = classificationServiceDao;
|
||||
}
|
||||
|
||||
public void setAttributeService(AttributeService service) { this.attributeService = service; }
|
||||
|
||||
/** Set the object from which configuration options will be read. */
|
||||
public void setClassificationServiceDAO(ClassificationServiceDAO classificationServiceDao) { this.classificationServiceDao = classificationServiceDao; }
|
||||
|
||||
void initConfiguredClassificationLevels()
|
||||
{
|
||||
final List<ClassificationLevel> allPersistedLevels = getPersistedLevels();
|
||||
|
@@ -43,46 +43,47 @@ public class ClassificationServiceDAOUnitTest
|
||||
|
||||
@Test public void getConfiguredLevels_readingDefaultConfigurationShouldWork()
|
||||
{
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO(ClassificationServiceImpl.DEFAULT_LEVELS_FILE, ClassificationServiceImpl.DEFAULT_REASONS_FILE);
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO();
|
||||
c.setLevelConfigLocation("/alfresco/module/org_alfresco_module_rm/classification/rm-classification-levels.json");
|
||||
List<ClassificationLevel> config = c.getConfiguredLevels();
|
||||
assertEquals(DEFAULT_CLASSIFICATION_LEVELS, config);
|
||||
}
|
||||
|
||||
@Test public void getConfiguredLevels_readingMissingConfigurationShouldProduceEmptyConfig() throws Exception
|
||||
{
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO("/no/such/resource", "/no/such/resource");
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO();
|
||||
c.setLevelConfigLocation("/no/such/resource");
|
||||
assertTrue(c.getConfiguredLevels().isEmpty());
|
||||
}
|
||||
|
||||
@Test (expected = MalformedConfiguration.class)
|
||||
public void getConfiguredLevels_readingMalformedConfigurationShouldFail()
|
||||
{
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO(
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json",
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json");
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO();
|
||||
c.setLevelConfigLocation("/alfresco/classification/rm-classification-levels-malformed.json");
|
||||
c.getConfiguredLevels();
|
||||
}
|
||||
|
||||
@Test public void getConfiguredReasons_readingDefaultConfigurationShouldWork()
|
||||
{
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO(ClassificationServiceImpl.DEFAULT_LEVELS_FILE,
|
||||
ClassificationServiceImpl.DEFAULT_REASONS_FILE);
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO();
|
||||
c.setReasonConfigLocation("/alfresco/module/org_alfresco_module_rm/classification/rm-classification-reasons.json");
|
||||
List<ClassificationReason> config = c.getConfiguredReasons();
|
||||
assertFalse(config.isEmpty());
|
||||
}
|
||||
|
||||
@Test public void getConfiguredReasons_readingMissingConfigurationShouldProduceEmptyConfig() throws Exception
|
||||
{
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO("/no/such/resource", "/no/such/resource");
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO();
|
||||
c.setReasonConfigLocation("/no/such/resource");
|
||||
assertTrue(c.getConfiguredReasons().isEmpty());
|
||||
}
|
||||
|
||||
@Test (expected = MalformedConfiguration.class)
|
||||
public void getConfiguredReasons_readingMalformedConfigurationShouldFail()
|
||||
{
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO(
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json",
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json");
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO();
|
||||
c.setReasonConfigLocation("/alfresco/classification/rm-classification-levels-malformed.json");
|
||||
c.getConfiguredReasons();
|
||||
}
|
||||
}
|
||||
|
@@ -103,8 +103,9 @@ public class ClassificationServiceImplUnitTest
|
||||
reset(mockClassificationServiceDAO, mockedAttributeService, mockAppender);
|
||||
mockedAuthenticationUtil = MockAuthenticationUtilHelper.create();
|
||||
|
||||
classificationServiceImpl = new ClassificationServiceImpl(mockClassificationServiceDAO);
|
||||
classificationServiceImpl = new ClassificationServiceImpl();
|
||||
classificationServiceImpl.setAttributeService(mockedAttributeService);
|
||||
classificationServiceImpl.setClassificationServiceDAO(mockClassificationServiceDAO);
|
||||
classificationServiceImpl.setAuthenticationUtil(mockedAuthenticationUtil);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user