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;
}