From 66384de5c29ccf0a0562ab8453463ff6463104c5 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 14 Oct 2015 15:47:17 +0000 Subject: [PATCH] RM-2586 Add method on CaveatDAOInterface to get a single group. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/caveatmarkdatatype@114356 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../caveat/CaveatException.java | 12 +++++++++ .../caveat/dao/CaveatDAOCache.java | 26 ++++++++++++++++++- .../caveat/dao/CaveatDAOFromJSON.java | 17 ++++++++++++ .../caveat/dao/CaveatDAOInterface.java | 11 +++++++- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/CaveatException.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/CaveatException.java index 6777be24ed..5d37c2592c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/CaveatException.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/CaveatException.java @@ -42,6 +42,18 @@ public class CaveatException extends AlfrescoRuntimeException super(msgId, cause); } + /** The supplied caveat group id was not found in the configured list. */ + public static class CaveatGroupNotFound extends CaveatException + { + /** serial version uid */ + private static final long serialVersionUID = -3547790332616121911L; + + public CaveatGroupNotFound(String caveatGroupId) + { + super("Could not find caveat group with id " + caveatGroupId); + } + } + /** The supplied caveat mark id was not found in the configured list. */ public static class CaveatMarkNotFound extends CaveatException { diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOCache.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOCache.java index 4e903b0112..2bf24bb478 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOCache.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOCache.java @@ -16,9 +16,12 @@ * You should have received a copy of the GNU Lesser General Public License * along with Alfresco. If not, see . */ + package org.alfresco.module.org_alfresco_module_rm.caveat.dao; import com.google.common.collect.ImmutableMap; + +import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.CaveatGroupNotFound; import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup; /** @@ -39,12 +42,33 @@ public class CaveatDAOCache implements CaveatDAOInterface */ @Override public ImmutableMap getCaveatGroups() + { + ensureCachePopulated(); + return caveatGroups; + } + + /** + * {@inheritDoc} The first call to this method will populate the cache for future calls. + */ + @Override + public CaveatGroup getGroupById(String groupId) throws CaveatGroupNotFound + { + ensureCachePopulated(); + CaveatGroup caveatGroup = caveatGroups.get(groupId); + if (caveatGroup == null) + { + throw new CaveatGroupNotFound(groupId); + } + return caveatGroup; + } + + /** The first call to this method will populate the cache, subsequent calls will do nothing. */ + private void ensureCachePopulated() { if (caveatGroups == null) { caveatGroups = caveatDAO.getCaveatGroups(); } - return caveatGroups; } /** diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java index 8e9a8aa43e..6862572681 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java @@ -28,6 +28,7 @@ import java.util.Set; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; +import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.CaveatGroupNotFound; 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.caveat.scheme.CaveatGroupType; @@ -120,6 +121,22 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface return map; } + /** + * {@inheritDoc} + *

+ * This method loads all caveat groups just to return a single group. + */ + @Override + public CaveatGroup getGroupById(String groupId) + { + CaveatGroup caveatGroup = getCaveatGroups().get(groupId); + if (caveatGroup == null) + { + throw new CaveatGroupNotFound(groupId); + } + return caveatGroup; + } + /** * Create a caveat group from the supplied JSON. * diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOInterface.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOInterface.java index 6f48422949..612a246729 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOInterface.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOInterface.java @@ -20,9 +20,9 @@ package org.alfresco.module.org_alfresco_module_rm.caveat.dao; import com.google.common.collect.ImmutableMap; +import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.CaveatGroupNotFound; import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup; - /** * An object responsible for providing access to the configured caveat groups and marks. * @@ -35,4 +35,13 @@ public interface CaveatDAOInterface * Gets a map of all the available caveat groups keyed by id. */ ImmutableMap getCaveatGroups(); + + /** + * Gets the caveat group for a given id. + * + * @param groupId The group id to look up. + * @return The caveat group. + * @throws CaveatGroupNotFound if the caveat group is not found. + */ + CaveatGroup getGroupById(String groupId) throws CaveatGroupNotFound; }