RM-1330 (Implement REST API for getting the hold(s) for a given node)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@63826 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2014-03-10 11:07:41 +00:00
parent e77273f7b4
commit 8633c30242
11 changed files with 80 additions and 28 deletions

View File

@@ -31,12 +31,20 @@ import org.alfresco.service.cmr.repository.NodeRef;
public interface HoldService
{
/**
* Gets the list of the holds within the holds container for the given file plan
* Gets the list of all the holds within the holds container in the given file plan
*
* @param filePlan The {@link NodeRef} of the file plan
* @return List of hold node references
*/
List<NodeRef> getHolds(NodeRef filePlan);
List<NodeRef> getHoldsInFilePlan(NodeRef filePlan);
/**
* Gets the list of all the holds within the holds container for the given node reference
*
* @param nodeRef The {@link NodeRef} of the record / record folder which will be in the retrieved list of hold(s)
* @return List of hold node references which has the node reference of the given record / record folder in it
*/
List<NodeRef> getHoldsForItem(NodeRef nodeRef);
/**
* Adds the record to the given hold

View File

@@ -105,22 +105,37 @@ public class HoldServiceImpl implements HoldService, RecordsManagementModel
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService#getHolds(org.alfresco.service.cmr.repository.NodeRef)
* @see org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService#getHoldsInFilePlan(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public List<NodeRef> getHolds(NodeRef filePlan)
public List<NodeRef> getHoldsInFilePlan(NodeRef filePlan)
{
ParameterCheck.mandatory("filePlan", filePlan);
NodeRef holdContainer = filePlanService.getHoldContainer(filePlan);
List<ChildAssociationRef> holdsAssocs = nodeService.getChildAssocs(holdContainer, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
List<NodeRef> holds = new ArrayList<NodeRef>(holdsAssocs.size());
if (holdsAssocs != null && !holdsAssocs.isEmpty())
for (ChildAssociationRef holdAssoc : holdsAssocs)
{
for (ChildAssociationRef holdAssoc : holdsAssocs)
{
holds.add(holdAssoc.getChildRef());
}
holds.add(holdAssoc.getChildRef());
}
return holds;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService#getHoldsForItem(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public List<NodeRef> getHoldsForItem(NodeRef nodeRef)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
List<ChildAssociationRef> holdsAssocs = nodeService.getParentAssocs(nodeRef, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
List<NodeRef> holds = new ArrayList<NodeRef>(holdsAssocs.size());
for (ChildAssociationRef holdAssoc : holdsAssocs)
{
holds.add(holdAssoc.getParentRef());
}
return holds;

View File

@@ -149,7 +149,7 @@ public interface FreezeService
* @param filePlan file plan for which the hold nodes will be retrieved
* @return Set<NodeRef> hold node references
*
* @deprecated as of 2.2, use {@link HoldService#getHolds(NodeRef)} instead
* @deprecated as of 2.2, use {@link HoldService#getHoldsInFilePlan(NodeRef)} instead
*/
@Deprecated
Set<NodeRef> getHolds(NodeRef filePlan);

View File

@@ -381,7 +381,7 @@ public class FreezeServiceImpl extends ServiceBaseImpl
{
ParameterCheck.mandatory("filePlan", filePlan);
return new HashSet<NodeRef>(holdService.getHolds(filePlan));
return new HashSet<NodeRef>(holdService.getHoldsInFilePlan(filePlan));
}
/**

View File

@@ -92,7 +92,18 @@ public class HoldsGet extends DeclarativeWebScript
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef filePlan = getFilePlan(req);
List<NodeRef> holds = holdService.getHolds(filePlan);
NodeRef itemNodeRef = getItemNodeRef(req);
List<NodeRef> holds = new ArrayList<NodeRef>();
if (itemNodeRef == null)
{
holds.addAll(holdService.getHoldsInFilePlan(filePlan));
}
else
{
holds.addAll(holdService.getHoldsForItem(itemNodeRef));
}
List<String> holdNames = new ArrayList<String>(holds.size());
for (NodeRef hold : holds)
{
@@ -138,6 +149,23 @@ public class HoldsGet extends DeclarativeWebScript
return filePlan;
}
/**
* Helper method to get the item node reference
*
* @param req The webscript request
* @return The {@link NodeRef} of the item (record / record folder) or null if the parameter has not been passed
*/
private NodeRef getItemNodeRef(WebScriptRequest req)
{
String nodeRef = req.getParameter("itemNodeRef");
NodeRef itemNodeRef = null;
if (StringUtils.isNotBlank(nodeRef))
{
itemNodeRef = new NodeRef(nodeRef);
}
return itemNodeRef;
}
/**
* Helper method to sort the holds by their names
*