From f973afcc14f864599a40fb8438efd0d07dfb1942 Mon Sep 17 00:00:00 2001 From: Raluca Munteanu Date: Mon, 13 Jul 2020 21:48:42 +0300 Subject: [PATCH] APPS-265: Java API Development - Create WORM Lock Action --- .../rm-action-context.xml | 25 +++++++ .../action/impl/WormAction.java | 70 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/WormAction.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml index d719d76697..c398851937 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml @@ -965,6 +965,31 @@ + + + + + + + + + + + + + + + + + org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction.*=RM_ALLOW + org.alfresco.repo.action.executer.ActionExecuter.*=RM_ALLOW + + + + + + + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/WormAction.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/WormAction.java new file mode 100644 index 0000000000..346080a3c2 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/WormAction.java @@ -0,0 +1,70 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2020 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * 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 . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.action.impl; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.repository.NodeRef; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Collections; + +/** + * Worm lock Action + */ +public class WormAction extends RMActionExecuterAbstractBase { + + private static Log logger = LogFactory.getLog(WormAction.class); + + /** + * Action name + */ + public static final String NAME = "worm"; + + /** + * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + protected void executeImpl(Action action, NodeRef actionedUponNodeRef) { + + // TODO also check if the node is already worm locked + if (getNodeService().exists(actionedUponNodeRef) && getRecordService().isRecord(actionedUponNodeRef)) { + + getNodeService().addAspect(actionedUponNodeRef, ContentModel.ASPECT_STORE_SELECTOR, Collections.emptyMap()); + // TODO: set PROP_STORE_NAME to the desired worm enabled bucket, hardcoded for now + //getNodeService().setProperty(actionedUponNodeRef, ContentModel.PROP_STORE_NAME, "cm:storeName"); + } else { + // we cannot lock a document which is not a record + if (logger.isErrorEnabled()) { + logger.error("Cannot worm lock the document, because '" + actionedUponNodeRef.toString() + "' is not a record."); + } + } + } +}