mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +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>
|
<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 -->
|
<!-- Classification Service -->
|
||||||
|
|
||||||
<bean id="classificationService"
|
<bean id="classificationService"
|
||||||
class="org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceImpl"
|
class="org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceImpl"
|
||||||
parent="baseService">
|
parent="baseService">
|
||||||
<property name="attributeService" ref="AttributeService"/>
|
<property name="attributeService" ref="AttributeService"/>
|
||||||
|
<property name="classificationServiceDAO" ref="classificationServiceDAO"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="ClassificationService" class="org.springframework.aop.framework.ProxyFactoryBean">
|
<bean id="ClassificationService" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||||
|
@@ -40,14 +40,14 @@ import org.json.JSONTokener;
|
|||||||
*/
|
*/
|
||||||
class ClassificationServiceDAO
|
class ClassificationServiceDAO
|
||||||
{
|
{
|
||||||
public final String levelConfigLocation;
|
private String levelConfigLocation;
|
||||||
public final String reasonConfigLocation;
|
private String reasonConfigLocation;
|
||||||
|
|
||||||
public ClassificationServiceDAO(String levelConfigLocation, String reasonConfigLocation)
|
/** Set the location of the level configuration file relative to the classpath. */
|
||||||
{
|
public void setLevelConfigLocation(String levelConfigLocation) { this.levelConfigLocation = levelConfigLocation; }
|
||||||
this.levelConfigLocation = levelConfigLocation;
|
|
||||||
this.reasonConfigLocation = reasonConfigLocation;
|
/** 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.
|
* 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" };
|
"classification.reasons" };
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationServiceImpl.class);
|
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 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. */
|
/** The classification levels currently configured in this server. */
|
||||||
private List<ClassificationLevel> configuredLevels;
|
private List<ClassificationLevel> configuredLevels;
|
||||||
/** The classification reasons currently configured in this server. */
|
/** The classification reasons currently configured in this server. */
|
||||||
private List<ClassificationReason> configuredReasons;
|
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; }
|
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()
|
void initConfiguredClassificationLevels()
|
||||||
{
|
{
|
||||||
final List<ClassificationLevel> allPersistedLevels = getPersistedLevels();
|
final List<ClassificationLevel> allPersistedLevels = getPersistedLevels();
|
||||||
|
@@ -43,46 +43,47 @@ public class ClassificationServiceDAOUnitTest
|
|||||||
|
|
||||||
@Test public void getConfiguredLevels_readingDefaultConfigurationShouldWork()
|
@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();
|
List<ClassificationLevel> config = c.getConfiguredLevels();
|
||||||
assertEquals(DEFAULT_CLASSIFICATION_LEVELS, config);
|
assertEquals(DEFAULT_CLASSIFICATION_LEVELS, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void getConfiguredLevels_readingMissingConfigurationShouldProduceEmptyConfig() throws Exception
|
@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());
|
assertTrue(c.getConfiguredLevels().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test (expected = MalformedConfiguration.class)
|
@Test (expected = MalformedConfiguration.class)
|
||||||
public void getConfiguredLevels_readingMalformedConfigurationShouldFail()
|
public void getConfiguredLevels_readingMalformedConfigurationShouldFail()
|
||||||
{
|
{
|
||||||
ClassificationServiceDAO c = new ClassificationServiceDAO(
|
ClassificationServiceDAO c = new ClassificationServiceDAO();
|
||||||
"/alfresco/classification/rm-classification-levels-malformed.json",
|
c.setLevelConfigLocation("/alfresco/classification/rm-classification-levels-malformed.json");
|
||||||
"/alfresco/classification/rm-classification-levels-malformed.json");
|
|
||||||
c.getConfiguredLevels();
|
c.getConfiguredLevels();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void getConfiguredReasons_readingDefaultConfigurationShouldWork()
|
@Test public void getConfiguredReasons_readingDefaultConfigurationShouldWork()
|
||||||
{
|
{
|
||||||
ClassificationServiceDAO c = new ClassificationServiceDAO(ClassificationServiceImpl.DEFAULT_LEVELS_FILE,
|
ClassificationServiceDAO c = new ClassificationServiceDAO();
|
||||||
ClassificationServiceImpl.DEFAULT_REASONS_FILE);
|
c.setReasonConfigLocation("/alfresco/module/org_alfresco_module_rm/classification/rm-classification-reasons.json");
|
||||||
List<ClassificationReason> config = c.getConfiguredReasons();
|
List<ClassificationReason> config = c.getConfiguredReasons();
|
||||||
assertFalse(config.isEmpty());
|
assertFalse(config.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void getConfiguredReasons_readingMissingConfigurationShouldProduceEmptyConfig() throws Exception
|
@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());
|
assertTrue(c.getConfiguredReasons().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test (expected = MalformedConfiguration.class)
|
@Test (expected = MalformedConfiguration.class)
|
||||||
public void getConfiguredReasons_readingMalformedConfigurationShouldFail()
|
public void getConfiguredReasons_readingMalformedConfigurationShouldFail()
|
||||||
{
|
{
|
||||||
ClassificationServiceDAO c = new ClassificationServiceDAO(
|
ClassificationServiceDAO c = new ClassificationServiceDAO();
|
||||||
"/alfresco/classification/rm-classification-levels-malformed.json",
|
c.setReasonConfigLocation("/alfresco/classification/rm-classification-levels-malformed.json");
|
||||||
"/alfresco/classification/rm-classification-levels-malformed.json");
|
|
||||||
c.getConfiguredReasons();
|
c.getConfiguredReasons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -103,8 +103,9 @@ public class ClassificationServiceImplUnitTest
|
|||||||
reset(mockClassificationServiceDAO, mockedAttributeService, mockAppender);
|
reset(mockClassificationServiceDAO, mockedAttributeService, mockAppender);
|
||||||
mockedAuthenticationUtil = MockAuthenticationUtilHelper.create();
|
mockedAuthenticationUtil = MockAuthenticationUtilHelper.create();
|
||||||
|
|
||||||
classificationServiceImpl = new ClassificationServiceImpl(mockClassificationServiceDAO);
|
classificationServiceImpl = new ClassificationServiceImpl();
|
||||||
classificationServiceImpl.setAttributeService(mockedAttributeService);
|
classificationServiceImpl.setAttributeService(mockedAttributeService);
|
||||||
|
classificationServiceImpl.setClassificationServiceDAO(mockClassificationServiceDAO);
|
||||||
classificationServiceImpl.setAuthenticationUtil(mockedAuthenticationUtil);
|
classificationServiceImpl.setAuthenticationUtil(mockedAuthenticationUtil);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user