From 2f3596266b4639336481ae8a30862b07b6be418f Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 23 Jul 2024 15:46:09 +0530 Subject: [PATCH] [feature/MNT-24127] Endpoint Added To Calculate Folder Size --- .../org/alfresco/rest/api/impl/FolderSizeImpl.java | 2 +- .../rest/api/nodes/NodeFolderSizeRelation.java | 13 +++++-------- .../rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) 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 index 6187be5812b..131e0e248f8 100644 --- 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 @@ -43,7 +43,7 @@ public class FolderSizeImpl { private ActionService actionService; private static final Logger LOG = LoggerFactory.getLogger(FolderSizeImpl.class); - public Map executingAsynchronousFolderAction(final int maxItems, final NodeRef nodeRef, final Map result, final SimpleCache simpleCache) throws Exception + public Map executingAsynchronousFolderAction(final int maxItems, final NodeRef nodeRef, final Map result, final SimpleCache simpleCache) { Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); folderSizeAction.setTrackStatus(true); diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java index eb5e59bee91..35ad51726b7 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java @@ -75,10 +75,7 @@ public class NodeFolderSizeRelation implements CalculateSize private NodeService nodeService; private ActionService actionService; private ActionTrackingService actionTrackingService; - private FolderSizeImpl folderSizeImpl; - private NodeRef nodeRef; private String invalidMessage = "Invalid parameter: value of nodeId is invalid"; - private String notFoundMessage = "Searched ExecutionId does not exist"; /** the simple cache that will hold action data */ @@ -150,7 +147,7 @@ public void setSimpleCache(SimpleCache simpleCache) @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder", successStatus = Status.STATUS_ACCEPTED) public Map createById(String nodeId, Parameters params) { - nodeRef = nodes.validateNode(nodeId); + NodeRef nodeRef = nodes.validateNode(nodeId); int maxItems = Math.min(params.getPaging().getMaxItems(), 1000); QName qName = nodeService.getType(nodeRef); Map result = new HashMap<>(); @@ -164,13 +161,13 @@ public Map createById(String nodeId, Parameters params) try { - this.folderSizeImpl = new FolderSizeImpl(actionService); - return this.folderSizeImpl.executingAsynchronousFolderAction(maxItems, nodeRef, result, simpleCache); + FolderSizeImpl folderSizeImpl = new FolderSizeImpl(actionService); + return folderSizeImpl.executingAsynchronousFolderAction(maxItems, nodeRef, result, simpleCache); } catch (Exception ex) { LOG.error("Exception occurred in NodeFolderSizeRelation:createById {}", ex.getMessage()); - throw new AlfrescoRuntimeException("Exception occurred in NodeFolderSizeRelation:createById"); + throw new AlfrescoRuntimeException("Exception occurred in NodeFolderSizeRelation:createById",ex); } } @@ -179,7 +176,7 @@ public Map createById(String nodeId, Parameters params) @WebApiParameters({@WebApiParam(name = "executionId", title = "The unique id of Execution Job", description = "A single execution id")}) public Map readById(String executionId, String id, Parameters parameters) { - Map result = new HashMap<>(); + Map result; try { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java index 1c42194b604..b444bd96122 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java @@ -158,7 +158,7 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - executionId = executionId.substring(executionId.indexOf("=") + 1,executionId.indexOf("}")); + executionId = executionId.substring(executionId.indexOf('=') + 1,executionId.indexOf('}')); HttpResponse response = getSingle(getFolderSizeUrl(executionId), null, 200); assertNotNull(response);