From 31f8d362b1d07c81c2e4909a31a6da4c55c68a98 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Thu, 6 Mar 2014 22:39:54 +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-1325 (Implement Hold Service) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@63732 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rm-service-context.xml | 43 ++++- .../fileplan/hold/HoldService.java | 72 +++++++++ .../fileplan/hold/HoldServiceImpl.java | 148 ++++++++++++++++++ 3 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/hold/HoldService.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/hold/HoldServiceImpl.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index abe8d90671..27a9bf61de 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -1177,7 +1177,7 @@ - + @@ -1637,4 +1637,45 @@ --> + + + + + + + + + + org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService + + + + + + + + + + + + + + + + + + + + + + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/hold/HoldService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/hold/HoldService.java new file mode 100644 index 0000000000..6dd9e3d1a3 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/hold/HoldService.java @@ -0,0 +1,72 @@ +/* + * 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.fileplan.hold; + +import java.util.List; + +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Hold service interface. + * + * @author Tuna Aksoy + * @since 2.2 + */ +public interface HoldService +{ + /** + * Gets the list of the holds within the holds container for the given file plan + * + * @param filePlan The {@link NodeRef} of the file plan + * @return List of hold node references + */ + List getHolds(NodeRef filePlan); + + /** + * Adds the record to the given hold + * + * @param hold The {@link NodeRef} of the hold + * @param record The {@link NodeRef} of the record which will be added to the given hold + */ + void addToHoldContainer(NodeRef hold, NodeRef record); + + /** + * Adds the record to the given list of holds + * + * @param holds The list of {@link NodeRef}s of the holds + * @param record The {@link NodeRef} of the record which will be added to the given holds + */ + void addToHoldContainers(List holds, NodeRef record); + + /** + * Removes the record from the given hold + * + * @param hold The {@link NodeRef} of the hold + * @param record The {@link NodeRef} of the record which will be removed from the given hold + */ + void removeFromHoldContainer(NodeRef hold, NodeRef record); + + /** + * Removes the record from the given list of hold + * + * @param holds The list {@link NodeRef}s of the holds + * @param record The {@link NodeRef} of the record which will be removed from the given holds + */ + void removeFromHoldContainers(List holds, NodeRef record); +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/hold/HoldServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/hold/HoldServiceImpl.java new file mode 100644 index 0000000000..c0c1753581 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/hold/HoldServiceImpl.java @@ -0,0 +1,148 @@ +/* + * 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.fileplan.hold; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.ParameterCheck; + +/** + * Hold service implementation + * + * @author Tuna Aksoy + * @since 2.2 + */ +public class HoldServiceImpl implements HoldService +{ + /** File Plan Service */ + private FilePlanService filePlanService; + + /** Node Service */ + private NodeService nodeService; + + /** + * 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; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService#getHolds(org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public List getHolds(NodeRef filePlan) + { + ParameterCheck.mandatory("filePlan", filePlan); + + NodeRef holdContainer = filePlanService.getHoldContainer(filePlan); + List holdsAssocs = nodeService.getChildAssocs(holdContainer); + List holds = new ArrayList(holdsAssocs.size()); + for (ChildAssociationRef holdAssoc : holdsAssocs) + { + holds.add(holdAssoc.getChildRef()); + } + + return holds; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService#addToHoldContainer(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public void addToHoldContainer(NodeRef hold, NodeRef record) + { + ParameterCheck.mandatory("hold", hold); + ParameterCheck.mandatory("record", record); + + List holds = new ArrayList(1); + holds.add(hold); + addToHoldContainers(Collections.unmodifiableList(holds), record); + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService#addToHoldContainers(java.util.List, org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public void addToHoldContainers(List holds, NodeRef record) + { + ParameterCheck.mandatoryCollection("holds", holds); + ParameterCheck.mandatory("record", record); + + String recordName = (String) nodeService.getProperty(record, ContentModel.PROP_NAME); + String validLocalName = QName.createValidLocalName(recordName); + QName name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, validLocalName); + + for (NodeRef hold : holds) + { + nodeService.addChild(hold, record, ContentModel.ASSOC_CONTAINS, name); + } + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService#removeFromHoldContainer(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public void removeFromHoldContainer(NodeRef hold, NodeRef record) + { + ParameterCheck.mandatory("hold", hold); + ParameterCheck.mandatory("record", record); + + List holds = new ArrayList(1); + holds.add(hold); + removeFromHoldContainers(Collections.unmodifiableList(holds), record); + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService#removeFromHoldContainers(java.util.List, org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public void removeFromHoldContainers(List holds, NodeRef record) + { + ParameterCheck.mandatory("holds", holds); + ParameterCheck.mandatory("record", record); + + for (NodeRef hold : holds) + { + nodeService.removeChild(hold, record); + } + } +}