From b47e0551cbe36e0cf680fa528f56905e2f464e70 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 22 Jul 2024 09:13:34 +0530 Subject: [PATCH] [feature/MNT-24127] EndpointToCalculateFolderSize --- .../rest/api/impl/FolderSizeImpl.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 remote-api/src/main/java/org/alfresco/rest/api/impl/FolderSizeImpl.java diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/FolderSizeImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/FolderSizeImpl.java new file mode 100644 index 0000000000..c22339d896 --- /dev/null +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/FolderSizeImpl.java @@ -0,0 +1,86 @@ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2024 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.rest.api.impl; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import lombok.AllArgsConstructor; +import org.alfresco.repo.action.executer.NodeSizeActionExecuter; +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.action.ActionTrackingService; +import org.alfresco.service.cmr.action.ExecutionDetails; +import org.alfresco.service.cmr.action.ExecutionSummary; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@AllArgsConstructor +public class FolderSizeImpl { + + private ActionService actionService; + private ActionTrackingService actionTrackingService; + private NodeService nodeService; + + private static final Logger LOG = LoggerFactory.getLogger(FolderSizeImpl.class); + + public Map executingAsynchronousFolderAction(final int maxItems, final NodeRef nodeRef, final Map result, final SimpleCache sharedCache) throws Exception + { + Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); + folderSizeAction.setTrackStatus(true); + folderSizeAction.setExecuteAsynchronously(true); + folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); + folderSizeAction.setParameterValue(NodeSizeActionExecuter.CACHE_REF, (Serializable) sharedCache); + actionService.executeAction(folderSizeAction, nodeRef, false, true); + NodeSizeActionExecuter.actionsRecords.put(folderSizeAction.getId(),folderSizeAction); + LOG.info("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); + List executionSummaryList = actionTrackingService.getExecutingActions(NodeSizeActionExecuter.NAME); + ExecutionDetails executionDetails = actionTrackingService.getExecutionDetails(executionSummaryList.get(0)); + result.putIfAbsent("executionId",folderSizeAction.getId()); + return result; + } + + public Action getAction(NodeRef nodeRef, String executionId) + { + if (this.nodeService.exists(nodeRef) == true) + { + Map actionsRecords = NodeSizeActionExecuter.actionsRecords; + List actionList = new ArrayList<>(actionsRecords.values()); + for (Action action : actionList) + { + if (action.getId().equals(executionId)) { + return action; + } + } + } + return null; + } +} \ No newline at end of file