mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-2604 Fun with generics and add missing @Test annotation.
(Thanks Neil). git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/caveatmarkdatatype@114266 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.caveat.dao;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
|
||||
@@ -28,18 +29,18 @@ import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
|
||||
* @author Tom Page
|
||||
* @since 2.4.a
|
||||
*/
|
||||
public class CaveatDAOCache implements CaveatDAOInterface
|
||||
public class CaveatDAOCache<SMAP extends Map<String, CaveatGroup> & Serializable> implements CaveatDAOInterface<SMAP>
|
||||
{
|
||||
/** The wrapped caveat DAO. */
|
||||
private CaveatDAOInterface caveatDAO;
|
||||
private CaveatDAOInterface<SMAP> caveatDAO;
|
||||
/** A cache of the system caveat groups. */
|
||||
private Map<String, CaveatGroup> caveatGroups;
|
||||
private SMAP caveatGroups;
|
||||
|
||||
/**
|
||||
* {@inheritDoc} The first call to this method will be cached and returned for every successive call.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, CaveatGroup> getCaveatGroups()
|
||||
public SMAP getCaveatGroups()
|
||||
{
|
||||
if (caveatGroups == null)
|
||||
{
|
||||
@@ -53,7 +54,7 @@ public class CaveatDAOCache implements CaveatDAOInterface
|
||||
*
|
||||
* @param caveatDAO The caveat DAO to be wrapped.
|
||||
*/
|
||||
public void setCaveatDAO(CaveatDAOInterface caveatDAO)
|
||||
public void setCaveatDAO(CaveatDAOInterface<SMAP> caveatDAO)
|
||||
{
|
||||
this.caveatDAO = caveatDAO;
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.caveat.dao;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -46,7 +47,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Tom Page
|
||||
* @since 2.4.a
|
||||
*/
|
||||
public class CaveatDAOFromJSON implements CaveatDAOInterface
|
||||
public class CaveatDAOFromJSON<SMAP extends Map<String, CaveatGroup> & Serializable> implements CaveatDAOInterface<SMAP>
|
||||
{
|
||||
/** JSON key for the group id. */
|
||||
private static final String GROUP_ID_JSON_KEY = "id";
|
||||
@@ -80,9 +81,10 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
|
||||
* @throws MalformedConfiguration If the configuration file cannot be interpreted.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, CaveatGroup> getCaveatGroups()
|
||||
public SMAP getCaveatGroups()
|
||||
{
|
||||
Map<String, CaveatGroup> result = new HashMap<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
SMAP result = (SMAP) new HashMap<String, CaveatGroup>();
|
||||
try (final InputStream in = this.getClass().getResourceAsStream(configLocation))
|
||||
{
|
||||
if (in != null)
|
||||
|
@@ -25,7 +25,6 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.MalformedConfiguration;
|
||||
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
@@ -42,7 +41,7 @@ import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||
* @author Tom Page
|
||||
* @since 2.4.a
|
||||
*/
|
||||
public class CaveatDAOFromJSONBootstrap extends AbstractLifecycleBean implements ClassifiedContentModel
|
||||
public class CaveatDAOFromJSONBootstrap<SMAP extends Map<String, CaveatGroup> & Serializable> extends AbstractLifecycleBean
|
||||
{
|
||||
/** Logging utility for the class. */
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CaveatDAOFromJSONBootstrap.class);
|
||||
@@ -50,14 +49,14 @@ public class CaveatDAOFromJSONBootstrap extends AbstractLifecycleBean implements
|
||||
private final AuthenticationUtil authenticationUtil;
|
||||
private final TransactionService transactionService;
|
||||
private AttributeService attributeService;
|
||||
private CaveatDAOInterface caveatDAO;
|
||||
private CaveatDAOInterface<SMAP> caveatDAO;
|
||||
|
||||
private boolean isInitialised = false;
|
||||
|
||||
public CaveatDAOFromJSONBootstrap(AuthenticationUtil authUtil,
|
||||
TransactionService txService,
|
||||
AttributeService attributeService,
|
||||
CaveatDAOInterface caveatDAO)
|
||||
CaveatDAOInterface<SMAP> caveatDAO)
|
||||
{
|
||||
this.authenticationUtil = authUtil;
|
||||
this.transactionService = txService;
|
||||
@@ -66,7 +65,7 @@ public class CaveatDAOFromJSONBootstrap extends AbstractLifecycleBean implements
|
||||
}
|
||||
|
||||
/** Set the object from which configuration options will be read. */
|
||||
public void setClassificationServiceDAO(CaveatDAOInterface caveatDAO) { this.caveatDAO = caveatDAO; }
|
||||
public void setClassificationServiceDAO(CaveatDAOInterface<SMAP> caveatDAO) { this.caveatDAO = caveatDAO; }
|
||||
public void setAttributeService(AttributeService attributeService) { this.attributeService = attributeService; }
|
||||
|
||||
public boolean isInitialised()
|
||||
@@ -100,15 +99,15 @@ public class CaveatDAOFromJSONBootstrap extends AbstractLifecycleBean implements
|
||||
*
|
||||
* @return the persisted caveat groups if they have been persisted, else {@code null}.
|
||||
*/
|
||||
private Map<String, CaveatGroup> getPersistedValues(final Serializable[] key)
|
||||
private SMAP getPersistedCaveatGroups(final Serializable[] key)
|
||||
{
|
||||
return authenticationUtil.runAsSystem(new RunAsWork<Map<String, CaveatGroup>>()
|
||||
return authenticationUtil.runAsSystem(new RunAsWork<SMAP>()
|
||||
{
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, CaveatGroup> doWork() throws Exception
|
||||
public SMAP doWork() throws Exception
|
||||
{
|
||||
return (Map<String, CaveatGroup>) attributeService.getAttribute(key);
|
||||
return (SMAP) attributeService.getAttribute(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -134,24 +133,24 @@ public class CaveatDAOFromJSONBootstrap extends AbstractLifecycleBean implements
|
||||
*/
|
||||
protected void initialiseConfiguredCaveatGroups(Serializable[] key)
|
||||
{
|
||||
final Map<String, CaveatGroup> persistedValues = getPersistedValues(key);
|
||||
final Map<String, CaveatGroup> classpathValues = caveatDAO.getCaveatGroups();
|
||||
final SMAP persistedGroups = getPersistedCaveatGroups(key);
|
||||
final SMAP classpathGroups = caveatDAO.getCaveatGroups();
|
||||
|
||||
// Note! We cannot log the entities or even the size of these lists for security reasons.
|
||||
LOGGER.debug("Persisted CaveatGroup: {}", loggableStatusOf(persistedValues));
|
||||
LOGGER.debug("Classpath CaveatGroup: {}", loggableStatusOf(classpathValues));
|
||||
LOGGER.debug("Persisted CaveatGroup: {}", loggableStatusOf(persistedGroups));
|
||||
LOGGER.debug("Classpath CaveatGroup: {}", loggableStatusOf(classpathGroups));
|
||||
|
||||
if (isEmpty(classpathValues))
|
||||
if (isEmpty(classpathGroups))
|
||||
{
|
||||
throw new MalformedConfiguration("CaveatGroup configuration is missing.");
|
||||
}
|
||||
if (!classpathValues.equals(persistedValues))
|
||||
if (!classpathGroups.equals(persistedGroups))
|
||||
{
|
||||
if (!isEmpty(persistedValues))
|
||||
if (!isEmpty(persistedGroups))
|
||||
{
|
||||
LOGGER.warn("CaveatGroup configuration changed. This may result in unpredictable results if the caveat scheme is already in use.");
|
||||
}
|
||||
attributeService.setAttribute((Serializable) classpathValues, key);
|
||||
attributeService.setAttribute(classpathGroups, key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.caveat.dao;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
|
||||
@@ -29,10 +30,10 @@ import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
|
||||
* @author Tom Page
|
||||
* @since 2.4.a
|
||||
*/
|
||||
public interface CaveatDAOInterface
|
||||
public interface CaveatDAOInterface<SMAP extends Map<String, CaveatGroup> & Serializable>
|
||||
{
|
||||
/**
|
||||
* Gets a map of all the available caveat groups keyed by id.
|
||||
*/
|
||||
Map<String, CaveatGroup> getCaveatGroups();
|
||||
SMAP getCaveatGroups();
|
||||
}
|
||||
|
@@ -37,7 +37,8 @@ import org.junit.Test;
|
||||
public class CaveatDAOFromJSONUnitTest
|
||||
{
|
||||
/** The class under test. */
|
||||
CaveatDAOFromJSON caveatDAOFromJSON = new CaveatDAOFromJSON();
|
||||
@SuppressWarnings("rawtypes")
|
||||
CaveatDAOFromJSON<?> caveatDAOFromJSON = new CaveatDAOFromJSON();
|
||||
|
||||
/** Test that loading the default caveat configuration file doesn't throw any exceptions. */
|
||||
@Test
|
||||
@@ -90,6 +91,7 @@ public class CaveatDAOFromJSONUnitTest
|
||||
}
|
||||
|
||||
/** Test that a duplicate mark id (in different groups) doesn't cause an exception. */
|
||||
@Test
|
||||
public void testGetCaveatGroups_duplicateMarkIdInDifferentGroups()
|
||||
{
|
||||
caveatDAOFromJSON.setConfigLocation("/alfresco/caveat/rm-caveats-duplicateMarkIdInDifferentGroups.json");
|
||||
|
Reference in New Issue
Block a user