From 839de8e80c227611f899cdf4da4a5cd674e5a81f Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Fri, 7 Mar 2014 11:52:25 +0000 Subject: [PATCH] Story: RM-1206 (As a records user I want to be able to add records to a hold(s) I have permission to see so that I can freeze a record) Sub-task: RM-1319 (Implement REST API for getting the holds) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@63758 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rm-webscript-context.xml | 8 + .../org/alfresco/rma/holds.get.desc.xml | 10 ++ .../org/alfresco/rma/holds.get.json.ftl | 13 ++ .../script/hold/HoldsGet.java | 157 ++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.desc.xml create mode 100644 rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.json.ftl create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldsGet.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml index 725ae4ea8f..7aa50dea2d 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml @@ -584,4 +584,12 @@ + + + + + + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.desc.xml new file mode 100644 index 0000000000..3c47734366 --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.desc.xml @@ -0,0 +1,10 @@ + + Get the list of holds + WebScript to get the list of available holds in the holds container + /api/rma/{store_type}/{store_id}/{id}/holds + /api/rma/holds + argument + user + required + internal + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.json.ftl new file mode 100644 index 0000000000..6df92865f6 --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.json.ftl @@ -0,0 +1,13 @@ +{ + "data": + { + "holds": + [ + <#list holds as hold> + { + "name": "${hold}" + }<#if hold_has_next>, + + ] + } +} \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldsGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldsGet.java new file mode 100644 index 0000000000..a4cc25ffdb --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldsGet.java @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * 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.script.hold; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; +import org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.apache.commons.lang.StringUtils; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.DeclarativeWebScript; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * Implementation for Java backed webscript to return the list of holds in the hold container. + * + * @author Tuna Aksoy + * @since 2.2 + */ +public class HoldsGet extends DeclarativeWebScript +{ + /** File Plan Service */ + private FilePlanService filePlanService; + + /** Node Service */ + private NodeService nodeService; + + /** Hold Service */ + private HoldService holdService; + + /** + * Set the file plan service + * + * @param filePlanService the file plan service + */ + public void setFilePlanService(FilePlanService filePlanService) + { + this.filePlanService = filePlanService; + } + + /** + * Set the node service + * + * @param nodeService the node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * Set the hold service + * + * @param holdService the hold service + */ + public void setHoldService(HoldService holdService) + { + this.holdService = holdService; + } + + /** + * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache) + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) + { + NodeRef filePlan = getFilePlan(req); + List holds = holdService.getHolds(filePlan); + List holdNames = new ArrayList(holds.size()); + for (NodeRef hold : holds) + { + String holdName = (String) nodeService.getProperty(hold, ContentModel.PROP_NAME); + holdNames.add(holdName); + } + + Map model = new HashMap(1); + sortByName(holdNames); + model.put("holds", holdNames); + + return model; + } + + /** + * Helper method to get the file plan + * + * @param req The webscript request + * @return The {@link NodeRef} of the file plan + */ + private NodeRef getFilePlan(WebScriptRequest req) + { + NodeRef filePlan = null; + + Map templateVars = req.getServiceMatch().getTemplateVars(); + String storeType = templateVars.get("store_type"); + String storeId = templateVars.get("store_id"); + String id = templateVars.get("id"); + + if (StringUtils.isNotBlank(storeType) && StringUtils.isNotBlank(storeId) && StringUtils.isNotBlank(id)) + { + filePlan = new NodeRef(new StoreRef(storeType, storeId), id); + } + else + { + filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID); + if (filePlan == null) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The default file plan node could not be found."); + } + } + + return filePlan; + } + + /** + * Helper method to sort the holds by their names + * + * @param holdNames List of hold names to sort + */ + private void sortByName(List holdNames) + { + Collections.sort(holdNames, new Comparator() + { + @Override + public int compare(String o1, String o2) + { + return o1.toLowerCase().compareTo(o2.toLowerCase()); + } + }); + } +}