mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
@@ -16,9 +16,12 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String, CaveatGroup> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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}
|
||||
* <p>
|
||||
* 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.
|
||||
*
|
||||
|
@@ -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<String, CaveatGroup> 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user