From 37ae98e2530988405432043d825423b10d8f2d68 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 18 Jun 2024 17:05:52 +0530 Subject: [PATCH 001/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 196 ++++++++++++++++++ .../framework/core/ResourceInspector.java | 3 + .../RelationshipResourceAction.java | 11 + .../webscripts/ResourceWebScriptGet.java | 10 + .../webscripts/ResourceWebScriptPost.java | 14 ++ .../alfresco/public-rest-context.xml | 8 + .../org/alfresco/AppContext02TestSuite.java | 1 + .../rest/api/tests/AbstractBaseApiTest.java | 6 + .../rest/api/tests/NodeFolderSizeApiTest.java | 96 +++++++++ .../framework/tests/core/InspectorTests.java | 12 ++ .../org/alfresco/model/FolderSizeModel.java | 39 ++++ .../executer/NodeSizeActionExecuter.java | 160 ++++++++++++++ .../alfresco/action-services-context.xml | 5 + .../org/alfresco/AppContext01TestSuite.java | 3 +- .../executer/NodeSizeActionExecuterTest.java | 118 +++++++++++ 15 files changed, 681 insertions(+), 1 deletion(-) create mode 100644 remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java create mode 100644 remote-api/src/test/java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java create mode 100644 repository/src/main/java/org/alfresco/model/FolderSizeModel.java create mode 100644 repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java create mode 100644 repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java 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 new file mode 100644 index 00000000000..bf5ec930536 --- /dev/null +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java @@ -0,0 +1,196 @@ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 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.nodes; + +import org.alfresco.model.FolderSizeModel; +import org.alfresco.repo.action.executer.NodeSizeActionExecuter; +import org.alfresco.repo.security.permissions.AccessDeniedException; +import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.model.Node; +import org.alfresco.rest.api.model.NodePermissions; +import org.alfresco.rest.framework.WebApiDescription; +import org.alfresco.rest.framework.WebApiParam; +import org.alfresco.rest.framework.WebApiParameters; +import org.alfresco.rest.framework.resource.RelationshipResource; +import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; +import org.alfresco.rest.framework.resource.parameters.Parameters; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.ParameterCheck; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.extensions.webscripts.Status; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +/** + * Node Size + * + * - get folder size + * + */ +@RelationshipResource(name = "calculateSize", entityResource = NodesEntityResource.class, title = "Calculate size") +public class NodeFolderSizeRelation implements + RelationshipResourceAction.CalculateSize>, + RelationshipResourceAction.ReadById>, + InitializingBean { + + private Nodes nodes; + private SearchService searchService; + private ServiceRegistry serviceRegistry; + private PermissionService permissionService; + private NodeService nodeService; + private ActionService actionService; + + /** + * The logger + */ + private static Log logger = LogFactory.getLog(NodeFolderSizeRelation.class); + + /** + * The class that wraps the ReST APIs from core. + */ + + public void setNodes(Nodes nodes) { + this.nodes = nodes; + } + + public void setSearchService(SearchService searchService) { + this.searchService = searchService; + } + + public void setServiceRegistry(ServiceRegistry serviceRegistry) { + this.serviceRegistry = serviceRegistry; + this.permissionService = serviceRegistry.getPermissionService(); + } + + public void setNodeService(NodeService nodeService) { + this.nodeService = nodeService; + } + + public void setActionService(ActionService actionService) { + this.actionService = actionService; + } + + @Override + public void afterPropertiesSet() { + ParameterCheck.mandatory("nodes", this.nodes); + } + + /** + * Folder Size - returns size of a folder. + * + * @param nodeId String id of folder - will also accept well-known alias, eg. -root- or -my- or -shared- + * Please refer to OpenAPI spec for more details ! + *

+ * If NodeId does not exist, EntityNotFoundException (status 404). + */ + @Override + @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder/file", successStatus = Status.STATUS_ACCEPTED) + public Map createById(String nodeId, Parameters params) { + + NodeRef nodeRef = nodes.validateNode(nodeId); + Node nodeInfo = nodes.getNode(nodeId); + NodePermissions nodePerms = nodeInfo.getPermissions(); + int maxItems = params.getPaging().getMaxItems(); + + if (nodePerms != null) { + if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { + throw new AccessDeniedException("permissions.err_access_denied"); + } + } + + try + { + Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); + folderSizeAction.setTrackStatus(true); + folderSizeAction.setExecuteAsynchronously(true); + folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); + actionService.executeAction(folderSizeAction, nodeRef, false, true); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "IN-PROGRESS"); + Map result = new HashMap<>(); + result.put("executionId", nodeId); + return result; + } + catch (Exception ex) + { + logger.error("Exception occured in NodeFolderSizeRelation:createById "+ex.getMessage()); + } + return null; + } + + @Override + @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") + @WebApiParameters({ + @WebApiParam(name = "nodeId", title = "The unique id of the Node being addressed", description = "A single node id")}) + public Map readById(String nodeId, String id, Parameters parameters) + { + NodeRef nodeRef = nodes.validateNode(nodeId); + Node nodeInfo = nodes.getNode(nodeId); + NodePermissions nodePerms = nodeInfo.getPermissions(); + + if (nodePerms != null) { + if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { + throw new AccessDeniedException("permissions.err_access_denied"); + } + } + + try + { + Map properties = nodeService.getProperties(nodeRef); + Map result = new HashMap<>(); + + if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { + result.put("status", "NOT INITIATED"); + } else { + String status = (String) properties.get(FolderSizeModel.PROP_STATUS); + if ("IN-PROGRESS".equals(status)) { + result.put("status", status); + } else { + Map mapResult = (Map) properties.get(FolderSizeModel.PROP_OUTPUT); + mapResult.put("status", status); + result = mapResult; + } + } + return result; + } + catch (Exception ex) + { + logger.error("Exception occured in NodeFolderSizeRelation:readById "+ex.getMessage()); + } + return null; + } +} \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index 146450667e9..c1f961240f0 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -126,6 +126,8 @@ public class ResourceInspector ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(MultiPartRelationshipResourceAction.Create.class); + ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.CalculateSize.class); + ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Read.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Delete.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Update.class); @@ -291,6 +293,7 @@ private static List inspectRelationship(RelationshipResource a findOperation(RelationshipResourceAction.DeleteSetWithResponse.class, DELETE, helper); findOperation(MultiPartRelationshipResourceAction.Create.class, POST, helper); + findOperation(RelationshipResourceAction.CalculateSize.class, POST, helper); boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java index 071641503fc..120eacdc0e3 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java @@ -163,4 +163,15 @@ public static interface DeleteSetWithResponse extends ResourceAction */ public void deleteSet(String entityResourceId, Parameters params, WithResponse withResponse); } + + interface CalculateSize extends ResourceAction + { + /** + * Calculate the size of Folder/File. + * + * @param nodeId Entity resource context for this relationship. + * @param params implementation may choose to restrict the set to be deleted based on params (ie. not necessarily "all") + */ + E createById(String nodeId,Parameters params); + } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 87ee84c074f..50afa9ad8d4 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -238,6 +238,16 @@ else if (EntityResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resour CollectionWithPagingInfo relations = relationGetter.readAll(params.getEntityId(),params); return relations; } + else if (RelationshipResourceAction.ReadById.class.isAssignableFrom(resource.getResource().getClass())) + { + if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadById.class)) + { + throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId()); + } + RelationshipResourceAction.ReadById relationGetter = (RelationshipResourceAction.ReadById) resource.getResource(); + Object result = relationGetter.readById(params.getEntityId(), params.getRelationshipId(), params); + return result; + } else { if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadWithResponse.class)) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java index 1d3500a5961..29cbe4b5c33 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java @@ -109,6 +109,10 @@ else if (StringUtils.isNotBlank(relationshipId)) { throw new UnsupportedResourceOperationException("POST is executed against a collection URL"); } + else if ("calculateSize".equals(operationName)) + { + return Params.valueOf(entityId, params, "", req); + } else { Object postedRel = processRequest(resourceMeta, operation, req); @@ -366,6 +370,16 @@ public Object executeAction(ResourceWithMetadata resource, Params params, WithRe return wrapWithCollectionWithPaging(createdRel); } } + else if (RelationshipResourceAction.CalculateSize.class.isAssignableFrom(resource.getResource().getClass())) + { + if (resource.getMetaData().isDeleted(RelationshipResourceAction.CalculateSize.class)) + { + throw new DeletedResourceException("(GET by id) " + resource.getMetaData().getUniqueId()); + } + RelationshipResourceAction.CalculateSize relationGetter = (RelationshipResourceAction.CalculateSize) resource.getResource(); + Object result = relationGetter.createById(params.getEntityId(),params); + return result; + } } case OPERATION: return executeOperation(resource, params, withResponse); diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index f5627ad8239..f87a8fd513b 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1768,4 +1768,12 @@ + + + + + + + + diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 4756d0958b8..ed6748a6863 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -76,6 +76,7 @@ org.alfresco.rest.api.tests.BufferedResponseTest.class, org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, + org.alfresco.rest.api.tests.NodeFolderSizeApiTest.class }) public class AppContext02TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index 4c233ffea9b..ce3bb6e2a7e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -105,6 +105,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi private static final String URL_CHILDREN = "children"; private static final String URL_CONTENT = "content"; + private static final String URL_CALCULATESIZE = "calculateSize"; protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; @@ -1120,5 +1121,10 @@ protected void disableRestDirectAccessUrls() RestApiDirectUrlConfig restDauConfig = (RestApiDirectUrlConfig) applicationContext.getBean("restApiDirectUrlConfig"); restDauConfig.setEnabled(false); } + + protected String getFolderSizeUrl(String nodeId) + { + return URL_NODES + "/" + nodeId + "/" + URL_CALCULATESIZE; + } } 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 new file mode 100644 index 00000000000..d3db0fe4755 --- /dev/null +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java @@ -0,0 +1,96 @@ +/* + * #%L + * Alfresco Remote API + * %% + * 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.rest.api.tests; + +import org.alfresco.rest.api.model.Site; +import org.alfresco.rest.api.tests.client.HttpResponse; +import org.alfresco.rest.api.tests.util.RestApiUtil; +import org.alfresco.service.cmr.site.SiteVisibility; +import org.junit.After; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; +import static org.junit.Assert.assertNotNull; + +/** + * V1 REST API tests for Folder size + * + * @author Mohit Singh + */ +public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ + + /** + * Private site of user one from network one. + */ + private Site userOneN1Site; + + private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception + { + String parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); + return createNode(parentId, name, nodeType, null).getId(); + } + + /** + * Tests Folder Size Calculation + *

POST:

+ * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} + */ + @Test + public void testCalculateFolderSize() throws Exception + { + setRequestContext(user1); + + String siteTitle = "RandomSite" + System.currentTimeMillis(); + userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + + // Create a folder within the site document's library. + String folderName = "folder" + System.currentTimeMillis(); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT, user1); + + Map params = new HashMap<>(); + params.put("nodeId",folderId); + params.put("maxItems","100"); + + HttpResponse response = post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); + String contentNodeId = document.toString(); + assertNotNull(contentNodeId); + } + + @After + public void tearDown() throws Exception + { + deleteSite(userOneN1Site.getId(), true, 204); + } + + @Override + public String getScope() { + return "public"; + } +} diff --git a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java index 646bae13b8c..9b4d78fa1dd 100644 --- a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java +++ b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java @@ -41,6 +41,7 @@ import org.alfresco.rest.api.model.Comment; import org.alfresco.rest.api.nodes.NodeCommentsRelation; +import org.alfresco.rest.api.nodes.NodeFolderSizeRelation; import org.alfresco.rest.framework.Api; import org.alfresco.rest.framework.core.OperationResourceMetaData; import org.alfresco.rest.framework.core.ResourceInspector; @@ -642,4 +643,15 @@ public void testValidSuccessCode() assertEquals(Status.STATUS_ACCEPTED,ResourceInspector.validSuccessCode(HttpMethod.PUT, Status.STATUS_ACCEPTED)); assertEquals(Status.STATUS_NOT_MODIFIED,ResourceInspector.validSuccessCode(HttpMethod.DELETE, Status.STATUS_NOT_MODIFIED)); } + + @Test + public void testCalculateSizeRelation() + { + List metainfo = ResourceInspector.inspect(NodeFolderSizeRelation.class); + assertTrue("Must be one ResourceMetadata",metainfo.size()>0); + ResourceMetadata metaData = metainfo.get(0); + assertNotNull(metaData); + ResourceOperation op = metaData.getOperation(HttpMethod.POST); + assertNotNull("NodeFolderSizeRelation supports POST", op); + } } diff --git a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java new file mode 100644 index 00000000000..889a7cdddb7 --- /dev/null +++ b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java @@ -0,0 +1,39 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 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.model; + +import org.alfresco.api.AlfrescoPublicApi; +import org.alfresco.service.namespace.QName; + +@AlfrescoPublicApi +public interface FolderSizeModel { + + /** Folder Model URI */ + static final String SIZE_MODEL_1_0_URI = "http://www.alfresco.org/model/size/1.0"; + + static final QName PROP_STATUS = QName.createQName(SIZE_MODEL_1_0_URI, "status"); + static final QName PROP_OUTPUT = QName.createQName(SIZE_MODEL_1_0_URI, "result"); +} diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java new file mode 100644 index 00000000000..4c0c9df9b65 --- /dev/null +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -0,0 +1,160 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 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.repo.action.executer; + +import org.alfresco.model.ContentModel; +import org.alfresco.model.FolderSizeModel; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.search.ResultSet; +import org.alfresco.service.cmr.search.SearchParameters; +import org.alfresco.service.cmr.search.SearchService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.Serializable; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class NodeSizeActionExecuter extends ActionExecuterAbstractBase +{ + /** + * Action constants + */ + public static final String NAME = "folder-size"; + public static final String PAGE_SIZE = "page-size"; + + /** + * The node service + */ + private NodeService nodeService; + private SearchService searchService; + + /** + * The logger + */ + private static Log logger = LogFactory.getLog(NodeSizeActionExecuter.class); + + /** + * Set the node service + * + * @param nodeService the node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * Set the search service + * + * @param searchService the search service + */ + public void setSearchService(SearchService searchService) { + this.searchService = searchService; + } + + /** + * @see ActionExecuter#execute(Action, NodeRef) + */ + public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) + { + Serializable serializable = ruleAction.getParameterValue(NodeSizeActionExecuter.PAGE_SIZE); + int maxItems = Integer.parseInt(serializable.toString()); + int skipCount = 0; + int totalItems = maxItems; + NodeRef nodeRef = actionedUponNodeRef; + long totalSize = 0; + long resultSize; + ResultSet results =null; + + StringBuilder aftsQuery = new StringBuilder(); + aftsQuery.append("ANCESTOR:\""+nodeRef+"\" AND TYPE:content"); + String query = aftsQuery.toString(); + + SearchParameters searchParameters = new SearchParameters(); + searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); + searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); + searchParameters.setQuery(query.toString()); + + try{ + // executing Alfresco FTS query. + results = searchService.query(searchParameters); + + while(true) { + + if (results.getNodeRefs().size() < maxItems) + totalItems = results.getNodeRefs().size(); + + resultSize = results.getNodeRefs().subList(skipCount,totalItems).parallelStream() + .map(id -> ((ContentData) nodeService.getProperty(id, ContentModel.PROP_CONTENT)).getSize()) + .reduce(0L, Long::sum); + + totalSize+=resultSize; + + if (results.getNodeRefs().size() <= totalItems || results.getNodeRefs().size() <= maxItems) + break; + + if (results.getNodeRefs().size() > maxItems) { + skipCount += maxItems; + totalItems += maxItems; + } + } + + } + catch (RuntimeException ex) + { + logger.error("Exception occured in NodeSizeActionExecutor:results "+ex.getMessage()); + } + + final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); + String formattedTimestamp = eventTimestamp.format(formatter); + Map response = new HashMap<>(); + response.put("id", nodeRef.getId()); + response.put("size", totalSize); + response.put("calculatedAtTime", formattedTimestamp); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) response); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS,"COMPLETED"); + } + + /** + * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(List) + */ + @Override + protected void addParameterDefinitions(List paramList) + { + } +} diff --git a/repository/src/main/resources/alfresco/action-services-context.xml b/repository/src/main/resources/alfresco/action-services-context.xml index 632f0707bef..e9d179d9b89 100644 --- a/repository/src/main/resources/alfresco/action-services-context.xml +++ b/repository/src/main/resources/alfresco/action-services-context.xml @@ -788,5 +788,10 @@ + + + + + diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index 277bb60627c..aa9e4e3a210 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -76,7 +76,8 @@ org.alfresco.repo.activities.SiteActivityTestCaseSensitivity.class, org.alfresco.repo.activities.feed.cleanup.FeedCleanerTestCaseSensitivity.class, org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, - org.alfresco.repo.admin.registry.RegistryServiceImplTest.class + org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, + org.alfresco.repo.action.executer.NodeSizeActionExecuterTest.class }) public class AppContext01TestSuite { diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java new file mode 100644 index 00000000000..daeacb6e284 --- /dev/null +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -0,0 +1,118 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 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.repo.action.executer; + + +import org.alfresco.model.ContentModel; +import org.alfresco.model.FolderSizeModel; +import org.alfresco.repo.action.ActionImpl; +import org.alfresco.repo.security.authentication.AuthenticationComponent; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.BaseSpringTest; +import org.alfresco.util.GUID; +import org.junit.Before; +import org.junit.Test; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +public class NodeSizeActionExecuterTest extends BaseSpringTest +{ + /** + * The node service + */ + private NodeService nodeService; + + /** + * The store reference + */ + private StoreRef testStoreRef; + + /** + * The root node reference + */ + private NodeRef rootNodeRef; + + /** + * The test node reference + */ + private NodeRef nodeRef; + + /** + * The folder Size executer + */ + private NodeSizeActionExecuter executer; + + /** + * Id used to identify the test action created + */ + private final static String ID = GUID.generate(); + + /** + * Called at the begining of all tests + */ + @Before + public void before() throws Exception + { + this.nodeService = (NodeService)this.applicationContext.getBean("nodeService"); + + AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent"); + authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); + + // Create the store and get the root node + this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + + System.currentTimeMillis()); + this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef); + + // Create the node used for tests + this.nodeRef = this.nodeService.createNode( + this.rootNodeRef, + ContentModel.ASSOC_CHILDREN, + QName.createQName("{test}testnode"), + ContentModel.TYPE_CONTENT).getChildRef(); + + // Get the executer instance + this.executer = (NodeSizeActionExecuter)this.applicationContext.getBean(NodeSizeActionExecuter.NAME); + } + + /** + * Test execution + */ + @Test + public void testExecution() + { + assertEquals(1,1); + int maxItems = 100; + // Execute the action + ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null); + action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); + this.executer.executeImpl(action, this.nodeRef); + String compareString = this.nodeService.getProperty(this.nodeRef, FolderSizeModel.PROP_STATUS).toString(); + assertTrue(compareString!=null?true:false); + } +} From b69487c9bba5d4575f1a4fd215074df003f9def3 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 19 Jun 2024 08:58:59 +0530 Subject: [PATCH 002/267] [MNT-24127] Added Endpoint to calculate folder size with test cases [ags][tas] --- .../repo/action/executer/NodeSizeActionExecuter.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 4c0c9df9b65..45ea4029cb1 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -98,7 +98,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) NodeRef nodeRef = actionedUponNodeRef; long totalSize = 0; long resultSize; - ResultSet results =null; + ResultSet results = null; StringBuilder aftsQuery = new StringBuilder(); aftsQuery.append("ANCESTOR:\""+nodeRef+"\" AND TYPE:content"); @@ -129,10 +129,13 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) if (results.getNodeRefs().size() > maxItems) { skipCount += maxItems; - totalItems += maxItems; + int remainingItems = (results.getNodeRefs().size()-totalItems); + if(remainingItems > maxItems) + totalItems += maxItems; + else + totalItems += remainingItems; } } - } catch (RuntimeException ex) { From 53cc9c4eeede46f6430e4024475df43130bd0cca Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 14:26:10 +0530 Subject: [PATCH 003/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 6 +-- .../rest/api/tests/NodeFolderSizeApiTest.java | 37 ++++++++++++++++++- 2 files changed, 38 insertions(+), 5 deletions(-) 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 bf5ec930536..2c95fc844a8 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 @@ -25,6 +25,7 @@ */ package org.alfresco.rest.api.nodes; +import org.alfresco.model.ContentModel; import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.executer.NodeSizeActionExecuter; import org.alfresco.repo.security.permissions.AccessDeniedException; @@ -53,8 +54,7 @@ import org.springframework.extensions.webscripts.Status; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * Node Size @@ -123,6 +123,7 @@ public void afterPropertiesSet() { public Map createById(String nodeId, Parameters params) { NodeRef nodeRef = nodes.validateNode(nodeId); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "IN-PROGRESS"); Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); int maxItems = params.getPaging().getMaxItems(); @@ -140,7 +141,6 @@ public Map createById(String nodeId, Parameters params) { folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); actionService.executeAction(folderSizeAction, nodeRef, false, true); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "IN-PROGRESS"); Map result = new HashMap<>(); result.put("executionId", nodeId); return result; 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 d3db0fe4755..8fa61dcc002 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 @@ -46,10 +46,12 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ /** - * Private site of user one from network one. + * Private site of user two from network one. */ private Site userOneN1Site; + private Site userOneN2Site; + private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception { String parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); @@ -62,7 +64,7 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType, * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} */ @Test - public void testCalculateFolderSize() throws Exception + public void testPostCalculateFolderSize() throws Exception { setRequestContext(user1); @@ -81,12 +83,43 @@ public void testCalculateFolderSize() throws Exception Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); String contentNodeId = document.toString(); assertNotNull(contentNodeId); + + // -ve test - unknown nodeId + delete(getFolderSizeUrl(folderId), folderId, null, 404); + + // -ve test - unauthenticated. + delete(getFolderSizeUrl(folderId), folderId, null, 401); + + // -ve test - permission denied (on version other than most recent) + delete(getFolderSizeUrl(folderId), folderId, null, 403); + } + + @Test + public void testGetCalculateFolderSize() throws Exception + { + setRequestContext(user1); + + String siteTitle = "RandomSite" + System.currentTimeMillis(); + userOneN2Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + + // Create a folder within the site document's library. + String folderName = "folder" + System.currentTimeMillis(); + String folderId = addToDocumentLibrary(userOneN2Site, folderName, TYPE_CM_CONTENT, user1); + + Map params = new HashMap<>(); + params.put("nodeId",folderId); + + HttpResponse response = getSingle(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); + Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); + String contentNodeId = document.toString(); + assertNotNull(contentNodeId); } @After public void tearDown() throws Exception { deleteSite(userOneN1Site.getId(), true, 204); + deleteSite(userOneN2Site.getId(), true, 204); } @Override From 490ec6ec081a5fc82da91133989e6361fdf65e3e Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 15:12:35 +0530 Subject: [PATCH 004/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) 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 8fa61dcc002..289e0952cf1 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 @@ -83,15 +83,6 @@ public void testPostCalculateFolderSize() throws Exception Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); String contentNodeId = document.toString(); assertNotNull(contentNodeId); - - // -ve test - unknown nodeId - delete(getFolderSizeUrl(folderId), folderId, null, 404); - - // -ve test - unauthenticated. - delete(getFolderSizeUrl(folderId), folderId, null, 401); - - // -ve test - permission denied (on version other than most recent) - delete(getFolderSizeUrl(folderId), folderId, null, 403); } @Test @@ -109,7 +100,7 @@ public void testGetCalculateFolderSize() throws Exception Map params = new HashMap<>(); params.put("nodeId",folderId); - HttpResponse response = getSingle(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); + HttpResponse response = get(getFolderSizeUrl(folderId), params, 200); Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); String contentNodeId = document.toString(); assertNotNull(contentNodeId); From 202c99a99bfa52eafb3f005055b326874985cdc6 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 15:58:47 +0530 Subject: [PATCH 005/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 289e0952cf1..d547edf0c02 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 @@ -28,6 +28,7 @@ import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.util.RestApiUtil; +import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; import org.junit.After; import org.junit.Test; @@ -91,16 +92,19 @@ public void testGetCalculateFolderSize() throws Exception setRequestContext(user1); String siteTitle = "RandomSite" + System.currentTimeMillis(); - userOneN2Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN2Site, folderName, TYPE_CM_CONTENT, user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT, user1); Map params = new HashMap<>(); params.put("nodeId",folderId); - HttpResponse response = get(getFolderSizeUrl(folderId), params, 200); + AuthenticationUtil.setFullyAuthenticatedUser(user1); + permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderId), user1, PermissionService.ALL_PERMISSIONS, true); + + HttpResponse response = getSingle(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); String contentNodeId = document.toString(); assertNotNull(contentNodeId); From e6f13528d9db103f30b12b1e953d88ccaa1a495f Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 16:05:17 +0530 Subject: [PATCH 006/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 d547edf0c02..7dcece378ce 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 @@ -25,9 +25,12 @@ */ package org.alfresco.rest.api.tests; +import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.util.RestApiUtil; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; import org.junit.After; @@ -51,7 +54,7 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ */ private Site userOneN1Site; - private Site userOneN2Site; + private PermissionService permissionService; private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception { @@ -102,6 +105,7 @@ public void testGetCalculateFolderSize() throws Exception params.put("nodeId",folderId); AuthenticationUtil.setFullyAuthenticatedUser(user1); + permissionService = applicationContext.getBean("permissionService", PermissionService.class); permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderId), user1, PermissionService.ALL_PERMISSIONS, true); HttpResponse response = getSingle(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); @@ -114,7 +118,6 @@ public void testGetCalculateFolderSize() throws Exception public void tearDown() throws Exception { deleteSite(userOneN1Site.getId(), true, 204); - deleteSite(userOneN2Site.getId(), true, 204); } @Override From 7c298e6f35f56452e3a9c6c1fefee3f98c7b3a05 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 16:31:55 +0530 Subject: [PATCH 007/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 3 --- 1 file changed, 3 deletions(-) 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 7dcece378ce..0e99dcf4886 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 @@ -29,8 +29,6 @@ import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.util.RestApiUtil; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; import org.junit.After; @@ -106,7 +104,6 @@ public void testGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); permissionService = applicationContext.getBean("permissionService", PermissionService.class); - permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderId), user1, PermissionService.ALL_PERMISSIONS, true); HttpResponse response = getSingle(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); From 76da68d205e39dc4bf3427fadd0ccda2aba1e32c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 17:04:07 +0530 Subject: [PATCH 008/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0e99dcf4886..547df563800 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 @@ -105,7 +105,7 @@ public void testGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); permissionService = applicationContext.getBean("permissionService", PermissionService.class); - HttpResponse response = getSingle(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); + HttpResponse response = getSingle(getFolderSizeUrl(folderId), null, 200); Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); String contentNodeId = document.toString(); assertNotNull(contentNodeId); From 368cebde9e12d4a8a2d28d89dac6f09f13299e67 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 21:03:41 +0530 Subject: [PATCH 009/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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 547df563800..171462c67d9 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 @@ -52,8 +52,6 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ */ private Site userOneN1Site; - private PermissionService permissionService; - private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception { String parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); @@ -103,7 +101,6 @@ public void testGetCalculateFolderSize() throws Exception params.put("nodeId",folderId); AuthenticationUtil.setFullyAuthenticatedUser(user1); - permissionService = applicationContext.getBean("permissionService", PermissionService.class); HttpResponse response = getSingle(getFolderSizeUrl(folderId), null, 200); Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); @@ -111,6 +108,27 @@ public void testGetCalculateFolderSize() throws Exception assertNotNull(contentNodeId); } + @Test + public void testHTTPStatus() throws Exception + { + + setRequestContext(user1); + + String siteTitle = "RandomSite" + System.currentTimeMillis(); + userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + + // Create a folder within the site document's library. + String folderName = "folder" + System.currentTimeMillis(); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT, user1); + + setRequestContext(null); + delete(getFolderSizeUrl(folderId), folderId, null, 401); + + setRequestContext(user1); + delete(getFolderSizeUrl(folderId), folderId, null, 404); + delete(getFolderSizeUrl(folderId), folderId, null, 403); + } + @After public void tearDown() throws Exception { From cf97c3a3ef0ab91a165a48255a342ca20b8daefe Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 21:36:59 +0530 Subject: [PATCH 010/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 171462c67d9..08246833a66 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 @@ -125,7 +125,8 @@ public void testHTTPStatus() throws Exception delete(getFolderSizeUrl(folderId), folderId, null, 401); setRequestContext(user1); - delete(getFolderSizeUrl(folderId), folderId, null, 404); + delete(getFolderSizeUrl(folderId), "dummy", null, 404); + AuthenticationUtil.clearCurrentSecurityContext(); delete(getFolderSizeUrl(folderId), folderId, null, 403); } From 087fbba598a78dc52d8a847401738ca0fa77149c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 22:19:51 +0530 Subject: [PATCH 011/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 08246833a66..a59662ef30c 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 @@ -26,6 +26,7 @@ package org.alfresco.rest.api.tests; import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.util.RestApiUtil; @@ -36,6 +37,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.UUID; import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; import static org.junit.Assert.assertNotNull; @@ -116,6 +118,7 @@ public void testHTTPStatus() throws Exception String siteTitle = "RandomSite" + System.currentTimeMillis(); userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + String rootNodeId = getRootNodeId(); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); @@ -125,9 +128,13 @@ public void testHTTPStatus() throws Exception delete(getFolderSizeUrl(folderId), folderId, null, 401); setRequestContext(user1); - delete(getFolderSizeUrl(folderId), "dummy", null, 404); - AuthenticationUtil.clearCurrentSecurityContext(); - delete(getFolderSizeUrl(folderId), folderId, null, 403); + NodeTarget tgt = new NodeTarget(); + tgt.setTargetParentId(UUID.randomUUID().toString()); + post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(tgt), null, 404); + + tgt = new NodeTarget(); + tgt.setTargetParentId(rootNodeId); + post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(tgt), null, 403); } @After From 44e14d9fbddf330fb926c4e8b41c10e95dfac33a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 22:49:56 +0530 Subject: [PATCH 012/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 a59662ef30c..2c4d70b708a 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 @@ -129,8 +129,8 @@ public void testHTTPStatus() throws Exception setRequestContext(user1); NodeTarget tgt = new NodeTarget(); - tgt.setTargetParentId(UUID.randomUUID().toString()); - post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(tgt), null, 404); + tgt.setTargetParentId(folderId); + post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); tgt = new NodeTarget(); tgt.setTargetParentId(rootNodeId); From d06c7b6fd3846bfaeb56410f3fecd519ccc3acb2 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 20 Jun 2024 23:21:41 +0530 Subject: [PATCH 013/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 2c4d70b708a..0eb96477491 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 @@ -119,6 +119,7 @@ public void testHTTPStatus() throws Exception String siteTitle = "RandomSite" + System.currentTimeMillis(); userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); String rootNodeId = getRootNodeId(); + String my2NodeId = getMyNodeId(); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); @@ -133,8 +134,8 @@ public void testHTTPStatus() throws Exception post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); tgt = new NodeTarget(); - tgt.setTargetParentId(rootNodeId); - post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(tgt), null, 403); + tgt.setTargetParentId(my2NodeId); + post(getFolderSizeUrl(rootNodeId), toJsonAsStringNonNull(tgt), null, 403); } @After From 4c6052b92de6bd328a1c62e3718a44f3d38e212b Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 21 Jun 2024 00:06:11 +0530 Subject: [PATCH 014/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 0eb96477491..9bff2a6ea01 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 @@ -133,9 +133,8 @@ public void testHTTPStatus() throws Exception tgt.setTargetParentId(folderId); post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); - tgt = new NodeTarget(); - tgt.setTargetParentId(my2NodeId); - post(getFolderSizeUrl(rootNodeId), toJsonAsStringNonNull(tgt), null, 403); + setRequestContext(folderId, user1, null); + delete(getFolderSizeUrl(folderId), folderId, null, 403); } @After From d628fc6799891b77ddfaf9087657847b183575ac Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 21 Jun 2024 00:44:21 +0530 Subject: [PATCH 015/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 9bff2a6ea01..5f801945883 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 @@ -133,8 +133,10 @@ public void testHTTPStatus() throws Exception tgt.setTargetParentId(folderId); post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); - setRequestContext(folderId, user1, null); - delete(getFolderSizeUrl(folderId), folderId, null, 403); + setRequestContext(networkAdmin); + tgt = new NodeTarget(); + tgt.setTargetParentId(my2NodeId); + post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(tgt), null, 403); } @After From 0a7f27c27eeb1cfc4702e09e4d6ceb0dd1cd8673 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 21 Jun 2024 09:09:15 +0530 Subject: [PATCH 016/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) 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 5f801945883..bdcdf098f0f 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 @@ -30,9 +30,17 @@ import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.util.RestApiUtil; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.rule.RuleService; +import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; +import org.alfresco.service.namespace.NamespaceService; import org.junit.After; +import org.junit.Before; import org.junit.Test; import java.util.HashMap; @@ -54,12 +62,22 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ */ private Site userOneN1Site; + protected PermissionService permissionService; + private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception { String parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); return createNode(parentId, name, nodeType, null).getId(); } + @Before + public void setup() throws Exception + { + super.setup(); + + permissionService = applicationContext.getBean("permissionService", PermissionService.class); + } + /** * Tests Folder Size Calculation *

POST:

@@ -133,10 +151,10 @@ public void testHTTPStatus() throws Exception tgt.setTargetParentId(folderId); post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); - setRequestContext(networkAdmin); - tgt = new NodeTarget(); - tgt.setTargetParentId(my2NodeId); - post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(tgt), null, 403); + setRequestContext(user1); + NodeRef folderC_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderId); + permissionService.setPermission(folderC_Ref, user1, PermissionService.READ, false); + post(getFolderSizeUrl(folderC_Ref.getId()), toJsonAsStringNonNull(tgt), null, 403); } @After From 798549f0f824b3a90203e554a81a2640a395763e Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 21 Jun 2024 09:35:59 +0530 Subject: [PATCH 017/267] [MNT-24127] Added Endpoint with test cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 5 ----- 1 file changed, 5 deletions(-) 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 bdcdf098f0f..df89492aece 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 @@ -150,11 +150,6 @@ public void testHTTPStatus() throws Exception NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(folderId); post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); - - setRequestContext(user1); - NodeRef folderC_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderId); - permissionService.setPermission(folderC_Ref, user1, PermissionService.READ, false); - post(getFolderSizeUrl(folderC_Ref.getId()), toJsonAsStringNonNull(tgt), null, 403); } @After From 25a95383bef35264c0b09ad53214d60a0bc69fbd Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 11:24:10 +0530 Subject: [PATCH 018/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 19 +++++++++++++++++-- .../rest/api/tests/NodeFolderSizeApiTest.java | 11 +---------- .../executer/NodeSizeActionExecuter.java | 3 ++- .../executer/NodeSizeActionExecuterTest.java | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) 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 2c95fc844a8..4af4e946c0f 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 @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * 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 @@ -25,7 +25,7 @@ */ package org.alfresco.rest.api.nodes; -import org.alfresco.model.ContentModel; + import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.executer.NodeSizeActionExecuter; import org.alfresco.repo.security.permissions.AccessDeniedException; @@ -35,6 +35,8 @@ import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.WebApiParameters; +import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; +import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.parameters.Parameters; @@ -74,6 +76,7 @@ public class NodeFolderSizeRelation implements private PermissionService permissionService; private NodeService nodeService; private ActionService actionService; + static final String NOT_A_VALID_NODEID = "Node Id does not refer to a valid type [folder type]"; /** * The logger @@ -127,6 +130,7 @@ public Map createById(String nodeId, Parameters params) { Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); int maxItems = params.getPaging().getMaxItems(); + QName qName = nodeService.getType(nodeRef); if (nodePerms != null) { if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { @@ -134,6 +138,11 @@ public Map createById(String nodeId, Parameters params) { } } + if(!"folder".equals(qName.getLocalName())) + { + throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); + } + try { Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); @@ -161,6 +170,12 @@ public Map readById(String nodeId, String id, Parameters paramet NodeRef nodeRef = nodes.validateNode(nodeId); Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); + QName qName = nodeService.getType(nodeRef); + + if(!"folder".equals(qName.getLocalName())) + { + throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); + } if (nodePerms != null) { if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { 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 df89492aece..3d435755a78 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 @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * 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 @@ -30,15 +30,8 @@ import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.util.RestApiUtil; -import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.rule.RuleService; -import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; -import org.alfresco.service.namespace.NamespaceService; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -136,8 +129,6 @@ public void testHTTPStatus() throws Exception String siteTitle = "RandomSite" + System.currentTimeMillis(); userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); - String rootNodeId = getRootNodeId(); - String my2NodeId = getMyNodeId(); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 45ea4029cb1..ddad27704e4 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * 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 @@ -149,6 +149,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) response.put("id", nodeRef.getId()); response.put("size", totalSize); response.put("calculatedAtTime", formattedTimestamp); + response.put("numberOfFiles", results!=null?results.getNodeRefs().size():0); nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) response); nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS,"COMPLETED"); } diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index daeacb6e284..4b8f97f9115 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * 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 From afb506e4ae872b008e34a0873e3cd7be476cd0a4 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 11:41:10 +0530 Subject: [PATCH 019/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/nodes/NodeFolderSizeRelation.java | 12 +++++------- .../rest/api/tests/NodeFolderSizeApiTest.java | 2 ++ .../repo/action/executer/NodeSizeActionExecuter.java | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) 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 4af4e946c0f..e9430407a10 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 @@ -25,7 +25,6 @@ */ package org.alfresco.rest.api.nodes; - import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.executer.NodeSizeActionExecuter; import org.alfresco.repo.security.permissions.AccessDeniedException; @@ -35,7 +34,6 @@ import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.WebApiParameters; -import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; @@ -172,17 +170,17 @@ public Map readById(String nodeId, String id, Parameters paramet NodePermissions nodePerms = nodeInfo.getPermissions(); QName qName = nodeService.getType(nodeRef); - if(!"folder".equals(qName.getLocalName())) - { - throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); - } - if (nodePerms != null) { if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { throw new AccessDeniedException("permissions.err_access_denied"); } } + if(!"folder".equals(qName.getLocalName())) + { + throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); + } + try { Map properties = nodeService.getProperties(nodeRef); 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 3d435755a78..1250ec70563 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 @@ -129,6 +129,8 @@ public void testHTTPStatus() throws Exception String siteTitle = "RandomSite" + System.currentTimeMillis(); userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + String rootNodeId = getRootNodeId(); + String my2NodeId = getMyNodeId(); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ddad27704e4..1697f0febfa 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2024 Alfresco Software Limited + * Copyright (C) 2005 - 2016 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of From 87e64a617dfe4362d7e5e419f0e57db2774eee86 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 11:45:13 +0530 Subject: [PATCH 020/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../alfresco/repo/action/executer/NodeSizeActionExecuter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 1697f0febfa..ddad27704e4 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * 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 From bb4d3eb2769670d26f4f8eb30b3188919639723a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 13:14:39 +0530 Subject: [PATCH 021/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 4 ++-- .../src/main/java/org/alfresco/model/FolderSizeModel.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 1250ec70563..40e0ddf4227 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 @@ -108,7 +108,7 @@ public void testGetCalculateFolderSize() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT, user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, "folder", user1); Map params = new HashMap<>(); params.put("nodeId",folderId); @@ -134,7 +134,7 @@ public void testHTTPStatus() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT, user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, "folder", user1); setRequestContext(null); delete(getFolderSizeUrl(folderId), folderId, null, 401); diff --git a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java index 889a7cdddb7..0cfdb0b0cf7 100644 --- a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java +++ b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * 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 From ead9aa9fd3438e44510f283c257ff2fa11591de0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 13:16:56 +0530 Subject: [PATCH 022/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 40e0ddf4227..5a8083d309e 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 @@ -86,7 +86,7 @@ public void testPostCalculateFolderSize() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT, user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, "folder", user1); Map params = new HashMap<>(); params.put("nodeId",folderId); From e749366a7788bb936696c0f57273dd8c46dd6a3d Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 13:43:04 +0530 Subject: [PATCH 023/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 5a8083d309e..4fea5440ca1 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 @@ -29,6 +29,7 @@ import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; +import org.alfresco.rest.api.tests.client.data.Node; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; @@ -60,7 +61,13 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception { String parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); - return createNode(parentId, name, nodeType, null).getId(); + Node n = new Node(); + n.setName(name); + n.setNodeType(nodeType); + n.setProperties(null); + // created node. + HttpResponse response = post(getFolderSizeUrl(parentId), RestApiUtil.toJsonAsStringNonNull(n), 201); + return String.valueOf(RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class)); } @Before @@ -86,7 +93,7 @@ public void testPostCalculateFolderSize() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, "folder", user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, user1); Map params = new HashMap<>(); params.put("nodeId",folderId); @@ -108,7 +115,7 @@ public void testGetCalculateFolderSize() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, "folder", user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, user1); Map params = new HashMap<>(); params.put("nodeId",folderId); @@ -134,7 +141,7 @@ public void testHTTPStatus() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, "folder", user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, user1); setRequestContext(null); delete(getFolderSizeUrl(folderId), folderId, null, 401); From 24334d1b29ebd27fe3ac1a0646c5ff998d2902b0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 14:03:36 +0530 Subject: [PATCH 024/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4fea5440ca1..26755661c6b 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 @@ -66,7 +66,7 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType, n.setNodeType(nodeType); n.setProperties(null); // created node. - HttpResponse response = post(getFolderSizeUrl(parentId), RestApiUtil.toJsonAsStringNonNull(n), 201); + HttpResponse response = post(getFolderSizeUrl(parentId), RestApiUtil.toJsonAsStringNonNull(n), 202); return String.valueOf(RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class)); } From e119821ce29a9d345db5a748d077a5f66ceeace0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 14:23:43 +0530 Subject: [PATCH 025/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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 26755661c6b..cdcdd6568f3 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 @@ -61,13 +61,7 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception { String parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); - Node n = new Node(); - n.setName(name); - n.setNodeType(nodeType); - n.setProperties(null); - // created node. - HttpResponse response = post(getFolderSizeUrl(parentId), RestApiUtil.toJsonAsStringNonNull(n), 202); - return String.valueOf(RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class)); + return createNode(parentId, name, nodeType, null).getId(); } @Before From cf456596277aa1343b1c51e8a6ab9b8d2381322d Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 16:21:07 +0530 Subject: [PATCH 026/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 13 +++++----- .../framework/tests/core/InspectorTests.java | 2 +- .../org/alfresco/model/FolderSizeModel.java | 6 ++--- .../executer/NodeSizeActionExecuter.java | 23 +++++++++++++----- .../executer/NodeSizeActionExecuterTest.java | 24 +++++++------------ 5 files changed, 35 insertions(+), 33 deletions(-) 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 cdcdd6568f3..4624989834b 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 @@ -29,7 +29,6 @@ import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; -import org.alfresco.rest.api.tests.client.data.Node; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; @@ -43,6 +42,7 @@ import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * V1 REST API tests for Folder size @@ -58,7 +58,7 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ protected PermissionService permissionService; - private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception + private String addToDocumentLibrary(Site testSite, String name, String nodeType) throws Exception { String parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); return createNode(parentId, name, nodeType, null).getId(); @@ -87,7 +87,7 @@ public void testPostCalculateFolderSize() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); Map params = new HashMap<>(); params.put("nodeId",folderId); @@ -109,7 +109,7 @@ public void testGetCalculateFolderSize() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); Map params = new HashMap<>(); params.put("nodeId",folderId); @@ -130,12 +130,10 @@ public void testHTTPStatus() throws Exception String siteTitle = "RandomSite" + System.currentTimeMillis(); userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); - String rootNodeId = getRootNodeId(); - String my2NodeId = getMyNodeId(); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, user1); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); setRequestContext(null); delete(getFolderSizeUrl(folderId), folderId, null, 401); @@ -144,6 +142,7 @@ public void testHTTPStatus() throws Exception NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(folderId); post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); + assertTrue(true); } @After diff --git a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java index 9b4d78fa1dd..376e552624a 100644 --- a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java +++ b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java @@ -648,7 +648,7 @@ public void testValidSuccessCode() public void testCalculateSizeRelation() { List metainfo = ResourceInspector.inspect(NodeFolderSizeRelation.class); - assertTrue("Must be one ResourceMetadata",metainfo.size()>0); + assertTrue("Must be one ResourceMetadata",!metainfo.isEmpty()); ResourceMetadata metaData = metainfo.get(0); assertNotNull(metaData); ResourceOperation op = metaData.getOperation(HttpMethod.POST); diff --git a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java index 0cfdb0b0cf7..39e9c554a58 100644 --- a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java +++ b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java @@ -32,8 +32,8 @@ public interface FolderSizeModel { /** Folder Model URI */ - static final String SIZE_MODEL_1_0_URI = "http://www.alfresco.org/model/size/1.0"; + String SIZE_MODEL_1_0_URI = "http://www.alfresco.org/model/size/1.0"; - static final QName PROP_STATUS = QName.createQName(SIZE_MODEL_1_0_URI, "status"); - static final QName PROP_OUTPUT = QName.createQName(SIZE_MODEL_1_0_URI, "result"); + QName PROP_STATUS = QName.createQName(SIZE_MODEL_1_0_URI, "status"); + QName PROP_OUTPUT = QName.createQName(SIZE_MODEL_1_0_URI, "result"); } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ddad27704e4..1cbafac36e3 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -65,7 +65,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase /** * The logger */ - private static Log logger = LogFactory.getLog(NodeSizeActionExecuter.class); + private static final Log logger = LogFactory.getLog(NodeSizeActionExecuter.class); /** * Set the node service @@ -89,9 +89,10 @@ public void setSearchService(SearchService searchService) { /** * @see ActionExecuter#execute(Action, NodeRef) */ + @Override public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) { - Serializable serializable = ruleAction.getParameterValue(NodeSizeActionExecuter.PAGE_SIZE); + Serializable serializable = ruleAction.getParameterValue(PAGE_SIZE); int maxItems = Integer.parseInt(serializable.toString()); int skipCount = 0; int totalItems = maxItems; @@ -101,13 +102,13 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) ResultSet results = null; StringBuilder aftsQuery = new StringBuilder(); - aftsQuery.append("ANCESTOR:\""+nodeRef+"\" AND TYPE:content"); + aftsQuery.append("ANCESTOR:\"").append(nodeRef).append("\" AND TYPE:content"); String query = aftsQuery.toString(); SearchParameters searchParameters = new SearchParameters(); searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - searchParameters.setQuery(query.toString()); + searchParameters.setQuery(query); try{ // executing Alfresco FTS query. @@ -116,7 +117,9 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) while(true) { if (results.getNodeRefs().size() < maxItems) + { totalItems = results.getNodeRefs().size(); + } resultSize = results.getNodeRefs().subList(skipCount,totalItems).parallelStream() .map(id -> ((ContentData) nodeService.getProperty(id, ContentModel.PROP_CONTENT)).getSize()) @@ -125,15 +128,23 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) totalSize+=resultSize; if (results.getNodeRefs().size() <= totalItems || results.getNodeRefs().size() <= maxItems) + { break; + } - if (results.getNodeRefs().size() > maxItems) { + if (results.getNodeRefs().size() > maxItems) + { skipCount += maxItems; - int remainingItems = (results.getNodeRefs().size()-totalItems); + int remainingItems = results.getNodeRefs().size()-totalItems; + if(remainingItems > maxItems) + { totalItems += maxItems; + } else + { totalItems += remainingItems; + } } } } diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index 4b8f97f9115..798488811ac 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -48,16 +48,6 @@ public class NodeSizeActionExecuterTest extends BaseSpringTest */ private NodeService nodeService; - /** - * The store reference - */ - private StoreRef testStoreRef; - - /** - * The root node reference - */ - private NodeRef rootNodeRef; - /** * The test node reference */ @@ -79,24 +69,27 @@ public class NodeSizeActionExecuterTest extends BaseSpringTest @Before public void before() throws Exception { + this.nodeService = (NodeService)this.applicationContext.getBean("nodeService"); + StoreRef testStoreRef; + NodeRef rootNodeRef; AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent"); authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); // Create the store and get the root node - this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); - this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef); + rootNodeRef = this.nodeService.getRootNode(testStoreRef); // Create the node used for tests this.nodeRef = this.nodeService.createNode( - this.rootNodeRef, + rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), ContentModel.TYPE_CONTENT).getChildRef(); - // Get the executer instance + // Get the executer instance. this.executer = (NodeSizeActionExecuter)this.applicationContext.getBean(NodeSizeActionExecuter.NAME); } @@ -108,11 +101,10 @@ public void testExecution() { assertEquals(1,1); int maxItems = 100; - // Execute the action ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null); action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); this.executer.executeImpl(action, this.nodeRef); String compareString = this.nodeService.getProperty(this.nodeRef, FolderSizeModel.PROP_STATUS).toString(); - assertTrue(compareString!=null?true:false); + assertTrue(compareString != null); } } From 824bca52dbf0f3ac82983aa49f7130419a11d838 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 17:08:35 +0530 Subject: [PATCH 027/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 20 ++++++++--------- .../rest/api/tests/NodeFolderSizeApiTest.java | 22 ++++++++++++++----- .../executer/NodeSizeActionExecuter.java | 5 +++-- 3 files changed, 29 insertions(+), 18 deletions(-) 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 e9430407a10..4ab8e65fb2c 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 @@ -79,7 +79,7 @@ public class NodeFolderSizeRelation implements /** * The logger */ - private static Log logger = LogFactory.getLog(NodeFolderSizeRelation.class); + private static final Log LOGGER = LogFactory.getLog(NodeFolderSizeRelation.class); /** * The class that wraps the ReST APIs from core. @@ -130,10 +130,9 @@ public Map createById(String nodeId, Parameters params) { int maxItems = params.getPaging().getMaxItems(); QName qName = nodeService.getType(nodeRef); - if (nodePerms != null) { - if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { - throw new AccessDeniedException("permissions.err_access_denied"); - } + if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) + { + throw new AccessDeniedException("permissions.err_access_denied"); } if(!"folder".equals(qName.getLocalName())) @@ -154,7 +153,7 @@ public Map createById(String nodeId, Parameters params) { } catch (Exception ex) { - logger.error("Exception occured in NodeFolderSizeRelation:createById "+ex.getMessage()); + LOGGER.error("Exception occured in NodeFolderSizeRelation:createById "+ex.getMessage()); } return null; } @@ -170,10 +169,9 @@ public Map readById(String nodeId, String id, Parameters paramet NodePermissions nodePerms = nodeInfo.getPermissions(); QName qName = nodeService.getType(nodeRef); - if (nodePerms != null) { - if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { - throw new AccessDeniedException("permissions.err_access_denied"); - } + if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) + { + throw new AccessDeniedException("permissions.err_access_denied"); } if(!"folder".equals(qName.getLocalName())) @@ -202,7 +200,7 @@ public Map readById(String nodeId, String id, Parameters paramet } catch (Exception ex) { - logger.error("Exception occured in NodeFolderSizeRelation:readById "+ex.getMessage()); + LOGGER.error("Exception occured in NodeFolderSizeRelation:readById "+ex.getMessage()); } return null; } 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 4624989834b..4a59d5e609d 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 @@ -25,6 +25,7 @@ */ package org.alfresco.rest.api.tests; +import org.alfresco.repo.action.executer.NodeSizeActionExecuter; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; @@ -32,6 +33,8 @@ import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -58,10 +61,17 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ protected PermissionService permissionService; - private String addToDocumentLibrary(Site testSite, String name, String nodeType) throws Exception + private String addToDocumentLibrary(Site testSite, String name, String nodeType) { - String parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); - return createNode(parentId, name, nodeType, null).getId(); + String parentId; + try + { + parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); + return createNode(parentId, name, nodeType, null).getId(); + } catch (Exception e) + { + throw new RuntimeException(e.getMessage()); + } } @Before @@ -141,8 +151,10 @@ public void testHTTPStatus() throws Exception setRequestContext(user1); NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(folderId); - post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); - assertTrue(true); + HttpResponse response = post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); + Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); + String contentNodeId = document.toString(); + assertNotNull(contentNodeId); } @After diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 1cbafac36e3..ade59d3ef38 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -65,7 +65,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase /** * The logger */ - private static final Log logger = LogFactory.getLog(NodeSizeActionExecuter.class); + private static final Log LOGGER = LogFactory.getLog(NodeSizeActionExecuter.class); /** * Set the node service @@ -150,7 +150,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) } catch (RuntimeException ex) { - logger.error("Exception occured in NodeSizeActionExecutor:results "+ex.getMessage()); + LOGGER.error("Exception occured in NodeSizeActionExecutor:results "+ex.getMessage()); } final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); @@ -171,5 +171,6 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) @Override protected void addParameterDefinitions(List paramList) { + // Intentionally empty } } From cfe265f1ce6f8ddb80ea18788b3280d6f811e660 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 17:50:58 +0530 Subject: [PATCH 028/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/nodes/NodeFolderSizeRelation.java | 10 +++++----- .../rest/api/tests/NodeFolderSizeApiTest.java | 13 +++++++++---- .../java/org/alfresco/model/FolderSizeModel.java | 8 ++++---- .../action/executer/NodeSizeActionExecuter.java | 8 ++++---- 4 files changed, 22 insertions(+), 17 deletions(-) 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 4ab8e65fb2c..ba4279c5d80 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 @@ -48,8 +48,8 @@ import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; import org.alfresco.util.ParameterCheck; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.extensions.webscripts.Status; @@ -79,7 +79,7 @@ public class NodeFolderSizeRelation implements /** * The logger */ - private static final Log LOGGER = LogFactory.getLog(NodeFolderSizeRelation.class); + private static final Logger LOG = LoggerFactory.getLogger(NodeFolderSizeRelation.class); /** * The class that wraps the ReST APIs from core. @@ -153,7 +153,7 @@ public Map createById(String nodeId, Parameters params) { } catch (Exception ex) { - LOGGER.error("Exception occured in NodeFolderSizeRelation:createById "+ex.getMessage()); + LOG.error("Exception occured in NodeFolderSizeRelation:createById {}", ex.getMessage()); } return null; } @@ -200,7 +200,7 @@ public Map readById(String nodeId, String id, Parameters paramet } catch (Exception ex) { - LOGGER.error("Exception occured in NodeFolderSizeRelation:readById "+ex.getMessage()); + LOG.error("Exception occured in NodeFolderSizeRelation:readById {}", ex.getMessage()); } return null; } 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 4a59d5e609d..e9366f71c7a 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 @@ -33,11 +33,11 @@ import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; @@ -45,7 +45,6 @@ import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; /** * V1 REST API tests for Folder size @@ -61,6 +60,11 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ protected PermissionService permissionService; + /** + * The logger + */ + private static final Logger LOG = LoggerFactory.getLogger(NodeFolderSizeApiTest.class); + private String addToDocumentLibrary(Site testSite, String name, String nodeType) { String parentId; @@ -70,8 +74,9 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType) return createNode(parentId, name, nodeType, null).getId(); } catch (Exception e) { - throw new RuntimeException(e.getMessage()); + LOG.error("Exception occured in NodeFolderSizeApiTest:addToDocumentLibrary {}", e.getMessage()); } + return null; } @Before diff --git a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java index 39e9c554a58..77dd4b0c8d5 100644 --- a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java +++ b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java @@ -29,11 +29,11 @@ import org.alfresco.service.namespace.QName; @AlfrescoPublicApi -public interface FolderSizeModel { +public class FolderSizeModel { /** Folder Model URI */ - String SIZE_MODEL_1_0_URI = "http://www.alfresco.org/model/size/1.0"; + private static final String SIZE_MODEL_1_0_URI = "http://www.alfresco.org/model/size/1.0"; - QName PROP_STATUS = QName.createQName(SIZE_MODEL_1_0_URI, "status"); - QName PROP_OUTPUT = QName.createQName(SIZE_MODEL_1_0_URI, "result"); + public static final QName PROP_STATUS = QName.createQName(SIZE_MODEL_1_0_URI, "status"); + public static final QName PROP_OUTPUT = QName.createQName(SIZE_MODEL_1_0_URI, "result"); } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ade59d3ef38..ff91cd5a7ca 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -36,8 +36,8 @@ import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.search.SearchService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.Serializable; import java.time.Instant; @@ -65,7 +65,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase /** * The logger */ - private static final Log LOGGER = LogFactory.getLog(NodeSizeActionExecuter.class); + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeActionExecuter.class); /** * Set the node service @@ -150,7 +150,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) } catch (RuntimeException ex) { - LOGGER.error("Exception occured in NodeSizeActionExecutor:results "+ex.getMessage()); + LOG.error("Exception occured in NodeSizeActionExecutor:results {}", ex.getMessage()); } final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); From 1b36b5103169c570b866a71ca6317d29526433d2 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 24 Jun 2024 18:08:28 +0530 Subject: [PATCH 029/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 e9366f71c7a..4fa0973b18e 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 @@ -157,9 +157,7 @@ public void testHTTPStatus() throws Exception NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(folderId); HttpResponse response = post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); - Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); - String contentNodeId = document.toString(); - assertNotNull(contentNodeId); + assertNotNull(response); } @After From 3d2b1d0ee8290c6cadab62da1ef9f8a37089c3e1 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 25 Jun 2024 13:29:29 +0530 Subject: [PATCH 030/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 72 +++++++++++-------- .../RelationshipResourceAction.java | 2 +- .../rest/api/tests/NodeFolderSizeApiTest.java | 22 ++++-- .../org/alfresco/model/FolderSizeModel.java | 5 +- .../executer/NodeSizeActionExecuter.java | 26 +++++-- .../executer/NodeSizeActionExecuterTest.java | 5 +- 6 files changed, 82 insertions(+), 50 deletions(-) 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 ba4279c5d80..028be023161 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 @@ -47,34 +47,33 @@ import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; +import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ParameterCheck; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.extensions.webscripts.Status; - import java.io.Serializable; -import java.util.*; +import java.util.HashMap; +import java.util.Map; /** - * Node Size - * - * - get folder size - * + * NodeFolderSizeRelation + * Calculating and Retrieving the folder size + * @author Mohit Singh */ -@RelationshipResource(name = "calculateSize", entityResource = NodesEntityResource.class, title = "Calculate size") -public class NodeFolderSizeRelation implements - RelationshipResourceAction.CalculateSize>, - RelationshipResourceAction.ReadById>, - InitializingBean { +@RelationshipResource(name = "calculateSize", entityResource = NodesEntityResource.class, title = "Calculate size") +public class NodeFolderSizeRelation implements RelationshipResourceAction.CalculateSize>, + RelationshipResourceAction.ReadById>, InitializingBean +{ private Nodes nodes; private SearchService searchService; private ServiceRegistry serviceRegistry; private PermissionService permissionService; private NodeService nodeService; private ActionService actionService; - static final String NOT_A_VALID_NODEID = "Node Id does not refer to a valid type [folder type]"; + private static final String NOT_A_VALID_NODEID = "Node Id does not refer to a valid type [should be of folder type]"; /** * The logger @@ -85,29 +84,35 @@ public class NodeFolderSizeRelation implements * The class that wraps the ReST APIs from core. */ - public void setNodes(Nodes nodes) { + public void setNodes(Nodes nodes) + { this.nodes = nodes; } - public void setSearchService(SearchService searchService) { + public void setSearchService(SearchService searchService) + { this.searchService = searchService; } - public void setServiceRegistry(ServiceRegistry serviceRegistry) { + public void setServiceRegistry(ServiceRegistry serviceRegistry) + { this.serviceRegistry = serviceRegistry; this.permissionService = serviceRegistry.getPermissionService(); } - public void setNodeService(NodeService nodeService) { + public void setNodeService(NodeService nodeService) + { this.nodeService = nodeService; } - public void setActionService(ActionService actionService) { + public void setActionService(ActionService actionService) + { this.actionService = actionService; } @Override - public void afterPropertiesSet() { + public void afterPropertiesSet() + { ParameterCheck.mandatory("nodes", this.nodes); } @@ -116,19 +121,23 @@ public void afterPropertiesSet() { * * @param nodeId String id of folder - will also accept well-known alias, eg. -root- or -my- or -shared- * Please refer to OpenAPI spec for more details ! + * Returns the executionId which shows pending action, which can be used in a + * GET/calculateSize endpoint to check if the action's status has been completed, comprising the size of the node in bytes. *

* If NodeId does not exist, EntityNotFoundException (status 404). + * If nodeId does not represent a folder, InvalidNodeTypeException (status 400). */ @Override - @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder/file", successStatus = Status.STATUS_ACCEPTED) - public Map createById(String nodeId, Parameters params) { - + @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder", successStatus = Status.STATUS_ACCEPTED) + public Map createById(String nodeId, Parameters params) + { NodeRef nodeRef = nodes.validateNode(nodeId); nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "IN-PROGRESS"); Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); int maxItems = params.getPaging().getMaxItems(); QName qName = nodeService.getType(nodeRef); + Map result = new HashMap<>(); if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { @@ -147,13 +156,12 @@ public Map createById(String nodeId, Parameters params) { folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); actionService.executeAction(folderSizeAction, nodeRef, false, true); - Map result = new HashMap<>(); result.put("executionId", nodeId); return result; } catch (Exception ex) { - LOG.error("Exception occured in NodeFolderSizeRelation:createById {}", ex.getMessage()); + LOG.error("Exception occurred in NodeFolderSizeRelation:createById {}", ex.getMessage()); } return null; } @@ -168,6 +176,7 @@ public Map readById(String nodeId, String id, Parameters paramet Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); QName qName = nodeService.getType(nodeRef); + Map result = new HashMap<>(); if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { @@ -182,15 +191,20 @@ public Map readById(String nodeId, String id, Parameters paramet try { Map properties = nodeService.getProperties(nodeRef); - Map result = new HashMap<>(); - if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { + if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) + { result.put("status", "NOT INITIATED"); - } else { + } + else + { String status = (String) properties.get(FolderSizeModel.PROP_STATUS); - if ("IN-PROGRESS".equals(status)) { + if ("IN-PROGRESS".equals(status)) + { result.put("status", status); - } else { + } + else + { Map mapResult = (Map) properties.get(FolderSizeModel.PROP_OUTPUT); mapResult.put("status", status); result = mapResult; @@ -200,7 +214,7 @@ public Map readById(String nodeId, String id, Parameters paramet } catch (Exception ex) { - LOG.error("Exception occured in NodeFolderSizeRelation:readById {}", ex.getMessage()); + LOG.error("Exception occurred in NodeFolderSizeRelation:readById {}", ex.getMessage()); } return null; } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java index 120eacdc0e3..40abf6a2f51 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java @@ -167,7 +167,7 @@ public static interface DeleteSetWithResponse extends ResourceAction interface CalculateSize extends ResourceAction { /** - * Calculate the size of Folder/File. + * Calculate the size of Folder Node. * * @param nodeId Entity resource context for this relationship. * @param params implementation may choose to restrict the set to be deleted based on params (ie. not necessarily "all") 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 4fa0973b18e..7aa4c1a59ff 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 @@ -25,7 +25,6 @@ */ package org.alfresco.rest.api.tests; -import org.alfresco.repo.action.executer.NodeSizeActionExecuter; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; @@ -51,7 +50,8 @@ * * @author Mohit Singh */ -public class NodeFolderSizeApiTest extends AbstractBaseApiTest{ +public class NodeFolderSizeApiTest extends AbstractBaseApiTest +{ /** * Private site of user two from network one. @@ -72,7 +72,8 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType) { parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); return createNode(parentId, name, nodeType, null).getId(); - } catch (Exception e) + } + catch (Exception e) { LOG.error("Exception occured in NodeFolderSizeApiTest:addToDocumentLibrary {}", e.getMessage()); } @@ -83,12 +84,11 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType) public void setup() throws Exception { super.setup(); - permissionService = applicationContext.getBean("permissionService", PermissionService.class); } /** - * Tests Folder Size Calculation + * Test case for POST/calculateSize, which calculates Folder Size. *

POST:

* {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} */ @@ -114,6 +114,11 @@ public void testPostCalculateFolderSize() throws Exception assertNotNull(contentNodeId); } + /** + * Test case for GET/calculateSize, to retrieve FolderSize. + *

GET:

+ * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} + */ @Test public void testGetCalculateFolderSize() throws Exception { @@ -137,12 +142,14 @@ public void testGetCalculateFolderSize() throws Exception assertNotNull(contentNodeId); } + /** + * Test case for others HTTP status codes. + */ @Test public void testHTTPStatus() throws Exception { setRequestContext(user1); - String siteTitle = "RandomSite" + System.currentTimeMillis(); userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); @@ -167,7 +174,8 @@ public void tearDown() throws Exception } @Override - public String getScope() { + public String getScope() + { return "public"; } } diff --git a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java index 77dd4b0c8d5..704eb53553d 100644 --- a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java +++ b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java @@ -29,11 +29,10 @@ import org.alfresco.service.namespace.QName; @AlfrescoPublicApi -public class FolderSizeModel { - +public class FolderSizeModel +{ /** Folder Model URI */ private static final String SIZE_MODEL_1_0_URI = "http://www.alfresco.org/model/size/1.0"; - public static final QName PROP_STATUS = QName.createQName(SIZE_MODEL_1_0_URI, "status"); public static final QName PROP_OUTPUT = QName.createQName(SIZE_MODEL_1_0_URI, "result"); } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ff91cd5a7ca..de0007e1ad0 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -27,6 +27,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.model.FolderSizeModel; +import org.alfresco.repo.action.ParameterizedItemAbstractBase; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.repository.ContentData; @@ -82,7 +83,8 @@ public void setNodeService(NodeService nodeService) * * @param searchService the search service */ - public void setSearchService(SearchService searchService) { + public void setSearchService(SearchService searchService) + { this.searchService = searchService; } @@ -93,7 +95,16 @@ public void setSearchService(SearchService searchService) { public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) { Serializable serializable = ruleAction.getParameterValue(PAGE_SIZE); - int maxItems = Integer.parseInt(serializable.toString()); + int maxItems = 0; + try + { + maxItems = Integer.parseInt(serializable.toString()); + } + catch (NumberFormatException e) + { + LOG.error("Exception occurred in NodeSizeActionExecutor:executeImpl:parsingInteger{}", e.getMessage()); + } + int skipCount = 0; int totalItems = maxItems; NodeRef nodeRef = actionedUponNodeRef; @@ -110,12 +121,13 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); searchParameters.setQuery(query); - try{ + try + { // executing Alfresco FTS query. results = searchService.query(searchParameters); - while(true) { - + while(true) + { if (results.getNodeRefs().size() < maxItems) { totalItems = results.getNodeRefs().size(); @@ -150,7 +162,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) } catch (RuntimeException ex) { - LOG.error("Exception occured in NodeSizeActionExecutor:results {}", ex.getMessage()); + LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", ex.getMessage()); } final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); @@ -166,7 +178,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) } /** - * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(List) + * @see ParameterizedItemAbstractBase#addParameterDefinitions(List) */ @Override protected void addParameterDefinitions(List paramList) diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index 798488811ac..0ca562efd22 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -25,7 +25,6 @@ */ package org.alfresco.repo.action.executer; - import org.alfresco.model.ContentModel; import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.ActionImpl; @@ -64,7 +63,7 @@ public class NodeSizeActionExecuterTest extends BaseSpringTest private final static String ID = GUID.generate(); /** - * Called at the begining of all tests + * Called at the begining of all tests. */ @Before public void before() throws Exception @@ -94,7 +93,7 @@ public void before() throws Exception } /** - * Test execution + * Test execution. */ @Test public void testExecution() From 6c5058246f4f9e95f9d9d716611930ad3bf65383 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 25 Jun 2024 15:03:18 +0530 Subject: [PATCH 031/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java | 1 - .../repo/action/executer/NodeSizeActionExecuter.java | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 028be023161..788e1245449 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 @@ -47,7 +47,6 @@ import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ParameterCheck; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index de0007e1ad0..ae2001acbc8 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -49,6 +49,12 @@ import java.util.List; import java.util.Map; +/** + * NodeSizeActionExecuter + * Executing Alfresco FTS Query to find size of Folder Node. + * @author Mohit Singh + */ + public class NodeSizeActionExecuter extends ActionExecuterAbstractBase { /** From 3cd67921d7da35cde4732403b2d6227422432fd3 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 25 Jun 2024 16:55:34 +0530 Subject: [PATCH 032/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 22 +++++++------------ .../executer/NodeSizeActionExecuter.java | 12 +++++++--- 2 files changed, 17 insertions(+), 17 deletions(-) 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 788e1245449..10a6fbc4bc8 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 @@ -63,8 +63,7 @@ */ @RelationshipResource(name = "calculateSize", entityResource = NodesEntityResource.class, title = "Calculate size") -public class NodeFolderSizeRelation implements RelationshipResourceAction.CalculateSize>, - RelationshipResourceAction.ReadById>, InitializingBean +public class NodeFolderSizeRelation implements RelationshipResourceAction.CalculateSize>,RelationshipResourceAction.ReadById>, InitializingBean { private Nodes nodes; private SearchService searchService; @@ -190,24 +189,19 @@ public Map readById(String nodeId, String id, Parameters paramet try { Map properties = nodeService.getProperties(nodeRef); - if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { result.put("status", "NOT INITIATED"); } + else if (!properties.containsKey(FolderSizeModel.PROP_OUTPUT)) + { + result.put("status", "IN-PROGRESS"); + } else { - String status = (String) properties.get(FolderSizeModel.PROP_STATUS); - if ("IN-PROGRESS".equals(status)) - { - result.put("status", status); - } - else - { - Map mapResult = (Map) properties.get(FolderSizeModel.PROP_OUTPUT); - mapResult.put("status", status); - result = mapResult; - } + Map mapResult = (Map) properties.get(FolderSizeModel.PROP_OUTPUT); + mapResult.put("status", "COMPLETED"); + result = mapResult; } return result; } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ae2001acbc8..ae527fea1ed 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -102,6 +102,8 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) { Serializable serializable = ruleAction.getParameterValue(PAGE_SIZE); int maxItems = 0; + Map response = new HashMap<>(); + try { maxItems = Integer.parseInt(serializable.toString()); @@ -117,6 +119,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) long totalSize = 0; long resultSize; ResultSet results = null; + boolean isCalculationCompleted = false; StringBuilder aftsQuery = new StringBuilder(); aftsQuery.append("ANCESTOR:\"").append(nodeRef).append("\" AND TYPE:content"); @@ -147,6 +150,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) if (results.getNodeRefs().size() <= totalItems || results.getNodeRefs().size() <= maxItems) { + isCalculationCompleted = true; break; } @@ -174,13 +178,15 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); String formattedTimestamp = eventTimestamp.format(formatter); - Map response = new HashMap<>(); response.put("id", nodeRef.getId()); response.put("size", totalSize); response.put("calculatedAtTime", formattedTimestamp); response.put("numberOfFiles", results!=null?results.getNodeRefs().size():0); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) response); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS,"COMPLETED"); + if(isCalculationCompleted) + { + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) response); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "COMPLETED"); + } } /** From 80cb5b6caa1705cb8faa65dadd75ebaa95d73d2b Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 09:57:47 +0530 Subject: [PATCH 033/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 13 +++--- .../webscripts/ResourceWebScriptPost.java | 2 +- .../executer/NodeSizeActionExecuter.java | 44 ++++++++----------- 3 files changed, 27 insertions(+), 32 deletions(-) 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 10a6fbc4bc8..3180de70c80 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 @@ -130,7 +130,10 @@ public void afterPropertiesSet() public Map createById(String nodeId, Parameters params) { NodeRef nodeRef = nodes.validateNode(nodeId); + Map resetFolderOutput = new HashMap<>(); + resetFolderOutput.put("status","IN-PROGRESS"); nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "IN-PROGRESS"); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) resetFolderOutput); Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); int maxItems = params.getPaging().getMaxItems(); @@ -154,14 +157,14 @@ public Map createById(String nodeId, Parameters params) folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); actionService.executeAction(folderSizeAction, nodeRef, false, true); + LOG.info(" Executing ActionExecutor in NodeFolderSizeRelation:createById "); result.put("executionId", nodeId); return result; } catch (Exception ex) { - LOG.error("Exception occurred in NodeFolderSizeRelation:createById {}", ex.getMessage()); + throw new RuntimeException("Exception occurred in NodeFolderSizeRelation:createById "+ex.getMessage()); } - return null; } @Override @@ -188,10 +191,11 @@ public Map readById(String nodeId, String id, Parameters paramet try { + LOG.info(" Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById "); Map properties = nodeService.getProperties(nodeRef); if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { - result.put("status", "NOT INITIATED"); + result.put("status", "NOT-INITIATED"); } else if (!properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { @@ -207,8 +211,7 @@ else if (!properties.containsKey(FolderSizeModel.PROP_OUTPUT)) } catch (Exception ex) { - LOG.error("Exception occurred in NodeFolderSizeRelation:readById {}", ex.getMessage()); + throw new RuntimeException("Exception occurred in NodeFolderSizeRelation:readById "+ex.getMessage()); } - return null; } } \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java index 29cbe4b5c33..9fc652c6f40 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java @@ -374,7 +374,7 @@ else if (RelationshipResourceAction.CalculateSize.class.isAssignableFrom(resourc { if (resource.getMetaData().isDeleted(RelationshipResourceAction.CalculateSize.class)) { - throw new DeletedResourceException("(GET by id) " + resource.getMetaData().getUniqueId()); + throw new DeletedResourceException("(POST by id) " + resource.getMetaData().getUniqueId()); } RelationshipResourceAction.CalculateSize relationGetter = (RelationshipResourceAction.CalculateSize) resource.getResource(); Object result = relationGetter.createById(params.getEntityId(),params); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ae527fea1ed..200cbccafc9 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -28,6 +28,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.ParameterizedItemAbstractBase; +import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.repository.ContentData; @@ -101,7 +102,9 @@ public void setSearchService(SearchService searchService) public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) { Serializable serializable = ruleAction.getParameterValue(PAGE_SIZE); - int maxItems = 0; + int maxItems; + int skipCount = 0; + int totalItems; Map response = new HashMap<>(); try @@ -110,11 +113,9 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) } catch (NumberFormatException e) { - LOG.error("Exception occurred in NodeSizeActionExecutor:executeImpl:parsingInteger{}", e.getMessage()); + throw new NumberFormatException("Exception occurred in NodeSizeActionExecutor "+e.getMessage()); } - int skipCount = 0; - int totalItems = maxItems; NodeRef nodeRef = actionedUponNodeRef; long totalSize = 0; long resultSize; @@ -134,54 +135,45 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) { // executing Alfresco FTS query. results = searchService.query(searchParameters); + List nodeRefs = results.getNodeRefs(); + totalItems = Math.min(nodeRefs.size(), maxItems); - while(true) + while (!isCalculationCompleted) { - if (results.getNodeRefs().size() < maxItems) - { - totalItems = results.getNodeRefs().size(); - } + List subList = nodeRefs.subList(skipCount, totalItems); - resultSize = results.getNodeRefs().subList(skipCount,totalItems).parallelStream() + resultSize = subList.parallelStream() .map(id -> ((ContentData) nodeService.getProperty(id, ContentModel.PROP_CONTENT)).getSize()) .reduce(0L, Long::sum); totalSize+=resultSize; - if (results.getNodeRefs().size() <= totalItems || results.getNodeRefs().size() <= maxItems) + if (nodeRefs.size() <= totalItems || nodeRefs.size() <= maxItems) { isCalculationCompleted = true; - break; } - - if (results.getNodeRefs().size() > maxItems) + else { skipCount += maxItems; - int remainingItems = results.getNodeRefs().size()-totalItems; - - if(remainingItems > maxItems) - { - totalItems += maxItems; - } - else - { - totalItems += remainingItems; - } + int remainingItems = nodeRefs.size() - totalItems; + totalItems += Math.min(remainingItems, maxItems); } } } catch (RuntimeException ex) { - LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", ex.getMessage()); + throw new RuntimeException("Exception occurred in NodeSizeActionExecutor:results "+ex.getMessage()); } + LOG.info(" Calculating size of Folder Node - NodeSizeActionExecutor:executeImpl "); final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); String formattedTimestamp = eventTimestamp.format(formatter); response.put("id", nodeRef.getId()); response.put("size", totalSize); response.put("calculatedAtTime", formattedTimestamp); - response.put("numberOfFiles", results!=null?results.getNodeRefs().size():0); + response.put("numberOfFiles", results != null ? results.getNodeRefs().size() : 0); + if(isCalculationCompleted) { nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) response); From 7daf9c0d61f2e54b53ac5daf0226d616816242a1 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 11:33:04 +0530 Subject: [PATCH 034/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/nodes/NodeFolderSizeRelation.java | 6 ++++-- .../repo/action/executer/NodeSizeActionExecuter.java | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) 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 3180de70c80..4e325eb5380 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 @@ -163,7 +163,8 @@ public Map createById(String nodeId, Parameters params) } catch (Exception ex) { - throw new RuntimeException("Exception occurred in NodeFolderSizeRelation:createById "+ex.getMessage()); + LOG.error("Exception occurred in NodeFolderSizeRelation:createById {}", ex.getMessage()); + throw ex; // This rethrows with the original stack trace preserved. } } @@ -211,7 +212,8 @@ else if (!properties.containsKey(FolderSizeModel.PROP_OUTPUT)) } catch (Exception ex) { - throw new RuntimeException("Exception occurred in NodeFolderSizeRelation:readById "+ex.getMessage()); + LOG.error("Exception occurred in NodeFolderSizeRelation:readById {}", ex.getMessage()); + throw ex;// This rethrows with the original stack trace preserved. } } } \ No newline at end of file diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 200cbccafc9..a5873e6eb5b 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -103,8 +103,6 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) { Serializable serializable = ruleAction.getParameterValue(PAGE_SIZE); int maxItems; - int skipCount = 0; - int totalItems; Map response = new HashMap<>(); try @@ -113,7 +111,8 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) } catch (NumberFormatException e) { - throw new NumberFormatException("Exception occurred in NodeSizeActionExecutor "+e.getMessage()); + LOG.error("Exception occurred while parsing String to INT: {}", e.getMessage()); + throw e; } NodeRef nodeRef = actionedUponNodeRef; @@ -136,12 +135,13 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) // executing Alfresco FTS query. results = searchService.query(searchParameters); List nodeRefs = results.getNodeRefs(); + int skipCount = 0; + int totalItems; totalItems = Math.min(nodeRefs.size(), maxItems); while (!isCalculationCompleted) { List subList = nodeRefs.subList(skipCount, totalItems); - resultSize = subList.parallelStream() .map(id -> ((ContentData) nodeService.getProperty(id, ContentModel.PROP_CONTENT)).getSize()) .reduce(0L, Long::sum); @@ -162,7 +162,8 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) } catch (RuntimeException ex) { - throw new RuntimeException("Exception occurred in NodeSizeActionExecutor:results "+ex.getMessage()); + LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", ex.getMessage()); + throw ex; } LOG.info(" Calculating size of Folder Node - NodeSizeActionExecutor:executeImpl "); From 2bf9dac653a333f57736d9410f0561adedd8e8b2 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 11:44:49 +0530 Subject: [PATCH 035/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../alfresco/repo/action/executer/NodeSizeActionExecuter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index a5873e6eb5b..2e251555102 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -118,7 +118,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) NodeRef nodeRef = actionedUponNodeRef; long totalSize = 0; long resultSize; - ResultSet results = null; + ResultSet results; boolean isCalculationCompleted = false; StringBuilder aftsQuery = new StringBuilder(); From e1d3469bc56924d05329fd63268ad95e4e4119a2 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 13:11:54 +0530 Subject: [PATCH 036/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java | 2 +- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) 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 4e325eb5380..fca1dfaefc6 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 @@ -158,7 +158,7 @@ public Map createById(String nodeId, Parameters params) folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); actionService.executeAction(folderSizeAction, nodeRef, false, true); LOG.info(" Executing ActionExecutor in NodeFolderSizeRelation:createById "); - result.put("executionId", nodeId); + result.put("nodeId", nodeId); return result; } catch (Exception ex) 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 7aa4c1a59ff..438d31af783 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 @@ -47,8 +47,6 @@ /** * V1 REST API tests for Folder size - * - * @author Mohit Singh */ public class NodeFolderSizeApiTest extends AbstractBaseApiTest { From e5617d8440e13f34cfc40a3e0b08d90de8bb942c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 13:13:16 +0530 Subject: [PATCH 037/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java | 1 - .../alfresco/repo/action/executer/NodeSizeActionExecuter.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) 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 fca1dfaefc6..e495bdb1506 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 @@ -59,7 +59,6 @@ /** * NodeFolderSizeRelation * Calculating and Retrieving the folder size - * @author Mohit Singh */ @RelationshipResource(name = "calculateSize", entityResource = NodesEntityResource.class, title = "Calculate size") diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 2e251555102..ec4e9427351 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -52,8 +52,7 @@ /** * NodeSizeActionExecuter - * Executing Alfresco FTS Query to find size of Folder Node. - * @author Mohit Singh + * Executing Alfresco FTS Query to find size of Folder Node */ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase From 9b0337cb8ad259cf12b9e9f4d3637cd5484fb52d Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 17:21:40 +0530 Subject: [PATCH 038/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/nodes/NodeFolderSizeRelation.java | 8 +++++++- .../rest/api/tests/NodeFolderSizeApiTest.java | 7 +++++-- .../org/alfresco/model/FolderSizeModel.java | 1 + .../action/executer/NodeSizeActionExecuter.java | 17 ++++++++--------- 4 files changed, 21 insertions(+), 12 deletions(-) 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 e495bdb1506..8c67f2c5f20 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 @@ -133,6 +133,7 @@ public Map createById(String nodeId, Parameters params) resetFolderOutput.put("status","IN-PROGRESS"); nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "IN-PROGRESS"); nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) resetFolderOutput); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null); Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); int maxItems = params.getPaging().getMaxItems(); @@ -177,6 +178,7 @@ public Map readById(String nodeId, String id, Parameters paramet Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); QName qName = nodeService.getType(nodeRef); + Map properties = nodeService.getProperties(nodeRef); Map result = new HashMap<>(); if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) @@ -189,10 +191,14 @@ public Map readById(String nodeId, String id, Parameters paramet throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); } + if(properties.containsKey(FolderSizeModel.PROP_ERROR) && properties.get(FolderSizeModel.PROP_ERROR) != null) + { + throw new RuntimeException(String.valueOf(properties.get(FolderSizeModel.PROP_ERROR))); + } + try { LOG.info(" Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById "); - Map properties = nodeService.getProperties(nodeRef); if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { result.put("status", "NOT-INITIATED"); 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 438d31af783..69dbf091a6a 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 @@ -34,7 +34,9 @@ import org.alfresco.service.cmr.site.SiteVisibility; import org.junit.After; import org.junit.Before; +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,6 +50,7 @@ /** * V1 REST API tests for Folder size */ +@FixMethodOrder (MethodSorters.NAME_ASCENDING) public class NodeFolderSizeApiTest extends AbstractBaseApiTest { @@ -91,7 +94,7 @@ public void setup() throws Exception * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} */ @Test - public void testPostCalculateFolderSize() throws Exception + public void testAPostCalculateFolderSize() throws Exception { setRequestContext(user1); @@ -118,7 +121,7 @@ public void testPostCalculateFolderSize() throws Exception * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} */ @Test - public void testGetCalculateFolderSize() throws Exception + public void testBGetCalculateFolderSize() throws Exception { setRequestContext(user1); diff --git a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java index 704eb53553d..e5e187fb209 100644 --- a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java +++ b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java @@ -35,4 +35,5 @@ public class FolderSizeModel private static final String SIZE_MODEL_1_0_URI = "http://www.alfresco.org/model/size/1.0"; public static final QName PROP_STATUS = QName.createQName(SIZE_MODEL_1_0_URI, "status"); public static final QName PROP_OUTPUT = QName.createQName(SIZE_MODEL_1_0_URI, "result"); + public static final QName PROP_ERROR = QName.createQName(SIZE_MODEL_1_0_URI, "error"); } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ec4e9427351..c9221821de0 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -111,6 +111,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) catch (NumberFormatException e) { LOG.error("Exception occurred while parsing String to INT: {}", e.getMessage()); + nodeService.setProperty(actionedUponNodeRef, FolderSizeModel.PROP_ERROR,e.getMessage()); throw e; } @@ -133,28 +134,26 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) { // executing Alfresco FTS query. results = searchService.query(searchParameters); - List nodeRefs = results.getNodeRefs(); int skipCount = 0; int totalItems; - totalItems = Math.min(nodeRefs.size(), maxItems); + totalItems = Math.min(results.getNodeRefs().size(), maxItems); while (!isCalculationCompleted) { - List subList = nodeRefs.subList(skipCount, totalItems); - resultSize = subList.parallelStream() - .map(id -> ((ContentData) nodeService.getProperty(id, ContentModel.PROP_CONTENT)).getSize()) - .reduce(0L, Long::sum); + resultSize = results.getNodeRefs().subList(skipCount,totalItems).parallelStream() + .map(id -> nodeService.getProperty(id, ContentModel.PROP_CONTENT)!=null? ((ContentData) nodeService.getProperty(id, ContentModel.PROP_CONTENT)).getSize():0) + .reduce(0L, Long::sum); totalSize+=resultSize; - if (nodeRefs.size() <= totalItems || nodeRefs.size() <= maxItems) + if (results.getNodeRefs().size() <= totalItems || results.getNodeRefs().size() <= maxItems) { isCalculationCompleted = true; } else { skipCount += maxItems; - int remainingItems = nodeRefs.size() - totalItems; + int remainingItems = results.getNodeRefs().size() - totalItems; totalItems += Math.min(remainingItems, maxItems); } } @@ -162,6 +161,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) catch (RuntimeException ex) { LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", ex.getMessage()); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,ex.getMessage()); throw ex; } @@ -177,7 +177,6 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) if(isCalculationCompleted) { nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) response); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "COMPLETED"); } } From b1ad2780b9b8bcd8ec6756614d203c75bcdb804c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 17:22:02 +0530 Subject: [PATCH 039/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../alfresco/repo/action/executer/NodeSizeActionExecuter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index c9221821de0..f61b42c2f44 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -28,7 +28,6 @@ import org.alfresco.model.ContentModel; import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.ParameterizedItemAbstractBase; -import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.repository.ContentData; From 95e256bfe55ec8b4a88028547efd540ac36c226a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 17:45:43 +0530 Subject: [PATCH 040/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) 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 8c67f2c5f20..451d6bdafb6 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 @@ -131,7 +131,6 @@ public Map createById(String nodeId, Parameters params) NodeRef nodeRef = nodes.validateNode(nodeId); Map resetFolderOutput = new HashMap<>(); resetFolderOutput.put("status","IN-PROGRESS"); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "IN-PROGRESS"); nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) resetFolderOutput); nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null); Node nodeInfo = nodes.getNode(nodeId); @@ -177,48 +176,55 @@ public Map readById(String nodeId, String id, Parameters paramet NodeRef nodeRef = nodes.validateNode(nodeId); Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); - QName qName = nodeService.getType(nodeRef); - Map properties = nodeService.getProperties(nodeRef); - Map result = new HashMap<>(); + // Validate permissions. if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { throw new AccessDeniedException("permissions.err_access_denied"); } - if(!"folder".equals(qName.getLocalName())) + // Check node type. + QName qName = nodeService.getType(nodeRef); + if (!"folder".equals(qName.getLocalName())) { throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); } - if(properties.containsKey(FolderSizeModel.PROP_ERROR) && properties.get(FolderSizeModel.PROP_ERROR) != null) + // Check for specific properties + Map properties = nodeService.getProperties(nodeRef); + if (properties.containsKey(FolderSizeModel.PROP_ERROR) && properties.get(FolderSizeModel.PROP_ERROR) != null) { - throw new RuntimeException(String.valueOf(properties.get(FolderSizeModel.PROP_ERROR))); + throw new InvalidNodeTypeException(String.valueOf(properties.get(FolderSizeModel.PROP_ERROR))); } + // Process properties and return result. try { - LOG.info(" Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById "); + LOG.info("Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById"); + Map result = new HashMap<>(); if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { result.put("status", "NOT-INITIATED"); } - else if (!properties.containsKey(FolderSizeModel.PROP_OUTPUT)) - { - result.put("status", "IN-PROGRESS"); - } - else + else if(properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { Map mapResult = (Map) properties.get(FolderSizeModel.PROP_OUTPUT); - mapResult.put("status", "COMPLETED"); - result = mapResult; + if(mapResult.get(0).toString().contains("IN-PROGRESS")) + { + result.put("status", "IN-PROGRESS"); + } + else + { + mapResult.put("status", "COMPLETED"); + result = mapResult; + } } return result; } catch (Exception ex) { LOG.error("Exception occurred in NodeFolderSizeRelation:readById {}", ex.getMessage()); - throw ex;// This rethrows with the original stack trace preserved. + throw ex; // Rethrow with original stack trace } } } \ No newline at end of file From a16ac952b316e9546cef06e9ed64bb7da3e48ca0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 18:15:05 +0530 Subject: [PATCH 041/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../alfresco/rest/api/nodes/NodeFolderSizeRelation.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 451d6bdafb6..dac3abe0fd9 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 @@ -202,14 +202,17 @@ public Map readById(String nodeId, String id, Parameters paramet { LOG.info("Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById"); Map result = new HashMap<>(); + if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { result.put("status", "NOT-INITIATED"); } - else if(properties.containsKey(FolderSizeModel.PROP_OUTPUT)) + else { Map mapResult = (Map) properties.get(FolderSizeModel.PROP_OUTPUT); - if(mapResult.get(0).toString().contains("IN-PROGRESS")) + Object status = mapResult.get("status"); + + if (status != null && status.toString().contains("IN-PROGRESS")) { result.put("status", "IN-PROGRESS"); } @@ -227,4 +230,5 @@ else if(properties.containsKey(FolderSizeModel.PROP_OUTPUT)) throw ex; // Rethrow with original stack trace } } + } \ No newline at end of file From 9d9d5ee599e68849d414eaf37f81fa0205bb4cd6 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 26 Jun 2024 23:24:25 +0530 Subject: [PATCH 042/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 69 ++++++++++--------- .../executer/NodeSizeActionExecuterTest.java | 7 +- 2 files changed, 41 insertions(+), 35 deletions(-) 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 dac3abe0fd9..9889dbd2df3 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 @@ -130,19 +130,14 @@ public Map createById(String nodeId, Parameters params) { NodeRef nodeRef = nodes.validateNode(nodeId); Map resetFolderOutput = new HashMap<>(); - resetFolderOutput.put("status","IN-PROGRESS"); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) resetFolderOutput); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null); - Node nodeInfo = nodes.getNode(nodeId); - NodePermissions nodePerms = nodeInfo.getPermissions(); int maxItems = params.getPaging().getMaxItems(); QName qName = nodeService.getType(nodeRef); Map result = new HashMap<>(); + resetFolderOutput.put("status","IN-PROGRESS"); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) resetFolderOutput); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null); - if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) - { - throw new AccessDeniedException("permissions.err_access_denied"); - } + validatePermissions(nodeRef, nodeId); if(!"folder".equals(qName.getLocalName())) { @@ -174,33 +169,13 @@ public Map createById(String nodeId, Parameters params) public Map readById(String nodeId, String id, Parameters parameters) { NodeRef nodeRef = nodes.validateNode(nodeId); - Node nodeInfo = nodes.getNode(nodeId); - NodePermissions nodePerms = nodeInfo.getPermissions(); - - // Validate permissions. - if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) - { - throw new AccessDeniedException("permissions.err_access_denied"); - } - - // Check node type. - QName qName = nodeService.getType(nodeRef); - if (!"folder".equals(qName.getLocalName())) - { - throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); - } - - // Check for specific properties - Map properties = nodeService.getProperties(nodeRef); - if (properties.containsKey(FolderSizeModel.PROP_ERROR) && properties.get(FolderSizeModel.PROP_ERROR) != null) - { - throw new InvalidNodeTypeException(String.valueOf(properties.get(FolderSizeModel.PROP_ERROR))); - } + validatePermissions(nodeRef, nodeId); + validateNodeType(nodeRef); - // Process properties and return result. try { LOG.info("Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById"); + Map properties = nodeService.getProperties(nodeRef); Map result = new HashMap<>(); if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) @@ -231,4 +206,34 @@ public Map readById(String nodeId, String id, Parameters paramet } } + private void validatePermissions(NodeRef nodeRef, String nodeId) + { + Node nodeInfo = nodes.getNode(nodeId); + NodePermissions nodePerms = nodeInfo.getPermissions(); + + // Validate permissions. + if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) + { + throw new AccessDeniedException("permissions.err_access_denied"); + } + } + + private void validateNodeType(NodeRef nodeRef) + { + // Check node type. + QName qName = nodeService.getType(nodeRef); + + if (!"folder".equals(qName.getLocalName())) + { + throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); + } + + // Check for specific properties + Map properties = nodeService.getProperties(nodeRef); + if (properties.containsKey(FolderSizeModel.PROP_ERROR) && properties.get(FolderSizeModel.PROP_ERROR) != null) + { + throw new InvalidNodeTypeException(String.valueOf(properties.get(FolderSizeModel.PROP_ERROR))); + } + } + } \ No newline at end of file diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index 0ca562efd22..9048e3a8618 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -25,6 +25,8 @@ */ package org.alfresco.repo.action.executer; +import java.util.Map; + import org.alfresco.model.ContentModel; import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.ActionImpl; @@ -98,12 +100,11 @@ public void before() throws Exception @Test public void testExecution() { - assertEquals(1,1); int maxItems = 100; ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null); action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); this.executer.executeImpl(action, this.nodeRef); - String compareString = this.nodeService.getProperty(this.nodeRef, FolderSizeModel.PROP_STATUS).toString(); - assertTrue(compareString != null); + Map mapResult = (Map)this.nodeService.getProperty(this.nodeRef, FolderSizeModel.PROP_OUTPUT); + assertTrue(mapResult != null); } } From c3e03ca837c3f3e568a8ae45be5c15d1dbb83271 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 10:41:36 +0530 Subject: [PATCH 043/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 4 +-- .../rest/api/tests/NodeFolderSizeApiTest.java | 4 +++ .../executer/NodeSizeActionExecuter.java | 27 ++++++++++++++----- 3 files changed, 26 insertions(+), 9 deletions(-) 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 9889dbd2df3..2897bb05e9e 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 @@ -135,7 +135,6 @@ public Map createById(String nodeId, Parameters params) Map result = new HashMap<>(); resetFolderOutput.put("status","IN-PROGRESS"); nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) resetFolderOutput); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null); validatePermissions(nodeRef, nodeId); @@ -164,8 +163,7 @@ public Map createById(String nodeId, Parameters params) @Override @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") - @WebApiParameters({ - @WebApiParam(name = "nodeId", title = "The unique id of the Node being addressed", description = "A single node id")}) + @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of the Node being addressed", description = "A single node id")}) public Map readById(String nodeId, String id, Parameters parameters) { NodeRef nodeRef = nodes.validateNode(nodeId); 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 69dbf091a6a..23297d891bb 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 @@ -40,13 +40,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; import static org.junit.Assert.assertNotNull; +import javax.validation.constraints.AssertTrue; + /** * V1 REST API tests for Folder size */ diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index f61b42c2f44..47ed8b433e1 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -48,6 +48,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; /** * NodeSizeActionExecuter @@ -116,7 +117,6 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) NodeRef nodeRef = actionedUponNodeRef; long totalSize = 0; - long resultSize; ResultSet results; boolean isCalculationCompleted = false; @@ -139,11 +139,25 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) while (!isCalculationCompleted) { - resultSize = results.getNodeRefs().subList(skipCount,totalItems).parallelStream() - .map(id -> nodeService.getProperty(id, ContentModel.PROP_CONTENT)!=null? ((ContentData) nodeService.getProperty(id, ContentModel.PROP_CONTENT)).getSize():0) - .reduce(0L, Long::sum); - - totalSize+=resultSize; + List nodeRefs = results.getNodeRefs().subList(skipCount, totalItems); + // Using AtomicLong to accumulate the total size. + AtomicLong resultSize = new AtomicLong(0); + nodeRefs.parallelStream().forEach(id -> { + try + { + ContentData contentData = (ContentData) nodeService.getProperty(id, ContentModel.PROP_CONTENT); + if (contentData != null) + { + resultSize.addAndGet(contentData.getSize()); + } + } + catch (Exception e) + { + resultSize.addAndGet(0); + } + }); + + totalSize+=resultSize.longValue(); if (results.getNodeRefs().size() <= totalItems || results.getNodeRefs().size() <= maxItems) { @@ -176,6 +190,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) if(isCalculationCompleted) { nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) response); + nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null); } } From 2deb4f428fc8a008738753cdebcd594e725dc6b7 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 10:41:58 +0530 Subject: [PATCH 044/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 3 --- 1 file changed, 3 deletions(-) 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 23297d891bb..7c86b50be05 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 @@ -39,10 +39,7 @@ import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.UUID; From c2a5948a024c92ef2f3883a85d14c45960294264 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 10:42:15 +0530 Subject: [PATCH 045/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 -- 1 file changed, 2 deletions(-) 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 7c86b50be05..b3a28e8e466 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 @@ -46,8 +46,6 @@ import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; import static org.junit.Assert.assertNotNull; -import javax.validation.constraints.AssertTrue; - /** * V1 REST API tests for Folder size */ From 44ecf9fc4c9031521e235b04be210ba8f3c25be0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 11:14:34 +0530 Subject: [PATCH 046/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../alfresco/repo/action/executer/NodeSizeActionExecuter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 47ed8b433e1..8b16eff3b11 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -200,6 +200,6 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) @Override protected void addParameterDefinitions(List paramList) { - // Intentionally empty + // Intentionally empty. } } From 5deb2b470ffaa3e9b26ef92db5f3cb50d2eec9d0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 12:00:57 +0530 Subject: [PATCH 047/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- repository/src/test/java/org/alfresco/AppContext01TestSuite.java | 1 + 1 file changed, 1 insertion(+) diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index aa9e4e3a210..c7f78a960c4 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -77,6 +77,7 @@ org.alfresco.repo.activities.feed.cleanup.FeedCleanerTestCaseSensitivity.class, org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, + org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, org.alfresco.repo.action.executer.NodeSizeActionExecuterTest.class }) public class AppContext01TestSuite From 63d6de76c4941a9230b0316ed3a0e9441fa8eaf7 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 12:13:17 +0530 Subject: [PATCH 048/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../src/test/java/org/alfresco/AppContext01TestSuite.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index 147626480aa..c7f78a960c4 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -77,7 +77,8 @@ org.alfresco.repo.activities.feed.cleanup.FeedCleanerTestCaseSensitivity.class, org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, - org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class + org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, + org.alfresco.repo.action.executer.NodeSizeActionExecuterTest.class }) public class AppContext01TestSuite { From 9d313bd6b3740a95e2581691674e8fad4f917d1a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 18:03:12 +0530 Subject: [PATCH 049/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) 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 b3a28e8e466..8d46f12794a 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 @@ -25,13 +25,23 @@ */ package org.alfresco.rest.api.tests; +import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.rest.api.model.ContentInfo; +import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.util.RestApiUtil; +import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.cmr.repository.MimetypeService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; import org.junit.After; import org.junit.Before; import org.junit.FixMethodOrder; @@ -39,6 +49,11 @@ import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -60,6 +75,10 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest protected PermissionService permissionService; + private NodeService nodeService; + + private MimetypeService mimeTypeService; + /** * The logger */ @@ -85,6 +104,8 @@ public void setup() throws Exception { super.setup(); permissionService = applicationContext.getBean("permissionService", PermissionService.class); + nodeService = applicationContext.getBean("NodeService", NodeService.class); + mimeTypeService = applicationContext.getBean("MimetypeService", MimetypeService.class); } /** @@ -114,6 +135,71 @@ public void testAPostCalculateFolderSize() throws Exception assertNotNull(contentNodeId); } + /** + * Test case to trigger POST/calculateSize with >200 Children Nodes. + * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} + */ + @Test + public void testPerformance() throws Exception + { + setRequestContext(user1); + Node n; + + // Logging initial time. + LocalDateTime eventTimestamp = LocalDateTime.now(); + String formattedTimestamp = eventTimestamp.format(DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss")); + LOG.info(" ********** In NodeFolderSizeApiTest:testPerformance Initial Time : {}", formattedTimestamp); + + String siteTitle = "RandomSite" + System.currentTimeMillis(); + userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + + // Create a folder within the site document's library. + String folderName = "folder" + System.currentTimeMillis(); + String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); + NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,folderId); + QName qName = nodeService.getType(nodeRef); + + for(int i =0;i<300;i++) + { + n = new Node(); + n.setName("c1" + RUNID); + n.setNodeType(TYPE_CM_FOLDER); + QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(n.getName())); + + if(i%7==0) + { + for(int j =0 ; j<=5; j++) + { + n = new Node(); + n.setName("c2" + RUNID); + n.setNodeType(TYPE_CM_CONTENT); + ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10L, null); + String mimeType = contentData.getMimetype(); + String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType); + ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, contentData.getSize(),contentData.getEncoding()); + n.setContent(contentInfo); + QName assocChildQNameInternal = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(n.getName())); + nodeService.addChild(n.getNodeRef(), new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, n.getName()), qName, assocChildQNameInternal); + } + } + nodeService.addChild(nodeRef, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, n.getName()), qName, assocChildQName); + } + Map params = new HashMap<>(); + params.put("nodeId",folderId); + params.put("maxItems","100"); + + HttpResponse response = post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); + String contentNodeId = document.toString(); + if(contentNodeId != null) + { + eventTimestamp = LocalDateTime.now(); + formattedTimestamp = eventTimestamp.format(DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss")); + LOG.info(" ********** In NodeFolderSizeApiTest:testPerformance Completed Time : {}", formattedTimestamp); + } + assertNotNull(contentNodeId); + } + /** * Test case for GET/calculateSize, to retrieve FolderSize. *

GET:

From 5e024c95c2aaa2f53504ee3d943287d58e86c2be Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 18:28:59 +0530 Subject: [PATCH 050/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) 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 8d46f12794a..6f651048a79 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 @@ -79,6 +79,10 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest private MimetypeService mimeTypeService; + private String folderName; + + private String folderId; + /** * The logger */ @@ -119,11 +123,11 @@ public void testAPostCalculateFolderSize() throws Exception setRequestContext(user1); String siteTitle = "RandomSite" + System.currentTimeMillis(); - userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + this.userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); // Create a folder within the site document's library. - String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); + this.folderName = "folder" + System.currentTimeMillis(); + this.folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); Map params = new HashMap<>(); params.put("nodeId",folderId); @@ -148,7 +152,7 @@ public void testPerformance() throws Exception // Logging initial time. LocalDateTime eventTimestamp = LocalDateTime.now(); String formattedTimestamp = eventTimestamp.format(DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss")); - LOG.info(" ********** In NodeFolderSizeApiTest:testPerformance Initial Time : {}", formattedTimestamp); + System.out.println(" ********** In NodeFolderSizeApiTest:testPerformance Initial Time :"+formattedTimestamp); String siteTitle = "RandomSite" + System.currentTimeMillis(); userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); @@ -157,7 +161,7 @@ public void testPerformance() throws Exception String folderName = "folder" + System.currentTimeMillis(); String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,folderId); - QName qName = nodeService.getType(nodeRef); + QName qName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeRef.getId())); for(int i =0;i<300;i++) { @@ -195,7 +199,7 @@ public void testPerformance() throws Exception { eventTimestamp = LocalDateTime.now(); formattedTimestamp = eventTimestamp.format(DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss")); - LOG.info(" ********** In NodeFolderSizeApiTest:testPerformance Completed Time : {}", formattedTimestamp); + System.out.println(" ********** In NodeFolderSizeApiTest:testPerformance Completed Time :"+formattedTimestamp); } assertNotNull(contentNodeId); } @@ -210,19 +214,9 @@ public void testBGetCalculateFolderSize() throws Exception { setRequestContext(user1); - String siteTitle = "RandomSite" + System.currentTimeMillis(); - userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); - - // Create a folder within the site document's library. - String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); - - Map params = new HashMap<>(); - params.put("nodeId",folderId); - AuthenticationUtil.setFullyAuthenticatedUser(user1); - HttpResponse response = getSingle(getFolderSizeUrl(folderId), null, 200); + HttpResponse response = getSingle(getFolderSizeUrl(this.folderId), null, 200); Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); String contentNodeId = document.toString(); assertNotNull(contentNodeId); From 6aaa24d9d6facf50b30fedc58c4059d4118feb3a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 19:05:16 +0530 Subject: [PATCH 051/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) 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 6f651048a79..def848a26a4 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 @@ -43,6 +43,7 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Test; @@ -81,7 +82,7 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest private String folderName; - private String folderId; + private static String folderId; /** * The logger @@ -147,12 +148,12 @@ public void testAPostCalculateFolderSize() throws Exception public void testPerformance() throws Exception { setRequestContext(user1); - Node n; + Node parentNodes; // Logging initial time. LocalDateTime eventTimestamp = LocalDateTime.now(); String formattedTimestamp = eventTimestamp.format(DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss")); - System.out.println(" ********** In NodeFolderSizeApiTest:testPerformance Initial Time :"+formattedTimestamp); + LOG.info(" ********** In NodeFolderSizeApiTest:testPerformance Initial Time :{}", formattedTimestamp); String siteTitle = "RandomSite" + System.currentTimeMillis(); userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); @@ -165,28 +166,28 @@ public void testPerformance() throws Exception for(int i =0;i<300;i++) { - n = new Node(); - n.setName("c1" + RUNID); - n.setNodeType(TYPE_CM_FOLDER); - QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(n.getName())); + parentNodes = new Node(); + parentNodes.setName("c1" + RUNID); + parentNodes.setNodeType(TYPE_CM_FOLDER); + QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(parentNodes.getName())); if(i%7==0) { for(int j =0 ; j<=5; j++) { - n = new Node(); - n.setName("c2" + RUNID); - n.setNodeType(TYPE_CM_CONTENT); + Node childNodes = new Node(); + childNodes.setName("c2" + RUNID); + childNodes.setNodeType(TYPE_CM_CONTENT); ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10L, null); String mimeType = contentData.getMimetype(); String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType); ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, contentData.getSize(),contentData.getEncoding()); - n.setContent(contentInfo); - QName assocChildQNameInternal = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(n.getName())); - nodeService.addChild(n.getNodeRef(), new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, n.getName()), qName, assocChildQNameInternal); + childNodes.setContent(contentInfo); + QName assocChildQNameInternal = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(childNodes.getName())); + nodeService.addChild(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentNodes.getNodeId()), new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, childNodes.getName()), qName, assocChildQNameInternal); } } - nodeService.addChild(nodeRef, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, n.getName()), qName, assocChildQName); + nodeService.addChild(nodeRef, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, parentNodes.getName()), qName, assocChildQName); } Map params = new HashMap<>(); params.put("nodeId",folderId); @@ -199,7 +200,7 @@ public void testPerformance() throws Exception { eventTimestamp = LocalDateTime.now(); formattedTimestamp = eventTimestamp.format(DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss")); - System.out.println(" ********** In NodeFolderSizeApiTest:testPerformance Completed Time :"+formattedTimestamp); + LOG.info(" ********** In NodeFolderSizeApiTest:testPerformance Completed Time :{}", formattedTimestamp); } assertNotNull(contentNodeId); } From 9180053a2938dbddbd8e43c1f08b79d0c89bdbb1 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 23:08:14 +0530 Subject: [PATCH 052/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 90 +++++++++++-------- 1 file changed, 54 insertions(+), 36 deletions(-) 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 def848a26a4..1a5be5b70cc 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 @@ -43,17 +43,16 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.time.Instant; import java.time.LocalDateTime; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; @@ -66,6 +65,7 @@ * V1 REST API tests for Folder size */ @FixMethodOrder (MethodSorters.NAME_ASCENDING) +@RunWith (JUnit4.class) public class NodeFolderSizeApiTest extends AbstractBaseApiTest { @@ -80,8 +80,6 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest private MimetypeService mimeTypeService; - private String folderName; - private static String folderId; /** @@ -111,6 +109,15 @@ public void setup() throws Exception permissionService = applicationContext.getBean("permissionService", PermissionService.class); nodeService = applicationContext.getBean("NodeService", NodeService.class); mimeTypeService = applicationContext.getBean("MimetypeService", MimetypeService.class); + + setRequestContext(user1); + + String siteTitle = "RandomSite" + System.currentTimeMillis(); + this.userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + + // Create a folder within the site document's library. + String folderName = "folder" + System.currentTimeMillis(); + folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); } /** @@ -119,25 +126,54 @@ public void setup() throws Exception * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} */ @Test - public void testAPostCalculateFolderSize() throws Exception - { - setRequestContext(user1); + public void testAPostCalculateFolderSize() throws Exception { + // Prepare parameters + Map params = new HashMap<>(); + params.put("nodeId", folderId); + params.put("maxItems", "100"); - String siteTitle = "RandomSite" + System.currentTimeMillis(); - this.userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + // Perform POST request + HttpResponse response = post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + // Validate response and parsed document + assertNotNull("Response should not be null", response); - // Create a folder within the site document's library. - this.folderName = "folder" + System.currentTimeMillis(); - this.folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); + String jsonResponse = String.valueOf(response.getJsonResponse()); + assertNotNull("JSON response should not be null", jsonResponse); - Map params = new HashMap<>(); - params.put("nodeId",folderId); - params.put("maxItems","100"); + // Parse JSON response + Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); + assertNotNull("Parsed document should not be null", document); - HttpResponse response = post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + // Convert document to string and validate contentNodeId + String contentNodeId = document.toString(); + assertNotNull("Content node ID should not be null", contentNodeId); + } + + + /** + * Test case for GET/calculateSize, to retrieve FolderSize. + *

GET:

+ * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} + */ + @Test + public void testBGetCalculateFolderSize() throws Exception + { + AuthenticationUtil.setFullyAuthenticatedUser(user1); + + // Check if response and JSON parsing were successful + HttpResponse response = getSingle(getFolderSizeUrl(folderId), null, 200); + assertNotNull(response); + + String jsonResponse = String.valueOf(response.getJsonResponse()); + assertNotNull("JSON response should not be null", jsonResponse); + + // Parse the JSON response. Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); + assertNotNull("Parsed document should not be null", document); + + // Convert document to string and verify contentNodeId. String contentNodeId = document.toString(); - assertNotNull(contentNodeId); + assertNotNull("Content node ID should not be null", contentNodeId); } /** @@ -205,24 +241,6 @@ public void testPerformance() throws Exception assertNotNull(contentNodeId); } - /** - * Test case for GET/calculateSize, to retrieve FolderSize. - *

GET:

- * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} - */ - @Test - public void testBGetCalculateFolderSize() throws Exception - { - setRequestContext(user1); - - AuthenticationUtil.setFullyAuthenticatedUser(user1); - - HttpResponse response = getSingle(getFolderSizeUrl(this.folderId), null, 200); - Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); - String contentNodeId = document.toString(); - assertNotNull(contentNodeId); - } - /** * Test case for others HTTP status codes. */ From 8424c1b90ae2e7f0a4dc7ad3ce40c95773dff438 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 23:29:38 +0530 Subject: [PATCH 053/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 13 ------------- 1 file changed, 13 deletions(-) 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 1a5be5b70cc..cf98d9cd0df 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 @@ -183,7 +183,6 @@ public void testBGetCalculateFolderSize() throws Exception @Test public void testPerformance() throws Exception { - setRequestContext(user1); Node parentNodes; // Logging initial time. @@ -191,9 +190,6 @@ public void testPerformance() throws Exception String formattedTimestamp = eventTimestamp.format(DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss")); LOG.info(" ********** In NodeFolderSizeApiTest:testPerformance Initial Time :{}", formattedTimestamp); - String siteTitle = "RandomSite" + System.currentTimeMillis(); - userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); - // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); @@ -247,15 +243,6 @@ public void testPerformance() throws Exception @Test public void testHTTPStatus() throws Exception { - - setRequestContext(user1); - String siteTitle = "RandomSite" + System.currentTimeMillis(); - userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); - - // Create a folder within the site document's library. - String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); - setRequestContext(null); delete(getFolderSizeUrl(folderId), folderId, null, 401); From d4ef7246488ee934cf594e35dbb5abaa89df4a92 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 27 Jun 2024 23:51:50 +0530 Subject: [PATCH 054/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 cf98d9cd0df..074c40dc35d 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 @@ -200,6 +200,7 @@ public void testPerformance() throws Exception { parentNodes = new Node(); parentNodes.setName("c1" + RUNID); + parentNodes.setNodeId("folder1"+RUNID); parentNodes.setNodeType(TYPE_CM_FOLDER); QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(parentNodes.getName())); @@ -219,7 +220,7 @@ public void testPerformance() throws Exception nodeService.addChild(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentNodes.getNodeId()), new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, childNodes.getName()), qName, assocChildQNameInternal); } } - nodeService.addChild(nodeRef, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, parentNodes.getName()), qName, assocChildQName); + nodeService.addChild(nodeRef, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, parentNodes.getNodeId()), qName, assocChildQName); } Map params = new HashMap<>(); params.put("nodeId",folderId); From dfcfa87680d4c6caa83104845bdc34f5fd37e56e Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 28 Jun 2024 00:15:00 +0530 Subject: [PATCH 055/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 074c40dc35d..793a61764ff 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 @@ -210,6 +210,7 @@ public void testPerformance() throws Exception { Node childNodes = new Node(); childNodes.setName("c2" + RUNID); + childNodes.setNodeId("doc"+RUNID); childNodes.setNodeType(TYPE_CM_CONTENT); ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10L, null); String mimeType = contentData.getMimetype(); @@ -217,7 +218,7 @@ public void testPerformance() throws Exception ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, contentData.getSize(),contentData.getEncoding()); childNodes.setContent(contentInfo); QName assocChildQNameInternal = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(childNodes.getName())); - nodeService.addChild(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentNodes.getNodeId()), new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, childNodes.getName()), qName, assocChildQNameInternal); + nodeService.addChild(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentNodes.getNodeId()), new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, childNodes.getNodeId()), qName, assocChildQNameInternal); } } nodeService.addChild(nodeRef, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, parentNodes.getNodeId()), qName, assocChildQName); From 5ec06091eab42c587ba1f9f93af5ee71e0774f81 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 28 Jun 2024 08:13:52 +0530 Subject: [PATCH 056/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 793a61764ff..c58f86e94dd 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 @@ -201,6 +201,7 @@ public void testPerformance() throws Exception parentNodes = new Node(); parentNodes.setName("c1" + RUNID); parentNodes.setNodeId("folder1"+RUNID); + parentNodes.setNodeRef(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentNodes.getNodeId())); parentNodes.setNodeType(TYPE_CM_FOLDER); QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(parentNodes.getName())); @@ -212,16 +213,17 @@ public void testPerformance() throws Exception childNodes.setName("c2" + RUNID); childNodes.setNodeId("doc"+RUNID); childNodes.setNodeType(TYPE_CM_CONTENT); + childNodes.setNodeRef(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, childNodes.getNodeId())); ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10L, null); String mimeType = contentData.getMimetype(); String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType); ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, contentData.getSize(),contentData.getEncoding()); childNodes.setContent(contentInfo); QName assocChildQNameInternal = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(childNodes.getName())); - nodeService.addChild(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentNodes.getNodeId()), new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, childNodes.getNodeId()), qName, assocChildQNameInternal); + nodeService.addChild(parentNodes.getNodeRef(), childNodes.getNodeRef(), qName, assocChildQNameInternal); } } - nodeService.addChild(nodeRef, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, parentNodes.getNodeId()), qName, assocChildQName); + nodeService.addChild(nodeRef, parentNodes.getNodeRef(), qName, assocChildQName); } Map params = new HashMap<>(); params.put("nodeId",folderId); From ef4d1d8437723832ed32877a7f7012ebe1e3182c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 28 Jun 2024 08:54:14 +0530 Subject: [PATCH 057/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) 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 c58f86e94dd..9250ba59562 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 @@ -203,26 +203,12 @@ public void testPerformance() throws Exception parentNodes.setNodeId("folder1"+RUNID); parentNodes.setNodeRef(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentNodes.getNodeId())); parentNodes.setNodeType(TYPE_CM_FOLDER); + ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10L, null); + String mimeType = contentData.getMimetype(); + String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType); + ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, contentData.getSize(),contentData.getEncoding()); + parentNodes.setContent(contentInfo); QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(parentNodes.getName())); - - if(i%7==0) - { - for(int j =0 ; j<=5; j++) - { - Node childNodes = new Node(); - childNodes.setName("c2" + RUNID); - childNodes.setNodeId("doc"+RUNID); - childNodes.setNodeType(TYPE_CM_CONTENT); - childNodes.setNodeRef(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, childNodes.getNodeId())); - ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10L, null); - String mimeType = contentData.getMimetype(); - String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType); - ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, contentData.getSize(),contentData.getEncoding()); - childNodes.setContent(contentInfo); - QName assocChildQNameInternal = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(childNodes.getName())); - nodeService.addChild(parentNodes.getNodeRef(), childNodes.getNodeRef(), qName, assocChildQNameInternal); - } - } nodeService.addChild(nodeRef, parentNodes.getNodeRef(), qName, assocChildQName); } Map params = new HashMap<>(); From 2b2a754a1fef33cab9d302738b5d13e831e9691a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 28 Jun 2024 11:37:51 +0530 Subject: [PATCH 058/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) 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 9250ba59562..29e97febb23 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 @@ -32,6 +32,7 @@ import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; +import org.alfresco.rest.api.tests.client.data.Folder; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.MimetypeService; @@ -192,30 +193,32 @@ public void testPerformance() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); - NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,folderId); + String parentFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); + NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentFolderId); QName qName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeRef.getId())); for(int i =0;i<300;i++) { - parentNodes = new Node(); - parentNodes.setName("c1" + RUNID); - parentNodes.setNodeId("folder1"+RUNID); - parentNodes.setNodeRef(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentNodes.getNodeId())); - parentNodes.setNodeType(TYPE_CM_FOLDER); + Folder folder = createFolder(parentFolderId,"c1" + RUNID); ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10L, null); String mimeType = contentData.getMimetype(); String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType); - ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, contentData.getSize(),contentData.getEncoding()); - parentNodes.setContent(contentInfo); - QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(parentNodes.getName())); - nodeService.addChild(nodeRef, parentNodes.getNodeRef(), qName, assocChildQName); + org.alfresco.rest.api.tests.client.data.ContentInfo contentInfo1 = new org.alfresco.rest.api.tests.client.data.ContentInfo(); + contentInfo1.setEncoding(contentData.getEncoding()); + contentInfo1.setSizeInBytes(contentData.getSize()); + contentInfo1.setMimeType(mimeType); + contentInfo1.setMimeTypeName(mimeTypeName); + folder.setContent(contentInfo1); + String folderID = addToDocumentLibrary(userOneN1Site, folder.getName(), TYPE_CM_FOLDER); + NodeRef folderNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,folderID); + QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(folder.getName())); + nodeService.addChild(nodeRef, folderNodeRef , qName, assocChildQName); } Map params = new HashMap<>(); - params.put("nodeId",folderId); + params.put("nodeId",parentFolderId); params.put("maxItems","100"); - HttpResponse response = post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + HttpResponse response = post(getFolderSizeUrl(parentFolderId), toJsonAsStringNonNull(params), 202); Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); String contentNodeId = document.toString(); if(contentNodeId != null) From 6040b138ef6751af7cd7f48dcc9b423951a202d0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 14:15:24 +0530 Subject: [PATCH 059/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 77 ++++++++++++------ .../alfresco/public-rest-context.xml | 1 + .../rest/api/tests/NodeFolderSizeApiTest.java | 79 +++---------------- .../executer/NodeSizeActionExecuter.java | 4 +- 4 files changed, 68 insertions(+), 93 deletions(-) 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 2897bb05e9e..c7a82c5159f 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 @@ -37,10 +37,15 @@ import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.CalculateSize; +import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.ReadById; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.service.ServiceRegistry; 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.alfresco.service.cmr.search.SearchService; @@ -54,6 +59,7 @@ import org.springframework.extensions.webscripts.Status; import java.io.Serializable; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -62,7 +68,7 @@ */ @RelationshipResource(name = "calculateSize", entityResource = NodesEntityResource.class, title = "Calculate size") -public class NodeFolderSizeRelation implements RelationshipResourceAction.CalculateSize>,RelationshipResourceAction.ReadById>, InitializingBean +public class NodeFolderSizeRelation implements CalculateSize>, ReadById>, InitializingBean { private Nodes nodes; private SearchService searchService; @@ -70,6 +76,8 @@ public class NodeFolderSizeRelation implements RelationshipResourceAction.Calcul private PermissionService permissionService; private NodeService nodeService; private ActionService actionService; + private ActionTrackingService actionTrackingService; + private Action folderSizeAction; private static final String NOT_A_VALID_NODEID = "Node Id does not refer to a valid type [should be of folder type]"; /** @@ -113,6 +121,11 @@ public void afterPropertiesSet() ParameterCheck.mandatory("nodes", this.nodes); } + public void setActionTrackingService(ActionTrackingService actionTrackingService) + { + this.actionTrackingService = actionTrackingService; + } + /** * Folder Size - returns size of a folder. * @@ -122,19 +135,16 @@ public void afterPropertiesSet() * GET/calculateSize endpoint to check if the action's status has been completed, comprising the size of the node in bytes. *

* If NodeId does not exist, EntityNotFoundException (status 404). - * If nodeId does not represent a folder, InvalidNodeTypeException (status 400). + * If nodeId does not represent a folder, InvalidNodeTypeException (status 422). */ @Override @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder", successStatus = Status.STATUS_ACCEPTED) public Map createById(String nodeId, Parameters params) { NodeRef nodeRef = nodes.validateNode(nodeId); - Map resetFolderOutput = new HashMap<>(); - int maxItems = params.getPaging().getMaxItems(); + int maxItems = Math.min(params.getPaging().getMaxItems(), 1000); QName qName = nodeService.getType(nodeRef); Map result = new HashMap<>(); - resetFolderOutput.put("status","IN-PROGRESS"); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) resetFolderOutput); validatePermissions(nodeRef, nodeId); @@ -145,13 +155,16 @@ public Map createById(String nodeId, Parameters params) try { - Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); + folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); folderSizeAction.setTrackStatus(true); folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); + folderSizeAction.setParameterValue(NodeSizeActionExecuter.RESULT, "IN-PROGRESS"); actionService.executeAction(folderSizeAction, nodeRef, false, true); LOG.info(" Executing ActionExecutor in NodeFolderSizeRelation:createById "); - result.put("nodeId", nodeId); + List executionSummaryList = actionTrackingService.getExecutingActions(NodeSizeActionExecuter.NAME); + ExecutionDetails executionDetails = actionTrackingService.getExecutionDetails(executionSummaryList.get(0)); + result.put("executionId", executionDetails.getActionId()); return result; } catch (Exception ex) @@ -167,33 +180,22 @@ public Map createById(String nodeId, Parameters params) public Map readById(String nodeId, String id, Parameters parameters) { NodeRef nodeRef = nodes.validateNode(nodeId); + Object resultAction; + Map result = new HashMap<>(); validatePermissions(nodeRef, nodeId); validateNodeType(nodeRef); try { LOG.info("Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById"); - Map properties = nodeService.getProperties(nodeRef); - Map result = new HashMap<>(); - - if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) + if(folderSizeAction!=null) { - result.put("status", "NOT-INITIATED"); + resultAction = folderSizeAction.getParameterValue(NodeSizeActionExecuter.RESULT); + result = getResult(resultAction); } else { - Map mapResult = (Map) properties.get(FolderSizeModel.PROP_OUTPUT); - Object status = mapResult.get("status"); - - if (status != null && status.toString().contains("IN-PROGRESS")) - { - result.put("status", "IN-PROGRESS"); - } - else - { - mapResult.put("status", "COMPLETED"); - result = mapResult; - } + result.put("status", "NOT-INITIATED"); } return result; } @@ -204,6 +206,31 @@ public Map readById(String nodeId, String id, Parameters paramet } } + private Map getResult(Object resultAction) + { + Map result = new HashMap<>(); + + if (resultAction == null) + { + result.put("status", "NOT-INITIATED"); + } + else + { + Map mapResult = (Map) resultAction; + + if(!mapResult.containsKey("size")) + { + result.put("status", "IN-PROGRESS"); + } + else + { + mapResult.put("status", "COMPLETED"); + result = mapResult; + } + } + return result; + } + private void validatePermissions(NodeRef nodeRef, String nodeId) { Node nodeInfo = nodes.getNode(nodeId); diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index b1c39daa825..c6375177b14 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1776,5 +1776,6 @@ + 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 29e97febb23..a10093d5f3f 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 @@ -25,24 +25,16 @@ */ package org.alfresco.rest.api.tests; -import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.rest.api.model.ContentInfo; -import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; -import org.alfresco.rest.api.tests.client.data.Folder; +import org.alfresco.rest.api.tests.client.data.Node; import org.alfresco.rest.api.tests.util.RestApiUtil; -import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.MimetypeService; -import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; import org.junit.After; import org.junit.Before; import org.junit.FixMethodOrder; @@ -52,15 +44,13 @@ import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; import java.util.UUID; import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * V1 REST API tests for Folder size @@ -150,7 +140,6 @@ public void testAPostCalculateFolderSize() throws Exception { assertNotNull("Content node ID should not be null", contentNodeId); } - /** * Test case for GET/calculateSize, to retrieve FolderSize. *

GET:

@@ -168,6 +157,8 @@ public void testBGetCalculateFolderSize() throws Exception String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); + assertTrue("We are not getting correct response",jsonResponse.contains("size") || jsonResponse.contains("status")); + // Parse the JSON response. Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); @@ -177,59 +168,6 @@ public void testBGetCalculateFolderSize() throws Exception assertNotNull("Content node ID should not be null", contentNodeId); } - /** - * Test case to trigger POST/calculateSize with >200 Children Nodes. - * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} - */ - @Test - public void testPerformance() throws Exception - { - Node parentNodes; - - // Logging initial time. - LocalDateTime eventTimestamp = LocalDateTime.now(); - String formattedTimestamp = eventTimestamp.format(DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss")); - LOG.info(" ********** In NodeFolderSizeApiTest:testPerformance Initial Time :{}", formattedTimestamp); - - // Create a folder within the site document's library. - String folderName = "folder" + System.currentTimeMillis(); - String parentFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); - NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,parentFolderId); - QName qName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeRef.getId())); - - for(int i =0;i<300;i++) - { - Folder folder = createFolder(parentFolderId,"c1" + RUNID); - ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10L, null); - String mimeType = contentData.getMimetype(); - String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType); - org.alfresco.rest.api.tests.client.data.ContentInfo contentInfo1 = new org.alfresco.rest.api.tests.client.data.ContentInfo(); - contentInfo1.setEncoding(contentData.getEncoding()); - contentInfo1.setSizeInBytes(contentData.getSize()); - contentInfo1.setMimeType(mimeType); - contentInfo1.setMimeTypeName(mimeTypeName); - folder.setContent(contentInfo1); - String folderID = addToDocumentLibrary(userOneN1Site, folder.getName(), TYPE_CM_FOLDER); - NodeRef folderNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,folderID); - QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(folder.getName())); - nodeService.addChild(nodeRef, folderNodeRef , qName, assocChildQName); - } - Map params = new HashMap<>(); - params.put("nodeId",parentFolderId); - params.put("maxItems","100"); - - HttpResponse response = post(getFolderSizeUrl(parentFolderId), toJsonAsStringNonNull(params), 202); - Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); - String contentNodeId = document.toString(); - if(contentNodeId != null) - { - eventTimestamp = LocalDateTime.now(); - formattedTimestamp = eventTimestamp.format(DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss")); - LOG.info(" ********** In NodeFolderSizeApiTest:testPerformance Completed Time :{}", formattedTimestamp); - } - assertNotNull(contentNodeId); - } - /** * Test case for others HTTP status codes. */ @@ -243,6 +181,15 @@ public void testHTTPStatus() throws Exception NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(folderId); HttpResponse response = post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); + + assertNotNull(response); + + // create node + Node n = new Node(); + n.setName("temp1"); + n.setNodeType(""); + + response = post(getFolderSizeUrl(n.getName()), RestApiUtil.toJsonAsStringNonNull(n), 422); assertNotNull(response); } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 8b16eff3b11..685bf133574 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -62,6 +62,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase */ public static final String NAME = "folder-size"; public static final String PAGE_SIZE = "page-size"; + public static final String RESULT = "size-result"; /** * The node service @@ -189,8 +190,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) if(isCalculationCompleted) { - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) response); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null); + ruleAction.setParameterValue(NodeSizeActionExecuter.RESULT, (Serializable) response); } } From 98a9d6467c04e6e44ece381097051c3ca4d8d306 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 14:33:53 +0530 Subject: [PATCH 060/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../alfresco/rest/api/nodes/NodeFolderSizeRelation.java | 7 +++---- .../repo/action/executer/NodeSizeActionExecuter.java | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) 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 c7a82c5159f..04c927029c8 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 @@ -253,11 +253,10 @@ private void validateNodeType(NodeRef nodeRef) throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); } - // Check for specific properties - Map properties = nodeService.getProperties(nodeRef); - if (properties.containsKey(FolderSizeModel.PROP_ERROR) && properties.get(FolderSizeModel.PROP_ERROR) != null) + if(folderSizeAction!=null) { - throw new InvalidNodeTypeException(String.valueOf(properties.get(FolderSizeModel.PROP_ERROR))); + String errorInAction = (String) folderSizeAction.getParameterValue(NodeSizeActionExecuter.ERROR); + throw new InvalidNodeTypeException(errorInAction); } } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 685bf133574..fb8f095c0a3 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -63,6 +63,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase public static final String NAME = "folder-size"; public static final String PAGE_SIZE = "page-size"; public static final String RESULT = "size-result"; + public static final String ERROR = "exception"; /** * The node service @@ -112,7 +113,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) catch (NumberFormatException e) { LOG.error("Exception occurred while parsing String to INT: {}", e.getMessage()); - nodeService.setProperty(actionedUponNodeRef, FolderSizeModel.PROP_ERROR,e.getMessage()); + ruleAction.setParameterValue(ERROR, e.getMessage()); throw e; } @@ -175,7 +176,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) catch (RuntimeException ex) { LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", ex.getMessage()); - nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,ex.getMessage()); + ruleAction.setParameterValue(ERROR, ex.getMessage()); throw ex; } @@ -190,7 +191,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) if(isCalculationCompleted) { - ruleAction.setParameterValue(NodeSizeActionExecuter.RESULT, (Serializable) response); + ruleAction.setParameterValue(RESULT, (Serializable) response); } } From 1f1d80d93d51076b7e29751dd31e7fb2e51cfe25 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 14:40:13 +0530 Subject: [PATCH 061/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java | 5 ++++- .../src/main/java/org/alfresco/model/FolderSizeModel.java | 2 -- .../repo/action/executer/NodeSizeActionExecuterTest.java | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) 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 04c927029c8..744e7402f45 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 @@ -256,7 +256,10 @@ private void validateNodeType(NodeRef nodeRef) if(folderSizeAction!=null) { String errorInAction = (String) folderSizeAction.getParameterValue(NodeSizeActionExecuter.ERROR); - throw new InvalidNodeTypeException(errorInAction); + if(errorInAction.length()>1) + { + throw new InvalidNodeTypeException(errorInAction); + } } } diff --git a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java index e5e187fb209..2a3d0bcb7e1 100644 --- a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java +++ b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java @@ -33,7 +33,5 @@ public class FolderSizeModel { /** Folder Model URI */ private static final String SIZE_MODEL_1_0_URI = "http://www.alfresco.org/model/size/1.0"; - public static final QName PROP_STATUS = QName.createQName(SIZE_MODEL_1_0_URI, "status"); public static final QName PROP_OUTPUT = QName.createQName(SIZE_MODEL_1_0_URI, "result"); - public static final QName PROP_ERROR = QName.createQName(SIZE_MODEL_1_0_URI, "error"); } diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index 9048e3a8618..c15f16878cc 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -104,7 +104,8 @@ public void testExecution() ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null); action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); this.executer.executeImpl(action, this.nodeRef); - Map mapResult = (Map)this.nodeService.getProperty(this.nodeRef, FolderSizeModel.PROP_OUTPUT); + Object resultAction = action.getParameterValue(NodeSizeActionExecuter.RESULT); + Map mapResult = (Map)resultAction; assertTrue(mapResult != null); } } From a2e48a4512331f823f16e65c5639faa1f11ce35c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 14:41:34 +0530 Subject: [PATCH 062/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 3 -- .../org/alfresco/model/FolderSizeModel.java | 37 ------------------- .../executer/NodeSizeActionExecuter.java | 1 - .../executer/NodeSizeActionExecuterTest.java | 1 - 4 files changed, 42 deletions(-) delete mode 100644 repository/src/main/java/org/alfresco/model/FolderSizeModel.java 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 744e7402f45..9b4613e2efb 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 @@ -25,7 +25,6 @@ */ package org.alfresco.rest.api.nodes; -import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.executer.NodeSizeActionExecuter; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.rest.api.Nodes; @@ -36,7 +35,6 @@ import org.alfresco.rest.framework.WebApiParameters; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.resource.RelationshipResource; -import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.CalculateSize; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.ReadById; import org.alfresco.rest.framework.resource.parameters.Parameters; @@ -57,7 +55,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.extensions.webscripts.Status; -import java.io.Serializable; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java b/repository/src/main/java/org/alfresco/model/FolderSizeModel.java deleted file mode 100644 index 2a3d0bcb7e1..00000000000 --- a/repository/src/main/java/org/alfresco/model/FolderSizeModel.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * 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.model; - -import org.alfresco.api.AlfrescoPublicApi; -import org.alfresco.service.namespace.QName; - -@AlfrescoPublicApi -public class FolderSizeModel -{ - /** Folder Model URI */ - private static final String SIZE_MODEL_1_0_URI = "http://www.alfresco.org/model/size/1.0"; - public static final QName PROP_OUTPUT = QName.createQName(SIZE_MODEL_1_0_URI, "result"); -} diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index fb8f095c0a3..ba47298b380 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -26,7 +26,6 @@ package org.alfresco.repo.action.executer; import org.alfresco.model.ContentModel; -import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.ParameterizedItemAbstractBase; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index c15f16878cc..65042395491 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -28,7 +28,6 @@ import java.util.Map; import org.alfresco.model.ContentModel; -import org.alfresco.model.FolderSizeModel; import org.alfresco.repo.action.ActionImpl; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.service.cmr.repository.NodeRef; From bf7f6da4c5057960f0de5fcc3ec0b4f2e637c8ba Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 15:10:21 +0530 Subject: [PATCH 063/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/nodes/NodeFolderSizeRelation.java | 14 ++++++++++---- .../resources/alfresco/public-rest-context.xml | 1 + .../rest/api/tests/NodeFolderSizeApiTest.java | 2 +- .../action/executer/NodeSizeActionExecuter.java | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) 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 9b4613e2efb..cde4818af4b 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 @@ -25,6 +25,7 @@ */ package org.alfresco.rest.api.nodes; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.action.executer.NodeSizeActionExecuter; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.rest.api.Nodes; @@ -75,7 +76,7 @@ public class NodeFolderSizeRelation implements CalculateSize private ActionService actionService; private ActionTrackingService actionTrackingService; private Action folderSizeAction; - private static final String NOT_A_VALID_NODEID = "Node Id does not refer to a valid type [should be of folder type]"; + private InvalidNodeTypeException invalidNodeTypeException; /** * The logger @@ -123,6 +124,11 @@ public void setActionTrackingService(ActionTrackingService actionTrackingService this.actionTrackingService = actionTrackingService; } + public void setInvalidNodeTypeException(InvalidNodeTypeException invalidNodeTypeException) + { + this.invalidNodeTypeException = invalidNodeTypeException; + } + /** * Folder Size - returns size of a folder. * @@ -147,7 +153,7 @@ public Map createById(String nodeId, Parameters params) if(!"folder".equals(qName.getLocalName())) { - throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); + throw invalidNodeTypeException; } try @@ -247,7 +253,7 @@ private void validateNodeType(NodeRef nodeRef) if (!"folder".equals(qName.getLocalName())) { - throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); + throw invalidNodeTypeException; } if(folderSizeAction!=null) @@ -255,7 +261,7 @@ private void validateNodeType(NodeRef nodeRef) String errorInAction = (String) folderSizeAction.getParameterValue(NodeSizeActionExecuter.ERROR); if(errorInAction.length()>1) { - throw new InvalidNodeTypeException(errorInAction); + throw new AlfrescoRuntimeException(errorInAction); } } } diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index c6375177b14..13d8f9cf782 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1777,5 +1777,6 @@ + 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 a10093d5f3f..f4087389258 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 @@ -187,7 +187,7 @@ public void testHTTPStatus() throws Exception // create node Node n = new Node(); n.setName("temp1"); - n.setNodeType(""); + n.setNodeType("retention"); response = post(getFolderSizeUrl(n.getName()), RestApiUtil.toJsonAsStringNonNull(n), 422); assertNotNull(response); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ba47298b380..a67a5bc69cd 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -104,6 +104,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) Serializable serializable = ruleAction.getParameterValue(PAGE_SIZE); int maxItems; Map response = new HashMap<>(); + ruleAction.setParameterValue(ERROR, ""); try { From d0e3c69b55589d2c60314376ebc86e7def5bdb95 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 15:21:14 +0530 Subject: [PATCH 064/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../executer/NodeSizeActionExecuterTest.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index 65042395491..a56669c2cb1 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -43,11 +43,6 @@ @Transactional public class NodeSizeActionExecuterTest extends BaseSpringTest { - /** - * The node service - */ - private NodeService nodeService; - /** * The test node reference */ @@ -69,8 +64,7 @@ public class NodeSizeActionExecuterTest extends BaseSpringTest @Before public void before() throws Exception { - - this.nodeService = (NodeService)this.applicationContext.getBean("nodeService"); + NodeService nodeService = (NodeService)this.applicationContext.getBean("nodeService"); StoreRef testStoreRef; NodeRef rootNodeRef; @@ -78,12 +72,12 @@ public void before() throws Exception authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); // Create the store and get the root node - testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + testStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); - rootNodeRef = this.nodeService.getRootNode(testStoreRef); + rootNodeRef = nodeService.getRootNode(testStoreRef); // Create the node used for tests - this.nodeRef = this.nodeService.createNode( + this.nodeRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), From 87ea4444d4621cddcce4419a88227ef55fabce8f Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 15:43:34 +0530 Subject: [PATCH 065/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 27 +++++++++++++------ .../alfresco/public-rest-context.xml | 1 - 2 files changed, 19 insertions(+), 9 deletions(-) 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 cde4818af4b..9f880670d6e 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 @@ -34,6 +34,9 @@ import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.WebApiParameters; +import org.alfresco.rest.framework.core.exceptions.ApiException; +import org.alfresco.rest.framework.core.exceptions.DefaultExceptionResolver; +import org.alfresco.rest.framework.core.exceptions.ErrorResponse; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.CalculateSize; @@ -76,7 +79,7 @@ public class NodeFolderSizeRelation implements CalculateSize private ActionService actionService; private ActionTrackingService actionTrackingService; private Action folderSizeAction; - private InvalidNodeTypeException invalidNodeTypeException; + private String exceptionMessage = "Invalid parameter: value of nodeId is invalid"; /** * The logger @@ -124,11 +127,6 @@ public void setActionTrackingService(ActionTrackingService actionTrackingService this.actionTrackingService = actionTrackingService; } - public void setInvalidNodeTypeException(InvalidNodeTypeException invalidNodeTypeException) - { - this.invalidNodeTypeException = invalidNodeTypeException; - } - /** * Folder Size - returns size of a folder. * @@ -153,7 +151,7 @@ public Map createById(String nodeId, Parameters params) if(!"folder".equals(qName.getLocalName())) { - throw invalidNodeTypeException; + makeErrorResponse(new InvalidNodeTypeException(exceptionMessage),422); } try @@ -253,7 +251,7 @@ private void validateNodeType(NodeRef nodeRef) if (!"folder".equals(qName.getLocalName())) { - throw invalidNodeTypeException; + makeErrorResponse(new InvalidNodeTypeException(exceptionMessage),422); } if(folderSizeAction!=null) @@ -266,4 +264,17 @@ private void validateNodeType(NodeRef nodeRef) } } + private ErrorResponse makeErrorResponse(Exception ex, Integer statusCode) + { + if (ex instanceof ApiException) + { + ApiException apEx = (ApiException) ex; + return new ErrorResponse(apEx.getMsgId(), statusCode, ex.getLocalizedMessage(), ex.getStackTrace(), apEx.getAdditionalState()); + } + else + { + return new ErrorResponse(DefaultExceptionResolver.DEFAULT_MESSAGE_ID, statusCode, ex.getLocalizedMessage(), ex.getStackTrace(), null); + } + } + } \ No newline at end of file diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 13d8f9cf782..c6375177b14 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1777,6 +1777,5 @@ - From 5f7b97b6a21dc499161a5bc89da238e227b17c25 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 16:55:49 +0530 Subject: [PATCH 066/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 20 ++++++++++--------- .../rest/api/tests/NodeFolderSizeApiTest.java | 9 --------- 2 files changed, 11 insertions(+), 18 deletions(-) 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 9f880670d6e..487d6d76f4a 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 @@ -80,6 +80,7 @@ public class NodeFolderSizeRelation implements CalculateSize private ActionTrackingService actionTrackingService; private Action folderSizeAction; private String exceptionMessage = "Invalid parameter: value of nodeId is invalid"; + private InvalidNodeTypeException invalidNodeTypeException; /** * The logger @@ -151,7 +152,8 @@ public Map createById(String nodeId, Parameters params) if(!"folder".equals(qName.getLocalName())) { - makeErrorResponse(new InvalidNodeTypeException(exceptionMessage),422); + invalidNodeTypeException = new InvalidNodeTypeException(exceptionMessage); + return (Map) new ErrorResponse(invalidNodeTypeException.getMsgId(), 422, invalidNodeTypeException.getLocalizedMessage(), invalidNodeTypeException.getStackTrace(), invalidNodeTypeException.getAdditionalState()); } try @@ -181,11 +183,19 @@ public Map createById(String nodeId, Parameters params) public Map readById(String nodeId, String id, Parameters parameters) { NodeRef nodeRef = nodes.validateNode(nodeId); + // Check node type. + QName qName = nodeService.getType(nodeRef); Object resultAction; Map result = new HashMap<>(); validatePermissions(nodeRef, nodeId); validateNodeType(nodeRef); + if(!"folder".equals(qName.getLocalName())) + { + invalidNodeTypeException = new InvalidNodeTypeException(exceptionMessage); + return (Map) new ErrorResponse(invalidNodeTypeException.getMsgId(), 422, invalidNodeTypeException.getLocalizedMessage(), invalidNodeTypeException.getStackTrace(), invalidNodeTypeException.getAdditionalState()); + } + try { LOG.info("Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById"); @@ -246,14 +256,6 @@ private void validatePermissions(NodeRef nodeRef, String nodeId) private void validateNodeType(NodeRef nodeRef) { - // Check node type. - QName qName = nodeService.getType(nodeRef); - - if (!"folder".equals(qName.getLocalName())) - { - makeErrorResponse(new InvalidNodeTypeException(exceptionMessage),422); - } - if(folderSizeAction!=null) { String errorInAction = (String) folderSizeAction.getParameterValue(NodeSizeActionExecuter.ERROR); 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 f4087389258..d2a601d916c 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 @@ -181,15 +181,6 @@ public void testHTTPStatus() throws Exception NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(folderId); HttpResponse response = post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); - - assertNotNull(response); - - // create node - Node n = new Node(); - n.setName("temp1"); - n.setNodeType("retention"); - - response = post(getFolderSizeUrl(n.getName()), RestApiUtil.toJsonAsStringNonNull(n), 422); assertNotNull(response); } From 2022c38913934ae05519f23bd9faae9c3bbfa917 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 17:27:47 +0530 Subject: [PATCH 067/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) 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 487d6d76f4a..8699eb0d717 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 @@ -80,7 +80,6 @@ public class NodeFolderSizeRelation implements CalculateSize private ActionTrackingService actionTrackingService; private Action folderSizeAction; private String exceptionMessage = "Invalid parameter: value of nodeId is invalid"; - private InvalidNodeTypeException invalidNodeTypeException; /** * The logger @@ -152,7 +151,7 @@ public Map createById(String nodeId, Parameters params) if(!"folder".equals(qName.getLocalName())) { - invalidNodeTypeException = new InvalidNodeTypeException(exceptionMessage); + InvalidNodeTypeException invalidNodeTypeException = new InvalidNodeTypeException(exceptionMessage); return (Map) new ErrorResponse(invalidNodeTypeException.getMsgId(), 422, invalidNodeTypeException.getLocalizedMessage(), invalidNodeTypeException.getStackTrace(), invalidNodeTypeException.getAdditionalState()); } @@ -185,14 +184,13 @@ public Map readById(String nodeId, String id, Parameters paramet NodeRef nodeRef = nodes.validateNode(nodeId); // Check node type. QName qName = nodeService.getType(nodeRef); - Object resultAction; Map result = new HashMap<>(); validatePermissions(nodeRef, nodeId); - validateNodeType(nodeRef); + validateAction(); if(!"folder".equals(qName.getLocalName())) { - invalidNodeTypeException = new InvalidNodeTypeException(exceptionMessage); + InvalidNodeTypeException invalidNodeTypeException = new InvalidNodeTypeException(exceptionMessage); return (Map) new ErrorResponse(invalidNodeTypeException.getMsgId(), 422, invalidNodeTypeException.getLocalizedMessage(), invalidNodeTypeException.getStackTrace(), invalidNodeTypeException.getAdditionalState()); } @@ -201,7 +199,7 @@ public Map readById(String nodeId, String id, Parameters paramet LOG.info("Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById"); if(folderSizeAction!=null) { - resultAction = folderSizeAction.getParameterValue(NodeSizeActionExecuter.RESULT); + Object resultAction = folderSizeAction.getParameterValue(NodeSizeActionExecuter.RESULT); result = getResult(resultAction); } else @@ -254,7 +252,7 @@ private void validatePermissions(NodeRef nodeRef, String nodeId) } } - private void validateNodeType(NodeRef nodeRef) + private void validateAction() { if(folderSizeAction!=null) { @@ -266,17 +264,4 @@ private void validateNodeType(NodeRef nodeRef) } } - private ErrorResponse makeErrorResponse(Exception ex, Integer statusCode) - { - if (ex instanceof ApiException) - { - ApiException apEx = (ApiException) ex; - return new ErrorResponse(apEx.getMsgId(), statusCode, ex.getLocalizedMessage(), ex.getStackTrace(), apEx.getAdditionalState()); - } - else - { - return new ErrorResponse(DefaultExceptionResolver.DEFAULT_MESSAGE_ID, statusCode, ex.getLocalizedMessage(), ex.getStackTrace(), null); - } - } - } \ No newline at end of file From f9f199deb59ebdc088076447fa54add1a3ff2447 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 23:20:25 +0530 Subject: [PATCH 068/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../api/nodes/NodeFolderSizeRelation.java | 25 +++++++++---------- .../executer/NodeSizeActionExecuter.java | 1 - 2 files changed, 12 insertions(+), 14 deletions(-) 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 8699eb0d717..7f94332b20a 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 @@ -34,9 +34,6 @@ import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.WebApiParameters; -import org.alfresco.rest.framework.core.exceptions.ApiException; -import org.alfresco.rest.framework.core.exceptions.DefaultExceptionResolver; -import org.alfresco.rest.framework.core.exceptions.ErrorResponse; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.CalculateSize; @@ -151,8 +148,7 @@ public Map createById(String nodeId, Parameters params) if(!"folder".equals(qName.getLocalName())) { - InvalidNodeTypeException invalidNodeTypeException = new InvalidNodeTypeException(exceptionMessage); - return (Map) new ErrorResponse(invalidNodeTypeException.getMsgId(), 422, invalidNodeTypeException.getLocalizedMessage(), invalidNodeTypeException.getStackTrace(), invalidNodeTypeException.getAdditionalState()); + throw new InvalidNodeTypeException(exceptionMessage); } try @@ -190,8 +186,7 @@ public Map readById(String nodeId, String id, Parameters paramet if(!"folder".equals(qName.getLocalName())) { - InvalidNodeTypeException invalidNodeTypeException = new InvalidNodeTypeException(exceptionMessage); - return (Map) new ErrorResponse(invalidNodeTypeException.getMsgId(), 422, invalidNodeTypeException.getLocalizedMessage(), invalidNodeTypeException.getStackTrace(), invalidNodeTypeException.getAdditionalState()); + throw new InvalidNodeTypeException(exceptionMessage); } try @@ -200,7 +195,7 @@ public Map readById(String nodeId, String id, Parameters paramet if(folderSizeAction!=null) { Object resultAction = folderSizeAction.getParameterValue(NodeSizeActionExecuter.RESULT); - result = getResult(resultAction); + result = getResult(resultAction, nodeId); } else { @@ -215,7 +210,7 @@ public Map readById(String nodeId, String id, Parameters paramet } } - private Map getResult(Object resultAction) + private Map getResult(Object resultAction, String nodeId) { Map result = new HashMap<>(); @@ -227,15 +222,19 @@ private Map getResult(Object resultAction) { Map mapResult = (Map) resultAction; - if(!mapResult.containsKey("size")) + if (!mapResult.containsKey("size")) { result.put("status", "IN-PROGRESS"); } - else + else if (mapResult.get("id").equals(nodeId)) { mapResult.put("status", "COMPLETED"); result = mapResult; } + else + { + result.put("status", "NOT-INITIATED"); + } } return result; } @@ -254,10 +253,10 @@ private void validatePermissions(NodeRef nodeRef, String nodeId) private void validateAction() { - if(folderSizeAction!=null) + if(folderSizeAction != null) { String errorInAction = (String) folderSizeAction.getParameterValue(NodeSizeActionExecuter.ERROR); - if(errorInAction.length()>1) + if(errorInAction != null && errorInAction.length()>1) { throw new AlfrescoRuntimeException(errorInAction); } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index a67a5bc69cd..ba47298b380 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -104,7 +104,6 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) Serializable serializable = ruleAction.getParameterValue(PAGE_SIZE); int maxItems; Map response = new HashMap<>(); - ruleAction.setParameterValue(ERROR, ""); try { From 225c521f09b1f1e7928927815e28223517928955 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 2 Jul 2024 23:41:36 +0530 Subject: [PATCH 069/267] [MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas] --- .../rest/api/tests/NodeFolderSizeApiTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 d2a601d916c..de4115a8f93 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 @@ -182,6 +182,18 @@ public void testHTTPStatus() throws Exception tgt.setTargetParentId(folderId); HttpResponse response = post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); assertNotNull(response); + + // Create a folder within the site document's library. + String folderName = "nestedFolder" + System.currentTimeMillis(); + String nestedFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); + // Prepare parameters + Map params = new HashMap<>(); + params.put("nodeId", nestedFolderId); + params.put("maxItems", "100"); + + // Perform POST request + response = post(getFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); + assertNotNull(response); } @After From b47e0551cbe36e0cf680fa528f56905e2f464e70 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 22 Jul 2024 09:13:34 +0530 Subject: [PATCH 070/267] [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 00000000000..c22339d896f --- /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 From 88d10f2f4f68fd40d0b1af49f1d1e8dc14ce426e Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 22 Jul 2024 09:15:19 +0530 Subject: [PATCH 071/267] [feature/MNT-24127] EndpointToCalculateFolderSize --- remote-api/pom.xml | 6 ++ .../api/nodes/NodeFolderSizeRelation.java | 74 +++++++++---------- .../framework/core/ResourceInspector.java | 1 + .../alfresco/public-rest-context.xml | 1 + .../framework/tests/core/InspectorTests.java | 10 --- .../executer/NodeSizeActionExecuter.java | 21 ++++-- .../main/resources/alfresco/cache-context.xml | 6 ++ .../main/resources/alfresco/caches.properties | 11 ++- 8 files changed, 72 insertions(+), 58 deletions(-) diff --git a/remote-api/pom.xml b/remote-api/pom.xml index 68d15be3ffd..a551b5bd316 100644 --- a/remote-api/pom.xml +++ b/remote-api/pom.xml @@ -60,6 +60,12 @@ test + + org.projectlombok + lombok + provided + + junit 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 7f94332b20a..390407815ec 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 @@ -27,8 +27,10 @@ import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.action.executer.NodeSizeActionExecuter; +import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.impl.FolderSizeImpl; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.NodePermissions; import org.alfresco.rest.framework.WebApiDescription; @@ -42,9 +44,8 @@ import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.action.ActionStatus; 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.alfresco.service.cmr.search.SearchService; @@ -56,8 +57,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.extensions.webscripts.Status; + +import java.io.Serializable; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -76,7 +78,11 @@ public class NodeFolderSizeRelation implements CalculateSize private ActionService actionService; private ActionTrackingService actionTrackingService; private Action folderSizeAction; + private FolderSizeImpl folderSizeImpl; + private NodeRef nodeRef; private String exceptionMessage = "Invalid parameter: value of nodeId is invalid"; + /** the shared cache that will hold action data */ + private static SimpleCache sharedCache; /** * The logger @@ -124,6 +130,11 @@ public void setActionTrackingService(ActionTrackingService actionTrackingService this.actionTrackingService = actionTrackingService; } + public void setSharedCache(SimpleCache sharedCache) + { + this.sharedCache = sharedCache; + } + /** * Folder Size - returns size of a folder. * @@ -139,7 +150,7 @@ public void setActionTrackingService(ActionTrackingService actionTrackingService @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder", successStatus = Status.STATUS_ACCEPTED) public Map createById(String nodeId, Parameters params) { - NodeRef nodeRef = nodes.validateNode(nodeId); + nodeRef = nodes.validateNode(nodeId); int maxItems = Math.min(params.getPaging().getMaxItems(), 1000); QName qName = nodeService.getType(nodeRef); Map result = new HashMap<>(); @@ -153,49 +164,33 @@ public Map createById(String nodeId, Parameters params) try { - folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); - folderSizeAction.setTrackStatus(true); - folderSizeAction.setExecuteAsynchronously(true); - folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); - folderSizeAction.setParameterValue(NodeSizeActionExecuter.RESULT, "IN-PROGRESS"); - actionService.executeAction(folderSizeAction, nodeRef, false, true); - LOG.info(" Executing ActionExecutor in NodeFolderSizeRelation:createById "); - List executionSummaryList = actionTrackingService.getExecutingActions(NodeSizeActionExecuter.NAME); - ExecutionDetails executionDetails = actionTrackingService.getExecutionDetails(executionSummaryList.get(0)); - result.put("executionId", executionDetails.getActionId()); - return result; + this.folderSizeImpl = new FolderSizeImpl(actionService, actionTrackingService, nodeService); + return this.folderSizeImpl.executingAsynchronousFolderAction(maxItems, nodeRef, result, sharedCache); } catch (Exception ex) { LOG.error("Exception occurred in NodeFolderSizeRelation:createById {}", ex.getMessage()); - throw ex; // This rethrows with the original stack trace preserved. + throw new AlfrescoRuntimeException("Exception occurred in NodeFolderSizeRelation:createById"); } } @Override @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") - @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of the Node being addressed", description = "A single node id")}) - public Map readById(String nodeId, String id, Parameters parameters) + @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) { - NodeRef nodeRef = nodes.validateNode(nodeId); - // Check node type. - QName qName = nodeService.getType(nodeRef); Map result = new HashMap<>(); - validatePermissions(nodeRef, nodeId); - validateAction(); - - if(!"folder".equals(qName.getLocalName())) - { - throw new InvalidNodeTypeException(exceptionMessage); - } try { - LOG.info("Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById"); - if(folderSizeAction!=null) + LOG.info("Retrieving OUTPUT from NodeSizeActionExecutor - NodeFolderSizeRelation:readById"); + if(nodeRef!=null) { - Object resultAction = folderSizeAction.getParameterValue(NodeSizeActionExecuter.RESULT); - result = getResult(resultAction, nodeId); + //Action extractedResult = this.folderSizeImpl.extractingActionsResult(nodeRef, executionId); + Action actionData = (Action) sharedCache.get(executionId); + Action extractedResult = this.folderSizeImpl.getAction(nodeRef, executionId); + result = getResult(extractedResult); + } else { @@ -210,7 +205,7 @@ public Map readById(String nodeId, String id, Parameters paramet } } - private Map getResult(Object resultAction, String nodeId) + private Map getResult(Action resultAction) { Map result = new HashMap<>(); @@ -220,20 +215,17 @@ private Map getResult(Object resultAction, String nodeId) } else { - Map mapResult = (Map) resultAction; + ActionStatus actionStatus = resultAction.getExecutionStatus(); - if (!mapResult.containsKey("size")) + if(ActionStatus.Pending.name().equals(actionStatus.name())) { result.put("status", "IN-PROGRESS"); } - else if (mapResult.get("id").equals(nodeId)) - { - mapResult.put("status", "COMPLETED"); - result = mapResult; - } else { - result.put("status", "NOT-INITIATED"); + Map mapResult = (Map) resultAction.getParameterValue(NodeSizeActionExecuter.RESULT); + mapResult.put("status","COMPLETED"); + result = mapResult; } } return result; diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index c1f961240f0..5388722b5be 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -294,6 +294,7 @@ private static List inspectRelationship(RelationshipResource a findOperation(MultiPartRelationshipResourceAction.Create.class, POST, helper); findOperation(RelationshipResourceAction.CalculateSize.class, POST, helper); + findOperation(RelationshipResourceAction.CalculateSize.class, GET, helper); boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index c6375177b14..3238de75fd6 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1777,5 +1777,6 @@ + diff --git a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java index 376e552624a..85aa8b1f77a 100644 --- a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java +++ b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java @@ -644,14 +644,4 @@ public void testValidSuccessCode() assertEquals(Status.STATUS_NOT_MODIFIED,ResourceInspector.validSuccessCode(HttpMethod.DELETE, Status.STATUS_NOT_MODIFIED)); } - @Test - public void testCalculateSizeRelation() - { - List metainfo = ResourceInspector.inspect(NodeFolderSizeRelation.class); - assertTrue("Must be one ResourceMetadata",!metainfo.isEmpty()); - ResourceMetadata metaData = metainfo.get(0); - assertNotNull(metaData); - ResourceOperation op = metaData.getOperation(HttpMethod.POST); - assertNotNull("NodeFolderSizeRelation supports POST", op); - } } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ba47298b380..60f075164e0 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -27,6 +27,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.action.ParameterizedItemAbstractBase; +import org.alfresco.repo.cache.SimpleCache; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.repository.ContentData; @@ -44,6 +45,7 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -63,6 +65,8 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase public static final String PAGE_SIZE = "page-size"; public static final String RESULT = "size-result"; public static final String ERROR = "exception"; + public static final String CACHE_REF = "sharedCache"; + public static final Map actionsRecords = new HashMap<>(); /** * The node service @@ -99,9 +103,10 @@ public void setSearchService(SearchService searchService) * @see ActionExecuter#execute(Action, NodeRef) */ @Override - public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) + public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) { - Serializable serializable = ruleAction.getParameterValue(PAGE_SIZE); + Serializable serializable = nodeAction.getParameterValue(PAGE_SIZE); + Serializable serializedCache = nodeAction.getParameterValue(CACHE_REF); int maxItems; Map response = new HashMap<>(); @@ -112,7 +117,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) catch (NumberFormatException e) { LOG.error("Exception occurred while parsing String to INT: {}", e.getMessage()); - ruleAction.setParameterValue(ERROR, e.getMessage()); + nodeAction.setParameterValue(ERROR, e.getMessage()); throw e; } @@ -129,6 +134,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); searchParameters.setQuery(query); + //searchParameters.addFacetQuery(); try { @@ -175,7 +181,7 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) catch (RuntimeException ex) { LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", ex.getMessage()); - ruleAction.setParameterValue(ERROR, ex.getMessage()); + nodeAction.setParameterValue(ERROR, ex.getMessage()); throw ex; } @@ -185,12 +191,15 @@ public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) String formattedTimestamp = eventTimestamp.format(formatter); response.put("id", nodeRef.getId()); response.put("size", totalSize); - response.put("calculatedAtTime", formattedTimestamp); + response.put("calculatedAt", formattedTimestamp); response.put("numberOfFiles", results != null ? results.getNodeRefs().size() : 0); if(isCalculationCompleted) { - ruleAction.setParameterValue(RESULT, (Serializable) response); + nodeAction.setParameterValue(RESULT, (Serializable) response); + actionsRecords.put(nodeAction.getId(),nodeAction); + SimpleCache simpleCache = (SimpleCache) serializedCache; + simpleCache.put(nodeAction.getId(),nodeAction); } } diff --git a/repository/src/main/resources/alfresco/cache-context.xml b/repository/src/main/resources/alfresco/cache-context.xml index 6cb3c7e1dc3..8bd336aed38 100644 --- a/repository/src/main/resources/alfresco/cache-context.xml +++ b/repository/src/main/resources/alfresco/cache-context.xml @@ -514,4 +514,10 @@ + + + + + + diff --git a/repository/src/main/resources/alfresco/caches.properties b/repository/src/main/resources/alfresco/caches.properties index ad12d905ff4..0bcf8f5b120 100644 --- a/repository/src/main/resources/alfresco/caches.properties +++ b/repository/src/main/resources/alfresco/caches.properties @@ -709,4 +709,13 @@ cache.ldapInitialDirContextCache.cluster.type=fully-distributed cache.ldapInitialDirContextCache.backup-count=1 cache.ldapInitialDirContextCache.eviction-policy=NONE cache.ldapInitialDirContextCache.merge-policy=com.hazelcast.spi.merge.LatestUpdateMergePolicy -cache.ldapInitialDirContextCache.readBackupData=false \ No newline at end of file +cache.ldapInitialDirContextCache.readBackupData=false + +cache.folderSizeSharedCache.maxItems=1000 +cache.folderSizeSharedCache.timeToLiveSeconds=0 +cache.folderSizeSharedCache.maxIdleSeconds=0 +cache.folderSizeSharedCache.cluster.type=fully-distributed +cache.folderSizeSharedCache.backup-count=1 +cache.folderSizeSharedCache.eviction-policy=NONE +cache.folderSizeSharedCache.merge-policy=com.hazelcast.spi.merge.LatestUpdateMergePolicy +cache.folderSizeSharedCache.readBackupData=false \ No newline at end of file From 9578891af449229c98b51e3f8c3f22ae9fc9d64f Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 22 Jul 2024 09:16:06 +0530 Subject: [PATCH 072/267] [feature/MNT-24127] EndpointToCalculateFolderSize --- .../rest/api/nodes/NodeFolderSizeRelation.java | 12 ------------ 1 file changed, 12 deletions(-) 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 390407815ec..660bde0584e 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 @@ -243,16 +243,4 @@ private void validatePermissions(NodeRef nodeRef, String nodeId) } } - private void validateAction() - { - if(folderSizeAction != null) - { - String errorInAction = (String) folderSizeAction.getParameterValue(NodeSizeActionExecuter.ERROR); - if(errorInAction != null && errorInAction.length()>1) - { - throw new AlfrescoRuntimeException(errorInAction); - } - } - } - } \ No newline at end of file From 4e86bb70ee8334c6fa2ab29ec5e0f482bdba4bf2 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 22 Jul 2024 10:11:06 +0530 Subject: [PATCH 073/267] [feature/MNT-24127] EndpointToCalculateFolderSize --- .../java/org/alfresco/rest/api/impl/FolderSizeImpl.java | 2 -- .../alfresco/rest/api/nodes/NodeFolderSizeRelation.java | 1 - .../org/alfresco/rest/api/tests/AbstractBaseApiTest.java | 7 ++++++- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 6 +++--- .../repo/action/executer/NodeSizeActionExecuterTest.java | 9 +++++++++ 5 files changed, 18 insertions(+), 7 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 c22339d896f..94474aba1df 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 @@ -62,8 +62,6 @@ public Map executingAsynchronousFolderAction(final int maxItems, 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; } 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 660bde0584e..a54abf013e2 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 @@ -77,7 +77,6 @@ public class NodeFolderSizeRelation implements CalculateSize private NodeService nodeService; private ActionService actionService; private ActionTrackingService actionTrackingService; - private Action folderSizeAction; private FolderSizeImpl folderSizeImpl; private NodeRef nodeRef; private String exceptionMessage = "Invalid parameter: value of nodeId is invalid"; diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index ce3bb6e2a7e..5b7db342894 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -1122,9 +1122,14 @@ protected void disableRestDirectAccessUrls() restDauConfig.setEnabled(false); } - protected String getFolderSizeUrl(String nodeId) + protected String postFolderSizeCalculation(String nodeId) { return URL_NODES + "/" + nodeId + "/" + URL_CALCULATESIZE; } + + protected String getFolderSizeUrl(String executionId) + { + return URL_NODES + "/" + executionId + "/" + URL_CALCULATESIZE; + } } 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 de4115a8f93..ee95cadb82e 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 @@ -124,7 +124,7 @@ public void testAPostCalculateFolderSize() throws Exception { params.put("maxItems", "100"); // Perform POST request - HttpResponse response = post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + HttpResponse response = post(postFolderSizeCalculation(folderId), toJsonAsStringNonNull(params), 202); // Validate response and parsed document assertNotNull("Response should not be null", response); @@ -180,7 +180,7 @@ public void testHTTPStatus() throws Exception setRequestContext(user1); NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(folderId); - HttpResponse response = post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); + HttpResponse response = post(postFolderSizeCalculation(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); assertNotNull(response); // Create a folder within the site document's library. @@ -192,7 +192,7 @@ public void testHTTPStatus() throws Exception params.put("maxItems", "100"); // Perform POST request - response = post(getFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); + response = post(postFolderSizeCalculation(nestedFolderId), toJsonAsStringNonNull(params), 422); assertNotNull(response); } diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index a56669c2cb1..dda22ca3624 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -25,11 +25,14 @@ */ package org.alfresco.repo.action.executer; +import java.io.Serializable; import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.repo.action.ActionImpl; +import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.security.authentication.AuthenticationComponent; +import org.alfresco.service.cmr.action.ExecutionDetails; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; @@ -38,6 +41,7 @@ import org.alfresco.util.GUID; import org.junit.Before; import org.junit.Test; +import org.springframework.context.ApplicationContext; import org.springframework.transaction.annotation.Transactional; @Transactional @@ -58,6 +62,8 @@ public class NodeSizeActionExecuterTest extends BaseSpringTest */ private final static String ID = GUID.generate(); + private SimpleCache executingActionsCache; + /** * Called at the begining of all tests. */ @@ -85,6 +91,8 @@ public void before() throws Exception // Get the executer instance. this.executer = (NodeSizeActionExecuter)this.applicationContext.getBean(NodeSizeActionExecuter.NAME); + + executingActionsCache = (SimpleCache)this.applicationContext.getBean("folderSizeSharedCache"); } /** @@ -96,6 +104,7 @@ public void testExecution() int maxItems = 100; ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null); action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); + action.setParameterValue(NodeSizeActionExecuter.CACHE_REF, (Serializable)executingActionsCache); this.executer.executeImpl(action, this.nodeRef); Object resultAction = action.getParameterValue(NodeSizeActionExecuter.RESULT); Map mapResult = (Map)resultAction; From 10b436d3c4b94647db8d52194c34ab547246ffc4 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 22 Jul 2024 11:01:01 +0530 Subject: [PATCH 074/267] [feature/MNT-24127] EndpointToCalculateFolderSize --- .../java/org/alfresco/rest/api/impl/FolderSizeImpl.java | 9 ++++++--- .../repo/action/executer/NodeSizeActionExecuter.java | 4 ---- .../repo/action/executer/NodeSizeActionExecuterTest.java | 3 +-- 3 files changed, 7 insertions(+), 9 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 94474aba1df..993900d2276 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 @@ -25,6 +25,11 @@ */ package org.alfresco.rest.api.impl; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -32,12 +37,11 @@ import lombok.AllArgsConstructor; import org.alfresco.repo.action.executer.NodeSizeActionExecuter; +import org.alfresco.repo.cache.DefaultSimpleCache; 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; @@ -58,7 +62,6 @@ public Map executingAsynchronousFolderAction(final int maxItems, 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"); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 60f075164e0..b8f080be601 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -45,7 +45,6 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -106,7 +105,6 @@ public void setSearchService(SearchService searchService) public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) { Serializable serializable = nodeAction.getParameterValue(PAGE_SIZE); - Serializable serializedCache = nodeAction.getParameterValue(CACHE_REF); int maxItems; Map response = new HashMap<>(); @@ -198,8 +196,6 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) { nodeAction.setParameterValue(RESULT, (Serializable) response); actionsRecords.put(nodeAction.getId(),nodeAction); - SimpleCache simpleCache = (SimpleCache) serializedCache; - simpleCache.put(nodeAction.getId(),nodeAction); } } diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index dda22ca3624..6e7e56c81c8 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -92,7 +92,7 @@ public void before() throws Exception // Get the executer instance. this.executer = (NodeSizeActionExecuter)this.applicationContext.getBean(NodeSizeActionExecuter.NAME); - executingActionsCache = (SimpleCache)this.applicationContext.getBean("folderSizeSharedCache"); + executingActionsCache = (SimpleCache) this.applicationContext.getBean("folderSizeSharedCache"); } /** @@ -104,7 +104,6 @@ public void testExecution() int maxItems = 100; ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null); action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); - action.setParameterValue(NodeSizeActionExecuter.CACHE_REF, (Serializable)executingActionsCache); this.executer.executeImpl(action, this.nodeRef); Object resultAction = action.getParameterValue(NodeSizeActionExecuter.RESULT); Map mapResult = (Map)resultAction; From 3c7f5b5ad1fd9606b9bbbbd1934e8a2966b9bec6 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 22 Jul 2024 11:02:15 +0530 Subject: [PATCH 075/267] [feature/MNT-24127] EndpointToCalculateFolderSize --- .../java/org/alfresco/rest/api/impl/FolderSizeImpl.java | 6 ------ .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 1 - .../repo/action/executer/NodeSizeActionExecuter.java | 1 - .../repo/action/executer/NodeSizeActionExecuterTest.java | 2 -- 4 files changed, 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 993900d2276..5cc66e79320 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 @@ -25,11 +25,6 @@ */ package org.alfresco.rest.api.impl; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -37,7 +32,6 @@ import lombok.AllArgsConstructor; import org.alfresco.repo.action.executer.NodeSizeActionExecuter; -import org.alfresco.repo.cache.DefaultSimpleCache; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; 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 ee95cadb82e..2ede35540ef 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 @@ -29,7 +29,6 @@ import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; -import org.alfresco.rest.api.tests.client.data.Node; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.service.cmr.repository.NodeService; diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index b8f080be601..9670286f303 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -27,7 +27,6 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.action.ParameterizedItemAbstractBase; -import org.alfresco.repo.cache.SimpleCache; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.repository.ContentData; diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index 6e7e56c81c8..7c8f5494851 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -32,7 +32,6 @@ import org.alfresco.repo.action.ActionImpl; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.service.cmr.action.ExecutionDetails; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; @@ -41,7 +40,6 @@ import org.alfresco.util.GUID; import org.junit.Before; import org.junit.Test; -import org.springframework.context.ApplicationContext; import org.springframework.transaction.annotation.Transactional; @Transactional From 1c8c6ff84196f29f340f92857976f26ed7f9d2d2 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 22 Jul 2024 11:22:42 +0530 Subject: [PATCH 076/267] [feature/MNT-24127] EndpointToCalculateFolderSize --- .../org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java | 2 -- 1 file changed, 2 deletions(-) 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 a54abf013e2..821cb625666 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 @@ -186,10 +186,8 @@ public Map readById(String executionId, String id, Parameters pa if(nodeRef!=null) { //Action extractedResult = this.folderSizeImpl.extractingActionsResult(nodeRef, executionId); - Action actionData = (Action) sharedCache.get(executionId); Action extractedResult = this.folderSizeImpl.getAction(nodeRef, executionId); result = getResult(extractedResult); - } else { From 67987858938151338322ea214723eb8596834190 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 23 Jul 2024 12:54:57 +0530 Subject: [PATCH 077/267] [feature/MNT-24127] Endpoint Added To Calculate Folder Size --- .../rest/api/impl/FolderSizeImpl.java | 22 +------- .../api/nodes/NodeFolderSizeRelation.java | 54 ++++++++----------- .../alfresco/public-rest-context.xml | 2 +- .../executer/NodeSizeActionExecuter.java | 10 +++- .../alfresco/action-services-context.xml | 1 + 5 files changed, 34 insertions(+), 55 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 5cc66e79320..ed3fd790460 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 @@ -45,37 +45,19 @@ 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 + public Map executingAsynchronousFolderAction(final int maxItems, final NodeRef nodeRef, final Map result, final SimpleCache simpleCache) throws Exception { Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); folderSizeAction.setTrackStatus(true); folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); + simpleCache.put(folderSizeAction.getId(),"IN-PROGRESS"); actionService.executeAction(folderSizeAction, nodeRef, false, true); NodeSizeActionExecuter.actionsRecords.put(folderSizeAction.getId(),folderSizeAction); LOG.info("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); 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 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 821cb625666..eb5e59bee91 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 @@ -26,7 +26,6 @@ package org.alfresco.rest.api.nodes; import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.action.executer.NodeSizeActionExecuter; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.rest.api.Nodes; @@ -37,14 +36,13 @@ import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.WebApiParameters; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; +import org.alfresco.rest.framework.core.exceptions.NotFoundException; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.CalculateSize; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.ReadById; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.action.ActionStatus; import org.alfresco.service.cmr.action.ActionTrackingService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -79,9 +77,12 @@ public class NodeFolderSizeRelation implements CalculateSize private ActionTrackingService actionTrackingService; private FolderSizeImpl folderSizeImpl; private NodeRef nodeRef; - private String exceptionMessage = "Invalid parameter: value of nodeId is invalid"; - /** the shared cache that will hold action data */ - private static SimpleCache sharedCache; + 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 */ + private SimpleCache simpleCache; /** * The logger @@ -129,9 +130,9 @@ public void setActionTrackingService(ActionTrackingService actionTrackingService this.actionTrackingService = actionTrackingService; } - public void setSharedCache(SimpleCache sharedCache) + public void setSimpleCache(SimpleCache simpleCache) { - this.sharedCache = sharedCache; + this.simpleCache = simpleCache; } /** @@ -158,13 +159,13 @@ public Map createById(String nodeId, Parameters params) if(!"folder".equals(qName.getLocalName())) { - throw new InvalidNodeTypeException(exceptionMessage); + throw new InvalidNodeTypeException(invalidMessage); } try { - this.folderSizeImpl = new FolderSizeImpl(actionService, actionTrackingService, nodeService); - return this.folderSizeImpl.executingAsynchronousFolderAction(maxItems, nodeRef, result, sharedCache); + this.folderSizeImpl = new FolderSizeImpl(actionService); + return this.folderSizeImpl.executingAsynchronousFolderAction(maxItems, nodeRef, result, simpleCache); } catch (Exception ex) { @@ -183,15 +184,14 @@ public Map readById(String executionId, String id, Parameters pa try { LOG.info("Retrieving OUTPUT from NodeSizeActionExecutor - NodeFolderSizeRelation:readById"); - if(nodeRef!=null) + Object cachedResult = simpleCache.get(executionId); + if(cachedResult != null) { - //Action extractedResult = this.folderSizeImpl.extractingActionsResult(nodeRef, executionId); - Action extractedResult = this.folderSizeImpl.getAction(nodeRef, executionId); - result = getResult(extractedResult); + result = getResult(cachedResult); } else { - result.put("status", "NOT-INITIATED"); + throw new NotFoundException(notFoundMessage); } return result; } @@ -201,29 +201,19 @@ public Map readById(String executionId, String id, Parameters pa throw ex; // Rethrow with original stack trace } } - - private Map getResult(Action resultAction) + private Map getResult(Object outputResult) { Map result = new HashMap<>(); - if (resultAction == null) + if (outputResult instanceof Map) { - result.put("status", "NOT-INITIATED"); + Map mapResult = (Map) outputResult; + mapResult.put("status", "COMPLETED"); + result = mapResult; } else { - ActionStatus actionStatus = resultAction.getExecutionStatus(); - - if(ActionStatus.Pending.name().equals(actionStatus.name())) - { - result.put("status", "IN-PROGRESS"); - } - else - { - Map mapResult = (Map) resultAction.getParameterValue(NodeSizeActionExecuter.RESULT); - mapResult.put("status","COMPLETED"); - result = mapResult; - } + result.put("status", "IN-PROGRESS"); } return result; } diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 3238de75fd6..f237ba024aa 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1777,6 +1777,6 @@ - + diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 9670286f303..1d887dbd7a3 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -27,6 +27,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.action.ParameterizedItemAbstractBase; +import org.alfresco.repo.cache.SimpleCache; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.repository.ContentData; @@ -63,7 +64,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase public static final String PAGE_SIZE = "page-size"; public static final String RESULT = "size-result"; public static final String ERROR = "exception"; - public static final String CACHE_REF = "sharedCache"; + private SimpleCache simpleCache; public static final Map actionsRecords = new HashMap<>(); /** @@ -97,6 +98,11 @@ public void setSearchService(SearchService searchService) this.searchService = searchService; } + public void setSimpleCache(SimpleCache simpleCache) + { + this.simpleCache = simpleCache; + } + /** * @see ActionExecuter#execute(Action, NodeRef) */ @@ -131,7 +137,6 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); searchParameters.setQuery(query); - //searchParameters.addFacetQuery(); try { @@ -195,6 +200,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) { nodeAction.setParameterValue(RESULT, (Serializable) response); actionsRecords.put(nodeAction.getId(),nodeAction); + simpleCache.put(nodeAction.getId(),response); } } diff --git a/repository/src/main/resources/alfresco/action-services-context.xml b/repository/src/main/resources/alfresco/action-services-context.xml index e9d179d9b89..a6932607542 100644 --- a/repository/src/main/resources/alfresco/action-services-context.xml +++ b/repository/src/main/resources/alfresco/action-services-context.xml @@ -792,6 +792,7 @@ + From 464fc207fcc2c685b7b1e6d5e0bbef6e698fa947 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 23 Jul 2024 14:47:05 +0530 Subject: [PATCH 078/267] [feature/MNT-24127] Endpoint Added To Calculate Folder Size --- .../rest/api/tests/NodeFolderSizeApiTest.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 2ede35540ef..01e00fe8ee5 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 @@ -25,6 +25,7 @@ */ package org.alfresco.rest.api.tests; +import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; @@ -43,6 +44,8 @@ import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import java.io.Serializable; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -72,6 +75,10 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest private static String folderId; + private static String executionId; + + private SimpleCache executingActionsCache; + /** * The logger */ @@ -99,6 +106,7 @@ public void setup() throws Exception permissionService = applicationContext.getBean("permissionService", PermissionService.class); nodeService = applicationContext.getBean("NodeService", NodeService.class); mimeTypeService = applicationContext.getBean("MimetypeService", MimetypeService.class); + executingActionsCache = (SimpleCache) applicationContext.getBean("folderSizeSharedCache"); setRequestContext(user1); @@ -134,9 +142,9 @@ public void testAPostCalculateFolderSize() throws Exception { Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); - // Convert document to string and validate contentNodeId - String contentNodeId = document.toString(); - assertNotNull("Content node ID should not be null", contentNodeId); + // Convert document to string and validate executionId + executionId = document.toString(); + assertNotNull("executionId should not be null", executionId); } /** @@ -150,7 +158,7 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(getFolderSizeUrl(folderId), null, 200); + HttpResponse response = getSingle(getFolderSizeUrl(executionId), null, 200); assertNotNull(response); String jsonResponse = String.valueOf(response.getJsonResponse()); From 2a1ee7d312ef7f75975ea8cc33d382431581f03b Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 23 Jul 2024 14:49:55 +0530 Subject: [PATCH 079/267] [feature/MNT-24127] Endpoint Added To Calculate Folder Size --- .../alfresco/repo/action/executer/NodeSizeActionExecuter.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 1d887dbd7a3..d947ffdb81f 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -65,7 +65,6 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase public static final String RESULT = "size-result"; public static final String ERROR = "exception"; private SimpleCache simpleCache; - public static final Map actionsRecords = new HashMap<>(); /** * The node service @@ -199,7 +198,6 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) if(isCalculationCompleted) { nodeAction.setParameterValue(RESULT, (Serializable) response); - actionsRecords.put(nodeAction.getId(),nodeAction); simpleCache.put(nodeAction.getId(),response); } } From ec2280531fc3964a6337622908aed9c74c782954 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 23 Jul 2024 15:15:57 +0530 Subject: [PATCH 080/267] [feature/MNT-24127] Endpoint Added To Calculate Folder Size --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 1 + 1 file changed, 1 insertion(+) 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 01e00fe8ee5..1c42194b604 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,6 +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("}")); HttpResponse response = getSingle(getFolderSizeUrl(executionId), null, 200); assertNotNull(response); From 4edc87cb52aec6b4878cc1664ab62a136477fc76 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 23 Jul 2024 15:23:19 +0530 Subject: [PATCH 081/267] [feature/MNT-24127] Endpoint Added To Calculate Folder Size --- .../main/java/org/alfresco/rest/api/impl/FolderSizeImpl.java | 5 ----- 1 file changed, 5 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 ed3fd790460..6187be5812b 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 @@ -26,8 +26,6 @@ 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; @@ -35,9 +33,7 @@ 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.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +51,6 @@ public Map executingAsynchronousFolderAction(final int maxItems, folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); simpleCache.put(folderSizeAction.getId(),"IN-PROGRESS"); actionService.executeAction(folderSizeAction, nodeRef, false, true); - NodeSizeActionExecuter.actionsRecords.put(folderSizeAction.getId(),folderSizeAction); LOG.info("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); result.putIfAbsent("executionId",folderSizeAction.getId()); return result; From 2f3596266b4639336481ae8a30862b07b6be418f Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 23 Jul 2024 15:46:09 +0530 Subject: [PATCH 082/267] [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); From 43ca02592cd6e5a7c96046e9e84426b694b3dbb9 Mon Sep 17 00:00:00 2001 From: kshah Date: Wed, 24 Jul 2024 15:22:51 +0530 Subject: [PATCH 083/267] Some Optimization for NodeSize Calculation. --- .../rest/api/impl/FolderSizeImpl.java | 5 +- .../api/nodes/NodeFolderSizeRelation.java | 59 ++++++++----------- .../RelationshipResourceAction.java | 3 + .../executer/NodeSizeActionExecuter.java | 10 ++-- 4 files changed, 37 insertions(+), 40 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 131e0e248f8..34ec79390df 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 @@ -42,6 +42,7 @@ public class FolderSizeImpl { private ActionService actionService; private static final Logger LOG = LoggerFactory.getLogger(FolderSizeImpl.class); + private static final String IN_PROGRESS = "IN-PROGRESS"; public Map executingAsynchronousFolderAction(final int maxItems, final NodeRef nodeRef, final Map result, final SimpleCache simpleCache) { @@ -49,9 +50,11 @@ public Map executingAsynchronousFolderAction(final int maxItems, folderSizeAction.setTrackStatus(true); folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); - simpleCache.put(folderSizeAction.getId(),"IN-PROGRESS"); + simpleCache.put(folderSizeAction.getId(),IN_PROGRESS); actionService.executeAction(folderSizeAction, nodeRef, false, true); + LOG.info("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); + result.putIfAbsent("executionId",folderSizeAction.getId()); return result; } 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 35ad51726b7..0e3a2a90896 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 @@ -37,6 +37,7 @@ import org.alfresco.rest.framework.WebApiParameters; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.core.exceptions.NotFoundException; +import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.CalculateSize; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.ReadById; @@ -68,6 +69,12 @@ @RelationshipResource(name = "calculateSize", entityResource = NodesEntityResource.class, title = "Calculate size") public class NodeFolderSizeRelation implements CalculateSize>, ReadById>, InitializingBean { + + private static final Logger LOG = LoggerFactory.getLogger(NodeFolderSizeRelation.class); + + private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; + private static final String EXECUTIONID_NOT_FOUND = "Searched ExecutionId does not exist"; + private Nodes nodes; private SearchService searchService; private ServiceRegistry serviceRegistry; @@ -75,21 +82,8 @@ public class NodeFolderSizeRelation implements CalculateSize private NodeService nodeService; private ActionService actionService; private ActionTrackingService actionTrackingService; - 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 */ private SimpleCache simpleCache; - /** - * The logger - */ - private static final Logger LOG = LoggerFactory.getLogger(NodeFolderSizeRelation.class); - - /** - * The class that wraps the ReST APIs from core. - */ - public void setNodes(Nodes nodes) { this.nodes = nodes; @@ -116,12 +110,6 @@ public void setActionService(ActionService actionService) this.actionService = actionService; } - @Override - public void afterPropertiesSet() - { - ParameterCheck.mandatory("nodes", this.nodes); - } - public void setActionTrackingService(ActionTrackingService actionTrackingService) { this.actionTrackingService = actionTrackingService; @@ -132,6 +120,11 @@ public void setSimpleCache(SimpleCache simpleCache) this.simpleCache = simpleCache; } + @Override + public void afterPropertiesSet() + { + ParameterCheck.mandatory("nodes", this.nodes); + } /** * Folder Size - returns size of a folder. * @@ -151,12 +144,11 @@ public Map createById(String nodeId, Parameters params) int maxItems = Math.min(params.getPaging().getMaxItems(), 1000); QName qName = nodeService.getType(nodeRef); Map result = new HashMap<>(); - validatePermissions(nodeRef, nodeId); - if(!"folder".equals(qName.getLocalName())) + if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) { - throw new InvalidNodeTypeException(invalidMessage); + throw new InvalidNodeTypeException(INVALID_NODEID); } try @@ -164,33 +156,30 @@ public Map createById(String nodeId, Parameters params) FolderSizeImpl folderSizeImpl = new FolderSizeImpl(actionService); return folderSizeImpl.executingAsynchronousFolderAction(maxItems, nodeRef, result, simpleCache); } - catch (Exception ex) + catch (Exception alfrescoRuntimeError) { - LOG.error("Exception occurred in NodeFolderSizeRelation:createById {}", ex.getMessage()); - throw new AlfrescoRuntimeException("Exception occurred in NodeFolderSizeRelation:createById",ex); + LOG.error("Exception occurred in NodeFolderSizeRelation:createById {}", alfrescoRuntimeError.getMessage()); + throw new AlfrescoRuntimeException("Exception occurred in NodeFolderSizeRelation:createById",alfrescoRuntimeError); } } @Override @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") @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) + public Map readById(String executionId, String nodeId, Parameters parameters) { - Map result; - try { LOG.info("Retrieving OUTPUT from NodeSizeActionExecutor - NodeFolderSizeRelation:readById"); Object cachedResult = simpleCache.get(executionId); if(cachedResult != null) { - result = getResult(cachedResult); + return getResult(cachedResult); } else { - throw new NotFoundException(notFoundMessage); + throw new NotFoundException(EXECUTIONID_NOT_FOUND); } - return result; } catch (Exception ex) { @@ -198,6 +187,7 @@ public Map readById(String executionId, String id, Parameters pa throw ex; // Rethrow with original stack trace } } + private Map getResult(Object outputResult) { Map result = new HashMap<>(); @@ -205,12 +195,12 @@ private Map getResult(Object outputResult) if (outputResult instanceof Map) { Map mapResult = (Map) outputResult; - mapResult.put("status", "COMPLETED"); + mapResult.put(STATUS, COMPLETED); result = mapResult; } - else + else if(outputResult instanceof String) { - result.put("status", "IN-PROGRESS"); + result.put(STATUS, outputResult); } return result; } @@ -226,5 +216,4 @@ private void validatePermissions(NodeRef nodeRef, String nodeId) throw new AccessDeniedException("permissions.err_access_denied"); } } - } \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java index 40abf6a2f51..10c0e297b3e 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java @@ -166,6 +166,9 @@ public static interface DeleteSetWithResponse extends ResourceAction interface CalculateSize extends ResourceAction { + String STATUS = "status"; + String COMPLETED = "Completed"; + String FOLDER = "folder"; /** * Calculate the size of Folder Node. * diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index d947ffdb81f..abdea170837 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -64,13 +64,10 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase public static final String PAGE_SIZE = "page-size"; public static final String RESULT = "size-result"; public static final String ERROR = "exception"; - private SimpleCache simpleCache; - /** - * The node service - */ private NodeService nodeService; private SearchService searchService; + private SimpleCache simpleCache; /** * The logger @@ -97,6 +94,11 @@ public void setSearchService(SearchService searchService) this.searchService = searchService; } + /** + * Set the simpleCache service + * + * @param simpleCache the cache service + */ public void setSimpleCache(SimpleCache simpleCache) { this.simpleCache = simpleCache; From 6206be9c7753f14099b51674eee52ee6332833e3 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Mon, 29 Jul 2024 11:36:33 +0530 Subject: [PATCH 084/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/api/impl/FolderSizeImpl.java | 6 +- .../api/nodes/NodeFolderSizeRelation.java | 219 ------------------ .../rest/api/nodes/NodesEntityResource.java | 169 +++++++++++++- .../framework/core/ResourceInspector.java | 13 +- .../interfaces/EntityResourceAction.java | 22 ++ .../RelationshipResourceAction.java | 18 +- .../webscripts/ResourceWebScriptGet.java | 20 +- .../webscripts/ResourceWebScriptPost.java | 28 +-- .../alfresco/public-rest-context.xml | 14 +- .../rest/api/tests/AbstractBaseApiTest.java | 7 +- .../rest/api/tests/NodeFolderSizeApiTest.java | 14 +- .../framework/tests/core/InspectorTests.java | 1 - .../executer/NodeSizeActionExecuter.java | 4 +- .../executer/NodeSizeActionExecuterTest.java | 9 +- 14 files changed, 243 insertions(+), 301 deletions(-) delete mode 100644 remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeFolderSizeRelation.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 index 34ec79390df..5e2b4c091bc 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 @@ -44,16 +44,16 @@ public class FolderSizeImpl { private static final Logger LOG = LoggerFactory.getLogger(FolderSizeImpl.class); private static final String IN_PROGRESS = "IN-PROGRESS"; - public Map executingAsynchronousFolderAction(final int maxItems, final NodeRef nodeRef, final Map result, final SimpleCache simpleCache) + public Map executingAsynchronousFolderAction(final NodeRef nodeRef, final int maxItems, final Map result, final SimpleCache simpleCache) { Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); folderSizeAction.setTrackStatus(true); folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); - simpleCache.put(folderSizeAction.getId(),IN_PROGRESS); + simpleCache.put(nodeRef.getId(),IN_PROGRESS); actionService.executeAction(folderSizeAction, nodeRef, false, true); - LOG.info("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); + LOG.debug("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); result.putIfAbsent("executionId",folderSizeAction.getId()); return result; 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 deleted file mode 100644 index 0e3a2a90896..00000000000 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeFolderSizeRelation.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * #%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.nodes; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.security.permissions.AccessDeniedException; -import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.impl.FolderSizeImpl; -import org.alfresco.rest.api.model.Node; -import org.alfresco.rest.api.model.NodePermissions; -import org.alfresco.rest.framework.WebApiDescription; -import org.alfresco.rest.framework.WebApiParam; -import org.alfresco.rest.framework.WebApiParameters; -import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; -import org.alfresco.rest.framework.core.exceptions.NotFoundException; -import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException; -import org.alfresco.rest.framework.resource.RelationshipResource; -import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.CalculateSize; -import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.ReadById; -import org.alfresco.rest.framework.resource.parameters.Parameters; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.action.ActionTrackingService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.ParameterCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.extensions.webscripts.Status; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -/** - * NodeFolderSizeRelation - * Calculating and Retrieving the folder size - */ - -@RelationshipResource(name = "calculateSize", entityResource = NodesEntityResource.class, title = "Calculate size") -public class NodeFolderSizeRelation implements CalculateSize>, ReadById>, InitializingBean -{ - - private static final Logger LOG = LoggerFactory.getLogger(NodeFolderSizeRelation.class); - - private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; - private static final String EXECUTIONID_NOT_FOUND = "Searched ExecutionId does not exist"; - - private Nodes nodes; - private SearchService searchService; - private ServiceRegistry serviceRegistry; - private PermissionService permissionService; - private NodeService nodeService; - private ActionService actionService; - private ActionTrackingService actionTrackingService; - private SimpleCache simpleCache; - - public void setNodes(Nodes nodes) - { - this.nodes = nodes; - } - - public void setSearchService(SearchService searchService) - { - this.searchService = searchService; - } - - public void setServiceRegistry(ServiceRegistry serviceRegistry) - { - this.serviceRegistry = serviceRegistry; - this.permissionService = serviceRegistry.getPermissionService(); - } - - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - - public void setActionService(ActionService actionService) - { - this.actionService = actionService; - } - - public void setActionTrackingService(ActionTrackingService actionTrackingService) - { - this.actionTrackingService = actionTrackingService; - } - - public void setSimpleCache(SimpleCache simpleCache) - { - this.simpleCache = simpleCache; - } - - @Override - public void afterPropertiesSet() - { - ParameterCheck.mandatory("nodes", this.nodes); - } - /** - * Folder Size - returns size of a folder. - * - * @param nodeId String id of folder - will also accept well-known alias, eg. -root- or -my- or -shared- - * Please refer to OpenAPI spec for more details ! - * Returns the executionId which shows pending action, which can be used in a - * GET/calculateSize endpoint to check if the action's status has been completed, comprising the size of the node in bytes. - *

- * If NodeId does not exist, EntityNotFoundException (status 404). - * If nodeId does not represent a folder, InvalidNodeTypeException (status 422). - */ - @Override - @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder", successStatus = Status.STATUS_ACCEPTED) - public Map createById(String nodeId, Parameters params) - { - NodeRef nodeRef = nodes.validateNode(nodeId); - int maxItems = Math.min(params.getPaging().getMaxItems(), 1000); - QName qName = nodeService.getType(nodeRef); - Map result = new HashMap<>(); - validatePermissions(nodeRef, nodeId); - - if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) - { - throw new InvalidNodeTypeException(INVALID_NODEID); - } - - try - { - FolderSizeImpl folderSizeImpl = new FolderSizeImpl(actionService); - return folderSizeImpl.executingAsynchronousFolderAction(maxItems, nodeRef, result, simpleCache); - } - catch (Exception alfrescoRuntimeError) - { - LOG.error("Exception occurred in NodeFolderSizeRelation:createById {}", alfrescoRuntimeError.getMessage()); - throw new AlfrescoRuntimeException("Exception occurred in NodeFolderSizeRelation:createById",alfrescoRuntimeError); - } - } - - @Override - @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") - @WebApiParameters({@WebApiParam(name = "executionId", title = "The unique id of Execution Job", description = "A single execution id")}) - public Map readById(String executionId, String nodeId, Parameters parameters) - { - try - { - LOG.info("Retrieving OUTPUT from NodeSizeActionExecutor - NodeFolderSizeRelation:readById"); - Object cachedResult = simpleCache.get(executionId); - if(cachedResult != null) - { - return getResult(cachedResult); - } - else - { - throw new NotFoundException(EXECUTIONID_NOT_FOUND); - } - } - catch (Exception ex) - { - LOG.error("Exception occurred in NodeFolderSizeRelation:readById {}", ex.getMessage()); - throw ex; // Rethrow with original stack trace - } - } - - private Map getResult(Object outputResult) - { - Map result = new HashMap<>(); - - if (outputResult instanceof Map) - { - Map mapResult = (Map) outputResult; - mapResult.put(STATUS, COMPLETED); - result = mapResult; - } - else if(outputResult instanceof String) - { - result.put(STATUS, outputResult); - } - return result; - } - - private void validatePermissions(NodeRef nodeRef, String nodeId) - { - Node nodeInfo = nodes.getNode(nodeId); - NodePermissions nodePerms = nodeInfo.getPermissions(); - - // Validate permissions. - if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) - { - throw new AccessDeniedException("permissions.err_access_denied"); - } - } -} \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 89338921cf0..f4591d47dfc 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -27,21 +27,24 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.InputStream; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.content.directurl.DirectAccessUrlDisabledException; +import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.rest.api.DirectAccessUrlHelper; import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.model.DirectAccessUrlRequest; -import org.alfresco.rest.api.model.LockInfo; -import org.alfresco.rest.api.model.Node; -import org.alfresco.rest.api.model.NodeTarget; -import org.alfresco.rest.framework.BinaryProperties; -import org.alfresco.rest.framework.Operation; -import org.alfresco.rest.framework.WebApiDescription; -import org.alfresco.rest.framework.WebApiParam; +import org.alfresco.rest.api.impl.FolderSizeImpl; +import org.alfresco.rest.api.model.*; +import org.alfresco.rest.framework.*; import org.alfresco.rest.framework.core.ResourceParameter; import org.alfresco.rest.framework.core.exceptions.DisabledServiceException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; +import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; +import org.alfresco.rest.framework.core.exceptions.NotFoundException; import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; @@ -49,11 +52,21 @@ import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rest.framework.webscripts.WithResponse; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.DirectAccessUrl; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.namespace.QName; import org.alfresco.util.ParameterCheck; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.extensions.webscripts.Status; /** * An implementation of an Entity Resource for a Node (file or folder) @@ -65,10 +78,21 @@ @EntityResource(name="nodes", title = "Nodes") public class NodesEntityResource implements EntityResourceAction.ReadById, EntityResourceAction.Delete, EntityResourceAction.Update, - BinaryResourceAction.Read, BinaryResourceAction.Update, InitializingBean + BinaryResourceAction.Read, BinaryResourceAction.Update, EntityResourceAction.CalculateFolderSize>, EntityResourceAction.RetrieveFolderSize>, InitializingBean { + + private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class); + private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; + private static final String NODEID_NOT_FOUND = "Searched nodeId does not exist"; private Nodes nodes; private DirectAccessUrlHelper directAccessUrlHelper; + private SearchService searchService; + private ServiceRegistry serviceRegistry; + private PermissionService permissionService; + private NodeService nodeService; + private ActionService actionService; + private SimpleCache simpleCache; + public void setNodes(Nodes nodes) { @@ -80,6 +104,32 @@ public void setDirectAccessUrlHelper(DirectAccessUrlHelper directAccessUrlHelper this.directAccessUrlHelper = directAccessUrlHelper; } + public void setSearchService(SearchService searchService) + { + this.searchService = searchService; + } + + public void setServiceRegistry(ServiceRegistry serviceRegistry) + { + this.serviceRegistry = serviceRegistry; + this.permissionService = serviceRegistry.getPermissionService(); + } + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + public void setActionService(ActionService actionService) + { + this.actionService = actionService; + } + + public void setSimpleCache(SimpleCache simpleCache) + { + this.simpleCache = simpleCache; + } + @Override public void afterPropertiesSet() { @@ -225,5 +275,106 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq } return directAccessUrl; } + + /** + * Folder Size - returns size of a folder. + * + * @param nodeId String id of folder - will also accept well-known alias, eg. -root- or -my- or -shared- + * Please refer to OpenAPI spec for more details ! + * Returns the executionId which shows pending action, which can be used in a + * GET/calculateSize endpoint to check if the action's status has been completed, comprising the size of the node in bytes. + *

+ * If NodeId does not exist, EntityNotFoundException (status 404). + * If nodeId does not represent a folder, InvalidNodeTypeException (status 422). + */ + @Override + @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder", successStatus = Status.STATUS_ACCEPTED) + public Map createById(String nodeId, Parameters params) + { + NodeRef nodeRef = nodes.validateNode(nodeId); + int maxItems = Math.min(params.getPaging().getMaxItems(), 1000); + QName qName = nodeService.getType(nodeRef); + Map result = new HashMap<>(); + validatePermissions(nodeRef, nodeId); + + if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) + { + throw new InvalidNodeTypeException(INVALID_NODEID); + } + + try + { + FolderSizeImpl folderSizeImpl = new FolderSizeImpl(actionService); + return folderSizeImpl.executingAsynchronousFolderAction(nodeRef, maxItems, result, simpleCache); + } + catch (Exception alfrescoRuntimeError) + { + LOG.error("Exception occurred in NodesEntityResource:createById {}", alfrescoRuntimeError.getMessage()); + throw new AlfrescoRuntimeException("Exception occurred in NodesEntityResource:createById",alfrescoRuntimeError); + } + } + + @Override + @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") + @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) + public Map readByNodeId(String nodeId, Parameters parameters) + { + try + { + LOG.debug("Retrieving OUTPUT from NodeSizeActionExecutor - NodesEntityResource:readById"); + NodeRef nodeRef = nodes.validateNode(nodeId); + validatePermissions(nodeRef, nodeId); + QName qName = nodeService.getType(nodeRef); + + if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) + { + throw new InvalidNodeTypeException(INVALID_NODEID); + } + + Object cachedResult = simpleCache.get(nodeId); + if(cachedResult != null) + { + return getResult(cachedResult); + } + else + { + throw new NotFoundException(NODEID_NOT_FOUND); + } + } + catch (Exception ex) + { + LOG.error("Exception occurred in NodesEntityResource:readById {}", ex.getMessage()); + throw ex; // Rethrow with original stack trace + } + } + + private Map getResult(Object outputResult) + { + Map result = new HashMap<>(); + + if (outputResult instanceof Map) + { + Map mapResult = (Map) outputResult; + mapResult.put(STATUS, COMPLETED); + result = mapResult; + } + else if(outputResult instanceof String) + { + result.put(STATUS, outputResult); + } + return result; + } + + private void validatePermissions(NodeRef nodeRef, String nodeId) + { + Node nodeInfo = nodes.getNode(nodeId); + NodePermissions nodePerms = nodeInfo.getPermissions(); + + // Validate permissions. + if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) + { + throw new AccessDeniedException("permissions.err_access_denied"); + } + } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index 5388722b5be..1852251700d 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -110,6 +110,9 @@ public class ResourceInspector ALL_ENTITY_RESOURCE_INTERFACES.add(MultiPartResourceAction.Create.class); + ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.CalculateFolderSize.class); + ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.RetrieveFolderSize.class); + ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Create.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Read.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadById.class); @@ -126,7 +129,7 @@ public class ResourceInspector ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(MultiPartRelationshipResourceAction.Create.class); - ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.CalculateSize.class); + ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Read.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Delete.class); @@ -168,6 +171,9 @@ private static List inspectEntity(EntityResource annot, Class< findOperation(MultiPartResourceAction.Create.class, POST, helper); + findOperation(EntityResourceAction.CalculateFolderSize.class, POST, helper); + findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helper); + boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) { @@ -293,8 +299,9 @@ private static List inspectRelationship(RelationshipResource a findOperation(RelationshipResourceAction.DeleteSetWithResponse.class, DELETE, helper); findOperation(MultiPartRelationshipResourceAction.Create.class, POST, helper); - findOperation(RelationshipResourceAction.CalculateSize.class, POST, helper); - findOperation(RelationshipResourceAction.CalculateSize.class, GET, helper); + + findOperation(EntityResourceAction.CalculateFolderSize.class, POST, helper); + findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helper); boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java index 029b2b75e37..cc3348a7581 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java @@ -161,4 +161,26 @@ public static interface DeleteSetWithResponse extends ResourceAction */ public void deleteSet(Parameters params, WithResponse withResponse); } + + interface CalculateFolderSize extends ResourceAction + { + String STATUS = "status"; + String COMPLETED = "Completed"; + String FOLDER = "folder"; + /** + * Calculate the size of Folder Node. + * + * @param nodeId Entity resource context for this relationship. + * @param params implementation may choose to restrict the set to be deleted based on params (ie. not necessarily "all") + */ + E createById(String nodeId,Parameters params); + } + + /** + * HTTP GET - Retrieve an entity by its unique id + */ + interface RetrieveFolderSize extends ResourceAction + { + E readByNodeId (String nodeId, Parameters parameters) throws EntityNotFoundException; + } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java index 10c0e297b3e..3851727d806 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java @@ -26,7 +26,12 @@ package org.alfresco.rest.framework.resource.actions.interfaces; import java.util.List; +import java.util.Map; +import org.alfresco.rest.framework.WebApiDescription; +import org.alfresco.rest.framework.WebApiParam; +import org.alfresco.rest.framework.WebApiParameters; +import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Parameters; @@ -164,17 +169,4 @@ public static interface DeleteSetWithResponse extends ResourceAction public void deleteSet(String entityResourceId, Parameters params, WithResponse withResponse); } - interface CalculateSize extends ResourceAction - { - String STATUS = "status"; - String COMPLETED = "Completed"; - String FOLDER = "folder"; - /** - * Calculate the size of Folder Node. - * - * @param nodeId Entity resource context for this relationship. - * @param params implementation may choose to restrict the set to be deleted based on params (ie. not necessarily "all") - */ - E createById(String nodeId,Parameters params); - } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 50afa9ad8d4..ec1be50d1ac 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -219,6 +219,16 @@ else if (EntityResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resour Object result = entityGetter.readById(params.getEntityId(), params, withResponse); return result; } + else if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass())) + { + if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class)) + { + throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId()); + } + EntityResourceAction.RetrieveFolderSize relationGetter = (EntityResourceAction.RetrieveFolderSize) resource.getResource(); + Object result = relationGetter.readByNodeId(params.getEntityId(), params); + return result; + } else { throw new UnsupportedResourceOperationException(); @@ -238,16 +248,6 @@ else if (EntityResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resour CollectionWithPagingInfo relations = relationGetter.readAll(params.getEntityId(),params); return relations; } - else if (RelationshipResourceAction.ReadById.class.isAssignableFrom(resource.getResource().getClass())) - { - if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadById.class)) - { - throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId()); - } - RelationshipResourceAction.ReadById relationGetter = (RelationshipResourceAction.ReadById) resource.getResource(); - Object result = relationGetter.readById(params.getEntityId(), params.getRelationshipId(), params); - return result; - } else { if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadWithResponse.class)) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java index 9fc652c6f40..34058aba39c 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java @@ -93,6 +93,10 @@ public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req) { throw new UnsupportedResourceOperationException("POST is executed against a collection URL"); } + else if ("calculateSize".equals(operationName)) + { + return Params.valueOf(entityId, params, "", req); + } else { Object postedObj = processRequest(resourceMeta, operation, req); @@ -109,10 +113,6 @@ else if (StringUtils.isNotBlank(relationshipId)) { throw new UnsupportedResourceOperationException("POST is executed against a collection URL"); } - else if ("calculateSize".equals(operationName)) - { - return Params.valueOf(entityId, params, "", req); - } else { Object postedRel = processRequest(resourceMeta, operation, req); @@ -321,6 +321,16 @@ public Object executeAction(ResourceWithMetadata resource, Params params, WithRe return wrapWithCollectionWithPaging(created); } } + else if (EntityResourceAction.CalculateFolderSize.class.isAssignableFrom(resource.getResource().getClass())) + { + if (resource.getMetaData().isDeleted(EntityResourceAction.CalculateFolderSize.class)) + { + throw new DeletedResourceException("(POST by id) " + resource.getMetaData().getUniqueId()); + } + EntityResourceAction.CalculateFolderSize relationGetter = (EntityResourceAction.CalculateFolderSize) resource.getResource(); + Object result = relationGetter.createById(params.getEntityId(),params); + return result; + } } case RELATIONSHIP: @@ -370,16 +380,6 @@ public Object executeAction(ResourceWithMetadata resource, Params params, WithRe return wrapWithCollectionWithPaging(createdRel); } } - else if (RelationshipResourceAction.CalculateSize.class.isAssignableFrom(resource.getResource().getClass())) - { - if (resource.getMetaData().isDeleted(RelationshipResourceAction.CalculateSize.class)) - { - throw new DeletedResourceException("(POST by id) " + resource.getMetaData().getUniqueId()); - } - RelationshipResourceAction.CalculateSize relationGetter = (RelationshipResourceAction.CalculateSize) resource.getResource(); - Object result = relationGetter.createById(params.getEntityId(),params); - return result; - } } case OPERATION: return executeOperation(resource, params, withResponse); diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index f237ba024aa..8a094f000ae 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1147,6 +1147,11 @@ + + + + + @@ -1770,13 +1775,4 @@ - - - - - - - - - diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index 5b7db342894..ce3bb6e2a7e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -1122,14 +1122,9 @@ protected void disableRestDirectAccessUrls() restDauConfig.setEnabled(false); } - protected String postFolderSizeCalculation(String nodeId) + protected String getFolderSizeUrl(String nodeId) { return URL_NODES + "/" + nodeId + "/" + URL_CALCULATESIZE; } - - protected String getFolderSizeUrl(String executionId) - { - return URL_NODES + "/" + executionId + "/" + URL_CALCULATESIZE; - } } 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 b444bd96122..672811cec08 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 @@ -25,7 +25,6 @@ */ package org.alfresco.rest.api.tests; -import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; @@ -45,7 +44,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.Serializable; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -77,8 +75,6 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest private static String executionId; - private SimpleCache executingActionsCache; - /** * The logger */ @@ -106,7 +102,6 @@ public void setup() throws Exception permissionService = applicationContext.getBean("permissionService", PermissionService.class); nodeService = applicationContext.getBean("NodeService", NodeService.class); mimeTypeService = applicationContext.getBean("MimetypeService", MimetypeService.class); - executingActionsCache = (SimpleCache) applicationContext.getBean("folderSizeSharedCache"); setRequestContext(user1); @@ -131,7 +126,7 @@ public void testAPostCalculateFolderSize() throws Exception { params.put("maxItems", "100"); // Perform POST request - HttpResponse response = post(postFolderSizeCalculation(folderId), toJsonAsStringNonNull(params), 202); + HttpResponse response = post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); // Validate response and parsed document assertNotNull("Response should not be null", response); @@ -158,8 +153,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('}')); - HttpResponse response = getSingle(getFolderSizeUrl(executionId), null, 200); + HttpResponse response = getSingle(getFolderSizeUrl(folderId), null, 200); assertNotNull(response); String jsonResponse = String.valueOf(response.getJsonResponse()); @@ -188,7 +182,7 @@ public void testHTTPStatus() throws Exception setRequestContext(user1); NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(folderId); - HttpResponse response = post(postFolderSizeCalculation(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); + HttpResponse response = post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); assertNotNull(response); // Create a folder within the site document's library. @@ -200,7 +194,7 @@ public void testHTTPStatus() throws Exception params.put("maxItems", "100"); // Perform POST request - response = post(postFolderSizeCalculation(nestedFolderId), toJsonAsStringNonNull(params), 422); + response = post(getFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); assertNotNull(response); } diff --git a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java index 85aa8b1f77a..85374ef1a6e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java +++ b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java @@ -41,7 +41,6 @@ import org.alfresco.rest.api.model.Comment; import org.alfresco.rest.api.nodes.NodeCommentsRelation; -import org.alfresco.rest.api.nodes.NodeFolderSizeRelation; import org.alfresco.rest.framework.Api; import org.alfresco.rest.framework.core.OperationResourceMetaData; import org.alfresco.rest.framework.core.ResourceInspector; diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index abdea170837..39e0438bd4e 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -188,7 +188,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) throw ex; } - LOG.info(" Calculating size of Folder Node - NodeSizeActionExecutor:executeImpl "); + LOG.debug(" Calculating size of Folder Node - NodeSizeActionExecutor:executeImpl "); final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); String formattedTimestamp = eventTimestamp.format(formatter); @@ -200,7 +200,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) if(isCalculationCompleted) { nodeAction.setParameterValue(RESULT, (Serializable) response); - simpleCache.put(nodeAction.getId(),response); + simpleCache.put(nodeRef.getId(),response); } } diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index 7c8f5494851..aedbd3339ba 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -60,7 +60,12 @@ public class NodeSizeActionExecuterTest extends BaseSpringTest */ private final static String ID = GUID.generate(); - private SimpleCache executingActionsCache; + /** + * Set the simpleCache service + * + * @param simpleCache the cache service + */ + private SimpleCache simpleCache; /** * Called at the begining of all tests. @@ -90,7 +95,7 @@ public void before() throws Exception // Get the executer instance. this.executer = (NodeSizeActionExecuter)this.applicationContext.getBean(NodeSizeActionExecuter.NAME); - executingActionsCache = (SimpleCache) this.applicationContext.getBean("folderSizeSharedCache"); + simpleCache = (SimpleCache) this.applicationContext.getBean("folderSizeSharedCache"); } /** From 244d10f95f393fc89821a477d2553763763431c2 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Mon, 29 Jul 2024 12:15:06 +0530 Subject: [PATCH 085/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index ce3bb6e2a7e..755a2e5572f 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -105,7 +105,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi private static final String URL_CHILDREN = "children"; private static final String URL_CONTENT = "content"; - private static final String URL_CALCULATESIZE = "calculateSize"; + private static final String URL_CALCULATESIZE = "folder-size"; protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; From 4a43eaabb0e1fb7b45524a09fb7151e17aa3b567 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Mon, 29 Jul 2024 22:23:28 +0530 Subject: [PATCH 086/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/api/nodes/NodesEntityResource.java | 17 +++++++++----- .../framework/core/ResourceInspector.java | 9 -------- .../interfaces/EntityResourceAction.java | 22 ------------------- .../webscripts/ResourceWebScriptGet.java | 20 ++++++++--------- .../webscripts/ResourceWebScriptPost.java | 14 ------------ .../rest/api/tests/AbstractBaseApiTest.java | 11 +++++++--- .../rest/api/tests/NodeFolderSizeApiTest.java | 10 ++++----- 7 files changed, 34 insertions(+), 69 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index f4591d47dfc..3932691cea1 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -78,12 +78,16 @@ @EntityResource(name="nodes", title = "Nodes") public class NodesEntityResource implements EntityResourceAction.ReadById, EntityResourceAction.Delete, EntityResourceAction.Update, - BinaryResourceAction.Read, BinaryResourceAction.Update, EntityResourceAction.CalculateFolderSize>, EntityResourceAction.RetrieveFolderSize>, InitializingBean + BinaryResourceAction.Read, BinaryResourceAction.Update, InitializingBean { private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class); + private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; private static final String NODEID_NOT_FOUND = "Searched nodeId does not exist"; + private static final String STATUS = "status"; + private static final String COMPLETED = "Completed"; + private static final String FOLDER = "folder"; private Nodes nodes; private DirectAccessUrlHelper directAccessUrlHelper; private SearchService searchService; @@ -287,12 +291,13 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq * If NodeId does not exist, EntityNotFoundException (status 404). * If nodeId does not represent a folder, InvalidNodeTypeException (status 422). */ - @Override + @Operation("calculate-folder-size") @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder", successStatus = Status.STATUS_ACCEPTED) - public Map createById(String nodeId, Parameters params) + @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) + public Map calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) { NodeRef nodeRef = nodes.validateNode(nodeId); - int maxItems = Math.min(params.getPaging().getMaxItems(), 1000); + int maxItems = Math.min(parameters.getPaging().getMaxItems(), 1000); QName qName = nodeService.getType(nodeRef); Map result = new HashMap<>(); validatePermissions(nodeRef, nodeId); @@ -314,10 +319,10 @@ public Map createById(String nodeId, Parameters params) } } - @Override + @Operation("get-folder-size") @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) - public Map readByNodeId(String nodeId, Parameters parameters) + public Map getFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) { try { diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index 1852251700d..7ec1574661a 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -110,9 +110,6 @@ public class ResourceInspector ALL_ENTITY_RESOURCE_INTERFACES.add(MultiPartResourceAction.Create.class); - ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.CalculateFolderSize.class); - ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.RetrieveFolderSize.class); - ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Create.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Read.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadById.class); @@ -171,9 +168,6 @@ private static List inspectEntity(EntityResource annot, Class< findOperation(MultiPartResourceAction.Create.class, POST, helper); - findOperation(EntityResourceAction.CalculateFolderSize.class, POST, helper); - findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helper); - boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) { @@ -300,9 +294,6 @@ private static List inspectRelationship(RelationshipResource a findOperation(MultiPartRelationshipResourceAction.Create.class, POST, helper); - findOperation(EntityResourceAction.CalculateFolderSize.class, POST, helper); - findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helper); - boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) { diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java index cc3348a7581..029b2b75e37 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java @@ -161,26 +161,4 @@ public static interface DeleteSetWithResponse extends ResourceAction */ public void deleteSet(Parameters params, WithResponse withResponse); } - - interface CalculateFolderSize extends ResourceAction - { - String STATUS = "status"; - String COMPLETED = "Completed"; - String FOLDER = "folder"; - /** - * Calculate the size of Folder Node. - * - * @param nodeId Entity resource context for this relationship. - * @param params implementation may choose to restrict the set to be deleted based on params (ie. not necessarily "all") - */ - E createById(String nodeId,Parameters params); - } - - /** - * HTTP GET - Retrieve an entity by its unique id - */ - interface RetrieveFolderSize extends ResourceAction - { - E readByNodeId (String nodeId, Parameters parameters) throws EntityNotFoundException; - } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index ec1be50d1ac..50afa9ad8d4 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -219,16 +219,6 @@ else if (EntityResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resour Object result = entityGetter.readById(params.getEntityId(), params, withResponse); return result; } - else if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass())) - { - if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class)) - { - throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId()); - } - EntityResourceAction.RetrieveFolderSize relationGetter = (EntityResourceAction.RetrieveFolderSize) resource.getResource(); - Object result = relationGetter.readByNodeId(params.getEntityId(), params); - return result; - } else { throw new UnsupportedResourceOperationException(); @@ -248,6 +238,16 @@ else if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource CollectionWithPagingInfo relations = relationGetter.readAll(params.getEntityId(),params); return relations; } + else if (RelationshipResourceAction.ReadById.class.isAssignableFrom(resource.getResource().getClass())) + { + if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadById.class)) + { + throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId()); + } + RelationshipResourceAction.ReadById relationGetter = (RelationshipResourceAction.ReadById) resource.getResource(); + Object result = relationGetter.readById(params.getEntityId(), params.getRelationshipId(), params); + return result; + } else { if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadWithResponse.class)) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java index 34058aba39c..1d3500a5961 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java @@ -93,10 +93,6 @@ public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req) { throw new UnsupportedResourceOperationException("POST is executed against a collection URL"); } - else if ("calculateSize".equals(operationName)) - { - return Params.valueOf(entityId, params, "", req); - } else { Object postedObj = processRequest(resourceMeta, operation, req); @@ -321,16 +317,6 @@ public Object executeAction(ResourceWithMetadata resource, Params params, WithRe return wrapWithCollectionWithPaging(created); } } - else if (EntityResourceAction.CalculateFolderSize.class.isAssignableFrom(resource.getResource().getClass())) - { - if (resource.getMetaData().isDeleted(EntityResourceAction.CalculateFolderSize.class)) - { - throw new DeletedResourceException("(POST by id) " + resource.getMetaData().getUniqueId()); - } - EntityResourceAction.CalculateFolderSize relationGetter = (EntityResourceAction.CalculateFolderSize) resource.getResource(); - Object result = relationGetter.createById(params.getEntityId(),params); - return result; - } } case RELATIONSHIP: diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index 755a2e5572f..b9139c17a9d 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -105,7 +105,8 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi private static final String URL_CHILDREN = "children"; private static final String URL_CONTENT = "content"; - private static final String URL_CALCULATESIZE = "folder-size"; + private static final String URL_CALCULATEFOLDERSIZE = "calculate-folder-size"; + private static final String URL_GETFOLDERSIZE = "get-folder-size"; protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; @@ -1122,9 +1123,13 @@ protected void disableRestDirectAccessUrls() restDauConfig.setEnabled(false); } - protected String getFolderSizeUrl(String nodeId) + protected String getCalculateFolderSizeUrl(String nodeId) { - return URL_NODES + "/" + nodeId + "/" + URL_CALCULATESIZE; + return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE; + } + protected String getFolderSizeDataUrl(String nodeId) + { + return URL_NODES + "/" + nodeId + "/" + URL_GETFOLDERSIZE; } } 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 672811cec08..2b2c42318c7 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 @@ -126,7 +126,7 @@ public void testAPostCalculateFolderSize() throws Exception { params.put("maxItems", "100"); // Perform POST request - HttpResponse response = post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + HttpResponse response = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); // Validate response and parsed document assertNotNull("Response should not be null", response); @@ -153,7 +153,7 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(getFolderSizeUrl(folderId), null, 200); + HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, 200); assertNotNull(response); String jsonResponse = String.valueOf(response.getJsonResponse()); @@ -177,12 +177,12 @@ public void testBGetCalculateFolderSize() throws Exception public void testHTTPStatus() throws Exception { setRequestContext(null); - delete(getFolderSizeUrl(folderId), folderId, null, 401); + delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401); setRequestContext(user1); NodeTarget tgt = new NodeTarget(); tgt.setTargetParentId(folderId); - HttpResponse response = post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); + HttpResponse response = post(getCalculateFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); assertNotNull(response); // Create a folder within the site document's library. @@ -194,7 +194,7 @@ public void testHTTPStatus() throws Exception params.put("maxItems", "100"); // Perform POST request - response = post(getFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); + response = post(getCalculateFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); assertNotNull(response); } From 742ab3669a3d0032f80056cf884ed6b004ff6394 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Mon, 29 Jul 2024 22:46:23 +0530 Subject: [PATCH 087/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 2b2c42318c7..a91ba90bfe2 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 @@ -73,8 +73,6 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest private static String folderId; - private static String executionId; - /** * The logger */ @@ -138,7 +136,7 @@ public void testAPostCalculateFolderSize() throws Exception { assertNotNull("Parsed document should not be null", document); // Convert document to string and validate executionId - executionId = document.toString(); + String executionId = document.toString(); assertNotNull("executionId should not be null", executionId); } @@ -153,7 +151,7 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, 200); + HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), folderId, 200); assertNotNull(response); String jsonResponse = String.valueOf(response.getJsonResponse()); From 0f6bb34c725bfc7f6a40e8b69509c675fc09016e Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 30 Jul 2024 09:20:29 +0530 Subject: [PATCH 088/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../alfresco/rest/api/nodes/NodesEntityResource.java | 2 -- .../rest/framework/core/ResourceInspector.java | 12 +++++++++--- .../framework/webscripts/ResourceWebScriptGet.java | 10 ---------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 3932691cea1..21d426f7f23 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -97,7 +97,6 @@ public class NodesEntityResource implements private ActionService actionService; private SimpleCache simpleCache; - public void setNodes(Nodes nodes) { this.nodes = nodes; @@ -318,7 +317,6 @@ public Map calculateFolderSize(String nodeId, Void ignore, Param throw new AlfrescoRuntimeException("Exception occurred in NodesEntityResource:createById",alfrescoRuntimeError); } } - @Operation("get-folder-size") @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index 7ec1574661a..7fec9ef5b3a 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -126,8 +126,6 @@ public class ResourceInspector ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(MultiPartRelationshipResourceAction.Create.class); - - ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Read.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Delete.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Update.class); @@ -727,7 +725,15 @@ private static Map> findOperations(String Map annotAttribs = AnnotationUtils.getAnnotationAttributes(annot); String actionName = String.valueOf(annotAttribs.get("value")); String actionPath = ResourceDictionary.propertyResourceKey(entityPath, actionName); - ResourceOperation ro = inspectOperation(anyClass, annotatedMethod, POST); + ResourceOperation ro; + if("/nodes/{id}/get-folder-size".equals(actionPath)) + { + ro = inspectOperation(anyClass, annotatedMethod, GET); + } + else + { + ro = inspectOperation(anyClass, annotatedMethod, POST); + } embeds.put(actionPath, new Pair(ro, annotatedMethod)); } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 50afa9ad8d4..87ee84c074f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -238,16 +238,6 @@ else if (EntityResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resour CollectionWithPagingInfo relations = relationGetter.readAll(params.getEntityId(),params); return relations; } - else if (RelationshipResourceAction.ReadById.class.isAssignableFrom(resource.getResource().getClass())) - { - if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadById.class)) - { - throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId()); - } - RelationshipResourceAction.ReadById relationGetter = (RelationshipResourceAction.ReadById) resource.getResource(); - Object result = relationGetter.readById(params.getEntityId(), params.getRelationshipId(), params); - return result; - } else { if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadWithResponse.class)) From 32879377d1e9945cb90499b82cf8a517b27505e5 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 30 Jul 2024 09:41:46 +0530 Subject: [PATCH 089/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a91ba90bfe2..ce4c74921bc 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 @@ -151,7 +151,7 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), folderId, 200); + HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, 200); assertNotNull(response); String jsonResponse = String.valueOf(response.getJsonResponse()); From 9f109e9672e2b82e5e94e91c027253fa47638d6f Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 30 Jul 2024 12:31:17 +0530 Subject: [PATCH 090/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/api/nodes/NodesEntityResource.java | 9 ++++++--- .../rest/framework/core/ResourceInspector.java | 13 ++++--------- .../actions/interfaces/EntityResourceAction.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 21d426f7f23..6298abc2529 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -78,7 +78,7 @@ @EntityResource(name="nodes", title = "Nodes") public class NodesEntityResource implements EntityResourceAction.ReadById, EntityResourceAction.Delete, EntityResourceAction.Update, - BinaryResourceAction.Read, BinaryResourceAction.Update, InitializingBean + BinaryResourceAction.Read, BinaryResourceAction.Update, EntityResourceAction.RetrieveFolderSize>, InitializingBean { private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class); @@ -88,6 +88,7 @@ public class NodesEntityResource implements private static final String STATUS = "status"; private static final String COMPLETED = "Completed"; private static final String FOLDER = "folder"; + private Nodes nodes; private DirectAccessUrlHelper directAccessUrlHelper; private SearchService searchService; @@ -317,11 +318,13 @@ public Map calculateFolderSize(String nodeId, Void ignore, Param throw new AlfrescoRuntimeException("Exception occurred in NodesEntityResource:createById",alfrescoRuntimeError); } } - @Operation("get-folder-size") + @Override + @BinaryProperties({"get-folder-size"}) @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) - public Map getFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) + public Map getFolderSize(String nodeId, Parameters parameters) throws EntityNotFoundException { + try { LOG.debug("Retrieving OUTPUT from NodeSizeActionExecutor - NodesEntityResource:readById"); diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index 7fec9ef5b3a..3cbc45e1b61 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -110,6 +110,8 @@ public class ResourceInspector ALL_ENTITY_RESOURCE_INTERFACES.add(MultiPartResourceAction.Create.class); + ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.RetrieveFolderSize.class); + ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Create.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Read.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadById.class); @@ -163,6 +165,7 @@ private static List inspectEntity(EntityResource annot, Class< findOperation(EntityResourceAction.UpdateWithResponse.class, PUT, helper); findOperation(EntityResourceAction.DeleteWithResponse.class, DELETE, helper); findOperation(EntityResourceAction.DeleteSetWithResponse.class, DELETE, helper); + findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helper); findOperation(MultiPartResourceAction.Create.class, POST, helper); @@ -725,15 +728,7 @@ private static Map> findOperations(String Map annotAttribs = AnnotationUtils.getAnnotationAttributes(annot); String actionName = String.valueOf(annotAttribs.get("value")); String actionPath = ResourceDictionary.propertyResourceKey(entityPath, actionName); - ResourceOperation ro; - if("/nodes/{id}/get-folder-size".equals(actionPath)) - { - ro = inspectOperation(anyClass, annotatedMethod, GET); - } - else - { - ro = inspectOperation(anyClass, annotatedMethod, POST); - } + ResourceOperation ro = inspectOperation(anyClass, annotatedMethod, POST); embeds.put(actionPath, new Pair(ro, annotatedMethod)); } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java index 029b2b75e37..a3a692baf8d 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java @@ -161,4 +161,14 @@ public static interface DeleteSetWithResponse extends ResourceAction */ public void deleteSet(Parameters params, WithResponse withResponse); } + public static interface RetrieveFolderSize extends ResourceAction + { + /** + * get the size of Folder Node. + * + * @param nodeId Entity resource context for this relationship. + * @param params implementation may choose to restrict the set to be deleted based on params (ie. not necessarily "all") + */ + public E getFolderSize (String nodeId, Parameters parameters); + } } From 4fbca55d866b28fb1bce1991d3e7136afb574afd Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 30 Jul 2024 16:18:27 +0530 Subject: [PATCH 091/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../alfresco/rest/api/nodes/NodesEntityResource.java | 5 ++--- .../rest/framework/core/ResourceInspector.java | 4 +++- .../actions/interfaces/EntityResourceAction.java | 3 +-- .../framework/webscripts/ResourceWebScriptGet.java | 10 ++++++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 6298abc2529..cb657f5ed17 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -319,12 +319,11 @@ public Map calculateFolderSize(String nodeId, Void ignore, Param } } @Override - @BinaryProperties({"get-folder-size"}) @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) - public Map getFolderSize(String nodeId, Parameters parameters) throws EntityNotFoundException + @BinaryProperties({"get-folder-size"}) + public Map getFolderSize(String nodeId) throws EntityNotFoundException { - try { LOG.debug("Retrieving OUTPUT from NodeSizeActionExecutor - NodesEntityResource:readById"); diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index 3cbc45e1b61..e3e7712ac7a 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -135,6 +135,7 @@ public class ResourceInspector ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.ReadWithResponse.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.DeleteWithResponse.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.UpdateWithResponse.class); + ALL_PROPERTY_RESOURCE_INTERFACES.add(EntityResourceAction.RetrieveFolderSize.class); } /** @@ -165,7 +166,6 @@ private static List inspectEntity(EntityResource annot, Class< findOperation(EntityResourceAction.UpdateWithResponse.class, PUT, helper); findOperation(EntityResourceAction.DeleteWithResponse.class, DELETE, helper); findOperation(EntityResourceAction.DeleteSetWithResponse.class, DELETE, helper); - findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helper); findOperation(MultiPartResourceAction.Create.class, POST, helper); @@ -223,6 +223,8 @@ public static void inspectAddressedProperties(Api api, Class resource, final findOperation(RelationshipResourceBinaryAction.DeleteWithResponse.class, DELETE, helperForAddressProps); findOperation(RelationshipResourceBinaryAction.UpdateWithResponse.class, PUT, helperForAddressProps); + findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helperForAddressProps); + boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) { diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java index a3a692baf8d..6a5771b598d 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java @@ -167,8 +167,7 @@ public static interface RetrieveFolderSize extends ResourceAction * get the size of Folder Node. * * @param nodeId Entity resource context for this relationship. - * @param params implementation may choose to restrict the set to be deleted based on params (ie. not necessarily "all") */ - public E getFolderSize (String nodeId, Parameters parameters); + E getFolderSize (String nodeId); } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 87ee84c074f..69856741fb7 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -279,6 +279,16 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( case PROPERTY: if (StringUtils.isNotBlank(params.getEntityId())) { + if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass())) + { + if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class)) + { + throw new DeletedResourceException("(GET) "+resource.getMetaData().getUniqueId()); + } + EntityResourceAction.RetrieveFolderSize getter = (EntityResourceAction.RetrieveFolderSize) resource.getResource(); + Object result = getter.getFolderSize(params.getEntityId()); + return result; + } if (BinaryResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(BinaryResourceAction.Read.class)) From af7ebb06caaaf8a89ebf2016eae749befe818697 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 30 Jul 2024 16:53:10 +0530 Subject: [PATCH 092/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/framework/webscripts/ResourceWebScriptGet.java | 6 +++++- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 69856741fb7..a38dd8805bf 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -57,6 +57,8 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements ParamsExtractor, RecognizedParamsExtractor { private static Log logger = LogFactory.getLog(ResourceWebScriptGet.class); + + private static final String GET_FOLDERSIZE = "/nodes/{id}/get-folder-size"; public ResourceWebScriptGet() { @@ -279,7 +281,8 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( case PROPERTY: if (StringUtils.isNotBlank(params.getEntityId())) { - if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass())) + if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass()) + && GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId())) { if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class)) { @@ -289,6 +292,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( Object result = getter.getFolderSize(params.getEntityId()); return result; } + if (BinaryResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(BinaryResourceAction.Read.class)) 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 ce4c74921bc..a91ba90bfe2 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 @@ -151,7 +151,7 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, 200); + HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), folderId, 200); assertNotNull(response); String jsonResponse = String.valueOf(response.getJsonResponse()); From 3581f54beaf0c1e7afbfc4583d3d17f39ead5fda Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 31 Jul 2024 09:57:43 +0530 Subject: [PATCH 093/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 a91ba90bfe2..5c7daab9593 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 @@ -29,6 +29,7 @@ import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; +import org.alfresco.rest.api.tests.client.PublicApiHttpClient; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.service.cmr.repository.NodeService; @@ -44,6 +45,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -150,8 +152,13 @@ public void testBGetCalculateFolderSize() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(user1); + HttpResponse response2 = get(getFolderSizeDataUrl(folderId),null,200); + // Check if response and JSON parsing were successful - HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), folderId, 200); + String fileName = "demo.docx"; + File file = getResourceFile(fileName); + PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(file); + HttpResponse response = putBinary(getFolderSizeDataUrl(folderId), payload, null, null, 200); assertNotNull(response); String jsonResponse = String.valueOf(response.getJsonResponse()); From 76611fd1acaf7e47e68e145f12aa2208e197c5b1 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 31 Jul 2024 10:45:06 +0530 Subject: [PATCH 094/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) 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 5c7daab9593..5c83f65975d 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 @@ -150,16 +150,10 @@ public void testAPostCalculateFolderSize() throws Exception { @Test public void testBGetCalculateFolderSize() throws Exception { - AuthenticationUtil.setFullyAuthenticatedUser(user1); - - HttpResponse response2 = get(getFolderSizeDataUrl(folderId),null,200); + setRequestContext(null, user1, null); // Check if response and JSON parsing were successful - String fileName = "demo.docx"; - File file = getResourceFile(fileName); - PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(file); - HttpResponse response = putBinary(getFolderSizeDataUrl(folderId), payload, null, null, 200); - assertNotNull(response); + HttpResponse response = get(getFolderSizeDataUrl(folderId),null,200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From 0ce174586d8aa74125d2fae6f569282e7212de4f Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 31 Jul 2024 11:07:07 +0530 Subject: [PATCH 095/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 5c83f65975d..50f97b46fe9 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 @@ -150,10 +150,16 @@ public void testAPostCalculateFolderSize() throws Exception { @Test public void testBGetCalculateFolderSize() throws Exception { - setRequestContext(null, user1, null); + AuthenticationUtil.setFullyAuthenticatedUser(user1); + + Map params = new HashMap<>(); + params.put("nodeId", folderId); + params.put("skipCount", "0"); + params.put("maxItems", "100"); + params.put("properties", ""); // Check if response and JSON parsing were successful - HttpResponse response = get(getFolderSizeDataUrl(folderId),null,200); + HttpResponse response = get(getFolderSizeDataUrl(folderId),params,200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From 044b05481fb051e967a2a8c39ae1f8eef69da2ff Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 31 Jul 2024 11:47:52 +0530 Subject: [PATCH 096/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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 50f97b46fe9..4591501f6c5 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 @@ -28,6 +28,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; +import org.alfresco.rest.api.nodes.NodesEntityResource; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiHttpClient; import org.alfresco.rest.api.tests.util.RestApiUtil; @@ -152,14 +153,8 @@ public void testBGetCalculateFolderSize() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(user1); - Map params = new HashMap<>(); - params.put("nodeId", folderId); - params.put("skipCount", "0"); - params.put("maxItems", "100"); - params.put("properties", ""); - // Check if response and JSON parsing were successful - HttpResponse response = get(getFolderSizeDataUrl(folderId),params,200); + HttpResponse response = getSingle(NodesEntityResource.class, folderId+"/get-folder-size", null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From b88af161c86b13b5b92f5a9a658da5e19f14a5ae Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 31 Jul 2024 13:05:09 +0530 Subject: [PATCH 097/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 4591501f6c5..0ac52d80e24 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 @@ -153,8 +153,14 @@ public void testBGetCalculateFolderSize() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(user1); + String fileName = "demo.docx"; + File file = getResourceFile(fileName); + PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(file); + HttpResponse response = putBinary(getFolderSizeDataUrl(folderId), payload, null, null, 200); + assertNotNull(response); + // Check if response and JSON parsing were successful - HttpResponse response = getSingle(NodesEntityResource.class, folderId+"/get-folder-size", null, 200); + HttpResponse response2 = getSingle(getFolderSizeDataUrl(folderId), null, null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From 4faa421a55616708ae1b0debb5795b9d5c7e454f Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 31 Jul 2024 14:09:08 +0530 Subject: [PATCH 098/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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 0ac52d80e24..153510f1a9d 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 @@ -153,14 +153,8 @@ public void testBGetCalculateFolderSize() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(user1); - String fileName = "demo.docx"; - File file = getResourceFile(fileName); - PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(file); - HttpResponse response = putBinary(getFolderSizeDataUrl(folderId), payload, null, null, 200); - assertNotNull(response); - // Check if response and JSON parsing were successful - HttpResponse response2 = getSingle(getFolderSizeDataUrl(folderId), null, null, 200); + HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From 5e9a99dc02e6c3f84c2ecde84a67da43b5fe47d4 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 31 Jul 2024 15:21:16 +0530 Subject: [PATCH 099/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 153510f1a9d..7a66f199086 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 @@ -154,7 +154,13 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, null, 200); + //HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, null, 200); + Map params = new HashMap<>(); + params.put("nodeId", folderId); + params.put("skipCount", "0"); + params.put("maxItems", "100"); + params.put("properties", ""); + HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), (folderId + "/get-folder-size"), params, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From 2c879c7b16f9f5910c6f712fc882076dc260b8be Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 1 Aug 2024 14:29:19 +0530 Subject: [PATCH 100/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 7 +------ .../repo/action/executer/NodeSizeActionExecuter.java | 6 ++++++ 2 files changed, 7 insertions(+), 6 deletions(-) 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 7a66f199086..8f2c2258128 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 @@ -155,12 +155,7 @@ public void testBGetCalculateFolderSize() throws Exception // Check if response and JSON parsing were successful //HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, null, 200); - Map params = new HashMap<>(); - params.put("nodeId", folderId); - params.put("skipCount", "0"); - params.put("maxItems", "100"); - params.put("properties", ""); - HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), (folderId + "/get-folder-size"), params, 200); + HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), folderId, null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 39e0438bd4e..205aca9b727 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -138,6 +138,12 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); searchParameters.setQuery(query); + searchParameters.addFacetQuery("content.size:[0 TO 10240]\", \"label\": \"extra small\",\"group\":\"Size\""); + searchParameters.addFacetQuery("content.size:[10240 TO 102400]\", \"label\": \"small\", \"group\":\"Size\""); + searchParameters.addFacetQuery("content.size:[102400 TO 1048576]\", \"label\": \"medium\",\"group\":\"Size\""); + searchParameters.addFacetQuery("content.size:[1048576 TO 16777216]\", \"label\": \"large\",\"group\":\"Size\""); + final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet("content.size"); + searchParameters.addFieldFacet(ff); try { From 586990db88c5178ee2fe8e628c82c3b17a297b8b Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 1 Aug 2024 15:24:13 +0530 Subject: [PATCH 101/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java | 3 +-- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index b9139c17a9d..130d9ef5842 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -106,7 +106,6 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi private static final String URL_CHILDREN = "children"; private static final String URL_CONTENT = "content"; private static final String URL_CALCULATEFOLDERSIZE = "calculate-folder-size"; - private static final String URL_GETFOLDERSIZE = "get-folder-size"; protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; @@ -1129,7 +1128,7 @@ protected String getCalculateFolderSizeUrl(String nodeId) } protected String getFolderSizeDataUrl(String nodeId) { - return URL_NODES + "/" + nodeId + "/" + URL_GETFOLDERSIZE; + return URL_NODES + "/" + nodeId + "/"; } } 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 8f2c2258128..a97f627995e 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 @@ -154,8 +154,7 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - //HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, null, 200); - HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), folderId, null, 200); + HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), "get-folder-size", 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From 51f8142fd19f42fe6973154810e57b65b96b14b1 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 1 Aug 2024 15:54:35 +0530 Subject: [PATCH 102/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a97f627995e..3e9741a7faa 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 @@ -159,7 +159,7 @@ public void testBGetCalculateFolderSize() throws Exception String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); - assertTrue("We are not getting correct response",jsonResponse.contains("size") || jsonResponse.contains("status")); + assertTrue("We are not getting correct response "+jsonResponse,jsonResponse.contains("size") || jsonResponse.contains("status")); // Parse the JSON response. Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); From 7a16e30f3088c1a94cb158cca24e253c3171c95e Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 1 Aug 2024 16:31:40 +0530 Subject: [PATCH 103/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/api/tests/AbstractBaseApiTest.java | 4 ---- .../rest/api/tests/NodeFolderSizeApiTest.java | 18 ++---------------- .../executer/NodeSizeActionExecuter.java | 12 +++++++++++- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index 130d9ef5842..2f753cff670 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -1126,9 +1126,5 @@ protected String getCalculateFolderSizeUrl(String nodeId) { return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE; } - protected String getFolderSizeDataUrl(String nodeId) - { - return URL_NODES + "/" + nodeId + "/"; - } } 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 3e9741a7faa..cf48d16ab71 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 @@ -30,11 +30,7 @@ import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.nodes.NodesEntityResource; import org.alfresco.rest.api.tests.client.HttpResponse; -import org.alfresco.rest.api.tests.client.PublicApiHttpClient; import org.alfresco.rest.api.tests.util.RestApiUtil; -import org.alfresco.service.cmr.repository.MimetypeService; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; import org.junit.After; import org.junit.Before; @@ -46,7 +42,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -68,13 +63,7 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest */ private Site userOneN1Site; - protected PermissionService permissionService; - - private NodeService nodeService; - - private MimetypeService mimeTypeService; - - private static String folderId; + private String folderId; /** * The logger @@ -100,9 +89,6 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType) public void setup() throws Exception { super.setup(); - permissionService = applicationContext.getBean("permissionService", PermissionService.class); - nodeService = applicationContext.getBean("NodeService", NodeService.class); - mimeTypeService = applicationContext.getBean("MimetypeService", MimetypeService.class); setRequestContext(user1); @@ -154,7 +140,7 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), "get-folder-size", 200); + HttpResponse response = getSingle(NodesEntityResource.class, folderId+"/get-folder-size", null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 205aca9b727..068b9c12844 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -37,6 +37,7 @@ import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.util.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,6 +65,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase public static final String PAGE_SIZE = "page-size"; public static final String RESULT = "size-result"; public static final String ERROR = "exception"; + public static final String FIELD_FACET = "content.size"; private NodeService nodeService; private SearchService searchService; @@ -127,6 +129,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) NodeRef nodeRef = actionedUponNodeRef; long totalSize = 0; + long totalSizeFromFacet = 0; ResultSet results; boolean isCalculationCompleted = false; @@ -142,13 +145,19 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) searchParameters.addFacetQuery("content.size:[10240 TO 102400]\", \"label\": \"small\", \"group\":\"Size\""); searchParameters.addFacetQuery("content.size:[102400 TO 1048576]\", \"label\": \"medium\",\"group\":\"Size\""); searchParameters.addFacetQuery("content.size:[1048576 TO 16777216]\", \"label\": \"large\",\"group\":\"Size\""); - final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet("content.size"); + final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); searchParameters.addFieldFacet(ff); try { // executing Alfresco FTS query. results = searchService.query(searchParameters); + List> fieldData = results.getFieldFacet(FIELD_FACET); + totalSizeFromFacet = fieldData.stream() + .filter(pairData -> pairData.getSecond() > 0) + .mapToLong(pairData -> Long.valueOf(pairData.getFirst()) * pairData.getSecond()) + .sum(); + int skipCount = 0; int totalItems; totalItems = Math.min(results.getNodeRefs().size(), maxItems); @@ -200,6 +209,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) String formattedTimestamp = eventTimestamp.format(formatter); response.put("id", nodeRef.getId()); response.put("size", totalSize); + response.put("sizeFromFacet", totalSizeFromFacet); response.put("calculatedAt", formattedTimestamp); response.put("numberOfFiles", results != null ? results.getNodeRefs().size() : 0); From 58cd9db7307310c9a08e44c4039579558625b1d1 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 1 Aug 2024 17:16:57 +0530 Subject: [PATCH 104/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../org/alfresco/rest/api/tests/AbstractBaseApiTest.java | 5 +++++ .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index 2f753cff670..b9139c17a9d 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -106,6 +106,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi private static final String URL_CHILDREN = "children"; private static final String URL_CONTENT = "content"; private static final String URL_CALCULATEFOLDERSIZE = "calculate-folder-size"; + private static final String URL_GETFOLDERSIZE = "get-folder-size"; protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; @@ -1126,5 +1127,9 @@ protected String getCalculateFolderSizeUrl(String nodeId) { return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE; } + protected String getFolderSizeDataUrl(String nodeId) + { + return URL_NODES + "/" + nodeId + "/" + URL_GETFOLDERSIZE; + } } 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 cf48d16ab71..252d9bbd236 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 @@ -140,7 +140,7 @@ public void testBGetCalculateFolderSize() throws Exception AuthenticationUtil.setFullyAuthenticatedUser(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(NodesEntityResource.class, folderId+"/get-folder-size", null, 200); + HttpResponse response = putBinary(getFolderSizeDataUrl(folderId), null, null, null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From fbfcdfec3e10f4d38903b0bf73f5389e7a70fb57 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 1 Aug 2024 20:56:39 +0530 Subject: [PATCH 105/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 252d9bbd236..ced537e80a4 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 @@ -29,6 +29,7 @@ import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.nodes.NodesEntityResource; +import org.alfresco.rest.api.quicksharelinks.QuickShareLinkEntityResource; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.site.SiteVisibility; @@ -137,10 +138,10 @@ public void testAPostCalculateFolderSize() throws Exception { @Test public void testBGetCalculateFolderSize() throws Exception { - AuthenticationUtil.setFullyAuthenticatedUser(user1); + setRequestContext(null); // Check if response and JSON parsing were successful - HttpResponse response = putBinary(getFolderSizeDataUrl(folderId), null, null, null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From aa2acb18b2d101b8bbde8183824acc24e958dff1 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 1 Aug 2024 21:16:41 +0530 Subject: [PATCH 106/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ced537e80a4..cbb0d50b393 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 @@ -138,7 +138,7 @@ public void testAPostCalculateFolderSize() throws Exception { @Test public void testBGetCalculateFolderSize() throws Exception { - setRequestContext(null); + setRequestContext(user1); // Check if response and JSON parsing were successful HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); From 1073677dc72b8d1222ac21b82aa71a62f49df093 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 1 Aug 2024 22:49:52 +0530 Subject: [PATCH 107/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../resource/actions/interfaces/EntityResourceAction.java | 2 +- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 4 +--- .../alfresco/repo/action/executer/NodeSizeActionExecuter.java | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java index 6a5771b598d..ddd28525ec2 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java @@ -161,7 +161,7 @@ public static interface DeleteSetWithResponse extends ResourceAction */ public void deleteSet(Parameters params, WithResponse withResponse); } - public static interface RetrieveFolderSize extends ResourceAction + interface RetrieveFolderSize extends ResourceAction { /** * get the size of Folder Node. 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 cbb0d50b393..92a088f5bda 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 @@ -25,11 +25,9 @@ */ package org.alfresco.rest.api.tests; -import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.nodes.NodesEntityResource; -import org.alfresco.rest.api.quicksharelinks.QuickShareLinkEntityResource; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.site.SiteVisibility; @@ -141,7 +139,7 @@ public void testBGetCalculateFolderSize() throws Exception setRequestContext(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/content", null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 068b9c12844..0e886502831 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -129,7 +129,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) NodeRef nodeRef = actionedUponNodeRef; long totalSize = 0; - long totalSizeFromFacet = 0; + long totalSizeFromFacet; ResultSet results; boolean isCalculationCompleted = false; From 44f42992dd51dfd412a3f465fd5b04f188490c3f Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 1 Aug 2024 23:49:27 +0530 Subject: [PATCH 108/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/framework/webscripts/ResourceWebScriptGet.java | 2 +- .../org/alfresco/rest/api/tests/AbstractBaseApiTest.java | 5 ----- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index a38dd8805bf..e409f1f5907 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -282,7 +282,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( if (StringUtils.isNotBlank(params.getEntityId())) { if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass()) - && GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId())) + && (GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId()) || params.getEntityId().contains("get-folder-size"))) { if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class)) { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index b9139c17a9d..2f753cff670 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -106,7 +106,6 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi private static final String URL_CHILDREN = "children"; private static final String URL_CONTENT = "content"; private static final String URL_CALCULATEFOLDERSIZE = "calculate-folder-size"; - private static final String URL_GETFOLDERSIZE = "get-folder-size"; protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; @@ -1127,9 +1126,5 @@ protected String getCalculateFolderSizeUrl(String nodeId) { return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE; } - protected String getFolderSizeDataUrl(String nodeId) - { - return URL_NODES + "/" + nodeId + "/" + URL_GETFOLDERSIZE; - } } 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 92a088f5bda..383c1c8a299 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 @@ -139,7 +139,7 @@ public void testBGetCalculateFolderSize() throws Exception setRequestContext(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/content", null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From 873dfe2224f67e618ce877b5ffb54a96fb7ae92a Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Fri, 2 Aug 2024 00:15:12 +0530 Subject: [PATCH 109/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/framework/webscripts/ResourceWebScriptGet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index e409f1f5907..7cf611dc2e6 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -282,7 +282,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( if (StringUtils.isNotBlank(params.getEntityId())) { if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass()) - && (GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId()) || params.getEntityId().contains("get-folder-size"))) + && (GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId()) || params.getBinaryProperty().equals("get-folder-size"))) { if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class)) { From 0c5cc98de935c7bb183a2aa0c9648eff0b0bcd5d Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Fri, 2 Aug 2024 15:21:45 +0530 Subject: [PATCH 110/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/api/impl/FolderSizeImpl.java | 17 ++- .../webscripts/ResourceWebScriptGet.java | 2 +- .../rest/api/tests/NodeFolderSizeApiTest.java | 8 +- .../api/tests/client/PublicApiHttpClient.java | 2 + .../executer/NodeSizeActionExecuter.java | 112 ++++-------------- .../alfresco/action-services-context.xml | 1 - .../executer/NodeSizeActionExecuterTest.java | 2 +- 7 files changed, 46 insertions(+), 98 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 5e2b4c091bc..7834f92f5b2 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 @@ -45,6 +45,18 @@ public class FolderSizeImpl { private static final String IN_PROGRESS = "IN-PROGRESS"; public Map executingAsynchronousFolderAction(final NodeRef nodeRef, final int maxItems, final Map result, final SimpleCache simpleCache) + { + if(simpleCache.get(nodeRef.getId()) == null) + { + executeAction(nodeRef, maxItems, simpleCache); + } + LOG.debug("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); + + result.putIfAbsent("nodeId",nodeRef.getId()); + return result; + } + + protected void executeAction(NodeRef nodeRef, int maxItems, SimpleCache simpleCache) { Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); folderSizeAction.setTrackStatus(true); @@ -52,10 +64,5 @@ public Map executingAsynchronousFolderAction(final NodeRef nodeR folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); simpleCache.put(nodeRef.getId(),IN_PROGRESS); actionService.executeAction(folderSizeAction, nodeRef, false, true); - - LOG.debug("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); - - result.putIfAbsent("executionId",folderSizeAction.getId()); - return result; } } \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 7cf611dc2e6..0eb5a3b6cfa 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -282,7 +282,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( if (StringUtils.isNotBlank(params.getEntityId())) { if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass()) - && (GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId()) || params.getBinaryProperty().equals("get-folder-size"))) + && (GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId()))) { if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class)) { 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 383c1c8a299..55e874a627d 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 @@ -100,9 +100,9 @@ public void setup() throws Exception } /** - * Test case for POST/calculateSize, which calculates Folder Size. + * Test case for POST/calculate-folder-size, which calculates Folder Size. *

POST:

- * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} + * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculate-folder-size} */ @Test public void testAPostCalculateFolderSize() throws Exception { @@ -129,9 +129,9 @@ public void testAPostCalculateFolderSize() throws Exception { } /** - * Test case for GET/calculateSize, to retrieve FolderSize. + * Test case for GET/get-folder-size, to retrieve FolderSize. *

GET:

- * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculateSize} + * {@literal :/alfresco/api/-default-/public/alfresco/versions/1/nodes//get-folder-size} */ @Test public void testBGetCalculateFolderSize() throws Exception diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/PublicApiHttpClient.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/PublicApiHttpClient.java index 74c7f01e0a3..6c2de9dd273 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/PublicApiHttpClient.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/PublicApiHttpClient.java @@ -305,6 +305,7 @@ public HttpResponse get(final Class c, final RequestContext rq, final Object { RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, params); String url = endpoint.getUrl(); + System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&& "+url+" :: "+entityId); GetMethod req = new GetMethod(url); return submitRequest(req, rq); @@ -762,6 +763,7 @@ private class RestApiEndpoint } addParams(sb, params); + System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&& 2 "+sb.toString()); this.url = sb.toString(); } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 0e886502831..f096e8dda94 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -25,14 +25,11 @@ */ package org.alfresco.repo.action.executer; -import org.alfresco.model.ContentModel; import org.alfresco.repo.action.ParameterizedItemAbstractBase; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; -import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; @@ -49,7 +46,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; /** * NodeSizeActionExecuter @@ -58,34 +54,20 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase { + + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeActionExecuter.class); + /** * Action constants */ public static final String NAME = "folder-size"; public static final String PAGE_SIZE = "page-size"; - public static final String RESULT = "size-result"; public static final String ERROR = "exception"; public static final String FIELD_FACET = "content.size"; - private NodeService nodeService; private SearchService searchService; private SimpleCache simpleCache; - /** - * The logger - */ - private static final Logger LOG = LoggerFactory.getLogger(NodeSizeActionExecuter.class); - - /** - * Set the node service - * - * @param nodeService the node service - */ - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - /** * Set the search service * @@ -128,73 +110,18 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) } NodeRef nodeRef = actionedUponNodeRef; - long totalSize = 0; long totalSizeFromFacet; ResultSet results; - boolean isCalculationCompleted = false; - - StringBuilder aftsQuery = new StringBuilder(); - aftsQuery.append("ANCESTOR:\"").append(nodeRef).append("\" AND TYPE:content"); - String query = aftsQuery.toString(); - - SearchParameters searchParameters = new SearchParameters(); - searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - searchParameters.setQuery(query); - searchParameters.addFacetQuery("content.size:[0 TO 10240]\", \"label\": \"extra small\",\"group\":\"Size\""); - searchParameters.addFacetQuery("content.size:[10240 TO 102400]\", \"label\": \"small\", \"group\":\"Size\""); - searchParameters.addFacetQuery("content.size:[102400 TO 1048576]\", \"label\": \"medium\",\"group\":\"Size\""); - searchParameters.addFacetQuery("content.size:[1048576 TO 16777216]\", \"label\": \"large\",\"group\":\"Size\""); - final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); - searchParameters.addFieldFacet(ff); try { - // executing Alfresco FTS query. - results = searchService.query(searchParameters); + // executing Alfresco FTS facet query. + results = facetQuery(nodeRef); List> fieldData = results.getFieldFacet(FIELD_FACET); totalSizeFromFacet = fieldData.stream() .filter(pairData -> pairData.getSecond() > 0) .mapToLong(pairData -> Long.valueOf(pairData.getFirst()) * pairData.getSecond()) .sum(); - - int skipCount = 0; - int totalItems; - totalItems = Math.min(results.getNodeRefs().size(), maxItems); - - while (!isCalculationCompleted) - { - List nodeRefs = results.getNodeRefs().subList(skipCount, totalItems); - // Using AtomicLong to accumulate the total size. - AtomicLong resultSize = new AtomicLong(0); - nodeRefs.parallelStream().forEach(id -> { - try - { - ContentData contentData = (ContentData) nodeService.getProperty(id, ContentModel.PROP_CONTENT); - if (contentData != null) - { - resultSize.addAndGet(contentData.getSize()); - } - } - catch (Exception e) - { - resultSize.addAndGet(0); - } - }); - - totalSize+=resultSize.longValue(); - - if (results.getNodeRefs().size() <= totalItems || results.getNodeRefs().size() <= maxItems) - { - isCalculationCompleted = true; - } - else - { - skipCount += maxItems; - int remainingItems = results.getNodeRefs().size() - totalItems; - totalItems += Math.min(remainingItems, maxItems); - } - } } catch (RuntimeException ex) { @@ -207,17 +134,30 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); String formattedTimestamp = eventTimestamp.format(formatter); - response.put("id", nodeRef.getId()); - response.put("size", totalSize); - response.put("sizeFromFacet", totalSizeFromFacet); + response.put("nodeId", nodeRef.getId()); + response.put("size", totalSizeFromFacet); response.put("calculatedAt", formattedTimestamp); response.put("numberOfFiles", results != null ? results.getNodeRefs().size() : 0); + simpleCache.put(nodeRef.getId(),response); + } - if(isCalculationCompleted) - { - nodeAction.setParameterValue(RESULT, (Serializable) response); - simpleCache.put(nodeRef.getId(),response); - } + protected ResultSet facetQuery(NodeRef nodeRef) + { + StringBuilder aftsQuery = new StringBuilder(); + aftsQuery.append("ANCESTOR:\"").append(nodeRef).append("\" AND TYPE:content"); + String query = aftsQuery.toString(); + + SearchParameters searchParameters = new SearchParameters(); + searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); + searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); + searchParameters.setQuery(query); + searchParameters.addFacetQuery("content.size:[0 TO 10240]\", \"label\": \"extra small\",\"group\":\"Size\""); + searchParameters.addFacetQuery("content.size:[10240 TO 102400]\", \"label\": \"small\", \"group\":\"Size\""); + searchParameters.addFacetQuery("content.size:[102400 TO 1048576]\", \"label\": \"medium\",\"group\":\"Size\""); + searchParameters.addFacetQuery("content.size:[1048576 TO 16777216]\", \"label\": \"large\",\"group\":\"Size\""); + final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); + searchParameters.addFieldFacet(ff); + return searchService.query(searchParameters); } /** diff --git a/repository/src/main/resources/alfresco/action-services-context.xml b/repository/src/main/resources/alfresco/action-services-context.xml index a6932607542..8219092e444 100644 --- a/repository/src/main/resources/alfresco/action-services-context.xml +++ b/repository/src/main/resources/alfresco/action-services-context.xml @@ -791,7 +791,6 @@ - diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index aedbd3339ba..7a846342b0d 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -108,7 +108,7 @@ public void testExecution() ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null); action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); this.executer.executeImpl(action, this.nodeRef); - Object resultAction = action.getParameterValue(NodeSizeActionExecuter.RESULT); + Object resultAction = simpleCache.get(this.nodeRef.getId()); Map mapResult = (Map)resultAction; assertTrue(mapResult != null); } From e5dfe0ea946c6e255752b6a064a49ea115fdf327 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Fri, 2 Aug 2024 18:23:31 +0530 Subject: [PATCH 111/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 4 +++- .../alfresco/rest/api/tests/client/PublicApiHttpClient.java | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) 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 55e874a627d..547ba5d1a83 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 @@ -139,7 +139,9 @@ public void testBGetCalculateFolderSize() throws Exception setRequestContext(user1); // Check if response and JSON parsing were successful - HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); + Map params = new HashMap<>(); + params.put("nodeId", folderId); + HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", params, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/PublicApiHttpClient.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/PublicApiHttpClient.java index 6c2de9dd273..74c7f01e0a3 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/PublicApiHttpClient.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/PublicApiHttpClient.java @@ -305,7 +305,6 @@ public HttpResponse get(final Class c, final RequestContext rq, final Object { RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, params); String url = endpoint.getUrl(); - System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&& "+url+" :: "+entityId); GetMethod req = new GetMethod(url); return submitRequest(req, rq); @@ -763,7 +762,6 @@ private class RestApiEndpoint } addParams(sb, params); - System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&& 2 "+sb.toString()); this.url = sb.toString(); } From 6af94b0ca530c3a044490da2849da1a92a8c95cf Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Sat, 3 Aug 2024 13:38:36 +0530 Subject: [PATCH 112/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/api/tests/NodeFolderSizeApiTest.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 547ba5d1a83..41306381192 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 @@ -25,6 +25,7 @@ */ package org.alfresco.rest.api.tests; +import org.alfresco.repo.cache.SimpleCache; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.nodes.NodesEntityResource; @@ -41,6 +42,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.Serializable; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -57,13 +59,12 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest { - /** - * Private site of user two from network one. - */ private Site userOneN1Site; private String folderId; + private SimpleCache simpleCache; + /** * The logger */ @@ -139,9 +140,11 @@ public void testBGetCalculateFolderSize() throws Exception setRequestContext(user1); // Check if response and JSON parsing were successful - Map params = new HashMap<>(); - params.put("nodeId", folderId); - HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", params, 200); + simpleCache = (SimpleCache) this.applicationContext.getBean("folderSizeSharedCache"); + Object resultAction = simpleCache.get(folderId); + assertNotNull("simpleCache response should not be null", resultAction); + + HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); String jsonResponse = String.valueOf(response.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); From 7f2aaeb6728c983bfbca50a6a25f3511719a7518 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Sat, 3 Aug 2024 14:30:43 +0530 Subject: [PATCH 113/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 3 +++ 1 file changed, 3 insertions(+) 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 41306381192..4415d6c5714 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 @@ -114,6 +114,9 @@ public void testAPostCalculateFolderSize() throws Exception { // Perform POST request HttpResponse response = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + Object resultAction = simpleCache.get(folderId); + assertNotNull("simpleCache response should not be null", resultAction); + // Validate response and parsed document assertNotNull("Response should not be null", response); From b9f0b8da233d7a1c2366d65b39252f2848d0aef1 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Sat, 3 Aug 2024 14:49:41 +0530 Subject: [PATCH 114/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 1 + 1 file changed, 1 insertion(+) 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 4415d6c5714..75cbfd9c0f1 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 @@ -114,6 +114,7 @@ public void testAPostCalculateFolderSize() throws Exception { // Perform POST request HttpResponse response = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + simpleCache = (SimpleCache) this.applicationContext.getBean("folderSizeSharedCache"); Object resultAction = simpleCache.get(folderId); assertNotNull("simpleCache response should not be null", resultAction); From 50cd40a1ba6ad8ce9392bcc72860e6e3085c9656 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Sat, 3 Aug 2024 15:13:05 +0530 Subject: [PATCH 115/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size --- .../rest/api/tests/NodeFolderSizeApiTest.java | 47 ++++--------------- 1 file changed, 8 insertions(+), 39 deletions(-) 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 75cbfd9c0f1..901fccd053d 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 @@ -113,55 +113,24 @@ public void testAPostCalculateFolderSize() throws Exception { params.put("maxItems", "100"); // Perform POST request - HttpResponse response = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); - simpleCache = (SimpleCache) this.applicationContext.getBean("folderSizeSharedCache"); - Object resultAction = simpleCache.get(folderId); - assertNotNull("simpleCache response should not be null", resultAction); + HttpResponse postResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); // Validate response and parsed document - assertNotNull("Response should not be null", response); + assertNotNull("Response should not be null", postResponse); - String jsonResponse = String.valueOf(response.getJsonResponse()); + String jsonResponse = String.valueOf(postResponse.getJsonResponse()); assertNotNull("JSON response should not be null", jsonResponse); // Parse JSON response - Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); + Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); - // Convert document to string and validate executionId - String executionId = document.toString(); - assertNotNull("executionId should not be null", executionId); - } - - /** - * Test case for GET/get-folder-size, to retrieve FolderSize. - *

GET:

- * {@literal :/alfresco/api/-default-/public/alfresco/versions/1/nodes//get-folder-size} - */ - @Test - public void testBGetCalculateFolderSize() throws Exception - { - setRequestContext(user1); + HttpResponse getResponse = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); - // Check if response and JSON parsing were successful - simpleCache = (SimpleCache) this.applicationContext.getBean("folderSizeSharedCache"); - Object resultAction = simpleCache.get(folderId); - assertNotNull("simpleCache response should not be null", resultAction); - - HttpResponse response = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); - - String jsonResponse = String.valueOf(response.getJsonResponse()); - assertNotNull("JSON response should not be null", jsonResponse); - - assertTrue("We are not getting correct response "+jsonResponse,jsonResponse.contains("size") || jsonResponse.contains("status")); - - // Parse the JSON response. - Object document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Object.class); - assertNotNull("Parsed document should not be null", document); + String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); + assertNotNull("JSON response should not be null", getJsonResponse); - // Convert document to string and verify contentNodeId. - String contentNodeId = document.toString(); - assertNotNull("Content node ID should not be null", contentNodeId); + assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status")); } /** From 420100ec910c010fb5a562b109941dfdcddbc8ad Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Sat, 3 Aug 2024 23:42:05 +0530 Subject: [PATCH 116/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoint to calculate folder size --- .../rest/api/tests/NodeFolderSizeApiTest.java | 5 +-- .../executer/NodeSizeActionExecuter.java | 35 +++++++++++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) 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 901fccd053d..47dffff196e 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 @@ -102,11 +102,12 @@ public void setup() throws Exception /** * Test case for POST/calculate-folder-size, which calculates Folder Size. - *

POST:

+ * Test case for GET/get-folder-size, which calculates Folder Size. * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculate-folder-size} + * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//get-folder-size} */ @Test - public void testAPostCalculateFolderSize() throws Exception { + public void testPostAndGetFolderSize() throws Exception { // Prepare parameters Map params = new HashMap<>(); params.put("nodeId", folderId); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index f096e8dda94..69be2dcec8a 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -110,18 +110,36 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) } NodeRef nodeRef = actionedUponNodeRef; - long totalSizeFromFacet; + long totalSizeFromFacet = 0; + int skipCount = 0; ResultSet results; + int totalItems; + boolean isCalculationCompleted = false; try { // executing Alfresco FTS facet query. results = facetQuery(nodeRef); - List> fieldData = results.getFieldFacet(FIELD_FACET); - totalSizeFromFacet = fieldData.stream() - .filter(pairData -> pairData.getSecond() > 0) - .mapToLong(pairData -> Long.valueOf(pairData.getFirst()) * pairData.getSecond()) - .sum(); + totalItems = Math.min(results.getFieldFacet(FIELD_FACET).size(), maxItems); + + while (!isCalculationCompleted) + { + List> pairSizes = results.getFieldFacet(FIELD_FACET).subList(skipCount, totalItems); + totalSizeFromFacet = pairSizes.parallelStream().filter(pairData -> pairData.getSecond() > 0) + .mapToLong(pairData -> Long.valueOf(pairData.getFirst()) * pairData.getSecond()) + .sum(); + + if (results.getFieldFacet(FIELD_FACET).size() <= totalItems || results.getFieldFacet(FIELD_FACET).size() <= maxItems) + { + isCalculationCompleted = true; + } + else + { + skipCount += maxItems; + int remainingItems = results.getFieldFacet(FIELD_FACET).size() - totalItems; + totalItems += Math.min(remainingItems, maxItems); + } + } } catch (RuntimeException ex) { @@ -138,7 +156,10 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) response.put("size", totalSizeFromFacet); response.put("calculatedAt", formattedTimestamp); response.put("numberOfFiles", results != null ? results.getNodeRefs().size() : 0); - simpleCache.put(nodeRef.getId(),response); + if(isCalculationCompleted) + { + simpleCache.put(nodeRef.getId(),response); + } } protected ResultSet facetQuery(NodeRef nodeRef) From 17ddfdb6df3aa16810de0b19303b4416582a1df8 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Sun, 4 Aug 2024 00:08:15 +0530 Subject: [PATCH 117/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoint to calculate folder size --- .../executer/NodeSizeActionExecuter.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 69be2dcec8a..b8320793191 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -46,6 +46,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; /** * NodeSizeActionExecuter @@ -121,13 +122,26 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) // executing Alfresco FTS facet query. results = facetQuery(nodeRef); totalItems = Math.min(results.getFieldFacet(FIELD_FACET).size(), maxItems); + // Using AtomicLong to accumulate the total size. + AtomicLong resultSize = new AtomicLong(0); while (!isCalculationCompleted) { List> pairSizes = results.getFieldFacet(FIELD_FACET).subList(skipCount, totalItems); - totalSizeFromFacet = pairSizes.parallelStream().filter(pairData -> pairData.getSecond() > 0) - .mapToLong(pairData -> Long.valueOf(pairData.getFirst()) * pairData.getSecond()) - .sum(); + pairSizes.parallelStream().forEach(id -> { + try + { + if(id.getSecond()>0){ + resultSize.addAndGet(Long.valueOf(id.getFirst()) * id.getSecond()); + } + } + catch (Exception e) + { + resultSize.addAndGet(0); + } + }); + + totalSizeFromFacet+=resultSize.longValue(); if (results.getFieldFacet(FIELD_FACET).size() <= totalItems || results.getFieldFacet(FIELD_FACET).size() <= maxItems) { From 25ba6efdde63875b225f838014da922efce7086e Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Sun, 4 Aug 2024 09:06:15 +0530 Subject: [PATCH 118/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoint to calculate folder size --- .../rest/framework/webscripts/ResourceWebScriptGet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 0eb5a3b6cfa..a38dd8805bf 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -282,7 +282,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( if (StringUtils.isNotBlank(params.getEntityId())) { if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass()) - && (GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId()))) + && GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId())) { if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class)) { From 90e6bb89b9e36c75de22cd6ee250b559b280a8ef Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Mon, 5 Aug 2024 11:12:45 +0530 Subject: [PATCH 119/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoint to calculate folder size --- .../rest/api/nodes/NodesEntityResource.java | 15 ++------------- .../interfaces/RelationshipResourceAction.java | 9 ++------- .../resources/alfresco/public-rest-context.xml | 4 +--- .../rest/api/tests/NodeFolderSizeApiTest.java | 2 +- .../rest/framework/tests/core/InspectorTests.java | 1 - 5 files changed, 6 insertions(+), 25 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index cb657f5ed17..606136f40fa 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -52,12 +52,10 @@ import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rest.framework.webscripts.WithResponse; -import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.DirectAccessUrl; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; @@ -88,11 +86,8 @@ public class NodesEntityResource implements private static final String STATUS = "status"; private static final String COMPLETED = "Completed"; private static final String FOLDER = "folder"; - private Nodes nodes; private DirectAccessUrlHelper directAccessUrlHelper; - private SearchService searchService; - private ServiceRegistry serviceRegistry; private PermissionService permissionService; private NodeService nodeService; private ActionService actionService; @@ -108,15 +103,9 @@ public void setDirectAccessUrlHelper(DirectAccessUrlHelper directAccessUrlHelper this.directAccessUrlHelper = directAccessUrlHelper; } - public void setSearchService(SearchService searchService) - { - this.searchService = searchService; - } - - public void setServiceRegistry(ServiceRegistry serviceRegistry) + public void setPermissionService(PermissionService permissionService) { - this.serviceRegistry = serviceRegistry; - this.permissionService = serviceRegistry.getPermissionService(); + this.permissionService = permissionService; } public void setNodeService(NodeService nodeService) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java index 3851727d806..6c2e4db36e2 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java @@ -25,18 +25,13 @@ */ package org.alfresco.rest.framework.resource.actions.interfaces; -import java.util.List; -import java.util.Map; - -import org.alfresco.rest.framework.WebApiDescription; -import org.alfresco.rest.framework.WebApiParam; -import org.alfresco.rest.framework.WebApiParameters; -import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rest.framework.webscripts.WithResponse; +import java.util.List; + /** * Permissible actions for an Relationship Resources * Based around CRUD - Create, ReadAll, ReadById, Update, Delete, DeleteSet diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index dddc92113da..6fed535032d 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1148,8 +1148,7 @@ - - + @@ -1775,5 +1774,4 @@ - 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 47dffff196e..330c92f7ef5 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 @@ -102,7 +102,7 @@ public void setup() throws Exception /** * Test case for POST/calculate-folder-size, which calculates Folder Size. - * Test case for GET/get-folder-size, which calculates Folder Size. + * Test case for GET/get-folder-size, which receive Folder Size. * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculate-folder-size} * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//get-folder-size} */ diff --git a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java index 85374ef1a6e..646bae13b8c 100644 --- a/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java +++ b/remote-api/src/test/java/org/alfresco/rest/framework/tests/core/InspectorTests.java @@ -642,5 +642,4 @@ public void testValidSuccessCode() assertEquals(Status.STATUS_ACCEPTED,ResourceInspector.validSuccessCode(HttpMethod.PUT, Status.STATUS_ACCEPTED)); assertEquals(Status.STATUS_NOT_MODIFIED,ResourceInspector.validSuccessCode(HttpMethod.DELETE, Status.STATUS_NOT_MODIFIED)); } - } From bd6d21f6f34294749cf6fb8dc4076f6e0a95d6d7 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Mon, 5 Aug 2024 14:32:32 +0530 Subject: [PATCH 120/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoint to calculate folder size --- .../rest/framework/webscripts/ResourceWebScriptGet.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index a38dd8805bf..9fd3d6f8091 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -227,7 +227,7 @@ else if (EntityResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resour } } case RELATIONSHIP: - if (StringUtils.isBlank(params.getRelationshipId()) || (params.isCollectionResource())) + if (StringUtils.isBlank(params.getRelationshipId()) || params.isCollectionResource()) { // Get the collection if (RelationshipResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) @@ -292,7 +292,6 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( Object result = getter.getFolderSize(params.getEntityId()); return result; } - if (BinaryResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(BinaryResourceAction.Read.class)) @@ -341,7 +340,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( default: throw new UnsupportedResourceOperationException("GET not supported for Actions"); } - } + } } From a61c1e98e11106e538d078fa4933be2dd1fc04cf Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Mon, 5 Aug 2024 15:29:56 +0530 Subject: [PATCH 121/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoint to calculate folder size --- .../rest/api/nodes/NodesEntityResource.java | 5 +++++ .../webscripts/ResourceWebScriptGet.java | 12 ++++++++---- .../rest/api/tests/NodeFolderSizeApiTest.java | 12 +----------- .../action/executer/NodeSizeActionExecuter.java | 17 ++++++++--------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 606136f40fa..b3fdf283fc0 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -86,6 +86,7 @@ public class NodesEntityResource implements private static final String STATUS = "status"; private static final String COMPLETED = "Completed"; private static final String FOLDER = "folder"; + private static final String EXCEPTION = "Exception"; private Nodes nodes; private DirectAccessUrlHelper directAccessUrlHelper; private PermissionService permissionService; @@ -356,6 +357,10 @@ else if(outputResult instanceof String) { result.put(STATUS, outputResult); } + else if(outputResult instanceof Exception) + { + result.put(EXCEPTION, ((Exception) outputResult).getMessage()); + } return result; } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 9fd3d6f8091..84e05649377 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -292,7 +292,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( Object result = getter.getFolderSize(params.getEntityId()); return result; } - if (BinaryResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) + else if (BinaryResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(BinaryResourceAction.Read.class)) { @@ -302,7 +302,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( BinaryResource prop = getter.readProperty(params.getEntityId(), params); return prop; } - if (BinaryResourceAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass())) + else if (BinaryResourceAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(BinaryResourceAction.ReadWithResponse.class)) { @@ -312,7 +312,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( BinaryResource prop = getter.readProperty(params.getEntityId(), params, withResponse); return prop; } - if (RelationshipResourceBinaryAction.Read.class.isAssignableFrom(resource.getResource().getClass())) + else if (RelationshipResourceBinaryAction.Read.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.Read.class)) { @@ -322,7 +322,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( BinaryResource prop = getter.readProperty(params.getEntityId(), params.getRelationshipId(), params); return prop; } - if (RelationshipResourceBinaryAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass())) + else if (RelationshipResourceBinaryAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.ReadWithResponse.class)) { @@ -332,6 +332,10 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( BinaryResource prop = getter.readProperty(params.getEntityId(), params.getRelationshipId(), params, withResponse); return prop; } + else + { + throw new UnsupportedResourceOperationException(); + } } else { 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 330c92f7ef5..07d1a7bd892 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 @@ -25,7 +25,6 @@ */ package org.alfresco.rest.api.tests; -import org.alfresco.repo.cache.SimpleCache; import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.nodes.NodesEntityResource; @@ -41,8 +40,6 @@ import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.io.Serializable; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -58,18 +55,11 @@ @RunWith (JUnit4.class) public class NodeFolderSizeApiTest extends AbstractBaseApiTest { + private static final Logger LOG = LoggerFactory.getLogger(NodeFolderSizeApiTest.class); private Site userOneN1Site; - private String folderId; - private SimpleCache simpleCache; - - /** - * The logger - */ - private static final Logger LOG = LoggerFactory.getLogger(NodeFolderSizeApiTest.class); - private String addToDocumentLibrary(Site testSite, String name, String nodeType) { String parentId; diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index b8320793191..a8a982e2cd6 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -63,7 +63,6 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase */ public static final String NAME = "folder-size"; public static final String PAGE_SIZE = "page-size"; - public static final String ERROR = "exception"; public static final String FIELD_FACET = "content.size"; private SearchService searchService; @@ -103,11 +102,11 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) { maxItems = Integer.parseInt(serializable.toString()); } - catch (NumberFormatException e) + catch (NumberFormatException numberFormatException) { - LOG.error("Exception occurred while parsing String to INT: {}", e.getMessage()); - nodeAction.setParameterValue(ERROR, e.getMessage()); - throw e; + LOG.error("Exception occurred while parsing String to INT: {}", numberFormatException.getMessage()); + simpleCache.put(actionedUponNodeRef.getId(),numberFormatException); + throw numberFormatException; } NodeRef nodeRef = actionedUponNodeRef; @@ -155,11 +154,11 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) } } } - catch (RuntimeException ex) + catch (RuntimeException runtimeException) { - LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", ex.getMessage()); - nodeAction.setParameterValue(ERROR, ex.getMessage()); - throw ex; + LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", runtimeException.getMessage()); + simpleCache.put(nodeRef.getId(),runtimeException); + throw runtimeException; } LOG.debug(" Calculating size of Folder Node - NodeSizeActionExecutor:executeImpl "); From 8f8045e302968cf3a5322bd305941be98079676f Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Mon, 5 Aug 2024 16:49:08 +0530 Subject: [PATCH 122/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoint to calculate folder size --- .../actions/interfaces/RelationshipResourceAction.java | 5 ++--- .../repo/action/executer/NodeSizeActionExecuter.java | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java index 6c2e4db36e2..071641503fc 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/RelationshipResourceAction.java @@ -25,13 +25,13 @@ */ package org.alfresco.rest.framework.resource.actions.interfaces; +import java.util.List; + import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rest.framework.webscripts.WithResponse; -import java.util.List; - /** * Permissible actions for an Relationship Resources * Based around CRUD - Create, ReadAll, ReadById, Update, Delete, DeleteSet @@ -163,5 +163,4 @@ public static interface DeleteSetWithResponse extends ResourceAction */ public void deleteSet(String entityResourceId, Parameters params, WithResponse withResponse); } - } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index a8a982e2cd6..9eae86460f7 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -141,6 +141,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) }); totalSizeFromFacet+=resultSize.longValue(); + resultSize.set(0); if (results.getFieldFacet(FIELD_FACET).size() <= totalItems || results.getFieldFacet(FIELD_FACET).size() <= maxItems) { From fcc393e0fa994c284397555f6f25c7d8ea8c547a Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 00:23:48 +0530 Subject: [PATCH 123/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../rest/api/tests/NodeFolderSizeApiTest.java | 81 ++++++++++++++++++- 1 file changed, 78 insertions(+), 3 deletions(-) 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 07d1a7bd892..2bfc5284f9d 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 @@ -29,6 +29,11 @@ import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.nodes.NodesEntityResource; import org.alfresco.rest.api.tests.client.HttpResponse; +import org.alfresco.rest.api.tests.client.PublicApiClient; +import org.alfresco.rest.api.tests.client.data.ContentInfo; +import org.alfresco.rest.api.tests.client.data.Document; +import org.alfresco.rest.api.tests.client.data.Node; +import org.alfresco.rest.api.tests.client.data.UserInfo; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.site.SiteVisibility; import org.junit.After; @@ -41,12 +46,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * V1 REST API tests for Folder size @@ -60,6 +65,16 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest private Site userOneN1Site; private String folderId; + // Method to create content info + private ContentInfo createContentInfo() { + ContentInfo ciExpected = new ContentInfo(); + ciExpected.setMimeType("text/plain"); + ciExpected.setMimeTypeName("Plain Text"); + ciExpected.setSizeInBytes(44500L); + ciExpected.setEncoding("ISO-8859-1"); + return ciExpected; + } + private String addToDocumentLibrary(Site testSite, String name, String nodeType) { String parentId; @@ -97,7 +112,67 @@ public void setup() throws Exception * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//get-folder-size} */ @Test - public void testPostAndGetFolderSize() throws Exception { + public void testPostAndGetFolderSize() throws Exception + { + // Prepare parameters + Map params = new HashMap<>(); + params.put("nodeId", folderId); + params.put("maxItems", "100"); + + // Perform POST request + HttpResponse postResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + + // Validate response and parsed document + assertNotNull("Response should not be null", postResponse); + + String jsonResponse = String.valueOf(postResponse.getJsonResponse()); + assertNotNull("JSON response should not be null", jsonResponse); + + // Parse JSON response + Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); + assertNotNull("Parsed document should not be null", document); + + HttpResponse getResponse = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); + + String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); + assertNotNull("JSON response should not be null", getJsonResponse); + + assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status")); + } + + @Test + public void testPerformanceTesting() throws Exception + { + UserInfo userInfo = new UserInfo(user1); + + for(int i=0;i<=10;i++) + { + String folderAName = "folder" + RUNID + "_A"; + String folderA_Id = createFolder(folderId, folderAName).getId(); + + for(int j=0;j<=50;j++) + { + String folderBName = "folder" + RUNID + "_B"; + String folderB_Id = createFolder(folderA_Id, folderBName).getId(); + String fileName = "content " + RUNID + ".txt"; + + Document d1 = new Document(); + d1.setIsFolder(false); + d1.setParentId(folderB_Id); + d1.setName(fileName); + d1.setNodeType(TYPE_CM_CONTENT); + d1.setContent(createContentInfo()); + d1.setCreatedByUser(userInfo); + d1.setModifiedByUser(userInfo); + } + } + + PublicApiClient.Paging paging = getPaging(0, 1000); + HttpResponse response = getAll(getNodeChildrenUrl(folderId), paging, 200); + List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); + assertTrue("We are getting no. of nodes"+nodes.stream().filter(n->n.getIsFolder()).toList().size(),nodes.size()>100); + assertEquals(500, nodes.size()); + // Prepare parameters Map params = new HashMap<>(); params.put("nodeId", folderId); From 0e34ea7f045f99fc095c62d4a14d50f550e9921e Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 00:52:02 +0530 Subject: [PATCH 124/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../rest/api/tests/NodeFolderSizeApiTest.java | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) 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 2bfc5284f9d..01ba2b09aa1 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 @@ -145,26 +145,21 @@ public void testPerformanceTesting() throws Exception { UserInfo userInfo = new UserInfo(user1); - for(int i=0;i<=10;i++) + for(int i=0;i<=200;i++) { String folderAName = "folder" + RUNID + "_A"; - String folderA_Id = createFolder(folderId, folderAName).getId(); - - for(int j=0;j<=50;j++) - { - String folderBName = "folder" + RUNID + "_B"; - String folderB_Id = createFolder(folderA_Id, folderBName).getId(); - String fileName = "content " + RUNID + ".txt"; - - Document d1 = new Document(); - d1.setIsFolder(false); - d1.setParentId(folderB_Id); - d1.setName(fileName); - d1.setNodeType(TYPE_CM_CONTENT); - d1.setContent(createContentInfo()); - d1.setCreatedByUser(userInfo); - d1.setModifiedByUser(userInfo); - } + String folderBName = "folder" + RUNID + "_B"; + String folderA_Id = createFolder(folderId, folderAName,null).getId(); + String folderB_Id = createFolder(folderA_Id, folderBName,null).getId(); + String fileName = "content " + RUNID + ".txt"; + Document d1 = new Document(); + d1.setIsFolder(false); + d1.setParentId(folderB_Id); + d1.setName(fileName); + d1.setNodeType(TYPE_CM_CONTENT); + d1.setContent(createContentInfo()); + d1.setCreatedByUser(userInfo); + d1.setModifiedByUser(userInfo); } PublicApiClient.Paging paging = getPaging(0, 1000); From 0a38c0c991857a3ba87a4835bf30a81109ddd51e Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 01:35:03 +0530 Subject: [PATCH 125/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../rest/api/tests/NodeFolderSizeApiTest.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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 01ba2b09aa1..9088fd2d68c 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 @@ -144,13 +144,12 @@ public void testPostAndGetFolderSize() throws Exception public void testPerformanceTesting() throws Exception { UserInfo userInfo = new UserInfo(user1); + String parentFolder = createFolder(tDocLibNodeId, "ParentFolder",null).getId(); for(int i=0;i<=200;i++) { - String folderAName = "folder" + RUNID + "_A"; String folderBName = "folder" + RUNID + "_B"; - String folderA_Id = createFolder(folderId, folderAName,null).getId(); - String folderB_Id = createFolder(folderA_Id, folderBName,null).getId(); + String folderB_Id = createFolder(parentFolder, folderBName,null).getId(); String fileName = "content " + RUNID + ".txt"; Document d1 = new Document(); d1.setIsFolder(false); @@ -163,10 +162,10 @@ public void testPerformanceTesting() throws Exception } PublicApiClient.Paging paging = getPaging(0, 1000); - HttpResponse response = getAll(getNodeChildrenUrl(folderId), paging, 200); + HttpResponse response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertTrue("We are getting no. of nodes"+nodes.stream().filter(n->n.getIsFolder()).toList().size(),nodes.size()>100); - assertEquals(500, nodes.size()); + assertEquals(200, nodes.size()); // Prepare parameters Map params = new HashMap<>(); @@ -174,7 +173,7 @@ public void testPerformanceTesting() throws Exception params.put("maxItems", "100"); // Perform POST request - HttpResponse postResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + HttpResponse postResponse = post(getCalculateFolderSizeUrl(tDocLibNodeId), toJsonAsStringNonNull(params), 202); // Validate response and parsed document assertNotNull("Response should not be null", postResponse); @@ -186,7 +185,7 @@ public void testPerformanceTesting() throws Exception Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); - HttpResponse getResponse = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); + HttpResponse getResponse = getSingle(NodesEntityResource.class, tDocLibNodeId + "/get-folder-size", null, 200); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); assertNotNull("JSON response should not be null", getJsonResponse); From be674a2b17916c369ec072f109b20d34571c5945 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 01:36:57 +0530 Subject: [PATCH 126/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 9088fd2d68c..36be4384bac 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 @@ -162,7 +162,7 @@ public void testPerformanceTesting() throws Exception } PublicApiClient.Paging paging = getPaging(0, 1000); - HttpResponse response = getAll(getNodeChildrenUrl(tDocLibNodeId), paging, 200); + HttpResponse response = getAll(getNodeChildrenUrl(parentFolder), paging, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertTrue("We are getting no. of nodes"+nodes.stream().filter(n->n.getIsFolder()).toList().size(),nodes.size()>100); assertEquals(200, nodes.size()); @@ -173,7 +173,7 @@ public void testPerformanceTesting() throws Exception params.put("maxItems", "100"); // Perform POST request - HttpResponse postResponse = post(getCalculateFolderSizeUrl(tDocLibNodeId), toJsonAsStringNonNull(params), 202); + HttpResponse postResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 202); // Validate response and parsed document assertNotNull("Response should not be null", postResponse); @@ -185,7 +185,7 @@ public void testPerformanceTesting() throws Exception Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); - HttpResponse getResponse = getSingle(NodesEntityResource.class, tDocLibNodeId + "/get-folder-size", null, 200); + HttpResponse getResponse = getSingle(NodesEntityResource.class, parentFolder + "/get-folder-size", null, 200); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); assertNotNull("JSON response should not be null", getJsonResponse); From 33626b462787b197aea359141bb14ead6837c60a Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 09:12:23 +0530 Subject: [PATCH 127/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 36be4384bac..5d0fbf61d8b 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 @@ -143,8 +143,11 @@ public void testPostAndGetFolderSize() throws Exception @Test public void testPerformanceTesting() throws Exception { + setRequestContext(user1); + UserInfo userInfo = new UserInfo(user1); - String parentFolder = createFolder(tDocLibNodeId, "ParentFolder",null).getId(); + String folder0Name = "f0-testParentFolder-"+RUNID; + String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); for(int i=0;i<=200;i++) { From 1e0d40a8b8c728d5ad700c942ed534942e6bcc47 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 09:45:56 +0530 Subject: [PATCH 128/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../rest/api/tests/NodeFolderSizeApiTest.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) 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 5d0fbf61d8b..dea85114ae3 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 @@ -149,25 +149,23 @@ public void testPerformanceTesting() throws Exception String folder0Name = "f0-testParentFolder-"+RUNID; String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); - for(int i=0;i<=200;i++) - { - String folderBName = "folder" + RUNID + "_B"; - String folderB_Id = createFolder(parentFolder, folderBName,null).getId(); - String fileName = "content " + RUNID + ".txt"; - Document d1 = new Document(); - d1.setIsFolder(false); - d1.setParentId(folderB_Id); - d1.setName(fileName); - d1.setNodeType(TYPE_CM_CONTENT); - d1.setContent(createContentInfo()); - d1.setCreatedByUser(userInfo); - d1.setModifiedByUser(userInfo); - } + String folderBName = "folder" + RUNID + "_B"; + String folderB_Id = createFolder(parentFolder, folderBName,null).getId(); + String fileName = "content " + RUNID + ".txt"; + Document d1 = new Document(); + d1.setIsFolder(false); + d1.setParentId(folderB_Id); + d1.setName(fileName); + d1.setNodeType(TYPE_CM_CONTENT); + d1.setContent(createContentInfo()); + d1.setCreatedByUser(userInfo); + d1.setModifiedByUser(userInfo); + PublicApiClient.Paging paging = getPaging(0, 1000); HttpResponse response = getAll(getNodeChildrenUrl(parentFolder), paging, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); - assertTrue("We are getting no. of nodes"+nodes.stream().filter(n->n.getIsFolder()).toList().size(),nodes.size()>100); + assertTrue("We are getting no. of nodes"+nodes.stream().filter(n->n.getIsFolder()).toList().size(),nodes.size()>10); assertEquals(200, nodes.size()); // Prepare parameters From 671190436ea58f613e2c2e9a60cff83612ca46d6 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 11:11:46 +0530 Subject: [PATCH 129/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../rest/api/tests/NodeFolderSizeApiTest.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) 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 dea85114ae3..bd8f257c938 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 @@ -149,24 +149,26 @@ public void testPerformanceTesting() throws Exception String folder0Name = "f0-testParentFolder-"+RUNID; String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); - String folderBName = "folder" + RUNID + "_B"; - String folderB_Id = createFolder(parentFolder, folderBName,null).getId(); - String fileName = "content " + RUNID + ".txt"; - Document d1 = new Document(); - d1.setIsFolder(false); - d1.setParentId(folderB_Id); - d1.setName(fileName); - d1.setNodeType(TYPE_CM_CONTENT); - d1.setContent(createContentInfo()); - d1.setCreatedByUser(userInfo); - d1.setModifiedByUser(userInfo); - + for(int i=0;i<=100;i++) + { + String folderBName = "folder"+i+RUNID + "_B"; + String folderB_Id = createFolder(parentFolder, folderBName, null).getId(); + String fileName = "content"+i+ RUNID + ".txt"; + Document d1 = new Document(); + d1.setIsFolder(false); + d1.setParentId(folderB_Id); + d1.setName(fileName); + d1.setNodeType(TYPE_CM_CONTENT); + d1.setContent(createContentInfo()); + d1.setCreatedByUser(userInfo); + d1.setModifiedByUser(userInfo); + } PublicApiClient.Paging paging = getPaging(0, 1000); HttpResponse response = getAll(getNodeChildrenUrl(parentFolder), paging, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); - assertTrue("We are getting no. of nodes"+nodes.stream().filter(n->n.getIsFolder()).toList().size(),nodes.size()>10); - assertEquals(200, nodes.size()); + assertTrue("We are getting no. of nodes "+nodes.stream().filter(n->n.getIsFolder()).toList().size(),nodes.size()>10); + assertEquals(100, nodes.size()); // Prepare parameters Map params = new HashMap<>(); From 94006dcab24c1e5852f28a9a3e42d02c4622b28e Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 12:23:57 +0530 Subject: [PATCH 130/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../rest/api/tests/NodeFolderSizeApiTest.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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 bd8f257c938..6c8a41c07f4 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 @@ -45,6 +45,8 @@ import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import java.time.LocalTime; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -144,12 +146,12 @@ public void testPostAndGetFolderSize() throws Exception public void testPerformanceTesting() throws Exception { setRequestContext(user1); - UserInfo userInfo = new UserInfo(user1); + String folder0Name = "f0-testParentFolder-"+RUNID; String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); - for(int i=0;i<=100;i++) + for(int i=1;i<=300;i++) { String folderBName = "folder"+i+RUNID + "_B"; String folderB_Id = createFolder(parentFolder, folderBName, null).getId(); @@ -167,10 +169,12 @@ public void testPerformanceTesting() throws Exception PublicApiClient.Paging paging = getPaging(0, 1000); HttpResponse response = getAll(getNodeChildrenUrl(parentFolder), paging, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); - assertTrue("We are getting no. of nodes "+nodes.stream().filter(n->n.getIsFolder()).toList().size(),nodes.size()>10); - assertEquals(100, nodes.size()); + assertEquals(300, nodes.size()); - // Prepare parameters + //Start Time before triggering POST/calculate-folder-size API + LocalTime expectedTime = LocalTime.now().plusMinutes(1); + + // Prepare parameters. Map params = new HashMap<>(); params.put("nodeId", folderId); params.put("maxItems", "100"); @@ -188,6 +192,11 @@ public void testPerformanceTesting() throws Exception Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); + //end Time after executing POST/calculate-folder-size API + LocalTime actualTime = LocalTime.now(); + + assertTrue("Calculating folder node is taking time greater than 1 minute ",actualTime.isAfter(expectedTime)); + HttpResponse getResponse = getSingle(NodesEntityResource.class, parentFolder + "/get-folder-size", null, 200); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); From 76fdba77205bb8ffbdb97f0f54b98cca60c9f092 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 12:48:36 +0530 Subject: [PATCH 131/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../rest/api/tests/NodeFolderSizeApiTest.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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 6c8a41c07f4..207d38ac9ec 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 @@ -172,7 +172,7 @@ public void testPerformanceTesting() throws Exception assertEquals(300, nodes.size()); //Start Time before triggering POST/calculate-folder-size API - LocalTime expectedTime = LocalTime.now().plusMinutes(1); + LocalTime expectedTime = LocalTime.now().plusMinutes(2); // Prepare parameters. Map params = new HashMap<>(); @@ -192,17 +192,16 @@ public void testPerformanceTesting() throws Exception Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); - //end Time after executing POST/calculate-folder-size API - LocalTime actualTime = LocalTime.now(); - - assertTrue("Calculating folder node is taking time greater than 1 minute ",actualTime.isAfter(expectedTime)); - HttpResponse getResponse = getSingle(NodesEntityResource.class, parentFolder + "/get-folder-size", null, 200); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); assertNotNull("JSON response should not be null", getJsonResponse); - assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status")); + assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size")); + + //current Time after executing GET/get-folder-size API + LocalTime actualTime = LocalTime.now(); + assertTrue("Calculating folder node is taking time greater than 2 minute ",actualTime.isBefore(expectedTime)); } /** From d0f133d4b316a84d3eaa12884fb7e71960c496f9 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 13:01:02 +0530 Subject: [PATCH 132/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../org/alfresco/rest/api/nodes/NodesEntityResource.java | 7 +++++++ .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 3 ++- .../repo/action/executer/NodeSizeActionExecuter.java | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index b3fdf283fc0..9867ba5640b 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -308,6 +308,7 @@ public Map calculateFolderSize(String nodeId, Void ignore, Param throw new AlfrescoRuntimeException("Exception occurred in NodesEntityResource:createById",alfrescoRuntimeError); } } + @Override @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) @@ -343,6 +344,9 @@ public Map getFolderSize(String nodeId) throws EntityNotFoundExc } } + /** + * Providing the response from SimpleCache. + */ private Map getResult(Object outputResult) { Map result = new HashMap<>(); @@ -364,6 +368,9 @@ else if(outputResult instanceof Exception) return result; } + /** + * Validating node permission [i.e. READ permission should be there ] + */ private void validatePermissions(NodeRef nodeRef, String nodeId) { Node nodeInfo = nodes.getNode(nodeId); 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 207d38ac9ec..0c2ae91b73c 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 @@ -68,7 +68,8 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest private String folderId; // Method to create content info - private ContentInfo createContentInfo() { + private ContentInfo createContentInfo() + { ContentInfo ciExpected = new ContentInfo(); ciExpected.setMimeType("text/plain"); ciExpected.setMimeTypeName("Plain Text"); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 9eae86460f7..b5b84588199 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -130,7 +130,8 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) pairSizes.parallelStream().forEach(id -> { try { - if(id.getSecond()>0){ + if(id.getSecond()>0) + { resultSize.addAndGet(Long.valueOf(id.getFirst()) * id.getSecond()); } } From 7300e5b3a36ccf8caca8d61001fa1de74899c5b4 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 13:13:53 +0530 Subject: [PATCH 133/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 0c2ae91b73c..7a65af0410e 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 @@ -173,7 +173,7 @@ public void testPerformanceTesting() throws Exception assertEquals(300, nodes.size()); //Start Time before triggering POST/calculate-folder-size API - LocalTime expectedTime = LocalTime.now().plusMinutes(2); + LocalTime expectedTime = LocalTime.now().plusSeconds(15); // Prepare parameters. Map params = new HashMap<>(); @@ -202,7 +202,7 @@ public void testPerformanceTesting() throws Exception //current Time after executing GET/get-folder-size API LocalTime actualTime = LocalTime.now(); - assertTrue("Calculating folder node is taking time greater than 2 minute ",actualTime.isBefore(expectedTime)); + assertTrue("Calculating folder node is taking time greater than 15 seconds ",actualTime.isBefore(expectedTime)); } /** From 1287ab435430b91feab81ba02e3758993c2d096f Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 14:21:51 +0530 Subject: [PATCH 134/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding performance test case --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7a65af0410e..68b20daf4f7 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 @@ -173,7 +173,7 @@ public void testPerformanceTesting() throws Exception assertEquals(300, nodes.size()); //Start Time before triggering POST/calculate-folder-size API - LocalTime expectedTime = LocalTime.now().plusSeconds(15); + LocalTime expectedTime = LocalTime.now().plusSeconds(5); // Prepare parameters. Map params = new HashMap<>(); From 933a0e67df15a32ef8a9a7c31eb9489921c6e792 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Wed, 7 Aug 2024 21:58:30 +0530 Subject: [PATCH 135/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoints implementation to calculate folder size --- .../rest/api/impl/FolderSizeImpl.java | 11 ++++---- .../rest/api/nodes/NodesEntityResource.java | 27 +++++++++++-------- .../webscripts/ResourceWebScriptGet.java | 2 +- .../alfresco/project-remote-api.properties | 6 ++++- .../alfresco/public-rest-context.xml | 1 + .../rest/api/tests/NodeFolderSizeApiTest.java | 10 +++---- .../executer/NodeSizeActionExecuter.java | 25 ++++++++--------- .../main/resources/alfresco/caches.properties | 6 ++--- .../executer/NodeSizeActionExecuterTest.java | 2 +- 9 files changed, 49 insertions(+), 41 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 7834f92f5b2..21992439402 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,25 +43,26 @@ public class FolderSizeImpl { private ActionService actionService; private static final Logger LOG = LoggerFactory.getLogger(FolderSizeImpl.class); private static final String IN_PROGRESS = "IN-PROGRESS"; + private static final String MESSAGE = "Request has been acknowledged"; - public Map executingAsynchronousFolderAction(final NodeRef nodeRef, final int maxItems, final Map result, final SimpleCache simpleCache) + public Map executingAsynchronousFolderAction(final NodeRef nodeRef, final int defaultItems, final Map result, final SimpleCache simpleCache) { if(simpleCache.get(nodeRef.getId()) == null) { - executeAction(nodeRef, maxItems, simpleCache); + executeAction(nodeRef, defaultItems, simpleCache); } LOG.debug("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); - result.putIfAbsent("nodeId",nodeRef.getId()); + result.putIfAbsent("message",MESSAGE); return result; } - protected void executeAction(NodeRef nodeRef, int maxItems, SimpleCache simpleCache) + protected void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache simpleCache) { Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); folderSizeAction.setTrackStatus(true); folderSizeAction.setExecuteAsynchronously(true); - folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); + folderSizeAction.setParameterValue(NodeSizeActionExecuter.DEFAULT_SIZE, defaultItems); simpleCache.put(nodeRef.getId(),IN_PROGRESS); actionService.executeAction(folderSizeAction, nodeRef, false, true); } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 9867ba5640b..9ccd807d568 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -44,7 +44,6 @@ import org.alfresco.rest.framework.core.exceptions.DisabledServiceException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; -import org.alfresco.rest.framework.core.exceptions.NotFoundException; import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; @@ -82,9 +81,9 @@ public class NodesEntityResource implements private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class); private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; - private static final String NODEID_NOT_FOUND = "Searched nodeId does not exist"; + private static final String NOT_INITIATED = "NOT-INITIATED"; private static final String STATUS = "status"; - private static final String COMPLETED = "Completed"; + private static final String COMPLETED = "COMPLETED"; private static final String FOLDER = "folder"; private static final String EXCEPTION = "Exception"; private Nodes nodes; @@ -94,6 +93,8 @@ public class NodesEntityResource implements private ActionService actionService; private SimpleCache simpleCache; + private int defaultItems; + public void setNodes(Nodes nodes) { this.nodes = nodes; @@ -124,6 +125,11 @@ public void setSimpleCache(SimpleCache simpleCache) this.simpleCache = simpleCache; } + public void setDefaultItems(int defaultItems) + { + this.defaultItems = defaultItems; + } + @Override public void afterPropertiesSet() { @@ -287,7 +293,6 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq public Map calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) { NodeRef nodeRef = nodes.validateNode(nodeId); - int maxItems = Math.min(parameters.getPaging().getMaxItems(), 1000); QName qName = nodeService.getType(nodeRef); Map result = new HashMap<>(); validatePermissions(nodeRef, nodeId); @@ -300,7 +305,7 @@ public Map calculateFolderSize(String nodeId, Void ignore, Param try { FolderSizeImpl folderSizeImpl = new FolderSizeImpl(actionService); - return folderSizeImpl.executingAsynchronousFolderAction(nodeRef, maxItems, result, simpleCache); + return folderSizeImpl.executingAsynchronousFolderAction(nodeRef, defaultItems, result, simpleCache); } catch (Exception alfrescoRuntimeError) { @@ -312,9 +317,10 @@ public Map calculateFolderSize(String nodeId, Void ignore, Param @Override @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) - @BinaryProperties({"get-folder-size"}) + @BinaryProperties({"size"}) public Map getFolderSize(String nodeId) throws EntityNotFoundException { + Map result = new HashMap<>(); try { LOG.debug("Retrieving OUTPUT from NodeSizeActionExecutor - NodesEntityResource:readById"); @@ -330,12 +336,13 @@ public Map getFolderSize(String nodeId) throws EntityNotFoundExc Object cachedResult = simpleCache.get(nodeId); if(cachedResult != null) { - return getResult(cachedResult); + return getResult(cachedResult, result); } else { - throw new NotFoundException(NODEID_NOT_FOUND); + result.put(STATUS,NOT_INITIATED); } + return result; } catch (Exception ex) { @@ -347,10 +354,8 @@ public Map getFolderSize(String nodeId) throws EntityNotFoundExc /** * Providing the response from SimpleCache. */ - private Map getResult(Object outputResult) + private Map getResult(Object outputResult, Map result) { - Map result = new HashMap<>(); - if (outputResult instanceof Map) { Map mapResult = (Map) outputResult; diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 84e05649377..59a70342a00 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -58,7 +58,7 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P { private static Log logger = LogFactory.getLog(ResourceWebScriptGet.class); - private static final String GET_FOLDERSIZE = "/nodes/{id}/get-folder-size"; + private static final String GET_FOLDERSIZE = "/nodes/{id}/size"; public ResourceWebScriptGet() { diff --git a/remote-api/src/main/resources/alfresco/project-remote-api.properties b/remote-api/src/main/resources/alfresco/project-remote-api.properties index c76b37a1c22..188c872461e 100644 --- a/remote-api/src/main/resources/alfresco/project-remote-api.properties +++ b/remote-api/src/main/resources/alfresco/project-remote-api.properties @@ -23,4 +23,8 @@ # See issue REPO-2575 for details. alfresco.restApi.basicAuthScheme=false # REPO-4388 allow CORS headers in transaction response -webscripts.transaction.preserveHeadersPattern=Access-Control-.* \ No newline at end of file +webscripts.transaction.preserveHeadersPattern=Access-Control-.* + +#Default value being used in POT/calculate-folder-size endpoint to partition a huge folder into smaller chunks +#so that we can compute more efficiently and consolidate all sizes into a single unit. +alfresco.restApi.calculateFolderSize.items=1000 \ No newline at end of file diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 6fed535032d..223b8f94003 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1152,6 +1152,7 @@ + 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 68b20daf4f7..a891adf0a16 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 @@ -110,9 +110,9 @@ public void setup() throws Exception /** * Test case for POST/calculate-folder-size, which calculates Folder Size. - * Test case for GET/get-folder-size, which receive Folder Size. + * Test case for GET/size, which receive Folder Size. * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculate-folder-size} - * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//get-folder-size} + * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size} */ @Test public void testPostAndGetFolderSize() throws Exception @@ -135,7 +135,7 @@ public void testPostAndGetFolderSize() throws Exception Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); - HttpResponse getResponse = getSingle(NodesEntityResource.class, folderId + "/get-folder-size", null, 200); + HttpResponse getResponse = getSingle(NodesEntityResource.class, folderId + "/size", null, 200); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); assertNotNull("JSON response should not be null", getJsonResponse); @@ -193,14 +193,14 @@ public void testPerformanceTesting() throws Exception Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); - HttpResponse getResponse = getSingle(NodesEntityResource.class, parentFolder + "/get-folder-size", null, 200); + HttpResponse getResponse = getSingle(NodesEntityResource.class, parentFolder + "/size", null, 200); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); assertNotNull("JSON response should not be null", getJsonResponse); assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size")); - //current Time after executing GET/get-folder-size API + //current Time after executing GET/size API LocalTime actualTime = LocalTime.now(); assertTrue("Calculating folder node is taking time greater than 15 seconds ",actualTime.isBefore(expectedTime)); } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index b5b84588199..e92acd251ec 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -62,9 +62,9 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase * Action constants */ public static final String NAME = "folder-size"; - public static final String PAGE_SIZE = "page-size"; - public static final String FIELD_FACET = "content.size"; - + public static final String DEFAULT_SIZE = "default-size"; + private static final String FIELD_FACET = "content.size"; + private static final String FACET_QUERY = "content.size:[0 TO "+Integer.MAX_VALUE+"] \"label\": \"extra small\",\"group\":\"Size\""; private SearchService searchService; private SimpleCache simpleCache; @@ -94,13 +94,13 @@ public void setSimpleCache(SimpleCache simpleCache) @Override public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) { - Serializable serializable = nodeAction.getParameterValue(PAGE_SIZE); - int maxItems; + Serializable serializable = nodeAction.getParameterValue(DEFAULT_SIZE); + int defaultItems; Map response = new HashMap<>(); try { - maxItems = Integer.parseInt(serializable.toString()); + defaultItems = Integer.parseInt(serializable.toString()); } catch (NumberFormatException numberFormatException) { @@ -120,7 +120,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) { // executing Alfresco FTS facet query. results = facetQuery(nodeRef); - totalItems = Math.min(results.getFieldFacet(FIELD_FACET).size(), maxItems); + totalItems = Math.min(results.getFieldFacet(FIELD_FACET).size(), defaultItems); // Using AtomicLong to accumulate the total size. AtomicLong resultSize = new AtomicLong(0); @@ -144,15 +144,15 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) totalSizeFromFacet+=resultSize.longValue(); resultSize.set(0); - if (results.getFieldFacet(FIELD_FACET).size() <= totalItems || results.getFieldFacet(FIELD_FACET).size() <= maxItems) + if (results.getFieldFacet(FIELD_FACET).size() <= totalItems || results.getFieldFacet(FIELD_FACET).size() <= defaultItems) { isCalculationCompleted = true; } else { - skipCount += maxItems; + skipCount += defaultItems; int remainingItems = results.getFieldFacet(FIELD_FACET).size() - totalItems; - totalItems += Math.min(remainingItems, maxItems); + totalItems += Math.min(remainingItems, defaultItems); } } } @@ -187,10 +187,7 @@ protected ResultSet facetQuery(NodeRef nodeRef) searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); searchParameters.setQuery(query); - searchParameters.addFacetQuery("content.size:[0 TO 10240]\", \"label\": \"extra small\",\"group\":\"Size\""); - searchParameters.addFacetQuery("content.size:[10240 TO 102400]\", \"label\": \"small\", \"group\":\"Size\""); - searchParameters.addFacetQuery("content.size:[102400 TO 1048576]\", \"label\": \"medium\",\"group\":\"Size\""); - searchParameters.addFacetQuery("content.size:[1048576 TO 16777216]\", \"label\": \"large\",\"group\":\"Size\""); + searchParameters.addFacetQuery(FACET_QUERY); final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); searchParameters.addFieldFacet(ff); return searchService.query(searchParameters); diff --git a/repository/src/main/resources/alfresco/caches.properties b/repository/src/main/resources/alfresco/caches.properties index 0bcf8f5b120..54de84de395 100644 --- a/repository/src/main/resources/alfresco/caches.properties +++ b/repository/src/main/resources/alfresco/caches.properties @@ -713,9 +713,9 @@ cache.ldapInitialDirContextCache.readBackupData=false cache.folderSizeSharedCache.maxItems=1000 cache.folderSizeSharedCache.timeToLiveSeconds=0 -cache.folderSizeSharedCache.maxIdleSeconds=0 +cache.folderSizeSharedCache.maxIdleSeconds=300 cache.folderSizeSharedCache.cluster.type=fully-distributed cache.folderSizeSharedCache.backup-count=1 -cache.folderSizeSharedCache.eviction-policy=NONE -cache.folderSizeSharedCache.merge-policy=com.hazelcast.spi.merge.LatestUpdateMergePolicy +cache.folderSizeSharedCache.eviction-policy=LRU +cache.folderSizeSharedCache.merge-policy=com.hazelcast.spi.merge.PutIfAbsentMergePolicy cache.folderSizeSharedCache.readBackupData=false \ No newline at end of file diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java index 7a846342b0d..4c2ce3335d6 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java @@ -106,7 +106,7 @@ public void testExecution() { int maxItems = 100; ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null); - action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); + action.setParameterValue(NodeSizeActionExecuter.DEFAULT_SIZE, maxItems); this.executer.executeImpl(action, this.nodeRef); Object resultAction = simpleCache.get(this.nodeRef.getId()); Map mapResult = (Map)resultAction; From cb9c0513834e52ba2a7809f3670c8d81e9864c13 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 8 Aug 2024 00:56:41 +0530 Subject: [PATCH 136/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoints implementation to calculate folder size --- repository/src/main/resources/alfresco/caches.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/repository/src/main/resources/alfresco/caches.properties b/repository/src/main/resources/alfresco/caches.properties index 54de84de395..cbc24d5d5a7 100644 --- a/repository/src/main/resources/alfresco/caches.properties +++ b/repository/src/main/resources/alfresco/caches.properties @@ -712,8 +712,8 @@ cache.ldapInitialDirContextCache.merge-policy=com.hazelcast.spi.merge.LatestUpda cache.ldapInitialDirContextCache.readBackupData=false cache.folderSizeSharedCache.maxItems=1000 -cache.folderSizeSharedCache.timeToLiveSeconds=0 -cache.folderSizeSharedCache.maxIdleSeconds=300 +cache.folderSizeSharedCache.timeToLiveSeconds=300 +cache.folderSizeSharedCache.maxIdleSeconds=0 cache.folderSizeSharedCache.cluster.type=fully-distributed cache.folderSizeSharedCache.backup-count=1 cache.folderSizeSharedCache.eviction-policy=LRU From 8927470328ad0673bbb7d6c3acad04589fc87b6f Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 8 Aug 2024 13:25:33 +0530 Subject: [PATCH 137/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoints implementation to calculate folder size --- .../rest/api/nodes/NodesEntityResource.java | 13 ++++++------- .../rest/api/tests/NodeFolderSizeApiTest.java | 4 ++-- .../action/executer/NodeSizeActionExecuter.java | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 9ccd807d568..caff2c61b77 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -281,10 +281,9 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq * * @param nodeId String id of folder - will also accept well-known alias, eg. -root- or -my- or -shared- * Please refer to OpenAPI spec for more details ! - * Returns the executionId which shows pending action, which can be used in a - * GET/calculateSize endpoint to check if the action's status has been completed, comprising the size of the node in bytes. + * Returns the response message i.e. Request has been acknowledged with 202 + * GET/size endpoint to check if the action's status has been completed, comprising the size of the node in bytes. *

- * If NodeId does not exist, EntityNotFoundException (status 404). * If nodeId does not represent a folder, InvalidNodeTypeException (status 422). */ @Operation("calculate-folder-size") @@ -309,8 +308,8 @@ public Map calculateFolderSize(String nodeId, Void ignore, Param } catch (Exception alfrescoRuntimeError) { - LOG.error("Exception occurred in NodesEntityResource:createById {}", alfrescoRuntimeError.getMessage()); - throw new AlfrescoRuntimeException("Exception occurred in NodesEntityResource:createById",alfrescoRuntimeError); + LOG.error("Exception occurred in NodesEntityResource:calculateFolderSize {}", alfrescoRuntimeError.getMessage()); + throw new AlfrescoRuntimeException("Exception occurred in NodesEntityResource:calculateFolderSize",alfrescoRuntimeError); } } @@ -323,7 +322,7 @@ public Map getFolderSize(String nodeId) throws EntityNotFoundExc Map result = new HashMap<>(); try { - LOG.debug("Retrieving OUTPUT from NodeSizeActionExecutor - NodesEntityResource:readById"); + LOG.debug("Retrieving OUTPUT from NodeSizeActionExecutor - NodesEntityResource:getFolderSize"); NodeRef nodeRef = nodes.validateNode(nodeId); validatePermissions(nodeRef, nodeId); QName qName = nodeService.getType(nodeRef); @@ -346,7 +345,7 @@ public Map getFolderSize(String nodeId) throws EntityNotFoundExc } catch (Exception ex) { - LOG.error("Exception occurred in NodesEntityResource:readById {}", ex.getMessage()); + LOG.error("Exception occurred in NodesEntityResource:getFolderSize {}", ex.getMessage()); throw ex; // Rethrow with original stack trace } } 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 a891adf0a16..45403af3d93 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 @@ -152,7 +152,7 @@ public void testPerformanceTesting() throws Exception String folder0Name = "f0-testParentFolder-"+RUNID; String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); - for(int i=1;i<=300;i++) + for(int i=1;i<=500;i++) { String folderBName = "folder"+i+RUNID + "_B"; String folderB_Id = createFolder(parentFolder, folderBName, null).getId(); @@ -202,7 +202,7 @@ public void testPerformanceTesting() throws Exception //current Time after executing GET/size API LocalTime actualTime = LocalTime.now(); - assertTrue("Calculating folder node is taking time greater than 15 seconds ",actualTime.isBefore(expectedTime)); + assertTrue("Calculating folder node is taking time greater than 5 seconds ",actualTime.isBefore(expectedTime)); } /** diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index e92acd251ec..ef4a0110cc9 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -64,7 +64,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase public static final String NAME = "folder-size"; public static final String DEFAULT_SIZE = "default-size"; private static final String FIELD_FACET = "content.size"; - private static final String FACET_QUERY = "content.size:[0 TO "+Integer.MAX_VALUE+"] \"label\": \"extra small\",\"group\":\"Size\""; + private static final String FACET_QUERY = "content.size:[0 TO "+Integer.MAX_VALUE+"] \"label\": \"large\",\"group\":\"Size\""; private SearchService searchService; private SimpleCache simpleCache; From c01445b916e4dc24314baa3f2bf968ed0fca852c Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Thu, 8 Aug 2024 13:45:35 +0530 Subject: [PATCH 138/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Added endpoints implementation to calculate folder size --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 45403af3d93..0c91b1a4180 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 @@ -170,7 +170,7 @@ public void testPerformanceTesting() throws Exception PublicApiClient.Paging paging = getPaging(0, 1000); HttpResponse response = getAll(getNodeChildrenUrl(parentFolder), paging, 200); List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); - assertEquals(300, nodes.size()); + assertEquals(500, nodes.size()); //Start Time before triggering POST/calculate-folder-size API LocalTime expectedTime = LocalTime.now().plusSeconds(5); From 569d9e85d10a955b7fd5b72c74be9867f4bb64ab Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 13 Aug 2024 11:57:05 +0530 Subject: [PATCH 139/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding endpoints to calculate and retrieve folder size --- remote-api/pom.xml | 6 --- .../rest/api/impl/FolderSizeImpl.java | 16 +++++-- .../rest/api/nodes/NodesEntityResource.java | 46 ++++++++++++------- .../framework/core/ResourceInspector.java | 14 ++---- .../interfaces/EntityResourceAction.java | 9 ---- .../interfaces/FolderResourceAction.java | 43 +++++++++++++++++ .../webscripts/ResourceWebScriptGet.java | 11 ++--- .../executer/NodeSizeActionExecuter.java | 10 +++- 8 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/FolderResourceAction.java diff --git a/remote-api/pom.xml b/remote-api/pom.xml index 4d8a321ae50..0ed3dbf0cad 100644 --- a/remote-api/pom.xml +++ b/remote-api/pom.xml @@ -60,12 +60,6 @@ test - - org.projectlombok - lombok - provided - - junit 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 21992439402..1cca5e57071 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 @@ -26,9 +26,9 @@ package org.alfresco.rest.api.impl; import java.io.Serializable; +import java.util.HashMap; 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; @@ -37,15 +37,20 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@AllArgsConstructor public class FolderSizeImpl { private ActionService actionService; private static final Logger LOG = LoggerFactory.getLogger(FolderSizeImpl.class); private static final String IN_PROGRESS = "IN-PROGRESS"; + private static final String STATUS = "status"; private static final String MESSAGE = "Request has been acknowledged"; - public Map executingAsynchronousFolderAction(final NodeRef nodeRef, final int defaultItems, final Map result, final SimpleCache simpleCache) + public FolderSizeImpl(ActionService actionService) + { + this.actionService = actionService; + } + + public Map executingAsynchronousFolderAction(final NodeRef nodeRef, final int defaultItems, final Map result, final SimpleCache simpleCache) { if(simpleCache.get(nodeRef.getId()) == null) { @@ -59,11 +64,14 @@ public Map executingAsynchronousFolderAction(final NodeRef nodeR protected void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache simpleCache) { + Map currentStatus = new HashMap<>(); + currentStatus.put(STATUS,IN_PROGRESS); + Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); folderSizeAction.setTrackStatus(true); folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeActionExecuter.DEFAULT_SIZE, defaultItems); - simpleCache.put(nodeRef.getId(),IN_PROGRESS); + simpleCache.put(nodeRef.getId(),currentStatus); actionService.executeAction(folderSizeAction, nodeRef, false, true); } } \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index caff2c61b77..bb998e09249 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -38,8 +38,16 @@ import org.alfresco.rest.api.DirectAccessUrlHelper; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.impl.FolderSizeImpl; -import org.alfresco.rest.api.model.*; -import org.alfresco.rest.framework.*; +import org.alfresco.rest.api.model.DirectAccessUrlRequest; +import org.alfresco.rest.api.model.LockInfo; +import org.alfresco.rest.api.model.Node; +import org.alfresco.rest.api.model.NodeTarget; +import org.alfresco.rest.api.model.NodePermissions; +import org.alfresco.rest.framework.BinaryProperties; +import org.alfresco.rest.framework.Operation; +import org.alfresco.rest.framework.WebApiDescription; +import org.alfresco.rest.framework.WebApiParam; +import org.alfresco.rest.framework.WebApiParameters; import org.alfresco.rest.framework.core.ResourceParameter; import org.alfresco.rest.framework.core.exceptions.DisabledServiceException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; @@ -47,6 +55,7 @@ import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.FolderResourceAction; import org.alfresco.rest.framework.resource.content.BasicContentInfo; import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.Parameters; @@ -75,7 +84,7 @@ @EntityResource(name="nodes", title = "Nodes") public class NodesEntityResource implements EntityResourceAction.ReadById, EntityResourceAction.Delete, EntityResourceAction.Update, - BinaryResourceAction.Read, BinaryResourceAction.Update, EntityResourceAction.RetrieveFolderSize>, InitializingBean + BinaryResourceAction.Read, BinaryResourceAction.Update, FolderResourceAction.RetrieveFolderSize>, InitializingBean { private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class); @@ -332,10 +341,18 @@ public Map getFolderSize(String nodeId) throws EntityNotFoundExc throw new InvalidNodeTypeException(INVALID_NODEID); } - Object cachedResult = simpleCache.get(nodeId); + Map cachedResult = (Map) simpleCache.get(nodeId); if(cachedResult != null) { - return getResult(cachedResult, result); + if(cachedResult.containsKey("size")) + { + cachedResult.put(STATUS, COMPLETED); + result = cachedResult; + } + else + { + result = cachedResult; + } } else { @@ -353,21 +370,18 @@ public Map getFolderSize(String nodeId) throws EntityNotFoundExc /** * Providing the response from SimpleCache. */ - private Map getResult(Object outputResult, Map result) + private Map getResult(Map cachedResult) { - if (outputResult instanceof Map) - { - Map mapResult = (Map) outputResult; - mapResult.put(STATUS, COMPLETED); - result = mapResult; - } - else if(outputResult instanceof String) + Map result; + + if(cachedResult.containsKey("size")) { - result.put(STATUS, outputResult); + cachedResult.put(STATUS, COMPLETED); + result = cachedResult; } - else if(outputResult instanceof Exception) + else { - result.put(EXCEPTION, ((Exception) outputResult).getMessage()); + result = cachedResult; } return result; } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index e3e7712ac7a..c3e8ac1a2fa 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -57,13 +57,7 @@ import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.UniqueId; -import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; -import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; -import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartResourceAction; -import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartRelationshipResourceAction; -import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; -import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction; -import org.alfresco.rest.framework.resource.actions.interfaces.ResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.*; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.util.Pair; import org.apache.commons.logging.Log; @@ -110,7 +104,7 @@ public class ResourceInspector ALL_ENTITY_RESOURCE_INTERFACES.add(MultiPartResourceAction.Create.class); - ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.RetrieveFolderSize.class); + ALL_ENTITY_RESOURCE_INTERFACES.add(FolderResourceAction.RetrieveFolderSize.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Create.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Read.class); @@ -135,7 +129,7 @@ public class ResourceInspector ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.ReadWithResponse.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.DeleteWithResponse.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.UpdateWithResponse.class); - ALL_PROPERTY_RESOURCE_INTERFACES.add(EntityResourceAction.RetrieveFolderSize.class); + ALL_PROPERTY_RESOURCE_INTERFACES.add(FolderResourceAction.RetrieveFolderSize.class); } /** @@ -223,7 +217,7 @@ public static void inspectAddressedProperties(Api api, Class resource, final findOperation(RelationshipResourceBinaryAction.DeleteWithResponse.class, DELETE, helperForAddressProps); findOperation(RelationshipResourceBinaryAction.UpdateWithResponse.class, PUT, helperForAddressProps); - findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helperForAddressProps); + findOperation(FolderResourceAction.RetrieveFolderSize.class, GET, helperForAddressProps); boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java index ddd28525ec2..029b2b75e37 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/EntityResourceAction.java @@ -161,13 +161,4 @@ public static interface DeleteSetWithResponse extends ResourceAction */ public void deleteSet(Parameters params, WithResponse withResponse); } - interface RetrieveFolderSize extends ResourceAction - { - /** - * get the size of Folder Node. - * - * @param nodeId Entity resource context for this relationship. - */ - E getFolderSize (String nodeId); - } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/FolderResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/FolderResourceAction.java new file mode 100644 index 00000000000..32d77266776 --- /dev/null +++ b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/FolderResourceAction.java @@ -0,0 +1,43 @@ +/* + * #%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.framework.resource.actions.interfaces; + +/** + * Supports folder node property. + */ +public interface FolderResourceAction +{ + + interface RetrieveFolderSize extends ResourceAction + { + /** + * get the size of Folder Node. + * + * @param nodeId Entity resource context for this relationship. + */ + E getFolderSize (String nodeId); + } +} diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 59a70342a00..2ded511f211 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -30,12 +30,9 @@ import org.alfresco.rest.framework.core.ResourceWithMetadata; import org.alfresco.rest.framework.core.exceptions.DeletedResourceException; import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException; -import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; -import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.*; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.Read; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById; -import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; -import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction; import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Params; @@ -281,14 +278,14 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( case PROPERTY: if (StringUtils.isNotBlank(params.getEntityId())) { - if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass()) + if (FolderResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass()) && GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId())) { - if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class)) + if (resource.getMetaData().isDeleted(FolderResourceAction.RetrieveFolderSize.class)) { throw new DeletedResourceException("(GET) "+resource.getMetaData().getUniqueId()); } - EntityResourceAction.RetrieveFolderSize getter = (EntityResourceAction.RetrieveFolderSize) resource.getResource(); + FolderResourceAction.RetrieveFolderSize getter = (FolderResourceAction.RetrieveFolderSize) resource.getResource(); Object result = getter.getFolderSize(params.getEntityId()); return result; } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index ef4a0110cc9..914b64df354 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -62,6 +62,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase * Action constants */ public static final String NAME = "folder-size"; + private static final String EXCEPTION = "Exception"; public static final String DEFAULT_SIZE = "default-size"; private static final String FIELD_FACET = "content.size"; private static final String FACET_QUERY = "content.size:[0 TO "+Integer.MAX_VALUE+"] \"label\": \"large\",\"group\":\"Size\""; @@ -105,7 +106,8 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) catch (NumberFormatException numberFormatException) { LOG.error("Exception occurred while parsing String to INT: {}", numberFormatException.getMessage()); - simpleCache.put(actionedUponNodeRef.getId(),numberFormatException); + response.put(EXCEPTION,numberFormatException.getMessage()); + simpleCache.put(actionedUponNodeRef.getId(),response); throw numberFormatException; } @@ -159,7 +161,8 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) catch (RuntimeException runtimeException) { LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", runtimeException.getMessage()); - simpleCache.put(nodeRef.getId(),runtimeException); + response.put(EXCEPTION,runtimeException.getMessage()); + simpleCache.put(nodeRef.getId(),response); throw runtimeException; } @@ -187,8 +190,11 @@ protected ResultSet facetQuery(NodeRef nodeRef) searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); searchParameters.setQuery(query); + ResultSet resultsWithoutFacet = searchService.query(searchParameters); + searchParameters.addFacetQuery(FACET_QUERY); final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); + ff.setLimitOrNull(resultsWithoutFacet.getNodeRefs().size()); searchParameters.addFieldFacet(ff); return searchService.query(searchParameters); } From a225f66198dffb4bdde368d8c04c344c22df87ad Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 13 Aug 2024 11:58:02 +0530 Subject: [PATCH 140/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding endpoints to calculate and retrieve folder size --- .../rest/api/nodes/NodesEntityResource.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index bb998e09249..d336b275883 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -367,25 +367,6 @@ public Map getFolderSize(String nodeId) throws EntityNotFoundExc } } - /** - * Providing the response from SimpleCache. - */ - private Map getResult(Map cachedResult) - { - Map result; - - if(cachedResult.containsKey("size")) - { - cachedResult.put(STATUS, COMPLETED); - result = cachedResult; - } - else - { - result = cachedResult; - } - return result; - } - /** * Validating node permission [i.e. READ permission should be there ] */ From 0721099517d4ef223442220560db0207e4110df3 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 13 Aug 2024 12:37:07 +0530 Subject: [PATCH 141/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding endpoints to calculate and retrieve folder size --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 1 - .../alfresco/repo/action/executer/NodeSizeActionExecuter.java | 2 -- 2 files changed, 3 deletions(-) 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 0c91b1a4180..a46b6313cfc 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 @@ -178,7 +178,6 @@ public void testPerformanceTesting() throws Exception // Prepare parameters. Map params = new HashMap<>(); params.put("nodeId", folderId); - params.put("maxItems", "100"); // Perform POST request HttpResponse postResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 202); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index 914b64df354..f86036e38ab 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -190,11 +190,9 @@ protected ResultSet facetQuery(NodeRef nodeRef) searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); searchParameters.setQuery(query); - ResultSet resultsWithoutFacet = searchService.query(searchParameters); searchParameters.addFacetQuery(FACET_QUERY); final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); - ff.setLimitOrNull(resultsWithoutFacet.getNodeRefs().size()); searchParameters.addFieldFacet(ff); return searchService.query(searchParameters); } From f3f099df6da941ee733d50caef16158c8df75407 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 13 Aug 2024 12:48:05 +0530 Subject: [PATCH 142/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding endpoints to calculate and retrieve folder size --- .../alfresco/rest/framework/core/ResourceInspector.java | 9 ++++++++- .../rest/framework/webscripts/ResourceWebScriptGet.java | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index c3e8ac1a2fa..89ed9b13c27 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -57,7 +57,14 @@ import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.UniqueId; -import org.alfresco.rest.framework.resource.actions.interfaces.*; +import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartRelationshipResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction; +import org.alfresco.rest.framework.resource.actions.interfaces.ResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.FolderResourceAction; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.util.Pair; import org.apache.commons.logging.Log; diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 2ded511f211..fd8591317dd 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -30,9 +30,13 @@ import org.alfresco.rest.framework.core.ResourceWithMetadata; import org.alfresco.rest.framework.core.exceptions.DeletedResourceException; import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException; -import org.alfresco.rest.framework.resource.actions.interfaces.*; +import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.Read; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById; +import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; +import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction; +import org.alfresco.rest.framework.resource.actions.interfaces.FolderResourceAction; import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Params; From ed3c189b10745fcc809141aa9fb18bc72354659d Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 13 Aug 2024 13:14:34 +0530 Subject: [PATCH 143/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding endpoints to calculate and retrieve folder size --- .../alfresco/repo/action/executer/NodeSizeActionExecuter.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java index f86036e38ab..3f073190863 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java @@ -190,10 +190,13 @@ protected ResultSet facetQuery(NodeRef nodeRef) searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); searchParameters.setQuery(query); + ResultSet resultsWithoutFacet = searchService.query(searchParameters); searchParameters.addFacetQuery(FACET_QUERY); final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); + ff.setLimitOrNull(resultsWithoutFacet.getNodeRefs().size()); searchParameters.addFieldFacet(ff); + resultsWithoutFacet.close(); return searchService.query(searchParameters); } From b43107731fbcc14094284d3f8a25aa3670e1ea3d Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Tue, 13 Aug 2024 14:06:29 +0530 Subject: [PATCH 144/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Adding endpoints to calculate and retrieve folder size --- .../java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a46b6313cfc..ebee78cd346 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 @@ -197,7 +197,7 @@ public void testPerformanceTesting() throws Exception String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); assertNotNull("JSON response should not be null", getJsonResponse); - assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size")); + assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status")); //current Time after executing GET/size API LocalTime actualTime = LocalTime.now(); From a9878d9514802d427185bf9fef2662e130557331 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 12:44:19 +0530 Subject: [PATCH 145/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/rest/api/SizeDetails.java | 33 ++++ .../rest/api/impl/FolderSizeImpl.java | 77 -------- .../rest/api/impl/SizeDetailsImpl.java | 180 ++++++++++++++++++ .../rest/api/model/NodeSizeDetails.java | 113 +++++++++++ .../rest/api/nodes/NodesEntityResource.java | 149 ++------------- .../framework/core/ResourceInspector.java | 6 - .../webscripts/ResourceWebScriptGet.java | 30 +-- .../alfresco/public-rest-context.xml | 29 ++- .../org/alfresco/AppContext02TestSuite.java | 3 +- .../org/alfresco/AppContext04TestSuite.java | 5 +- .../rest/api/impl/SizeDetailsImplTest.java | 120 ++++++++++++ .../rest/api/tests/AbstractBaseApiTest.java | 2 +- ...eApiTest.java => NodeSizeDetailsTest.java} | 27 ++- ...ava => NodeSizeDetailsActionExecutor.java} | 15 +- .../alfresco/action-services-context.xml | 2 +- .../org/alfresco/AppContext01TestSuite.java | 3 +- ...=> NodeSizeDetailsActionExecutorTest.java} | 16 +- 17 files changed, 533 insertions(+), 277 deletions(-) create mode 100644 remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java delete mode 100644 remote-api/src/main/java/org/alfresco/rest/api/impl/FolderSizeImpl.java create mode 100644 remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java create mode 100644 remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java create mode 100644 remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java rename remote-api/src/test/java/org/alfresco/rest/api/tests/{NodeFolderSizeApiTest.java => NodeSizeDetailsTest.java} (90%) rename repository/src/main/java/org/alfresco/repo/action/executer/{NodeSizeActionExecuter.java => NodeSizeDetailsActionExecutor.java} (94%) rename repository/src/test/java/org/alfresco/repo/action/executer/{NodeSizeActionExecuterTest.java => NodeSizeDetailsActionExecutorTest.java} (87%) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java new file mode 100644 index 00000000000..69434dc2014 --- /dev/null +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java @@ -0,0 +1,33 @@ +/* + * #%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; + +import org.alfresco.rest.api.model.NodeSizeDetails; + +public interface SizeDetails +{ + NodeSizeDetails calculateNodeSize(String nodeId); +} 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 deleted file mode 100644 index 1cca5e57071..00000000000 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/FolderSizeImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * #%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.HashMap; -import java.util.Map; - -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.repository.NodeRef; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FolderSizeImpl { - - private ActionService actionService; - private static final Logger LOG = LoggerFactory.getLogger(FolderSizeImpl.class); - private static final String IN_PROGRESS = "IN-PROGRESS"; - private static final String STATUS = "status"; - private static final String MESSAGE = "Request has been acknowledged"; - - public FolderSizeImpl(ActionService actionService) - { - this.actionService = actionService; - } - - public Map executingAsynchronousFolderAction(final NodeRef nodeRef, final int defaultItems, final Map result, final SimpleCache simpleCache) - { - if(simpleCache.get(nodeRef.getId()) == null) - { - executeAction(nodeRef, defaultItems, simpleCache); - } - LOG.debug("Executing NodeSizeActionExecuter from executingAsynchronousFolderAction method"); - - result.putIfAbsent("message",MESSAGE); - return result; - } - - protected void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache simpleCache) - { - Map currentStatus = new HashMap<>(); - currentStatus.put(STATUS,IN_PROGRESS); - - Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); - folderSizeAction.setTrackStatus(true); - folderSizeAction.setExecuteAsynchronously(true); - folderSizeAction.setParameterValue(NodeSizeActionExecuter.DEFAULT_SIZE, defaultItems); - simpleCache.put(nodeRef.getId(),currentStatus); - actionService.executeAction(folderSizeAction, nodeRef, false, true); - } -} \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java new file mode 100644 index 00000000000..3ac69ecbd27 --- /dev/null +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -0,0 +1,180 @@ +/* + * #%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 org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.security.permissions.AccessDeniedException; +import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.SizeDetails; +import org.alfresco.rest.api.model.Node; +import org.alfresco.rest.api.model.NodePermissions; +import org.alfresco.rest.api.model.NodeSizeDetails; +import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.namespace.QName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.alfresco.service.cmr.repository.NodeRef; +import java.io.Serializable; +import java.util.Map; +import java.util.HashMap; + +import org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutor; + +public class SizeDetailsImpl implements SizeDetails +{ + private static final Logger LOG = LoggerFactory.getLogger(SizeDetailsImpl.class); + private static final String IN_PROGRESS = "IN-PROGRESS"; + private static final String STATUS = "status"; + private static final String COMPLETED = "COMPLETED"; + private static final String NOT_INITIATED = "NOT-INITIATED"; + private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; + private static final String FOLDER = "folder"; + private Nodes nodes; + private NodeService nodeService; + private PermissionService permissionService; + private ActionService actionService; + private SimpleCache simpleCache; + private int defaultItems; + + public void setNodes(Nodes nodes) + { + this.nodes = nodes; + } + + public void setPermissionService(PermissionService permissionService) + { + this.permissionService = permissionService; + } + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + public void setActionService(ActionService actionService) + { + this.actionService = actionService; + } + + public void setSimpleCache(SimpleCache simpleCache) + { + this.simpleCache = simpleCache; + } + + public void setDefaultItems(int defaultItems) + { + this.defaultItems = defaultItems; + } + + /** + * calculateNodeSize : providing HTTP STATUS 202 which signifies REQUEST ACCEPTED. + * HTTP STATUS 200 will provide the size details response from cache. + */ + public NodeSizeDetails calculateNodeSize(final String nodeId) + { + NodeRef nodeRef = nodes.validateNode(nodeId); + QName qName = nodeService.getType(nodeRef); + validatePermissions(nodeRef, nodeId); + + if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) + { + throw new InvalidNodeTypeException(INVALID_NODEID); + } + + if(simpleCache.get(nodeRef.getId()) == null) + { + executeAction(nodeRef, defaultItems, simpleCache); + return null; + } + + LOG.debug("Executing NodeSizeActionExecuter from calculateNodeSize method"); + return executorResultToSizeDetails((Map)simpleCache.get(nodeRef.getId())); + } + + /** + * Executing Action Asynchronously. + */ + private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache simpleCache) + { + Map currentStatus = new HashMap<>(); + currentStatus.put(STATUS,IN_PROGRESS); + + Action folderSizeAction = actionService.createAction(NodeSizeDetailsActionExecutor.NAME); + folderSizeAction.setTrackStatus(true); + folderSizeAction.setExecuteAsynchronously(true); + folderSizeAction.setParameterValue(NodeSizeDetailsActionExecutor.DEFAULT_SIZE, defaultItems); + simpleCache.put(nodeRef.getId(),currentStatus); + actionService.executeAction(folderSizeAction, nodeRef, false, true); + } + + /** + * Converting action executor response to their respective model class. + */ + private NodeSizeDetails executorResultToSizeDetails(final Map result) + { + if (result == null) + { + return new NodeSizeDetails(NOT_INITIATED); + } + else if(result.containsKey(NodeSizeDetailsActionExecutor.EXCEPTION)) + { + return new NodeSizeDetails((String) result.get(NodeSizeDetailsActionExecutor.EXCEPTION)); + } + + // Check for the presence of "size" key. + boolean hasSizeKey = result.containsKey("size"); + + if (hasSizeKey) + { + return new NodeSizeDetails((String) result.get("nodeId"), (Long) result.get("size"), (String) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), COMPLETED); + } + else + { + return new NodeSizeDetails(IN_PROGRESS); + } + } + + /** + * Validating node permission [i.e. READ permission should be there ] + */ + private void validatePermissions(NodeRef nodeRef, String nodeId) + { + Node nodeInfo = nodes.getNode(nodeId); + NodePermissions nodePerms = nodeInfo.getPermissions(); + + // Validate permissions. + if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) + { + throw new AccessDeniedException("permissions.err_access_denied"); + } + } + +} \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java new file mode 100644 index 00000000000..5fdf4c21537 --- /dev/null +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java @@ -0,0 +1,113 @@ +/* + * #%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.model; + +public class NodeSizeDetails +{ + private String nodeId; + private long size; + private String calculatedAt; + private int numberOfFiles; + private String status; + public NodeSizeDetails() + { + super(); + } + + public NodeSizeDetails(String status) + { + this.status = status; + } + public NodeSizeDetails(String nodeId, long size, String calculatedAt, int numberOfFiles, String status) + { + this.nodeId = nodeId; + this.size = size; + this.calculatedAt = calculatedAt; + this.numberOfFiles = numberOfFiles; + this.status = status; + } + + public String getNodeId() + { + return nodeId; + } + + public void setNodeId(String nodeId) + { + this.nodeId = nodeId; + } + + public long getSize() + { + return size; + } + + public void setSize(long size) + { + this.size = size; + } + + public String getCalculatedAt() + { + return calculatedAt; + } + + public void setCalculatedAt(String calculatedAt) + { + this.calculatedAt = calculatedAt; + } + + public int getNumberOfFiles() + { + return numberOfFiles; + } + + public void setNumberOfFiles(int numberOfFiles) + { + this.numberOfFiles = numberOfFiles; + } + + public String getStatus() + { + return status; + } + + public void setStatus(String status) + { + this.status = status; + } + + @Override + public String toString() { + return "NodeSizeDetails{" + + "nodeId='" + nodeId + '\'' + + ", size='" + size + '\'' + + ", calculatedAt='" + calculatedAt + '\'' + + ", numberOfFiles=" + numberOfFiles + + ", status='" + status + '\'' + + '}'; + } +} diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index d336b275883..a52fd8206a8 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2023 Alfresco Software Limited + * 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 @@ -27,46 +27,34 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.InputStream; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.content.directurl.DirectAccessUrlDisabledException; -import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.rest.api.DirectAccessUrlHelper; import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.impl.FolderSizeImpl; import org.alfresco.rest.api.model.DirectAccessUrlRequest; import org.alfresco.rest.api.model.LockInfo; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.NodeTarget; -import org.alfresco.rest.api.model.NodePermissions; +import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.framework.BinaryProperties; import org.alfresco.rest.framework.Operation; import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.WebApiParameters; +import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.framework.core.ResourceParameter; import org.alfresco.rest.framework.core.exceptions.DisabledServiceException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; -import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; -import org.alfresco.rest.framework.resource.actions.interfaces.FolderResourceAction; import org.alfresco.rest.framework.resource.content.BasicContentInfo; import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rest.framework.webscripts.WithResponse; -import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.DirectAccessUrl; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.namespace.QName; import org.alfresco.util.ParameterCheck; import org.slf4j.Logger; @@ -84,25 +72,13 @@ @EntityResource(name="nodes", title = "Nodes") public class NodesEntityResource implements EntityResourceAction.ReadById, EntityResourceAction.Delete, EntityResourceAction.Update, - BinaryResourceAction.Read, BinaryResourceAction.Update, FolderResourceAction.RetrieveFolderSize>, InitializingBean + BinaryResourceAction.Read, BinaryResourceAction.Update, InitializingBean { - private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class); - - private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; - private static final String NOT_INITIATED = "NOT-INITIATED"; - private static final String STATUS = "status"; - private static final String COMPLETED = "COMPLETED"; - private static final String FOLDER = "folder"; - private static final String EXCEPTION = "Exception"; private Nodes nodes; private DirectAccessUrlHelper directAccessUrlHelper; - private PermissionService permissionService; - private NodeService nodeService; - private ActionService actionService; - private SimpleCache simpleCache; - private int defaultItems; + private SizeDetails sizeDetails; public void setNodes(Nodes nodes) { @@ -114,31 +90,6 @@ public void setDirectAccessUrlHelper(DirectAccessUrlHelper directAccessUrlHelper this.directAccessUrlHelper = directAccessUrlHelper; } - public void setPermissionService(PermissionService permissionService) - { - this.permissionService = permissionService; - } - - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - - public void setActionService(ActionService actionService) - { - this.actionService = actionService; - } - - public void setSimpleCache(SimpleCache simpleCache) - { - this.simpleCache = simpleCache; - } - - public void setDefaultItems(int defaultItems) - { - this.defaultItems = defaultItems; - } - @Override public void afterPropertiesSet() { @@ -286,100 +237,38 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq } /** - * Folder Size - returns size of a folder. + * Folder Size - returns size details of a folder. * * @param nodeId String id of folder - will also accept well-known alias, eg. -root- or -my- or -shared- * Please refer to OpenAPI spec for more details ! * Returns the response message i.e. Request has been acknowledged with 202 - * GET/size endpoint to check if the action's status has been completed, comprising the size of the node in bytes. + * Also, size-details endpoint to check if the action's status has been completed, comprising the size of the node in bytes. *

* If nodeId does not represent a folder, InvalidNodeTypeException (status 422). */ - @Operation("calculate-folder-size") - @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder", successStatus = Status.STATUS_ACCEPTED) - @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) - public Map calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) - { - NodeRef nodeRef = nodes.validateNode(nodeId); - QName qName = nodeService.getType(nodeRef); - Map result = new HashMap<>(); - validatePermissions(nodeRef, nodeId); - - if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) - { - throw new InvalidNodeTypeException(INVALID_NODEID); - } - - try - { - FolderSizeImpl folderSizeImpl = new FolderSizeImpl(actionService); - return folderSizeImpl.executingAsynchronousFolderAction(nodeRef, defaultItems, result, simpleCache); - } - catch (Exception alfrescoRuntimeError) - { - LOG.error("Exception occurred in NodesEntityResource:calculateFolderSize {}", alfrescoRuntimeError.getMessage()); - throw new AlfrescoRuntimeException("Exception occurred in NodesEntityResource:calculateFolderSize",alfrescoRuntimeError); - } - } - - @Override - @WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") + @Operation("request-size-details") + @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder",successStatus = Status.STATUS_ACCEPTED) @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) - @BinaryProperties({"size"}) - public Map getFolderSize(String nodeId) throws EntityNotFoundException + public NodeSizeDetails calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) { - Map result = new HashMap<>(); try { - LOG.debug("Retrieving OUTPUT from NodeSizeActionExecutor - NodesEntityResource:getFolderSize"); - NodeRef nodeRef = nodes.validateNode(nodeId); - validatePermissions(nodeRef, nodeId); - QName qName = nodeService.getType(nodeRef); - - if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) + NodeSizeDetails nodeSizeDetails = sizeDetails.calculateNodeSize(nodeId); + if(nodeSizeDetails == null) { - throw new InvalidNodeTypeException(INVALID_NODEID); - } - - Map cachedResult = (Map) simpleCache.get(nodeId); - if(cachedResult != null) - { - if(cachedResult.containsKey("size")) - { - cachedResult.put(STATUS, COMPLETED); - result = cachedResult; - } - else - { - result = cachedResult; - } + withResponse.setStatus(Status.STATUS_ACCEPTED); } else { - result.put(STATUS,NOT_INITIATED); + withResponse.setStatus(Status.STATUS_OK); } - return result; - } - catch (Exception ex) - { - LOG.error("Exception occurred in NodesEntityResource:getFolderSize {}", ex.getMessage()); - throw ex; // Rethrow with original stack trace + return nodeSizeDetails; } - } - - /** - * Validating node permission [i.e. READ permission should be there ] - */ - private void validatePermissions(NodeRef nodeRef, String nodeId) - { - Node nodeInfo = nodes.getNode(nodeId); - NodePermissions nodePerms = nodeInfo.getPermissions(); - - // Validate permissions. - if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) + catch (Exception alfrescoRuntimeError) { - throw new AccessDeniedException("permissions.err_access_denied"); + LOG.error("Exception occurred in NodesEntityResource:calculateFolderSize {}", alfrescoRuntimeError.getMessage()); + throw new AlfrescoRuntimeException("Exception occurred in NodesEntityResource:calculateFolderSize",alfrescoRuntimeError); } } -} +} \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java index 89ed9b13c27..146450667e9 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -64,7 +64,6 @@ import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction; import org.alfresco.rest.framework.resource.actions.interfaces.ResourceAction; -import org.alfresco.rest.framework.resource.actions.interfaces.FolderResourceAction; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.util.Pair; import org.apache.commons.logging.Log; @@ -111,8 +110,6 @@ public class ResourceInspector ALL_ENTITY_RESOURCE_INTERFACES.add(MultiPartResourceAction.Create.class); - ALL_ENTITY_RESOURCE_INTERFACES.add(FolderResourceAction.RetrieveFolderSize.class); - ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Create.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Read.class); ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadById.class); @@ -136,7 +133,6 @@ public class ResourceInspector ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.ReadWithResponse.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.DeleteWithResponse.class); ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.UpdateWithResponse.class); - ALL_PROPERTY_RESOURCE_INTERFACES.add(FolderResourceAction.RetrieveFolderSize.class); } /** @@ -224,8 +220,6 @@ public static void inspectAddressedProperties(Api api, Class resource, final findOperation(RelationshipResourceBinaryAction.DeleteWithResponse.class, DELETE, helperForAddressProps); findOperation(RelationshipResourceBinaryAction.UpdateWithResponse.class, PUT, helperForAddressProps); - findOperation(FolderResourceAction.RetrieveFolderSize.class, GET, helperForAddressProps); - boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) { diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index fd8591317dd..87ee84c074f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -36,7 +36,6 @@ import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction; -import org.alfresco.rest.framework.resource.actions.interfaces.FolderResourceAction; import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Params; @@ -58,8 +57,6 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements ParamsExtractor, RecognizedParamsExtractor { private static Log logger = LogFactory.getLog(ResourceWebScriptGet.class); - - private static final String GET_FOLDERSIZE = "/nodes/{id}/size"; public ResourceWebScriptGet() { @@ -228,7 +225,7 @@ else if (EntityResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resour } } case RELATIONSHIP: - if (StringUtils.isBlank(params.getRelationshipId()) || params.isCollectionResource()) + if (StringUtils.isBlank(params.getRelationshipId()) || (params.isCollectionResource())) { // Get the collection if (RelationshipResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) @@ -282,18 +279,7 @@ else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom( case PROPERTY: if (StringUtils.isNotBlank(params.getEntityId())) { - if (FolderResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass()) - && GET_FOLDERSIZE.equals(resource.getMetaData().getUniqueId())) - { - if (resource.getMetaData().isDeleted(FolderResourceAction.RetrieveFolderSize.class)) - { - throw new DeletedResourceException("(GET) "+resource.getMetaData().getUniqueId()); - } - FolderResourceAction.RetrieveFolderSize getter = (FolderResourceAction.RetrieveFolderSize) resource.getResource(); - Object result = getter.getFolderSize(params.getEntityId()); - return result; - } - else if (BinaryResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) + if (BinaryResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(BinaryResourceAction.Read.class)) { @@ -303,7 +289,7 @@ else if (BinaryResourceAction.Read.class.isAssignableFrom(resource.getResource() BinaryResource prop = getter.readProperty(params.getEntityId(), params); return prop; } - else if (BinaryResourceAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass())) + if (BinaryResourceAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(BinaryResourceAction.ReadWithResponse.class)) { @@ -313,7 +299,7 @@ else if (BinaryResourceAction.ReadWithResponse.class.isAssignableFrom(resource.g BinaryResource prop = getter.readProperty(params.getEntityId(), params, withResponse); return prop; } - else if (RelationshipResourceBinaryAction.Read.class.isAssignableFrom(resource.getResource().getClass())) + if (RelationshipResourceBinaryAction.Read.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.Read.class)) { @@ -323,7 +309,7 @@ else if (RelationshipResourceBinaryAction.Read.class.isAssignableFrom(resource.g BinaryResource prop = getter.readProperty(params.getEntityId(), params.getRelationshipId(), params); return prop; } - else if (RelationshipResourceBinaryAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass())) + if (RelationshipResourceBinaryAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass())) { if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.ReadWithResponse.class)) { @@ -333,10 +319,6 @@ else if (RelationshipResourceBinaryAction.ReadWithResponse.class.isAssignableFro BinaryResource prop = getter.readProperty(params.getEntityId(), params.getRelationshipId(), params, withResponse); return prop; } - else - { - throw new UnsupportedResourceOperationException(); - } } else { @@ -345,7 +327,7 @@ else if (RelationshipResourceBinaryAction.ReadWithResponse.class.isAssignableFro default: throw new UnsupportedResourceOperationException("GET not supported for Actions"); } - } + } diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 223b8f94003..8e8a321c078 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -996,6 +996,29 @@ + + + + + + + + + + + + org.alfresco.rest.api.SizeDetails + + + + + + + + + + + @@ -1148,11 +1171,7 @@ - - - - - + diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index ed6748a6863..5069c6065b2 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -25,6 +25,7 @@ */ package org.alfresco; +import org.alfresco.rest.api.tests.NodeSizeDetailsTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; @@ -76,7 +77,7 @@ org.alfresco.rest.api.tests.BufferedResponseTest.class, org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, - org.alfresco.rest.api.tests.NodeFolderSizeApiTest.class + NodeSizeDetailsTest.class }) public class AppContext02TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index 8f41edd452c..adcd9aee52a 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2021 Alfresco Software Limited + * 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 @@ -77,7 +77,8 @@ org.alfresco.repo.web.scripts.node.NodeWebScripTest.class, org.alfresco.rest.api.impl.CommentsImplUnitTest.class, org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, - org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class + org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, + org.alfresco.rest.api.impl.SizeDetailsImplTest.class }) public class AppContext04TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java new file mode 100644 index 00000000000..b0044953869 --- /dev/null +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -0,0 +1,120 @@ +/* + * #%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 org.alfresco.repo.cache.SimpleCache; +import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.model.NodeSizeDetails; +import org.alfresco.rest.api.tests.AbstractBaseApiTest; +import org.alfresco.rest.api.tests.client.data.ContentInfo; +import org.alfresco.rest.api.tests.client.data.Document; +import org.alfresco.rest.api.tests.client.data.UserInfo; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.security.PermissionService; +import org.junit.Before; +import org.junit.Test; + +import java.io.Serializable; + +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Unit tests for {@link SizeDetailsImpl} class. + * + */ +public class SizeDetailsImplTest extends AbstractBaseApiTest +{ + private SizeDetailsImpl sizeDetailsImpl; + private Nodes nodes; + private NodeService nodeService; + private PermissionService permissionService; + private ActionService actionService; + private SimpleCache simpleCache; + private final int defaultItems = 1000; + + @Before + public void setUp() + { + sizeDetailsImpl = new SizeDetailsImpl(); + nodes = mock(Nodes.class); + nodeService = mock(NodeService.class); + permissionService = mock(PermissionService.class); + actionService = mock(ActionService.class); + simpleCache = mock(SimpleCache.class); + + sizeDetailsImpl.setNodes(nodes); + sizeDetailsImpl.setNodeService(nodeService); + sizeDetailsImpl.setPermissionService(permissionService); + sizeDetailsImpl.setActionService(actionService); + sizeDetailsImpl.setSimpleCache(simpleCache); + sizeDetailsImpl.setDefaultItems(defaultItems); + } + + @Test + public void calculateNodeSize() throws Exception + { + setRequestContext(user1); + UserInfo userInfo = new UserInfo(user1); + + String fileName = "content.txt"; + String folder0Name = "f0-testParentFolder-"+RUNID; + String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); + NodeRef nodeRef = new NodeRef("protocol", "identifier", parentFolder); + + Document d1 = new Document(); + d1.setIsFolder(false); + d1.setParentId(parentFolder); + d1.setName(fileName); + d1.setNodeType(TYPE_CM_CONTENT); + d1.setContent(createContentInfo()); + d1.setCreatedByUser(userInfo); + d1.setModifiedByUser(userInfo); + + when(nodes.validateNode(parentFolder)).thenReturn(nodeRef); + NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(parentFolder); + assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",nodeSizeDetails); + } + + // Method to create content info + private ContentInfo createContentInfo() + { + ContentInfo ciExpected = new ContentInfo(); + ciExpected.setMimeType("text/plain"); + ciExpected.setMimeTypeName("Plain Text"); + ciExpected.setSizeInBytes(44500L); + ciExpected.setEncoding("ISO-8859-1"); + return ciExpected; + } + + @Override + public String getScope() { + return "public"; + } +} diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index 2f753cff670..66c0988397c 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -105,7 +105,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi private static final String URL_CHILDREN = "children"; private static final String URL_CONTENT = "content"; - private static final String URL_CALCULATEFOLDERSIZE = "calculate-folder-size"; + private static final String URL_CALCULATEFOLDERSIZE = "request-size-details"; protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; 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/NodeSizeDetailsTest.java similarity index 90% rename from remote-api/src/test/java/org/alfresco/rest/api/tests/NodeFolderSizeApiTest.java rename to remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index ebee78cd346..09e8fae0602 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/NodeSizeDetailsTest.java @@ -27,7 +27,6 @@ import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; -import org.alfresco.rest.api.nodes.NodesEntityResource; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; import org.alfresco.rest.api.tests.client.data.ContentInfo; @@ -53,16 +52,18 @@ import java.util.UUID; import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** - * V1 REST API tests for Folder size + * V1 REST API tests for calculating and retrieving Folder size. */ @FixMethodOrder (MethodSorters.NAME_ASCENDING) @RunWith (JUnit4.class) -public class NodeFolderSizeApiTest extends AbstractBaseApiTest +public class NodeSizeDetailsTest extends AbstractBaseApiTest { - private static final Logger LOG = LoggerFactory.getLogger(NodeFolderSizeApiTest.class); + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsTest.class); private Site userOneN1Site; private String folderId; @@ -88,7 +89,7 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType) } catch (Exception e) { - LOG.error("Exception occured in NodeFolderSizeApiTest:addToDocumentLibrary {}", e.getMessage()); + LOG.error("Exception occured in NodeSizeDetailsTest:addToDocumentLibrary {}", e.getMessage()); } return null; } @@ -109,10 +110,8 @@ public void setup() throws Exception } /** - * Test case for POST/calculate-folder-size, which calculates Folder Size. - * Test case for GET/size, which receive Folder Size. - * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//calculate-folder-size} - * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size} + * Test case for POST/request-size-details, which calculates and retrieve size of a folder. + * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//request-size-details} */ @Test public void testPostAndGetFolderSize() throws Exception @@ -120,7 +119,7 @@ public void testPostAndGetFolderSize() throws Exception // Prepare parameters Map params = new HashMap<>(); params.put("nodeId", folderId); - params.put("maxItems", "100"); + params.put("maxItems", "1000"); // Perform POST request HttpResponse postResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); @@ -135,7 +134,7 @@ public void testPostAndGetFolderSize() throws Exception Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); - HttpResponse getResponse = getSingle(NodesEntityResource.class, folderId + "/size", null, 200); + HttpResponse getResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); assertNotNull("JSON response should not be null", getJsonResponse); @@ -192,7 +191,7 @@ public void testPerformanceTesting() throws Exception Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); assertNotNull("Parsed document should not be null", document); - HttpResponse getResponse = getSingle(NodesEntityResource.class, parentFolder + "/size", null, 200); + HttpResponse getResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 200); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); assertNotNull("JSON response should not be null", getJsonResponse); @@ -243,4 +242,4 @@ public String getScope() { return "public"; } -} +} \ No newline at end of file diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java similarity index 94% rename from repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java rename to repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java index 3f073190863..3cc2ce1ad79 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeActionExecuter.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java @@ -49,20 +49,20 @@ import java.util.concurrent.atomic.AtomicLong; /** - * NodeSizeActionExecuter + * NodeSizeDetailsActionExecutor * Executing Alfresco FTS Query to find size of Folder Node */ -public class NodeSizeActionExecuter extends ActionExecuterAbstractBase +public class NodeSizeDetailsActionExecutor extends ActionExecuterAbstractBase { - private static final Logger LOG = LoggerFactory.getLogger(NodeSizeActionExecuter.class); + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsActionExecutor.class); /** * Action constants */ public static final String NAME = "folder-size"; - private static final String EXCEPTION = "Exception"; + public static final String EXCEPTION = "Exception"; public static final String DEFAULT_SIZE = "default-size"; private static final String FIELD_FACET = "content.size"; private static final String FACET_QUERY = "content.size:[0 TO "+Integer.MAX_VALUE+"] \"label\": \"large\",\"group\":\"Size\""; @@ -160,13 +160,13 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) } catch (RuntimeException runtimeException) { - LOG.error("Exception occurred in NodeSizeActionExecutor:results {}", runtimeException.getMessage()); + LOG.error("Exception occurred in NodeSizeDetailsActionExecutor:results {}", runtimeException.getMessage()); response.put(EXCEPTION,runtimeException.getMessage()); simpleCache.put(nodeRef.getId(),response); throw runtimeException; } - LOG.debug(" Calculating size of Folder Node - NodeSizeActionExecutor:executeImpl "); + LOG.debug(" Calculating size of Folder Node - NodeSizeDetailsActionExecutor:executeImpl "); final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); String formattedTimestamp = eventTimestamp.format(formatter); @@ -174,6 +174,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) response.put("size", totalSizeFromFacet); response.put("calculatedAt", formattedTimestamp); response.put("numberOfFiles", results != null ? results.getNodeRefs().size() : 0); + if(isCalculationCompleted) { simpleCache.put(nodeRef.getId(),response); @@ -208,4 +209,4 @@ protected void addParameterDefinitions(List paramList) { // Intentionally empty. } -} +} \ No newline at end of file diff --git a/repository/src/main/resources/alfresco/action-services-context.xml b/repository/src/main/resources/alfresco/action-services-context.xml index 8219092e444..21435fdfc54 100644 --- a/repository/src/main/resources/alfresco/action-services-context.xml +++ b/repository/src/main/resources/alfresco/action-services-context.xml @@ -789,7 +789,7 @@ - + diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index c7f78a960c4..53da9d4cf25 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -25,6 +25,7 @@ */ package org.alfresco; +import org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; @@ -78,7 +79,7 @@ org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, - org.alfresco.repo.action.executer.NodeSizeActionExecuterTest.class + NodeSizeDetailsActionExecutorTest.class }) public class AppContext01TestSuite { diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java similarity index 87% rename from repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java rename to repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java index 4c2ce3335d6..f9168af16a3 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeActionExecuterTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java @@ -43,7 +43,7 @@ import org.springframework.transaction.annotation.Transactional; @Transactional -public class NodeSizeActionExecuterTest extends BaseSpringTest +public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest { /** * The test node reference @@ -53,7 +53,7 @@ public class NodeSizeActionExecuterTest extends BaseSpringTest /** * The folder Size executer */ - private NodeSizeActionExecuter executer; + private NodeSizeDetailsActionExecutor executer; /** * Id used to identify the test action created @@ -82,7 +82,7 @@ public void before() throws Exception // Create the store and get the root node testStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" - + System.currentTimeMillis()); + + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(testStoreRef); // Create the node used for tests @@ -93,7 +93,7 @@ public void before() throws Exception ContentModel.TYPE_CONTENT).getChildRef(); // Get the executer instance. - this.executer = (NodeSizeActionExecuter)this.applicationContext.getBean(NodeSizeActionExecuter.NAME); + this.executer = (NodeSizeDetailsActionExecutor)this.applicationContext.getBean(NodeSizeDetailsActionExecutor.NAME); simpleCache = (SimpleCache) this.applicationContext.getBean("folderSizeSharedCache"); } @@ -104,12 +104,12 @@ public void before() throws Exception @Test public void testExecution() { - int maxItems = 100; - ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null); - action.setParameterValue(NodeSizeActionExecuter.DEFAULT_SIZE, maxItems); + int maxItems = 1000; + ActionImpl action = new ActionImpl(null, ID, NodeSizeDetailsActionExecutor.NAME, null); + action.setParameterValue(NodeSizeDetailsActionExecutor.DEFAULT_SIZE, maxItems); this.executer.executeImpl(action, this.nodeRef); Object resultAction = simpleCache.get(this.nodeRef.getId()); Map mapResult = (Map)resultAction; assertTrue(mapResult != null); } -} +} \ No newline at end of file From 5279b9925ee8a5b7e521c62b7d3eb4bdeda7ea6b Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 12:52:19 +0530 Subject: [PATCH 146/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../interfaces/FolderResourceAction.java | 43 ------------------- .../org/alfresco/AppContext02TestSuite.java | 4 +- .../org/alfresco/AppContext01TestSuite.java | 4 +- 3 files changed, 4 insertions(+), 47 deletions(-) delete mode 100644 remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/FolderResourceAction.java diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/FolderResourceAction.java b/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/FolderResourceAction.java deleted file mode 100644 index 32d77266776..00000000000 --- a/remote-api/src/main/java/org/alfresco/rest/framework/resource/actions/interfaces/FolderResourceAction.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * #%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.framework.resource.actions.interfaces; - -/** - * Supports folder node property. - */ -public interface FolderResourceAction -{ - - interface RetrieveFolderSize extends ResourceAction - { - /** - * get the size of Folder Node. - * - * @param nodeId Entity resource context for this relationship. - */ - E getFolderSize (String nodeId); - } -} diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 5069c6065b2..2b097a6e05f 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2021 Alfresco Software Limited + * 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 @@ -77,7 +77,7 @@ org.alfresco.rest.api.tests.BufferedResponseTest.class, org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, - NodeSizeDetailsTest.class + org.alfresco.rest.api.tests.NodeSizeDetailsTest.class }) public class AppContext02TestSuite { diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index 53da9d4cf25..e210648ca48 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2022 Alfresco Software Limited + * 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 @@ -79,7 +79,7 @@ org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, - NodeSizeDetailsActionExecutorTest.class + org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest.class }) public class AppContext01TestSuite { From dca8b792a1cf5886809be4a4795b3c38fbf7bf06 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 13:20:18 +0530 Subject: [PATCH 147/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../alfresco/rest/api/impl/SizeDetailsImpl.java | 1 + .../rest/api/impl/SizeDetailsImplTest.java | 14 +++++--------- .../rest/api/tests/NodeSizeDetailsTest.java | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 3ac69ecbd27..64c28b208b4 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -98,6 +98,7 @@ public void setDefaultItems(int defaultItems) * calculateNodeSize : providing HTTP STATUS 202 which signifies REQUEST ACCEPTED. * HTTP STATUS 200 will provide the size details response from cache. */ + @Override public NodeSizeDetails calculateNodeSize(final String nodeId) { NodeRef nodeRef = nodes.validateNode(nodeId); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index b0044953869..ed1202310fe 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -53,21 +53,17 @@ public class SizeDetailsImplTest extends AbstractBaseApiTest { private SizeDetailsImpl sizeDetailsImpl; private Nodes nodes; - private NodeService nodeService; - private PermissionService permissionService; - private ActionService actionService; - private SimpleCache simpleCache; - private final int defaultItems = 1000; + private final static int defaultItems = 1000; @Before public void setUp() { sizeDetailsImpl = new SizeDetailsImpl(); nodes = mock(Nodes.class); - nodeService = mock(NodeService.class); - permissionService = mock(PermissionService.class); - actionService = mock(ActionService.class); - simpleCache = mock(SimpleCache.class); + NodeService nodeService = mock(NodeService.class); + PermissionService permissionService = mock(PermissionService.class); + ActionService actionService = mock(ActionService.class); + SimpleCache simpleCache = mock(SimpleCache.class); sizeDetailsImpl.setNodes(nodes); sizeDetailsImpl.setNodeService(nodeService); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 09e8fae0602..0a6a56f1086 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -154,11 +154,11 @@ public void testPerformanceTesting() throws Exception for(int i=1;i<=500;i++) { String folderBName = "folder"+i+RUNID + "_B"; - String folderB_Id = createFolder(parentFolder, folderBName, null).getId(); + String folderBId = createFolder(parentFolder, folderBName, null).getId(); String fileName = "content"+i+ RUNID + ".txt"; Document d1 = new Document(); d1.setIsFolder(false); - d1.setParentId(folderB_Id); + d1.setParentId(folderBId); d1.setName(fileName); d1.setNodeType(TYPE_CM_CONTENT); d1.setContent(createContentInfo()); From f0549d18620c0f697605da2e4b9781253bdd8ccd Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 13:36:57 +0530 Subject: [PATCH 148/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index ed1202310fe..6e150831db9 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -53,7 +53,7 @@ public class SizeDetailsImplTest extends AbstractBaseApiTest { private SizeDetailsImpl sizeDetailsImpl; private Nodes nodes; - private final static int defaultItems = 1000; + private final static int DEFAULT_ITEMS = 1000; @Before public void setUp() @@ -70,7 +70,7 @@ public void setUp() sizeDetailsImpl.setPermissionService(permissionService); sizeDetailsImpl.setActionService(actionService); sizeDetailsImpl.setSimpleCache(simpleCache); - sizeDetailsImpl.setDefaultItems(defaultItems); + sizeDetailsImpl.setDefaultItems(DEFAULT_ITEMS); } @Test From 4a0ca9a133fe095264681878f7a2b2b79252ea5a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 14:31:07 +0530 Subject: [PATCH 149/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 6e150831db9..bbb00ebdf6a 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -63,7 +63,7 @@ public void setUp() NodeService nodeService = mock(NodeService.class); PermissionService permissionService = mock(PermissionService.class); ActionService actionService = mock(ActionService.class); - SimpleCache simpleCache = mock(SimpleCache.class); + SimpleCache simpleCache = mock(SimpleCache.class); sizeDetailsImpl.setNodes(nodes); sizeDetailsImpl.setNodeService(nodeService); From 2fb2f31668f420d3be189bd92e58269d1a1452fe Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 15:46:34 +0530 Subject: [PATCH 150/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../src/test/java/org/alfresco/AppContext04TestSuite.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index adcd9aee52a..d7822121dee 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -77,8 +77,7 @@ org.alfresco.repo.web.scripts.node.NodeWebScripTest.class, org.alfresco.rest.api.impl.CommentsImplUnitTest.class, org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, - org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, - org.alfresco.rest.api.impl.SizeDetailsImplTest.class + org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class }) public class AppContext04TestSuite { From a8c87f7273ac6393582085a481e9e8734e54761a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 16:17:00 +0530 Subject: [PATCH 151/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/rest/api/nodes/NodesEntityResource.java | 6 +++++- .../src/test/java/org/alfresco/AppContext02TestSuite.java | 3 +-- .../src/test/java/org/alfresco/AppContext01TestSuite.java | 3 +-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index a52fd8206a8..b424f70e3bd 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -77,7 +77,6 @@ public class NodesEntityResource implements private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class); private Nodes nodes; private DirectAccessUrlHelper directAccessUrlHelper; - private SizeDetails sizeDetails; public void setNodes(Nodes nodes) @@ -90,6 +89,11 @@ public void setDirectAccessUrlHelper(DirectAccessUrlHelper directAccessUrlHelper this.directAccessUrlHelper = directAccessUrlHelper; } + public void setSizeDetails(SizeDetails sizeDetails) + { + this.sizeDetails = sizeDetails; + } + @Override public void afterPropertiesSet() { diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 2b097a6e05f..6d004436480 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -76,8 +76,7 @@ org.alfresco.rest.api.tests.TempOutputStreamTest.class, org.alfresco.rest.api.tests.BufferedResponseTest.class, org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, - org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, - org.alfresco.rest.api.tests.NodeSizeDetailsTest.class + org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class }) public class AppContext02TestSuite { diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index e210648ca48..073827a1291 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -78,8 +78,7 @@ org.alfresco.repo.activities.feed.cleanup.FeedCleanerTestCaseSensitivity.class, org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, - org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, - org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest.class + org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class }) public class AppContext01TestSuite { From 83d798641a9ad37a052b19e006617dcaa0755f16 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 16:39:46 +0530 Subject: [PATCH 152/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../src/test/java/org/alfresco/AppContext02TestSuite.java | 3 ++- .../src/test/java/org/alfresco/AppContext04TestSuite.java | 3 ++- .../src/test/java/org/alfresco/AppContext01TestSuite.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 6d004436480..2b097a6e05f 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -76,7 +76,8 @@ org.alfresco.rest.api.tests.TempOutputStreamTest.class, org.alfresco.rest.api.tests.BufferedResponseTest.class, org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, - org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class + org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, + org.alfresco.rest.api.tests.NodeSizeDetailsTest.class }) public class AppContext02TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index d7822121dee..adcd9aee52a 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -77,7 +77,8 @@ org.alfresco.repo.web.scripts.node.NodeWebScripTest.class, org.alfresco.rest.api.impl.CommentsImplUnitTest.class, org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, - org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class + org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, + org.alfresco.rest.api.impl.SizeDetailsImplTest.class }) public class AppContext04TestSuite { diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index 073827a1291..e210648ca48 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -78,7 +78,8 @@ org.alfresco.repo.activities.feed.cleanup.FeedCleanerTestCaseSensitivity.class, org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, - org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class + org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, + org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest.class }) public class AppContext01TestSuite { From c3a0ebc44848d48db3aa563ec30f3a1d0cc7e783 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 17:32:12 +0530 Subject: [PATCH 153/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/impl/SizeDetailsImpl.java | 8 +-- .../rest/api/impl/SizeDetailsImplTest.java | 5 +- .../rest/api/tests/NodeSizeDetailsTest.java | 56 +++++++++---------- .../NodeSizeDetailsActionExecutor.java | 4 +- .../NodeSizeDetailsActionExecutorTest.java | 4 +- 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 64c28b208b4..baae67b003a 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -61,7 +61,7 @@ public class SizeDetailsImpl implements SizeDetails private NodeService nodeService; private PermissionService permissionService; private ActionService actionService; - private SimpleCache simpleCache; + private SimpleCache> simpleCache; private int defaultItems; public void setNodes(Nodes nodes) @@ -84,7 +84,7 @@ public void setActionService(ActionService actionService) this.actionService = actionService; } - public void setSimpleCache(SimpleCache simpleCache) + public void setSimpleCache(SimpleCache> simpleCache) { this.simpleCache = simpleCache; } @@ -117,13 +117,13 @@ public NodeSizeDetails calculateNodeSize(final String nodeId) } LOG.debug("Executing NodeSizeActionExecuter from calculateNodeSize method"); - return executorResultToSizeDetails((Map)simpleCache.get(nodeRef.getId())); + return executorResultToSizeDetails(simpleCache.get(nodeRef.getId())); } /** * Executing Action Asynchronously. */ - private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache simpleCache) + private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache> simpleCache) { Map currentStatus = new HashMap<>(); currentStatus.put(STATUS,IN_PROGRESS); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index bbb00ebdf6a..a9c3e167dc2 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -40,6 +40,7 @@ import org.junit.Test; import java.io.Serializable; +import java.util.Map; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.mock; @@ -63,7 +64,7 @@ public void setUp() NodeService nodeService = mock(NodeService.class); PermissionService permissionService = mock(PermissionService.class); ActionService actionService = mock(ActionService.class); - SimpleCache simpleCache = mock(SimpleCache.class); + SimpleCache> simpleCache = mock(SimpleCache.class); sizeDetailsImpl.setNodes(nodes); sizeDetailsImpl.setNodeService(nodeService); @@ -82,7 +83,6 @@ public void calculateNodeSize() throws Exception String fileName = "content.txt"; String folder0Name = "f0-testParentFolder-"+RUNID; String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); - NodeRef nodeRef = new NodeRef("protocol", "identifier", parentFolder); Document d1 = new Document(); d1.setIsFolder(false); @@ -93,7 +93,6 @@ public void calculateNodeSize() throws Exception d1.setCreatedByUser(userInfo); d1.setModifiedByUser(userInfo); - when(nodes.validateNode(parentFolder)).thenReturn(nodeRef); NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(parentFolder); assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",nodeSizeDetails); } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 0a6a56f1086..3eb60ca920e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -34,6 +34,9 @@ import org.alfresco.rest.api.tests.client.data.Node; import org.alfresco.rest.api.tests.client.data.UserInfo; import org.alfresco.rest.api.tests.util.RestApiUtil; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; import org.junit.After; import org.junit.Before; @@ -44,6 +47,7 @@ import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; import java.time.LocalTime; import java.util.HashMap; @@ -52,9 +56,7 @@ import java.util.UUID; import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * V1 REST API tests for calculating and retrieving Folder size. @@ -67,6 +69,9 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest private Site userOneN1Site; private String folderId; + private ApplicationContext applicationContext; + + private PermissionService permissionService; // Method to create content info private ContentInfo createContentInfo() @@ -107,6 +112,7 @@ public void setup() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); + permissionService = applicationContext.getBean("permissionService", PermissionService.class); } /** @@ -124,15 +130,7 @@ public void testPostAndGetFolderSize() throws Exception // Perform POST request HttpResponse postResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); - // Validate response and parsed document - assertNotNull("Response should not be null", postResponse); - - String jsonResponse = String.valueOf(postResponse.getJsonResponse()); - assertNotNull("JSON response should not be null", jsonResponse); - - // Parse JSON response - Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); - assertNotNull("Parsed document should not be null", document); + assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",postResponse.getJsonResponse()); HttpResponse getResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); @@ -181,15 +179,7 @@ public void testPerformanceTesting() throws Exception // Perform POST request HttpResponse postResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 202); - // Validate response and parsed document - assertNotNull("Response should not be null", postResponse); - - String jsonResponse = String.valueOf(postResponse.getJsonResponse()); - assertNotNull("JSON response should not be null", jsonResponse); - - // Parse JSON response - Object document = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), Object.class); - assertNotNull("Parsed document should not be null", document); + assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",postResponse.getJsonResponse()); HttpResponse getResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 200); @@ -209,26 +199,32 @@ public void testPerformanceTesting() throws Exception @Test public void testHTTPStatus() throws Exception { + // Prepare parameters + Map params = new HashMap<>(); + + setRequestContext(null); delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401); setRequestContext(user1); - NodeTarget tgt = new NodeTarget(); - tgt.setTargetParentId(folderId); - HttpResponse response = post(getCalculateFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404); + NodeRef folderIdRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderId); + params.put("nodeId", folderIdRef.getId()); + params.put("maxItems", "1000"); + permissionService.setPermission(folderIdRef, user1, PermissionService.ASPECTS, true); + HttpResponse response = post(getCalculateFolderSizeUrl(folderIdRef.getId()), toJsonAsStringNonNull(params), null, 403); assertNotNull(response); // Create a folder within the site document's library. String folderName = "nestedFolder" + System.currentTimeMillis(); String nestedFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); - // Prepare parameters - Map params = new HashMap<>(); - params.put("nodeId", nestedFolderId); - params.put("maxItems", "100"); + + params = new HashMap<>(); + params.put("nodeId", folderIdRef.getId()); + params.put("maxItems", "1000"); // Perform POST request - response = post(getCalculateFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); - assertNotNull(response); + HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); + assertNotNull(responseForInvalidNode); } @After diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java index 3cc2ce1ad79..fb85545e1f1 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java @@ -67,7 +67,7 @@ public class NodeSizeDetailsActionExecutor extends ActionExecuterAbstractBase private static final String FIELD_FACET = "content.size"; private static final String FACET_QUERY = "content.size:[0 TO "+Integer.MAX_VALUE+"] \"label\": \"large\",\"group\":\"Size\""; private SearchService searchService; - private SimpleCache simpleCache; + private SimpleCache> simpleCache; /** * Set the search service @@ -84,7 +84,7 @@ public void setSearchService(SearchService searchService) * * @param simpleCache the cache service */ - public void setSimpleCache(SimpleCache simpleCache) + public void setSimpleCache(SimpleCache> simpleCache) { this.simpleCache = simpleCache; } diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java index f9168af16a3..17f8dabc805 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java @@ -65,7 +65,7 @@ public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest * * @param simpleCache the cache service */ - private SimpleCache simpleCache; + private SimpleCache> simpleCache; /** * Called at the begining of all tests. @@ -95,7 +95,7 @@ public void before() throws Exception // Get the executer instance. this.executer = (NodeSizeDetailsActionExecutor)this.applicationContext.getBean(NodeSizeDetailsActionExecutor.NAME); - simpleCache = (SimpleCache) this.applicationContext.getBean("folderSizeSharedCache"); + simpleCache = (SimpleCache>) this.applicationContext.getBean("folderSizeSharedCache"); } /** From c9e6ab21444248b0c5d3910c6d651b942d649f6e Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 17:56:16 +0530 Subject: [PATCH 154/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/rest/api/impl/SizeDetailsImplTest.java | 7 ++----- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 8 +------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index a9c3e167dc2..e88a451a494 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -33,7 +33,6 @@ import org.alfresco.rest.api.tests.client.data.Document; import org.alfresco.rest.api.tests.client.data.UserInfo; import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.PermissionService; import org.junit.Before; @@ -44,7 +43,6 @@ import static org.junit.Assert.assertNull; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Unit tests for {@link SizeDetailsImpl} class. @@ -53,14 +51,13 @@ public class SizeDetailsImplTest extends AbstractBaseApiTest { private SizeDetailsImpl sizeDetailsImpl; - private Nodes nodes; private final static int DEFAULT_ITEMS = 1000; @Before public void setUp() { sizeDetailsImpl = new SizeDetailsImpl(); - nodes = mock(Nodes.class); + Nodes nodes = mock(Nodes.class); NodeService nodeService = mock(NodeService.class); PermissionService permissionService = mock(PermissionService.class); ActionService actionService = mock(ActionService.class); @@ -93,7 +90,7 @@ public void calculateNodeSize() throws Exception d1.setCreatedByUser(userInfo); d1.setModifiedByUser(userInfo); - NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(parentFolder); + NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(tDocLibNodeId); assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",nodeSizeDetails); } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 3eb60ca920e..03373b395dd 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -25,7 +25,6 @@ */ package org.alfresco.rest.api.tests; -import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; @@ -47,13 +46,11 @@ import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationContext; import java.time.LocalTime; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.UUID; import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; import static org.junit.Assert.*; @@ -69,8 +66,6 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest private Site userOneN1Site; private String folderId; - private ApplicationContext applicationContext; - private PermissionService permissionService; // Method to create content info @@ -188,7 +183,7 @@ public void testPerformanceTesting() throws Exception assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status")); - //current Time after executing GET/size API + //current Time after executing GET/request-size-details LocalTime actualTime = LocalTime.now(); assertTrue("Calculating folder node is taking time greater than 5 seconds ",actualTime.isBefore(expectedTime)); } @@ -202,7 +197,6 @@ public void testHTTPStatus() throws Exception // Prepare parameters Map params = new HashMap<>(); - setRequestContext(null); delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401); From 2642067af95df197b038903a54ff871a1f4e5a40 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 18:34:03 +0530 Subject: [PATCH 155/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../alfresco/rest/api/impl/SizeDetailsImplTest.java | 11 +++++++---- .../alfresco/rest/api/tests/NodeSizeDetailsTest.java | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index e88a451a494..6413bd08aa5 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -50,16 +50,18 @@ */ public class SizeDetailsImplTest extends AbstractBaseApiTest { - private SizeDetailsImpl sizeDetailsImpl; private final static int DEFAULT_ITEMS = 1000; + private SizeDetailsImpl sizeDetailsImpl; + private NodeService nodeService; + private PermissionService permissionService; @Before public void setUp() { sizeDetailsImpl = new SizeDetailsImpl(); Nodes nodes = mock(Nodes.class); - NodeService nodeService = mock(NodeService.class); - PermissionService permissionService = mock(PermissionService.class); + nodeService = mock(NodeService.class); + permissionService = mock(PermissionService.class); ActionService actionService = mock(ActionService.class); SimpleCache> simpleCache = mock(SimpleCache.class); @@ -80,6 +82,7 @@ public void calculateNodeSize() throws Exception String fileName = "content.txt"; String folder0Name = "f0-testParentFolder-"+RUNID; String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); + permissionService.setPermission(nodeService.getNodeRef(Long.valueOf(parentFolder)), user1, PermissionService.READ, true); Document d1 = new Document(); d1.setIsFolder(false); @@ -90,7 +93,7 @@ public void calculateNodeSize() throws Exception d1.setCreatedByUser(userInfo); d1.setModifiedByUser(userInfo); - NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(tDocLibNodeId); + NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(parentFolder); assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",nodeSizeDetails); } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 03373b395dd..1864df9ddb6 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -204,7 +204,7 @@ public void testHTTPStatus() throws Exception NodeRef folderIdRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderId); params.put("nodeId", folderIdRef.getId()); params.put("maxItems", "1000"); - permissionService.setPermission(folderIdRef, user1, PermissionService.ASPECTS, true); + permissionService.setPermission(folderIdRef, user1, PermissionService.WRITE, false); HttpResponse response = post(getCalculateFolderSizeUrl(folderIdRef.getId()), toJsonAsStringNonNull(params), null, 403); assertNotNull(response); From 46240eb2575b24db844b1f1fb2be5fff894b6ac8 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 19:14:09 +0530 Subject: [PATCH 156/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../alfresco/rest/api/impl/SizeDetailsImplTest.java | 5 +++-- .../alfresco/rest/api/tests/NodeSizeDetailsTest.java | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 6413bd08aa5..1f78634ce35 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -54,12 +54,13 @@ public class SizeDetailsImplTest extends AbstractBaseApiTest private SizeDetailsImpl sizeDetailsImpl; private NodeService nodeService; private PermissionService permissionService; + private Nodes nodes; @Before public void setUp() { sizeDetailsImpl = new SizeDetailsImpl(); - Nodes nodes = mock(Nodes.class); + nodes = mock(Nodes.class); nodeService = mock(NodeService.class); permissionService = mock(PermissionService.class); ActionService actionService = mock(ActionService.class); @@ -82,7 +83,7 @@ public void calculateNodeSize() throws Exception String fileName = "content.txt"; String folder0Name = "f0-testParentFolder-"+RUNID; String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); - permissionService.setPermission(nodeService.getNodeRef(Long.valueOf(parentFolder)), user1, PermissionService.READ, true); + permissionService.setPermission(nodes.validateNode(parentFolder), PermissionService.ALL_AUTHORITIES, PermissionService.READ, true); Document d1 = new Document(); d1.setIsFolder(false); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 1864df9ddb6..1e3d38bd0dd 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -25,6 +25,7 @@ */ package org.alfresco.rest.api.tests; +import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; @@ -67,6 +68,7 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest private Site userOneN1Site; private String folderId; private PermissionService permissionService; + private Nodes nodes; // Method to create content info private ContentInfo createContentInfo() @@ -108,6 +110,7 @@ public void setup() throws Exception String folderName = "folder" + System.currentTimeMillis(); folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); permissionService = applicationContext.getBean("permissionService", PermissionService.class); + nodes = applicationContext.getBean("Nodes", Nodes.class); } /** @@ -201,11 +204,10 @@ public void testHTTPStatus() throws Exception delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401); setRequestContext(user1); - NodeRef folderIdRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderId); - params.put("nodeId", folderIdRef.getId()); + params.put("nodeId", folderId); params.put("maxItems", "1000"); - permissionService.setPermission(folderIdRef, user1, PermissionService.WRITE, false); - HttpResponse response = post(getCalculateFolderSizeUrl(folderIdRef.getId()), toJsonAsStringNonNull(params), null, 403); + permissionService.setPermission(nodes.validateNode(folderId), PermissionService.ALL_AUTHORITIES, PermissionService.READ, false); + HttpResponse response = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), null, 403); assertNotNull(response); // Create a folder within the site document's library. @@ -213,7 +215,7 @@ public void testHTTPStatus() throws Exception String nestedFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); params = new HashMap<>(); - params.put("nodeId", folderIdRef.getId()); + params.put("nodeId", folderId); params.put("maxItems", "1000"); // Perform POST request From 9606d8e2deeca7113eb4c3e1656b56bb991ee4e8 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 22 Aug 2024 21:45:58 +0530 Subject: [PATCH 157/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/impl/SizeDetailsImplTest.java | 32 +++++++++++-------- .../rest/api/tests/NodeSizeDetailsTest.java | 23 +++++++++++-- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 1f78634ce35..618b8bcd70d 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -27,18 +27,20 @@ import org.alfresco.repo.cache.SimpleCache; import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.model.NodePermissions; import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.api.tests.AbstractBaseApiTest; -import org.alfresco.rest.api.tests.client.data.ContentInfo; -import org.alfresco.rest.api.tests.client.data.Document; -import org.alfresco.rest.api.tests.client.data.UserInfo; +import org.alfresco.rest.api.tests.client.data.*; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.junit.Before; import org.junit.Test; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import static org.junit.Assert.assertNull; @@ -52,17 +54,14 @@ public class SizeDetailsImplTest extends AbstractBaseApiTest { private final static int DEFAULT_ITEMS = 1000; private SizeDetailsImpl sizeDetailsImpl; - private NodeService nodeService; - private PermissionService permissionService; - private Nodes nodes; @Before public void setUp() { sizeDetailsImpl = new SizeDetailsImpl(); - nodes = mock(Nodes.class); - nodeService = mock(NodeService.class); - permissionService = mock(PermissionService.class); + Nodes nodes = mock(Nodes.class); + NodeService nodeService = mock(NodeService.class); + PermissionService permissionService = mock(PermissionService.class); ActionService actionService = mock(ActionService.class); SimpleCache> simpleCache = mock(SimpleCache.class); @@ -80,21 +79,28 @@ public void calculateNodeSize() throws Exception setRequestContext(user1); UserInfo userInfo = new UserInfo(user1); + String myNodeId = getMyNodeId(); String fileName = "content.txt"; String folder0Name = "f0-testParentFolder-"+RUNID; - String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); - permissionService.setPermission(nodes.validateNode(parentFolder), PermissionService.ALL_AUTHORITIES, PermissionService.READ, true); + NodePermissions nodePermissions = new NodePermissions(); + Folder parentFolder = createFolder(myNodeId, folder0Name,null); + + List locallySetPermissions = new ArrayList<>(); + locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.ALL_AUTHORITIES, AccessStatus.ALLOWED.toString())); + nodePermissions.setLocallySet(locallySetPermissions); Document d1 = new Document(); d1.setIsFolder(false); - d1.setParentId(parentFolder); + d1.setPermissions(nodePermissions); + d1.setParentId(parentFolder.getId()); d1.setName(fileName); d1.setNodeType(TYPE_CM_CONTENT); d1.setContent(createContentInfo()); d1.setCreatedByUser(userInfo); d1.setModifiedByUser(userInfo); + parentFolder.setPermissions(nodePermissions); - NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(parentFolder); + NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(parentFolder.getId()); assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",nodeSizeDetails); } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 1e3d38bd0dd..93b480c8955 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -26,6 +26,7 @@ package org.alfresco.rest.api.tests; import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.model.NodePermissions; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; @@ -34,8 +35,7 @@ import org.alfresco.rest.api.tests.client.data.Node; import org.alfresco.rest.api.tests.client.data.UserInfo; import org.alfresco.rest.api.tests.util.RestApiUtil; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; import org.junit.After; @@ -49,6 +49,7 @@ import org.slf4j.LoggerFactory; import java.time.LocalTime; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -199,6 +200,7 @@ public void testHTTPStatus() throws Exception { // Prepare parameters Map params = new HashMap<>(); + UserInfo userInfo = new UserInfo(user1); setRequestContext(null); delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401); @@ -206,7 +208,22 @@ public void testHTTPStatus() throws Exception setRequestContext(user1); params.put("nodeId", folderId); params.put("maxItems", "1000"); - permissionService.setPermission(nodes.validateNode(folderId), PermissionService.ALL_AUTHORITIES, PermissionService.READ, false); + String fileName = "content.txt"; + NodePermissions nodePermissions = new NodePermissions(); + List locallySetPermissions = new ArrayList<>(); + locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.READ, AccessStatus.DENIED.toString())); + nodePermissions.setLocallySet(locallySetPermissions); + + Document d1 = new Document(); + d1.setIsFolder(false); + d1.setParentId(folderId); + d1.setName(fileName); + d1.setNodeType(TYPE_CM_CONTENT); + d1.setContent(createContentInfo()); + d1.setCreatedByUser(userInfo); + d1.setModifiedByUser(userInfo); + d1.setPermissions(nodePermissions); + HttpResponse response = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), null, 403); assertNotNull(response); From 5a1ea3398ae903b2ec055eb4486e7df5768e3f55 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 00:15:06 +0530 Subject: [PATCH 158/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/AppContext04TestSuite.java | 5 +- .../rest/api/impl/SizeDetailsImplTest.java | 122 ------------------ .../rest/api/tests/NodeSizeDetailsTest.java | 2 +- 3 files changed, 3 insertions(+), 126 deletions(-) delete mode 100644 remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index adcd9aee52a..8f41edd452c 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2024 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -77,8 +77,7 @@ org.alfresco.repo.web.scripts.node.NodeWebScripTest.class, org.alfresco.rest.api.impl.CommentsImplUnitTest.class, org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, - org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, - org.alfresco.rest.api.impl.SizeDetailsImplTest.class + org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class }) public class AppContext04TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java deleted file mode 100644 index 618b8bcd70d..00000000000 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * #%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 org.alfresco.repo.cache.SimpleCache; -import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.model.NodePermissions; -import org.alfresco.rest.api.model.NodeSizeDetails; -import org.alfresco.rest.api.tests.AbstractBaseApiTest; -import org.alfresco.rest.api.tests.client.data.*; -import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.security.PermissionService; -import org.junit.Before; -import org.junit.Test; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.mock; - -/** - * Unit tests for {@link SizeDetailsImpl} class. - * - */ -public class SizeDetailsImplTest extends AbstractBaseApiTest -{ - private final static int DEFAULT_ITEMS = 1000; - private SizeDetailsImpl sizeDetailsImpl; - - @Before - public void setUp() - { - sizeDetailsImpl = new SizeDetailsImpl(); - Nodes nodes = mock(Nodes.class); - NodeService nodeService = mock(NodeService.class); - PermissionService permissionService = mock(PermissionService.class); - ActionService actionService = mock(ActionService.class); - SimpleCache> simpleCache = mock(SimpleCache.class); - - sizeDetailsImpl.setNodes(nodes); - sizeDetailsImpl.setNodeService(nodeService); - sizeDetailsImpl.setPermissionService(permissionService); - sizeDetailsImpl.setActionService(actionService); - sizeDetailsImpl.setSimpleCache(simpleCache); - sizeDetailsImpl.setDefaultItems(DEFAULT_ITEMS); - } - - @Test - public void calculateNodeSize() throws Exception - { - setRequestContext(user1); - UserInfo userInfo = new UserInfo(user1); - - String myNodeId = getMyNodeId(); - String fileName = "content.txt"; - String folder0Name = "f0-testParentFolder-"+RUNID; - NodePermissions nodePermissions = new NodePermissions(); - Folder parentFolder = createFolder(myNodeId, folder0Name,null); - - List locallySetPermissions = new ArrayList<>(); - locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.ALL_AUTHORITIES, AccessStatus.ALLOWED.toString())); - nodePermissions.setLocallySet(locallySetPermissions); - - Document d1 = new Document(); - d1.setIsFolder(false); - d1.setPermissions(nodePermissions); - d1.setParentId(parentFolder.getId()); - d1.setName(fileName); - d1.setNodeType(TYPE_CM_CONTENT); - d1.setContent(createContentInfo()); - d1.setCreatedByUser(userInfo); - d1.setModifiedByUser(userInfo); - parentFolder.setPermissions(nodePermissions); - - NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(parentFolder.getId()); - assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",nodeSizeDetails); - } - - // Method to create content info - private ContentInfo createContentInfo() - { - ContentInfo ciExpected = new ContentInfo(); - ciExpected.setMimeType("text/plain"); - ciExpected.setMimeTypeName("Plain Text"); - ciExpected.setSizeInBytes(44500L); - ciExpected.setEncoding("ISO-8859-1"); - return ciExpected; - } - - @Override - public String getScope() { - return "public"; - } -} diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 93b480c8955..5d58630a5e0 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -208,7 +208,7 @@ public void testHTTPStatus() throws Exception setRequestContext(user1); params.put("nodeId", folderId); params.put("maxItems", "1000"); - String fileName = "content.txt"; + String fileName = "dummyContent.txt"; NodePermissions nodePermissions = new NodePermissions(); List locallySetPermissions = new ArrayList<>(); locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.READ, AccessStatus.DENIED.toString())); From 61910036b3ada0bbafe07638493401cec260be42 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 00:46:12 +0530 Subject: [PATCH 159/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/tests/NodeSizeDetailsTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 5d58630a5e0..c234c93d78e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -30,10 +30,7 @@ import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; -import org.alfresco.rest.api.tests.client.data.ContentInfo; -import org.alfresco.rest.api.tests.client.data.Document; -import org.alfresco.rest.api.tests.client.data.Node; -import org.alfresco.rest.api.tests.client.data.UserInfo; +import org.alfresco.rest.api.tests.client.data.*; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; @@ -208,7 +205,11 @@ public void testHTTPStatus() throws Exception setRequestContext(user1); params.put("nodeId", folderId); params.put("maxItems", "1000"); + String childFolderName = "dummyFolder"; String fileName = "dummyContent.txt"; + + Folder folder = createFolder(tDocLibNodeId, childFolderName); + NodePermissions nodePermissions = new NodePermissions(); List locallySetPermissions = new ArrayList<>(); locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.READ, AccessStatus.DENIED.toString())); @@ -216,15 +217,16 @@ public void testHTTPStatus() throws Exception Document d1 = new Document(); d1.setIsFolder(false); - d1.setParentId(folderId); + d1.setParentId(folder.getId()); d1.setName(fileName); d1.setNodeType(TYPE_CM_CONTENT); d1.setContent(createContentInfo()); d1.setCreatedByUser(userInfo); d1.setModifiedByUser(userInfo); d1.setPermissions(nodePermissions); + folder.setPermissions(nodePermissions); - HttpResponse response = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), null, 403); + HttpResponse response = post(getCalculateFolderSizeUrl(folder.getId()), toJsonAsStringNonNull(params), null, 403); assertNotNull(response); // Create a folder within the site document's library. From cfbae046ddd8d0fb3372eba5879f27d178c4725a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 01:07:01 +0530 Subject: [PATCH 160/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index c234c93d78e..0aa9908a756 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -212,7 +212,7 @@ public void testHTTPStatus() throws Exception NodePermissions nodePermissions = new NodePermissions(); List locallySetPermissions = new ArrayList<>(); - locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.READ, AccessStatus.DENIED.toString())); + locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.DELETE, AccessStatus.DENIED.toString())); nodePermissions.setLocallySet(locallySetPermissions); Document d1 = new Document(); From 3f86162ab0331ef2bb7ea7dc09b4e14963bbb519 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 01:27:43 +0530 Subject: [PATCH 161/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 0aa9908a756..a7407263095 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -212,7 +212,7 @@ public void testHTTPStatus() throws Exception NodePermissions nodePermissions = new NodePermissions(); List locallySetPermissions = new ArrayList<>(); - locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.DELETE, AccessStatus.DENIED.toString())); + locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.READ, AccessStatus.DENIED.toString())); nodePermissions.setLocallySet(locallySetPermissions); Document d1 = new Document(); @@ -226,9 +226,12 @@ public void testHTTPStatus() throws Exception d1.setPermissions(nodePermissions); folder.setPermissions(nodePermissions); - HttpResponse response = post(getCalculateFolderSizeUrl(folder.getId()), toJsonAsStringNonNull(params), null, 403); + setRequestContext(user2); + HttpResponse response = post(getCalculateFolderSizeUrl(folder.getId()), toJsonAsStringNonNull(d1), null, 403); assertNotNull(response); + setRequestContext(user1); + // Create a folder within the site document's library. String folderName = "nestedFolder" + System.currentTimeMillis(); String nestedFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); From f4c36ad4e147d0d5421f978038d501b0affc651c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 01:53:37 +0530 Subject: [PATCH 162/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index a7407263095..e04c5af8bf6 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -208,7 +208,7 @@ public void testHTTPStatus() throws Exception String childFolderName = "dummyFolder"; String fileName = "dummyContent.txt"; - Folder folder = createFolder(tDocLibNodeId, childFolderName); + Folder folder = createFolder(Nodes.PATH_MY, childFolderName); NodePermissions nodePermissions = new NodePermissions(); List locallySetPermissions = new ArrayList<>(); @@ -226,7 +226,6 @@ public void testHTTPStatus() throws Exception d1.setPermissions(nodePermissions); folder.setPermissions(nodePermissions); - setRequestContext(user2); HttpResponse response = post(getCalculateFolderSizeUrl(folder.getId()), toJsonAsStringNonNull(d1), null, 403); assertNotNull(response); From 16f93add09eecbe1f39a7525c4882997d75faa9c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 02:18:36 +0530 Subject: [PATCH 163/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/tests/NodeSizeDetailsTest.java | 47 ++++--------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index e04c5af8bf6..59e7f114ee3 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -26,13 +26,14 @@ package org.alfresco.rest.api.tests; import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.model.NodePermissions; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; -import org.alfresco.rest.api.tests.client.data.*; +import org.alfresco.rest.api.tests.client.data.ContentInfo; +import org.alfresco.rest.api.tests.client.data.Document; +import org.alfresco.rest.api.tests.client.data.UserInfo; +import org.alfresco.rest.api.tests.client.data.Node; import org.alfresco.rest.api.tests.util.RestApiUtil; -import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; import org.junit.After; @@ -46,13 +47,15 @@ import org.slf4j.LoggerFactory; import java.time.LocalTime; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; /** * V1 REST API tests for calculating and retrieving Folder size. @@ -195,47 +198,15 @@ public void testPerformanceTesting() throws Exception @Test public void testHTTPStatus() throws Exception { - // Prepare parameters - Map params = new HashMap<>(); - UserInfo userInfo = new UserInfo(user1); - setRequestContext(null); delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401); setRequestContext(user1); - params.put("nodeId", folderId); - params.put("maxItems", "1000"); - String childFolderName = "dummyFolder"; - String fileName = "dummyContent.txt"; - - Folder folder = createFolder(Nodes.PATH_MY, childFolderName); - - NodePermissions nodePermissions = new NodePermissions(); - List locallySetPermissions = new ArrayList<>(); - locallySetPermissions.add(new NodePermissions.NodePermission(user1, PermissionService.READ, AccessStatus.DENIED.toString())); - nodePermissions.setLocallySet(locallySetPermissions); - - Document d1 = new Document(); - d1.setIsFolder(false); - d1.setParentId(folder.getId()); - d1.setName(fileName); - d1.setNodeType(TYPE_CM_CONTENT); - d1.setContent(createContentInfo()); - d1.setCreatedByUser(userInfo); - d1.setModifiedByUser(userInfo); - d1.setPermissions(nodePermissions); - folder.setPermissions(nodePermissions); - - HttpResponse response = post(getCalculateFolderSizeUrl(folder.getId()), toJsonAsStringNonNull(d1), null, 403); - assertNotNull(response); - - setRequestContext(user1); - // Create a folder within the site document's library. String folderName = "nestedFolder" + System.currentTimeMillis(); String nestedFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); - params = new HashMap<>(); + Map params = new HashMap<>(); params.put("nodeId", folderId); params.put("maxItems", "1000"); From 29d17ece20dab90d592c88ad5feae66bbd83ace7 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 02:54:35 +0530 Subject: [PATCH 164/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../alfresco/rest/api/tests/NodeSizeDetailsTest.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 59e7f114ee3..c9970bd4151 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -204,14 +204,20 @@ public void testHTTPStatus() throws Exception setRequestContext(user1); // Create a folder within the site document's library. String folderName = "nestedFolder" + System.currentTimeMillis(); + String fileName = "dummyContent.txt"; String nestedFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); + Document d1 = new Document(); + d1.setIsFolder(false); + d1.setParentId(nestedFolderId); + d1.setName(fileName); + d1.setNodeType(TYPE_CM_CONTENT); + Map params = new HashMap<>(); - params.put("nodeId", folderId); - params.put("maxItems", "1000"); + params.put("nodeId", nestedFolderId); // Perform POST request - HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); + HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(d1.getId()), toJsonAsStringNonNull(d1), 422); assertNotNull(responseForInvalidNode); } From 51176042c076d0f8936d723bfe330b87e2e3cc34 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 03:21:19 +0530 Subject: [PATCH 165/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index c9970bd4151..4f2d2312f6e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -213,11 +213,13 @@ public void testHTTPStatus() throws Exception d1.setName(fileName); d1.setNodeType(TYPE_CM_CONTENT); + // Prepare parameters Map params = new HashMap<>(); params.put("nodeId", nestedFolderId); + params.put("maxItems", "100"); // Perform POST request - HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(d1.getId()), toJsonAsStringNonNull(d1), 422); + HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); assertNotNull(responseForInvalidNode); } From d690797355496c98bf3d7156a6c6855b5bc77217 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 08:54:10 +0530 Subject: [PATCH 166/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/rest/api/nodes/NodesEntityResource.java | 4 ++-- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index b424f70e3bd..7b8f453b443 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -251,8 +251,8 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq * If nodeId does not represent a folder, InvalidNodeTypeException (status 422). */ @Operation("request-size-details") - @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder",successStatus = Status.STATUS_ACCEPTED) - @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")}) + @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder node",successStatus = Status.STATUS_ACCEPTED) + @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id", description = "A single nodeId")}) public NodeSizeDetails calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) { try diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 4f2d2312f6e..2cbb10871d1 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -205,21 +205,24 @@ public void testHTTPStatus() throws Exception // Create a folder within the site document's library. String folderName = "nestedFolder" + System.currentTimeMillis(); String fileName = "dummyContent.txt"; + String docId = "docId" + System.currentTimeMillis(); String nestedFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); Document d1 = new Document(); d1.setIsFolder(false); + d1.setId(docId); d1.setParentId(nestedFolderId); d1.setName(fileName); d1.setNodeType(TYPE_CM_CONTENT); + // Prepare parameters Map params = new HashMap<>(); - params.put("nodeId", nestedFolderId); - params.put("maxItems", "100"); + params.put("nodeId", docId); + params.put("maxItems", "1000"); // Perform POST request - HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422); + HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(docId), toJsonAsStringNonNull(params), 422); assertNotNull(responseForInvalidNode); } From 5e711c1a75cb77a9092abe411a628192ef94c026 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 09:21:45 +0530 Subject: [PATCH 167/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/tests/NodeSizeDetailsTest.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 2cbb10871d1..5455bcdd675 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -47,6 +47,7 @@ import org.slf4j.LoggerFactory; import java.time.LocalTime; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -202,27 +203,28 @@ public void testHTTPStatus() throws Exception delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401); setRequestContext(user1); - // Create a folder within the site document's library. - String folderName = "nestedFolder" + System.currentTimeMillis(); - String fileName = "dummyContent.txt"; - String docId = "docId" + System.currentTimeMillis(); - String nestedFolderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); + String nodeName = "node0" + System.currentTimeMillis(); + String folderName = "folder0" + System.currentTimeMillis(); + String nodeType = "app:folderlink"; + String nodeId = "docId0" + System.currentTimeMillis(); - Document d1 = new Document(); - d1.setIsFolder(false); - d1.setId(docId); - d1.setParentId(nestedFolderId); - d1.setName(fileName); - d1.setNodeType(TYPE_CM_CONTENT); + Node nodeResp = createNode(folderId, folderName, nodeType, null); + String n1Id = nodeResp.getId(); + Node n2 = new Node(); + n2.setName(nodeName); + n2.setId(nodeId); + n2.setNodeType(nodeType); + n2.setIsFolder(false); + n2.setParentId(n1Id); // Prepare parameters Map params = new HashMap<>(); - params.put("nodeId", docId); + params.put("nodeId", nodeId); params.put("maxItems", "1000"); // Perform POST request - HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(docId), toJsonAsStringNonNull(params), 422); + HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(nodeId), toJsonAsStringNonNull(params), 422); assertNotNull(responseForInvalidNode); } From 142529d8700d7884a5a970f51be565c0bc2dd701 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 10:19:29 +0530 Subject: [PATCH 168/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/rest/api/nodes/NodesEntityResource.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 7b8f453b443..c85e598deba 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -255,8 +255,6 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id", description = "A single nodeId")}) public NodeSizeDetails calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) { - try - { NodeSizeDetails nodeSizeDetails = sizeDetails.calculateNodeSize(nodeId); if(nodeSizeDetails == null) { @@ -267,12 +265,6 @@ public NodeSizeDetails calculateFolderSize(String nodeId, Void ignore, Parameter withResponse.setStatus(Status.STATUS_OK); } return nodeSizeDetails; - } - catch (Exception alfrescoRuntimeError) - { - LOG.error("Exception occurred in NodesEntityResource:calculateFolderSize {}", alfrescoRuntimeError.getMessage()); - throw new AlfrescoRuntimeException("Exception occurred in NodesEntityResource:calculateFolderSize",alfrescoRuntimeError); - } } } \ No newline at end of file From 7eff12818ead41a1a03fbe0fcfa1f4b76442144c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 10:19:54 +0530 Subject: [PATCH 169/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/nodes/NodesEntityResource.java | 1 - 1 file changed, 1 deletion(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index c85e598deba..f56da30d76f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -28,7 +28,6 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.InputStream; -import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.content.directurl.DirectAccessUrlDisabledException; import org.alfresco.rest.api.DirectAccessUrlHelper; import org.alfresco.rest.api.Nodes; From d3b9ef1ef869e98bbdc140e8dae9158c6a1f23e5 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 12:07:55 +0530 Subject: [PATCH 170/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/tests/NodeSizeDetailsTest.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 5455bcdd675..946b2e18a84 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -203,28 +203,24 @@ public void testHTTPStatus() throws Exception delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401); setRequestContext(user1); - String nodeName = "node0" + System.currentTimeMillis(); String folderName = "folder0" + System.currentTimeMillis(); - String nodeType = "app:folderlink"; - String nodeId = "docId0" + System.currentTimeMillis(); + + HttpResponse responseForNotFound = post(getCalculateFolderSizeUrl(folderName), null, 404); + assertNotNull(responseForNotFound); + + folderName = "folder1" + System.currentTimeMillis(); + String nodeType = "cm:content"; Node nodeResp = createNode(folderId, folderName, nodeType, null); String n1Id = nodeResp.getId(); - Node n2 = new Node(); - n2.setName(nodeName); - n2.setId(nodeId); - n2.setNodeType(nodeType); - n2.setIsFolder(false); - n2.setParentId(n1Id); - // Prepare parameters Map params = new HashMap<>(); - params.put("nodeId", nodeId); + params.put("nodeId", n1Id); params.put("maxItems", "1000"); // Perform POST request - HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(nodeId), toJsonAsStringNonNull(params), 422); + HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(n1Id), toJsonAsStringNonNull(params), 422); assertNotNull(responseForInvalidNode); } From 00bfbff92252a6b42bc55d97ffb8e24b45a34810 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 14:34:32 +0530 Subject: [PATCH 171/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../alfresco/rest/api/impl/SizeDetailsImpl.java | 16 ++++++++-------- .../java/org/alfresco/AppContext04TestSuite.java | 3 ++- .../rest/api/tests/NodeSizeDetailsTest.java | 1 - .../executer/NodeSizeDetailsActionExecutor.java | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index baae67b003a..7eaeda66499 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -50,11 +50,11 @@ public class SizeDetailsImpl implements SizeDetails { + private enum STATE + { + STATUS, NOT_INITIATED, IN_PROGRESS, COMPLETED; + }; private static final Logger LOG = LoggerFactory.getLogger(SizeDetailsImpl.class); - private static final String IN_PROGRESS = "IN-PROGRESS"; - private static final String STATUS = "status"; - private static final String COMPLETED = "COMPLETED"; - private static final String NOT_INITIATED = "NOT-INITIATED"; private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; private static final String FOLDER = "folder"; private Nodes nodes; @@ -126,7 +126,7 @@ public NodeSizeDetails calculateNodeSize(final String nodeId) private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache> simpleCache) { Map currentStatus = new HashMap<>(); - currentStatus.put(STATUS,IN_PROGRESS); + currentStatus.put(STATE.STATUS.name(),STATE.IN_PROGRESS.name()); Action folderSizeAction = actionService.createAction(NodeSizeDetailsActionExecutor.NAME); folderSizeAction.setTrackStatus(true); @@ -143,7 +143,7 @@ private NodeSizeDetails executorResultToSizeDetails(final Map res { if (result == null) { - return new NodeSizeDetails(NOT_INITIATED); + return new NodeSizeDetails(STATE.NOT_INITIATED.name()); } else if(result.containsKey(NodeSizeDetailsActionExecutor.EXCEPTION)) { @@ -155,11 +155,11 @@ else if(result.containsKey(NodeSizeDetailsActionExecutor.EXCEPTION)) if (hasSizeKey) { - return new NodeSizeDetails((String) result.get("nodeId"), (Long) result.get("size"), (String) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), COMPLETED); + return new NodeSizeDetails((String) result.get("nodeId"), (Long) result.get("size"), (String) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), STATE.COMPLETED.name()); } else { - return new NodeSizeDetails(IN_PROGRESS); + return new NodeSizeDetails(STATE.IN_PROGRESS.name()); } } diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index 8f41edd452c..c56273db18e 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -77,7 +77,8 @@ org.alfresco.repo.web.scripts.node.NodeWebScripTest.class, org.alfresco.rest.api.impl.CommentsImplUnitTest.class, org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, - org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class + org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, + org.alfresco.rest.api.impl.SizeDetailsImplTest.class }) public class AppContext04TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 946b2e18a84..2ae3a28c40d 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -47,7 +47,6 @@ import org.slf4j.LoggerFactory; import java.time.LocalTime; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java index fb85545e1f1..1cecf89df5b 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java @@ -105,8 +105,8 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) } catch (NumberFormatException numberFormatException) { - LOG.error("Exception occurred while parsing String to INT: {}", numberFormatException.getMessage()); - response.put(EXCEPTION,numberFormatException.getMessage()); + LOG.error("Exception occurred while parsing String to INT: {} ", numberFormatException.getMessage()); + response.put(EXCEPTION,"Exception occurred while parsing String to INT: {} " + numberFormatException.getMessage()); simpleCache.put(actionedUponNodeRef.getId(),response); throw numberFormatException; } @@ -160,8 +160,8 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) } catch (RuntimeException runtimeException) { - LOG.error("Exception occurred in NodeSizeDetailsActionExecutor:results {}", runtimeException.getMessage()); - response.put(EXCEPTION,runtimeException.getMessage()); + LOG.error("Exception occurred in NodeSizeDetailsActionExecutor:results {} ", runtimeException.getMessage()); + response.put(EXCEPTION,"Exception occurred in NodeSizeDetailsActionExecutor:results {} "+runtimeException.getMessage()); simpleCache.put(nodeRef.getId(),response); throw runtimeException; } From 385254bcbd93f5486eaf2cb91c281adaed075136 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 14:41:45 +0530 Subject: [PATCH 172/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/impl/SizeDetailsImplTest.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java new file mode 100644 index 00000000000..987d97702fe --- /dev/null +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -0,0 +1,109 @@ +/* + * #%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 org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutor; +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.model.Node; +import org.alfresco.rest.api.model.NodeSizeDetails; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.namespace.QName; +import org.junit.Before; +import org.junit.Test; + +import java.io.Serializable; +import java.util.Map; + +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Unit tests for {@link SizeDetailsImpl} class. + * + */ +public class SizeDetailsImplTest +{ + private final static int DEFAULT_ITEMS = 1000; + private SizeDetailsImpl sizeDetailsImpl; + private Nodes nodes; + private NodeService nodeService; + private ActionService actionService; + private SimpleCache> simpleCache; + private Action action; + private static final String NAMESPACE = "http://www.alfresco.org/test/NodeSizeDetailsTest"; + private static final QName TYPE_FOLDER = QName.createQName(NAMESPACE, "folder"); + + @Before + public void setUp() + { + sizeDetailsImpl = new SizeDetailsImpl(); + nodes = mock(Nodes.class); + nodeService = mock(NodeService.class); + PermissionService permissionService = mock(PermissionService.class); + actionService = mock(ActionService.class); + action = mock(Action.class); + simpleCache = mock(SimpleCache.class); + + sizeDetailsImpl.setNodes(nodes); + sizeDetailsImpl.setNodeService(nodeService); + sizeDetailsImpl.setPermissionService(permissionService); + sizeDetailsImpl.setActionService(actionService); + sizeDetailsImpl.setSimpleCache(simpleCache); + sizeDetailsImpl.setDefaultItems(DEFAULT_ITEMS); + } + + @Test + public void calculateNodeSize() + { + String nodeName = "folderNode"; + String nodeId = "node-id"; + NodeRef nodeRef = new NodeRef("protocol", "identifier", nodeId); + action.setTrackStatus(true); + action.setExecuteAsynchronously(true); + action.setParameterValue(NodeSizeDetailsActionExecutor.DEFAULT_SIZE, DEFAULT_ITEMS); + + Node node = new Node(); + node.setIsFolder(true); + node.setNodeRef(nodeRef); + node.setName(nodeName); + node.setNodeType(TYPE_FOLDER.getLocalName()); + node.setNodeId(nodeRef.getId()); + + when(nodes.validateNode(nodeId)).thenReturn(nodeRef); + when(nodes.getNode(nodeId)).thenReturn(node); + when(nodeService.getType(nodeRef)).thenReturn(TYPE_FOLDER); + when(actionService.createAction(NodeSizeDetailsActionExecutor.NAME)).thenReturn(action); + NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(nodeId); + assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",nodeSizeDetails); + } + +} From 2469ff3a1b11e72a04cb954d9379efd1040c871b Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 15:09:13 +0530 Subject: [PATCH 173/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/impl/SizeDetailsImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 7eaeda66499..079d0da03d7 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -52,9 +52,10 @@ public class SizeDetailsImpl implements SizeDetails { private enum STATE { - STATUS, NOT_INITIATED, IN_PROGRESS, COMPLETED; + NOT_INITIATED, IN_PROGRESS, COMPLETED; }; private static final Logger LOG = LoggerFactory.getLogger(SizeDetailsImpl.class); + private static final String STATUS = "status"; private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; private static final String FOLDER = "folder"; private Nodes nodes; @@ -126,7 +127,7 @@ public NodeSizeDetails calculateNodeSize(final String nodeId) private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache> simpleCache) { Map currentStatus = new HashMap<>(); - currentStatus.put(STATE.STATUS.name(),STATE.IN_PROGRESS.name()); + currentStatus.put(STATUS,STATE.IN_PROGRESS.name()); Action folderSizeAction = actionService.createAction(NodeSizeDetailsActionExecutor.NAME); folderSizeAction.setTrackStatus(true); From 6a8d9e076aa4cca98cdd03be5c46778196e34716 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 15:12:55 +0530 Subject: [PATCH 174/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java | 3 ++- .../java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 079d0da03d7..41dead6d73f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -53,7 +53,8 @@ public class SizeDetailsImpl implements SizeDetails private enum STATE { NOT_INITIATED, IN_PROGRESS, COMPLETED; - }; + } + private static final Logger LOG = LoggerFactory.getLogger(SizeDetailsImpl.class); private static final String STATUS = "status"; private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 987d97702fe..c7c98636b61 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -57,7 +57,6 @@ public class SizeDetailsImplTest private Nodes nodes; private NodeService nodeService; private ActionService actionService; - private SimpleCache> simpleCache; private Action action; private static final String NAMESPACE = "http://www.alfresco.org/test/NodeSizeDetailsTest"; private static final QName TYPE_FOLDER = QName.createQName(NAMESPACE, "folder"); @@ -71,7 +70,7 @@ public void setUp() PermissionService permissionService = mock(PermissionService.class); actionService = mock(ActionService.class); action = mock(Action.class); - simpleCache = mock(SimpleCache.class); + SimpleCache> simpleCache = mock(SimpleCache.class); sizeDetailsImpl.setNodes(nodes); sizeDetailsImpl.setNodeService(nodeService); From f86142ce18cae010a6c4fefefc8edc4131913520 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 17:50:51 +0530 Subject: [PATCH 175/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/SizeDetails.java | 5 +++++ .../alfresco/rest/api/impl/SizeDetailsImpl.java | 17 ++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java index 69434dc2014..921ce33b53b 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java @@ -29,5 +29,10 @@ public interface SizeDetails { + enum PROCESSING_STATE + { + NOT_INITIATED, IN_PROGRESS, COMPLETED; + } + NodeSizeDetails calculateNodeSize(String nodeId); } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 41dead6d73f..c8c24956579 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -48,13 +48,12 @@ import org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutor; +import static org.alfresco.rest.api.SizeDetails.PROCESSING_STATE.COMPLETED; +import static org.alfresco.rest.api.SizeDetails.PROCESSING_STATE.NOT_INITIATED; +import static org.alfresco.rest.api.SizeDetails.PROCESSING_STATE.IN_PROGRESS; + public class SizeDetailsImpl implements SizeDetails { - private enum STATE - { - NOT_INITIATED, IN_PROGRESS, COMPLETED; - } - private static final Logger LOG = LoggerFactory.getLogger(SizeDetailsImpl.class); private static final String STATUS = "status"; private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; @@ -128,7 +127,7 @@ public NodeSizeDetails calculateNodeSize(final String nodeId) private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache> simpleCache) { Map currentStatus = new HashMap<>(); - currentStatus.put(STATUS,STATE.IN_PROGRESS.name()); + currentStatus.put(STATUS,IN_PROGRESS.name()); Action folderSizeAction = actionService.createAction(NodeSizeDetailsActionExecutor.NAME); folderSizeAction.setTrackStatus(true); @@ -145,7 +144,7 @@ private NodeSizeDetails executorResultToSizeDetails(final Map res { if (result == null) { - return new NodeSizeDetails(STATE.NOT_INITIATED.name()); + return new NodeSizeDetails(NOT_INITIATED.name()); } else if(result.containsKey(NodeSizeDetailsActionExecutor.EXCEPTION)) { @@ -157,11 +156,11 @@ else if(result.containsKey(NodeSizeDetailsActionExecutor.EXCEPTION)) if (hasSizeKey) { - return new NodeSizeDetails((String) result.get("nodeId"), (Long) result.get("size"), (String) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), STATE.COMPLETED.name()); + return new NodeSizeDetails((String) result.get("nodeId"), (Long) result.get("size"), (String) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), COMPLETED.name()); } else { - return new NodeSizeDetails(STATE.IN_PROGRESS.name()); + return new NodeSizeDetails(IN_PROGRESS.name()); } } From d92f599d1686d664d8042d6b20765871073eae95 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 23 Aug 2024 18:13:11 +0530 Subject: [PATCH 176/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../src/main/java/org/alfresco/rest/api/SizeDetails.java | 2 +- .../java/org/alfresco/rest/api/impl/SizeDetailsImpl.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java index 921ce33b53b..db8ce749e9f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java @@ -29,7 +29,7 @@ public interface SizeDetails { - enum PROCESSING_STATE + enum PROCESSINGSTATE { NOT_INITIATED, IN_PROGRESS, COMPLETED; } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index c8c24956579..a55f2a859fd 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -48,9 +48,9 @@ import org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutor; -import static org.alfresco.rest.api.SizeDetails.PROCESSING_STATE.COMPLETED; -import static org.alfresco.rest.api.SizeDetails.PROCESSING_STATE.NOT_INITIATED; -import static org.alfresco.rest.api.SizeDetails.PROCESSING_STATE.IN_PROGRESS; +import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.COMPLETED; +import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.NOT_INITIATED; +import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.IN_PROGRESS; public class SizeDetailsImpl implements SizeDetails { From 7af7c29e0e0e66fc3a521c83d6600605b6386865 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 28 Aug 2024 14:31:41 +0530 Subject: [PATCH 177/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../api/{SizeDetails.java => SizeDetail.java} | 6 +-- ...zeDetailsImpl.java => SizeDetailImpl.java} | 37 +++++++++---------- ...deSizeDetails.java => NodeSizeDetail.java} | 10 ++--- .../rest/api/nodes/NodesEntityResource.java | 25 ++++++------- .../alfresco/public-rest-context.xml | 8 ++-- .../org/alfresco/AppContext02TestSuite.java | 4 +- .../org/alfresco/AppContext04TestSuite.java | 3 +- ...sImplTest.java => SizeDetailImplTest.java} | 32 ++++++++-------- .../rest/api/tests/AbstractBaseApiTest.java | 2 +- ...tailsTest.java => NodeSizeDetailTest.java} | 6 +-- ...java => NodeSizeDetailActionExecutor.java} | 12 +++--- .../alfresco/action-services-context.xml | 2 +- .../org/alfresco/AppContext01TestSuite.java | 4 +- ... => NodeSizeDetailActionExecutorTest.java} | 10 ++--- 14 files changed, 79 insertions(+), 82 deletions(-) rename remote-api/src/main/java/org/alfresco/rest/api/{SizeDetails.java => SizeDetail.java} (89%) rename remote-api/src/main/java/org/alfresco/rest/api/impl/{SizeDetailsImpl.java => SizeDetailImpl.java} (80%) rename remote-api/src/main/java/org/alfresco/rest/api/model/{NodeSizeDetails.java => NodeSizeDetail.java} (91%) rename remote-api/src/test/java/org/alfresco/rest/api/impl/{SizeDetailsImplTest.java => SizeDetailImplTest.java} (77%) rename remote-api/src/test/java/org/alfresco/rest/api/tests/{NodeSizeDetailsTest.java => NodeSizeDetailTest.java} (97%) rename repository/src/main/java/org/alfresco/repo/action/executer/{NodeSizeDetailsActionExecutor.java => NodeSizeDetailActionExecutor.java} (95%) rename repository/src/test/java/org/alfresco/repo/action/executer/{NodeSizeDetailsActionExecutorTest.java => NodeSizeDetailActionExecutorTest.java} (91%) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java similarity index 89% rename from remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java rename to remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java index db8ce749e9f..7e7915db4fd 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java @@ -25,14 +25,14 @@ */ package org.alfresco.rest.api; -import org.alfresco.rest.api.model.NodeSizeDetails; +import org.alfresco.rest.api.model.NodeSizeDetail; -public interface SizeDetails +public interface SizeDetail { enum PROCESSINGSTATE { NOT_INITIATED, IN_PROGRESS, COMPLETED; } - NodeSizeDetails calculateNodeSize(String nodeId); + NodeSizeDetail calculateNodeSize(String nodeId); } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java similarity index 80% rename from remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java rename to remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java index a55f2a859fd..573cd2a7e69 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java @@ -25,13 +25,14 @@ */ package org.alfresco.rest.api.impl; +import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutor; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.SizeDetails; +import org.alfresco.rest.api.SizeDetail; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.NodePermissions; -import org.alfresco.rest.api.model.NodeSizeDetails; +import org.alfresco.rest.api.model.NodeSizeDetail; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; @@ -46,15 +47,13 @@ import java.util.Map; import java.util.HashMap; -import org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutor; +import static org.alfresco.rest.api.SizeDetail.PROCESSINGSTATE.COMPLETED; +import static org.alfresco.rest.api.SizeDetail.PROCESSINGSTATE.NOT_INITIATED; +import static org.alfresco.rest.api.SizeDetail.PROCESSINGSTATE.IN_PROGRESS; -import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.COMPLETED; -import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.NOT_INITIATED; -import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.IN_PROGRESS; - -public class SizeDetailsImpl implements SizeDetails +public class SizeDetailImpl implements SizeDetail { - private static final Logger LOG = LoggerFactory.getLogger(SizeDetailsImpl.class); + private static final Logger LOG = LoggerFactory.getLogger(SizeDetailImpl.class); private static final String STATUS = "status"; private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; private static final String FOLDER = "folder"; @@ -100,7 +99,7 @@ public void setDefaultItems(int defaultItems) * HTTP STATUS 200 will provide the size details response from cache. */ @Override - public NodeSizeDetails calculateNodeSize(final String nodeId) + public NodeSizeDetail calculateNodeSize(final String nodeId) { NodeRef nodeRef = nodes.validateNode(nodeId); QName qName = nodeService.getType(nodeRef); @@ -118,7 +117,7 @@ public NodeSizeDetails calculateNodeSize(final String nodeId) } LOG.debug("Executing NodeSizeActionExecuter from calculateNodeSize method"); - return executorResultToSizeDetails(simpleCache.get(nodeRef.getId())); + return executorResultToSizeDetail(simpleCache.get(nodeRef.getId())); } /** @@ -129,10 +128,10 @@ private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache currentStatus = new HashMap<>(); currentStatus.put(STATUS,IN_PROGRESS.name()); - Action folderSizeAction = actionService.createAction(NodeSizeDetailsActionExecutor.NAME); + Action folderSizeAction = actionService.createAction(NodeSizeDetailActionExecutor.NAME); folderSizeAction.setTrackStatus(true); folderSizeAction.setExecuteAsynchronously(true); - folderSizeAction.setParameterValue(NodeSizeDetailsActionExecutor.DEFAULT_SIZE, defaultItems); + folderSizeAction.setParameterValue(NodeSizeDetailActionExecutor.DEFAULT_SIZE, defaultItems); simpleCache.put(nodeRef.getId(),currentStatus); actionService.executeAction(folderSizeAction, nodeRef, false, true); } @@ -140,15 +139,15 @@ private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache result) + private NodeSizeDetail executorResultToSizeDetail(final Map result) { if (result == null) { - return new NodeSizeDetails(NOT_INITIATED.name()); + return new NodeSizeDetail(NOT_INITIATED.name()); } - else if(result.containsKey(NodeSizeDetailsActionExecutor.EXCEPTION)) + else if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) { - return new NodeSizeDetails((String) result.get(NodeSizeDetailsActionExecutor.EXCEPTION)); + return new NodeSizeDetail((String) result.get(NodeSizeDetailActionExecutor.EXCEPTION)); } // Check for the presence of "size" key. @@ -156,11 +155,11 @@ else if(result.containsKey(NodeSizeDetailsActionExecutor.EXCEPTION)) if (hasSizeKey) { - return new NodeSizeDetails((String) result.get("nodeId"), (Long) result.get("size"), (String) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), COMPLETED.name()); + return new NodeSizeDetail((String) result.get("nodeId"), (Long) result.get("size"), (String) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), COMPLETED.name()); } else { - return new NodeSizeDetails(IN_PROGRESS.name()); + return new NodeSizeDetail(IN_PROGRESS.name()); } } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java similarity index 91% rename from remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java rename to remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java index 5fdf4c21537..f511a23e5b7 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java @@ -25,23 +25,23 @@ */ package org.alfresco.rest.api.model; -public class NodeSizeDetails +public class NodeSizeDetail { private String nodeId; private long size; private String calculatedAt; private int numberOfFiles; private String status; - public NodeSizeDetails() + public NodeSizeDetail() { super(); } - public NodeSizeDetails(String status) + public NodeSizeDetail(String status) { this.status = status; } - public NodeSizeDetails(String nodeId, long size, String calculatedAt, int numberOfFiles, String status) + public NodeSizeDetail(String nodeId, long size, String calculatedAt, int numberOfFiles, String status) { this.nodeId = nodeId; this.size = size; @@ -102,7 +102,7 @@ public void setStatus(String status) @Override public String toString() { - return "NodeSizeDetails{" + + return "NodeSizeDetail{" + "nodeId='" + nodeId + '\'' + ", size='" + size + '\'' + ", calculatedAt='" + calculatedAt + '\'' + diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index f56da30d76f..98571d06116 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -31,17 +31,14 @@ import org.alfresco.repo.content.directurl.DirectAccessUrlDisabledException; import org.alfresco.rest.api.DirectAccessUrlHelper; import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.model.DirectAccessUrlRequest; -import org.alfresco.rest.api.model.LockInfo; -import org.alfresco.rest.api.model.Node; -import org.alfresco.rest.api.model.NodeTarget; -import org.alfresco.rest.api.model.NodeSizeDetails; +import org.alfresco.rest.api.SizeDetail; +import org.alfresco.rest.api.model.*; +import org.alfresco.rest.api.model.NodeSizeDetail; import org.alfresco.rest.framework.BinaryProperties; import org.alfresco.rest.framework.Operation; import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.WebApiParameters; -import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.framework.core.ResourceParameter; import org.alfresco.rest.framework.core.exceptions.DisabledServiceException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; @@ -76,7 +73,7 @@ public class NodesEntityResource implements private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class); private Nodes nodes; private DirectAccessUrlHelper directAccessUrlHelper; - private SizeDetails sizeDetails; + private SizeDetail sizeDetail; public void setNodes(Nodes nodes) { @@ -88,9 +85,9 @@ public void setDirectAccessUrlHelper(DirectAccessUrlHelper directAccessUrlHelper this.directAccessUrlHelper = directAccessUrlHelper; } - public void setSizeDetails(SizeDetails sizeDetails) + public void setSizeDetails(SizeDetail sizeDetail) { - this.sizeDetails = sizeDetails; + this.sizeDetail = sizeDetail; } @Override @@ -249,13 +246,13 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq *

* If nodeId does not represent a folder, InvalidNodeTypeException (status 422). */ - @Operation("request-size-details") + @Operation("request-size-detail") @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder node",successStatus = Status.STATUS_ACCEPTED) @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id", description = "A single nodeId")}) - public NodeSizeDetails calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) + public NodeSizeDetail calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) { - NodeSizeDetails nodeSizeDetails = sizeDetails.calculateNodeSize(nodeId); - if(nodeSizeDetails == null) + NodeSizeDetail nodeSizeDetail = sizeDetail.calculateNodeSize(nodeId); + if(nodeSizeDetail == null) { withResponse.setStatus(Status.STATUS_ACCEPTED); } @@ -263,7 +260,7 @@ public NodeSizeDetails calculateFolderSize(String nodeId, Void ignore, Parameter { withResponse.setStatus(Status.STATUS_OK); } - return nodeSizeDetails; + return nodeSizeDetail; } } \ No newline at end of file diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 8e8a321c078..afba8298b17 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -996,7 +996,7 @@ - + @@ -1007,10 +1007,10 @@ - org.alfresco.rest.api.SizeDetails + org.alfresco.rest.api.SizeDetail - + @@ -1171,7 +1171,7 @@ - + diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 2b097a6e05f..4891cf6f6d2 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -25,7 +25,7 @@ */ package org.alfresco; -import org.alfresco.rest.api.tests.NodeSizeDetailsTest; +import org.alfresco.rest.api.tests.NodeSizeDetailTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; @@ -77,7 +77,7 @@ org.alfresco.rest.api.tests.BufferedResponseTest.class, org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, - org.alfresco.rest.api.tests.NodeSizeDetailsTest.class + NodeSizeDetailTest.class }) public class AppContext02TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index c56273db18e..2a00ff2722a 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -26,6 +26,7 @@ package org.alfresco; import org.alfresco.repo.web.scripts.TestWebScriptRepoServer; +import org.alfresco.rest.api.impl.SizeDetailImplTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; @@ -78,7 +79,7 @@ org.alfresco.rest.api.impl.CommentsImplUnitTest.class, org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, - org.alfresco.rest.api.impl.SizeDetailsImplTest.class + SizeDetailImplTest.class }) public class AppContext04TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java similarity index 77% rename from remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java rename to remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java index c7c98636b61..266174e2e7e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java @@ -25,11 +25,11 @@ */ package org.alfresco.rest.api.impl; -import org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutor; +import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutor; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; -import org.alfresco.rest.api.model.NodeSizeDetails; +import org.alfresco.rest.api.model.NodeSizeDetail; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.NodeRef; @@ -47,13 +47,13 @@ import static org.mockito.Mockito.when; /** - * Unit tests for {@link SizeDetailsImpl} class. + * Unit tests for {@link SizeDetailImpl} class. * */ -public class SizeDetailsImplTest +public class SizeDetailImplTest { private final static int DEFAULT_ITEMS = 1000; - private SizeDetailsImpl sizeDetailsImpl; + private SizeDetailImpl sizeDetailImpl; private Nodes nodes; private NodeService nodeService; private ActionService actionService; @@ -64,7 +64,7 @@ public class SizeDetailsImplTest @Before public void setUp() { - sizeDetailsImpl = new SizeDetailsImpl(); + sizeDetailImpl = new SizeDetailImpl(); nodes = mock(Nodes.class); nodeService = mock(NodeService.class); PermissionService permissionService = mock(PermissionService.class); @@ -72,12 +72,12 @@ public void setUp() action = mock(Action.class); SimpleCache> simpleCache = mock(SimpleCache.class); - sizeDetailsImpl.setNodes(nodes); - sizeDetailsImpl.setNodeService(nodeService); - sizeDetailsImpl.setPermissionService(permissionService); - sizeDetailsImpl.setActionService(actionService); - sizeDetailsImpl.setSimpleCache(simpleCache); - sizeDetailsImpl.setDefaultItems(DEFAULT_ITEMS); + sizeDetailImpl.setNodes(nodes); + sizeDetailImpl.setNodeService(nodeService); + sizeDetailImpl.setPermissionService(permissionService); + sizeDetailImpl.setActionService(actionService); + sizeDetailImpl.setSimpleCache(simpleCache); + sizeDetailImpl.setDefaultItems(DEFAULT_ITEMS); } @Test @@ -88,7 +88,7 @@ public void calculateNodeSize() NodeRef nodeRef = new NodeRef("protocol", "identifier", nodeId); action.setTrackStatus(true); action.setExecuteAsynchronously(true); - action.setParameterValue(NodeSizeDetailsActionExecutor.DEFAULT_SIZE, DEFAULT_ITEMS); + action.setParameterValue(NodeSizeDetailActionExecutor.DEFAULT_SIZE, DEFAULT_ITEMS); Node node = new Node(); node.setIsFolder(true); @@ -100,9 +100,9 @@ public void calculateNodeSize() when(nodes.validateNode(nodeId)).thenReturn(nodeRef); when(nodes.getNode(nodeId)).thenReturn(node); when(nodeService.getType(nodeRef)).thenReturn(TYPE_FOLDER); - when(actionService.createAction(NodeSizeDetailsActionExecutor.NAME)).thenReturn(action); - NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.calculateNodeSize(nodeId); - assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",nodeSizeDetails); + when(actionService.createAction(NodeSizeDetailActionExecutor.NAME)).thenReturn(action); + NodeSizeDetail nodeSizeDetail = sizeDetailImpl.calculateNodeSize(nodeId); + assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code", nodeSizeDetail); } } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index 66c0988397c..00e478bb2c7 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -105,7 +105,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi private static final String URL_CHILDREN = "children"; private static final String URL_CONTENT = "content"; - private static final String URL_CALCULATEFOLDERSIZE = "request-size-details"; + private static final String URL_CALCULATEFOLDERSIZE = "request-size-detail"; protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java similarity index 97% rename from remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java rename to remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java index 2ae3a28c40d..9d96e17d47e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java @@ -62,9 +62,9 @@ */ @FixMethodOrder (MethodSorters.NAME_ASCENDING) @RunWith (JUnit4.class) -public class NodeSizeDetailsTest extends AbstractBaseApiTest +public class NodeSizeDetailTest extends AbstractBaseApiTest { - private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsTest.class); + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailTest.class); private Site userOneN1Site; private String folderId; @@ -92,7 +92,7 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType) } catch (Exception e) { - LOG.error("Exception occured in NodeSizeDetailsTest:addToDocumentLibrary {}", e.getMessage()); + LOG.error("Exception occured in NodeSizeDetailTest:addToDocumentLibrary {}", e.getMessage()); } return null; } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java similarity index 95% rename from repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java rename to repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java index 1cecf89df5b..a7353fcfc4b 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutor.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java @@ -49,14 +49,14 @@ import java.util.concurrent.atomic.AtomicLong; /** - * NodeSizeDetailsActionExecutor + * NodeSizeDetailActionExecutor * Executing Alfresco FTS Query to find size of Folder Node */ -public class NodeSizeDetailsActionExecutor extends ActionExecuterAbstractBase +public class NodeSizeDetailActionExecutor extends ActionExecuterAbstractBase { - private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsActionExecutor.class); + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailActionExecutor.class); /** * Action constants @@ -160,13 +160,13 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) } catch (RuntimeException runtimeException) { - LOG.error("Exception occurred in NodeSizeDetailsActionExecutor:results {} ", runtimeException.getMessage()); - response.put(EXCEPTION,"Exception occurred in NodeSizeDetailsActionExecutor:results {} "+runtimeException.getMessage()); + LOG.error("Exception occurred in NodeSizeDetailActionExecutor:results {} ", runtimeException.getMessage()); + response.put(EXCEPTION,"Exception occurred in NodeSizeDetailActionExecutor:results {} "+runtimeException.getMessage()); simpleCache.put(nodeRef.getId(),response); throw runtimeException; } - LOG.debug(" Calculating size of Folder Node - NodeSizeDetailsActionExecutor:executeImpl "); + LOG.debug(" Calculating size of Folder Node - NodeSizeDetailActionExecutor:executeImpl "); final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); String formattedTimestamp = eventTimestamp.format(formatter); diff --git a/repository/src/main/resources/alfresco/action-services-context.xml b/repository/src/main/resources/alfresco/action-services-context.xml index 21435fdfc54..506974d2715 100644 --- a/repository/src/main/resources/alfresco/action-services-context.xml +++ b/repository/src/main/resources/alfresco/action-services-context.xml @@ -789,7 +789,7 @@ - + diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index e210648ca48..1fd24968009 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -25,7 +25,7 @@ */ package org.alfresco; -import org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest; +import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutorTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; @@ -79,7 +79,7 @@ org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, - org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest.class + NodeSizeDetailActionExecutorTest.class }) public class AppContext01TestSuite { diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutorTest.java similarity index 91% rename from repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java rename to repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutorTest.java index 17f8dabc805..c4c2cd58538 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutorTest.java @@ -43,7 +43,7 @@ import org.springframework.transaction.annotation.Transactional; @Transactional -public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest +public class NodeSizeDetailActionExecutorTest extends BaseSpringTest { /** * The test node reference @@ -53,7 +53,7 @@ public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest /** * The folder Size executer */ - private NodeSizeDetailsActionExecutor executer; + private NodeSizeDetailActionExecutor executer; /** * Id used to identify the test action created @@ -93,7 +93,7 @@ public void before() throws Exception ContentModel.TYPE_CONTENT).getChildRef(); // Get the executer instance. - this.executer = (NodeSizeDetailsActionExecutor)this.applicationContext.getBean(NodeSizeDetailsActionExecutor.NAME); + this.executer = (NodeSizeDetailActionExecutor)this.applicationContext.getBean(NodeSizeDetailActionExecutor.NAME); simpleCache = (SimpleCache>) this.applicationContext.getBean("folderSizeSharedCache"); } @@ -105,8 +105,8 @@ public void before() throws Exception public void testExecution() { int maxItems = 1000; - ActionImpl action = new ActionImpl(null, ID, NodeSizeDetailsActionExecutor.NAME, null); - action.setParameterValue(NodeSizeDetailsActionExecutor.DEFAULT_SIZE, maxItems); + ActionImpl action = new ActionImpl(null, ID, NodeSizeDetailActionExecutor.NAME, null); + action.setParameterValue(NodeSizeDetailActionExecutor.DEFAULT_SIZE, maxItems); this.executer.executeImpl(action, this.nodeRef); Object resultAction = simpleCache.get(this.nodeRef.getId()); Map mapResult = (Map)resultAction; From fed54a3252eedcfa1d8a55afccd53f788c155a48 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 28 Aug 2024 15:35:21 +0530 Subject: [PATCH 178/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/rest/api/impl/SizeDetailImpl.java | 2 +- .../alfresco/rest/api/nodes/NodesEntityResource.java | 2 +- .../main/resources/alfresco/public-rest-context.xml | 2 +- .../org/alfresco/rest/api/impl/SizeDetailImplTest.java | 2 +- .../alfresco/rest/api/tests/NodeSizeDetailTest.java | 10 +++++----- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java index 573cd2a7e69..441c7e123c4 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java @@ -116,7 +116,7 @@ public NodeSizeDetail calculateNodeSize(final String nodeId) return null; } - LOG.debug("Executing NodeSizeActionExecuter from calculateNodeSize method"); + LOG.debug("Executing NodeSizeDetailActionExecuter from calculateNodeSize method"); return executorResultToSizeDetail(simpleCache.get(nodeRef.getId())); } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 98571d06116..a12af4ef7e9 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -85,7 +85,7 @@ public void setDirectAccessUrlHelper(DirectAccessUrlHelper directAccessUrlHelper this.directAccessUrlHelper = directAccessUrlHelper; } - public void setSizeDetails(SizeDetail sizeDetail) + public void setSizeDetail(SizeDetail sizeDetail) { this.sizeDetail = sizeDetail; } diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index afba8298b17..5edbfbf883b 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1005,7 +1005,7 @@ - + org.alfresco.rest.api.SizeDetail diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java index 266174e2e7e..0a9f8f1d106 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java @@ -102,7 +102,7 @@ public void calculateNodeSize() when(nodeService.getType(nodeRef)).thenReturn(TYPE_FOLDER); when(actionService.createAction(NodeSizeDetailActionExecutor.NAME)).thenReturn(action); NodeSizeDetail nodeSizeDetail = sizeDetailImpl.calculateNodeSize(nodeId); - assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code", nodeSizeDetail); + assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code", nodeSizeDetail); } } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java index 9d96e17d47e..59318fe6ff6 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java @@ -92,7 +92,7 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType) } catch (Exception e) { - LOG.error("Exception occured in NodeSizeDetailTest:addToDocumentLibrary {}", e.getMessage()); + LOG.error("Exception occurred in NodeSizeDetailTest:addToDocumentLibrary {}", e.getMessage()); } return null; } @@ -115,8 +115,8 @@ public void setup() throws Exception } /** - * Test case for POST/request-size-details, which calculates and retrieve size of a folder. - * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//request-size-details} + * Test case for POST/request-size-detail, which calculates and retrieve size of a folder. + * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//request-size-detail} */ @Test public void testPostAndGetFolderSize() throws Exception @@ -129,7 +129,7 @@ public void testPostAndGetFolderSize() throws Exception // Perform POST request HttpResponse postResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); - assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",postResponse.getJsonResponse()); + assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code",postResponse.getJsonResponse()); HttpResponse getResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); @@ -178,7 +178,7 @@ public void testPerformanceTesting() throws Exception // Perform POST request HttpResponse postResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 202); - assertNull("After executing POST/request-size-details first time, it will provide null with 202 status code",postResponse.getJsonResponse()); + assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code",postResponse.getJsonResponse()); HttpResponse getResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 200); From a9901ef9e7795b09a98f575a4f7791b8bbaed5d2 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 28 Aug 2024 16:09:24 +0530 Subject: [PATCH 179/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../src/main/resources/alfresco/public-rest-context.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 5edbfbf883b..54f93803f44 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -996,7 +996,7 @@ - + @@ -1010,7 +1010,7 @@ org.alfresco.rest.api.SizeDetail - + @@ -1171,7 +1171,7 @@ - + From a9bae635fa999872e73127346c3e78d4e50f7412 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 28 Aug 2024 16:58:06 +0530 Subject: [PATCH 180/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/nodes/NodesEntityResource.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index a12af4ef7e9..3dda6c5814b 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -251,16 +251,17 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id", description = "A single nodeId")}) public NodeSizeDetail calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) { - NodeSizeDetail nodeSizeDetail = sizeDetail.calculateNodeSize(nodeId); - if(nodeSizeDetail == null) - { - withResponse.setStatus(Status.STATUS_ACCEPTED); - } - else - { - withResponse.setStatus(Status.STATUS_OK); - } - return nodeSizeDetail; + LOG.debug(" Executing calculateFolderSize method "); + NodeSizeDetail nodeSizeDetail = sizeDetail.calculateNodeSize(nodeId); + if(nodeSizeDetail == null) + { + withResponse.setStatus(Status.STATUS_ACCEPTED); + } + else + { + withResponse.setStatus(Status.STATUS_OK); + } + return nodeSizeDetail; } } \ No newline at end of file From a31adb16a92238cc2bfbf3a9473d9ad6ddbc0ecd Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 28 Aug 2024 17:27:20 +0530 Subject: [PATCH 181/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/rest/api/nodes/NodesEntityResource.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 3dda6c5814b..df9a58a6767 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -31,9 +31,12 @@ import org.alfresco.repo.content.directurl.DirectAccessUrlDisabledException; import org.alfresco.rest.api.DirectAccessUrlHelper; import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.SizeDetail; -import org.alfresco.rest.api.model.*; +import org.alfresco.rest.api.model.DirectAccessUrlRequest; +import org.alfresco.rest.api.model.LockInfo; +import org.alfresco.rest.api.model.Node; +import org.alfresco.rest.api.model.NodeTarget; import org.alfresco.rest.api.model.NodeSizeDetail; +import org.alfresco.rest.api.SizeDetail; import org.alfresco.rest.framework.BinaryProperties; import org.alfresco.rest.framework.Operation; import org.alfresco.rest.framework.WebApiDescription; From a747e7b104ad4d913a2444a08fc6eee3416f7cc9 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 28 Aug 2024 17:33:46 +0530 Subject: [PATCH 182/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../src/test/java/org/alfresco/AppContext02TestSuite.java | 2 +- .../src/test/java/org/alfresco/AppContext04TestSuite.java | 2 +- .../java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java | 2 +- .../src/test/java/org/alfresco/AppContext01TestSuite.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 4891cf6f6d2..63a45a9b05c 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -77,7 +77,7 @@ org.alfresco.rest.api.tests.BufferedResponseTest.class, org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, - NodeSizeDetailTest.class + org.alfresco.rest.api.tests.NodeSizeDetailTest.class }) public class AppContext02TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index 2a00ff2722a..4668add2eb3 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -79,7 +79,7 @@ org.alfresco.rest.api.impl.CommentsImplUnitTest.class, org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, - SizeDetailImplTest.class + org.alfresco.rest.api.impl.SizeDetailImplTest.class }) public class AppContext04TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index 00e478bb2c7..d4e383eb493 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2023 Alfresco Software Limited + * 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 diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index 1fd24968009..b342c42220e 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -79,7 +79,7 @@ org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, - NodeSizeDetailActionExecutorTest.class + org.alfresco.repo.action.executer.NodeSizeDetailActionExecutorTest.class }) public class AppContext01TestSuite { From 2da3ce6c15ef84fa1448aa17efc2c63a7d1edec0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 30 Aug 2024 13:32:48 +0530 Subject: [PATCH 183/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/impl/SizeDetailImpl.java | 2 +- .../rest/api/model/NodeSizeDetail.java | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java index 441c7e123c4..a34a0215271 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java @@ -147,7 +147,7 @@ private NodeSizeDetail executorResultToSizeDetail(final Map resul } else if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) { - return new NodeSizeDetail((String) result.get(NodeSizeDetailActionExecutor.EXCEPTION)); + return new NodeSizeDetail((String) result.get("nodeId"), 0L, 0, COMPLETED.name()); } // Check for the presence of "size" key. diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java index f511a23e5b7..140ebb6cd5b 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java @@ -28,19 +28,24 @@ public class NodeSizeDetail { private String nodeId; - private long size; + private Long size; private String calculatedAt; - private int numberOfFiles; + private Integer numberOfFiles; private String status; - public NodeSizeDetail() + + public NodeSizeDetail(String status) { - super(); + this.status = status; } - public NodeSizeDetail(String status) + public NodeSizeDetail(String nodeId, Long size, Integer numberOfFiles, String status) { + this.nodeId = nodeId; + this.size = size; + this.numberOfFiles = numberOfFiles; this.status = status; } + public NodeSizeDetail(String nodeId, long size, String calculatedAt, int numberOfFiles, String status) { this.nodeId = nodeId; @@ -60,12 +65,12 @@ public void setNodeId(String nodeId) this.nodeId = nodeId; } - public long getSize() + public Long getSize() { return size; } - public void setSize(long size) + public void setSize(Long size) { this.size = size; } @@ -80,12 +85,12 @@ public void setCalculatedAt(String calculatedAt) this.calculatedAt = calculatedAt; } - public int getNumberOfFiles() + public Integer getNumberOfFiles() { return numberOfFiles; } - public void setNumberOfFiles(int numberOfFiles) + public void setNumberOfFiles(Integer numberOfFiles) { this.numberOfFiles = numberOfFiles; } From 9782555d060c1c6a8c3a959c4d4d5c2a3ef20c00 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 2 Sep 2024 15:18:11 +0530 Subject: [PATCH 184/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../alfresco/rest/api/impl/SizeDetailImpl.java | 6 +++--- .../alfresco/rest/api/model/NodeSizeDetail.java | 15 +-------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java index a34a0215271..7dc4f832ee9 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java @@ -143,11 +143,11 @@ private NodeSizeDetail executorResultToSizeDetail(final Map resul { if (result == null) { - return new NodeSizeDetail(NOT_INITIATED.name()); + return new NodeSizeDetail(null, null, null, null, NOT_INITIATED.name()); } else if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) { - return new NodeSizeDetail((String) result.get("nodeId"), 0L, 0, COMPLETED.name()); + return new NodeSizeDetail(null, 0L, null, 0, COMPLETED.name()); } // Check for the presence of "size" key. @@ -159,7 +159,7 @@ else if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) } else { - return new NodeSizeDetail(IN_PROGRESS.name()); + return new NodeSizeDetail(null, null, null, null, IN_PROGRESS.name()); } } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java index 140ebb6cd5b..55c9ca33d7f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java @@ -33,20 +33,7 @@ public class NodeSizeDetail private Integer numberOfFiles; private String status; - public NodeSizeDetail(String status) - { - this.status = status; - } - - public NodeSizeDetail(String nodeId, Long size, Integer numberOfFiles, String status) - { - this.nodeId = nodeId; - this.size = size; - this.numberOfFiles = numberOfFiles; - this.status = status; - } - - public NodeSizeDetail(String nodeId, long size, String calculatedAt, int numberOfFiles, String status) + public NodeSizeDetail(String nodeId, Long size, String calculatedAt, Integer numberOfFiles, String status) { this.nodeId = nodeId; this.size = size; From a620e9114fada0b9d04f42a5914bd6199613f7eb Mon Sep 17 00:00:00 2001 From: kshah Date: Wed, 4 Sep 2024 01:50:09 +0530 Subject: [PATCH 185/267] Changes as per the Relationship Api Framework implementation. --- .../org/alfresco/rest/api/SizeDetail.java | 3 +- .../rest/api/impl/SizeDetailImpl.java | 76 ++++++++++----- .../rest/api/model/NodeSizeDetail.java | 35 ++++++- .../api/nodes/NodeSizeDetailsRelation.java | 92 +++++++++++++++++++ .../rest/api/nodes/NodesEntityResource.java | 45 +-------- .../alfresco/public-rest-context.xml | 6 +- .../rest/api/impl/SizeDetailImplTest.java | 2 +- .../NodeSizeDetailActionExecutor.java | 1 + 8 files changed, 187 insertions(+), 73 deletions(-) create mode 100644 remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java index 7e7915db4fd..5d264577da6 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java @@ -34,5 +34,6 @@ enum PROCESSINGSTATE NOT_INITIATED, IN_PROGRESS, COMPLETED; } - NodeSizeDetail calculateNodeSize(String nodeId); + NodeSizeDetail generateNodeSizeDetailsRequest(String nodeId); + NodeSizeDetail getNodeSizeDetails(String nodeId, String jobId); } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java index 7dc4f832ee9..cd870e4899d 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java @@ -34,6 +34,7 @@ import org.alfresco.rest.api.model.NodePermissions; import org.alfresco.rest.api.model.NodeSizeDetail; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; +import org.alfresco.rest.framework.core.exceptions.UnprocessableContentException; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.NodeService; @@ -55,7 +56,9 @@ public class SizeDetailImpl implements SizeDetail { private static final Logger LOG = LoggerFactory.getLogger(SizeDetailImpl.class); private static final String STATUS = "status"; + private static final String ACTIONID = "actionId"; private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; + private static final String INVALID_JOBID = "Invalid parameter: value of jobId is invalid"; private static final String FOLDER = "folder"; private Nodes nodes; private NodeService nodeService; @@ -94,60 +97,65 @@ public void setDefaultItems(int defaultItems) this.defaultItems = defaultItems; } + @Override + public NodeSizeDetail generateNodeSizeDetailsRequest(String nodeId) { + NodeRef nodeRef = nodes.validateNode(nodeId); + validateType(nodeRef); + String actionId; + if(simpleCache.get(nodeId) == null) + { + actionId = executeAction(nodeRef, defaultItems, simpleCache); + } else { + Map result = simpleCache.get(nodeRef.getId()); + actionId = (String)result.get(ACTIONID); + } + return new NodeSizeDetail(actionId); + } + /** * calculateNodeSize : providing HTTP STATUS 202 which signifies REQUEST ACCEPTED. * HTTP STATUS 200 will provide the size details response from cache. */ @Override - public NodeSizeDetail calculateNodeSize(final String nodeId) + public NodeSizeDetail getNodeSizeDetails(final String nodeId, final String jobId) { NodeRef nodeRef = nodes.validateNode(nodeId); - QName qName = nodeService.getType(nodeRef); - validatePermissions(nodeRef, nodeId); + validateType(nodeRef); - if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) - { - throw new InvalidNodeTypeException(INVALID_NODEID); - } - - if(simpleCache.get(nodeRef.getId()) == null) + if(simpleCache.get(nodeId) == null) { - executeAction(nodeRef, defaultItems, simpleCache); - return null; + return new NodeSizeDetail(nodeId, NOT_INITIATED.name()); } LOG.debug("Executing NodeSizeDetailActionExecuter from calculateNodeSize method"); - return executorResultToSizeDetail(simpleCache.get(nodeRef.getId())); + return executorResultToSizeDetail(simpleCache.get(nodeId), nodeId, jobId); } /** * Executing Action Asynchronously. */ - private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache> simpleCache) + private String executeAction(NodeRef nodeRef, int defaultItems, SimpleCache> simpleCache) { Map currentStatus = new HashMap<>(); currentStatus.put(STATUS,IN_PROGRESS.name()); - Action folderSizeAction = actionService.createAction(NodeSizeDetailActionExecutor.NAME); + currentStatus.put(ACTIONID,folderSizeAction.getId()); folderSizeAction.setTrackStatus(true); folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeDetailActionExecutor.DEFAULT_SIZE, defaultItems); simpleCache.put(nodeRef.getId(),currentStatus); actionService.executeAction(folderSizeAction, nodeRef, false, true); + return folderSizeAction.getId(); } /** * Converting action executor response to their respective model class. */ - private NodeSizeDetail executorResultToSizeDetail(final Map result) + private NodeSizeDetail executorResultToSizeDetail(final Map result, String nodeId, String jobId) { - if (result == null) + if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) { - return new NodeSizeDetail(null, null, null, null, NOT_INITIATED.name()); - } - else if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) - { - return new NodeSizeDetail(null, 0L, null, 0, COMPLETED.name()); + return new NodeSizeDetail(nodeId, COMPLETED.name()); } // Check for the presence of "size" key. @@ -155,11 +163,31 @@ else if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) if (hasSizeKey) { - return new NodeSizeDetail((String) result.get("nodeId"), (Long) result.get("size"), (String) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), COMPLETED.name()); + NodeSizeDetail nodeSizeDetail = new NodeSizeDetail((String) result.get("nodeId"), + (Long) result.get("size"), + (String) result.get("calculatedAt"), + (Integer) result.get("numberOfFiles"), + COMPLETED.name(), + (String) result.get(ACTIONID)); + + if(!nodeSizeDetail.getJobId().equalsIgnoreCase(jobId)) { + throw new UnprocessableContentException(INVALID_JOBID); + } + return nodeSizeDetail; } else { - return new NodeSizeDetail(null, null, null, null, IN_PROGRESS.name()); + return new NodeSizeDetail(nodeId, IN_PROGRESS.name()); + } + } + + private void validateType(NodeRef nodeRef) throws InvalidNodeTypeException + { + QName qName = nodeService.getType(nodeRef); + validatePermissions(nodeRef, nodeRef.getId()); + if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) + { + throw new InvalidNodeTypeException(INVALID_NODEID); } } @@ -170,12 +198,10 @@ private void validatePermissions(NodeRef nodeRef, String nodeId) { Node nodeInfo = nodes.getNode(nodeId); NodePermissions nodePerms = nodeInfo.getPermissions(); - // Validate permissions. if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) { throw new AccessDeniedException("permissions.err_access_denied"); } } - } \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java index 55c9ca33d7f..a019f2ffdba 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java @@ -25,6 +25,8 @@ */ package org.alfresco.rest.api.model; +import java.util.Objects; + public class NodeSizeDetail { private String nodeId; @@ -32,14 +34,25 @@ public class NodeSizeDetail private String calculatedAt; private Integer numberOfFiles; private String status; + private String jobId; + + public NodeSizeDetail(String jobId) { + this.jobId = jobId; + } + + public NodeSizeDetail(String nodeId, String status) { + this.nodeId = nodeId; + this.status = status; + } - public NodeSizeDetail(String nodeId, Long size, String calculatedAt, Integer numberOfFiles, String status) + public NodeSizeDetail(String nodeId, Long size, String calculatedAt, Integer numberOfFiles, String status, String jobId) { this.nodeId = nodeId; this.size = size; this.calculatedAt = calculatedAt; this.numberOfFiles = numberOfFiles; this.status = status; + this.jobId = jobId; } public String getNodeId() @@ -92,14 +105,32 @@ public void setStatus(String status) this.status = status; } + public String getJobId() { return jobId; } + + public void setJobId(String jobId) { this.jobId = jobId; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NodeSizeDetail that = (NodeSizeDetail) o; + return Objects.equals(nodeId, that.nodeId) && Objects.equals(size, that.size) && Objects.equals(calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) && Objects.equals(status, that.status) && Objects.equals(jobId, that.jobId); + } + + @Override + public int hashCode() { + return Objects.hash(nodeId, size, calculatedAt, numberOfFiles, status, jobId); + } + @Override public String toString() { return "NodeSizeDetail{" + "nodeId='" + nodeId + '\'' + - ", size='" + size + '\'' + + ", size=" + size + ", calculatedAt='" + calculatedAt + '\'' + ", numberOfFiles=" + numberOfFiles + ", status='" + status + '\'' + + ", jobId='" + jobId + '\'' + '}'; } } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java new file mode 100644 index 00000000000..00f3f014f24 --- /dev/null +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -0,0 +1,92 @@ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2023 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.nodes; + +import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.SizeDetail; +import org.alfresco.rest.api.model.NodeSizeDetail; +import org.alfresco.rest.framework.WebApiDescription; +import org.alfresco.rest.framework.WebApiParam; +import org.alfresco.rest.framework.WebApiParameters; +import org.alfresco.rest.framework.core.ResourceParameter; +import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException; +import org.alfresco.rest.framework.resource.RelationshipResource; +import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; +import org.alfresco.rest.framework.resource.parameters.Parameters; +import org.alfresco.util.ParameterCheck; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.extensions.webscripts.Status; +import java.util.Arrays; +import java.util.List; + +@RelationshipResource(name = "size-details", entityResource = NodesEntityResource.class, title = "Node Size Details") +public class NodeSizeDetailsRelation implements + RelationshipResourceAction.ReadById, + RelationshipResourceAction.Create, + InitializingBean { + + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsRelation.class); + private Nodes nodes; + private SizeDetail sizeDetail; + + public void setNodes(Nodes nodes) + { + this.nodes = nodes; + } + + public void setSizeDetail(SizeDetail sizeDetail) + { + this.sizeDetail = sizeDetail; + } + + @Override + public void afterPropertiesSet() + { + ParameterCheck.mandatory("nodes", this.nodes); + } + + @WebApiDescription(title = "Create node-size details request", successStatus = Status.STATUS_ACCEPTED) + @WebApiParam(name="nodeSizeEntity", title="Node Size Details Request", description="Request for processing Node Size.", + kind= ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple=false) + @Override + public List create(String nodeId, List nodeSizeEntity, Parameters parameters) { + LOG.debug(" Executing generateNodeSizeDetailsRequest method "); + return Arrays.asList(sizeDetail.generateNodeSizeDetailsRequest(nodeId)); + } + + @WebApiDescription(title = "Get Node Size Details", description = "Get the Node Size Details") + @WebApiParameters({ + @WebApiParam(name="nodeId", title="The unique id of the Node being addressed", description="A single node id"), + @WebApiParam(name="jobId", title="Job Id to get the NodeSizeDetails", description="JobId")}) + @Override + public NodeSizeDetail readById(String nodeId, String jobId, Parameters parameters) throws RelationshipResourceNotFoundException { + LOG.debug(" Executing getNodeSizeDetails method "); + return sizeDetail.getNodeSizeDetails(nodeId,jobId); + } +} diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index df9a58a6767..89338921cf0 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2024 Alfresco Software Limited + * Copyright (C) 2005 - 2023 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -35,13 +35,10 @@ import org.alfresco.rest.api.model.LockInfo; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.NodeTarget; -import org.alfresco.rest.api.model.NodeSizeDetail; -import org.alfresco.rest.api.SizeDetail; import org.alfresco.rest.framework.BinaryProperties; import org.alfresco.rest.framework.Operation; import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; -import org.alfresco.rest.framework.WebApiParameters; import org.alfresco.rest.framework.core.ResourceParameter; import org.alfresco.rest.framework.core.exceptions.DisabledServiceException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; @@ -56,10 +53,7 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.util.ParameterCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; -import org.springframework.extensions.webscripts.Status; /** * An implementation of an Entity Resource for a Node (file or folder) @@ -73,10 +67,8 @@ public class NodesEntityResource implements EntityResourceAction.ReadById, EntityResourceAction.Delete, EntityResourceAction.Update, BinaryResourceAction.Read, BinaryResourceAction.Update, InitializingBean { - private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class); private Nodes nodes; private DirectAccessUrlHelper directAccessUrlHelper; - private SizeDetail sizeDetail; public void setNodes(Nodes nodes) { @@ -88,11 +80,6 @@ public void setDirectAccessUrlHelper(DirectAccessUrlHelper directAccessUrlHelper this.directAccessUrlHelper = directAccessUrlHelper; } - public void setSizeDetail(SizeDetail sizeDetail) - { - this.sizeDetail = sizeDetail; - } - @Override public void afterPropertiesSet() { @@ -238,33 +225,5 @@ public DirectAccessUrl requestContentDirectUrl(String nodeId, DirectAccessUrlReq } return directAccessUrl; } +} - /** - * Folder Size - returns size details of a folder. - * - * @param nodeId String id of folder - will also accept well-known alias, eg. -root- or -my- or -shared- - * Please refer to OpenAPI spec for more details ! - * Returns the response message i.e. Request has been acknowledged with 202 - * Also, size-details endpoint to check if the action's status has been completed, comprising the size of the node in bytes. - *

- * If nodeId does not represent a folder, InvalidNodeTypeException (status 422). - */ - @Operation("request-size-detail") - @WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder node",successStatus = Status.STATUS_ACCEPTED) - @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id", description = "A single nodeId")}) - public NodeSizeDetail calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse) - { - LOG.debug(" Executing calculateFolderSize method "); - NodeSizeDetail nodeSizeDetail = sizeDetail.calculateNodeSize(nodeId); - if(nodeSizeDetail == null) - { - withResponse.setStatus(Status.STATUS_ACCEPTED); - } - else - { - withResponse.setStatus(Status.STATUS_OK); - } - return nodeSizeDetail; - } - -} \ No newline at end of file diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 54f93803f44..bddbe2630c5 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1171,7 +1171,6 @@ - @@ -1794,4 +1793,9 @@ + + + + + diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java index 0a9f8f1d106..601a4158774 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java @@ -101,7 +101,7 @@ public void calculateNodeSize() when(nodes.getNode(nodeId)).thenReturn(node); when(nodeService.getType(nodeRef)).thenReturn(TYPE_FOLDER); when(actionService.createAction(NodeSizeDetailActionExecutor.NAME)).thenReturn(action); - NodeSizeDetail nodeSizeDetail = sizeDetailImpl.calculateNodeSize(nodeId); + NodeSizeDetail nodeSizeDetail = sizeDetailImpl.getNodeSizeDetails(nodeId,""); assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code", nodeSizeDetail); } diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java index a7353fcfc4b..ca4397c8a6a 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java @@ -174,6 +174,7 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) response.put("size", totalSizeFromFacet); response.put("calculatedAt", formattedTimestamp); response.put("numberOfFiles", results != null ? results.getNodeRefs().size() : 0); + response.put("actionId", nodeAction.getId()); if(isCalculationCompleted) { From 0959f820e444d0a21757c6b69812df5bdd7fefc9 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 10:32:17 +0530 Subject: [PATCH 186/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../api/{SizeDetail.java => SizeDetails.java} | 8 +-- ...zeDetailImpl.java => SizeDetailsImpl.java} | 47 ++++++++------- ...deSizeDetail.java => NodeSizeDetails.java} | 46 +++++++++++---- .../api/nodes/NodeSizeDetailsRelation.java | 26 +++++---- .../alfresco/public-rest-context.xml | 10 ++-- .../org/alfresco/AppContext02TestSuite.java | 4 +- .../org/alfresco/AppContext04TestSuite.java | 4 +- ...ImplTest.java => SizeDetailsImplTest.java} | 36 +++++++----- .../rest/api/tests/AbstractBaseApiTest.java | 9 ++- ...tailTest.java => NodeSizeDetailsTest.java} | 57 +++++++++++-------- .../org/alfresco/AppContext01TestSuite.java | 4 +- ...=> NodeSizeDetailsActionExecutorTest.java} | 2 +- 12 files changed, 153 insertions(+), 100 deletions(-) rename remote-api/src/main/java/org/alfresco/rest/api/{SizeDetail.java => SizeDetails.java} (84%) rename remote-api/src/main/java/org/alfresco/rest/api/impl/{SizeDetailImpl.java => SizeDetailsImpl.java} (82%) rename remote-api/src/main/java/org/alfresco/rest/api/model/{NodeSizeDetail.java => NodeSizeDetails.java} (78%) rename remote-api/src/test/java/org/alfresco/rest/api/impl/{SizeDetailImplTest.java => SizeDetailsImplTest.java} (75%) rename remote-api/src/test/java/org/alfresco/rest/api/tests/{NodeSizeDetailTest.java => NodeSizeDetailsTest.java} (74%) rename repository/src/test/java/org/alfresco/repo/action/executer/{NodeSizeDetailActionExecutorTest.java => NodeSizeDetailsActionExecutorTest.java} (98%) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java similarity index 84% rename from remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java rename to remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java index 5d264577da6..d268b66f885 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetail.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java @@ -25,15 +25,15 @@ */ package org.alfresco.rest.api; -import org.alfresco.rest.api.model.NodeSizeDetail; +import org.alfresco.rest.api.model.NodeSizeDetails; -public interface SizeDetail +public interface SizeDetails { enum PROCESSINGSTATE { NOT_INITIATED, IN_PROGRESS, COMPLETED; } - NodeSizeDetail generateNodeSizeDetailsRequest(String nodeId); - NodeSizeDetail getNodeSizeDetails(String nodeId, String jobId); + NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId); + NodeSizeDetails getNodeSizeDetails(String nodeId, String jobId); } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java similarity index 82% rename from remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java rename to remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index cd870e4899d..5627ee62c29 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -29,10 +29,10 @@ import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.SizeDetail; +import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.NodePermissions; -import org.alfresco.rest.api.model.NodeSizeDetail; +import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.core.exceptions.UnprocessableContentException; import org.alfresco.service.cmr.action.Action; @@ -48,13 +48,13 @@ import java.util.Map; import java.util.HashMap; -import static org.alfresco.rest.api.SizeDetail.PROCESSINGSTATE.COMPLETED; -import static org.alfresco.rest.api.SizeDetail.PROCESSINGSTATE.NOT_INITIATED; -import static org.alfresco.rest.api.SizeDetail.PROCESSINGSTATE.IN_PROGRESS; +import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.COMPLETED; +import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.NOT_INITIATED; +import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.IN_PROGRESS; -public class SizeDetailImpl implements SizeDetail +public class SizeDetailsImpl implements SizeDetails { - private static final Logger LOG = LoggerFactory.getLogger(SizeDetailImpl.class); + private static final Logger LOG = LoggerFactory.getLogger(SizeDetailsImpl.class); private static final String STATUS = "status"; private static final String ACTIONID = "actionId"; private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; @@ -97,37 +97,41 @@ public void setDefaultItems(int defaultItems) this.defaultItems = defaultItems; } + /** + * generateNodeSizeDetailsRequest : providing HTTP STATUS 202 with jobId. + */ @Override - public NodeSizeDetail generateNodeSizeDetailsRequest(String nodeId) { + public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId) + { NodeRef nodeRef = nodes.validateNode(nodeId); validateType(nodeRef); String actionId; if(simpleCache.get(nodeId) == null) { actionId = executeAction(nodeRef, defaultItems, simpleCache); - } else { + } else + { Map result = simpleCache.get(nodeRef.getId()); actionId = (String)result.get(ACTIONID); } - return new NodeSizeDetail(actionId); + return new NodeSizeDetails(actionId); } /** - * calculateNodeSize : providing HTTP STATUS 202 which signifies REQUEST ACCEPTED. - * HTTP STATUS 200 will provide the size details response from cache. + * getNodeSizeDetails : providing HTTP STATUS 200 with NodeSizeDetails data from cache. */ @Override - public NodeSizeDetail getNodeSizeDetails(final String nodeId, final String jobId) + public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobId) { NodeRef nodeRef = nodes.validateNode(nodeId); validateType(nodeRef); if(simpleCache.get(nodeId) == null) { - return new NodeSizeDetail(nodeId, NOT_INITIATED.name()); + return new NodeSizeDetails(nodeId, NOT_INITIATED.name()); } - LOG.debug("Executing NodeSizeDetailActionExecuter from calculateNodeSize method"); + LOG.debug("Executing executorResultToSizeDetail method"); return executorResultToSizeDetail(simpleCache.get(nodeId), nodeId, jobId); } @@ -151,11 +155,11 @@ private String executeAction(NodeRef nodeRef, int defaultItems, SimpleCache result, String nodeId, String jobId) + private NodeSizeDetails executorResultToSizeDetail(final Map result, String nodeId, String jobId) { if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) { - return new NodeSizeDetail(nodeId, COMPLETED.name()); + return new NodeSizeDetails(nodeId, COMPLETED.name()); } // Check for the presence of "size" key. @@ -163,21 +167,22 @@ private NodeSizeDetail executorResultToSizeDetail(final Map resul if (hasSizeKey) { - NodeSizeDetail nodeSizeDetail = new NodeSizeDetail((String) result.get("nodeId"), + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails((String) result.get("nodeId"), (Long) result.get("size"), (String) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), COMPLETED.name(), (String) result.get(ACTIONID)); - if(!nodeSizeDetail.getJobId().equalsIgnoreCase(jobId)) { + if(!nodeSizeDetails.getJobId().equalsIgnoreCase(jobId)) + { throw new UnprocessableContentException(INVALID_JOBID); } - return nodeSizeDetail; + return nodeSizeDetails; } else { - return new NodeSizeDetail(nodeId, IN_PROGRESS.name()); + return new NodeSizeDetails(nodeId, IN_PROGRESS.name()); } } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java similarity index 78% rename from remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java rename to remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java index a019f2ffdba..48c31af5d0e 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetail.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java @@ -25,9 +25,11 @@ */ package org.alfresco.rest.api.model; +import org.json.simple.JSONObject; + import java.util.Objects; -public class NodeSizeDetail +public class NodeSizeDetails { private String nodeId; private Long size; @@ -36,16 +38,18 @@ public class NodeSizeDetail private String status; private String jobId; - public NodeSizeDetail(String jobId) { + public NodeSizeDetails(String jobId) + { this.jobId = jobId; } - public NodeSizeDetail(String nodeId, String status) { + public NodeSizeDetails(String nodeId, String status) + { this.nodeId = nodeId; this.status = status; } - public NodeSizeDetail(String nodeId, Long size, String calculatedAt, Integer numberOfFiles, String status, String jobId) + public NodeSizeDetails(String nodeId, Long size, String calculatedAt, Integer numberOfFiles, String status, String jobId) { this.nodeId = nodeId; this.size = size; @@ -105,26 +109,46 @@ public void setStatus(String status) this.status = status; } - public String getJobId() { return jobId; } + public String getJobId() + { + return jobId; + } - public void setJobId(String jobId) { this.jobId = jobId; } + public void setJobId(String jobId) + { + this.jobId = jobId; + } + + public static String parseJson(JSONObject jsonObject) + { + if (jsonObject == null) + { + return null; + } + + String jobId = (String)jsonObject.get("jobId"); + return jobId; + } @Override - public boolean equals(Object o) { + public boolean equals(Object o) + { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - NodeSizeDetail that = (NodeSizeDetail) o; + NodeSizeDetails that = (NodeSizeDetails) o; return Objects.equals(nodeId, that.nodeId) && Objects.equals(size, that.size) && Objects.equals(calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) && Objects.equals(status, that.status) && Objects.equals(jobId, that.jobId); } @Override - public int hashCode() { + public int hashCode() + { return Objects.hash(nodeId, size, calculatedAt, numberOfFiles, status, jobId); } @Override - public String toString() { - return "NodeSizeDetail{" + + public String toString() + { + return "NodeSizeDetails{" + "nodeId='" + nodeId + '\'' + ", size=" + size + ", calculatedAt='" + calculatedAt + '\'' + diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index 00f3f014f24..dfbbffc8a8a 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2023 Alfresco Software Limited + * 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 @@ -27,8 +27,8 @@ package org.alfresco.rest.api.nodes; import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.SizeDetail; -import org.alfresco.rest.api.model.NodeSizeDetail; +import org.alfresco.rest.api.SizeDetails; +import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.WebApiParameters; @@ -47,22 +47,22 @@ @RelationshipResource(name = "size-details", entityResource = NodesEntityResource.class, title = "Node Size Details") public class NodeSizeDetailsRelation implements - RelationshipResourceAction.ReadById, - RelationshipResourceAction.Create, + RelationshipResourceAction.ReadById, + RelationshipResourceAction.Create, InitializingBean { private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsRelation.class); private Nodes nodes; - private SizeDetail sizeDetail; + private SizeDetails sizeDetails; public void setNodes(Nodes nodes) { this.nodes = nodes; } - public void setSizeDetail(SizeDetail sizeDetail) + public void setSizeDetails(SizeDetails sizeDetails) { - this.sizeDetail = sizeDetail; + this.sizeDetails = sizeDetails; } @Override @@ -75,9 +75,10 @@ public void afterPropertiesSet() @WebApiParam(name="nodeSizeEntity", title="Node Size Details Request", description="Request for processing Node Size.", kind= ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple=false) @Override - public List create(String nodeId, List nodeSizeEntity, Parameters parameters) { + public List create(String nodeId, List nodeSizeEntity, Parameters parameters) + { LOG.debug(" Executing generateNodeSizeDetailsRequest method "); - return Arrays.asList(sizeDetail.generateNodeSizeDetailsRequest(nodeId)); + return Arrays.asList(sizeDetails.generateNodeSizeDetailsRequest(nodeId)); } @WebApiDescription(title = "Get Node Size Details", description = "Get the Node Size Details") @@ -85,8 +86,9 @@ public List create(String nodeId, List nodeSizeE @WebApiParam(name="nodeId", title="The unique id of the Node being addressed", description="A single node id"), @WebApiParam(name="jobId", title="Job Id to get the NodeSizeDetails", description="JobId")}) @Override - public NodeSizeDetail readById(String nodeId, String jobId, Parameters parameters) throws RelationshipResourceNotFoundException { + public NodeSizeDetails readById(String nodeId, String jobId, Parameters parameters) throws RelationshipResourceNotFoundException + { LOG.debug(" Executing getNodeSizeDetails method "); - return sizeDetail.getNodeSizeDetails(nodeId,jobId); + return sizeDetails.getNodeSizeDetails(nodeId,jobId); } } diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index bddbe2630c5..4b9d7546a76 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -996,7 +996,7 @@ - + @@ -1005,12 +1005,12 @@ - + - org.alfresco.rest.api.SizeDetail + org.alfresco.rest.api.SizeDetails - + @@ -1796,6 +1796,6 @@ - + diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 63a45a9b05c..2b097a6e05f 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -25,7 +25,7 @@ */ package org.alfresco; -import org.alfresco.rest.api.tests.NodeSizeDetailTest; +import org.alfresco.rest.api.tests.NodeSizeDetailsTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; @@ -77,7 +77,7 @@ org.alfresco.rest.api.tests.BufferedResponseTest.class, org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, - org.alfresco.rest.api.tests.NodeSizeDetailTest.class + org.alfresco.rest.api.tests.NodeSizeDetailsTest.class }) public class AppContext02TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index 4668add2eb3..ccf971c0051 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -26,7 +26,7 @@ package org.alfresco; import org.alfresco.repo.web.scripts.TestWebScriptRepoServer; -import org.alfresco.rest.api.impl.SizeDetailImplTest; +import org.alfresco.rest.api.impl.SizeDetailsImplTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; @@ -79,7 +79,7 @@ org.alfresco.rest.api.impl.CommentsImplUnitTest.class, org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, - org.alfresco.rest.api.impl.SizeDetailImplTest.class + org.alfresco.rest.api.impl.SizeDetailsImplTest.class }) public class AppContext04TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java similarity index 75% rename from remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java rename to remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 601a4158774..1cd2c1fa21f 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -29,7 +29,7 @@ import org.alfresco.repo.cache.SimpleCache; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; -import org.alfresco.rest.api.model.NodeSizeDetail; +import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.NodeRef; @@ -42,18 +42,18 @@ import java.io.Serializable; import java.util.Map; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** - * Unit tests for {@link SizeDetailImpl} class. + * Unit tests for {@link SizeDetailsImpl} class. * */ -public class SizeDetailImplTest +public class SizeDetailsImplTest { private final static int DEFAULT_ITEMS = 1000; - private SizeDetailImpl sizeDetailImpl; + private SizeDetailsImpl sizeDetailsImpl; private Nodes nodes; private NodeService nodeService; private ActionService actionService; @@ -64,7 +64,7 @@ public class SizeDetailImplTest @Before public void setUp() { - sizeDetailImpl = new SizeDetailImpl(); + sizeDetailsImpl = new SizeDetailsImpl(); nodes = mock(Nodes.class); nodeService = mock(NodeService.class); PermissionService permissionService = mock(PermissionService.class); @@ -72,19 +72,20 @@ public void setUp() action = mock(Action.class); SimpleCache> simpleCache = mock(SimpleCache.class); - sizeDetailImpl.setNodes(nodes); - sizeDetailImpl.setNodeService(nodeService); - sizeDetailImpl.setPermissionService(permissionService); - sizeDetailImpl.setActionService(actionService); - sizeDetailImpl.setSimpleCache(simpleCache); - sizeDetailImpl.setDefaultItems(DEFAULT_ITEMS); + sizeDetailsImpl.setNodes(nodes); + sizeDetailsImpl.setNodeService(nodeService); + sizeDetailsImpl.setPermissionService(permissionService); + sizeDetailsImpl.setActionService(actionService); + sizeDetailsImpl.setSimpleCache(simpleCache); + sizeDetailsImpl.setDefaultItems(DEFAULT_ITEMS); } @Test - public void calculateNodeSize() + public void calculateNodeSizeDetails() { String nodeName = "folderNode"; String nodeId = "node-id"; + String jobId = "job-id"; NodeRef nodeRef = new NodeRef("protocol", "identifier", nodeId); action.setTrackStatus(true); action.setExecuteAsynchronously(true); @@ -101,8 +102,13 @@ public void calculateNodeSize() when(nodes.getNode(nodeId)).thenReturn(node); when(nodeService.getType(nodeRef)).thenReturn(TYPE_FOLDER); when(actionService.createAction(NodeSizeDetailActionExecutor.NAME)).thenReturn(action); - NodeSizeDetail nodeSizeDetail = sizeDetailImpl.getNodeSizeDetails(nodeId,""); - assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code", nodeSizeDetail); + + NodeSizeDetails requestSizeDetails = sizeDetailsImpl.generateNodeSizeDetailsRequest(nodeId); + assertNotNull("After executing POST/size-details, it will provide with 202 status code", requestSizeDetails); + + NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.getNodeSizeDetails(nodeId,jobId); + assertNotNull("After executing GET/size-details, it will provide with 200 status code", nodeSizeDetails); + } } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index d4e383eb493..4a6764ff422 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -105,7 +105,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi private static final String URL_CHILDREN = "children"; private static final String URL_CONTENT = "content"; - private static final String URL_CALCULATEFOLDERSIZE = "request-size-detail"; + private static final String URL_CALCULATEFOLDERSIZE = "size-details"; protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; @@ -1122,9 +1122,14 @@ protected void disableRestDirectAccessUrls() restDauConfig.setEnabled(false); } - protected String getCalculateFolderSizeUrl(String nodeId) + protected String generateNodeSizeDetailsUrl(String nodeId) { return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE; } + + protected String getNodeSizeDetailsUrl(String nodeId, String jobId) + { + return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE + "/" + jobId; + } } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java similarity index 74% rename from remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java rename to remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 59318fe6ff6..cdc3bbacb7c 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -26,16 +26,15 @@ package org.alfresco.rest.api.tests; import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; -import org.alfresco.rest.api.tests.client.data.ContentInfo; -import org.alfresco.rest.api.tests.client.data.Document; -import org.alfresco.rest.api.tests.client.data.UserInfo; -import org.alfresco.rest.api.tests.client.data.Node; +import org.alfresco.rest.api.tests.client.data.*; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; +import org.json.simple.JSONObject; import org.junit.After; import org.junit.Before; import org.junit.FixMethodOrder; @@ -62,9 +61,9 @@ */ @FixMethodOrder (MethodSorters.NAME_ASCENDING) @RunWith (JUnit4.class) -public class NodeSizeDetailTest extends AbstractBaseApiTest +public class NodeSizeDetailsTest extends AbstractBaseApiTest { - private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailTest.class); + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsTest.class); private Site userOneN1Site; private String folderId; @@ -92,7 +91,7 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType) } catch (Exception e) { - LOG.error("Exception occurred in NodeSizeDetailTest:addToDocumentLibrary {}", e.getMessage()); + LOG.error("Exception occurred in NodeSizeDetailsTest:addToDocumentLibrary {}", e.getMessage()); } return null; } @@ -115,11 +114,13 @@ public void setup() throws Exception } /** - * Test case for POST/request-size-detail, which calculates and retrieve size of a folder. - * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//request-size-detail} + * Test case for POST/size-details, which request and calculates the size of a folder. + * GET/size-details, which retrieve the SizeDetails of the folder Node. + * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details} + * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details/} */ @Test - public void testPostAndGetFolderSize() throws Exception + public void testPostAndGetFolderSizeDetails() throws Exception { // Prepare parameters Map params = new HashMap<>(); @@ -127,14 +128,19 @@ public void testPostAndGetFolderSize() throws Exception params.put("maxItems", "1000"); // Perform POST request - HttpResponse postResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), toJsonAsStringNonNull(params), 202); - assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code",postResponse.getJsonResponse()); + assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse()); - HttpResponse getResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200); + String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry")); + + assertNotNull("In response, JobId should be present", jobId); + + HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); + + assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); - assertNotNull("JSON response should not be null", getJsonResponse); assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status")); } @@ -168,7 +174,7 @@ public void testPerformanceTesting() throws Exception List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(500, nodes.size()); - //Start Time before triggering POST/calculate-folder-size API + //Start Time before triggering POST/size-details API LocalTime expectedTime = LocalTime.now().plusSeconds(5); // Prepare parameters. @@ -176,18 +182,23 @@ public void testPerformanceTesting() throws Exception params.put("nodeId", folderId); // Perform POST request - HttpResponse postResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), toJsonAsStringNonNull(params), 202); + + assertNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse()); + + String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry")); + + assertNotNull("In response, JobId should be present", jobId); - assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code",postResponse.getJsonResponse()); + HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); - HttpResponse getResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 200); + assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); - assertNotNull("JSON response should not be null", getJsonResponse); assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status")); - //current Time after executing GET/request-size-details + //current Time after executing GET/size-details LocalTime actualTime = LocalTime.now(); assertTrue("Calculating folder node is taking time greater than 5 seconds ",actualTime.isBefore(expectedTime)); } @@ -199,12 +210,12 @@ public void testPerformanceTesting() throws Exception public void testHTTPStatus() throws Exception { setRequestContext(null); - delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401); + delete(generateNodeSizeDetailsUrl(folderId), folderId, null, 401); setRequestContext(user1); String folderName = "folder0" + System.currentTimeMillis(); - HttpResponse responseForNotFound = post(getCalculateFolderSizeUrl(folderName), null, 404); + HttpResponse responseForNotFound = post(generateNodeSizeDetailsUrl(folderName), null, 404); assertNotNull(responseForNotFound); folderName = "folder1" + System.currentTimeMillis(); @@ -219,7 +230,7 @@ public void testHTTPStatus() throws Exception params.put("maxItems", "1000"); // Perform POST request - HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(n1Id), toJsonAsStringNonNull(params), 422); + HttpResponse responseForInvalidNode = post(generateNodeSizeDetailsUrl(n1Id), toJsonAsStringNonNull(params), 422); assertNotNull(responseForInvalidNode); } diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index b342c42220e..e210648ca48 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -25,7 +25,7 @@ */ package org.alfresco; -import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutorTest; +import org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; @@ -79,7 +79,7 @@ org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, - org.alfresco.repo.action.executer.NodeSizeDetailActionExecutorTest.class + org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest.class }) public class AppContext01TestSuite { diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutorTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java similarity index 98% rename from repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutorTest.java rename to repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java index c4c2cd58538..9fc044bda0a 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutorTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java @@ -43,7 +43,7 @@ import org.springframework.transaction.annotation.Transactional; @Transactional -public class NodeSizeDetailActionExecutorTest extends BaseSpringTest +public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest { /** * The test node reference From 98a3469d60a8b4a1460ac0553c3f48c913301d52 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 11:06:31 +0530 Subject: [PATCH 187/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../alfresco/rest/api/model/NodeSizeDetails.java | 10 ++++++++-- .../rest/api/tests/NodeSizeDetailsTest.java | 14 +++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java index 48c31af5d0e..32e36bf1fad 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java @@ -133,8 +133,14 @@ public static String parseJson(JSONObject jsonObject) @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } NodeSizeDetails that = (NodeSizeDetails) o; return Objects.equals(nodeId, that.nodeId) && Objects.equals(size, that.size) && Objects.equals(calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) && Objects.equals(status, that.status) && Objects.equals(jobId, that.jobId); } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index cdc3bbacb7c..0f2fe10fd85 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -125,10 +125,10 @@ public void testPostAndGetFolderSizeDetails() throws Exception // Prepare parameters Map params = new HashMap<>(); params.put("nodeId", folderId); - params.put("maxItems", "1000"); + params.put("nodeSizeEntity", null); // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), toJsonAsStringNonNull(params), 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), null, 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse()); @@ -180,9 +180,10 @@ public void testPerformanceTesting() throws Exception // Prepare parameters. Map params = new HashMap<>(); params.put("nodeId", folderId); + params.put("nodeSizeEntity", null); // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), toJsonAsStringNonNull(params), 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), null, 202); assertNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse()); @@ -224,13 +225,8 @@ public void testHTTPStatus() throws Exception Node nodeResp = createNode(folderId, folderName, nodeType, null); String n1Id = nodeResp.getId(); - // Prepare parameters - Map params = new HashMap<>(); - params.put("nodeId", n1Id); - params.put("maxItems", "1000"); - // Perform POST request - HttpResponse responseForInvalidNode = post(generateNodeSizeDetailsUrl(n1Id), toJsonAsStringNonNull(params), 422); + HttpResponse responseForInvalidNode = post(generateNodeSizeDetailsUrl(n1Id), null, 422); assertNotNull(responseForInvalidNode); } From d1c3ca5a70a9c249b2eff1c4949d7634871f5f53 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 11:10:55 +0530 Subject: [PATCH 188/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../rest/api/tests/NodeSizeDetailsTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 0f2fe10fd85..32e1ae999c9 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -122,11 +122,6 @@ public void setup() throws Exception @Test public void testPostAndGetFolderSizeDetails() throws Exception { - // Prepare parameters - Map params = new HashMap<>(); - params.put("nodeId", folderId); - params.put("nodeSizeEntity", null); - // Perform POST request HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), null, 202); @@ -136,6 +131,11 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("In response, JobId should be present", jobId); + // Prepare parameters. + Map params = new HashMap<>(); + params.put("nodeId", folderId); + params.put("jobId", jobId); + HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); @@ -177,11 +177,6 @@ public void testPerformanceTesting() throws Exception //Start Time before triggering POST/size-details API LocalTime expectedTime = LocalTime.now().plusSeconds(5); - // Prepare parameters. - Map params = new HashMap<>(); - params.put("nodeId", folderId); - params.put("nodeSizeEntity", null); - // Perform POST request HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), null, 202); @@ -191,6 +186,11 @@ public void testPerformanceTesting() throws Exception assertNotNull("In response, JobId should be present", jobId); + // Prepare parameters. + Map params = new HashMap<>(); + params.put("nodeId", folderId); + params.put("jobId", jobId); + HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); From 280bbf6bb714615826f0ee3d6a523d1bf0d8a8be Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 11:42:18 +0530 Subject: [PATCH 189/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 32e1ae999c9..2fd51d474dd 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -50,11 +50,9 @@ import java.util.List; import java.util.Map; -import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; /** * V1 REST API tests for calculating and retrieving Folder size. @@ -136,7 +134,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), user1, params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); @@ -180,7 +178,7 @@ public void testPerformanceTesting() throws Exception // Perform POST request HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), null, 202); - assertNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse()); + assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse()); String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry")); @@ -191,7 +189,7 @@ public void testPerformanceTesting() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), user1, params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); From c603a7708210a6eff80b304c992bb8c1c7f01e4c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 12:08:27 +0530 Subject: [PATCH 190/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 2fd51d474dd..e14d9701f47 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -134,7 +134,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), user1, params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), folderId, params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); @@ -189,7 +189,7 @@ public void testPerformanceTesting() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), user1, params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), folderId, params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); From aa8bff499b462a2884c63014d2720b1bacf633c0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 12:44:42 +0530 Subject: [PATCH 191/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/AppContext02TestSuite.java | 1 - .../alfresco/rest/api/tests/NodeSizeDetailsTest.java | 12 +++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 2b097a6e05f..88cff8438af 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -25,7 +25,6 @@ */ package org.alfresco; -import org.alfresco.rest.api.tests.NodeSizeDetailsTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index e14d9701f47..e3c99cc0bdb 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -50,9 +50,7 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; /** * V1 REST API tests for calculating and retrieving Folder size. @@ -127,14 +125,14 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry")); - assertNotNull("In response, JobId should be present", jobId); + assertNull("In response, JobId should be present", jobId); // Prepare parameters. Map params = new HashMap<>(); params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), folderId, params, 200); + HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); @@ -182,14 +180,14 @@ public void testPerformanceTesting() throws Exception String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry")); - assertNotNull("In response, JobId should be present", jobId); + assertNull("In response, JobId should be present", jobId); // Prepare parameters. Map params = new HashMap<>(); params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), folderId, params, 200); + HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); From 3b49f50681690a1859efd336161e62b3a3e02392 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 13:12:29 +0530 Subject: [PATCH 192/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/model/NodeSizeDetails.java | 1 + .../src/test/java/org/alfresco/AppContext04TestSuite.java | 1 - .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 8 +++++--- .../src/test/java/org/alfresco/AppContext01TestSuite.java | 1 - 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java index 32e36bf1fad..c30a9dbbe4a 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java @@ -127,6 +127,7 @@ public static String parseJson(JSONObject jsonObject) } String jobId = (String)jsonObject.get("jobId"); + jobId = jobId.replace("<", "").replace(">", ""); return jobId; } diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index ccf971c0051..c56273db18e 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -26,7 +26,6 @@ package org.alfresco; import org.alfresco.repo.web.scripts.TestWebScriptRepoServer; -import org.alfresco.rest.api.impl.SizeDetailsImplTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index e3c99cc0bdb..5b233d3e76c 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -50,7 +50,9 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; /** * V1 REST API tests for calculating and retrieving Folder size. @@ -125,7 +127,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry")); - assertNull("In response, JobId should be present", jobId); + assertNotNull("In response, JobId should be present", jobId); // Prepare parameters. Map params = new HashMap<>(); @@ -180,7 +182,7 @@ public void testPerformanceTesting() throws Exception String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry")); - assertNull("In response, JobId should be present", jobId); + assertNotNull("In response, JobId should be present", jobId); // Prepare parameters. Map params = new HashMap<>(); diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index e210648ca48..96241657224 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -25,7 +25,6 @@ */ package org.alfresco; -import org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; From 817548aba784cc8620efb7019bdb6e33f179e8b7 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 13:44:14 +0530 Subject: [PATCH 193/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 5b233d3e76c..a3a829c15c2 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -134,7 +134,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId),user1, params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); @@ -189,7 +189,7 @@ public void testPerformanceTesting() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId),user1, params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); From ed20ea16056cdb4cbe62623b5b1c22e797a8329f Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 14:07:30 +0530 Subject: [PATCH 194/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index a3a829c15c2..fb258ea6efe 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -134,7 +134,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId),user1, params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId),folderId, params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); @@ -189,7 +189,7 @@ public void testPerformanceTesting() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId),user1, params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), folderId, params, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); From 6f1138fe4a66aab0583a2caaebb1d24568267e6a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 4 Sep 2024 14:29:11 +0530 Subject: [PATCH 195/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index fb258ea6efe..4ded97e882b 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -134,7 +134,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId),folderId, params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); @@ -189,7 +189,7 @@ public void testPerformanceTesting() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), folderId, params, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); From 47799cdbdd7cbcc8c84d4f2bb6620a1cbc2efca4 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 13 Sep 2024 00:50:37 +0530 Subject: [PATCH 196/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../org/alfresco/rest/api/SizeDetails.java | 13 +- .../rest/api/impl/SizeDetailsImpl.java | 117 ++++++------------ .../rest/api/model/NodeSizeDetails.java | 104 ++++++++-------- .../api/nodes/NodeSizeDetailsRelation.java | 37 +++--- .../alfresco/public-rest-context.xml | 2 - .../rest/api/impl/SizeDetailsImplTest.java | 23 ++-- .../rest/api/tests/NodeSizeDetailsTest.java | 68 +++++----- .../NodeSizeDetailActionExecutor.java | 110 ++++++++-------- .../NodeSizeDetailsActionExecutorTest.java | 36 +++--- 9 files changed, 235 insertions(+), 275 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java index d268b66f885..3412f27d650 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java @@ -29,11 +29,12 @@ public interface SizeDetails { - enum PROCESSINGSTATE - { - NOT_INITIATED, IN_PROGRESS, COMPLETED; - } + NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId); - NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId); - NodeSizeDetails getNodeSizeDetails(String nodeId, String jobId); + NodeSizeDetails getNodeSizeDetails(String nodeId, String jobId); + + enum ProcessingState + { + NOT_INITIATED, PENDING, IN_PROGRESS, COMPLETED + } } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 5627ee62c29..966a9ec21f9 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -25,46 +25,34 @@ */ package org.alfresco.rest.api.impl; +import static org.alfresco.rest.api.SizeDetails.ProcessingState.COMPLETED; +import static org.alfresco.rest.api.SizeDetails.ProcessingState.IN_PROGRESS; +import static org.alfresco.rest.api.SizeDetails.ProcessingState.NOT_INITIATED; + +import java.io.Serializable; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.model.ContentModel; import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutor; import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.SizeDetails; -import org.alfresco.rest.api.model.Node; -import org.alfresco.rest.api.model.NodePermissions; import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.core.exceptions.UnprocessableContentException; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.namespace.QName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.alfresco.service.cmr.repository.NodeRef; -import java.io.Serializable; -import java.util.Map; -import java.util.HashMap; - -import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.COMPLETED; -import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.NOT_INITIATED; -import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.IN_PROGRESS; public class SizeDetailsImpl implements SizeDetails { - private static final Logger LOG = LoggerFactory.getLogger(SizeDetailsImpl.class); - private static final String STATUS = "status"; - private static final String ACTIONID = "actionId"; - private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid"; - private static final String INVALID_JOBID = "Invalid parameter: value of jobId is invalid"; - private static final String FOLDER = "folder"; + private static final String ACTION_ID = "actionId"; private Nodes nodes; - private NodeService nodeService; - private PermissionService permissionService; + private NodeRef nodeRef; private ActionService actionService; - private SimpleCache> simpleCache; + private SimpleCache> simpleCache; private int defaultItems; public void setNodes(Nodes nodes) @@ -72,16 +60,6 @@ public void setNodes(Nodes nodes) this.nodes = nodes; } - public void setPermissionService(PermissionService permissionService) - { - this.permissionService = permissionService; - } - - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - public void setActionService(ActionService actionService) { this.actionService = actionService; @@ -103,16 +81,17 @@ public void setDefaultItems(int defaultItems) @Override public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId) { - NodeRef nodeRef = nodes.validateNode(nodeId); + nodeRef = nodes.validateOrLookupNode(nodeId); validateType(nodeRef); String actionId; - if(simpleCache.get(nodeId) == null) + if (!simpleCache.contains(nodeId)) { - actionId = executeAction(nodeRef, defaultItems, simpleCache); - } else + actionId = executeAction(); + } + else { Map result = simpleCache.get(nodeRef.getId()); - actionId = (String)result.get(ACTIONID); + actionId = (String) result.get(ACTION_ID); } return new NodeSizeDetails(actionId); } @@ -123,29 +102,27 @@ public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId) @Override public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobId) { - NodeRef nodeRef = nodes.validateNode(nodeId); + NodeRef nodeRef = nodes.validateOrLookupNode(nodeId); validateType(nodeRef); - if(simpleCache.get(nodeId) == null) + if (!simpleCache.contains(nodeId)) { return new NodeSizeDetails(nodeId, NOT_INITIATED.name()); } - LOG.debug("Executing executorResultToSizeDetail method"); return executorResultToSizeDetail(simpleCache.get(nodeId), nodeId, jobId); } /** * Executing Action Asynchronously. */ - private String executeAction(NodeRef nodeRef, int defaultItems, SimpleCache> simpleCache) + private String executeAction() { Map currentStatus = new HashMap<>(); - currentStatus.put(STATUS,IN_PROGRESS.name()); + currentStatus.put("status",IN_PROGRESS.name()); Action folderSizeAction = actionService.createAction(NodeSizeDetailActionExecutor.NAME); - currentStatus.put(ACTIONID,folderSizeAction.getId()); + currentStatus.put(ACTION_ID,folderSizeAction.getId()); folderSizeAction.setTrackStatus(true); - folderSizeAction.setExecuteAsynchronously(true); folderSizeAction.setParameterValue(NodeSizeDetailActionExecutor.DEFAULT_SIZE, defaultItems); simpleCache.put(nodeRef.getId(),currentStatus); actionService.executeAction(folderSizeAction, nodeRef, false, true); @@ -155,28 +132,24 @@ private String executeAction(NodeRef nodeRef, int defaultItems, SimpleCache result, String nodeId, String jobId) + private NodeSizeDetails executorResultToSizeDetail(final Map result, String nodeId, String jobId) { - if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) + if (result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) { return new NodeSizeDetails(nodeId, COMPLETED.name()); } - // Check for the presence of "size" key. - boolean hasSizeKey = result.containsKey("size"); - - if (hasSizeKey) + if (result.containsKey("size")) { - NodeSizeDetails nodeSizeDetails = new NodeSizeDetails((String) result.get("nodeId"), - (Long) result.get("size"), - (String) result.get("calculatedAt"), - (Integer) result.get("numberOfFiles"), - COMPLETED.name(), - (String) result.get(ACTIONID)); - - if(!nodeSizeDetails.getJobId().equalsIgnoreCase(jobId)) + NodeSizeDetails nodeSizeDetails = + new NodeSizeDetails((String) result.get("nodeId"), (Long) result.get("size"), + (Date) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), + COMPLETED.name(), (String) result.get(ACTION_ID)); + + if (!nodeSizeDetails.getJobId() + .equalsIgnoreCase(jobId)) { - throw new UnprocessableContentException(INVALID_JOBID); + throw new UnprocessableContentException("Invalid parameter: value of jobId is invalid"); } return nodeSizeDetails; } @@ -188,25 +161,9 @@ private NodeSizeDetails executorResultToSizeDetail(final Map resu private void validateType(NodeRef nodeRef) throws InvalidNodeTypeException { - QName qName = nodeService.getType(nodeRef); - validatePermissions(nodeRef, nodeRef.getId()); - if(!FOLDER.equalsIgnoreCase(qName.getLocalName())) - { - throw new InvalidNodeTypeException(INVALID_NODEID); - } - } - - /** - * Validating node permission [i.e. READ permission should be there ] - */ - private void validatePermissions(NodeRef nodeRef, String nodeId) - { - Node nodeInfo = nodes.getNode(nodeId); - NodePermissions nodePerms = nodeInfo.getPermissions(); - // Validate permissions. - if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) + if (!nodes.isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)) { - throw new AccessDeniedException("permissions.err_access_denied"); + throw new InvalidNodeTypeException("Invalid parameter: value of nodeId is invalid"); } } } \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java index c30a9dbbe4a..b3c1a5bc431 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java @@ -25,17 +25,17 @@ */ package org.alfresco.rest.api.model; -import org.json.simple.JSONObject; - +import java.util.Date; import java.util.Objects; +import org.json.simple.JSONObject; + public class NodeSizeDetails { - private String nodeId; - private Long size; - private String calculatedAt; + private String id; + private Long sizeInBytes; + private Date calculatedAt; private Integer numberOfFiles; - private String status; private String jobId; public NodeSizeDetails(String jobId) @@ -43,48 +43,62 @@ public NodeSizeDetails(String jobId) this.jobId = jobId; } - public NodeSizeDetails(String nodeId, String status) + public NodeSizeDetails(String id, String currentStatus) { - this.nodeId = nodeId; - this.status = status; + this.id = id; + NodeSizeDetails.status.valueOf(currentStatus); } - public NodeSizeDetails(String nodeId, Long size, String calculatedAt, Integer numberOfFiles, String status, String jobId) + public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer numberOfFiles, String currentStatus, + String jobId) { - this.nodeId = nodeId; - this.size = size; + this.id = id; + this.sizeInBytes = sizeInBytes; this.calculatedAt = calculatedAt; this.numberOfFiles = numberOfFiles; - this.status = status; + NodeSizeDetails.status.valueOf(currentStatus); this.jobId = jobId; } - public String getNodeId() + public static String parseJson(JSONObject jsonObject) { - return nodeId; + if (jsonObject == null) + { + return null; + } + + String jobId = (String) jsonObject.get("jobId"); + jobId = jobId.replace("<", "") + .replace(">", ""); + return jobId; + } + + public String getId() + { + return id; } - public void setNodeId(String nodeId) + public void setId(String id) { - this.nodeId = nodeId; + this.id = id; } - public Long getSize() + public Long getSizeInBytes() { - return size; + return sizeInBytes; } - public void setSize(Long size) + public void setSizeInBytes(Long sizeInBytes) { - this.size = size; + this.sizeInBytes = sizeInBytes; } - public String getCalculatedAt() + public Date getCalculatedAt() { return calculatedAt; } - public void setCalculatedAt(String calculatedAt) + public void setCalculatedAt(Date calculatedAt) { this.calculatedAt = calculatedAt; } @@ -99,16 +113,6 @@ public void setNumberOfFiles(Integer numberOfFiles) this.numberOfFiles = numberOfFiles; } - public String getStatus() - { - return status; - } - - public void setStatus(String status) - { - this.status = status; - } - public String getJobId() { return jobId; @@ -119,18 +123,6 @@ public void setJobId(String jobId) this.jobId = jobId; } - public static String parseJson(JSONObject jsonObject) - { - if (jsonObject == null) - { - return null; - } - - String jobId = (String)jsonObject.get("jobId"); - jobId = jobId.replace("<", "").replace(">", ""); - return jobId; - } - @Override public boolean equals(Object o) { @@ -143,25 +135,27 @@ public boolean equals(Object o) return false; } NodeSizeDetails that = (NodeSizeDetails) o; - return Objects.equals(nodeId, that.nodeId) && Objects.equals(size, that.size) && Objects.equals(calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) && Objects.equals(status, that.status) && Objects.equals(jobId, that.jobId); + return Objects.equals(id, that.id) && Objects.equals(sizeInBytes, that.sizeInBytes) && Objects.equals( + calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) + && Objects.equals(jobId, that.jobId); } @Override public int hashCode() { - return Objects.hash(nodeId, size, calculatedAt, numberOfFiles, status, jobId); + return Objects.hash(id, sizeInBytes, calculatedAt, numberOfFiles, jobId); } @Override public String toString() { - return "NodeSizeDetails{" + - "nodeId='" + nodeId + '\'' + - ", size=" + size + - ", calculatedAt='" + calculatedAt + '\'' + - ", numberOfFiles=" + numberOfFiles + - ", status='" + status + '\'' + - ", jobId='" + jobId + '\'' + - '}'; + return "NodeSizeDetails{" + "id='" + id + '\'' + ", sizeInBytes=" + sizeInBytes + ", calculatedAt=" + + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + '}'; } + + private enum status + { + NOT_INITIATED, PENDING, IN_PROGRESS, COMPLETED + } + } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index dfbbffc8a8a..537c322fd7c 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -26,6 +26,9 @@ package org.alfresco.rest.api.nodes; +import java.util.Collections; +import java.util.List; + import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.api.model.NodeSizeDetails; @@ -38,20 +41,14 @@ import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.util.ParameterCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.extensions.webscripts.Status; -import java.util.Arrays; -import java.util.List; @RelationshipResource(name = "size-details", entityResource = NodesEntityResource.class, title = "Node Size Details") -public class NodeSizeDetailsRelation implements - RelationshipResourceAction.ReadById, - RelationshipResourceAction.Create, - InitializingBean { +public class NodeSizeDetailsRelation implements RelationshipResourceAction.ReadById, + RelationshipResourceAction.Create, InitializingBean +{ - private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsRelation.class); private Nodes nodes; private SizeDetails sizeDetails; @@ -68,27 +65,27 @@ public void setSizeDetails(SizeDetails sizeDetails) @Override public void afterPropertiesSet() { - ParameterCheck.mandatory("nodes", this.nodes); + ParameterCheck.mandatory("sizeDetails", this.sizeDetails); } @WebApiDescription(title = "Create node-size details request", successStatus = Status.STATUS_ACCEPTED) - @WebApiParam(name="nodeSizeEntity", title="Node Size Details Request", description="Request for processing Node Size.", - kind= ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple=false) + @WebApiParam(name = "nodeSizeEntity", title = "Node Size Details Request", + description = "Request for processing Node Size.", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT, + allowMultiple = false) @Override public List create(String nodeId, List nodeSizeEntity, Parameters parameters) { - LOG.debug(" Executing generateNodeSizeDetailsRequest method "); - return Arrays.asList(sizeDetails.generateNodeSizeDetailsRequest(nodeId)); + return List.of(sizeDetails.generateNodeSizeDetailsRequest(nodeId)); } @WebApiDescription(title = "Get Node Size Details", description = "Get the Node Size Details") - @WebApiParameters({ - @WebApiParam(name="nodeId", title="The unique id of the Node being addressed", description="A single node id"), - @WebApiParam(name="jobId", title="Job Id to get the NodeSizeDetails", description="JobId")}) + @WebApiParameters({ @WebApiParam(name = "nodeId", title = "The unique id of the Node being addressed", + description = "A single node id"), + @WebApiParam(name = "jobId", title = "Job Id to get the NodeSizeDetails", description = "JobId") }) @Override - public NodeSizeDetails readById(String nodeId, String jobId, Parameters parameters) throws RelationshipResourceNotFoundException + public NodeSizeDetails readById(String nodeId, String jobId, Parameters parameters) + throws RelationshipResourceNotFoundException { - LOG.debug(" Executing getNodeSizeDetails method "); - return sizeDetails.getNodeSizeDetails(nodeId,jobId); + return sizeDetails.getNodeSizeDetails(nodeId, jobId); } } diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 4b9d7546a76..da717df7451 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -998,8 +998,6 @@ - - diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 1cd2c1fa21f..d510b144ed7 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -25,6 +25,13 @@ */ package org.alfresco.rest.api.impl; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.Serializable; +import java.util.Map; + import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutor; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.rest.api.Nodes; @@ -39,27 +46,19 @@ import org.junit.Before; import org.junit.Test; -import java.io.Serializable; -import java.util.Map; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - /** * Unit tests for {@link SizeDetailsImpl} class. - * */ public class SizeDetailsImplTest { private final static int DEFAULT_ITEMS = 1000; + private static final String NAMESPACE = "http://www.alfresco.org/test/NodeSizeDetailsTest"; + private static final QName TYPE_FOLDER = QName.createQName(NAMESPACE, "folder"); private SizeDetailsImpl sizeDetailsImpl; private Nodes nodes; private NodeService nodeService; private ActionService actionService; private Action action; - private static final String NAMESPACE = "http://www.alfresco.org/test/NodeSizeDetailsTest"; - private static final QName TYPE_FOLDER = QName.createQName(NAMESPACE, "folder"); @Before public void setUp() @@ -70,7 +69,7 @@ public void setUp() PermissionService permissionService = mock(PermissionService.class); actionService = mock(ActionService.class); action = mock(Action.class); - SimpleCache> simpleCache = mock(SimpleCache.class); + SimpleCache> simpleCache = mock(SimpleCache.class); sizeDetailsImpl.setNodes(nodes); sizeDetailsImpl.setNodeService(nodeService); @@ -106,7 +105,7 @@ public void calculateNodeSizeDetails() NodeSizeDetails requestSizeDetails = sizeDetailsImpl.generateNodeSizeDetailsRequest(nodeId); assertNotNull("After executing POST/size-details, it will provide with 202 status code", requestSizeDetails); - NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.getNodeSizeDetails(nodeId,jobId); + NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.getNodeSizeDetails(nodeId, jobId); assertNotNull("After executing GET/size-details, it will provide with 200 status code", nodeSizeDetails); } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 4ded97e882b..a227b98ec29 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -25,12 +25,24 @@ */ package org.alfresco.rest.api.tests; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.LocalTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; -import org.alfresco.rest.api.tests.client.data.*; +import org.alfresco.rest.api.tests.client.data.ContentInfo; +import org.alfresco.rest.api.tests.client.data.Document; +import org.alfresco.rest.api.tests.client.data.Node; +import org.alfresco.rest.api.tests.client.data.UserInfo; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; @@ -45,20 +57,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.time.LocalTime; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; - /** * V1 REST API tests for calculating and retrieving Folder size. */ -@FixMethodOrder (MethodSorters.NAME_ASCENDING) -@RunWith (JUnit4.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(JUnit4.class) public class NodeSizeDetailsTest extends AbstractBaseApiTest { private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsTest.class); @@ -102,7 +105,7 @@ public void setup() throws Exception setRequestContext(user1); String siteTitle = "RandomSite" + System.currentTimeMillis(); - this.userOneN1Site = createSite("RN"+RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + this.userOneN1Site = createSite("RN" + RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); @@ -123,9 +126,11 @@ public void testPostAndGetFolderSizeDetails() throws Exception // Perform POST request HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), null, 202); - assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse()); + assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", + postResponse.getJsonResponse()); - String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry")); + String jobId = NodeSizeDetails.parseJson((JSONObject) postResponse.getJsonResponse() + .get("entry")); assertNotNull("In response, JobId should be present", jobId); @@ -136,11 +141,13 @@ public void testPostAndGetFolderSizeDetails() throws Exception HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); - assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); + assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", + getResponse.getJsonResponse()); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); - assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status")); + assertTrue("We are not getting correct response " + getJsonResponse, + getJsonResponse.contains("size") || getJsonResponse.contains("status")); } @Test @@ -149,14 +156,14 @@ public void testPerformanceTesting() throws Exception setRequestContext(user1); UserInfo userInfo = new UserInfo(user1); - String folder0Name = "f0-testParentFolder-"+RUNID; - String parentFolder = createFolder(tDocLibNodeId, folder0Name,null).getId(); + String folder0Name = "f0-testParentFolder-" + RUNID; + String parentFolder = createFolder(tDocLibNodeId, folder0Name, null).getId(); - for(int i=1;i<=500;i++) + for (int i = 1; i <= 500; i++) { - String folderBName = "folder"+i+RUNID + "_B"; + String folderBName = "folder" + i + RUNID + "_B"; String folderBId = createFolder(parentFolder, folderBName, null).getId(); - String fileName = "content"+i+ RUNID + ".txt"; + String fileName = "content" + i + RUNID + ".txt"; Document d1 = new Document(); d1.setIsFolder(false); d1.setParentId(folderBId); @@ -173,14 +180,17 @@ public void testPerformanceTesting() throws Exception assertEquals(500, nodes.size()); //Start Time before triggering POST/size-details API - LocalTime expectedTime = LocalTime.now().plusSeconds(5); + LocalTime expectedTime = LocalTime.now() + .plusSeconds(5); // Perform POST request HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), null, 202); - assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse()); + assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", + postResponse.getJsonResponse()); - String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry")); + String jobId = NodeSizeDetails.parseJson((JSONObject) postResponse.getJsonResponse() + .get("entry")); assertNotNull("In response, JobId should be present", jobId); @@ -191,15 +201,17 @@ public void testPerformanceTesting() throws Exception HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); - assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse()); + assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", + getResponse.getJsonResponse()); String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); - assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status")); + assertTrue("We are not getting correct response " + getJsonResponse, + getJsonResponse.contains("size") || getJsonResponse.contains("status")); //current Time after executing GET/size-details LocalTime actualTime = LocalTime.now(); - assertTrue("Calculating folder node is taking time greater than 5 seconds ",actualTime.isBefore(expectedTime)); + assertTrue("Calculating folder node is taking time greater than 5 seconds ", actualTime.isBefore(expectedTime)); } /** diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java index ca4397c8a6a..64ea947472d 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java @@ -25,6 +25,17 @@ */ package org.alfresco.repo.action.executer; +import java.io.Serializable; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.alfresco.repo.action.ParameterizedItemAbstractBase; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.service.cmr.action.Action; @@ -34,23 +45,14 @@ import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.util.ISO8601DateFormat; import org.alfresco.util.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.Serializable; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; - /** - * NodeSizeDetailActionExecutor - * Executing Alfresco FTS Query to find size of Folder Node + * NodeSizeDetailActionExecutor + * Executing Alfresco FTS Query to find size of Folder Node */ public class NodeSizeDetailActionExecutor extends ActionExecuterAbstractBase @@ -63,16 +65,20 @@ public class NodeSizeDetailActionExecutor extends ActionExecuterAbstractBase */ public static final String NAME = "folder-size"; public static final String EXCEPTION = "Exception"; + + public static final String IN_PROGRESS = "IN_PROGRESS"; public static final String DEFAULT_SIZE = "default-size"; + private static final String STATUS = "status"; + private static final String ACTION_ID = "actionId"; private static final String FIELD_FACET = "content.size"; - private static final String FACET_QUERY = "content.size:[0 TO "+Integer.MAX_VALUE+"] \"label\": \"large\",\"group\":\"Size\""; + private static final String FACET_QUERY = "content.size:[0 TO " + Integer.MAX_VALUE + "] \"label\": \"large\",\"group\":\"Size\""; private SearchService searchService; private SimpleCache> simpleCache; /** * Set the search service * - * @param searchService the search service + * @param searchService the search service */ public void setSearchService(SearchService searchService) { @@ -82,7 +88,7 @@ public void setSearchService(SearchService searchService) /** * Set the simpleCache service * - * @param simpleCache the cache service + * @param simpleCache the cache service */ public void setSimpleCache(SimpleCache> simpleCache) { @@ -97,7 +103,10 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) { Serializable serializable = nodeAction.getParameterValue(DEFAULT_SIZE); int defaultItems; - Map response = new HashMap<>(); + Map response = new HashMap<>(); + response.put(STATUS, IN_PROGRESS); + response.put(ACTION_ID, nodeAction.getId()); + simpleCache.put(actionedUponNodeRef.getId(), response); try { @@ -106,8 +115,9 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) catch (NumberFormatException numberFormatException) { LOG.error("Exception occurred while parsing String to INT: {} ", numberFormatException.getMessage()); - response.put(EXCEPTION,"Exception occurred while parsing String to INT: {} " + numberFormatException.getMessage()); - simpleCache.put(actionedUponNodeRef.getId(),response); + response.put(EXCEPTION, + "Exception occurred while parsing String to INT: {} " + numberFormatException.getMessage()); + simpleCache.put(actionedUponNodeRef.getId(), response); throw numberFormatException; } @@ -122,38 +132,30 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) { // executing Alfresco FTS facet query. results = facetQuery(nodeRef); - totalItems = Math.min(results.getFieldFacet(FIELD_FACET).size(), defaultItems); - // Using AtomicLong to accumulate the total size. - AtomicLong resultSize = new AtomicLong(0); + totalItems = Math.min(results.getFieldFacet(FIELD_FACET) + .size(), defaultItems); while (!isCalculationCompleted) { - List> pairSizes = results.getFieldFacet(FIELD_FACET).subList(skipCount, totalItems); - pairSizes.parallelStream().forEach(id -> { - try - { - if(id.getSecond()>0) - { - resultSize.addAndGet(Long.valueOf(id.getFirst()) * id.getSecond()); - } - } - catch (Exception e) - { - resultSize.addAndGet(0); - } - }); - - totalSizeFromFacet+=resultSize.longValue(); - resultSize.set(0); - - if (results.getFieldFacet(FIELD_FACET).size() <= totalItems || results.getFieldFacet(FIELD_FACET).size() <= defaultItems) + List> pairSizes = results.getFieldFacet(FIELD_FACET) + .subList(skipCount, totalItems); + long total = pairSizes.parallelStream() + .mapToLong(id -> Long.parseLong(id.getFirst()) * id.getSecond()) + .sum(); + + totalSizeFromFacet += total; + + if (results.getFieldFacet(FIELD_FACET) + .size() <= totalItems || results.getFieldFacet(FIELD_FACET) + .size() <= defaultItems) { isCalculationCompleted = true; } else { skipCount += defaultItems; - int remainingItems = results.getFieldFacet(FIELD_FACET).size() - totalItems; + int remainingItems = results.getFieldFacet(FIELD_FACET) + .size() - totalItems; totalItems += Math.min(remainingItems, defaultItems); } } @@ -161,8 +163,9 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) catch (RuntimeException runtimeException) { LOG.error("Exception occurred in NodeSizeDetailActionExecutor:results {} ", runtimeException.getMessage()); - response.put(EXCEPTION,"Exception occurred in NodeSizeDetailActionExecutor:results {} "+runtimeException.getMessage()); - simpleCache.put(nodeRef.getId(),response); + response.put(EXCEPTION, "Exception occurred in NodeSizeDetailActionExecutor:results {} " + + runtimeException.getMessage()); + simpleCache.put(nodeRef.getId(), response); throw runtimeException; } @@ -170,23 +173,27 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); String formattedTimestamp = eventTimestamp.format(formatter); + + Date date = Calendar.getInstance() + .getTime(); + String dateStr = ISO8601DateFormat.format(date); + response.put("nodeId", nodeRef.getId()); response.put("size", totalSizeFromFacet); - response.put("calculatedAt", formattedTimestamp); - response.put("numberOfFiles", results != null ? results.getNodeRefs().size() : 0); + response.put("calculatedAt", dateStr); + response.put("numberOfFiles", results != null ? results.getNodeRefs() + .size() : 0); response.put("actionId", nodeAction.getId()); - if(isCalculationCompleted) + if (isCalculationCompleted) { - simpleCache.put(nodeRef.getId(),response); + simpleCache.put(nodeRef.getId(), response); } } protected ResultSet facetQuery(NodeRef nodeRef) { - StringBuilder aftsQuery = new StringBuilder(); - aftsQuery.append("ANCESTOR:\"").append(nodeRef).append("\" AND TYPE:content"); - String query = aftsQuery.toString(); + String query = "ANCESTOR:\"" + nodeRef + "\" AND TYPE:content"; SearchParameters searchParameters = new SearchParameters(); searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); @@ -196,7 +203,8 @@ protected ResultSet facetQuery(NodeRef nodeRef) searchParameters.addFacetQuery(FACET_QUERY); final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); - ff.setLimitOrNull(resultsWithoutFacet.getNodeRefs().size()); + ff.setLimitOrNull(resultsWithoutFacet.getNodeRefs() + .size()); searchParameters.addFieldFacet(ff); resultsWithoutFacet.close(); return searchService.query(searchParameters); diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java index 9fc044bda0a..637764d4a62 100644 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java +++ b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java @@ -45,27 +45,24 @@ @Transactional public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest { + /** + * Id used to identify the test action created + */ + private final static String ID = GUID.generate(); /** * The test node reference */ private NodeRef nodeRef; - /** * The folder Size executer */ private NodeSizeDetailActionExecutor executer; - - /** - * Id used to identify the test action created - */ - private final static String ID = GUID.generate(); - /** * Set the simpleCache service * * @param simpleCache the cache service */ - private SimpleCache> simpleCache; + private SimpleCache> simpleCache; /** * Called at the begining of all tests. @@ -73,29 +70,26 @@ public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest @Before public void before() throws Exception { - NodeService nodeService = (NodeService)this.applicationContext.getBean("nodeService"); + NodeService nodeService = (NodeService) this.applicationContext.getBean("nodeService"); StoreRef testStoreRef; NodeRef rootNodeRef; - AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent"); + AuthenticationComponent authenticationComponent = + (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); // Create the store and get the root node - testStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" - + System.currentTimeMillis()); + testStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(testStoreRef); // Create the node used for tests - this.nodeRef = nodeService.createNode( - rootNodeRef, - ContentModel.ASSOC_CHILDREN, - QName.createQName("{test}testnode"), - ContentModel.TYPE_CONTENT).getChildRef(); + this.nodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, + QName.createQName("{test}testnode"), ContentModel.TYPE_CONTENT).getChildRef(); // Get the executer instance. - this.executer = (NodeSizeDetailActionExecutor)this.applicationContext.getBean(NodeSizeDetailActionExecutor.NAME); + this.executer = (NodeSizeDetailActionExecutor) this.applicationContext.getBean(NodeSizeDetailActionExecutor.NAME); - simpleCache = (SimpleCache>) this.applicationContext.getBean("folderSizeSharedCache"); + simpleCache = (SimpleCache>) this.applicationContext.getBean("folderSizeSharedCache"); } /** @@ -109,7 +103,7 @@ public void testExecution() action.setParameterValue(NodeSizeDetailActionExecutor.DEFAULT_SIZE, maxItems); this.executer.executeImpl(action, this.nodeRef); Object resultAction = simpleCache.get(this.nodeRef.getId()); - Map mapResult = (Map)resultAction; - assertTrue(mapResult != null); + Map mapResult = (Map) resultAction; + assertNotNull(mapResult); } } \ No newline at end of file From 4c6633b7830a60ccbc68af0b09a9e91a6a1bc198 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 13 Sep 2024 01:10:34 +0530 Subject: [PATCH 197/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../alfresco/rest/api/impl/SizeDetailsImplTest.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index d510b144ed7..e13fa3b1e25 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -40,8 +40,6 @@ import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; import org.junit.Before; import org.junit.Test; @@ -56,7 +54,6 @@ public class SizeDetailsImplTest private static final QName TYPE_FOLDER = QName.createQName(NAMESPACE, "folder"); private SizeDetailsImpl sizeDetailsImpl; private Nodes nodes; - private NodeService nodeService; private ActionService actionService; private Action action; @@ -65,15 +62,11 @@ public void setUp() { sizeDetailsImpl = new SizeDetailsImpl(); nodes = mock(Nodes.class); - nodeService = mock(NodeService.class); - PermissionService permissionService = mock(PermissionService.class); actionService = mock(ActionService.class); action = mock(Action.class); SimpleCache> simpleCache = mock(SimpleCache.class); sizeDetailsImpl.setNodes(nodes); - sizeDetailsImpl.setNodeService(nodeService); - sizeDetailsImpl.setPermissionService(permissionService); sizeDetailsImpl.setActionService(actionService); sizeDetailsImpl.setSimpleCache(simpleCache); sizeDetailsImpl.setDefaultItems(DEFAULT_ITEMS); @@ -97,9 +90,8 @@ public void calculateNodeSizeDetails() node.setNodeType(TYPE_FOLDER.getLocalName()); node.setNodeId(nodeRef.getId()); - when(nodes.validateNode(nodeId)).thenReturn(nodeRef); + when(nodes.validateOrLookupNode(nodeId)).thenReturn(nodeRef); when(nodes.getNode(nodeId)).thenReturn(node); - when(nodeService.getType(nodeRef)).thenReturn(TYPE_FOLDER); when(actionService.createAction(NodeSizeDetailActionExecutor.NAME)).thenReturn(action); NodeSizeDetails requestSizeDetails = sizeDetailsImpl.generateNodeSizeDetailsRequest(nodeId); From 289011b6650c3819a99a93c1090f4009bd1a6797 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 13 Sep 2024 01:57:15 +0530 Subject: [PATCH 198/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../org/alfresco/rest/api/model/NodeSizeDetails.java | 6 +++--- .../org/alfresco/rest/api/impl/SizeDetailsImplTest.java | 3 ++- .../action/executer/NodeSizeDetailActionExecutor.java | 9 ++------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java index b3c1a5bc431..477d0be0d36 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java @@ -46,7 +46,7 @@ public NodeSizeDetails(String jobId) public NodeSizeDetails(String id, String currentStatus) { this.id = id; - NodeSizeDetails.status.valueOf(currentStatus); + NodeSizeDetails.STATUS.valueOf(currentStatus); } public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer numberOfFiles, String currentStatus, @@ -56,7 +56,7 @@ public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer n this.sizeInBytes = sizeInBytes; this.calculatedAt = calculatedAt; this.numberOfFiles = numberOfFiles; - NodeSizeDetails.status.valueOf(currentStatus); + NodeSizeDetails.STATUS.valueOf(currentStatus); this.jobId = jobId; } @@ -153,7 +153,7 @@ public String toString() + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + '}'; } - private enum status + private enum STATUS { NOT_INITIATED, PENDING, IN_PROGRESS, COMPLETED } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index e13fa3b1e25..4712e9b05d7 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -32,6 +32,7 @@ import java.io.Serializable; import java.util.Map; +import org.alfresco.model.ContentModel; import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutor; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.rest.api.Nodes; @@ -91,7 +92,7 @@ public void calculateNodeSizeDetails() node.setNodeId(nodeRef.getId()); when(nodes.validateOrLookupNode(nodeId)).thenReturn(nodeRef); - when(nodes.getNode(nodeId)).thenReturn(node); + when(nodes.isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)).thenReturn(true); when(actionService.createAction(NodeSizeDetailActionExecutor.NAME)).thenReturn(action); NodeSizeDetails requestSizeDetails = sizeDetailsImpl.generateNodeSizeDetailsRequest(nodeId); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java index 64ea947472d..bc756217557 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java @@ -170,17 +170,12 @@ public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) } LOG.debug(" Calculating size of Folder Node - NodeSizeDetailActionExecutor:executeImpl "); - final LocalDateTime eventTimestamp = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:mm:ss"); - String formattedTimestamp = eventTimestamp.format(formatter); - Date date = Calendar.getInstance() - .getTime(); - String dateStr = ISO8601DateFormat.format(date); + Date date = new Date(System.currentTimeMillis()); response.put("nodeId", nodeRef.getId()); response.put("size", totalSizeFromFacet); - response.put("calculatedAt", dateStr); + response.put("calculatedAt", date); response.put("numberOfFiles", results != null ? results.getNodeRefs() .size() : 0); response.put("actionId", nodeAction.getId()); From 1516ab9035565fd61455b51637adb2bfe950f838 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 13 Sep 2024 11:10:53 +0530 Subject: [PATCH 199/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../alfresco/rest/api/model/NodeSizeDetails.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java index 477d0be0d36..c243d99b072 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java @@ -37,6 +37,7 @@ public class NodeSizeDetails private Date calculatedAt; private Integer numberOfFiles; private String jobId; + private STATUS status; public NodeSizeDetails(String jobId) { @@ -46,7 +47,7 @@ public NodeSizeDetails(String jobId) public NodeSizeDetails(String id, String currentStatus) { this.id = id; - NodeSizeDetails.STATUS.valueOf(currentStatus); + this.status = STATUS.valueOf(currentStatus); } public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer numberOfFiles, String currentStatus, @@ -56,7 +57,7 @@ public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer n this.sizeInBytes = sizeInBytes; this.calculatedAt = calculatedAt; this.numberOfFiles = numberOfFiles; - NodeSizeDetails.STATUS.valueOf(currentStatus); + this.status = STATUS.valueOf(currentStatus); this.jobId = jobId; } @@ -123,6 +124,16 @@ public void setJobId(String jobId) this.jobId = jobId; } + public STATUS getStatus() + { + return status; + } + + public void setStatus(STATUS status) + { + this.status = status; + } + @Override public boolean equals(Object o) { From e1949ee572af051328fed7b27eadf7a558f2e033 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 13 Sep 2024 11:58:05 +0530 Subject: [PATCH 200/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../src/main/resources/alfresco/action-services-context.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/resources/alfresco/action-services-context.xml b/repository/src/main/resources/alfresco/action-services-context.xml index 506974d2715..e1b2149c071 100644 --- a/repository/src/main/resources/alfresco/action-services-context.xml +++ b/repository/src/main/resources/alfresco/action-services-context.xml @@ -790,7 +790,7 @@ - + From 0b8612de014caa49e81b05a56c380625b6169651 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 16 Sep 2024 15:09:57 +0530 Subject: [PATCH 201/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../java/org/alfresco/rest/api/impl/SizeDetailsImpl.java | 7 ++++--- .../resources/alfresco/project-remote-api.properties | 2 +- .../action/executer/NodeSizeDetailActionExecutor.java | 9 +-------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 966a9ec21f9..15677ad9e8f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -28,6 +28,7 @@ import static org.alfresco.rest.api.SizeDetails.ProcessingState.COMPLETED; import static org.alfresco.rest.api.SizeDetails.ProcessingState.IN_PROGRESS; import static org.alfresco.rest.api.SizeDetails.ProcessingState.NOT_INITIATED; +import static org.alfresco.rest.api.SizeDetails.ProcessingState.PENDING; import java.io.Serializable; import java.util.Date; @@ -41,7 +42,7 @@ import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; -import org.alfresco.rest.framework.core.exceptions.UnprocessableContentException; +import org.alfresco.rest.framework.core.exceptions.NotFoundException; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.NodeRef; @@ -119,7 +120,7 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI private String executeAction() { Map currentStatus = new HashMap<>(); - currentStatus.put("status",IN_PROGRESS.name()); + currentStatus.put("status",PENDING.name()); Action folderSizeAction = actionService.createAction(NodeSizeDetailActionExecutor.NAME); currentStatus.put(ACTION_ID,folderSizeAction.getId()); folderSizeAction.setTrackStatus(true); @@ -149,7 +150,7 @@ private NodeSizeDetails executorResultToSizeDetail(final Map res if (!nodeSizeDetails.getJobId() .equalsIgnoreCase(jobId)) { - throw new UnprocessableContentException("Invalid parameter: value of jobId is invalid"); + throw new NotFoundException("JobId does not exist"); } return nodeSizeDetails; } diff --git a/remote-api/src/main/resources/alfresco/project-remote-api.properties b/remote-api/src/main/resources/alfresco/project-remote-api.properties index 188c872461e..018c806e28e 100644 --- a/remote-api/src/main/resources/alfresco/project-remote-api.properties +++ b/remote-api/src/main/resources/alfresco/project-remote-api.properties @@ -25,6 +25,6 @@ alfresco.restApi.basicAuthScheme=false # REPO-4388 allow CORS headers in transaction response webscripts.transaction.preserveHeadersPattern=Access-Control-.* -#Default value being used in POT/calculate-folder-size endpoint to partition a huge folder into smaller chunks +#Default value being used in POST/size-details endpoint to partition a huge folder into smaller chunks #so that we can compute more efficiently and consolidate all sizes into a single unit. alfresco.restApi.calculateFolderSize.items=1000 \ No newline at end of file diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java index bc756217557..4bfaa9e1b09 100644 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java +++ b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java @@ -26,11 +26,6 @@ package org.alfresco.repo.action.executer; import java.io.Serializable; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -45,7 +40,6 @@ import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.util.ISO8601DateFormat; import org.alfresco.util.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -198,8 +192,7 @@ protected ResultSet facetQuery(NodeRef nodeRef) searchParameters.addFacetQuery(FACET_QUERY); final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); - ff.setLimitOrNull(resultsWithoutFacet.getNodeRefs() - .size()); + ff.setLimitOrNull((int) resultsWithoutFacet.getNumberFound()); searchParameters.addFieldFacet(ff); resultsWithoutFacet.close(); return searchService.query(searchParameters); From 5cd8ea2bac43763c0d3ab4b101f18a6ad8b2a535 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 16 Sep 2024 15:15:51 +0530 Subject: [PATCH 202/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../alfresco/rest/api/nodes/NodeSizeDetailsRelation.java | 7 ------- .../src/main/resources/alfresco/public-rest-context.xml | 1 - 2 files changed, 8 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index 537c322fd7c..2604b66bee5 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -26,7 +26,6 @@ package org.alfresco.rest.api.nodes; -import java.util.Collections; import java.util.List; import org.alfresco.rest.api.Nodes; @@ -49,14 +48,8 @@ public class NodeSizeDetailsRelation implements RelationshipResourceAction.ReadB RelationshipResourceAction.Create, InitializingBean { - private Nodes nodes; private SizeDetails sizeDetails; - public void setNodes(Nodes nodes) - { - this.nodes = nodes; - } - public void setSizeDetails(SizeDetails sizeDetails) { this.sizeDetails = sizeDetails; diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index da717df7451..e0bf0ca682c 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1793,7 +1793,6 @@ - From 8fa7f9c16ac9b80164a8d2ef8992d3b15bb59a85 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 16 Sep 2024 15:16:41 +0530 Subject: [PATCH 203/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java | 1 - 1 file changed, 1 deletion(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index 2604b66bee5..b90a5f9da1b 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -28,7 +28,6 @@ import java.util.List; -import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.framework.WebApiDescription; From 3b7601ff10332e560b774315e965e0ac76523d6a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 19 Sep 2024 09:17:28 +0530 Subject: [PATCH 204/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../org/alfresco/rest/api/SizeDetails.java | 2 +- .../rest/api/impl/SizeDetailsImpl.java | 104 ++--- .../rest/api/model/NodeSizeDetails.java | 172 -------- .../api/nodes/NodeSizeDetailsRelation.java | 2 +- .../alfresco/project-remote-api.properties | 6 +- .../alfresco/public-rest-context.xml | 3 +- .../rest/api/impl/SizeDetailsImplTest.java | 35 +- .../rest/api/tests/NodeSizeDetailsTest.java | 27 +- .../NodeSizeDetailActionExecutor.java | 209 ---------- .../repo/node/NodeSizeDetailsService.java | 379 ++++++++++++++++++ .../alfresco/action-services-context.xml | 5 - .../alfresco/node-services-context.xml | 24 +- .../resources/alfresco/repository.properties | 4 + .../org/alfresco/AppContext01TestSuite.java | 5 +- .../NodeSizeDetailsActionExecutorTest.java | 109 ----- 15 files changed, 478 insertions(+), 608 deletions(-) delete mode 100644 remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java delete mode 100644 repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java create mode 100644 repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java delete mode 100644 repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java index 3412f27d650..5c20d63e129 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java @@ -25,7 +25,7 @@ */ package org.alfresco.rest.api; -import org.alfresco.rest.api.model.NodeSizeDetails; +import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; public interface SizeDetails { diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 15677ad9e8f..c8006c982fe 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -25,55 +25,41 @@ */ package org.alfresco.rest.api.impl; -import static org.alfresco.rest.api.SizeDetails.ProcessingState.COMPLETED; -import static org.alfresco.rest.api.SizeDetails.ProcessingState.IN_PROGRESS; -import static org.alfresco.rest.api.SizeDetails.ProcessingState.NOT_INITIATED; -import static org.alfresco.rest.api.SizeDetails.ProcessingState.PENDING; - import java.io.Serializable; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; import org.alfresco.model.ContentModel; -import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutor; import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.node.NodeSizeDetailsService; +import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; +import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails.STATUS; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.SizeDetails; -import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.core.exceptions.NotFoundException; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.util.GUID; public class SizeDetailsImpl implements SizeDetails { - private static final String ACTION_ID = "actionId"; private Nodes nodes; private NodeRef nodeRef; - private ActionService actionService; - private SimpleCache> simpleCache; - private int defaultItems; + private SimpleCache simpleCache; + private NodeSizeDetailsService nodeSizeDetailsService; + private NodeSizeDetails nodeSizeDetails; public void setNodes(Nodes nodes) { this.nodes = nodes; } - public void setActionService(ActionService actionService) - { - this.actionService = actionService; - } - - public void setSimpleCache(SimpleCache> simpleCache) + public void setSimpleCache(SimpleCache simpleCache) { this.simpleCache = simpleCache; } - public void setDefaultItems(int defaultItems) + public void setNodeSizeDetailsService(NodeSizeDetailsService nodeSizeDetailsService) { - this.defaultItems = defaultItems; + this.nodeSizeDetailsService = nodeSizeDetailsService; } /** @@ -87,14 +73,14 @@ public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId) String actionId; if (!simpleCache.contains(nodeId)) { - actionId = executeAction(); + actionId = executeSizeDetails(); } else { - Map result = simpleCache.get(nodeRef.getId()); - actionId = (String) result.get(ACTION_ID); + nodeSizeDetails = simpleCache.get(nodeId); + actionId = nodeSizeDetails.getJobId(); } - return new NodeSizeDetails(actionId); + return new NodeSizeDetails(null, null, actionId, null); } /** @@ -108,56 +94,32 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI if (!simpleCache.contains(nodeId)) { - return new NodeSizeDetails(nodeId, NOT_INITIATED.name()); + nodeSizeDetails = new NodeSizeDetails(nodeId, null, null, STATUS.NOT_INITIATED); + return nodeSizeDetails; + } + else + { + nodeSizeDetails = simpleCache.get(nodeId); + String cachedJobId = nodeSizeDetails.getJobId(); + if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) + { + throw new NotFoundException("jobId does not exist"); + } } - return executorResultToSizeDetail(simpleCache.get(nodeId), nodeId, jobId); + return simpleCache.get(nodeId); } /** - * Executing Action Asynchronously. + * Executing Asynchronously. */ - private String executeAction() + private String executeSizeDetails() { - Map currentStatus = new HashMap<>(); - currentStatus.put("status",PENDING.name()); - Action folderSizeAction = actionService.createAction(NodeSizeDetailActionExecutor.NAME); - currentStatus.put(ACTION_ID,folderSizeAction.getId()); - folderSizeAction.setTrackStatus(true); - folderSizeAction.setParameterValue(NodeSizeDetailActionExecutor.DEFAULT_SIZE, defaultItems); - simpleCache.put(nodeRef.getId(),currentStatus); - actionService.executeAction(folderSizeAction, nodeRef, false, true); - return folderSizeAction.getId(); - } - - /** - * Converting action executor response to their respective model class. - */ - private NodeSizeDetails executorResultToSizeDetail(final Map result, String nodeId, String jobId) - { - if (result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION)) - { - return new NodeSizeDetails(nodeId, COMPLETED.name()); - } - - if (result.containsKey("size")) - { - NodeSizeDetails nodeSizeDetails = - new NodeSizeDetails((String) result.get("nodeId"), (Long) result.get("size"), - (Date) result.get("calculatedAt"), (Integer) result.get("numberOfFiles"), - COMPLETED.name(), (String) result.get(ACTION_ID)); - - if (!nodeSizeDetails.getJobId() - .equalsIgnoreCase(jobId)) - { - throw new NotFoundException("JobId does not exist"); - } - return nodeSizeDetails; - } - else - { - return new NodeSizeDetails(nodeId, IN_PROGRESS.name()); - } + String jobId = GUID.generate(); + nodeSizeDetailsService.invokeSizeDetailsExecutor(nodeRef, jobId); + nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.PENDING); + simpleCache.put(nodeRef.getId(), nodeSizeDetails); + return jobId; } private void validateType(NodeRef nodeRef) throws InvalidNodeTypeException diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java deleted file mode 100644 index c243d99b072..00000000000 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/NodeSizeDetails.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * #%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.model; - -import java.util.Date; -import java.util.Objects; - -import org.json.simple.JSONObject; - -public class NodeSizeDetails -{ - private String id; - private Long sizeInBytes; - private Date calculatedAt; - private Integer numberOfFiles; - private String jobId; - private STATUS status; - - public NodeSizeDetails(String jobId) - { - this.jobId = jobId; - } - - public NodeSizeDetails(String id, String currentStatus) - { - this.id = id; - this.status = STATUS.valueOf(currentStatus); - } - - public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer numberOfFiles, String currentStatus, - String jobId) - { - this.id = id; - this.sizeInBytes = sizeInBytes; - this.calculatedAt = calculatedAt; - this.numberOfFiles = numberOfFiles; - this.status = STATUS.valueOf(currentStatus); - this.jobId = jobId; - } - - public static String parseJson(JSONObject jsonObject) - { - if (jsonObject == null) - { - return null; - } - - String jobId = (String) jsonObject.get("jobId"); - jobId = jobId.replace("<", "") - .replace(">", ""); - return jobId; - } - - public String getId() - { - return id; - } - - public void setId(String id) - { - this.id = id; - } - - public Long getSizeInBytes() - { - return sizeInBytes; - } - - public void setSizeInBytes(Long sizeInBytes) - { - this.sizeInBytes = sizeInBytes; - } - - public Date getCalculatedAt() - { - return calculatedAt; - } - - public void setCalculatedAt(Date calculatedAt) - { - this.calculatedAt = calculatedAt; - } - - public Integer getNumberOfFiles() - { - return numberOfFiles; - } - - public void setNumberOfFiles(Integer numberOfFiles) - { - this.numberOfFiles = numberOfFiles; - } - - public String getJobId() - { - return jobId; - } - - public void setJobId(String jobId) - { - this.jobId = jobId; - } - - public STATUS getStatus() - { - return status; - } - - public void setStatus(STATUS status) - { - this.status = status; - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - NodeSizeDetails that = (NodeSizeDetails) o; - return Objects.equals(id, that.id) && Objects.equals(sizeInBytes, that.sizeInBytes) && Objects.equals( - calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) - && Objects.equals(jobId, that.jobId); - } - - @Override - public int hashCode() - { - return Objects.hash(id, sizeInBytes, calculatedAt, numberOfFiles, jobId); - } - - @Override - public String toString() - { - return "NodeSizeDetails{" + "id='" + id + '\'' + ", sizeInBytes=" + sizeInBytes + ", calculatedAt=" - + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + '}'; - } - - private enum STATUS - { - NOT_INITIATED, PENDING, IN_PROGRESS, COMPLETED - } - -} diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index b90a5f9da1b..f60259b04ab 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -28,8 +28,8 @@ import java.util.List; +import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; import org.alfresco.rest.api.SizeDetails; -import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.WebApiParameters; diff --git a/remote-api/src/main/resources/alfresco/project-remote-api.properties b/remote-api/src/main/resources/alfresco/project-remote-api.properties index 018c806e28e..c76b37a1c22 100644 --- a/remote-api/src/main/resources/alfresco/project-remote-api.properties +++ b/remote-api/src/main/resources/alfresco/project-remote-api.properties @@ -23,8 +23,4 @@ # See issue REPO-2575 for details. alfresco.restApi.basicAuthScheme=false # REPO-4388 allow CORS headers in transaction response -webscripts.transaction.preserveHeadersPattern=Access-Control-.* - -#Default value being used in POST/size-details endpoint to partition a huge folder into smaller chunks -#so that we can compute more efficiently and consolidate all sizes into a single unit. -alfresco.restApi.calculateFolderSize.items=1000 \ No newline at end of file +webscripts.transaction.preserveHeadersPattern=Access-Control-.* \ No newline at end of file diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index e0bf0ca682c..c0d8b5739cd 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -998,9 +998,8 @@ - - + diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 4712e9b05d7..33ee88f5780 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -30,17 +30,16 @@ import static org.mockito.Mockito.when; import java.io.Serializable; -import java.util.Map; +import java.util.concurrent.ThreadPoolExecutor; import org.alfresco.model.ContentModel; -import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutor; import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.node.NodeSizeDetailsService; +import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; -import org.alfresco.rest.api.model.NodeSizeDetails; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.namespace.QName; import org.junit.Before; import org.junit.Test; @@ -50,27 +49,33 @@ */ public class SizeDetailsImplTest { - private final static int DEFAULT_ITEMS = 1000; private static final String NAMESPACE = "http://www.alfresco.org/test/NodeSizeDetailsTest"; private static final QName TYPE_FOLDER = QName.createQName(NAMESPACE, "folder"); private SizeDetailsImpl sizeDetailsImpl; private Nodes nodes; - private ActionService actionService; - private Action action; + private NodeSizeDetailsService nodeSizeDetailsService; + private NodeSizeDetails nodeSizeDetails; + private SearchService searchService; + private ThreadPoolExecutor threadPoolExecutor; @Before public void setUp() { sizeDetailsImpl = new SizeDetailsImpl(); nodes = mock(Nodes.class); - actionService = mock(ActionService.class); - action = mock(Action.class); - SimpleCache> simpleCache = mock(SimpleCache.class); + searchService = mock(SearchService.class); + nodeSizeDetailsService = mock(NodeSizeDetailsService.class); + nodeSizeDetails = mock(NodeSizeDetails.class); + threadPoolExecutor = mock(ThreadPoolExecutor.class); + SimpleCache simpleCache = mock(SimpleCache.class); + nodeSizeDetailsService.setSearchService(searchService); + nodeSizeDetailsService.setDefaultItems(1000); + nodeSizeDetailsService.setSimpleCache(simpleCache); + nodeSizeDetailsService.setThreadPoolExecutor(threadPoolExecutor); sizeDetailsImpl.setNodes(nodes); - sizeDetailsImpl.setActionService(actionService); sizeDetailsImpl.setSimpleCache(simpleCache); - sizeDetailsImpl.setDefaultItems(DEFAULT_ITEMS); + sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsService); } @Test @@ -80,9 +85,6 @@ public void calculateNodeSizeDetails() String nodeId = "node-id"; String jobId = "job-id"; NodeRef nodeRef = new NodeRef("protocol", "identifier", nodeId); - action.setTrackStatus(true); - action.setExecuteAsynchronously(true); - action.setParameterValue(NodeSizeDetailActionExecutor.DEFAULT_SIZE, DEFAULT_ITEMS); Node node = new Node(); node.setIsFolder(true); @@ -93,7 +95,6 @@ public void calculateNodeSizeDetails() when(nodes.validateOrLookupNode(nodeId)).thenReturn(nodeRef); when(nodes.isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)).thenReturn(true); - when(actionService.createAction(NodeSizeDetailActionExecutor.NAME)).thenReturn(action); NodeSizeDetails requestSizeDetails = sizeDetailsImpl.generateNodeSizeDetailsRequest(nodeId); assertNotNull("After executing POST/size-details, it will provide with 202 status code", requestSizeDetails); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index a227b98ec29..555db5f8cf6 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -34,8 +34,8 @@ import java.util.List; import java.util.Map; +import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.model.NodeSizeDetails; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; @@ -65,7 +65,6 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest { private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsTest.class); - private Site userOneN1Site; private String folderId; private PermissionService permissionService; @@ -129,9 +128,11 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); - String jobId = NodeSizeDetails.parseJson((JSONObject) postResponse.getJsonResponse() - .get("entry")); + NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( + (JSONObject) postResponse.getJsonResponse() + .get("entry")); + String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); // Prepare parameters. @@ -144,10 +145,10 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); + nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails((JSONObject) getResponse.getJsonResponse() + .get("entry")); - assertTrue("We are not getting correct response " + getJsonResponse, - getJsonResponse.contains("size") || getJsonResponse.contains("status")); + assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); } @Test @@ -189,9 +190,11 @@ public void testPerformanceTesting() throws Exception assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); - String jobId = NodeSizeDetails.parseJson((JSONObject) postResponse.getJsonResponse() - .get("entry")); + NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( + (JSONObject) postResponse.getJsonResponse() + .get("entry")); + String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); // Prepare parameters. @@ -204,10 +207,10 @@ public void testPerformanceTesting() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - String getJsonResponse = String.valueOf(getResponse.getJsonResponse()); + nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails((JSONObject) getResponse.getJsonResponse() + .get("entry")); - assertTrue("We are not getting correct response " + getJsonResponse, - getJsonResponse.contains("size") || getJsonResponse.contains("status")); + assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); //current Time after executing GET/size-details LocalTime actualTime = LocalTime.now(); diff --git a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java b/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java deleted file mode 100644 index 4bfaa9e1b09..00000000000 --- a/repository/src/main/java/org/alfresco/repo/action/executer/NodeSizeDetailActionExecutor.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * 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.repo.action.executer; - -import java.io.Serializable; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.alfresco.repo.action.ParameterizedItemAbstractBase; -import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ParameterDefinition; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.SearchParameters; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.util.Pair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * NodeSizeDetailActionExecutor - * Executing Alfresco FTS Query to find size of Folder Node - */ - -public class NodeSizeDetailActionExecutor extends ActionExecuterAbstractBase -{ - - private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailActionExecutor.class); - - /** - * Action constants - */ - public static final String NAME = "folder-size"; - public static final String EXCEPTION = "Exception"; - - public static final String IN_PROGRESS = "IN_PROGRESS"; - public static final String DEFAULT_SIZE = "default-size"; - private static final String STATUS = "status"; - private static final String ACTION_ID = "actionId"; - private static final String FIELD_FACET = "content.size"; - private static final String FACET_QUERY = "content.size:[0 TO " + Integer.MAX_VALUE + "] \"label\": \"large\",\"group\":\"Size\""; - private SearchService searchService; - private SimpleCache> simpleCache; - - /** - * Set the search service - * - * @param searchService the search service - */ - public void setSearchService(SearchService searchService) - { - this.searchService = searchService; - } - - /** - * Set the simpleCache service - * - * @param simpleCache the cache service - */ - public void setSimpleCache(SimpleCache> simpleCache) - { - this.simpleCache = simpleCache; - } - - /** - * @see ActionExecuter#execute(Action, NodeRef) - */ - @Override - public void executeImpl(Action nodeAction, NodeRef actionedUponNodeRef) - { - Serializable serializable = nodeAction.getParameterValue(DEFAULT_SIZE); - int defaultItems; - Map response = new HashMap<>(); - response.put(STATUS, IN_PROGRESS); - response.put(ACTION_ID, nodeAction.getId()); - simpleCache.put(actionedUponNodeRef.getId(), response); - - try - { - defaultItems = Integer.parseInt(serializable.toString()); - } - catch (NumberFormatException numberFormatException) - { - LOG.error("Exception occurred while parsing String to INT: {} ", numberFormatException.getMessage()); - response.put(EXCEPTION, - "Exception occurred while parsing String to INT: {} " + numberFormatException.getMessage()); - simpleCache.put(actionedUponNodeRef.getId(), response); - throw numberFormatException; - } - - NodeRef nodeRef = actionedUponNodeRef; - long totalSizeFromFacet = 0; - int skipCount = 0; - ResultSet results; - int totalItems; - boolean isCalculationCompleted = false; - - try - { - // executing Alfresco FTS facet query. - results = facetQuery(nodeRef); - totalItems = Math.min(results.getFieldFacet(FIELD_FACET) - .size(), defaultItems); - - while (!isCalculationCompleted) - { - List> pairSizes = results.getFieldFacet(FIELD_FACET) - .subList(skipCount, totalItems); - long total = pairSizes.parallelStream() - .mapToLong(id -> Long.parseLong(id.getFirst()) * id.getSecond()) - .sum(); - - totalSizeFromFacet += total; - - if (results.getFieldFacet(FIELD_FACET) - .size() <= totalItems || results.getFieldFacet(FIELD_FACET) - .size() <= defaultItems) - { - isCalculationCompleted = true; - } - else - { - skipCount += defaultItems; - int remainingItems = results.getFieldFacet(FIELD_FACET) - .size() - totalItems; - totalItems += Math.min(remainingItems, defaultItems); - } - } - } - catch (RuntimeException runtimeException) - { - LOG.error("Exception occurred in NodeSizeDetailActionExecutor:results {} ", runtimeException.getMessage()); - response.put(EXCEPTION, "Exception occurred in NodeSizeDetailActionExecutor:results {} " - + runtimeException.getMessage()); - simpleCache.put(nodeRef.getId(), response); - throw runtimeException; - } - - LOG.debug(" Calculating size of Folder Node - NodeSizeDetailActionExecutor:executeImpl "); - - Date date = new Date(System.currentTimeMillis()); - - response.put("nodeId", nodeRef.getId()); - response.put("size", totalSizeFromFacet); - response.put("calculatedAt", date); - response.put("numberOfFiles", results != null ? results.getNodeRefs() - .size() : 0); - response.put("actionId", nodeAction.getId()); - - if (isCalculationCompleted) - { - simpleCache.put(nodeRef.getId(), response); - } - } - - protected ResultSet facetQuery(NodeRef nodeRef) - { - String query = "ANCESTOR:\"" + nodeRef + "\" AND TYPE:content"; - - SearchParameters searchParameters = new SearchParameters(); - searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - searchParameters.setQuery(query); - ResultSet resultsWithoutFacet = searchService.query(searchParameters); - - searchParameters.addFacetQuery(FACET_QUERY); - final SearchParameters.FieldFacet ff = new SearchParameters.FieldFacet(FIELD_FACET); - ff.setLimitOrNull((int) resultsWithoutFacet.getNumberFound()); - searchParameters.addFieldFacet(ff); - resultsWithoutFacet.close(); - return searchService.query(searchParameters); - } - - /** - * @see ParameterizedItemAbstractBase#addParameterDefinitions(List) - */ - @Override - protected void addParameterDefinitions(List paramList) - { - // Intentionally empty. - } -} \ No newline at end of file diff --git a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java new file mode 100644 index 00000000000..1a241bbf1dd --- /dev/null +++ b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java @@ -0,0 +1,379 @@ +/* + * #%L + * Alfresco Repository + * %% + * 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.repo.node; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.ThreadPoolExecutor; + +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails.STATUS; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.search.ResultSet; +import org.alfresco.service.cmr.search.SearchParameters; +import org.alfresco.service.cmr.search.SearchParameters.FieldFacet; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.Pair; +import org.alfresco.util.ParameterCheck; +import org.json.simple.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; + +import net.sf.acegisecurity.Authentication; + +/** + * NodeSizeDetailsService + * Executing Alfresco FTS Query to find size details of Folder Node + */ +public class NodeSizeDetailsService implements InitializingBean +{ + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsService.class); + private static final String FIELD_FACET = "content.size"; + private static final String FACET_QUERY = "content.size:[0 TO " + Integer.MAX_VALUE + "] \"label\": \"large\",\"group\":\"Size\""; + private SearchService searchService; + private SimpleCache simpleCache; + private TransactionService transactionService; + private ThreadPoolExecutor threadPoolExecutor; + private int defaultItems; + + public void setSearchService(SearchService searchService) + { + this.searchService = searchService; + } + + public void setSimpleCache(SimpleCache simpleCache) + { + this.simpleCache = simpleCache; + } + + public void setTransactionService(TransactionService transactionService) + { + this.transactionService = transactionService; + } + + public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor) + { + this.threadPoolExecutor = threadPoolExecutor; + } + + public void setDefaultItems(int defaultItems) + { + this.defaultItems = defaultItems; + } + + public void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId) + { + try + { + executeSizeCalculation(nodeRef, jobId); + } + catch (Exception e) + { + LOG.error("Exception occurred while executing invokeSizeDetailsExecutor method ", e); + } + + } + + private void executeSizeCalculation(NodeRef nodeRef, String jobId) + { + final Authentication fullAuthentication = AuthenticationUtil.getFullAuthentication(); + RetryingTransactionCallback executionCallback = () -> { + + try + { + return calculateTotalSizeFromFacet(nodeRef, jobId); + } + catch (Exception ex) + { + LOG.error("Exception occurred in executeSizeCalculation:RetryingTransactionCallback ", ex); + throw ex; + } + }; + + threadPoolExecutor.execute(() -> { + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.IN_PROGRESS); + simpleCache.put(nodeRef.getId(), nodeSizeDetails); + + try + { + AuthenticationUtil.setFullAuthentication(fullAuthentication); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); + nodeSizeDetails = AuthenticationUtil.runAs(() -> transactionService.getRetryingTransactionHelper() + .doInTransaction(executionCallback, true), AuthenticationUtil.getSystemUserName()); + } + catch (Exception e) + { + LOG.error("Exception occurred in executeSizeCalculation", e); + nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), 0L, jobId, STATUS.FAILED); + } + finally + { + simpleCache.put(nodeRef.getId(), nodeSizeDetails); + AuthenticationUtil.clearCurrentSecurityContext(); + } + }); + } + + private NodeSizeDetails calculateTotalSizeFromFacet(NodeRef nodeRef, String jobId) + { + long totalSizeFromFacet = 0; + int skipCount = 0; + int totalItems = defaultItems; + boolean isCalculationCompleted = false; + + try + { + ResultSet results = facetQuery(nodeRef); + LOG.debug(" Number of folder nodes found in results " + results.getNumberFound()); + + int resultsSize = results.getFieldFacet(FIELD_FACET) + .size(); + + while (!isCalculationCompleted) + { + List> facetPairs = results.getFieldFacet(FIELD_FACET) + .subList(skipCount, Math.min(totalItems, resultsSize)); + totalSizeFromFacet += facetPairs.parallelStream() + .mapToLong(pair -> Long.parseLong(pair.getFirst()) * pair.getSecond()) + .sum(); + + if (resultsSize <= totalItems || resultsSize <= defaultItems) + { + isCalculationCompleted = true; + } + else + { + skipCount += defaultItems; + resultsSize -= totalItems; + totalItems += Math.min(resultsSize, defaultItems); + } + } + Date calculationDate = new Date(System.currentTimeMillis()); + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), totalSizeFromFacet, calculationDate, + results.getNodeRefs() + .size(), STATUS.COMPLETED, jobId); + return nodeSizeDetails; + } + catch (Exception e) + { + LOG.error("Exception occurred while calculating total size from facet", e); + throw e; + } + } + + private ResultSet facetQuery(NodeRef nodeRef) + { + try + { + SearchParameters searchParameters = createSearchParameters(nodeRef); + ResultSet resultsWithoutFacet = searchService.query(searchParameters); + + LOG.debug(" After Executing query, no. of records " + resultsWithoutFacet.getNumberFound()); + + searchParameters.addFacetQuery(FACET_QUERY); + FieldFacet fieldFacet = new FieldFacet(FIELD_FACET); + fieldFacet.setLimitOrNull((int) resultsWithoutFacet.getNumberFound()); + searchParameters.addFieldFacet(fieldFacet); + resultsWithoutFacet.close(); + return searchService.query(searchParameters); + } + catch (Exception e) + { + LOG.error("Exception occurred while executing facetQuery ", e); + throw e; + } + } + + private SearchParameters createSearchParameters(NodeRef nodeRef) + { + SearchParameters searchParameters = new SearchParameters(); + searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); + searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); + searchParameters.setQuery("ANCESTOR:\"" + nodeRef + "\" AND TYPE:content"); + searchParameters.setTrackTotalHits(-1); + return searchParameters; + } + + @Override + public void afterPropertiesSet() throws Exception + { + ParameterCheck.mandatory("searchService", this.searchService); + ParameterCheck.mandatory("simpleCache", this.simpleCache); + ParameterCheck.mandatory("transactionService", this.transactionService); + ParameterCheck.mandatory("threadPoolExecutor", this.threadPoolExecutor); + } + + /** + * POJO class to hold node size details. + */ + public static class NodeSizeDetails implements Serializable + { + private static final long serialVersionUID = 1L; + private String id; + private Long sizeInBytes; + private Date calculatedAt; + private Integer numberOfFiles; + private String jobId; + private STATUS status; + + public NodeSizeDetails(String id, Long sizeInBytes, String jobId, STATUS status) + { + this.id = id; + this.sizeInBytes = sizeInBytes; + this.jobId = jobId; + this.status = status; + } + + public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer numberOfFiles, + STATUS currentStatus, String jobId) + { + this.id = id; + this.sizeInBytes = sizeInBytes; + this.calculatedAt = calculatedAt; + this.numberOfFiles = numberOfFiles; + this.status = currentStatus; + this.jobId = jobId; + } + + public static NodeSizeDetails parseNodeSizeDetails(JSONObject jsonObject) + { + if (jsonObject == null) + { + return null; + } + + String jobId = (String) jsonObject.get("jobId"); + String id = (String) jsonObject.get("id"); + STATUS status = (STATUS) jsonObject.get("status"); + Long sizeInBytes = (Long) jsonObject.get("sizeInBytes"); + return new NodeSizeDetails(id, sizeInBytes, jobId, status); + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public Long getSizeInBytes() + { + return sizeInBytes; + } + + public void setSizeInBytes(Long sizeInBytes) + { + this.sizeInBytes = sizeInBytes; + } + + public Date getCalculatedAt() + { + return calculatedAt; + } + + public void setCalculatedAt(Date calculatedAt) + { + this.calculatedAt = calculatedAt; + } + + public Integer getNumberOfFiles() + { + return numberOfFiles; + } + + public void setNumberOfFiles(Integer numberOfFiles) + { + this.numberOfFiles = numberOfFiles; + } + + public String getJobId() + { + return jobId; + } + + public void setJobId(String jobId) + { + this.jobId = jobId; + } + + public STATUS getStatus() + { + return status; + } + + public void setStatus(STATUS status) + { + this.status = status; + } + + @Override + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + NodeSizeDetails that = (NodeSizeDetails) o; + return Objects.equals(id, that.id) && Objects.equals(sizeInBytes, that.sizeInBytes) && Objects.equals( + calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) + && Objects.equals(jobId, that.jobId); + } + + @Override + public int hashCode() + { + return Objects.hash(id, sizeInBytes, calculatedAt, numberOfFiles, jobId); + } + + @Override + public String toString() + { + return "NodeSizeDetails{" + "id='" + id + '\'' + ", sizeInBytes=" + sizeInBytes + ", calculatedAt=" + + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + '}'; + } + + public enum STATUS + { + NOT_INITIATED, PENDING, IN_PROGRESS, COMPLETED, FAILED + } + + } + +} diff --git a/repository/src/main/resources/alfresco/action-services-context.xml b/repository/src/main/resources/alfresco/action-services-context.xml index e1b2149c071..632f0707bef 100644 --- a/repository/src/main/resources/alfresco/action-services-context.xml +++ b/repository/src/main/resources/alfresco/action-services-context.xml @@ -788,10 +788,5 @@ - - - - - diff --git a/repository/src/main/resources/alfresco/node-services-context.xml b/repository/src/main/resources/alfresco/node-services-context.xml index 518a674888b..3a00c1b24d5 100644 --- a/repository/src/main/resources/alfresco/node-services-context.xml +++ b/repository/src/main/resources/alfresco/node-services-context.xml @@ -330,6 +330,28 @@ - + + + + + defaultThreadPool + + + 5 + + + 10 + + + + + + + + + + + + diff --git a/repository/src/main/resources/alfresco/repository.properties b/repository/src/main/resources/alfresco/repository.properties index 2b7691cefa5..4f35a06dd17 100644 --- a/repository/src/main/resources/alfresco/repository.properties +++ b/repository/src/main/resources/alfresco/repository.properties @@ -1385,3 +1385,7 @@ scripts.execution.maxMemoryUsedInBytes=-1 # Number of instructions that will trigger the observer scripts.execution.observerInstructionCount=5000 + +#Default value being used in POST/size-details endpoint to partition a huge folder into smaller chunks +#so that we can compute more efficiently and consolidate all sizes into a single unit. +default.async.folder.items=1000 \ No newline at end of file diff --git a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java index 96241657224..147626480aa 100644 --- a/repository/src/test/java/org/alfresco/AppContext01TestSuite.java +++ b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2024 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -77,8 +77,7 @@ org.alfresco.repo.activities.feed.cleanup.FeedCleanerTestCaseSensitivity.class, org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class, org.alfresco.repo.admin.registry.RegistryServiceImplTest.class, - org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class, - org.alfresco.repo.action.executer.NodeSizeDetailsActionExecutorTest.class + org.alfresco.repo.bootstrap.DataDictionaryFolderTest.class }) public class AppContext01TestSuite { diff --git a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java b/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java deleted file mode 100644 index 637764d4a62..00000000000 --- a/repository/src/test/java/org/alfresco/repo/action/executer/NodeSizeDetailsActionExecutorTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * 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.repo.action.executer; - -import java.io.Serializable; -import java.util.Map; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.action.ActionImpl; -import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.BaseSpringTest; -import org.alfresco.util.GUID; -import org.junit.Before; -import org.junit.Test; -import org.springframework.transaction.annotation.Transactional; - -@Transactional -public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest -{ - /** - * Id used to identify the test action created - */ - private final static String ID = GUID.generate(); - /** - * The test node reference - */ - private NodeRef nodeRef; - /** - * The folder Size executer - */ - private NodeSizeDetailActionExecutor executer; - /** - * Set the simpleCache service - * - * @param simpleCache the cache service - */ - private SimpleCache> simpleCache; - - /** - * Called at the begining of all tests. - */ - @Before - public void before() throws Exception - { - NodeService nodeService = (NodeService) this.applicationContext.getBean("nodeService"); - StoreRef testStoreRef; - NodeRef rootNodeRef; - - AuthenticationComponent authenticationComponent = - (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); - authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); - - // Create the store and get the root node - testStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); - rootNodeRef = nodeService.getRootNode(testStoreRef); - - // Create the node used for tests - this.nodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, - QName.createQName("{test}testnode"), ContentModel.TYPE_CONTENT).getChildRef(); - - // Get the executer instance. - this.executer = (NodeSizeDetailActionExecutor) this.applicationContext.getBean(NodeSizeDetailActionExecutor.NAME); - - simpleCache = (SimpleCache>) this.applicationContext.getBean("folderSizeSharedCache"); - } - - /** - * Test execution. - */ - @Test - public void testExecution() - { - int maxItems = 1000; - ActionImpl action = new ActionImpl(null, ID, NodeSizeDetailActionExecutor.NAME, null); - action.setParameterValue(NodeSizeDetailActionExecutor.DEFAULT_SIZE, maxItems); - this.executer.executeImpl(action, this.nodeRef); - Object resultAction = simpleCache.get(this.nodeRef.getId()); - Map mapResult = (Map) resultAction; - assertNotNull(mapResult); - } -} \ No newline at end of file From 3450f9b2ee5ec7f03f175220fb9e95722513e31d Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 19 Sep 2024 09:53:04 +0530 Subject: [PATCH 205/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../alfresco/rest/api/impl/SizeDetailsImpl.java | 9 ++++----- .../rest/api/impl/SizeDetailsImplTest.java | 11 +++-------- .../alfresco/repo/node/NodeSizeDetailsService.java | 14 +++++++------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index c8006c982fe..2a32fde1441 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -45,7 +45,6 @@ public class SizeDetailsImpl implements SizeDetails private NodeRef nodeRef; private SimpleCache simpleCache; private NodeSizeDetailsService nodeSizeDetailsService; - private NodeSizeDetails nodeSizeDetails; public void setNodes(Nodes nodes) { @@ -77,7 +76,7 @@ public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId) } else { - nodeSizeDetails = simpleCache.get(nodeId); + NodeSizeDetails nodeSizeDetails = simpleCache.get(nodeId); actionId = nodeSizeDetails.getJobId(); } return new NodeSizeDetails(null, null, actionId, null); @@ -94,12 +93,12 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI if (!simpleCache.contains(nodeId)) { - nodeSizeDetails = new NodeSizeDetails(nodeId, null, null, STATUS.NOT_INITIATED); + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeId, null, null, STATUS.NOT_INITIATED); return nodeSizeDetails; } else { - nodeSizeDetails = simpleCache.get(nodeId); + NodeSizeDetails nodeSizeDetails = simpleCache.get(nodeId); String cachedJobId = nodeSizeDetails.getJobId(); if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) { @@ -117,7 +116,7 @@ private String executeSizeDetails() { String jobId = GUID.generate(); nodeSizeDetailsService.invokeSizeDetailsExecutor(nodeRef, jobId); - nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.PENDING); + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.PENDING); simpleCache.put(nodeRef.getId(), nodeSizeDetails); return jobId; } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 33ee88f5780..4c6eb9d4aaf 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -53,20 +53,15 @@ public class SizeDetailsImplTest private static final QName TYPE_FOLDER = QName.createQName(NAMESPACE, "folder"); private SizeDetailsImpl sizeDetailsImpl; private Nodes nodes; - private NodeSizeDetailsService nodeSizeDetailsService; - private NodeSizeDetails nodeSizeDetails; - private SearchService searchService; - private ThreadPoolExecutor threadPoolExecutor; @Before public void setUp() { sizeDetailsImpl = new SizeDetailsImpl(); nodes = mock(Nodes.class); - searchService = mock(SearchService.class); - nodeSizeDetailsService = mock(NodeSizeDetailsService.class); - nodeSizeDetails = mock(NodeSizeDetails.class); - threadPoolExecutor = mock(ThreadPoolExecutor.class); + SearchService searchService = mock(SearchService.class); + NodeSizeDetailsService nodeSizeDetailsService = mock(NodeSizeDetailsService.class); + ThreadPoolExecutor threadPoolExecutor = mock(ThreadPoolExecutor.class); SimpleCache simpleCache = mock(SimpleCache.class); nodeSizeDetailsService.setSearchService(searchService); diff --git a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java index 1a241bbf1dd..cc04d94ae42 100644 --- a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java +++ b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java @@ -154,8 +154,6 @@ private NodeSizeDetails calculateTotalSizeFromFacet(NodeRef nodeRef, String jobI try { ResultSet results = facetQuery(nodeRef); - LOG.debug(" Number of folder nodes found in results " + results.getNumberFound()); - int resultsSize = results.getFieldFacet(FIELD_FACET) .size(); @@ -197,8 +195,10 @@ private ResultSet facetQuery(NodeRef nodeRef) { SearchParameters searchParameters = createSearchParameters(nodeRef); ResultSet resultsWithoutFacet = searchService.query(searchParameters); - - LOG.debug(" After Executing query, no. of records " + resultsWithoutFacet.getNumberFound()); + if (LOG.isDebugEnabled()) + { + LOG.debug(" After Executing facet query, no. of records found " + resultsWithoutFacet.getNumberFound()); + } searchParameters.addFacetQuery(FACET_QUERY); FieldFacet fieldFacet = new FieldFacet(FIELD_FACET); @@ -274,9 +274,9 @@ public static NodeSizeDetails parseNodeSizeDetails(JSONObject jsonObject) String jobId = (String) jsonObject.get("jobId"); String id = (String) jsonObject.get("id"); - STATUS status = (STATUS) jsonObject.get("status"); - Long sizeInBytes = (Long) jsonObject.get("sizeInBytes"); - return new NodeSizeDetails(id, sizeInBytes, jobId, status); + String status = (String) jsonObject.get("status"); + String sizeInBytes = (String) jsonObject.get("sizeInBytes"); + return new NodeSizeDetails(id, Long.parseLong(sizeInBytes), jobId, STATUS.valueOf(status)); } public String getId() From 6aaffe4efcacea5ad9ec41f6907d7552859cf417 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 19 Sep 2024 10:18:49 +0530 Subject: [PATCH 206/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../java/org/alfresco/repo/node/NodeSizeDetailsService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java index cc04d94ae42..8d3f877537c 100644 --- a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java +++ b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java @@ -276,7 +276,9 @@ public static NodeSizeDetails parseNodeSizeDetails(JSONObject jsonObject) String id = (String) jsonObject.get("id"); String status = (String) jsonObject.get("status"); String sizeInBytes = (String) jsonObject.get("sizeInBytes"); - return new NodeSizeDetails(id, Long.parseLong(sizeInBytes), jobId, STATUS.valueOf(status)); + return new NodeSizeDetails(id, sizeInBytes != null + ? Long.parseLong(sizeInBytes) + : 0L, jobId, STATUS.valueOf(status)); } public String getId() From 76239a92ca0cb4e04006ea654e72959847488dc6 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 19 Sep 2024 10:53:08 +0530 Subject: [PATCH 207/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../rest/api/tests/NodeSizeDetailsTest.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 555db5f8cf6..8fa9076b8f8 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -128,11 +128,10 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); - NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( - (JSONObject) postResponse.getJsonResponse() - .get("entry")); + JSONObject jsonObject = (JSONObject) postResponse.getJsonResponse() + .get("entry"); - String jobId = nodeSizeDetails.getJobId(); + String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); // Prepare parameters. @@ -145,7 +144,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails((JSONObject) getResponse.getJsonResponse() + NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails((JSONObject) getResponse.getJsonResponse() .get("entry")); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); @@ -190,11 +189,10 @@ public void testPerformanceTesting() throws Exception assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); - NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( - (JSONObject) postResponse.getJsonResponse() - .get("entry")); + JSONObject jsonObject = (JSONObject) postResponse.getJsonResponse() + .get("entry"); - String jobId = nodeSizeDetails.getJobId(); + String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); // Prepare parameters. @@ -207,7 +205,7 @@ public void testPerformanceTesting() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails((JSONObject) getResponse.getJsonResponse() + NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails((JSONObject) getResponse.getJsonResponse() .get("entry")); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); From 269a621bfef224363aa9effd6f83b16c82d160ef Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 19 Sep 2024 11:15:33 +0530 Subject: [PATCH 208/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../java/org/alfresco/repo/node/NodeSizeDetailsService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java index 8d3f877537c..1eacdc6e7c1 100644 --- a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java +++ b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java @@ -275,9 +275,9 @@ public static NodeSizeDetails parseNodeSizeDetails(JSONObject jsonObject) String jobId = (String) jsonObject.get("jobId"); String id = (String) jsonObject.get("id"); String status = (String) jsonObject.get("status"); - String sizeInBytes = (String) jsonObject.get("sizeInBytes"); + Long sizeInBytes = (Long) jsonObject.get("sizeInBytes"); return new NodeSizeDetails(id, sizeInBytes != null - ? Long.parseLong(sizeInBytes) + ? sizeInBytes : 0L, jobId, STATUS.valueOf(status)); } From 4fa084b25b73b9011f33f18598a8375ed7b80d10 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 19 Sep 2024 17:36:58 +0530 Subject: [PATCH 209/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../org/alfresco/rest/api/SizeDetails.java | 6 +- .../rest/api/impl/SizeDetailsImpl.java | 22 +- .../api/nodes/NodeSizeDetailsRelation.java | 2 +- .../alfresco/public-rest-context.xml | 3 +- .../rest/api/impl/SizeDetailsImplTest.java | 23 +- .../rest/api/tests/NodeSizeDetailsTest.java | 2 +- .../repo/node/NodeSizeDetailsService.java | 351 +----------------- .../alfresco/node-services-context.xml | 13 +- 8 files changed, 48 insertions(+), 374 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java index 5c20d63e129..f9afe7a10c4 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java @@ -25,7 +25,7 @@ */ package org.alfresco.rest.api; -import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; +import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; public interface SizeDetails { @@ -33,8 +33,4 @@ public interface SizeDetails NodeSizeDetails getNodeSizeDetails(String nodeId, String jobId); - enum ProcessingState - { - NOT_INITIATED, PENDING, IN_PROGRESS, COMPLETED - } } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 2a32fde1441..006ac10f98e 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -30,16 +30,18 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.node.NodeSizeDetailsService; -import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; -import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails.STATUS; +import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; import org.alfresco.rest.framework.core.exceptions.NotFoundException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.util.GUID; +import org.alfresco.util.ParameterCheck; +import org.springframework.beans.factory.InitializingBean; -public class SizeDetailsImpl implements SizeDetails +public class SizeDetailsImpl implements SizeDetails, InitializingBean { private Nodes nodes; private NodeRef nodeRef; @@ -51,11 +53,6 @@ public void setNodes(Nodes nodes) this.nodes = nodes; } - public void setSimpleCache(SimpleCache simpleCache) - { - this.simpleCache = simpleCache; - } - public void setNodeSizeDetailsService(NodeSizeDetailsService nodeSizeDetailsService) { this.nodeSizeDetailsService = nodeSizeDetailsService; @@ -128,4 +125,13 @@ private void validateType(NodeRef nodeRef) throws InvalidNodeTypeException throw new InvalidNodeTypeException("Invalid parameter: value of nodeId is invalid"); } } + + @Override + public void afterPropertiesSet() throws Exception + { + ParameterCheck.mandatory("nodes", this.nodes); + ParameterCheck.mandatory("nodeSizeDetailsServiceImpl", this.nodeSizeDetailsService); + this.simpleCache = nodeSizeDetailsService.getSimpleCache(); + } + } \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index f60259b04ab..08220f8da50 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -28,7 +28,7 @@ import java.util.List; -import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; +import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index c0d8b5739cd..a3e18b81c84 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -998,8 +998,7 @@ - - + diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 4c6eb9d4aaf..9cf5fbd2b4e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -27,6 +27,7 @@ import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.Serializable; @@ -34,8 +35,8 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.NodeSizeDetailsService; -import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; +import org.alfresco.repo.node.NodeSizeDetailsServiceImpl; +import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; import org.alfresco.service.cmr.repository.NodeRef; @@ -55,22 +56,24 @@ public class SizeDetailsImplTest private Nodes nodes; @Before - public void setUp() + public void setUp() throws Exception { sizeDetailsImpl = new SizeDetailsImpl(); nodes = mock(Nodes.class); SearchService searchService = mock(SearchService.class); - NodeSizeDetailsService nodeSizeDetailsService = mock(NodeSizeDetailsService.class); + NodeSizeDetailsServiceImpl nodeSizeDetailsServiceImpl = mock(NodeSizeDetailsServiceImpl.class); ThreadPoolExecutor threadPoolExecutor = mock(ThreadPoolExecutor.class); SimpleCache simpleCache = mock(SimpleCache.class); - nodeSizeDetailsService.setSearchService(searchService); - nodeSizeDetailsService.setDefaultItems(1000); - nodeSizeDetailsService.setSimpleCache(simpleCache); - nodeSizeDetailsService.setThreadPoolExecutor(threadPoolExecutor); + nodeSizeDetailsServiceImpl.setSearchService(searchService); + nodeSizeDetailsServiceImpl.setDefaultItems(1000); + nodeSizeDetailsServiceImpl.setSimpleCache(simpleCache); + nodeSizeDetailsServiceImpl.setThreadPoolExecutor(threadPoolExecutor); sizeDetailsImpl.setNodes(nodes); - sizeDetailsImpl.setSimpleCache(simpleCache); - sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsService); + sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsServiceImpl); + when(nodeSizeDetailsServiceImpl.getSimpleCache()).thenReturn(simpleCache); + sizeDetailsImpl.afterPropertiesSet(); + verify(nodeSizeDetailsServiceImpl).setSimpleCache(simpleCache); } @Test diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 8fa9076b8f8..19ef4ec1f7d 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -34,7 +34,7 @@ import java.util.List; import java.util.Map; -import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails; +import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; diff --git a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java index 1eacdc6e7c1..df10828fac7 100644 --- a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java +++ b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java @@ -1,6 +1,6 @@ /* * #%L - * Alfresco Repository + * Alfresco Remote API * %% * Copyright (C) 2005 - 2024 Alfresco Software Limited * %% @@ -26,356 +26,15 @@ package org.alfresco.repo.node; import java.io.Serializable; -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.ThreadPoolExecutor; import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.NodeSizeDetailsService.NodeSizeDetails.STATUS; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.SearchParameters; -import org.alfresco.service.cmr.search.SearchParameters.FieldFacet; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.util.Pair; -import org.alfresco.util.ParameterCheck; -import org.json.simple.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.InitializingBean; -import net.sf.acegisecurity.Authentication; - -/** - * NodeSizeDetailsService - * Executing Alfresco FTS Query to find size details of Folder Node - */ -public class NodeSizeDetailsService implements InitializingBean +public interface NodeSizeDetailsService { - private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsService.class); - private static final String FIELD_FACET = "content.size"; - private static final String FACET_QUERY = "content.size:[0 TO " + Integer.MAX_VALUE + "] \"label\": \"large\",\"group\":\"Size\""; - private SearchService searchService; - private SimpleCache simpleCache; - private TransactionService transactionService; - private ThreadPoolExecutor threadPoolExecutor; - private int defaultItems; - - public void setSearchService(SearchService searchService) - { - this.searchService = searchService; - } - - public void setSimpleCache(SimpleCache simpleCache) - { - this.simpleCache = simpleCache; - } - - public void setTransactionService(TransactionService transactionService) - { - this.transactionService = transactionService; - } - - public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor) - { - this.threadPoolExecutor = threadPoolExecutor; - } - - public void setDefaultItems(int defaultItems) - { - this.defaultItems = defaultItems; - } - - public void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId) - { - try - { - executeSizeCalculation(nodeRef, jobId); - } - catch (Exception e) - { - LOG.error("Exception occurred while executing invokeSizeDetailsExecutor method ", e); - } - - } - - private void executeSizeCalculation(NodeRef nodeRef, String jobId) - { - final Authentication fullAuthentication = AuthenticationUtil.getFullAuthentication(); - RetryingTransactionCallback executionCallback = () -> { - - try - { - return calculateTotalSizeFromFacet(nodeRef, jobId); - } - catch (Exception ex) - { - LOG.error("Exception occurred in executeSizeCalculation:RetryingTransactionCallback ", ex); - throw ex; - } - }; - - threadPoolExecutor.execute(() -> { - NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.IN_PROGRESS); - simpleCache.put(nodeRef.getId(), nodeSizeDetails); - - try - { - AuthenticationUtil.setFullAuthentication(fullAuthentication); - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - nodeSizeDetails = AuthenticationUtil.runAs(() -> transactionService.getRetryingTransactionHelper() - .doInTransaction(executionCallback, true), AuthenticationUtil.getSystemUserName()); - } - catch (Exception e) - { - LOG.error("Exception occurred in executeSizeCalculation", e); - nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), 0L, jobId, STATUS.FAILED); - } - finally - { - simpleCache.put(nodeRef.getId(), nodeSizeDetails); - AuthenticationUtil.clearCurrentSecurityContext(); - } - }); - } - - private NodeSizeDetails calculateTotalSizeFromFacet(NodeRef nodeRef, String jobId) - { - long totalSizeFromFacet = 0; - int skipCount = 0; - int totalItems = defaultItems; - boolean isCalculationCompleted = false; - - try - { - ResultSet results = facetQuery(nodeRef); - int resultsSize = results.getFieldFacet(FIELD_FACET) - .size(); - - while (!isCalculationCompleted) - { - List> facetPairs = results.getFieldFacet(FIELD_FACET) - .subList(skipCount, Math.min(totalItems, resultsSize)); - totalSizeFromFacet += facetPairs.parallelStream() - .mapToLong(pair -> Long.parseLong(pair.getFirst()) * pair.getSecond()) - .sum(); - - if (resultsSize <= totalItems || resultsSize <= defaultItems) - { - isCalculationCompleted = true; - } - else - { - skipCount += defaultItems; - resultsSize -= totalItems; - totalItems += Math.min(resultsSize, defaultItems); - } - } - Date calculationDate = new Date(System.currentTimeMillis()); - NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), totalSizeFromFacet, calculationDate, - results.getNodeRefs() - .size(), STATUS.COMPLETED, jobId); - return nodeSizeDetails; - } - catch (Exception e) - { - LOG.error("Exception occurred while calculating total size from facet", e); - throw e; - } - } - - private ResultSet facetQuery(NodeRef nodeRef) - { - try - { - SearchParameters searchParameters = createSearchParameters(nodeRef); - ResultSet resultsWithoutFacet = searchService.query(searchParameters); - if (LOG.isDebugEnabled()) - { - LOG.debug(" After Executing facet query, no. of records found " + resultsWithoutFacet.getNumberFound()); - } - - searchParameters.addFacetQuery(FACET_QUERY); - FieldFacet fieldFacet = new FieldFacet(FIELD_FACET); - fieldFacet.setLimitOrNull((int) resultsWithoutFacet.getNumberFound()); - searchParameters.addFieldFacet(fieldFacet); - resultsWithoutFacet.close(); - return searchService.query(searchParameters); - } - catch (Exception e) - { - LOG.error("Exception occurred while executing facetQuery ", e); - throw e; - } - } - - private SearchParameters createSearchParameters(NodeRef nodeRef) - { - SearchParameters searchParameters = new SearchParameters(); - searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - searchParameters.setQuery("ANCESTOR:\"" + nodeRef + "\" AND TYPE:content"); - searchParameters.setTrackTotalHits(-1); - return searchParameters; - } - - @Override - public void afterPropertiesSet() throws Exception - { - ParameterCheck.mandatory("searchService", this.searchService); - ParameterCheck.mandatory("simpleCache", this.simpleCache); - ParameterCheck.mandatory("transactionService", this.transactionService); - ParameterCheck.mandatory("threadPoolExecutor", this.threadPoolExecutor); - } - - /** - * POJO class to hold node size details. - */ - public static class NodeSizeDetails implements Serializable - { - private static final long serialVersionUID = 1L; - private String id; - private Long sizeInBytes; - private Date calculatedAt; - private Integer numberOfFiles; - private String jobId; - private STATUS status; - - public NodeSizeDetails(String id, Long sizeInBytes, String jobId, STATUS status) - { - this.id = id; - this.sizeInBytes = sizeInBytes; - this.jobId = jobId; - this.status = status; - } - - public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer numberOfFiles, - STATUS currentStatus, String jobId) - { - this.id = id; - this.sizeInBytes = sizeInBytes; - this.calculatedAt = calculatedAt; - this.numberOfFiles = numberOfFiles; - this.status = currentStatus; - this.jobId = jobId; - } - - public static NodeSizeDetails parseNodeSizeDetails(JSONObject jsonObject) - { - if (jsonObject == null) - { - return null; - } - - String jobId = (String) jsonObject.get("jobId"); - String id = (String) jsonObject.get("id"); - String status = (String) jsonObject.get("status"); - Long sizeInBytes = (Long) jsonObject.get("sizeInBytes"); - return new NodeSizeDetails(id, sizeInBytes != null - ? sizeInBytes - : 0L, jobId, STATUS.valueOf(status)); - } - - public String getId() - { - return id; - } - - public void setId(String id) - { - this.id = id; - } - - public Long getSizeInBytes() - { - return sizeInBytes; - } - - public void setSizeInBytes(Long sizeInBytes) - { - this.sizeInBytes = sizeInBytes; - } - - public Date getCalculatedAt() - { - return calculatedAt; - } - - public void setCalculatedAt(Date calculatedAt) - { - this.calculatedAt = calculatedAt; - } - - public Integer getNumberOfFiles() - { - return numberOfFiles; - } - - public void setNumberOfFiles(Integer numberOfFiles) - { - this.numberOfFiles = numberOfFiles; - } - - public String getJobId() - { - return jobId; - } - - public void setJobId(String jobId) - { - this.jobId = jobId; - } - - public STATUS getStatus() - { - return status; - } - - public void setStatus(STATUS status) - { - this.status = status; - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - NodeSizeDetails that = (NodeSizeDetails) o; - return Objects.equals(id, that.id) && Objects.equals(sizeInBytes, that.sizeInBytes) && Objects.equals( - calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) - && Objects.equals(jobId, that.jobId); - } - - @Override - public int hashCode() - { - return Objects.hash(id, sizeInBytes, calculatedAt, numberOfFiles, jobId); - } - - @Override - public String toString() - { - return "NodeSizeDetails{" + "id='" + id + '\'' + ", sizeInBytes=" + sizeInBytes + ", calculatedAt=" - + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + '}'; - } - - public enum STATUS - { - NOT_INITIATED, PENDING, IN_PROGRESS, COMPLETED, FAILED - } + void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId); - } + SimpleCache getSimpleCache(); } diff --git a/repository/src/main/resources/alfresco/node-services-context.xml b/repository/src/main/resources/alfresco/node-services-context.xml index 3a00c1b24d5..6040282f546 100644 --- a/repository/src/main/resources/alfresco/node-services-context.xml +++ b/repository/src/main/resources/alfresco/node-services-context.xml @@ -344,7 +344,7 @@ - + @@ -353,5 +353,16 @@ + + + + NodeSizeDetailsServiceImpl + + + + org.alfresco.repo.node.NodeSizeDetailsService + + + From cc612bfb57f374a6843f630bda02b33bee9af6ad Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 19 Sep 2024 17:37:30 +0530 Subject: [PATCH 210/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../repo/node/NodeSizeDetailsServiceImpl.java | 384 ++++++++++++++++++ 1 file changed, 384 insertions(+) create mode 100644 repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java diff --git a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java new file mode 100644 index 00000000000..56dffff5b29 --- /dev/null +++ b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java @@ -0,0 +1,384 @@ +/* + * #%L + * Alfresco Repository + * %% + * 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.repo.node; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.ThreadPoolExecutor; + +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.search.ResultSet; +import org.alfresco.service.cmr.search.SearchParameters; +import org.alfresco.service.cmr.search.SearchParameters.FieldFacet; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.Pair; +import org.alfresco.util.ParameterCheck; +import org.json.simple.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; + +import net.sf.acegisecurity.Authentication; + +/** + * NodeSizeDetailsServiceImpl + * Executing Alfresco FTS Query to find size details of Folder Node + */ +public class NodeSizeDetailsServiceImpl implements NodeSizeDetailsService, InitializingBean +{ + private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsServiceImpl.class); + private static final String FIELD_FACET = "content.size"; + private static final String FACET_QUERY = "content.size:[0 TO " + Integer.MAX_VALUE + "] \"label\": \"large\",\"group\":\"Size\""; + private SearchService searchService; + private SimpleCache simpleCache; + private TransactionService transactionService; + private ThreadPoolExecutor threadPoolExecutor; + private int defaultItems; + + public void setSearchService(SearchService searchService) + { + this.searchService = searchService; + } + + public SimpleCache getSimpleCache() + { + return simpleCache; + } + + public void setSimpleCache(SimpleCache simpleCache) + { + this.simpleCache = simpleCache; + } + + public void setTransactionService(TransactionService transactionService) + { + this.transactionService = transactionService; + } + + public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor) + { + this.threadPoolExecutor = threadPoolExecutor; + } + + public void setDefaultItems(int defaultItems) + { + this.defaultItems = defaultItems; + } + + public void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId) + { + try + { + executeSizeCalculation(nodeRef, jobId); + } + catch (Exception e) + { + LOG.error("Exception occurred while executing invokeSizeDetailsExecutor method ", e); + } + + } + + private void executeSizeCalculation(NodeRef nodeRef, String jobId) + { + final Authentication fullAuthentication = AuthenticationUtil.getFullAuthentication(); + RetryingTransactionCallback executionCallback = () -> { + + try + { + return calculateTotalSizeFromFacet(nodeRef, jobId); + } + catch (Exception ex) + { + LOG.error("Exception occurred in executeSizeCalculation:RetryingTransactionCallback ", ex); + throw ex; + } + }; + + threadPoolExecutor.execute(() -> { + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.IN_PROGRESS); + simpleCache.put(nodeRef.getId(), nodeSizeDetails); + + try + { + AuthenticationUtil.setFullAuthentication(fullAuthentication); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); + nodeSizeDetails = AuthenticationUtil.runAs(() -> transactionService.getRetryingTransactionHelper() + .doInTransaction(executionCallback, true), AuthenticationUtil.getSystemUserName()); + } + catch (Exception e) + { + LOG.error("Exception occurred in executeSizeCalculation", e); + nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), 0L, jobId, STATUS.FAILED); + } + finally + { + simpleCache.put(nodeRef.getId(), nodeSizeDetails); + AuthenticationUtil.clearCurrentSecurityContext(); + } + }); + } + + private NodeSizeDetails calculateTotalSizeFromFacet(NodeRef nodeRef, String jobId) + { + long totalSizeFromFacet = 0; + int skipCount = 0; + int totalItems = defaultItems; + boolean isCalculationCompleted = false; + + try + { + ResultSet results = facetQuery(nodeRef); + int resultsSize = results.getFieldFacet(FIELD_FACET) + .size(); + + while (!isCalculationCompleted) + { + List> facetPairs = results.getFieldFacet(FIELD_FACET) + .subList(skipCount, Math.min(totalItems, resultsSize)); + totalSizeFromFacet += facetPairs.parallelStream() + .mapToLong(pair -> Long.parseLong(pair.getFirst()) * pair.getSecond()) + .sum(); + + if (resultsSize <= totalItems || resultsSize <= defaultItems) + { + isCalculationCompleted = true; + } + else + { + skipCount += defaultItems; + resultsSize -= totalItems; + totalItems += Math.min(resultsSize, defaultItems); + } + } + Date calculationDate = new Date(System.currentTimeMillis()); + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), totalSizeFromFacet, calculationDate, + results.getNodeRefs() + .size(), STATUS.COMPLETED, jobId); + return nodeSizeDetails; + } + catch (Exception e) + { + LOG.error("Exception occurred while calculating total size from facet", e); + throw e; + } + } + + private ResultSet facetQuery(NodeRef nodeRef) + { + try + { + SearchParameters searchParameters = createSearchParameters(nodeRef); + ResultSet resultsWithoutFacet = searchService.query(searchParameters); + if (LOG.isDebugEnabled()) + { + LOG.debug(" After Executing facet query, no. of records found " + resultsWithoutFacet.getNumberFound()); + } + + searchParameters.addFacetQuery(FACET_QUERY); + FieldFacet fieldFacet = new FieldFacet(FIELD_FACET); + fieldFacet.setLimitOrNull((int) resultsWithoutFacet.getNumberFound()); + searchParameters.addFieldFacet(fieldFacet); + resultsWithoutFacet.close(); + return searchService.query(searchParameters); + } + catch (Exception e) + { + LOG.error("Exception occurred while executing facetQuery ", e); + throw e; + } + } + + private SearchParameters createSearchParameters(NodeRef nodeRef) + { + SearchParameters searchParameters = new SearchParameters(); + searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); + searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); + searchParameters.setQuery("ANCESTOR:\"" + nodeRef + "\" AND TYPE:content"); + searchParameters.setTrackTotalHits(-1); + return searchParameters; + } + + @Override + public void afterPropertiesSet() throws Exception + { + ParameterCheck.mandatory("searchService", this.searchService); + ParameterCheck.mandatory("simpleCache", this.simpleCache); + ParameterCheck.mandatory("transactionService", this.transactionService); + ParameterCheck.mandatory("threadPoolExecutor", this.threadPoolExecutor); + } + + /** + * POJO class to hold node size details. + */ + public static class NodeSizeDetails implements Serializable + { + private static final long serialVersionUID = 1L; + private String id; + private Long sizeInBytes; + private Date calculatedAt; + private Integer numberOfFiles; + private String jobId; + private STATUS status; + + public NodeSizeDetails(String id, Long sizeInBytes, String jobId, STATUS status) + { + this.id = id; + this.sizeInBytes = sizeInBytes; + this.jobId = jobId; + this.status = status; + } + + public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer numberOfFiles, + STATUS currentStatus, String jobId) + { + this.id = id; + this.sizeInBytes = sizeInBytes; + this.calculatedAt = calculatedAt; + this.numberOfFiles = numberOfFiles; + this.status = currentStatus; + this.jobId = jobId; + } + + public static NodeSizeDetails parseNodeSizeDetails(JSONObject jsonObject) + { + if (jsonObject == null) + { + return null; + } + + String jobId = (String) jsonObject.get("jobId"); + String id = (String) jsonObject.get("id"); + String status = (String) jsonObject.get("status"); + Long sizeInBytes = (Long) jsonObject.get("sizeInBytes"); + return new NodeSizeDetails(id, sizeInBytes != null ? sizeInBytes : 0L, jobId, STATUS.valueOf(status)); + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public Long getSizeInBytes() + { + return sizeInBytes; + } + + public void setSizeInBytes(Long sizeInBytes) + { + this.sizeInBytes = sizeInBytes; + } + + public Date getCalculatedAt() + { + return calculatedAt; + } + + public void setCalculatedAt(Date calculatedAt) + { + this.calculatedAt = calculatedAt; + } + + public Integer getNumberOfFiles() + { + return numberOfFiles; + } + + public void setNumberOfFiles(Integer numberOfFiles) + { + this.numberOfFiles = numberOfFiles; + } + + public String getJobId() + { + return jobId; + } + + public void setJobId(String jobId) + { + this.jobId = jobId; + } + + public STATUS getStatus() + { + return status; + } + + public void setStatus(STATUS status) + { + this.status = status; + } + + @Override + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + NodeSizeDetails that = (NodeSizeDetails) o; + return Objects.equals(id, that.id) && Objects.equals(sizeInBytes, that.sizeInBytes) && Objects.equals( + calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) + && Objects.equals(jobId, that.jobId); + } + + @Override + public int hashCode() + { + return Objects.hash(id, sizeInBytes, calculatedAt, numberOfFiles, jobId); + } + + @Override + public String toString() + { + return "NodeSizeDetails{" + "id='" + id + '\'' + ", sizeInBytes=" + sizeInBytes + ", calculatedAt=" + + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + '}'; + } + + public enum STATUS + { + NOT_INITIATED, PENDING, IN_PROGRESS, COMPLETED, FAILED + } + + } + +} From 674bcb6c3662660e5039eb02b7bf59c6e2b63bc0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 19 Sep 2024 19:32:31 +0530 Subject: [PATCH 211/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java index 56dffff5b29..945dacf85d4 100644 --- a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java @@ -71,6 +71,7 @@ public void setSearchService(SearchService searchService) this.searchService = searchService; } + @Override public SimpleCache getSimpleCache() { return simpleCache; @@ -96,6 +97,7 @@ public void setDefaultItems(int defaultItems) this.defaultItems = defaultItems; } + @Override public void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId) { try From 1048c431c0dddf766cbe556cf119b31c34f5c55e Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 20 Sep 2024 14:35:21 +0530 Subject: [PATCH 212/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../src/main/java/org/alfresco/rest/api/SizeDetails.java | 2 +- .../java/org/alfresco/rest/api/impl/SizeDetailsImpl.java | 6 +++--- .../alfresco/rest/api/nodes/NodeSizeDetailsRelation.java | 2 +- .../org/alfresco/rest/api/impl/SizeDetailsImplTest.java | 4 ++-- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 2 +- .../node/{ => sizeDetails}/NodeSizeDetailsService.java | 4 ++-- .../{ => sizeDetails}/NodeSizeDetailsServiceImpl.java | 8 ++------ .../src/main/resources/alfresco/node-services-context.xml | 4 ++-- 8 files changed, 14 insertions(+), 18 deletions(-) rename repository/src/main/java/org/alfresco/repo/node/{ => sizeDetails}/NodeSizeDetailsService.java (91%) rename repository/src/main/java/org/alfresco/repo/node/{ => sizeDetails}/NodeSizeDetailsServiceImpl.java (97%) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java index f9afe7a10c4..a6e4c5795b9 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java @@ -25,7 +25,7 @@ */ package org.alfresco.rest.api; -import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; public interface SizeDetails { diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 006ac10f98e..3ca47143d60 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -29,9 +29,9 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.NodeSizeDetailsService; -import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; -import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsService; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index 08220f8da50..96153eb33e2 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -28,7 +28,7 @@ import java.util.List; -import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 9cf5fbd2b4e..8082504dc54 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -35,8 +35,8 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.NodeSizeDetailsServiceImpl; -import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; import org.alfresco.service.cmr.repository.NodeRef; diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 19ef4ec1f7d..a576177be75 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -34,7 +34,7 @@ import java.util.List; import java.util.Map; -import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; diff --git a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsService.java similarity index 91% rename from repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java rename to repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsService.java index df10828fac7..59b348773d9 100644 --- a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsService.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsService.java @@ -23,12 +23,12 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.repo.node; +package org.alfresco.repo.node.sizeDetails; import java.io.Serializable; import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.service.cmr.repository.NodeRef; public interface NodeSizeDetailsService diff --git a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsServiceImpl.java similarity index 97% rename from repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java rename to repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsServiceImpl.java index 945dacf85d4..e9ccc0b2553 100644 --- a/repository/src/main/java/org/alfresco/repo/node/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsServiceImpl.java @@ -23,7 +23,7 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.repo.node; +package org.alfresco.repo.node.sizeDetails; import java.io.Serializable; import java.util.Date; @@ -32,7 +32,7 @@ import java.util.concurrent.ThreadPoolExecutor; import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; +import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.cmr.repository.NodeRef; @@ -49,8 +49,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; -import net.sf.acegisecurity.Authentication; - /** * NodeSizeDetailsServiceImpl * Executing Alfresco FTS Query to find size details of Folder Node @@ -113,7 +111,6 @@ public void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId) private void executeSizeCalculation(NodeRef nodeRef, String jobId) { - final Authentication fullAuthentication = AuthenticationUtil.getFullAuthentication(); RetryingTransactionCallback executionCallback = () -> { try @@ -133,7 +130,6 @@ private void executeSizeCalculation(NodeRef nodeRef, String jobId) try { - AuthenticationUtil.setFullAuthentication(fullAuthentication); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); nodeSizeDetails = AuthenticationUtil.runAs(() -> transactionService.getRetryingTransactionHelper() .doInTransaction(executionCallback, true), AuthenticationUtil.getSystemUserName()); diff --git a/repository/src/main/resources/alfresco/node-services-context.xml b/repository/src/main/resources/alfresco/node-services-context.xml index 6040282f546..b517f08b255 100644 --- a/repository/src/main/resources/alfresco/node-services-context.xml +++ b/repository/src/main/resources/alfresco/node-services-context.xml @@ -344,7 +344,7 @@ - + @@ -360,7 +360,7 @@ - org.alfresco.repo.node.NodeSizeDetailsService + org.alfresco.repo.node.sizeDetails.NodeSizeDetailsService From 681b0efbcb44b20a8a3ece7856c772551ea69190 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 20 Sep 2024 15:45:14 +0530 Subject: [PATCH 213/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../org/alfresco/rest/api/SizeDetails.java | 2 +- .../rest/api/impl/SizeDetailsImpl.java | 23 +++++++----------- .../api/nodes/NodeSizeDetailsRelation.java | 2 +- .../rest/api/impl/SizeDetailsImplTest.java | 14 ++++++----- .../rest/api/tests/NodeSizeDetailsTest.java | 2 +- .../NodeSizeDetailsService.java | 13 +++++----- .../NodeSizeDetailsServiceImpl.java | 24 ++++++++++++++----- .../alfresco/node-services-context.xml | 4 ++-- 8 files changed, 47 insertions(+), 37 deletions(-) rename repository/src/main/java/org/alfresco/repo/node/{sizeDetails => sizedetails}/NodeSizeDetailsService.java (80%) rename repository/src/main/java/org/alfresco/repo/node/{sizeDetails => sizedetails}/NodeSizeDetailsServiceImpl.java (95%) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java index a6e4c5795b9..b749706566b 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/SizeDetails.java @@ -25,7 +25,7 @@ */ package org.alfresco.rest.api; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; public interface SizeDetails { diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 3ca47143d60..e057fbac0c1 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -25,13 +25,10 @@ */ package org.alfresco.rest.api.impl; -import java.io.Serializable; - import org.alfresco.model.ContentModel; -import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsService; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsService; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; @@ -45,7 +42,6 @@ public class SizeDetailsImpl implements SizeDetails, InitializingBean { private Nodes nodes; private NodeRef nodeRef; - private SimpleCache simpleCache; private NodeSizeDetailsService nodeSizeDetailsService; public void setNodes(Nodes nodes) @@ -67,13 +63,13 @@ public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId) nodeRef = nodes.validateOrLookupNode(nodeId); validateType(nodeRef); String actionId; - if (!simpleCache.contains(nodeId)) + if (!nodeSizeDetailsService.checkSizeDetailsExist(nodeId)) { actionId = executeSizeDetails(); } else { - NodeSizeDetails nodeSizeDetails = simpleCache.get(nodeId); + NodeSizeDetails nodeSizeDetails = nodeSizeDetailsService.getSizeDetailsFromCache(nodeId); actionId = nodeSizeDetails.getJobId(); } return new NodeSizeDetails(null, null, actionId, null); @@ -88,14 +84,14 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI NodeRef nodeRef = nodes.validateOrLookupNode(nodeId); validateType(nodeRef); - if (!simpleCache.contains(nodeId)) + if (!nodeSizeDetailsService.checkSizeDetailsExist(nodeId)) { NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeId, null, null, STATUS.NOT_INITIATED); return nodeSizeDetails; } else { - NodeSizeDetails nodeSizeDetails = simpleCache.get(nodeId); + NodeSizeDetails nodeSizeDetails = nodeSizeDetailsService.getSizeDetailsFromCache(nodeId); String cachedJobId = nodeSizeDetails.getJobId(); if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) { @@ -103,7 +99,7 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI } } - return simpleCache.get(nodeId); + return nodeSizeDetailsService.getSizeDetailsFromCache(nodeId); } /** @@ -114,7 +110,7 @@ private String executeSizeDetails() String jobId = GUID.generate(); nodeSizeDetailsService.invokeSizeDetailsExecutor(nodeRef, jobId); NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.PENDING); - simpleCache.put(nodeRef.getId(), nodeSizeDetails); + nodeSizeDetailsService.putSizeDetailsInCache(nodeRef.getId(), nodeSizeDetails); return jobId; } @@ -131,7 +127,6 @@ public void afterPropertiesSet() throws Exception { ParameterCheck.mandatory("nodes", this.nodes); ParameterCheck.mandatory("nodeSizeDetailsServiceImpl", this.nodeSizeDetailsService); - this.simpleCache = nodeSizeDetailsService.getSimpleCache(); } } \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index 96153eb33e2..c23a9263b95 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -28,7 +28,7 @@ import java.util.List; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiParam; diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 8082504dc54..3c9bfa616c4 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -35,8 +35,8 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; import org.alfresco.service.cmr.repository.NodeRef; @@ -54,6 +54,8 @@ public class SizeDetailsImplTest private static final QName TYPE_FOLDER = QName.createQName(NAMESPACE, "folder"); private SizeDetailsImpl sizeDetailsImpl; private Nodes nodes; + private NodeSizeDetailsServiceImpl nodeSizeDetailsServiceImpl; + private NodeSizeDetails nodeSizeDetails; @Before public void setUp() throws Exception @@ -61,19 +63,18 @@ public void setUp() throws Exception sizeDetailsImpl = new SizeDetailsImpl(); nodes = mock(Nodes.class); SearchService searchService = mock(SearchService.class); - NodeSizeDetailsServiceImpl nodeSizeDetailsServiceImpl = mock(NodeSizeDetailsServiceImpl.class); + nodeSizeDetailsServiceImpl = mock(NodeSizeDetailsServiceImpl.class); ThreadPoolExecutor threadPoolExecutor = mock(ThreadPoolExecutor.class); SimpleCache simpleCache = mock(SimpleCache.class); + nodeSizeDetails = mock(NodeSizeDetails.class); nodeSizeDetailsServiceImpl.setSearchService(searchService); nodeSizeDetailsServiceImpl.setDefaultItems(1000); nodeSizeDetailsServiceImpl.setSimpleCache(simpleCache); + verify(nodeSizeDetailsServiceImpl).setSimpleCache(simpleCache); nodeSizeDetailsServiceImpl.setThreadPoolExecutor(threadPoolExecutor); sizeDetailsImpl.setNodes(nodes); sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsServiceImpl); - when(nodeSizeDetailsServiceImpl.getSimpleCache()).thenReturn(simpleCache); - sizeDetailsImpl.afterPropertiesSet(); - verify(nodeSizeDetailsServiceImpl).setSimpleCache(simpleCache); } @Test @@ -93,6 +94,7 @@ public void calculateNodeSizeDetails() when(nodes.validateOrLookupNode(nodeId)).thenReturn(nodeRef); when(nodes.isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)).thenReturn(true); + when(nodeSizeDetailsServiceImpl.getSizeDetailsFromCache(nodeId)).thenReturn(nodeSizeDetails); NodeSizeDetails requestSizeDetails = sizeDetailsImpl.generateNodeSizeDetailsRequest(nodeId); assertNotNull("After executing POST/size-details, it will provide with 202 status code", requestSizeDetails); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index a576177be75..63fe4077c1e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -34,7 +34,7 @@ import java.util.List; import java.util.Map; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; diff --git a/repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java similarity index 80% rename from repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsService.java rename to repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java index 59b348773d9..63212a20296 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsService.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java @@ -23,18 +23,19 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.repo.node.sizeDetails; +package org.alfresco.repo.node.sizedetails; -import java.io.Serializable; - -import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.service.cmr.repository.NodeRef; public interface NodeSizeDetailsService { void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId); - SimpleCache getSimpleCache(); + void putSizeDetailsInCache(String id, NodeSizeDetails NodeSizeDetails); + + NodeSizeDetails getSizeDetailsFromCache(String id); + + boolean checkSizeDetailsExist(String id); } diff --git a/repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java similarity index 95% rename from repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsServiceImpl.java rename to repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index e9ccc0b2553..fd220dd6b50 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizeDetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -23,7 +23,7 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.repo.node.sizeDetails; +package org.alfresco.repo.node.sizedetails; import java.io.Serializable; import java.util.Date; @@ -32,7 +32,7 @@ import java.util.concurrent.ThreadPoolExecutor; import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.node.sizeDetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.cmr.repository.NodeRef; @@ -70,9 +70,15 @@ public void setSearchService(SearchService searchService) } @Override - public SimpleCache getSimpleCache() + public NodeSizeDetails getSizeDetailsFromCache(String id) { - return simpleCache; + return simpleCache.get(id); + } + + @Override + public boolean checkSizeDetailsExist(String id) + { + return simpleCache.contains(id); } public void setSimpleCache(SimpleCache simpleCache) @@ -109,6 +115,12 @@ public void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId) } + @Override + public void putSizeDetailsInCache(String id, NodeSizeDetails nodeSizeDetails) + { + simpleCache.put(id, nodeSizeDetails); + } + private void executeSizeCalculation(NodeRef nodeRef, String jobId) { RetryingTransactionCallback executionCallback = () -> { @@ -126,7 +138,7 @@ private void executeSizeCalculation(NodeRef nodeRef, String jobId) threadPoolExecutor.execute(() -> { NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.IN_PROGRESS); - simpleCache.put(nodeRef.getId(), nodeSizeDetails); + putSizeDetailsInCache(nodeRef.getId(), nodeSizeDetails); try { @@ -141,7 +153,7 @@ private void executeSizeCalculation(NodeRef nodeRef, String jobId) } finally { - simpleCache.put(nodeRef.getId(), nodeSizeDetails); + putSizeDetailsInCache(nodeRef.getId(), nodeSizeDetails); AuthenticationUtil.clearCurrentSecurityContext(); } }); diff --git a/repository/src/main/resources/alfresco/node-services-context.xml b/repository/src/main/resources/alfresco/node-services-context.xml index b517f08b255..a39aa5445d1 100644 --- a/repository/src/main/resources/alfresco/node-services-context.xml +++ b/repository/src/main/resources/alfresco/node-services-context.xml @@ -344,7 +344,7 @@ - + @@ -360,7 +360,7 @@ - org.alfresco.repo.node.sizeDetails.NodeSizeDetailsService + org.alfresco.repo.node.sizedetails.NodeSizeDetailsService From e0bc0e6ad666e124111e8943a18a20baa794bfcf Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 20 Sep 2024 15:57:53 +0530 Subject: [PATCH 214/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../alfresco/repo/node/sizedetails/NodeSizeDetailsService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java index 63212a20296..8a3a7ba3503 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java @@ -32,7 +32,7 @@ public interface NodeSizeDetailsService { void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId); - void putSizeDetailsInCache(String id, NodeSizeDetails NodeSizeDetails); + void putSizeDetailsInCache(String id, NodeSizeDetails nodeSizeDetails); NodeSizeDetails getSizeDetailsFromCache(String id); From 5b14722931e51e296921c57fb9fbd814003098e4 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 23 Sep 2024 13:17:29 +0530 Subject: [PATCH 215/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../rest/api/impl/SizeDetailsImpl.java | 14 +++++++------- .../rest/api/impl/SizeDetailsImplTest.java | 2 +- .../sizedetails/NodeSizeDetailsService.java | 4 ++-- .../NodeSizeDetailsServiceImpl.java | 19 +++++++++++++++---- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index e057fbac0c1..10af47dac9f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -69,10 +69,10 @@ public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId) } else { - NodeSizeDetails nodeSizeDetails = nodeSizeDetailsService.getSizeDetailsFromCache(nodeId); + NodeSizeDetails nodeSizeDetails = nodeSizeDetailsService.getSizeDetails(nodeId); actionId = nodeSizeDetails.getJobId(); } - return new NodeSizeDetails(null, null, actionId, null); + return new NodeSizeDetails(actionId); } /** @@ -86,12 +86,12 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI if (!nodeSizeDetailsService.checkSizeDetailsExist(nodeId)) { - NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeId, null, null, STATUS.NOT_INITIATED); + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeId,STATUS.NOT_INITIATED); return nodeSizeDetails; } else { - NodeSizeDetails nodeSizeDetails = nodeSizeDetailsService.getSizeDetailsFromCache(nodeId); + NodeSizeDetails nodeSizeDetails = nodeSizeDetailsService.getSizeDetails(nodeId); String cachedJobId = nodeSizeDetails.getJobId(); if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) { @@ -99,7 +99,7 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI } } - return nodeSizeDetailsService.getSizeDetailsFromCache(nodeId); + return nodeSizeDetailsService.getSizeDetails(nodeId); } /** @@ -108,9 +108,9 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI private String executeSizeDetails() { String jobId = GUID.generate(); - nodeSizeDetailsService.invokeSizeDetailsExecutor(nodeRef, jobId); NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.PENDING); - nodeSizeDetailsService.putSizeDetailsInCache(nodeRef.getId(), nodeSizeDetails); + nodeSizeDetailsService.putSizeDetails(nodeRef.getId(), nodeSizeDetails); + nodeSizeDetailsService.invokeSizeDetailsExecutor(nodeRef, jobId); return jobId; } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 3c9bfa616c4..b8dc4435669 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -94,7 +94,7 @@ public void calculateNodeSizeDetails() when(nodes.validateOrLookupNode(nodeId)).thenReturn(nodeRef); when(nodes.isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)).thenReturn(true); - when(nodeSizeDetailsServiceImpl.getSizeDetailsFromCache(nodeId)).thenReturn(nodeSizeDetails); + when(nodeSizeDetailsServiceImpl.getSizeDetails(nodeId)).thenReturn(nodeSizeDetails); NodeSizeDetails requestSizeDetails = sizeDetailsImpl.generateNodeSizeDetailsRequest(nodeId); assertNotNull("After executing POST/size-details, it will provide with 202 status code", requestSizeDetails); diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java index 8a3a7ba3503..ad9d667d33e 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java @@ -32,9 +32,9 @@ public interface NodeSizeDetailsService { void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId); - void putSizeDetailsInCache(String id, NodeSizeDetails nodeSizeDetails); + void putSizeDetails(String id, NodeSizeDetails nodeSizeDetails); - NodeSizeDetails getSizeDetailsFromCache(String id); + NodeSizeDetails getSizeDetails(String id); boolean checkSizeDetailsExist(String id); diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index fd220dd6b50..429f93ae224 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -70,7 +70,7 @@ public void setSearchService(SearchService searchService) } @Override - public NodeSizeDetails getSizeDetailsFromCache(String id) + public NodeSizeDetails getSizeDetails(String id) { return simpleCache.get(id); } @@ -116,7 +116,7 @@ public void invokeSizeDetailsExecutor(NodeRef nodeRef, String jobId) } @Override - public void putSizeDetailsInCache(String id, NodeSizeDetails nodeSizeDetails) + public void putSizeDetails(String id, NodeSizeDetails nodeSizeDetails) { simpleCache.put(id, nodeSizeDetails); } @@ -138,7 +138,7 @@ private void executeSizeCalculation(NodeRef nodeRef, String jobId) threadPoolExecutor.execute(() -> { NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.IN_PROGRESS); - putSizeDetailsInCache(nodeRef.getId(), nodeSizeDetails); + putSizeDetails(nodeRef.getId(), nodeSizeDetails); try { @@ -153,7 +153,7 @@ private void executeSizeCalculation(NodeRef nodeRef, String jobId) } finally { - putSizeDetailsInCache(nodeRef.getId(), nodeSizeDetails); + putSizeDetails(nodeRef.getId(), nodeSizeDetails); AuthenticationUtil.clearCurrentSecurityContext(); } }); @@ -261,6 +261,17 @@ public static class NodeSizeDetails implements Serializable private String jobId; private STATUS status; + public NodeSizeDetails(String jobId) + { + this.jobId = jobId; + } + + public NodeSizeDetails(String id, STATUS status) + { + this.id = id; + this.status = status; + } + public NodeSizeDetails(String id, Long sizeInBytes, String jobId, STATUS status) { this.id = id; From 697f8d865bab19a7f499ac2e796d04348044dc82 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 24 Sep 2024 12:24:06 +0530 Subject: [PATCH 216/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../rest/api/impl/SizeDetailsImpl.java | 2 +- .../NodeSizeDetailsServiceImpl.java | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 10af47dac9f..921e9a1fe1a 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -108,7 +108,7 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI private String executeSizeDetails() { String jobId = GUID.generate(); - NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.PENDING); + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), jobId, STATUS.PENDING); nodeSizeDetailsService.putSizeDetails(nodeRef.getId(), nodeSizeDetails); nodeSizeDetailsService.invokeSizeDetailsExecutor(nodeRef, jobId); return jobId; diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index 429f93ae224..9c50664fd39 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -72,7 +72,20 @@ public void setSearchService(SearchService searchService) @Override public NodeSizeDetails getSizeDetails(String id) { - return simpleCache.get(id); + try + { + NodeSizeDetails details = simpleCache.get(id); + if (details == null) + { + throw new NullPointerException("No size details found for ID: " + id); + } + return details; + } + catch (Exception e) + { + LOG.error("Error retrieving size details for ID " + id + ": " + e.getMessage()); + throw new RuntimeException("Failed to get size details for ID: " + id, e); + } } @Override @@ -123,6 +136,7 @@ public void putSizeDetails(String id, NodeSizeDetails nodeSizeDetails) private void executeSizeCalculation(NodeRef nodeRef, String jobId) { + String authenticatedUserName = AuthenticationUtil.getFullyAuthenticatedUser(); RetryingTransactionCallback executionCallback = () -> { try @@ -137,14 +151,13 @@ private void executeSizeCalculation(NodeRef nodeRef, String jobId) }; threadPoolExecutor.execute(() -> { - NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), null, jobId, STATUS.IN_PROGRESS); + NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), jobId, STATUS.IN_PROGRESS); putSizeDetails(nodeRef.getId(), nodeSizeDetails); try { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); nodeSizeDetails = AuthenticationUtil.runAs(() -> transactionService.getRetryingTransactionHelper() - .doInTransaction(executionCallback, true), AuthenticationUtil.getSystemUserName()); + .doInTransaction(executionCallback, true), authenticatedUserName); } catch (Exception e) { @@ -272,6 +285,13 @@ public NodeSizeDetails(String id, STATUS status) this.status = status; } + public NodeSizeDetails(String id, String jobId, STATUS status) + { + this.id = id; + this.jobId = jobId; + this.status = status; + } + public NodeSizeDetails(String id, Long sizeInBytes, String jobId, STATUS status) { this.id = id; From 40efd934ac74713199047e926d75bc60f8e6ac7a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 24 Sep 2024 12:55:00 +0530 Subject: [PATCH 217/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../NodeSizeDetailsServiceImpl.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index 9c50664fd39..37537ce632c 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -31,6 +31,7 @@ import java.util.Objects; import java.util.concurrent.ThreadPoolExecutor; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -72,20 +73,15 @@ public void setSearchService(SearchService searchService) @Override public NodeSizeDetails getSizeDetails(String id) { - try - { - NodeSizeDetails details = simpleCache.get(id); - if (details == null) - { - throw new NullPointerException("No size details found for ID: " + id); - } - return details; - } - catch (Exception e) + NodeSizeDetails details = simpleCache.get(id); + + if (details == null) { - LOG.error("Error retrieving size details for ID " + id + ": " + e.getMessage()); - throw new RuntimeException("Failed to get size details for ID: " + id, e); + LOG.error("No size details found for ID: " + id); + throw new AlfrescoRuntimeException("Failed to get size details for ID: " + id); } + + return details; } @Override From aecb0298606f4ce68410263001098e5f93dee9ff Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 7 Oct 2024 15:45:36 +0530 Subject: [PATCH 218/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../rest/api/impl/SizeDetailsImpl.java | 54 +++++++------------ .../api/nodes/NodeSizeDetailsRelation.java | 1 + .../alfresco/public-rest-context.xml | 4 +- .../org/alfresco/AppContext04TestSuite.java | 3 +- .../rest/api/impl/SizeDetailsImplTest.java | 9 ++-- .../sizedetails/NodeSizeDetailsService.java | 6 +-- .../NodeSizeDetailsServiceImpl.java | 23 +++----- .../alfresco/node-services-context.xml | 7 ++- .../resources/alfresco/repository.properties | 7 ++- 9 files changed, 50 insertions(+), 64 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index 921e9a1fe1a..ebdd1e744a0 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -25,6 +25,8 @@ */ package org.alfresco.rest.api.impl; +import java.util.Optional; + import org.alfresco.model.ContentModel; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsService; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; @@ -40,17 +42,12 @@ public class SizeDetailsImpl implements SizeDetails, InitializingBean { - private Nodes nodes; - private NodeRef nodeRef; - private NodeSizeDetailsService nodeSizeDetailsService; + private final Nodes nodes; + private final NodeSizeDetailsService nodeSizeDetailsService; - public void setNodes(Nodes nodes) + public SizeDetailsImpl(Nodes nodes, NodeSizeDetailsService nodeSizeDetailsService) { this.nodes = nodes; - } - - public void setNodeSizeDetailsService(NodeSizeDetailsService nodeSizeDetailsService) - { this.nodeSizeDetailsService = nodeSizeDetailsService; } @@ -60,18 +57,13 @@ public void setNodeSizeDetailsService(NodeSizeDetailsService nodeSizeDetailsServ @Override public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId) { - nodeRef = nodes.validateOrLookupNode(nodeId); + NodeRef nodeRef = nodes.validateOrLookupNode(nodeId); validateType(nodeRef); - String actionId; - if (!nodeSizeDetailsService.checkSizeDetailsExist(nodeId)) - { - actionId = executeSizeDetails(); - } - else - { - NodeSizeDetails nodeSizeDetails = nodeSizeDetailsService.getSizeDetails(nodeId); - actionId = nodeSizeDetails.getJobId(); - } + + Optional nodeSizeDetails = nodeSizeDetailsService.getSizeDetails(nodeId); + String actionId = nodeSizeDetails.map(NodeSizeDetails::getJobId) + .orElseGet(() -> executeSizeDetails(nodeRef)); + return new NodeSizeDetails(actionId); } @@ -84,28 +76,20 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI NodeRef nodeRef = nodes.validateOrLookupNode(nodeId); validateType(nodeRef); - if (!nodeSizeDetailsService.checkSizeDetailsExist(nodeId)) - { - NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeId,STATUS.NOT_INITIATED); - return nodeSizeDetails; - } - else - { - NodeSizeDetails nodeSizeDetails = nodeSizeDetailsService.getSizeDetails(nodeId); - String cachedJobId = nodeSizeDetails.getJobId(); - if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) - { + Optional optionalDetails = nodeSizeDetailsService.getSizeDetails(nodeId); + return optionalDetails.map(details -> { + String cachedJobId = details.getJobId(); + if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) { throw new NotFoundException("jobId does not exist"); } - } - - return nodeSizeDetailsService.getSizeDetails(nodeId); + return details; + }).orElseGet(() -> new NodeSizeDetails(nodeId, STATUS.NOT_INITIATED)); } /** * Executing Asynchronously. */ - private String executeSizeDetails() + private String executeSizeDetails(NodeRef nodeRef) { String jobId = GUID.generate(); NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), jobId, STATUS.PENDING); @@ -118,7 +102,7 @@ private void validateType(NodeRef nodeRef) throws InvalidNodeTypeException { if (!nodes.isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)) { - throw new InvalidNodeTypeException("Invalid parameter: value of nodeId is invalid"); + throw new InvalidNodeTypeException("Node id " + nodeRef.getId() + " does not represent a folder."); } } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index c23a9263b95..d365e7070d2 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -27,6 +27,7 @@ package org.alfresco.rest.api.nodes; import java.util.List; +import java.util.Optional; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.SizeDetails; diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index a3e18b81c84..c054b3b9dea 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -997,8 +997,8 @@ - - + + diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index 2ffec4fc7b6..372d6b085be 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -77,7 +77,8 @@ org.alfresco.rest.api.impl.CommentsImplUnitTest.class, org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, org.alfresco.rest.api.impl.FavouritesImplUnitTest.class, - org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class + org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, + org.alfresco.rest.api.impl.SizeDetailsImplTest.class }) public class AppContext04TestSuite { diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index b8dc4435669..c8f2a65fe34 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -31,6 +31,7 @@ import static org.mockito.Mockito.when; import java.io.Serializable; +import java.util.Optional; import java.util.concurrent.ThreadPoolExecutor; import org.alfresco.model.ContentModel; @@ -60,7 +61,6 @@ public class SizeDetailsImplTest @Before public void setUp() throws Exception { - sizeDetailsImpl = new SizeDetailsImpl(); nodes = mock(Nodes.class); SearchService searchService = mock(SearchService.class); nodeSizeDetailsServiceImpl = mock(NodeSizeDetailsServiceImpl.class); @@ -73,8 +73,9 @@ public void setUp() throws Exception nodeSizeDetailsServiceImpl.setSimpleCache(simpleCache); verify(nodeSizeDetailsServiceImpl).setSimpleCache(simpleCache); nodeSizeDetailsServiceImpl.setThreadPoolExecutor(threadPoolExecutor); - sizeDetailsImpl.setNodes(nodes); - sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsServiceImpl); + sizeDetailsImpl = new SizeDetailsImpl(nodes, nodeSizeDetailsServiceImpl); +// sizeDetailsImpl.setNodes(nodes); +// sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsServiceImpl); } @Test @@ -94,7 +95,7 @@ public void calculateNodeSizeDetails() when(nodes.validateOrLookupNode(nodeId)).thenReturn(nodeRef); when(nodes.isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)).thenReturn(true); - when(nodeSizeDetailsServiceImpl.getSizeDetails(nodeId)).thenReturn(nodeSizeDetails); + when(nodeSizeDetailsServiceImpl.getSizeDetails(nodeId)).thenReturn(Optional.ofNullable(nodeSizeDetails)); NodeSizeDetails requestSizeDetails = sizeDetailsImpl.generateNodeSizeDetailsRequest(nodeId); assertNotNull("After executing POST/size-details, it will provide with 202 status code", requestSizeDetails); diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java index ad9d667d33e..63e621f8679 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsService.java @@ -25,6 +25,8 @@ */ package org.alfresco.repo.node.sizedetails; +import java.util.Optional; + import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.service.cmr.repository.NodeRef; @@ -34,8 +36,6 @@ public interface NodeSizeDetailsService void putSizeDetails(String id, NodeSizeDetails nodeSizeDetails); - NodeSizeDetails getSizeDetails(String id); - - boolean checkSizeDetailsExist(String id); + Optional getSizeDetails(String id); } diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index 37537ce632c..361541e1371 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -29,9 +29,9 @@ import java.util.Date; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.concurrent.ThreadPoolExecutor; -import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -71,23 +71,14 @@ public void setSearchService(SearchService searchService) } @Override - public NodeSizeDetails getSizeDetails(String id) + public Optional getSizeDetails(String id) { NodeSizeDetails details = simpleCache.get(id); - - if (details == null) - { - LOG.error("No size details found for ID: " + id); - throw new AlfrescoRuntimeException("Failed to get size details for ID: " + id); - } - - return details; - } - - @Override - public boolean checkSizeDetailsExist(String id) - { - return simpleCache.contains(id); + return Optional.ofNullable(details) + .or(() -> { + LOG.error("No size details found for ID: " + id); + return Optional.empty(); + }); } public void setSimpleCache(SimpleCache simpleCache) diff --git a/repository/src/main/resources/alfresco/node-services-context.xml b/repository/src/main/resources/alfresco/node-services-context.xml index a39aa5445d1..4cf86ccec70 100644 --- a/repository/src/main/resources/alfresco/node-services-context.xml +++ b/repository/src/main/resources/alfresco/node-services-context.xml @@ -337,10 +337,13 @@ defaultThreadPool - 5 + ${default.nodeSize.corePoolSize} - 10 + ${default.nodeSize.maximumPoolSize} + + + ${default.nodeSize.workQueueSize} diff --git a/repository/src/main/resources/alfresco/repository.properties b/repository/src/main/resources/alfresco/repository.properties index 4f35a06dd17..cb552f5e4ae 100644 --- a/repository/src/main/resources/alfresco/repository.properties +++ b/repository/src/main/resources/alfresco/repository.properties @@ -1388,4 +1388,9 @@ scripts.execution.observerInstructionCount=5000 #Default value being used in POST/size-details endpoint to partition a huge folder into smaller chunks #so that we can compute more efficiently and consolidate all sizes into a single unit. -default.async.folder.items=1000 \ No newline at end of file +default.async.folder.items=1000 + +# Default NodeSize Thread pool +default.nodeSize.corePoolSize=5 +default.nodeSize.maximumPoolSize=10 +default.nodeSize.workQueueSize=100 \ No newline at end of file From c07109943e91abf1cca125c46d4efd8a073233f2 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 7 Oct 2024 15:57:43 +0530 Subject: [PATCH 219/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java | 1 - 1 file changed, 1 deletion(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index d365e7070d2..c23a9263b95 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -27,7 +27,6 @@ package org.alfresco.rest.api.nodes; import java.util.List; -import java.util.Optional; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.SizeDetails; From 79e2cb63421944adbb0ef5ae937355731cb92cac Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 7 Oct 2024 16:17:05 +0530 Subject: [PATCH 220/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../org/alfresco/AppContext04TestSuite.java | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index 372d6b085be..adcd9aee52a 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2021 Alfresco Software Limited + * 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 @@ -25,60 +25,60 @@ */ package org.alfresco; -import org.junit.experimental.categories.Categories; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - import org.alfresco.repo.web.scripts.TestWebScriptRepoServer; import org.alfresco.util.testing.category.DBTests; import org.alfresco.util.testing.category.NonBuildTests; +import org.junit.experimental.categories.Categories; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; @RunWith(Categories.class) @Categories.ExcludeCategory({DBTests.class, NonBuildTests.class}) @Suite.SuiteClasses({ - org.alfresco.repo.web.scripts.quickshare.QuickShareRestApiTest.class, - org.alfresco.repo.web.scripts.admin.AdminWebScriptTest.class, - org.alfresco.repo.web.scripts.audit.AuditWebScriptTest.class, - org.alfresco.repo.web.scripts.blogs.BlogServiceTest.class, - org.alfresco.repo.web.scripts.dictionary.DictionaryRestApiTest.class, - org.alfresco.repo.web.scripts.discussion.DiscussionRestApiTest.class, - org.alfresco.repo.web.scripts.activities.feed.control.FeedControlTest.class, - org.alfresco.repo.web.scripts.forms.FormRestApiGet_Test.class, - org.alfresco.repo.web.scripts.forms.FormRestApiJsonPost_Test.class, - org.alfresco.repo.web.scripts.groups.GroupsTest.class, - org.alfresco.repo.web.scripts.invitation.InvitationWebScriptTest.class, - org.alfresco.repo.web.scripts.invite.InviteServiceTest.class, - org.alfresco.repo.web.scripts.LoginTest.class, - org.alfresco.repo.web.scripts.search.PersonSearchTest.class, - org.alfresco.repo.web.scripts.person.PersonServiceTest.class, - org.alfresco.repo.web.scripts.preference.PreferenceServiceTest.class, - org.alfresco.repo.web.scripts.rating.RatingRestApiTest.class, - org.alfresco.repo.web.scripts.replication.ReplicationRestApiTest.class, - org.alfresco.repo.web.scripts.RepositoryContainerTest.class, - org.alfresco.repo.web.scripts.rule.RuleServiceTest.class, - org.alfresco.repo.web.scripts.action.RunningActionRestApiTest.class, - org.alfresco.repo.web.scripts.site.SiteServiceTest.class, - org.alfresco.repo.web.scripts.tagging.TaggingServiceTest.class, - org.alfresco.repo.web.scripts.thumbnail.ThumbnailServiceTest.class, - org.alfresco.repo.web.scripts.transfer.TransferWebScriptTest.class, - org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest.class, - org.alfresco.repo.web.scripts.solr.SOLRWebScriptTest.class, - org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceRestApiTest.class, - org.alfresco.repo.web.scripts.facet.FacetRestApiTest.class, - org.alfresco.repo.web.scripts.comment.CommentsApiTest.class, - org.alfresco.repo.web.scripts.content.ContentGetTest.class, - org.alfresco.repo.web.scripts.XssVulnerabilityTest.class, - org.alfresco.repo.web.scripts.links.LinksRestApiTest.class, - org.alfresco.repo.model.filefolder.RemoteFileFolderLoaderTest.class, - org.alfresco.repo.web.scripts.ReadOnlyTransactionInGetRestApiTest.class, - org.alfresco.repo.web.scripts.custommodel.CustomModelImportTest.class, - org.alfresco.repo.web.scripts.site.SurfConfigTest.class, - org.alfresco.repo.web.scripts.node.NodeWebScripTest.class, - org.alfresco.rest.api.impl.CommentsImplUnitTest.class, - org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, - org.alfresco.rest.api.impl.FavouritesImplUnitTest.class, - org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, - org.alfresco.rest.api.impl.SizeDetailsImplTest.class + // [classpath:alfresco/application-context.xml, classpath:alfresco/web-scripts-application-context-test.xml, + // classpath:alfresco/web-scripts-application-context.xml] + org.alfresco.repo.web.scripts.quickshare.QuickShareRestApiTest.class, + org.alfresco.repo.web.scripts.admin.AdminWebScriptTest.class, + org.alfresco.repo.web.scripts.audit.AuditWebScriptTest.class, + org.alfresco.repo.web.scripts.blogs.BlogServiceTest.class, + org.alfresco.repo.web.scripts.dictionary.DictionaryRestApiTest.class, + org.alfresco.repo.web.scripts.discussion.DiscussionRestApiTest.class, + org.alfresco.repo.web.scripts.activities.feed.control.FeedControlTest.class, + org.alfresco.repo.web.scripts.forms.FormRestApiGet_Test.class, + org.alfresco.repo.web.scripts.forms.FormRestApiJsonPost_Test.class, + org.alfresco.repo.web.scripts.groups.GroupsTest.class, + org.alfresco.repo.web.scripts.invitation.InvitationWebScriptTest.class, + org.alfresco.repo.web.scripts.invite.InviteServiceTest.class, + org.alfresco.repo.web.scripts.LoginTest.class, + org.alfresco.repo.web.scripts.search.PersonSearchTest.class, + org.alfresco.repo.web.scripts.person.PersonServiceTest.class, + org.alfresco.repo.web.scripts.preference.PreferenceServiceTest.class, + org.alfresco.repo.web.scripts.rating.RatingRestApiTest.class, + org.alfresco.repo.web.scripts.replication.ReplicationRestApiTest.class, + org.alfresco.repo.web.scripts.RepositoryContainerTest.class, + org.alfresco.repo.web.scripts.rule.RuleServiceTest.class, + org.alfresco.repo.web.scripts.action.RunningActionRestApiTest.class, + org.alfresco.repo.web.scripts.site.SiteServiceTest.class, + org.alfresco.repo.web.scripts.tagging.TaggingServiceTest.class, + org.alfresco.repo.web.scripts.thumbnail.ThumbnailServiceTest.class, + org.alfresco.repo.web.scripts.transfer.TransferWebScriptTest.class, + org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest.class, + org.alfresco.repo.web.scripts.solr.SOLRWebScriptTest.class, + org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceRestApiTest.class, + org.alfresco.repo.web.scripts.facet.FacetRestApiTest.class, + org.alfresco.repo.web.scripts.comment.CommentsApiTest.class, + org.alfresco.repo.web.scripts.content.ContentGetTest.class, + org.alfresco.repo.web.scripts.XssVulnerabilityTest.class, + org.alfresco.repo.web.scripts.links.LinksRestApiTest.class, + org.alfresco.repo.model.filefolder.RemoteFileFolderLoaderTest.class, + org.alfresco.repo.web.scripts.ReadOnlyTransactionInGetRestApiTest.class, + org.alfresco.repo.web.scripts.custommodel.CustomModelImportTest.class, + org.alfresco.repo.web.scripts.site.SurfConfigTest.class, + org.alfresco.repo.web.scripts.node.NodeWebScripTest.class, + org.alfresco.rest.api.impl.CommentsImplUnitTest.class, + org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, + org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, + org.alfresco.rest.api.impl.SizeDetailsImplTest.class }) public class AppContext04TestSuite { From 18901c779d03e526942f4ac747b8e656c4c02dba Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 7 Oct 2024 16:41:34 +0530 Subject: [PATCH 221/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../alfresco/rest/api/tests/NodeSizeDetailsTest.java | 12 +++++++----- .../main/resources/alfresco/repository.properties | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 63fe4077c1e..61607b43e0b 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -144,8 +144,9 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails((JSONObject) getResponse.getJsonResponse() - .get("entry")); + NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( + (JSONObject) getResponse.getJsonResponse() + .get("entry")); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); } @@ -190,7 +191,7 @@ public void testPerformanceTesting() throws Exception postResponse.getJsonResponse()); JSONObject jsonObject = (JSONObject) postResponse.getJsonResponse() - .get("entry"); + .get("entry"); String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); @@ -205,8 +206,9 @@ public void testPerformanceTesting() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails((JSONObject) getResponse.getJsonResponse() - .get("entry")); + NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( + (JSONObject) getResponse.getJsonResponse() + .get("entry")); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); diff --git a/repository/src/main/resources/alfresco/repository.properties b/repository/src/main/resources/alfresco/repository.properties index cb552f5e4ae..f5dfa686a9c 100644 --- a/repository/src/main/resources/alfresco/repository.properties +++ b/repository/src/main/resources/alfresco/repository.properties @@ -1386,8 +1386,8 @@ scripts.execution.maxMemoryUsedInBytes=-1 # Number of instructions that will trigger the observer scripts.execution.observerInstructionCount=5000 -#Default value being used in POST/size-details endpoint to partition a huge folder into smaller chunks -#so that we can compute more efficiently and consolidate all sizes into a single unit. +# Default value being used in POST/size-details endpoint to partition a huge folder into smaller chunks +# so that we can compute more efficiently and consolidate all sizes into a single unit. default.async.folder.items=1000 # Default NodeSize Thread pool From 1027bc14cd4ae6c9d9561d3985bcd02f2143687c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 8 Oct 2024 11:21:53 +0530 Subject: [PATCH 222/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../alfresco/rest/api/impl/SizeDetailsImpl.java | 14 ++++++++------ .../rest/api/impl/SizeDetailsImplTest.java | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index ebdd1e744a0..dcee265c85e 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -78,12 +78,14 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI Optional optionalDetails = nodeSizeDetailsService.getSizeDetails(nodeId); return optionalDetails.map(details -> { - String cachedJobId = details.getJobId(); - if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) { - throw new NotFoundException("jobId does not exist"); - } - return details; - }).orElseGet(() -> new NodeSizeDetails(nodeId, STATUS.NOT_INITIATED)); + String cachedJobId = details.getJobId(); + if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) + { + throw new NotFoundException("jobId does not exist"); + } + return details; + }) + .orElseGet(() -> new NodeSizeDetails(nodeId, STATUS.NOT_INITIATED)); } /** diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index c8f2a65fe34..6132ce5646c 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -74,8 +74,8 @@ public void setUp() throws Exception verify(nodeSizeDetailsServiceImpl).setSimpleCache(simpleCache); nodeSizeDetailsServiceImpl.setThreadPoolExecutor(threadPoolExecutor); sizeDetailsImpl = new SizeDetailsImpl(nodes, nodeSizeDetailsServiceImpl); -// sizeDetailsImpl.setNodes(nodes); -// sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsServiceImpl); + // sizeDetailsImpl.setNodes(nodes); + // sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsServiceImpl); } @Test From d386924ac93b6c612e080e88afe3f09a4c441aac Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 8 Oct 2024 11:50:30 +0530 Subject: [PATCH 223/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index dcee265c85e..ab481314b0f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -44,7 +44,6 @@ public class SizeDetailsImpl implements SizeDetails, InitializingBean { private final Nodes nodes; private final NodeSizeDetailsService nodeSizeDetailsService; - public SizeDetailsImpl(Nodes nodes, NodeSizeDetailsService nodeSizeDetailsService) { this.nodes = nodes; From 013cfb140321805f53a5aca11e33d8f8fb6b8f0a Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 8 Oct 2024 12:29:07 +0530 Subject: [PATCH 224/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index ab481314b0f..dcee265c85e 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -44,6 +44,7 @@ public class SizeDetailsImpl implements SizeDetails, InitializingBean { private final Nodes nodes; private final NodeSizeDetailsService nodeSizeDetailsService; + public SizeDetailsImpl(Nodes nodes, NodeSizeDetailsService nodeSizeDetailsService) { this.nodes = nodes; From 26c79b4621faa9d82da1070cfea608ea9fafbf91 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 8 Oct 2024 16:07:45 +0530 Subject: [PATCH 225/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../rest/api/impl/SizeDetailsImpl.java | 23 ++++---- .../api/nodes/NodeSizeDetailsRelation.java | 19 ++++--- .../rest/api/impl/SizeDetailsImplTest.java | 7 +-- .../rest/api/tests/NodeSizeDetailsTest.java | 55 +++++++++---------- 4 files changed, 51 insertions(+), 53 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java index dcee265c85e..3acc0ea87d7 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/SizeDetailsImpl.java @@ -27,6 +27,8 @@ import java.util.Optional; +import org.springframework.beans.factory.InitializingBean; + import org.alfresco.model.ContentModel; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsService; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; @@ -38,7 +40,6 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.util.GUID; import org.alfresco.util.ParameterCheck; -import org.springframework.beans.factory.InitializingBean; public class SizeDetailsImpl implements SizeDetails, InitializingBean { @@ -62,7 +63,7 @@ public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId) Optional nodeSizeDetails = nodeSizeDetailsService.getSizeDetails(nodeId); String actionId = nodeSizeDetails.map(NodeSizeDetails::getJobId) - .orElseGet(() -> executeSizeDetails(nodeRef)); + .orElseGet(() -> executeSizeDetails(nodeRef)); return new NodeSizeDetails(actionId); } @@ -78,14 +79,14 @@ public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobI Optional optionalDetails = nodeSizeDetailsService.getSizeDetails(nodeId); return optionalDetails.map(details -> { - String cachedJobId = details.getJobId(); - if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) - { - throw new NotFoundException("jobId does not exist"); - } - return details; - }) - .orElseGet(() -> new NodeSizeDetails(nodeId, STATUS.NOT_INITIATED)); + String cachedJobId = details.getJobId(); + if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId)) + { + throw new NotFoundException("jobId does not exist"); + } + return details; + }) + .orElseGet(() -> new NodeSizeDetails(nodeId, STATUS.NOT_INITIATED)); } /** @@ -115,4 +116,4 @@ public void afterPropertiesSet() throws Exception ParameterCheck.mandatory("nodeSizeDetailsServiceImpl", this.nodeSizeDetailsService); } -} \ No newline at end of file +} diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java index c23a9263b95..3a6095c1b07 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeSizeDetailsRelation.java @@ -28,6 +28,9 @@ import java.util.List; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.extensions.webscripts.Status; + import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.SizeDetails; import org.alfresco.rest.framework.WebApiDescription; @@ -39,12 +42,10 @@ import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.util.ParameterCheck; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.extensions.webscripts.Status; @RelationshipResource(name = "size-details", entityResource = NodesEntityResource.class, title = "Node Size Details") public class NodeSizeDetailsRelation implements RelationshipResourceAction.ReadById, - RelationshipResourceAction.Create, InitializingBean + RelationshipResourceAction.Create, InitializingBean { private SizeDetails sizeDetails; @@ -62,8 +63,8 @@ public void afterPropertiesSet() @WebApiDescription(title = "Create node-size details request", successStatus = Status.STATUS_ACCEPTED) @WebApiParam(name = "nodeSizeEntity", title = "Node Size Details Request", - description = "Request for processing Node Size.", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT, - allowMultiple = false) + description = "Request for processing Node Size.", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT, + allowMultiple = false) @Override public List create(String nodeId, List nodeSizeEntity, Parameters parameters) { @@ -71,12 +72,12 @@ public List create(String nodeId, List nodeSiz } @WebApiDescription(title = "Get Node Size Details", description = "Get the Node Size Details") - @WebApiParameters({ @WebApiParam(name = "nodeId", title = "The unique id of the Node being addressed", - description = "A single node id"), - @WebApiParam(name = "jobId", title = "Job Id to get the NodeSizeDetails", description = "JobId") }) + @WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of the Node being addressed", + description = "A single Node id"), + @WebApiParam(name = "jobId", title = "Job Id to get the NodeSizeDetails", description = "JobId")}) @Override public NodeSizeDetails readById(String nodeId, String jobId, Parameters parameters) - throws RelationshipResourceNotFoundException + throws RelationshipResourceNotFoundException { return sizeDetails.getNodeSizeDetails(nodeId, jobId); } diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java index 6132ce5646c..7e4b49e936e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/SizeDetailsImplTest.java @@ -34,6 +34,9 @@ import java.util.Optional; import java.util.concurrent.ThreadPoolExecutor; +import org.junit.Before; +import org.junit.Test; + import org.alfresco.model.ContentModel; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl; @@ -43,8 +46,6 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.namespace.QName; -import org.junit.Before; -import org.junit.Test; /** * Unit tests for {@link SizeDetailsImpl} class. @@ -74,8 +75,6 @@ public void setUp() throws Exception verify(nodeSizeDetailsServiceImpl).setSimpleCache(simpleCache); nodeSizeDetailsServiceImpl.setThreadPoolExecutor(threadPoolExecutor); sizeDetailsImpl = new SizeDetailsImpl(nodes, nodeSizeDetailsServiceImpl); - // sizeDetailsImpl.setNodes(nodes); - // sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsServiceImpl); } @Test diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 61607b43e0b..edb30fcc77e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -34,6 +34,17 @@ import java.util.List; import java.util.Map; +import org.json.simple.JSONObject; +import org.junit.After; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.junit.runners.MethodSorters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Site; @@ -46,16 +57,6 @@ import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; -import org.json.simple.JSONObject; -import org.junit.After; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.junit.runners.MethodSorters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * V1 REST API tests for calculating and retrieving Folder size. @@ -100,7 +101,6 @@ private String addToDocumentLibrary(Site testSite, String name, String nodeType) public void setup() throws Exception { super.setup(); - setRequestContext(user1); String siteTitle = "RandomSite" + System.currentTimeMillis(); @@ -114,10 +114,7 @@ public void setup() throws Exception } /** - * Test case for POST/size-details, which request and calculates the size of a folder. - * GET/size-details, which retrieve the SizeDetails of the folder Node. - * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details} - * {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details/} + * Test case for POST/size-details, which request and calculates the size of a folder. GET/size-details, which retrieve the SizeDetails of the folder Node. {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details} {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details/} */ @Test public void testPostAndGetFolderSizeDetails() throws Exception @@ -126,10 +123,10 @@ public void testPostAndGetFolderSizeDetails() throws Exception HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), null, 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", - postResponse.getJsonResponse()); + postResponse.getJsonResponse()); JSONObject jsonObject = (JSONObject) postResponse.getJsonResponse() - .get("entry"); + .get("entry"); String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); @@ -142,11 +139,11 @@ public void testPostAndGetFolderSizeDetails() throws Exception HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", - getResponse.getJsonResponse()); + getResponse.getJsonResponse()); NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( - (JSONObject) getResponse.getJsonResponse() - .get("entry")); + (JSONObject) getResponse.getJsonResponse() + .get("entry")); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); } @@ -180,18 +177,18 @@ public void testPerformanceTesting() throws Exception List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); assertEquals(500, nodes.size()); - //Start Time before triggering POST/size-details API + // Start Time before triggering POST/size-details API LocalTime expectedTime = LocalTime.now() - .plusSeconds(5); + .plusSeconds(5); // Perform POST request HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), null, 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", - postResponse.getJsonResponse()); + postResponse.getJsonResponse()); JSONObject jsonObject = (JSONObject) postResponse.getJsonResponse() - .get("entry"); + .get("entry"); String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); @@ -204,15 +201,15 @@ public void testPerformanceTesting() throws Exception HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", - getResponse.getJsonResponse()); + getResponse.getJsonResponse()); NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( - (JSONObject) getResponse.getJsonResponse() - .get("entry")); + (JSONObject) getResponse.getJsonResponse() + .get("entry")); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); - //current Time after executing GET/size-details + // current Time after executing GET/size-details LocalTime actualTime = LocalTime.now(); assertTrue("Calculating folder node is taking time greater than 5 seconds ", actualTime.isBefore(expectedTime)); } @@ -254,4 +251,4 @@ public String getScope() { return "public"; } -} \ No newline at end of file +} From 26035477e4593413fb22f615624e28b24e4ce302 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 8 Oct 2024 16:20:53 +0530 Subject: [PATCH 226/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details --- .../NodeSizeDetailsServiceImpl.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index 361541e1371..f8382124c41 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -32,6 +32,11 @@ import java.util.Optional; import java.util.concurrent.ThreadPoolExecutor; +import org.json.simple.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; + import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -45,14 +50,9 @@ import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.Pair; import org.alfresco.util.ParameterCheck; -import org.json.simple.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.InitializingBean; /** - * NodeSizeDetailsServiceImpl - * Executing Alfresco FTS Query to find size details of Folder Node + * NodeSizeDetailsServiceImpl Executing Alfresco FTS Query to find size details of Folder Node */ public class NodeSizeDetailsServiceImpl implements NodeSizeDetailsService, InitializingBean { @@ -75,10 +75,10 @@ public Optional getSizeDetails(String id) { NodeSizeDetails details = simpleCache.get(id); return Optional.ofNullable(details) - .or(() -> { - LOG.error("No size details found for ID: " + id); - return Optional.empty(); - }); + .or(() -> { + LOG.error("No Size details found for ID: " + id); + return Optional.empty(); + }); } public void setSimpleCache(SimpleCache simpleCache) @@ -144,7 +144,7 @@ private void executeSizeCalculation(NodeRef nodeRef, String jobId) try { nodeSizeDetails = AuthenticationUtil.runAs(() -> transactionService.getRetryingTransactionHelper() - .doInTransaction(executionCallback, true), authenticatedUserName); + .doInTransaction(executionCallback, true), authenticatedUserName); } catch (Exception e) { @@ -170,15 +170,15 @@ private NodeSizeDetails calculateTotalSizeFromFacet(NodeRef nodeRef, String jobI { ResultSet results = facetQuery(nodeRef); int resultsSize = results.getFieldFacet(FIELD_FACET) - .size(); + .size(); while (!isCalculationCompleted) { List> facetPairs = results.getFieldFacet(FIELD_FACET) - .subList(skipCount, Math.min(totalItems, resultsSize)); + .subList(skipCount, Math.min(totalItems, resultsSize)); totalSizeFromFacet += facetPairs.parallelStream() - .mapToLong(pair -> Long.parseLong(pair.getFirst()) * pair.getSecond()) - .sum(); + .mapToLong(pair -> Long.parseLong(pair.getFirst()) * pair.getSecond()) + .sum(); if (resultsSize <= totalItems || resultsSize <= defaultItems) { @@ -193,8 +193,9 @@ private NodeSizeDetails calculateTotalSizeFromFacet(NodeRef nodeRef, String jobI } Date calculationDate = new Date(System.currentTimeMillis()); NodeSizeDetails nodeSizeDetails = new NodeSizeDetails(nodeRef.getId(), totalSizeFromFacet, calculationDate, - results.getNodeRefs() - .size(), STATUS.COMPLETED, jobId); + results.getNodeRefs() + .size(), + STATUS.COMPLETED, jobId); return nodeSizeDetails; } catch (Exception e) @@ -288,7 +289,7 @@ public NodeSizeDetails(String id, Long sizeInBytes, String jobId, STATUS status) } public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer numberOfFiles, - STATUS currentStatus, String jobId) + STATUS currentStatus, String jobId) { this.id = id; this.sizeInBytes = sizeInBytes; @@ -385,8 +386,8 @@ public boolean equals(Object o) } NodeSizeDetails that = (NodeSizeDetails) o; return Objects.equals(id, that.id) && Objects.equals(sizeInBytes, that.sizeInBytes) && Objects.equals( - calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) - && Objects.equals(jobId, that.jobId); + calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) + && Objects.equals(jobId, that.jobId); } @Override @@ -399,7 +400,7 @@ public int hashCode() public String toString() { return "NodeSizeDetails{" + "id='" + id + '\'' + ", sizeInBytes=" + sizeInBytes + ", calculatedAt=" - + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + '}'; + + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + '}'; } public enum STATUS From ba393a56521529564ceb9149b58b7799d5ddaa10 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 9 Oct 2024 09:01:13 +0530 Subject: [PATCH 227/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments From e33feb28898dfab353a3c847e0775eba59fec9c5 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 9 Oct 2024 10:21:56 +0530 Subject: [PATCH 228/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments and refactoring files --- .../org/alfresco/AppContext02TestSuite.java | 95 +++++++++---------- 1 file changed, 43 insertions(+), 52 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 88cff8438af..ebc5a71a243 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -4,80 +4,71 @@ * %% * 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 + * 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; -import org.alfresco.util.testing.category.DBTests; -import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; import org.junit.runner.RunWith; import org.junit.runners.Suite; +import org.alfresco.util.testing.category.DBTests; +import org.alfresco.util.testing.category.NonBuildTests; + @RunWith(Categories.class) @Categories.ExcludeCategory({DBTests.class, NonBuildTests.class}) @Suite.SuiteClasses({ - // [classpath*:/publicapi/lucene/, classpath:alfresco/application-context.xml, - // classpath:alfresco/web-scripts-application-context-test.xml, - // classpath:alfresco/web-scripts-application-context.xml, rest-api-test-context.xml, testcmis-model-context.xml] + // [classpath*:/publicapi/lucene/, classpath:alfresco/application-context.xml, + // classpath:alfresco/web-scripts-application-context-test.xml, + // classpath:alfresco/web-scripts-application-context.xml, rest-api-test-context.xml, testcmis-model-context.xml] - // this need to be run first - org.alfresco.rest.api.tests.TestCMIS.class, + // this need to be run first + org.alfresco.rest.api.tests.TestCMIS.class, - org.alfresco.rest.api.tests.TestCustomModelExport.class, - org.alfresco.rest.DeletedNodesTest.class, - org.alfresco.rest.api.search.BasicSearchApiIntegrationTest.class, - org.alfresco.rest.api.tests.ActivitiesPostingTest.class, - org.alfresco.rest.api.tests.AuthenticationsTest.class, - org.alfresco.rest.api.tests.DiscoveryApiTest.class, - org.alfresco.rest.api.discovery.DiscoveryApiWebscriptUnitTest.class, - org.alfresco.rest.api.tests.GroupsTest.class, - org.alfresco.rest.api.tests.ModulePackagesApiTest.class, - org.alfresco.rest.api.tests.NodeApiTest.class, - org.alfresco.rest.api.tests.NodeApiVersioningMultipartParameterizedTest.class, - org.alfresco.rest.api.tests.NodeApiVersioningJsonParameterizedTest.class, - org.alfresco.rest.api.tests.NodeAssociationsApiTest.class, - org.alfresco.rest.api.tests.NodeVersionsApiTest.class, - org.alfresco.rest.api.tests.NodeVersionRenditionsApiTest.class, - org.alfresco.rest.api.tests.QueriesNodesApiTest.class, - org.alfresco.rest.api.tests.QueriesPeopleApiTest.class, - org.alfresco.rest.api.tests.QueriesSitesApiTest.class, - org.alfresco.rest.api.tests.TestActivities.class, - org.alfresco.rest.api.tests.TestDownloads.class, - org.alfresco.rest.api.tests.TestFavouriteSites.class, - org.alfresco.rest.api.tests.TestFavourites.class, - org.alfresco.rest.api.tests.TestNetworks.class, - org.alfresco.rest.api.tests.TestNodeComments.class, - org.alfresco.rest.api.tests.TestNodeRatings.class, - org.alfresco.rest.api.tests.TestPersonSites.class, - org.alfresco.rest.api.tests.TestPublicApi128.class, - org.alfresco.rest.api.tests.TestPublicApiCaching.class, - org.alfresco.rest.api.tests.TestUserPreferences.class, - org.alfresco.rest.api.tests.WherePredicateApiTest.class, - org.alfresco.rest.api.tests.TestRemovePermissions.class, - org.alfresco.rest.api.tests.TempOutputStreamTest.class, - org.alfresco.rest.api.tests.BufferedResponseTest.class, - org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, - org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, - org.alfresco.rest.api.tests.NodeSizeDetailsTest.class -}) + org.alfresco.rest.api.tests.TestCustomModelExport.class, org.alfresco.rest.DeletedNodesTest.class, + org.alfresco.rest.api.search.BasicSearchApiIntegrationTest.class, + org.alfresco.rest.api.tests.ActivitiesPostingTest.class, + org.alfresco.rest.api.tests.AuthenticationsTest.class, org.alfresco.rest.api.tests.DiscoveryApiTest.class, + org.alfresco.rest.api.discovery.DiscoveryApiWebscriptUnitTest.class, + org.alfresco.rest.api.tests.GroupsTest.class, org.alfresco.rest.api.tests.ModulePackagesApiTest.class, + org.alfresco.rest.api.tests.NodeApiTest.class, + org.alfresco.rest.api.tests.NodeApiVersioningMultipartParameterizedTest.class, + org.alfresco.rest.api.tests.NodeApiVersioningJsonParameterizedTest.class, + org.alfresco.rest.api.tests.NodeAssociationsApiTest.class, + org.alfresco.rest.api.tests.NodeVersionsApiTest.class, + org.alfresco.rest.api.tests.NodeVersionRenditionsApiTest.class, + org.alfresco.rest.api.tests.QueriesNodesApiTest.class, + org.alfresco.rest.api.tests.QueriesPeopleApiTest.class, + org.alfresco.rest.api.tests.QueriesSitesApiTest.class, org.alfresco.rest.api.tests.TestActivities.class, + org.alfresco.rest.api.tests.TestDownloads.class, org.alfresco.rest.api.tests.TestFavouriteSites.class, + org.alfresco.rest.api.tests.TestFavourites.class, org.alfresco.rest.api.tests.TestNetworks.class, + org.alfresco.rest.api.tests.TestNodeComments.class, org.alfresco.rest.api.tests.TestNodeRatings.class, + org.alfresco.rest.api.tests.TestPersonSites.class, org.alfresco.rest.api.tests.TestPublicApi128.class, + org.alfresco.rest.api.tests.TestPublicApiCaching.class, + org.alfresco.rest.api.tests.TestUserPreferences.class, + org.alfresco.rest.api.tests.WherePredicateApiTest.class, + org.alfresco.rest.api.tests.TestRemovePermissions.class, + org.alfresco.rest.api.tests.TempOutputStreamTest.class, + org.alfresco.rest.api.tests.BufferedResponseTest.class, + org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class, + org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class, + org.alfresco.rest.api.tests.NodeSizeDetailsTest.class}) public class AppContext02TestSuite -{ -} +{} From ebce0529271b15f03c0f02f2718f8d62b1fd39e5 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 9 Oct 2024 14:43:24 +0530 Subject: [PATCH 229/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments and refactoring files --- .secrets.baseline | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.secrets.baseline b/.secrets.baseline index 4f2c57dff61..f5cdfe1c321 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -1889,4 +1889,4 @@ ] }, "generated_at": "2024-10-02T10:18:47Z" -} +} \ No newline at end of file From 7187b5bc470fdcf7f9d0ec8cbb3115d89852ce49 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 9 Oct 2024 15:31:39 +0530 Subject: [PATCH 230/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments and refactoring files --- .secrets.baseline | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index f5cdfe1c321..2fe959c947a 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -731,7 +731,7 @@ "filename": "remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java", "hashed_secret": "d033e22ae348aeb5660fc2140aec35850c4da997", "is_verified": false, - "line_number": 120, + "line_number": 121, "is_secret": false } ], @@ -1888,5 +1888,5 @@ } ] }, - "generated_at": "2024-10-02T10:18:47Z" + "generated_at": "2024-10-09T09:32:52Z" } \ No newline at end of file From b8d08f0866f1afaea54f702109111f06c196663c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Wed, 9 Oct 2024 15:53:41 +0530 Subject: [PATCH 231/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments and refactoring files --- .secrets.baseline | 2 +- .../org/alfresco/AppContext04TestSuite.java | 107 +++--- .../rest/api/tests/AbstractBaseApiTest.java | 356 +++++++++--------- 3 files changed, 240 insertions(+), 225 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 2fe959c947a..42456c42abc 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -731,7 +731,7 @@ "filename": "remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java", "hashed_secret": "d033e22ae348aeb5660fc2140aec35850c4da997", "is_verified": false, - "line_number": 121, + "line_number": 111, "is_secret": false } ], diff --git a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java index adcd9aee52a..eec9f3db37c 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -4,82 +4,81 @@ * %% * 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 + * 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; -import org.alfresco.repo.web.scripts.TestWebScriptRepoServer; -import org.alfresco.util.testing.category.DBTests; -import org.alfresco.util.testing.category.NonBuildTests; import org.junit.experimental.categories.Categories; import org.junit.runner.RunWith; import org.junit.runners.Suite; +import org.alfresco.repo.web.scripts.TestWebScriptRepoServer; +import org.alfresco.util.testing.category.DBTests; +import org.alfresco.util.testing.category.NonBuildTests; + @RunWith(Categories.class) @Categories.ExcludeCategory({DBTests.class, NonBuildTests.class}) @Suite.SuiteClasses({ - // [classpath:alfresco/application-context.xml, classpath:alfresco/web-scripts-application-context-test.xml, - // classpath:alfresco/web-scripts-application-context.xml] - org.alfresco.repo.web.scripts.quickshare.QuickShareRestApiTest.class, - org.alfresco.repo.web.scripts.admin.AdminWebScriptTest.class, - org.alfresco.repo.web.scripts.audit.AuditWebScriptTest.class, - org.alfresco.repo.web.scripts.blogs.BlogServiceTest.class, - org.alfresco.repo.web.scripts.dictionary.DictionaryRestApiTest.class, - org.alfresco.repo.web.scripts.discussion.DiscussionRestApiTest.class, - org.alfresco.repo.web.scripts.activities.feed.control.FeedControlTest.class, - org.alfresco.repo.web.scripts.forms.FormRestApiGet_Test.class, - org.alfresco.repo.web.scripts.forms.FormRestApiJsonPost_Test.class, - org.alfresco.repo.web.scripts.groups.GroupsTest.class, - org.alfresco.repo.web.scripts.invitation.InvitationWebScriptTest.class, - org.alfresco.repo.web.scripts.invite.InviteServiceTest.class, - org.alfresco.repo.web.scripts.LoginTest.class, - org.alfresco.repo.web.scripts.search.PersonSearchTest.class, - org.alfresco.repo.web.scripts.person.PersonServiceTest.class, - org.alfresco.repo.web.scripts.preference.PreferenceServiceTest.class, - org.alfresco.repo.web.scripts.rating.RatingRestApiTest.class, - org.alfresco.repo.web.scripts.replication.ReplicationRestApiTest.class, - org.alfresco.repo.web.scripts.RepositoryContainerTest.class, - org.alfresco.repo.web.scripts.rule.RuleServiceTest.class, - org.alfresco.repo.web.scripts.action.RunningActionRestApiTest.class, - org.alfresco.repo.web.scripts.site.SiteServiceTest.class, - org.alfresco.repo.web.scripts.tagging.TaggingServiceTest.class, - org.alfresco.repo.web.scripts.thumbnail.ThumbnailServiceTest.class, - org.alfresco.repo.web.scripts.transfer.TransferWebScriptTest.class, - org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest.class, - org.alfresco.repo.web.scripts.solr.SOLRWebScriptTest.class, - org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceRestApiTest.class, - org.alfresco.repo.web.scripts.facet.FacetRestApiTest.class, - org.alfresco.repo.web.scripts.comment.CommentsApiTest.class, - org.alfresco.repo.web.scripts.content.ContentGetTest.class, - org.alfresco.repo.web.scripts.XssVulnerabilityTest.class, - org.alfresco.repo.web.scripts.links.LinksRestApiTest.class, - org.alfresco.repo.model.filefolder.RemoteFileFolderLoaderTest.class, - org.alfresco.repo.web.scripts.ReadOnlyTransactionInGetRestApiTest.class, - org.alfresco.repo.web.scripts.custommodel.CustomModelImportTest.class, - org.alfresco.repo.web.scripts.site.SurfConfigTest.class, - org.alfresco.repo.web.scripts.node.NodeWebScripTest.class, - org.alfresco.rest.api.impl.CommentsImplUnitTest.class, - org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, - org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, - org.alfresco.rest.api.impl.SizeDetailsImplTest.class -}) + // [classpath:alfresco/application-context.xml, classpath:alfresco/web-scripts-application-context-test.xml, + // classpath:alfresco/web-scripts-application-context.xml] + org.alfresco.repo.web.scripts.quickshare.QuickShareRestApiTest.class, + org.alfresco.repo.web.scripts.admin.AdminWebScriptTest.class, + org.alfresco.repo.web.scripts.audit.AuditWebScriptTest.class, + org.alfresco.repo.web.scripts.blogs.BlogServiceTest.class, + org.alfresco.repo.web.scripts.dictionary.DictionaryRestApiTest.class, + org.alfresco.repo.web.scripts.discussion.DiscussionRestApiTest.class, + org.alfresco.repo.web.scripts.activities.feed.control.FeedControlTest.class, + org.alfresco.repo.web.scripts.forms.FormRestApiGet_Test.class, + org.alfresco.repo.web.scripts.forms.FormRestApiJsonPost_Test.class, + org.alfresco.repo.web.scripts.groups.GroupsTest.class, + org.alfresco.repo.web.scripts.invitation.InvitationWebScriptTest.class, + org.alfresco.repo.web.scripts.invite.InviteServiceTest.class, org.alfresco.repo.web.scripts.LoginTest.class, + org.alfresco.repo.web.scripts.search.PersonSearchTest.class, + org.alfresco.repo.web.scripts.person.PersonServiceTest.class, + org.alfresco.repo.web.scripts.preference.PreferenceServiceTest.class, + org.alfresco.repo.web.scripts.rating.RatingRestApiTest.class, + org.alfresco.repo.web.scripts.replication.ReplicationRestApiTest.class, + org.alfresco.repo.web.scripts.RepositoryContainerTest.class, + org.alfresco.repo.web.scripts.rule.RuleServiceTest.class, + org.alfresco.repo.web.scripts.action.RunningActionRestApiTest.class, + org.alfresco.repo.web.scripts.site.SiteServiceTest.class, + org.alfresco.repo.web.scripts.tagging.TaggingServiceTest.class, + org.alfresco.repo.web.scripts.thumbnail.ThumbnailServiceTest.class, + org.alfresco.repo.web.scripts.transfer.TransferWebScriptTest.class, + org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest.class, + org.alfresco.repo.web.scripts.solr.SOLRWebScriptTest.class, + org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceRestApiTest.class, + org.alfresco.repo.web.scripts.facet.FacetRestApiTest.class, + org.alfresco.repo.web.scripts.comment.CommentsApiTest.class, + org.alfresco.repo.web.scripts.content.ContentGetTest.class, + org.alfresco.repo.web.scripts.XssVulnerabilityTest.class, + org.alfresco.repo.web.scripts.links.LinksRestApiTest.class, + org.alfresco.repo.model.filefolder.RemoteFileFolderLoaderTest.class, + org.alfresco.repo.web.scripts.ReadOnlyTransactionInGetRestApiTest.class, + org.alfresco.repo.web.scripts.custommodel.CustomModelImportTest.class, + org.alfresco.repo.web.scripts.site.SurfConfigTest.class, + org.alfresco.repo.web.scripts.node.NodeWebScripTest.class, + org.alfresco.rest.api.impl.CommentsImplUnitTest.class, + org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class, + org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class, + org.alfresco.rest.api.impl.SizeDetailsImplTest.class}) public class AppContext04TestSuite { public AppContext04TestSuite() diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java index 4a6764ff422..dce7aea3f88 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/AbstractBaseApiTest.java @@ -4,48 +4,66 @@ * %% * 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 + * 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.tests; -import org.alfresco.repo.content.directurl.SystemWideDirectUrlConfig; -import org.alfresco.rest.api.impl.directurl.RestApiDirectUrlConfig; -import org.alfresco.rest.api.tests.client.PublicApiHttpClient; -import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString; -import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString; +import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.json.simple.JSONObject; +import org.junit.After; +import org.junit.Before; +import org.junit.experimental.categories.Category; +import org.springframework.util.ResourceUtils; +import org.alfresco.repo.content.directurl.SystemWideDirectUrlConfig; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.tenant.TenantUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.impl.directurl.RestApiDirectUrlConfig; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.nodes.NodesEntityResource; import org.alfresco.rest.api.tests.RepoService.TestNetwork; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; +import org.alfresco.rest.api.tests.client.PublicApiHttpClient; import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload; import org.alfresco.rest.api.tests.client.PublicApiHttpClient.RequestBuilder; import org.alfresco.rest.api.tests.client.RequestContext; @@ -65,26 +83,10 @@ import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.util.TempFileProvider; import org.alfresco.util.testing.category.LuceneTests; -import org.json.simple.JSONObject; -import org.junit.After; -import org.junit.Before; -import org.junit.experimental.categories.Category; -import org.springframework.util.ResourceUtils; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.HashMap; /** * Generic methods for calling the Api (originally taken and adapted from BaseCustomModelApiTest) - * + * * @author Jamal Kaabi-Mofrad * @author janv * @author gethin @@ -94,55 +96,40 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi { public static final String LAST_MODIFIED_HEADER = "Last-Modified"; public static final String IF_MODIFIED_SINCE_HEADER = "If-Modified-Since"; - - private static final String RESOURCE_PREFIX = "publicapi/upload/"; - protected static final String URL_NODES = "nodes"; protected static final String URL_DELETED_NODES = "deleted-nodes"; - protected static final String URL_RENDITIONS = "renditions"; protected static final String URL_VERSIONS = "versions"; - - private static final String URL_CHILDREN = "children"; - private static final String URL_CONTENT = "content"; - private static final String URL_CALCULATEFOLDERSIZE = "size-details"; - protected static final String TYPE_CM_FOLDER = "cm:folder"; protected static final String TYPE_CM_CONTENT = "cm:content"; protected static final String TYPE_CM_OBJECT = "cm:cmobject"; - protected static final String ASPECT_CM_PREFERENCES = "cm:preferences"; protected static final String ASSOC_TYPE_CM_PREFERENCE_IMAGE = "cm:preferenceImage"; - protected static final String ASSOC_TYPE_CM_CONTAINS = "cm:contains"; - // TODO improve admin-related tests, including ability to override default admin un/pw protected static final String DEFAULT_ADMIN = "admin"; protected static final String DEFAULT_ADMIN_PWD = "admin"; - + protected static final long PAUSE_TIME = 5000; // millisecond + protected static final int MAX_RETRY = 20; + private static final String RESOURCE_PREFIX = "publicapi/upload/"; + private static final String URL_CHILDREN = "children"; + private static final String URL_CONTENT = "content"; + private static final String URL_CALCULATEFOLDERSIZE = "size-details"; + private static final String REQUEST_DIRECT_ACCESS_URL = "request-direct-access-url"; // network1 with user1, user2 and a testsite1 protected static TestNetwork networkOne; - protected static String user1; // user1 from network1 protected static String user2; // user2 from network1 - // network admin (or default super admin, if not running within a tenant/network) protected static String networkAdmin = DEFAULT_ADMIN; - protected static String tSiteId; protected static String tDocLibNodeId; - - protected static List users = new ArrayList<>(); - protected static JacksonUtil jacksonUtil; protected static MutableAuthenticationService authenticationService; protected static PersonService personService; + protected final String RUNID = System.currentTimeMillis() + ""; - protected final String RUNID = System.currentTimeMillis()+""; - - private static final String REQUEST_DIRECT_ACCESS_URL = "request-direct-access-url"; - @Override @Before public void setup() throws Exception @@ -154,22 +141,22 @@ public void setup() throws Exception // note: populateTestData/createTestData will be called (which currently creates 2 tenants, 9 users per tenant, 10 sites per tenant, ...) networkOne = getTestFixture().getRandomNetwork(); } - - //userOneN1 = networkN1.createUser(); - //userTwoN1 = networkN1.createUser(); + + // userOneN1 = networkN1.createUser(); + // userTwoN1 = networkN1.createUser(); String tenantDomain = networkOne.getId(); - - if (! TenantService.DEFAULT_DOMAIN.equals(tenantDomain)) + + if (!TenantService.DEFAULT_DOMAIN.equals(tenantDomain)) { - networkAdmin = DEFAULT_ADMIN+"@"+tenantDomain; + networkAdmin = DEFAULT_ADMIN + "@" + tenantDomain; } // to enable admin access via test calls - eg. via PublicApiClient -> AbstractTestApi -> findUserByUserName getOrCreateUser(networkAdmin, "admin", networkOne); - + setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); - + // note: createUser currently relies on repoService user1 = createUser("user1-" + RUNID, "user1Password", networkOne); user2 = createUser("user2-" + RUNID, "user2Password", networkOne); @@ -181,7 +168,7 @@ public void setup() throws Exception users.add(user2); setRequestContext(networkOne.getId(), user1, null); - + tSiteId = createSite("TestSite A - " + RUNID, SiteVisibility.PRIVATE).getId(); tDocLibNodeId = getSiteContainerNodeId(tSiteId, "documentLibrary"); @@ -198,11 +185,10 @@ public void tearDown() throws Exception } setRequestContext(networkAdmin); - + for (final String username : users) { - transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() - { + transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() { @Override public Void execute() throws Throwable { @@ -211,7 +197,7 @@ public Void execute() throws Throwable } }); } - + users.clear(); AuthenticationUtil.clearCurrentSecurityContext(); setRequestContext(null); @@ -234,7 +220,8 @@ protected String getRequestArchivedContentDirectUrl(String nodeId) protected String getRequestArchivedRenditonContentDirectUrl(String nodeId, String renditionID) { - return URL_DELETED_NODES + "/" + nodeId + "/" + URL_RENDITIONS + "/" + renditionID + "/" + REQUEST_DIRECT_ACCESS_URL; + return URL_DELETED_NODES + "/" + nodeId + "/" + URL_RENDITIONS + "/" + renditionID + "/" + + REQUEST_DIRECT_ACCESS_URL; } protected String getRequestRenditionDirectAccessUrl(String nodeId, String renditionID) @@ -247,7 +234,6 @@ protected String getRequestVersionDirectAccessUrl(String nodeId, String versionI return URL_NODES + "/" + nodeId + "/" + URL_VERSIONS + "/" + versionId + "/" + REQUEST_DIRECT_ACCESS_URL; } - /** * The api scope. either public or private * @@ -263,10 +249,10 @@ protected HttpResponse post(String url, String body, int expectedStatus) throws return response; } - protected HttpResponse post(String url, byte[] body, Map params, Map headers, String apiName, String contentType, int expectedStatus) throws Exception + protected HttpResponse post(String url, byte[] body, Map params, Map headers, + String apiName, String contentType, int expectedStatus) throws Exception { - RequestBuilder requestBuilder = httpClient.new PostRequestBuilder() - .setBodyAsByteArray(body) + RequestBuilder requestBuilder = httpClient.new PostRequestBuilder().setBodyAsByteArray(body) .setContentType(contentType) .setRequestContext(publicApiClient.getRequestContext()) .setScope(getScope()) @@ -280,10 +266,10 @@ protected HttpResponse post(String url, byte[] body, Map params, return response; } - protected HttpResponse post(String url, String body, Map params, Map headers, String apiName, int expectedStatus) throws Exception + protected HttpResponse post(String url, String body, Map params, Map headers, + String apiName, int expectedStatus) throws Exception { - RequestBuilder requestBuilder = httpClient.new PostRequestBuilder() - .setBodyAsString(body) + RequestBuilder requestBuilder = httpClient.new PostRequestBuilder().setBodyAsString(body) .setRequestContext(publicApiClient.getRequestContext()) .setScope(getScope()) .setApiName(apiName) @@ -308,7 +294,8 @@ protected HttpResponse post(String url, String body, String queryString, int exp return response; } - protected HttpResponse post(String url, String body, String queryString, String contentType, int expectedStatus) throws Exception + protected HttpResponse post(String url, String body, String queryString, String contentType, int expectedStatus) + throws Exception { if (queryString != null) { @@ -320,7 +307,8 @@ protected HttpResponse post(String url, String body, String queryString, String return response; } - protected HttpResponse post(String url, byte[] body, String queryString, String contentType, int expectedStatus) throws Exception + protected HttpResponse post(String url, byte[] body, String queryString, String contentType, int expectedStatus) + throws Exception { if (queryString != null) { @@ -333,9 +321,12 @@ protected HttpResponse post(String url, byte[] body, String queryString, String } // TODO unused queryString - fix-up usages and then remove - protected HttpResponse post(String entityCollectionName, String entityId, String relationCollectionName, byte[] body, String queryString, String contentType, int expectedStatus) throws Exception + protected HttpResponse post(String entityCollectionName, String entityId, String relationCollectionName, + byte[] body, String queryString, String contentType, int expectedStatus) + throws Exception { - HttpResponse response = publicApiClient.post(getScope(), entityCollectionName, entityId, relationCollectionName, null, body, contentType); + HttpResponse response = publicApiClient.post(getScope(), entityCollectionName, entityId, relationCollectionName, null, body, + contentType); checkStatus(expectedStatus, response.getStatusCode()); return response; @@ -346,7 +337,8 @@ protected HttpResponse getAll(String url, PublicApiClient.Paging paging, int exp return getAll(url, paging, null, expectedStatus); } - protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map otherParams, int expectedStatus) throws Exception + protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map otherParams, + int expectedStatus) throws Exception { Map params = createParams(paging, otherParams); @@ -356,7 +348,8 @@ protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map entityResource, PublicApiClient.Paging paging, Map otherParams, int expectedStatus) throws Exception + protected HttpResponse getAll(Class entityResource, PublicApiClient.Paging paging, + Map otherParams, int expectedStatus) throws Exception { HttpResponse response = publicApiClient.get(entityResource, null, null, otherParams); checkStatus(expectedStatus, response.getStatusCode()); @@ -364,16 +357,17 @@ protected HttpResponse getAll(Class entityResource, PublicApiClient.Paging pa return response; } - protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map otherParams, Map headers, int expectedStatus) throws Exception + protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map otherParams, + Map headers, int expectedStatus) throws Exception { return getAll(url, paging, otherParams, headers, null, expectedStatus); } - protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map otherParams, Map headers, String apiName, int expectedStatus) throws Exception + protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map otherParams, + Map headers, String apiName, int expectedStatus) throws Exception { Map params = createParams(paging, otherParams); - RequestBuilder requestBuilder = httpClient.new GetRequestBuilder() - .setRequestContext(publicApiClient.getRequestContext()) + RequestBuilder requestBuilder = httpClient.new GetRequestBuilder().setRequestContext(publicApiClient.getRequestContext()) .setScope(getScope()) .setApiName(apiName) .setEntityCollectionName(url) @@ -385,7 +379,7 @@ protected HttpResponse getAll(String url, PublicApiClient.Paging paging, Map params, int expectedStat return response; } - protected HttpResponse getSingle(String url, String entityId, Map params, int expectedStatus) throws Exception + protected HttpResponse getSingle(String url, String entityId, Map params, int expectedStatus) + throws Exception { HttpResponse response = publicApiClient.get(getScope(), url, entityId, null, null, params); checkStatus(expectedStatus, response.getStatusCode()); @@ -407,7 +402,8 @@ protected HttpResponse getSingle(String url, String entityId, Map entityResource, String entityId, Map params, int expectedStatus) throws Exception + protected HttpResponse getSingle(Class entityResource, String entityId, Map params, + int expectedStatus) throws Exception { HttpResponse response = publicApiClient.get(entityResource, entityId, null, params); checkStatus(expectedStatus, response.getStatusCode()); @@ -415,15 +411,16 @@ protected HttpResponse getSingle(Class entityResource, String entityId, Map params, Map headers, int expectedStatus) throws Exception + protected HttpResponse getSingle(String url, String entityId, Map params, + Map headers, int expectedStatus) throws Exception { return getSingle(url, entityId, params, headers, null, expectedStatus); } - protected HttpResponse getSingle(String url, String entityId, Map params, Map headers, String apiName, int expectedStatus) throws Exception + protected HttpResponse getSingle(String url, String entityId, Map params, + Map headers, String apiName, int expectedStatus) throws Exception { - RequestBuilder requestBuilder = httpClient.new GetRequestBuilder() - .setRequestContext(publicApiClient.getRequestContext()) + RequestBuilder requestBuilder = httpClient.new GetRequestBuilder().setRequestContext(publicApiClient.getRequestContext()) .setScope(getScope()) .setApiName(apiName) .setEntityCollectionName(url) @@ -438,7 +435,8 @@ protected HttpResponse getSingle(String url, String entityId, Map params, - Map headers, int repeat, long pauseInMillisecond, int expectedStatus) throws Exception + Map headers, int repeat, long pauseInMillisecond, + int expectedStatus) throws Exception { int retryCount = 0; while (retryCount < repeat) @@ -446,7 +444,7 @@ protected HttpResponse getSingleWithDelayRetry(String url, String entityId, Map< try { return getSingle(url, entityId, params, headers, expectedStatus); - } + } catch (AssertionError ex) { retryCount++; @@ -456,7 +454,8 @@ protected HttpResponse getSingleWithDelayRetry(String url, String entityId, Map< return null; } - protected HttpResponse put(String url, String entityId, String body, String queryString, int expectedStatus) throws Exception + protected HttpResponse put(String url, String entityId, String body, String queryString, int expectedStatus) + throws Exception { if (queryString != null) { @@ -468,8 +467,8 @@ protected HttpResponse put(String url, String entityId, String body, String quer return response; } - protected HttpResponse putBinary(String url, int version, BinaryPayload payload, String queryString, Map params, - int expectedStatus) throws Exception + protected HttpResponse putBinary(String url, int version, BinaryPayload payload, String queryString, + Map params, int expectedStatus) throws Exception { if (queryString != null) { @@ -483,7 +482,7 @@ protected HttpResponse putBinary(String url, int version, BinaryPayload payload, } protected HttpResponse putBinary(String url, BinaryPayload payload, String queryString, Map params, - int expectedStatus) throws Exception + int expectedStatus) throws Exception { return putBinary(url, 1, payload, queryString, params, expectedStatus); } @@ -493,18 +492,19 @@ protected HttpResponse delete(String url, String entityId, int expectedStatus) t return delete(url, entityId, null, expectedStatus); } - protected HttpResponse delete(String url, String entityId, Map params, int expectedStatus) throws Exception + protected HttpResponse delete(String url, String entityId, Map params, int expectedStatus) + throws Exception { HttpResponse response = publicApiClient.delete(getScope(), 1, url, entityId, null, null, params); checkStatus(expectedStatus, response.getStatusCode()); return response; } - - protected HttpResponse delete(String url, String entityId, Map params, Map headers, String apiName, int expectedStatus) throws Exception + + protected HttpResponse delete(String url, String entityId, Map params, Map headers, + String apiName, int expectedStatus) throws Exception { - RequestBuilder requestBuilder = httpClient.new DeleteRequestBuilder() - .setRequestContext(publicApiClient.getRequestContext()) + RequestBuilder requestBuilder = httpClient.new DeleteRequestBuilder().setRequestContext(publicApiClient.getRequestContext()) .setScope(getScope()) .setApiName(apiName) .setEntityCollectionName(url) @@ -525,7 +525,10 @@ protected String createUser(String username) protected String createUser(String usernameIn, String password, TestNetwork network) { - return createUser(new PersonInfo(usernameIn, usernameIn, usernameIn, password, null, null, null, null, null, null, null), network); + return createUser( + new PersonInfo(usernameIn, usernameIn, usernameIn, password, null, null, null, null, null, null, + null), + network); } /** @@ -534,17 +537,16 @@ protected String createUser(String usernameIn, String password, TestNetwork netw protected String createUser(final PersonInfo personInfo, final TestNetwork network) { final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN); - - return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() - { + + return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() { @Override public String doWork() throws Exception { - return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork() - { + return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork() { public String doWork() throws Exception { - String username = repoService.getPublicApiContext().createUserName(personInfo.getUsername(), tenantDomain); + String username = repoService.getPublicApiContext() + .createUserName(personInfo.getUsername(), tenantDomain); personInfo.setUsername(username); RepoService.TestPerson person = repoService.createUser(personInfo, username, network); return person.getId(); @@ -562,17 +564,17 @@ protected String getOrCreateUser(String usernameIn, String password, TestNetwork { final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN); - return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() - { + return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() { @Override public String doWork() throws Exception { - return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork() - { + return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork() { public String doWork() throws Exception { - String username = repoService.getPublicApiContext().createUserName(usernameIn, tenantDomain); - PersonInfo personInfo = new PersonInfo(username, username, username, password, null, null, null, null, null, null, null); + String username = repoService.getPublicApiContext() + .createUserName(usernameIn, tenantDomain); + PersonInfo personInfo = new PersonInfo(username, username, username, password, null, null, null, null, null, + null, null); RepoService.TestPerson person = repoService.getOrCreateUser(personInfo, username, network); return person.getId(); } @@ -588,13 +590,11 @@ protected String deleteUser(final String username, final TestNetwork network) { final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN); - return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() - { + return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() { @Override public String doWork() throws Exception { - return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork() - { + return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork() { public String doWork() throws Exception { repoService.deleteUser(username, network); @@ -604,13 +604,15 @@ public String doWork() throws Exception } }, networkAdmin); } - + protected SiteMember addSiteMember(String siteId, String userId, final SiteRole siteRole) throws Exception { SiteMember siteMember = new SiteMember(userId, siteRole.name()); - HttpResponse response = publicApiClient.post(getScope(), "sites", siteId, "members", null, siteMember.toJSON().toString()); + HttpResponse response = publicApiClient.post(getScope(), "sites", siteId, "members", null, siteMember.toJSON() + .toString()); checkStatus(201, response.getStatusCode()); - return SiteMember.parseSiteMember(siteMember.getSiteId(), (JSONObject)response.getJsonResponse().get("entry")); + return SiteMember.parseSiteMember(siteMember.getSiteId(), (JSONObject) response.getJsonResponse() + .get("entry")); } protected Site createSite(String siteTitle, SiteVisibility siteVisibility) throws Exception @@ -618,7 +620,8 @@ protected Site createSite(String siteTitle, SiteVisibility siteVisibility) throw return createSite(null, siteTitle, null, siteVisibility, 201); } - protected Site createSite(String siteId, String siteTitle, String siteDescription, SiteVisibility siteVisibility, int expectedStatus) throws Exception + protected Site createSite(String siteId, String siteTitle, String siteDescription, SiteVisibility siteVisibility, + int expectedStatus) throws Exception { Site site = new Site(); site.setId(siteId); @@ -634,7 +637,7 @@ protected Site createSite(String siteId, String siteTitle, String siteDescriptio protected HttpResponse deleteSite(String siteId, boolean permanent, int expectedStatus) throws Exception { Map params = null; - if (permanent == true) + if (permanent) { params = Collections.singletonMap("permanent", "true"); } @@ -656,14 +659,14 @@ protected HttpResponse deleteSite(String siteId, boolean permanent, int expected protected String getSiteContainerNodeId(String siteId, String containerNameId) throws Exception { Map params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/Sites/" + siteId + "/" + containerNameId); - + HttpResponse response = publicApiClient.get(NodesEntityResource.class, Nodes.PATH_ROOT, null, params); checkStatus(200, response.getStatusCode()); Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); return node.getId(); } - + protected void checkStatus(int expectedStatus, int actualStatus) { if (expectedStatus > 0 && expectedStatus != actualStatus) @@ -673,9 +676,8 @@ protected void checkStatus(int expectedStatus, int actualStatus) } /** - * @deprecated - * * @param runAsUser + * @deprecated */ protected void setRequestContext(String runAsUser) { @@ -703,9 +705,9 @@ protected void setRequestContext(String runAsNetwork, String runAsUser, String p } else if ((runAsUser != null) && runAsUser.equals(DEFAULT_ADMIN)) { - runAsUser = runAsUser+"@"+runAsNetwork; + runAsUser = runAsUser + "@" + runAsNetwork; } - + publicApiClient.setRequestContext(new RequestContext(runAsNetwork, runAsUser, password)); } @@ -737,7 +739,7 @@ protected Folder createFolder(String parentId, String folderName) throws Excepti { return createFolder(parentId, folderName, null); } - + protected Folder createFolder(String parentId, String folderName, Map props) throws Exception { return createNode(parentId, folderName, TYPE_CM_FOLDER, props, Folder.class); @@ -751,17 +753,18 @@ protected String createUniqueFolder(String parentId) throws Exception protected String createUniqueContent(String folderId) throws Exception { Document documentResp = createTextFile(folderId, "file-" + System.currentTimeMillis(), - "some text-" + System.currentTimeMillis(), "UTF-8", null); + "some text-" + System.currentTimeMillis(), "UTF-8", null); return documentResp.getId(); } - protected Node createNode(String parentId, String nodeName, String nodeType, Map props) throws Exception + protected Node createNode(String parentId, String nodeName, String nodeType, Map props) + throws Exception { return createNode(parentId, nodeName, nodeType, props, Node.class); } - protected T createNode(String parentId, String nodeName, String nodeType, Map props, Class returnType) - throws Exception + protected T createNode(String parentId, String nodeName, String nodeType, Map props, + Class returnType) throws Exception { Node n = new Node(); n.setName(nodeName); @@ -773,7 +776,7 @@ protected T createNode(String parentId, String nodeName, String nodeType, Ma return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), returnType); } - + protected void deleteNode(String nodeId) throws Exception { deleteNode(nodeId, 204); @@ -787,25 +790,27 @@ protected void deleteNode(String nodeId, int expectedStatus) throws Exception protected void deleteNode(String nodeId, boolean permanent, int expectedStatus) throws Exception { Map params = null; - if (permanent == true) + if (permanent) { params = Collections.singletonMap("permanent", "true"); } - + delete(URL_NODES, nodeId, params, expectedStatus); } - protected Document createTextFile(String parentId, String fileName, String textContent) throws IOException, Exception + protected Document createTextFile(String parentId, String fileName, String textContent) throws Exception { return createTextFile(parentId, fileName, textContent, "UTF-8", null); } - protected Document createTextFile(String parentId, String fileName, String textContent, String encoding, Map props) throws IOException, Exception + protected Document createTextFile(String parentId, String fileName, String textContent, String encoding, + Map props) throws Exception { return createTextFile(parentId, fileName, textContent, encoding, props, 201); } - protected Document createTextFile(String parentId, String fileName, String textContent, String encoding, Map props, int expectedStatus) throws IOException, Exception + protected Document createTextFile(String parentId, String fileName, String textContent, String encoding, + Map props, int expectedStatus) throws Exception { if (props == null) { @@ -821,9 +826,11 @@ protected Document createTextFile(String parentId, String fileName, String textC .setProperties(props) .build(); - HttpResponse response = post(getNodeChildrenUrl(parentId), reqBody.getBody(), null, reqBody.getContentType(), expectedStatus); + HttpResponse response = post(getNodeChildrenUrl(parentId), reqBody.getBody(), null, reqBody.getContentType(), + expectedStatus); - if (response.getJsonResponse().get("error") != null) + if (response.getJsonResponse() + .get("error") != null) { return null; } @@ -835,8 +842,9 @@ protected Document createEmptyTextFile(String parentFolderId, String docName) th { return createEmptyTextFile(parentFolderId, docName, null, 201); } - - protected Document createEmptyTextFile(String parentFolderId, String docName, Map params, int expectedStatus) throws Exception + + protected Document createEmptyTextFile(String parentFolderId, String docName, Map params, + int expectedStatus) throws Exception { Document d1 = new Document(); d1.setName(docName); @@ -846,7 +854,8 @@ protected Document createEmptyTextFile(String parentFolderId, String docName, Ma d1.setContent(ci); // create empty file - HttpResponse response = post(getNodeChildrenUrl(parentFolderId), toJsonAsStringNonNull(d1), params, null, "alfresco", expectedStatus); + HttpResponse response = post(getNodeChildrenUrl(parentFolderId), toJsonAsStringNonNull(d1), params, null, "alfresco", + expectedStatus); if (expectedStatus != 201) { return null; @@ -859,7 +868,8 @@ protected Document updateTextFile(String contentId, String textContent, Map params, int expectedStatus) throws Exception + protected Document updateTextFile(String contentId, String textContent, Map params, + int expectedStatus) throws Exception { ByteArrayInputStream inputStream = new ByteArrayInputStream(textContent.getBytes()); File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); @@ -875,7 +885,8 @@ protected Document updateTextFile(String contentId, String textContent, Map params = new HashMap<>(); params.put(Nodes.PARAM_OVERWRITE, "true"); @@ -929,7 +941,6 @@ protected String updateFileVersions(String userId, String contentNodeId, int cnt majorVersion = false; } - if (majorVersion) { minorVer = 0; @@ -962,30 +973,33 @@ protected String updateFileVersions(String userId, String contentNodeId, int cnt HttpResponse response = putBinary(getNodeContentUrl(contentNodeId), payload, null, params, 200); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); - assertTrue(nodeResp.getAspectNames().contains("cm:versionable")); + assertTrue(nodeResp.getAspectNames() + .contains("cm:versionable")); assertNotNull(nodeResp.getProperties()); - assertEquals(currentVersionLabel, nodeResp.getProperties().get("cm:versionLabel")); - assertEquals((majorVersion ? "MAJOR" : "MINOR"), nodeResp.getProperties().get("cm:versionType")); + assertEquals(currentVersionLabel, nodeResp.getProperties() + .get("cm:versionLabel")); + assertEquals((majorVersion ? "MAJOR" : "MINOR"), nodeResp.getProperties() + .get("cm:versionType")); // double-check - get version node info response = getSingle(getNodeVersionsUrl(contentNodeId), currentVersionLabel, null, 200); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); - assertEquals(currentVersionLabel, nodeResp.getProperties().get("cm:versionLabel")); - assertEquals((majorVersion ? "MAJOR" : "MINOR"), nodeResp.getProperties().get("cm:versionType")); + assertEquals(currentVersionLabel, nodeResp.getProperties() + .get("cm:versionLabel")); + assertEquals((majorVersion ? "MAJOR" : "MINOR"), nodeResp.getProperties() + .get("cm:versionType")); } return currentVersionLabel; } - protected static final long PAUSE_TIME = 5000; //millisecond - protected static final int MAX_RETRY = 20; - protected Rendition waitAndGetRendition(String sourceNodeId, String versionId, String renditionId) throws Exception { return waitAndGetRendition(sourceNodeId, versionId, renditionId, MAX_RETRY, PAUSE_TIME); } - protected Rendition waitAndGetRendition(String sourceNodeId, String versionId, String renditionId, int maxRetry, long pauseTime) throws Exception + protected Rendition waitAndGetRendition(String sourceNodeId, String versionId, String renditionId, int maxRetry, + long pauseTime) throws Exception { int retryCount = 0; while (retryCount < maxRetry) @@ -993,7 +1007,7 @@ protected Rendition waitAndGetRendition(String sourceNodeId, String versionId, S try { HttpResponse response; - if ((versionId != null) && (! versionId.isEmpty())) + if ((versionId != null) && (!versionId.isEmpty())) { response = getSingle(getNodeVersionRenditionsUrl(sourceNodeId, versionId), renditionId, 200); } @@ -1012,7 +1026,7 @@ protected Rendition waitAndGetRendition(String sourceNodeId, String versionId, S // wait for 'PAUSE_TIME' and try again. retryCount++; - System.out.println("waitAndGetRendition: "+retryCount); + System.out.println("waitAndGetRendition: " + retryCount); Thread.sleep(pauseTime); } } @@ -1025,7 +1039,8 @@ protected Rendition createAndGetRendition(String sourceNodeId, String renditionI return createAndGetRendition(sourceNodeId, null, renditionId); } - protected Rendition createAndGetRendition(String sourceNodeId, String versionId, String renditionId) throws Exception + protected Rendition createAndGetRendition(String sourceNodeId, String versionId, String renditionId) + throws Exception { Rendition renditionRequest = new Rendition(); renditionRequest.setId(renditionId); @@ -1036,9 +1051,10 @@ protected Rendition createAndGetRendition(String sourceNodeId, String versionId, try { HttpResponse response; - if ((versionId != null) && (! versionId.isEmpty())) + if ((versionId != null) && (!versionId.isEmpty())) { - response = post(getNodeVersionRenditionsUrl(sourceNodeId, versionId), toJsonAsString(renditionRequest), 202); + response = post(getNodeVersionRenditionsUrl(sourceNodeId, versionId), + toJsonAsString(renditionRequest), 202); } else { @@ -1053,7 +1069,7 @@ protected Rendition createAndGetRendition(String sourceNodeId, String versionId, // wait for 'PAUSE_TIME' and try again. retryCount++; - System.out.println("waitAndGetRendition: "+retryCount); + System.out.println("waitAndGetRendition: " + retryCount); Thread.sleep(PAUSE_TIME); } } @@ -1073,7 +1089,8 @@ protected String getNodeRenditionIdUrl(String nodeId, String renditionID) protected String getNodeVersionRenditionIdUrl(String nodeId, String versionId, String renditionID) { - return URL_NODES + "/" + nodeId + "/" + URL_VERSIONS + "/" + versionId + "/" + URL_RENDITIONS + "/" + renditionID; + return URL_NODES + "/" + nodeId + "/" + URL_VERSIONS + "/" + versionId + "/" + URL_RENDITIONS + "/" + + renditionID; } protected String getNodeVersionsUrl(String nodeId) @@ -1132,4 +1149,3 @@ protected String getNodeSizeDetailsUrl(String nodeId, String jobId) return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE + "/" + jobId; } } - From 76f537527d83b7e1307a086a7be8a14c31226bb0 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 18 Oct 2024 11:30:41 +0530 Subject: [PATCH 232/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments regarding Integeration testcases --- .../rest/api/tests/NodeSizeDetailsTest.java | 27 +++++++++++++++++-- .../NodeSizeDetailsServiceImpl.java | 15 ----------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index edb30fcc77e..6a20c7258f2 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -46,6 +46,7 @@ import org.slf4j.LoggerFactory; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; +import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; @@ -70,6 +71,8 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest private String folderId; private PermissionService permissionService; private Nodes nodes; + private final String STATUS = "COMPLETED"; + private final Long DEFAULT_SIZE = 22250000L; // Method to create content info private ContentInfo createContentInfo() @@ -141,11 +144,14 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( + NodeSizeDetails nodeSizeDetails = parseNodeSizeDetails( (JSONObject) getResponse.getJsonResponse() .get("entry")); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); + assertEquals(STATUS, nodeSizeDetails.getStatus().name(), "SizeDetails hasn't been calculated yet, with COMPLETED status"); + assertTrue("We are not getting size greater than 0", nodeSizeDetails.getSizeInBytes() > 0L); + } @Test @@ -203,7 +209,7 @@ public void testPerformanceTesting() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails( + NodeSizeDetails nodeSizeDetails = parseNodeSizeDetails( (JSONObject) getResponse.getJsonResponse() .get("entry")); @@ -212,6 +218,9 @@ public void testPerformanceTesting() throws Exception // current Time after executing GET/size-details LocalTime actualTime = LocalTime.now(); assertTrue("Calculating folder node is taking time greater than 5 seconds ", actualTime.isBefore(expectedTime)); + assertEquals(STATUS, nodeSizeDetails.getStatus().name(), "SizeDetails hasn't been calculated yet, with COMPLETED status"); + assertTrue("We are not getting size greater than 0", nodeSizeDetails.getSizeInBytes() > 0L); + assertEquals(nodeSizeDetails.getSizeInBytes(), DEFAULT_SIZE); } /** @@ -240,6 +249,20 @@ public void testHTTPStatus() throws Exception assertNotNull(responseForInvalidNode); } + private NodeSizeDetails parseNodeSizeDetails(JSONObject jsonObject) + { + if (jsonObject == null) + { + return null; + } + + String jobId = (String) jsonObject.get("jobId"); + String id = (String) jsonObject.get("id"); + String status = (String) jsonObject.get("status"); + Long sizeInBytes = (Long) jsonObject.get("sizeInBytes"); + return new NodeSizeDetails(id, sizeInBytes != null ? sizeInBytes : 0L, jobId, NodeSizeDetails.STATUS.valueOf(status)); + } + @After public void tearDown() throws Exception { diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index f8382124c41..5a2b4bda3ec 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -32,7 +32,6 @@ import java.util.Optional; import java.util.concurrent.ThreadPoolExecutor; -import org.json.simple.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; @@ -299,20 +298,6 @@ public NodeSizeDetails(String id, Long sizeInBytes, Date calculatedAt, Integer n this.jobId = jobId; } - public static NodeSizeDetails parseNodeSizeDetails(JSONObject jsonObject) - { - if (jsonObject == null) - { - return null; - } - - String jobId = (String) jsonObject.get("jobId"); - String id = (String) jsonObject.get("id"); - String status = (String) jsonObject.get("status"); - Long sizeInBytes = (Long) jsonObject.get("sizeInBytes"); - return new NodeSizeDetails(id, sizeInBytes != null ? sizeInBytes : 0L, jobId, STATUS.valueOf(status)); - } - public String getId() { return id; From 29d25eaf6b1dfeffb93bb0c345533e9b60747d85 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 18 Oct 2024 12:19:05 +0530 Subject: [PATCH 233/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments regarding Integeration testcases --- .../rest/api/tests/NodeSizeDetailsTest.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 6a20c7258f2..35135204811 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -46,7 +46,6 @@ import org.slf4j.LoggerFactory; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; -import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails.STATUS; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.tests.client.HttpResponse; @@ -71,8 +70,7 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest private String folderId; private PermissionService permissionService; private Nodes nodes; - private final String STATUS = "COMPLETED"; - private final Long DEFAULT_SIZE = 22250000L; + private final String status = "COMPLETED"; // Method to create content info private ContentInfo createContentInfo() @@ -134,6 +132,8 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); + Thread.sleep(500); + // Prepare parameters. Map params = new HashMap<>(); params.put("nodeId", folderId); @@ -149,7 +149,8 @@ public void testPostAndGetFolderSizeDetails() throws Exception .get("entry")); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); - assertEquals(STATUS, nodeSizeDetails.getStatus().name(), "SizeDetails hasn't been calculated yet, with COMPLETED status"); + + assertEquals(status, nodeSizeDetails.getStatus().name(), "SizeDetails hasn't been calculated yet, with COMPLETED status [Current status -" + nodeSizeDetails.getStatus().name() + "]"); assertTrue("We are not getting size greater than 0", nodeSizeDetails.getSizeInBytes() > 0L); } @@ -199,6 +200,8 @@ public void testPerformanceTesting() throws Exception String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); + Thread.sleep(500); + // Prepare parameters. Map params = new HashMap<>(); params.put("nodeId", folderId); @@ -218,9 +221,10 @@ public void testPerformanceTesting() throws Exception // current Time after executing GET/size-details LocalTime actualTime = LocalTime.now(); assertTrue("Calculating folder node is taking time greater than 5 seconds ", actualTime.isBefore(expectedTime)); - assertEquals(STATUS, nodeSizeDetails.getStatus().name(), "SizeDetails hasn't been calculated yet, with COMPLETED status"); + assertEquals(status, nodeSizeDetails.getStatus().name(), "SizeDetails hasn't been calculated yet, with COMPLETED status [Current status -" + nodeSizeDetails.getStatus().name() + "]"); assertTrue("We are not getting size greater than 0", nodeSizeDetails.getSizeInBytes() > 0L); - assertEquals(nodeSizeDetails.getSizeInBytes(), DEFAULT_SIZE); + Long defaultSize = 22250000L; + assertEquals(nodeSizeDetails.getSizeInBytes(), defaultSize); } /** From 16e57ae154fbb8990d501419338042b357c6f4d4 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 18 Oct 2024 12:50:15 +0530 Subject: [PATCH 234/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 35135204811..8ed9e55ef1c 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -149,8 +149,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception .get("entry")); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); - - assertEquals(status, nodeSizeDetails.getStatus().name(), "SizeDetails hasn't been calculated yet, with COMPLETED status [Current status -" + nodeSizeDetails.getStatus().name() + "]"); + assertEquals("SizeDetails hasn't been calculated yet, current status -" + nodeSizeDetails.getStatus().name() + "]", status, nodeSizeDetails.getStatus().name()); assertTrue("We are not getting size greater than 0", nodeSizeDetails.getSizeInBytes() > 0L); } @@ -221,7 +220,7 @@ public void testPerformanceTesting() throws Exception // current Time after executing GET/size-details LocalTime actualTime = LocalTime.now(); assertTrue("Calculating folder node is taking time greater than 5 seconds ", actualTime.isBefore(expectedTime)); - assertEquals(status, nodeSizeDetails.getStatus().name(), "SizeDetails hasn't been calculated yet, with COMPLETED status [Current status -" + nodeSizeDetails.getStatus().name() + "]"); + assertEquals("SizeDetails hasn't been calculated yet, current status -" + nodeSizeDetails.getStatus().name() + "]", status, nodeSizeDetails.getStatus().name()); assertTrue("We are not getting size greater than 0", nodeSizeDetails.getSizeInBytes() > 0L); Long defaultSize = 22250000L; assertEquals(nodeSizeDetails.getSizeInBytes(), defaultSize); From 855ab535b60ccb9f03a66513442a6a937b8f7154 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 18 Oct 2024 13:44:09 +0530 Subject: [PATCH 235/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../rest/api/tests/NodeSizeDetailsTest.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 8ed9e55ef1c..cefe4b4d4fe 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -120,8 +120,23 @@ public void setup() throws Exception @Test public void testPostAndGetFolderSizeDetails() throws Exception { + + UserInfo userInfo = new UserInfo(user1); + + String folder0Name = "f0-testParentFolder-" + RUNID; + String fileName = "content" + RUNID + ".txt"; + String childFolder = createFolder(folderId, folder0Name, null).getId(); + Document d1 = new Document(); + d1.setIsFolder(false); + d1.setParentId(childFolder); + d1.setName(fileName); + d1.setNodeType(TYPE_CM_CONTENT); + d1.setContent(createContentInfo()); + d1.setCreatedByUser(userInfo); + d1.setModifiedByUser(userInfo); + // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), null, 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(childFolder), null, 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); @@ -136,10 +151,10 @@ public void testPostAndGetFolderSizeDetails() throws Exception // Prepare parameters. Map params = new HashMap<>(); - params.put("nodeId", folderId); + params.put("nodeId", childFolder); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(childFolder, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); @@ -160,7 +175,7 @@ public void testPerformanceTesting() throws Exception setRequestContext(user1); UserInfo userInfo = new UserInfo(user1); - String folder0Name = "f0-testParentFolder-" + RUNID; + String folder0Name = "f1-testParentFolder-" + RUNID; String parentFolder = createFolder(tDocLibNodeId, folder0Name, null).getId(); for (int i = 1; i <= 500; i++) @@ -206,7 +221,7 @@ public void testPerformanceTesting() throws Exception params.put("nodeId", folderId); params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(parentFolder, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); From 74cc4c0b4c02ddd0c62d9add1b048a1474d39c79 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 18 Oct 2024 15:47:10 +0530 Subject: [PATCH 236/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index cefe4b4d4fe..5e1592d926a 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -147,13 +147,6 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); - Thread.sleep(500); - - // Prepare parameters. - Map params = new HashMap<>(); - params.put("nodeId", childFolder); - params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(childFolder, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", @@ -236,7 +229,7 @@ public void testPerformanceTesting() throws Exception LocalTime actualTime = LocalTime.now(); assertTrue("Calculating folder node is taking time greater than 5 seconds ", actualTime.isBefore(expectedTime)); assertEquals("SizeDetails hasn't been calculated yet, current status -" + nodeSizeDetails.getStatus().name() + "]", status, nodeSizeDetails.getStatus().name()); - assertTrue("We are not getting size greater than 0", nodeSizeDetails.getSizeInBytes() > 0L); + assertTrue("We are not getting size greater than 0 " + nodeSizeDetails, nodeSizeDetails.getSizeInBytes() > 0L); Long defaultSize = 22250000L; assertEquals(nodeSizeDetails.getSizeInBytes(), defaultSize); } From 9692257487418ae9e2d9ccb101c9aefe2cbf5e40 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 18 Oct 2024 17:00:41 +0530 Subject: [PATCH 237/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 9 --------- .../node/sizedetails/NodeSizeDetailsServiceImpl.java | 7 ++++--- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 5e1592d926a..41a4fa03864 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -30,9 +30,7 @@ import static org.junit.Assert.assertTrue; import java.time.LocalTime; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.json.simple.JSONObject; import org.junit.After; @@ -207,13 +205,6 @@ public void testPerformanceTesting() throws Exception String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); - Thread.sleep(500); - - // Prepare parameters. - Map params = new HashMap<>(); - params.put("nodeId", folderId); - params.put("jobId", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(parentFolder, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index 5a2b4bda3ec..2f7185378b3 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -372,20 +372,21 @@ public boolean equals(Object o) NodeSizeDetails that = (NodeSizeDetails) o; return Objects.equals(id, that.id) && Objects.equals(sizeInBytes, that.sizeInBytes) && Objects.equals( calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) - && Objects.equals(jobId, that.jobId); + && Objects.equals(jobId, that.jobId) && status == that.status; } @Override public int hashCode() { - return Objects.hash(id, sizeInBytes, calculatedAt, numberOfFiles, jobId); + return Objects.hash(id, sizeInBytes, calculatedAt, numberOfFiles, jobId, status); } @Override public String toString() { return "NodeSizeDetails{" + "id='" + id + '\'' + ", sizeInBytes=" + sizeInBytes + ", calculatedAt=" - + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + '}'; + + calculatedAt + ", numberOfFiles=" + numberOfFiles + ", jobId='" + jobId + '\'' + ", status=" + + status + '}'; } public enum STATUS From d49d4c2c1da123f9086c86e63248e482074b38c7 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Fri, 18 Oct 2024 17:30:44 +0530 Subject: [PATCH 238/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 41a4fa03864..a2ebc7944ea 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -156,7 +156,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); assertEquals("SizeDetails hasn't been calculated yet, current status -" + nodeSizeDetails.getStatus().name() + "]", status, nodeSizeDetails.getStatus().name()); - assertTrue("We are not getting size greater than 0", nodeSizeDetails.getSizeInBytes() > 0L); + assertTrue("We are not getting size greater than 0 " + nodeSizeDetails, nodeSizeDetails.getSizeInBytes() > 0L); } @@ -205,6 +205,8 @@ public void testPerformanceTesting() throws Exception String jobId = (String) jsonObject.get("jobId"); assertNotNull("In response, JobId should be present", jobId); + Thread.sleep(500); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(parentFolder, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", From 7f95d625938377b3a28eacb1b84a03d60780f9b4 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Sat, 19 Oct 2024 09:13:26 +0530 Subject: [PATCH 239/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index a2ebc7944ea..ac98f69bae4 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -139,10 +139,9 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); - JSONObject jsonObject = (JSONObject) postResponse.getJsonResponse() - .get("entry"); + NodeSizeDetails nodeSizeDetails = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), NodeSizeDetails.class); - String jobId = (String) jsonObject.get("jobId"); + String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(childFolder, jobId), null, 200); @@ -150,9 +149,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - NodeSizeDetails nodeSizeDetails = parseNodeSizeDetails( - (JSONObject) getResponse.getJsonResponse() - .get("entry")); + nodeSizeDetails = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), NodeSizeDetails.class); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); assertEquals("SizeDetails hasn't been calculated yet, current status -" + nodeSizeDetails.getStatus().name() + "]", status, nodeSizeDetails.getStatus().name()); From 6d6fbbe3c7bcf1d1f371dd7e64ed4267efaaab75 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Sat, 19 Oct 2024 09:42:13 +0530 Subject: [PATCH 240/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../repo/node/sizedetails/NodeSizeDetailsServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index 2f7185378b3..2ad69c72519 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -261,6 +261,9 @@ public static class NodeSizeDetails implements Serializable private String jobId; private STATUS status; + public NodeSizeDetails() + {} + public NodeSizeDetails(String jobId) { this.jobId = jobId; From 3922c07a24eb1bb8170c5b331de7f98ad4cc47e4 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Sat, 19 Oct 2024 11:33:24 +0530 Subject: [PATCH 241/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index ac98f69bae4..f916a30a9ec 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -149,7 +149,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - nodeSizeDetails = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), NodeSizeDetails.class); + nodeSizeDetails = RestApiUtil.parseRestApiEntry(getResponse.getJsonResponse(), NodeSizeDetails.class); assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); assertEquals("SizeDetails hasn't been calculated yet, current status -" + nodeSizeDetails.getStatus().name() + "]", status, nodeSizeDetails.getStatus().name()); From 28e5f76eb72a68f2b2a68329c450fed6e92b987c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Sun, 20 Oct 2024 10:04:37 +0530 Subject: [PATCH 242/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index f916a30a9ec..dd02b50a83b 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -128,13 +128,12 @@ public void testPostAndGetFolderSizeDetails() throws Exception d1.setIsFolder(false); d1.setParentId(childFolder); d1.setName(fileName); - d1.setNodeType(TYPE_CM_CONTENT); d1.setContent(createContentInfo()); d1.setCreatedByUser(userInfo); d1.setModifiedByUser(userInfo); // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(childFolder), null, 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), null, 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); @@ -144,7 +143,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(childFolder, jobId), null, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); From f39913562b2a7652e4b359cd466f5755077b28e2 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Sun, 20 Oct 2024 11:12:33 +0530 Subject: [PATCH 243/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../rest/api/tests/NodeSizeDetailsTest.java | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index dd02b50a83b..2979a1d68b9 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -30,7 +30,9 @@ import static org.junit.Assert.assertTrue; import java.time.LocalTime; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.json.simple.JSONObject; import org.junit.After; @@ -46,6 +48,7 @@ import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Site; +import org.alfresco.rest.api.nodes.NodesEntityResource; import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; import org.alfresco.rest.api.tests.client.data.ContentInfo; @@ -122,18 +125,41 @@ public void testPostAndGetFolderSizeDetails() throws Exception UserInfo userInfo = new UserInfo(user1); String folder0Name = "f0-testParentFolder-" + RUNID; - String fileName = "content" + RUNID + ".txt"; String childFolder = createFolder(folderId, folder0Name, null).getId(); + + String title = "test title"; + Map docProps = new HashMap<>(); + docProps.put("cm:title", title); + docProps.put("cm:owner", user1); + String contentName = "content " + RUNID + ".txt"; + String content1Id = createTextFile(childFolder, contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps).getId(); + + Thread.sleep(3000); + // get node info. + HttpResponse response = getSingle(NodesEntityResource.class, content1Id, null, 200); + Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); + String content_Id = documentResp.getId(); + Document d1 = new Document(); - d1.setIsFolder(false); + d1.setId(content_Id); d1.setParentId(childFolder); - d1.setName(fileName); + d1.setName(contentName); + d1.setNodeType(TYPE_CM_CONTENT); d1.setContent(createContentInfo()); d1.setCreatedByUser(userInfo); d1.setModifiedByUser(userInfo); + Map props = new HashMap<>(); + props.put("cm:title", title); + props.put("cm:versionLabel", "1.0"); + props.put("cm:versionType", "MAJOR"); + props.put("cm:owner", user1); + + d1.setProperties(props); + d1.expected(documentResp); + // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), null, 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(childFolder), null, 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); @@ -143,7 +169,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(childFolder, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); From 29e76f3074976ae715b1874e9c933924000a78ee Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Sun, 20 Oct 2024 11:46:30 +0530 Subject: [PATCH 244/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 2979a1d68b9..cbec8ee0adc 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -30,6 +30,7 @@ import static org.junit.Assert.assertTrue; import java.time.LocalTime; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -156,6 +157,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception props.put("cm:owner", user1); d1.setProperties(props); + d1.setAspectNames(Arrays.asList("cm:auditable", "cm:titled", "cm:versionable", "cm:author", "cm:ownable")); d1.expected(documentResp); // Perform POST request From 05e2bcdcdd7327cd6a8d4fa05b89c1407d867da5 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Sun, 20 Oct 2024 14:18:39 +0530 Subject: [PATCH 245/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../rest/api/tests/NodeSizeDetailsTest.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index cbec8ee0adc..644f120ca2b 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -30,7 +30,6 @@ import static org.junit.Assert.assertTrue; import java.time.LocalTime; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -141,24 +140,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String content_Id = documentResp.getId(); - Document d1 = new Document(); - d1.setId(content_Id); - d1.setParentId(childFolder); - d1.setName(contentName); - d1.setNodeType(TYPE_CM_CONTENT); - d1.setContent(createContentInfo()); - d1.setCreatedByUser(userInfo); - d1.setModifiedByUser(userInfo); - - Map props = new HashMap<>(); - props.put("cm:title", title); - props.put("cm:versionLabel", "1.0"); - props.put("cm:versionType", "MAJOR"); - props.put("cm:owner", user1); - - d1.setProperties(props); - d1.setAspectNames(Arrays.asList("cm:auditable", "cm:titled", "cm:versionable", "cm:author", "cm:ownable")); - d1.expected(documentResp); + assertNotNull("contentId shouldn't be null", content_Id); // Perform POST request HttpResponse postResponse = post(generateNodeSizeDetailsUrl(childFolder), null, 202); From 7a74f7947a2114bef889773275dd55d59ddeaf10 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 21 Oct 2024 10:34:05 +0530 Subject: [PATCH 246/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 644f120ca2b..71fcca843b3 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -110,7 +110,7 @@ public void setup() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); + folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); permissionService = applicationContext.getBean("permissionService", PermissionService.class); nodes = applicationContext.getBean("Nodes", Nodes.class); } @@ -143,7 +143,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("contentId shouldn't be null", content_Id); // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(childFolder), null, 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), null, 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); @@ -153,7 +153,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(childFolder, jobId), null, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); From 8388a1d5bca39f409d05add35ea46772edc1a5a8 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 21 Oct 2024 11:09:01 +0530 Subject: [PATCH 247/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../rest/api/tests/NodeSizeDetailsTest.java | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 71fcca843b3..8b20ab537a2 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -29,6 +29,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.IOException; import java.time.LocalTime; import java.util.HashMap; import java.util.List; @@ -37,6 +38,7 @@ import org.json.simple.JSONObject; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; @@ -110,11 +112,31 @@ public void setup() throws Exception // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); - folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_CONTENT); + folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); permissionService = applicationContext.getBean("permissionService", PermissionService.class); nodes = applicationContext.getBean("Nodes", Nodes.class); } + @BeforeClass + public static void testRestartSearchReindexing() throws IOException + { + try + { + ProcessBuilder processBuilder = new ProcessBuilder("docker-compose", "restart", "search-reindexing"); + processBuilder.redirectErrorStream(true); + + Process process = processBuilder.start(); + int exitCode = process.waitFor(); + + assertTrue("Docker Compose command failed", exitCode == 0); + } + catch (IOException | InterruptedException e) + { + e.printStackTrace(); + assertTrue("Exception occurred while executing Docker command", false); + } + } + /** * Test case for POST/size-details, which request and calculates the size of a folder. GET/size-details, which retrieve the SizeDetails of the folder Node. {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details} {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details/} */ @@ -122,8 +144,6 @@ public void setup() throws Exception public void testPostAndGetFolderSizeDetails() throws Exception { - UserInfo userInfo = new UserInfo(user1); - String folder0Name = "f0-testParentFolder-" + RUNID; String childFolder = createFolder(folderId, folder0Name, null).getId(); @@ -143,7 +163,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertNotNull("contentId shouldn't be null", content_Id); // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), null, 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(childFolder), null, 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); @@ -153,7 +173,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, jobId), null, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(childFolder, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); @@ -173,7 +193,7 @@ public void testPerformanceTesting() throws Exception UserInfo userInfo = new UserInfo(user1); String folder0Name = "f1-testParentFolder-" + RUNID; - String parentFolder = createFolder(tDocLibNodeId, folder0Name, null).getId(); + String parentFolder = createFolder(folderId, folder0Name, null).getId(); for (int i = 1; i <= 500; i++) { @@ -205,24 +225,21 @@ public void testPerformanceTesting() throws Exception assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); - JSONObject jsonObject = (JSONObject) postResponse.getJsonResponse() - .get("entry"); + NodeSizeDetails nodeSizeDetails = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), NodeSizeDetails.class); - String jobId = (String) jsonObject.get("jobId"); + String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); - Thread.sleep(500); + Thread.sleep(4000); HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(parentFolder, jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); - NodeSizeDetails nodeSizeDetails = parseNodeSizeDetails( - (JSONObject) getResponse.getJsonResponse() - .get("entry")); + nodeSizeDetails = RestApiUtil.parseRestApiEntry(getResponse.getJsonResponse(), NodeSizeDetails.class); - assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); + assertNotNull("We are not getting correct response ", nodeSizeDetails.getStatus()); // current Time after executing GET/size-details LocalTime actualTime = LocalTime.now(); From fae21b6c0adcf890863b151863dcb9bd09122524 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 21 Oct 2024 11:52:58 +0530 Subject: [PATCH 248/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../rest/api/tests/NodeSizeDetailsTest.java | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 8b20ab537a2..be18dec216e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -29,7 +29,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.io.IOException; import java.time.LocalTime; import java.util.HashMap; import java.util.List; @@ -38,7 +37,6 @@ import org.json.simple.JSONObject; import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; @@ -117,26 +115,6 @@ public void setup() throws Exception nodes = applicationContext.getBean("Nodes", Nodes.class); } - @BeforeClass - public static void testRestartSearchReindexing() throws IOException - { - try - { - ProcessBuilder processBuilder = new ProcessBuilder("docker-compose", "restart", "search-reindexing"); - processBuilder.redirectErrorStream(true); - - Process process = processBuilder.start(); - int exitCode = process.waitFor(); - - assertTrue("Docker Compose command failed", exitCode == 0); - } - catch (IOException | InterruptedException e) - { - e.printStackTrace(); - assertTrue("Exception occurred while executing Docker command", false); - } - } - /** * Test case for POST/size-details, which request and calculates the size of a folder. GET/size-details, which retrieve the SizeDetails of the folder Node. {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details} {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details/} */ From e9d8b1e388b6645ee3d950dd370ec509d841beba Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 21 Oct 2024 14:25:53 +0530 Subject: [PATCH 249/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../rest/api/tests/NodeSizeDetailsTest.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index be18dec216e..cb9d798f64f 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -29,6 +29,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; + import java.time.LocalTime; import java.util.HashMap; import java.util.List; @@ -46,7 +48,6 @@ import org.slf4j.LoggerFactory; import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; -import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.nodes.NodesEntityResource; import org.alfresco.rest.api.tests.client.HttpResponse; @@ -54,9 +55,11 @@ import org.alfresco.rest.api.tests.client.data.ContentInfo; import org.alfresco.rest.api.tests.client.data.Document; import org.alfresco.rest.api.tests.client.data.Node; +import org.alfresco.rest.api.tests.client.data.SiteRole; import org.alfresco.rest.api.tests.client.data.UserInfo; import org.alfresco.rest.api.tests.util.RestApiUtil; -import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.site.SiteVisibility; /** @@ -69,8 +72,6 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsTest.class); private Site userOneN1Site; private String folderId; - private PermissionService permissionService; - private Nodes nodes; private final String status = "COMPLETED"; // Method to create content info @@ -106,13 +107,12 @@ public void setup() throws Exception setRequestContext(user1); String siteTitle = "RandomSite" + System.currentTimeMillis(); - this.userOneN1Site = createSite("RN" + RUNID, siteTitle, siteTitle, SiteVisibility.PRIVATE, 201); + userOneN1Site = createSite("RN" + RUNID, siteTitle, siteTitle, SiteVisibility.PUBLIC, 201); + addSiteMember(userOneN1Site.getId(), user1, SiteRole.SiteCollaborator); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); - permissionService = applicationContext.getBean("permissionService", PermissionService.class); - nodes = applicationContext.getBean("Nodes", Nodes.class); } /** @@ -121,27 +121,25 @@ public void setup() throws Exception @Test public void testPostAndGetFolderSizeDetails() throws Exception { + setRequestContext(user1); String folder0Name = "f0-testParentFolder-" + RUNID; - String childFolder = createFolder(folderId, folder0Name, null).getId(); + String folderB = createFolder(folderId, folder0Name, null).getId(); + NodeRef folderB_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderB); String title = "test title"; Map docProps = new HashMap<>(); docProps.put("cm:title", title); docProps.put("cm:owner", user1); String contentName = "content " + RUNID + ".txt"; - String content1Id = createTextFile(childFolder, contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps).getId(); + String content1Id = createTextFile(folderB_Ref.getId(), contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps).getId(); - Thread.sleep(3000); - // get node info. HttpResponse response = getSingle(NodesEntityResource.class, content1Id, null, 200); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); - String content_Id = documentResp.getId(); - - assertNotNull("contentId shouldn't be null", content_Id); + assertEquals("DocumentId must be equal", documentResp.getId(), content1Id); // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(childFolder), null, 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderB_Ref.getId()), toJsonAsStringNonNull(documentResp), 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); @@ -151,7 +149,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(childFolder, jobId), null, 200); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderB_Ref.getId(), jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", getResponse.getJsonResponse()); From bfa3f0407f855329bb805eb3d73df94b5c6fbb52 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 21 Oct 2024 15:05:54 +0530 Subject: [PATCH 250/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index cb9d798f64f..837ddef74d8 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -107,8 +107,9 @@ public void setup() throws Exception setRequestContext(user1); String siteTitle = "RandomSite" + System.currentTimeMillis(); - userOneN1Site = createSite("RN" + RUNID, siteTitle, siteTitle, SiteVisibility.PUBLIC, 201); - addSiteMember(userOneN1Site.getId(), user1, SiteRole.SiteCollaborator); + userOneN1Site = createSite(siteTitle, SiteVisibility.PUBLIC); + // userOneN1Site = createSite("RN" + RUNID, siteTitle, siteTitle, SiteVisibility.PUBLIC, 201); + addSiteMember(userOneN1Site.getId(), user1, SiteRole.SiteManager); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); From e65e0d54c7d53f0b05298217e388bbc040a43d93 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 21 Oct 2024 15:37:36 +0530 Subject: [PATCH 251/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 837ddef74d8..7bda3f37c90 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -55,7 +55,6 @@ import org.alfresco.rest.api.tests.client.data.ContentInfo; import org.alfresco.rest.api.tests.client.data.Document; import org.alfresco.rest.api.tests.client.data.Node; -import org.alfresco.rest.api.tests.client.data.SiteRole; import org.alfresco.rest.api.tests.client.data.UserInfo; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.repository.NodeRef; @@ -108,8 +107,6 @@ public void setup() throws Exception String siteTitle = "RandomSite" + System.currentTimeMillis(); userOneN1Site = createSite(siteTitle, SiteVisibility.PUBLIC); - // userOneN1Site = createSite("RN" + RUNID, siteTitle, siteTitle, SiteVisibility.PUBLIC, 201); - addSiteMember(userOneN1Site.getId(), user1, SiteRole.SiteManager); // Create a folder within the site document's library. String folderName = "folder" + System.currentTimeMillis(); From f8fd9b44b36fe7c2ef4ea95c096b75072757cdbc Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 21 Oct 2024 15:40:13 +0530 Subject: [PATCH 252/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 7bda3f37c90..64fa1cceca7 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -147,6 +147,8 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); + Thread.sleep(6000); + HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderB_Ref.getId(), jobId), null, 200); assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", From ed42c0003640e490126f7838ba3c3ee12fd6f5e5 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 21 Oct 2024 20:50:38 +0530 Subject: [PATCH 253/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 64fa1cceca7..09ceee2eef4 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -132,6 +132,8 @@ public void testPostAndGetFolderSizeDetails() throws Exception String contentName = "content " + RUNID + ".txt"; String content1Id = createTextFile(folderB_Ref.getId(), contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps).getId(); + Thread.sleep(5000); + HttpResponse response = getSingle(NodesEntityResource.class, content1Id, null, 200); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals("DocumentId must be equal", documentResp.getId(), content1Id); @@ -206,7 +208,7 @@ public void testPerformanceTesting() throws Exception String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); - Thread.sleep(4000); + Thread.sleep(10000); HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(parentFolder, jobId), null, 200); From 17456937251a73600b5104b6f494fb39a6472beb Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Mon, 21 Oct 2024 22:31:38 +0530 Subject: [PATCH 254/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 09ceee2eef4..076691d2dd1 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -29,8 +29,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; - import java.time.LocalTime; import java.util.HashMap; import java.util.List; @@ -139,7 +137,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception assertEquals("DocumentId must be equal", documentResp.getId(), content1Id); // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderB_Ref.getId()), toJsonAsStringNonNull(documentResp), 202); + HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderB_Ref.getId()), null, 202); assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", postResponse.getJsonResponse()); @@ -195,7 +193,7 @@ public void testPerformanceTesting() throws Exception // Start Time before triggering POST/size-details API LocalTime expectedTime = LocalTime.now() - .plusSeconds(5); + .plusSeconds(10); // Perform POST request HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), null, 202); From 3e6be4555dc7c859d4dea2f193a01357678d48bd Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 22 Oct 2024 11:31:04 +0530 Subject: [PATCH 255/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments --- .../org/alfresco/rest/api/tests/NodeSizeDetailsTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java index 076691d2dd1..4b9fd15e1a5 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java @@ -130,8 +130,6 @@ public void testPostAndGetFolderSizeDetails() throws Exception String contentName = "content " + RUNID + ".txt"; String content1Id = createTextFile(folderB_Ref.getId(), contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps).getId(); - Thread.sleep(5000); - HttpResponse response = getSingle(NodesEntityResource.class, content1Id, null, 200); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); assertEquals("DocumentId must be equal", documentResp.getId(), content1Id); @@ -147,7 +145,7 @@ public void testPostAndGetFolderSizeDetails() throws Exception String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); - Thread.sleep(6000); + Thread.sleep(15000); HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderB_Ref.getId(), jobId), null, 200); @@ -206,7 +204,7 @@ public void testPerformanceTesting() throws Exception String jobId = nodeSizeDetails.getJobId(); assertNotNull("In response, JobId should be present", jobId); - Thread.sleep(10000); + Thread.sleep(15000); HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(parentFolder, jobId), null, 200); From b271bf5de5f6a8d5f9c426b6e27e488019501d1b Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 29 Oct 2024 13:20:19 +0530 Subject: [PATCH 256/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Creating Integeration test cases --- .../rest/api/tests/NodeSizeDetailsTest.java | 278 ------------------ 1 file changed, 278 deletions(-) delete mode 100644 remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java deleted file mode 100644 index 4b9fd15e1a5..00000000000 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeSizeDetailsTest.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * #%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.tests; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.time.LocalTime; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.json.simple.JSONObject; -import org.junit.After; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.junit.runners.MethodSorters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails; -import org.alfresco.rest.api.model.Site; -import org.alfresco.rest.api.nodes.NodesEntityResource; -import org.alfresco.rest.api.tests.client.HttpResponse; -import org.alfresco.rest.api.tests.client.PublicApiClient; -import org.alfresco.rest.api.tests.client.data.ContentInfo; -import org.alfresco.rest.api.tests.client.data.Document; -import org.alfresco.rest.api.tests.client.data.Node; -import org.alfresco.rest.api.tests.client.data.UserInfo; -import org.alfresco.rest.api.tests.util.RestApiUtil; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.site.SiteVisibility; - -/** - * V1 REST API tests for calculating and retrieving Folder size. - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(JUnit4.class) -public class NodeSizeDetailsTest extends AbstractBaseApiTest -{ - private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsTest.class); - private Site userOneN1Site; - private String folderId; - private final String status = "COMPLETED"; - - // Method to create content info - private ContentInfo createContentInfo() - { - ContentInfo ciExpected = new ContentInfo(); - ciExpected.setMimeType("text/plain"); - ciExpected.setMimeTypeName("Plain Text"); - ciExpected.setSizeInBytes(44500L); - ciExpected.setEncoding("ISO-8859-1"); - return ciExpected; - } - - private String addToDocumentLibrary(Site testSite, String name, String nodeType) - { - String parentId; - try - { - parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary"); - return createNode(parentId, name, nodeType, null).getId(); - } - catch (Exception e) - { - LOG.error("Exception occurred in NodeSizeDetailsTest:addToDocumentLibrary {}", e.getMessage()); - } - return null; - } - - @Before - public void setup() throws Exception - { - super.setup(); - setRequestContext(user1); - - String siteTitle = "RandomSite" + System.currentTimeMillis(); - userOneN1Site = createSite(siteTitle, SiteVisibility.PUBLIC); - - // Create a folder within the site document's library. - String folderName = "folder" + System.currentTimeMillis(); - folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER); - } - - /** - * Test case for POST/size-details, which request and calculates the size of a folder. GET/size-details, which retrieve the SizeDetails of the folder Node. {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details} {@literal :/alfresco/api//public/alfresco/versions/1/nodes//size-details/} - */ - @Test - public void testPostAndGetFolderSizeDetails() throws Exception - { - setRequestContext(user1); - - String folder0Name = "f0-testParentFolder-" + RUNID; - String folderB = createFolder(folderId, folder0Name, null).getId(); - NodeRef folderB_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderB); - - String title = "test title"; - Map docProps = new HashMap<>(); - docProps.put("cm:title", title); - docProps.put("cm:owner", user1); - String contentName = "content " + RUNID + ".txt"; - String content1Id = createTextFile(folderB_Ref.getId(), contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps).getId(); - - HttpResponse response = getSingle(NodesEntityResource.class, content1Id, null, 200); - Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); - assertEquals("DocumentId must be equal", documentResp.getId(), content1Id); - - // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderB_Ref.getId()), null, 202); - - assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", - postResponse.getJsonResponse()); - - NodeSizeDetails nodeSizeDetails = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), NodeSizeDetails.class); - - String jobId = nodeSizeDetails.getJobId(); - assertNotNull("In response, JobId should be present", jobId); - - Thread.sleep(15000); - - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderB_Ref.getId(), jobId), null, 200); - - assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", - getResponse.getJsonResponse()); - - nodeSizeDetails = RestApiUtil.parseRestApiEntry(getResponse.getJsonResponse(), NodeSizeDetails.class); - - assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus()); - assertEquals("SizeDetails hasn't been calculated yet, current status -" + nodeSizeDetails.getStatus().name() + "]", status, nodeSizeDetails.getStatus().name()); - assertTrue("We are not getting size greater than 0 " + nodeSizeDetails, nodeSizeDetails.getSizeInBytes() > 0L); - - } - - @Test - public void testPerformanceTesting() throws Exception - { - setRequestContext(user1); - UserInfo userInfo = new UserInfo(user1); - - String folder0Name = "f1-testParentFolder-" + RUNID; - String parentFolder = createFolder(folderId, folder0Name, null).getId(); - - for (int i = 1; i <= 500; i++) - { - String folderBName = "folder" + i + RUNID + "_B"; - String folderBId = createFolder(parentFolder, folderBName, null).getId(); - String fileName = "content" + i + RUNID + ".txt"; - Document d1 = new Document(); - d1.setIsFolder(false); - d1.setParentId(folderBId); - d1.setName(fileName); - d1.setNodeType(TYPE_CM_CONTENT); - d1.setContent(createContentInfo()); - d1.setCreatedByUser(userInfo); - d1.setModifiedByUser(userInfo); - } - - PublicApiClient.Paging paging = getPaging(0, 1000); - HttpResponse response = getAll(getNodeChildrenUrl(parentFolder), paging, 200); - List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); - assertEquals(500, nodes.size()); - - // Start Time before triggering POST/size-details API - LocalTime expectedTime = LocalTime.now() - .plusSeconds(10); - - // Perform POST request - HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), null, 202); - - assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code", - postResponse.getJsonResponse()); - - NodeSizeDetails nodeSizeDetails = RestApiUtil.parseRestApiEntry(postResponse.getJsonResponse(), NodeSizeDetails.class); - - String jobId = nodeSizeDetails.getJobId(); - assertNotNull("In response, JobId should be present", jobId); - - Thread.sleep(15000); - - HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(parentFolder, jobId), null, 200); - - assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code", - getResponse.getJsonResponse()); - - nodeSizeDetails = RestApiUtil.parseRestApiEntry(getResponse.getJsonResponse(), NodeSizeDetails.class); - - assertNotNull("We are not getting correct response ", nodeSizeDetails.getStatus()); - - // current Time after executing GET/size-details - LocalTime actualTime = LocalTime.now(); - assertTrue("Calculating folder node is taking time greater than 5 seconds ", actualTime.isBefore(expectedTime)); - assertEquals("SizeDetails hasn't been calculated yet, current status -" + nodeSizeDetails.getStatus().name() + "]", status, nodeSizeDetails.getStatus().name()); - assertTrue("We are not getting size greater than 0 " + nodeSizeDetails, nodeSizeDetails.getSizeInBytes() > 0L); - Long defaultSize = 22250000L; - assertEquals(nodeSizeDetails.getSizeInBytes(), defaultSize); - } - - /** - * Test case for others HTTP status codes. - */ - @Test - public void testHTTPStatus() throws Exception - { - setRequestContext(null); - delete(generateNodeSizeDetailsUrl(folderId), folderId, null, 401); - - setRequestContext(user1); - String folderName = "folder0" + System.currentTimeMillis(); - - HttpResponse responseForNotFound = post(generateNodeSizeDetailsUrl(folderName), null, 404); - assertNotNull(responseForNotFound); - - folderName = "folder1" + System.currentTimeMillis(); - String nodeType = "cm:content"; - - Node nodeResp = createNode(folderId, folderName, nodeType, null); - String n1Id = nodeResp.getId(); - - // Perform POST request - HttpResponse responseForInvalidNode = post(generateNodeSizeDetailsUrl(n1Id), null, 422); - assertNotNull(responseForInvalidNode); - } - - private NodeSizeDetails parseNodeSizeDetails(JSONObject jsonObject) - { - if (jsonObject == null) - { - return null; - } - - String jobId = (String) jsonObject.get("jobId"); - String id = (String) jsonObject.get("id"); - String status = (String) jsonObject.get("status"); - Long sizeInBytes = (Long) jsonObject.get("sizeInBytes"); - return new NodeSizeDetails(id, sizeInBytes != null ? sizeInBytes : 0L, jobId, NodeSizeDetails.STATUS.valueOf(status)); - } - - @After - public void tearDown() throws Exception - { - deleteSite(userOneN1Site.getId(), true, 204); - } - - @Override - public String getScope() - { - return "public"; - } -} From 1295f704358db9c25b8979d9a4a56389c519d81c Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 29 Oct 2024 13:29:17 +0530 Subject: [PATCH 257/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Creating Integeration test cases --- .../rest/model/RestSizeDetailsModel.java | 141 +++ .../java/org/alfresco/rest/requests/Node.java | 212 ++-- .../rest/nodes/NodeSizeDetailsTests.java | 175 +++ .../testdata/sampleLargeContent.txt | 1050 +++++++++++++++++ .../org/alfresco/AppContext02TestSuite.java | 84 +- 5 files changed, 1525 insertions(+), 137 deletions(-) create mode 100644 packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSizeDetailsModel.java create mode 100644 packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java create mode 100644 packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSizeDetailsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSizeDetailsModel.java new file mode 100644 index 00000000000..60b0d296f9a --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSizeDetailsModel.java @@ -0,0 +1,141 @@ +/*- + * #%L + * alfresco-tas-restapi + * %% + * 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.model; + +import java.util.Date; +import java.util.Objects; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.utility.model.TestModel; + +public class RestSizeDetailsModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestSizeDetailsModel model; + + private String id; + private Long sizeInBytes; + private Date calculatedAt; + private Integer numberOfFiles; + private String jobId; + private STATUS status; + + public enum STATUS + { + NOT_INITIATED, PENDING, IN_PROGRESS, COMPLETED, FAILED + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public Long getSizeInBytes() + { + return sizeInBytes; + } + + public void setSizeInBytes(Long sizeInBytes) + { + this.sizeInBytes = sizeInBytes; + } + + public Date getCalculatedAt() + { + return calculatedAt; + } + + public void setCalculatedAt(Date calculatedAt) + { + this.calculatedAt = calculatedAt; + } + + public Integer getNumberOfFiles() + { + return numberOfFiles; + } + + public void setNumberOfFiles(Integer numberOfFiles) + { + this.numberOfFiles = numberOfFiles; + } + + public String getJobId() + { + return jobId; + } + + public void setJobId(String jobId) + { + this.jobId = jobId; + } + + public STATUS getStatus() + { + return status; + } + + public void setStatus(STATUS status) + { + this.status = status; + } + + @Override + public RestSizeDetailsModel onModel() + { + return model; + } + + @Override + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + RestSizeDetailsModel that = (RestSizeDetailsModel) o; + return Objects.equals(id, that.id) && Objects.equals(sizeInBytes, that.sizeInBytes) && Objects.equals( + calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) + && Objects.equals(jobId, that.jobId) && status == that.status; + } + + @Override + public int hashCode() + { + return Objects.hash(id, sizeInBytes, calculatedAt, numberOfFiles, jobId, status); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Node.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Node.java index c45164d8b34..ef1d0decda9 100644 --- a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Node.java +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Node.java @@ -2,7 +2,7 @@ * #%L * alfresco-tas-restapi * %% - * Copyright (C) 2005 - 2023 Alfresco Software Limited + * 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 @@ -26,59 +26,34 @@ package org.alfresco.rest.requests; +import static org.springframework.http.HttpMethod.PUT; + import static org.alfresco.rest.core.JsonBodyGenerator.arrayToJson; import static org.alfresco.rest.requests.RuleSettings.IS_INHERITANCE_ENABLED; -import static org.springframework.http.HttpMethod.PUT; -import jakarta.json.JsonArrayBuilder; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.List; import java.util.stream.Stream; +import jakarta.json.JsonArrayBuilder; import io.restassured.http.ContentType; +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.reporters.Files; + import org.alfresco.rest.core.JsonBodyGenerator; import org.alfresco.rest.core.RestRequest; import org.alfresco.rest.core.RestResponse; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.exception.JsonToModelConversionException; -import org.alfresco.rest.model.RestActionDefinitionModelsCollection; -import org.alfresco.rest.model.RestCategoryLinkBodyModel; -import org.alfresco.rest.model.RestCategoryModel; -import org.alfresco.rest.model.RestCategoryModelsCollection; -import org.alfresco.rest.model.RestCommentModel; -import org.alfresco.rest.model.RestCommentModelsCollection; -import org.alfresco.rest.model.RestNodeAssocTargetModel; -import org.alfresco.rest.model.RestNodeAssociationModel; -import org.alfresco.rest.model.RestNodeAssociationModelCollection; -import org.alfresco.rest.model.RestNodeAssociationTypeModel; -import org.alfresco.rest.model.RestNodeBodyModel; -import org.alfresco.rest.model.RestNodeBodyMoveCopyModel; -import org.alfresco.rest.model.RestNodeChildAssocModelCollection; -import org.alfresco.rest.model.RestNodeChildAssociationModel; -import org.alfresco.rest.model.RestNodeModel; -import org.alfresco.rest.model.RestNodeModelsCollection; -import org.alfresco.rest.model.RestRatingModel; -import org.alfresco.rest.model.RestRatingModelsCollection; -import org.alfresco.rest.model.RestRenditionInfoModel; -import org.alfresco.rest.model.RestRenditionInfoModelCollection; -import org.alfresco.rest.model.RestRuleExecutionModel; -import org.alfresco.rest.model.RestRuleSetLinkModel; -import org.alfresco.rest.model.RestRuleSetModel; -import org.alfresco.rest.model.RestRuleSetModelsCollection; -import org.alfresco.rest.model.RestTagModel; -import org.alfresco.rest.model.RestTagModelsCollection; -import org.alfresco.rest.model.RestVersionModel; -import org.alfresco.rest.model.RestVersionModelsCollection; +import org.alfresco.rest.model.*; import org.alfresco.rest.model.body.RestNodeLockBodyModel; import org.alfresco.rest.model.builder.NodesBuilder; import org.alfresco.utility.Utility; import org.alfresco.utility.model.RepoTestModel; -import org.apache.commons.lang3.StringUtils; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.testng.reporters.Files; /** * Declares all Rest API under the /nodes path @@ -294,6 +269,7 @@ public void deleteFiveStarRating() /** * * Get fivestar rating of a document using GET call on "nodes/{nodeId}/ratings/{ratingId}" + * * @return */ public RestRatingModel getFiveStarRating() @@ -336,7 +312,6 @@ public RestTagModelsCollection addTags(String... tags) return restWrapper.processModels(RestTagModelsCollection.class, request); } - /** * Deletes a tag for a specific content node using DELETE call on nodes/{nodeId}/tags/{tagId} * @@ -381,6 +356,7 @@ public RestNodeModel createNode(RestNodeBodyModel node) * You need to specify first the multipart call {@link RestWrapper#usingMultipartFile(java.io.File)} * * usingMultipartFile(new File("your-local-file.txt")).withCoreAPI().usingNode(ContentModel.my()).createNode(); + * * @return */ public RestNodeModel createNode() @@ -415,7 +391,8 @@ public RestResponse getNodeContent(String nodeId) /** * Create node rendition using POST call on '/nodes/{nodeId}/renditions' * - * @param renditionId id of rendition to be created + * @param renditionId + * id of rendition to be created * @return */ public void createNodeRendition(String renditionId) @@ -428,8 +405,10 @@ public void createNodeRendition(String renditionId) /** * Create node version rendition using POST call on '/nodes/{nodeId}/versions/{versionId}/renditions' * - * @param renditionId id of rendition to be created - * @param versionId version id of node + * @param renditionId + * id of rendition to be created + * @param versionId + * version id of node * @return */ public void createNodeVersionRendition(String renditionId, String versionId) @@ -442,10 +421,10 @@ public void createNodeVersionRendition(String renditionId, String versionId) } /** - * Check if specified rendition exists and if not - * create node rendition using POST call on '/nodes/{nodeId}/renditions' + * Check if specified rendition exists and if not create node rendition using POST call on '/nodes/{nodeId}/renditions' * - * @param renditionId id of rendition to be created + * @param renditionId + * id of rendition to be created * @return */ public void createNodeRenditionIfNotExists(String renditionId) @@ -460,9 +439,10 @@ public void createNodeRenditionIfNotExists(String renditionId) } /** - * Get node rendition using GET call on '/nodes/{nodeId}/renditions/{renditionId} + * Get node rendition using GET call on '/nodes/{nodeId}/renditions/{renditionId} * - * @param renditionId id of rendition to be retrieved + * @param renditionId + * id of rendition to be retrieved * @return */ public RestRenditionInfoModel getNodeRendition(String renditionId) @@ -474,8 +454,10 @@ public RestRenditionInfoModel getNodeRendition(String renditionId) /** * Get node version rendition using GET call on '/nodes/{nodeId}/versions/{versionId}renditions/{renditionId} * - * @param renditionId id of rendition to be retrieved - * @param versionId versionId of the node + * @param renditionId + * id of rendition to be retrieved + * @param versionId + * versionId of the node * @return */ public RestRenditionInfoModel getNodeVersionRendition(String renditionId, String versionId) @@ -487,8 +469,7 @@ public RestRenditionInfoModel getNodeVersionRendition(String renditionId, String } /** - * Get node rendition using GET call on 'nodes/{nodeId}/renditions/{renditionId} Please note that it retries to get - * the renditions response several times because on the alfresco server the rendition can take a while to be created. + * Get node rendition using GET call on 'nodes/{nodeId}/renditions/{renditionId} Please note that it retries to get the renditions response several times because on the alfresco server the rendition can take a while to be created. * * @return */ @@ -510,8 +491,7 @@ public RestRenditionInfoModel getNodeRenditionUntilIsCreated(String renditionId) } /** - * Get node version rendition using GET call on 'nodes/{nodeId}/versions/{versionId}/renditions/{renditionId} Please note that it retries to get - * the renditions response several times because on the alfresco server the rendition can take a while to be created. + * Get node version rendition using GET call on 'nodes/{nodeId}/versions/{versionId}/renditions/{renditionId} Please note that it retries to get the renditions response several times because on the alfresco server the rendition can take a while to be created. * * @return */ @@ -533,10 +513,7 @@ public RestRenditionInfoModel getNodeVersionRenditionUntilIsCreated(String rendi } /** - * Get node rendition content using GET call on - * 'nodes/{nodeId}/renditions/{renditionId}/content Please note that it - * retries to get the renditions response several times because on the - * alfresco server the rendition can take a while to be created. + * Get node rendition content using GET call on 'nodes/{nodeId}/renditions/{renditionId}/content Please note that it retries to get the renditions response several times because on the alfresco server the rendition can take a while to be created. * * @return */ @@ -546,7 +523,7 @@ public RestResponse getNodeRenditionContentUntilIsCreated(String renditionId) renditionId); RestResponse response = restWrapper.process(request); int retry = 0; - //Multiplied by '8' because AI rendition test cases need more time (~30 seconds) - see ACS-2158 + // Multiplied by '8' because AI rendition test cases need more time (~30 seconds) - see ACS-2158 while (!Integer.valueOf(response.getStatusCode()).equals(HttpStatus.OK.value()) && retry < (8 * Utility.retryCountSeconds)) { Utility.waitToLoopTime(1); @@ -558,10 +535,7 @@ public RestResponse getNodeRenditionContentUntilIsCreated(String renditionId) } /** - * Get node version rendition content using GET call on - * 'nodes/{nodeId}/versions/{versionId}/renditions/{renditionId}/content Please note that it - * retries to get the renditions response several times because on the - * alfresco server the rendition can take a while to be created. + * Get node version rendition content using GET call on 'nodes/{nodeId}/versions/{versionId}/renditions/{renditionId}/content Please note that it retries to get the renditions response several times because on the alfresco server the rendition can take a while to be created. * * @return */ @@ -582,8 +556,7 @@ public RestResponse getNodeVersionRenditionContentUntilIsCreated(String renditio } /** - * Get node rendition content using GET call on - * 'nodes/{nodeId}/renditions/{renditionId}/content + * Get node rendition content using GET call on 'nodes/{nodeId}/renditions/{renditionId}/content * * @return */ @@ -595,8 +568,7 @@ public RestResponse getNodeRenditionContent(String renditionId) } /** - * Get node version rendition content using GET call on - * 'nodes/{nodeId}/versions/{versionId}/renditions/{renditionId}/content + * Get node version rendition content using GET call on 'nodes/{nodeId}/versions/{versionId}/renditions/{renditionId}/content * * @return */ @@ -608,8 +580,8 @@ public RestResponse getNodeVersionRenditionContent(String renditionId, String ve } /** - * Get rendition information for available renditions for the node using GET call on - * 'nodes/{nodeId}/renditions' + * Get rendition information for available renditions for the node using GET call on 'nodes/{nodeId}/renditions' + * * @return */ public RestRenditionInfoModelCollection getNodeRenditionsInfo() @@ -620,8 +592,8 @@ public RestRenditionInfoModelCollection getNodeRenditionsInfo() } /** - * Get rendition information for available renditions for the node version using GET call on - * 'nodes/{nodeId}/versions/{versionId}/renditions' + * Get rendition information for available renditions for the node version using GET call on 'nodes/{nodeId}/versions/{versionId}/renditions' + * * @return */ public RestRenditionInfoModelCollection getNodeVersionRenditionsInfo(String versionId) @@ -631,11 +603,11 @@ public RestRenditionInfoModelCollection getNodeVersionRenditionsInfo(String vers return restWrapper.processModels(RestRenditionInfoModelCollection.class, request); } - /** * Delete the rendition identified by renditionId using DELETE call on "/nodes/{nodeId}/renditions/{renditionId}" * - * @param renditionId id of rendition to delete + * @param renditionId + * id of rendition to delete */ public void deleteNodeRendition(String renditionId) { @@ -657,7 +629,8 @@ public RestNodeModelsCollection listChildren() /** * Move a node to a target folder * - * @param moveBody a {@link RestNodeBodyMoveCopyModel} containing at least the target parent id + * @param moveBody + * a {@link RestNodeBodyMoveCopyModel} containing at least the target parent id * @return the moved node's new information */ public RestNodeModel move(RestNodeBodyMoveCopyModel moveBody) @@ -669,7 +642,8 @@ public RestNodeModel move(RestNodeBodyMoveCopyModel moveBody) /** * Copy a node to a target folder * - * @param copyBody a {@link RestNodeBodyMoveCopyModel} containing at least the target parent id + * @param copyBody + * a {@link RestNodeBodyMoveCopyModel} containing at least the target parent id * @return the moved node's new information */ public RestNodeModel copy(RestNodeBodyMoveCopyModel copyBody) @@ -679,7 +653,6 @@ public RestNodeModel copy(RestNodeBodyMoveCopyModel copyBody) return restWrapper.processModel(RestNodeModel.class, request); } - /** * Lock a specific node using POST call on "nodes/{nodeId}/lock" * @@ -747,8 +720,7 @@ public RestNodeAssocTargetModel createTargetForNode(RestNodeAssocTargetModel tar } /** - * Delete a target for a specific node using DELETE call on - * nodes/{nodeId}/targets/{targetId} + * Delete a target for a specific node using DELETE call on nodes/{nodeId}/targets/{targetId} * * @param target */ @@ -830,7 +802,8 @@ public RestNodeAssociationModelCollection getSecondaryChildren() /** * Creates a secondary child association using POST call to: 'nodes/{nodeId}/secondary-children'. * - * @param secondaryChild - node, which should become a secondary child + * @param secondaryChild + * - node, which should become a secondary child * @return a node's parent-child association */ public RestNodeChildAssociationModel addSecondaryChild(RepoTestModel secondaryChild) @@ -841,8 +814,10 @@ public RestNodeChildAssociationModel addSecondaryChild(RepoTestModel secondaryCh /** * Creates a secondary child association using POST call to: 'nodes/{nodeId}/secondary-children'. * - * @param associationType - type of secondary parent-child relationship association - * @param secondaryChild - node, which should become a secondary child + * @param associationType + * - type of secondary parent-child relationship association + * @param secondaryChild + * - node, which should become a secondary child * @return a node's parent-child association */ public RestNodeChildAssociationModel addSecondaryChild(String associationType, RepoTestModel secondaryChild) @@ -853,7 +828,8 @@ public RestNodeChildAssociationModel addSecondaryChild(String associationType, R /** * Creates a secondary child association using POST call to: 'nodes/{nodeId}/secondary-children'. * - * @param secondaryChildAssociation - node's secondary parent-child association model + * @param secondaryChildAssociation + * - node's secondary parent-child association model * @return a node's parent-child association */ public RestNodeChildAssociationModel addSecondaryChild(RestNodeChildAssociationModel secondaryChildAssociation) @@ -865,7 +841,8 @@ public RestNodeChildAssociationModel addSecondaryChild(RestNodeChildAssociationM /** * Creates a secondary children association using POST call to: 'nodes/{nodeId}/secondary-children'. * - * @param secondaryChildren - nodes, which should become secondary children + * @param secondaryChildren + * - nodes, which should become secondary children * @return a collection of node's parent-child associations */ public RestNodeChildAssocModelCollection addSecondaryChildren(RepoTestModel... secondaryChildren) @@ -876,21 +853,24 @@ public RestNodeChildAssocModelCollection addSecondaryChildren(RepoTestModel... s /** * Creates a secondary children association using POST call to: 'nodes/{nodeId}/secondary-children'. * - * @param associationType - type of secondary parent-child relationship association - * @param secondaryChildren - nodes, which should become secondary children + * @param associationType + * - type of secondary parent-child relationship association + * @param secondaryChildren + * - nodes, which should become secondary children * @return a collection of node's parent-child associations */ public RestNodeChildAssocModelCollection addSecondaryChildren(String associationType, RepoTestModel... secondaryChildren) { return addSecondaryChildren(Stream.of(secondaryChildren) - .map(child -> new RestNodeChildAssociationModel(child.getNodeRef(), associationType)) - .toArray(RestNodeChildAssociationModel[]::new)); + .map(child -> new RestNodeChildAssociationModel(child.getNodeRef(), associationType)) + .toArray(RestNodeChildAssociationModel[]::new)); } /** * Creates a secondary children association using POST call to: 'nodes/{nodeId}/secondary-children'. * - * @param secondaryChildrenAssociations - node's secondary parent-child association models + * @param secondaryChildrenAssociations + * - node's secondary parent-child association models * @return a collection of node's parent-child associations */ public RestNodeChildAssocModelCollection addSecondaryChildren(RestNodeChildAssociationModel... secondaryChildrenAssociations) @@ -903,7 +883,8 @@ public RestNodeChildAssocModelCollection addSecondaryChildren(RestNodeChildAssoc /** * Removes secondary child association using DELETE call 'nodes/{nodeId}/secondary-children/{childId}'. * - * @param secondaryChild - node, which should NOT be a secondary child anymore + * @param secondaryChild + * - node, which should NOT be a secondary child anymore */ public void removeSecondaryChild(RepoTestModel secondaryChild) { @@ -913,8 +894,10 @@ public void removeSecondaryChild(RepoTestModel secondaryChild) /** * Removes secondary child association using DELETE call 'nodes/{nodeId}/secondary-children/{childId}'. * - * @param associationType - type of secondary parent-child relationship association - * @param secondaryChild - node, which should NOT be a secondary child anymore + * @param associationType + * - type of secondary parent-child relationship association + * @param secondaryChild + * - node, which should NOT be a secondary child anymore */ public void removeSecondaryChild(String associationType, RepoTestModel secondaryChild) { @@ -932,13 +915,12 @@ public void removeSecondaryChild(String associationType, RepoTestModel secondary /** * Removes secondary child association using DELETE call 'nodes/{nodeId}/secondary-children/{childId}'. * - * @param secondaryChildAssociation - node's secondary parent-child association to remove + * @param secondaryChildAssociation + * - node's secondary parent-child association to remove */ public void removeSecondaryChild(RestNodeAssociationModel secondaryChildAssociation) { - String parameters = StringUtils.isNotEmpty(secondaryChildAssociation.getAssociation().getAssocType()) ? - "assocType=" + secondaryChildAssociation.getAssociation().getAssocType() + "&" + restWrapper.getParameters() : - restWrapper.getParameters(); + String parameters = StringUtils.isNotEmpty(secondaryChildAssociation.getAssociation().getAssocType()) ? "assocType=" + secondaryChildAssociation.getAssociation().getAssocType() + "&" + restWrapper.getParameters() : restWrapper.getParameters(); RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}/secondary-children/{childId}?{parameters}", repoModel.getNodeRef(), secondaryChildAssociation.getId(), parameters); restWrapper.processEmptyModel(request); } @@ -1013,7 +995,6 @@ public void deleteNode(RestNodeModel nodeModel) deleteNode(nodeModel.getId()); } - /** * Delete a specific node using DELETE call on nodes/{nodeId} * @@ -1035,6 +1016,7 @@ public RestActionDefinitionModelsCollection getActionDefinitions() /** * Get Direct Access URL for a node + * * @param postBody * @return */ @@ -1055,6 +1037,7 @@ public RestResponse createDirectAccessURL(String postBody) /** * Get Direct Access URL for a specific node rendition E.g "pdf" + * * @param renditionId * @return */ @@ -1067,6 +1050,7 @@ public RestResponse createDirectAccessURLforRendition(String renditionId) /** * Get Direct Access URL for a specific node version. E.g "1.1" + * * @param versionId * @return */ @@ -1079,6 +1063,7 @@ public RestResponse createDirectAccessURLforVersion(String versionId) /** * Get Direct Access URL for a specific node version rendition. E.g ("1.1", "pdf") + * * @param versionId * @param renditionId * @return @@ -1132,7 +1117,8 @@ public RestRuleSetModelsCollection getListOfRuleSets() /** * Get the specified rule set from a folder. * - * @param ruleSetId The id of the rule set. + * @param ruleSetId + * The id of the rule set. * @return The specified rule set. */ public RestRuleSetModel getRuleSet(String ruleSetId) @@ -1145,7 +1131,8 @@ public RestRuleSetModel getRuleSet(String ruleSetId) /** * Update a rule set on this folder - for example to reorder the rules. * - * @param ruleSet The updated rule set. + * @param ruleSet + * The updated rule set. * @return The updated rule set returned by the server. */ public RestRuleSetModel updateRuleSet(RestRuleSetModel ruleSet) @@ -1188,7 +1175,8 @@ public RestRuleSetLinkModel createRuleLink(RestRuleSetLinkModel body) /** * Try to delete a ruleset link performing a DELETE call on "/nodes/{folderNodeId}/rule-set-links/{rulesetId}" * - * @param ruleSetId the id of the ruleset to be unlinked from the folder + * @param ruleSetId + * the id of the ruleset to be unlinked from the folder * @return */ public void unlinkRuleSet(String ruleSetId) @@ -1200,7 +1188,8 @@ public void unlinkRuleSet(String ruleSetId) /** * Trigger rules on a folder performing POST call on "/nodes/{folderNodeId}/rule-executions" * - * @param body - rules execution request + * @param body + * - rules execution request * @return execution result */ public RestRuleExecutionModel executeRules(RestRuleExecutionModel body) @@ -1223,7 +1212,8 @@ public RestCategoryModelsCollection getLinkedCategories() /** * Link content to category performing POST call on "/nodes/{nodeId}/category-links" * - * @param categoryLink - contains category ID + * @param categoryLink + * - contains category ID * @return linked to category */ public RestCategoryModel linkToCategory(RestCategoryLinkBodyModel categoryLink) @@ -1235,7 +1225,8 @@ public RestCategoryModel linkToCategory(RestCategoryLinkBodyModel categoryLink) /** * Link content to many categories performing POST call on "/nodes/{nodeId}/category-links" * - * @param categoryLinks - contains categories IDs + * @param categoryLinks + * - contains categories IDs * @return linked to categories */ public RestCategoryModelsCollection linkToCategories(List categoryLinks) @@ -1247,11 +1238,34 @@ public RestCategoryModelsCollection linkToCategories(List Date: Tue, 29 Oct 2024 15:20:15 +0530 Subject: [PATCH 258/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Creating Integeration test cases --- .../rest/nodes/NodeSizeDetailsTests.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java index a3da01d8772..d7505d18f31 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java @@ -2,6 +2,8 @@ import static org.alfresco.utility.report.log.Step.STEP; +import java.util.stream.IntStream; + import org.apache.commons.lang3.RandomStringUtils; import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; @@ -127,11 +129,11 @@ public void performanceTestCase() throws InterruptedException STEP("2. Creating a 200 nested folders in the folder-1"); - for (int i = 1; i <= 200; i++) - { + IntStream.rangeClosed(1, 5).forEach(i -> { String folder0Name = "childFolder" + i + RandomStringUtils.randomAlphanumeric(2); FolderModel folderModel = new FolderModel(); folderModel.setName(folder0Name); + FolderModel childFolder = dataContent.usingUser(user1) .usingSite(siteModel) .usingResource(folder) @@ -141,10 +143,12 @@ public void performanceTestCase() throws InterruptedException restClient.authenticateUser(user1) .configureRequestSpec() .addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt")); + RestNodeModel newNode = restClient.authenticateUser(user1) .withCoreAPI() .usingNode(childFolder) .createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); newNode.assertThat() @@ -156,20 +160,19 @@ public void performanceTestCase() throws InterruptedException .and() .field("content.mimeType") .is(FileType.TEXT_PLAIN.mimeType); - - } + }); RestSizeDetailsModel restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).executeSizeDetails(); restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); restSizeDetailsModel.assertThat().field("jobId").isNotEmpty(); - - Thread.sleep(2000); - String jobId = restSizeDetailsModel.getJobId(); - restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).getSizeDetails(jobId); - restClient.assertStatusCodeIs(HttpStatus.OK); - restSizeDetailsModel.assertThat().field("sizeInBytes").isNotEmpty(); - restSizeDetailsModel.assertThat().field("sizeInBytes").isGreaterThan(0); + + Utility.sleep(2000, 60000, () -> { + RestSizeDetailsModel sizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).getSizeDetails(jobId); + restClient.assertStatusCodeIs(HttpStatus.OK); + sizeDetailsModel.assertThat().field("sizeInBytes").isNotEmpty(); + sizeDetailsModel.assertThat().field("sizeInBytes").isGreaterThan(0); + }); } } From d4294cfa0033657890f9eca6bf0b0de140589b5f Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 29 Oct 2024 15:23:26 +0530 Subject: [PATCH 259/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Creating Integeration test cases --- .../test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java index d7505d18f31..fa0e201310a 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java @@ -129,7 +129,7 @@ public void performanceTestCase() throws InterruptedException STEP("2. Creating a 200 nested folders in the folder-1"); - IntStream.rangeClosed(1, 5).forEach(i -> { + IntStream.rangeClosed(1, 200).forEach(i -> { String folder0Name = "childFolder" + i + RandomStringUtils.randomAlphanumeric(2); FolderModel folderModel = new FolderModel(); folderModel.setName(folder0Name); From 63814e0775012848226c9f21cc509ccf62ce1815 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 29 Oct 2024 15:36:10 +0530 Subject: [PATCH 260/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Creating Integeration test cases --- .../org/alfresco/rest/nodes/NodeSizeDetailsTests.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java index fa0e201310a..bb8f49d75d3 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java @@ -14,8 +14,6 @@ import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.model.RestSizeDetailsModel; import org.alfresco.utility.Utility; -import org.alfresco.utility.constants.UserRole; -import org.alfresco.utility.data.DataUser.ListUserWithRoles; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.FolderModel; @@ -29,17 +27,13 @@ public class NodeSizeDetailsTests extends RestTest { private UserModel user1; private SiteModel siteModel; - private ListUserWithRoles usersWithRoles; private FolderModel folder; @BeforeClass(alwaysRun = true) public void dataPreparation() { user1 = dataUser.createRandomTestUser("User-1"); - user1.setUserRole(UserRole.SiteManager); - restClient.authenticateUser(user1); siteModel = dataSite.usingUser(user1).createPublicRandomSite(); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager); } /** @@ -129,7 +123,7 @@ public void performanceTestCase() throws InterruptedException STEP("2. Creating a 200 nested folders in the folder-1"); - IntStream.rangeClosed(1, 200).forEach(i -> { + IntStream.rangeClosed(1, 2).forEach(i -> { String folder0Name = "childFolder" + i + RandomStringUtils.randomAlphanumeric(2); FolderModel folderModel = new FolderModel(); folderModel.setName(folder0Name); From 7a3a05f5ed3ce7daaa0111e5116fd4b6cce671d1 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 29 Oct 2024 15:37:19 +0530 Subject: [PATCH 261/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Creating Integeration test cases --- .../test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java index bb8f49d75d3..c2b4378615f 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java @@ -123,7 +123,7 @@ public void performanceTestCase() throws InterruptedException STEP("2. Creating a 200 nested folders in the folder-1"); - IntStream.rangeClosed(1, 2).forEach(i -> { + IntStream.rangeClosed(1, 200).forEach(i -> { String folder0Name = "childFolder" + i + RandomStringUtils.randomAlphanumeric(2); FolderModel folderModel = new FolderModel(); folderModel.setName(folder0Name); From 8ba10aa0198a6b36d895c8aa80fb9d68a4c30ee9 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 5 Nov 2024 00:49:26 +0530 Subject: [PATCH 262/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Some Changes in NodeSizeDetailsTests --- .../rest/nodes/NodeSizeDetailsTests.java | 18 +- .../testdata/sampleLargeContent.txt | 1050 ----------------- 2 files changed, 11 insertions(+), 1057 deletions(-) delete mode 100644 packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java index c2b4378615f..57076c8d7e6 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java @@ -6,6 +6,7 @@ import org.apache.commons.lang3.RandomStringUtils; import org.springframework.http.HttpStatus; +import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -49,11 +50,11 @@ public void createSizeDetails() throws Exception folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel()); STEP("Upload a text document to the folder."); - restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("sampleContent.txt")); + restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt")); RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode(); restClient.assertStatusCodeIs(HttpStatus.CREATED); fileNode.assertThat().field("id").isNotNull() - .and().field("name").is("sampleContent.txt") + .and().field("name").is("sampleLargeContent.txt") .and().field("content.mimeType").is(FileType.TEXT_PLAIN.mimeType); RestSizeDetailsModel restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).executeSizeDetails(); @@ -64,7 +65,8 @@ public void createSizeDetails() throws Exception restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).getSizeDetails(jobId); restClient.assertStatusCodeIs(HttpStatus.OK); restSizeDetailsModel.assertThat().field("sizeInBytes").isNotEmpty(); - restSizeDetailsModel.assertThat().field("sizeInBytes").isGreaterThan(0); + Assert.assertTrue((restSizeDetailsModel.getSizeInBytes() > 52000), "Value of sizeInBytes " + restSizeDetailsModel.getSizeInBytes() + " is less than expected 52000"); + Assert.assertTrue((restSizeDetailsModel.getSizeInBytes() < 55000), "Value of sizeInBytes " + restSizeDetailsModel.getSizeInBytes() + " is greater than expected 55000"); } @@ -121,9 +123,9 @@ public void performanceTestCase() throws InterruptedException STEP("1. Create a parent folder in the test site."); FolderModel folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel()); - STEP("2. Creating a 200 nested folders in the folder-1"); + STEP("2. Creating a 50 nested folders in the folder-1"); - IntStream.rangeClosed(1, 200).forEach(i -> { + IntStream.rangeClosed(1, 51).forEach(i -> { String folder0Name = "childFolder" + i + RandomStringUtils.randomAlphanumeric(2); FolderModel folderModel = new FolderModel(); folderModel.setName(folder0Name); @@ -161,11 +163,13 @@ public void performanceTestCase() throws InterruptedException restSizeDetailsModel.assertThat().field("jobId").isNotEmpty(); String jobId = restSizeDetailsModel.getJobId(); - Utility.sleep(2000, 60000, () -> { + Utility.sleep(4000, 60000, () -> { RestSizeDetailsModel sizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).getSizeDetails(jobId); restClient.assertStatusCodeIs(HttpStatus.OK); sizeDetailsModel.assertThat().field("sizeInBytes").isNotEmpty(); - sizeDetailsModel.assertThat().field("sizeInBytes").isGreaterThan(0); + Assert.assertTrue(sizeDetailsModel.getSizeInBytes() > 2600000, "Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes() + " is less than expected " + 2600000); + Assert.assertTrue(sizeDetailsModel.getSizeInBytes() < 2800000, "Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes() + " is less than expected " + 2800000); + }); } diff --git a/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt b/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt deleted file mode 100644 index 31d3f837f64..00000000000 --- a/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt +++ /dev/null @@ -1,1050 +0,0 @@ -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. -Sample text. - - - - - - - - - - From c7ef0046a8d92fc0f908fb7298ddfc09bf190270 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 5 Nov 2024 00:52:51 +0530 Subject: [PATCH 263/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Some Changes in NodeSizeDetailsTests --- .../shared-resources/testdata/sampleLargeContent.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt diff --git a/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt b/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt new file mode 100644 index 00000000000..b9bbd24df2b --- /dev/null +++ b/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt @@ -0,0 +1,9 @@ +Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. +Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. +Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. +Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. +Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. +Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. +Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. +A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. +It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated \ No newline at end of file From 36a164965d5d5b304d71627771d21ed4bb2bb64f Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 5 Nov 2024 00:53:59 +0530 Subject: [PATCH 264/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Some Changes in NodeSizeDetailsTests --- .../test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java index 57076c8d7e6..93ab5963690 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java @@ -123,7 +123,7 @@ public void performanceTestCase() throws InterruptedException STEP("1. Create a parent folder in the test site."); FolderModel folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel()); - STEP("2. Creating a 50 nested folders in the folder-1"); + STEP("2. Creating a 51 nested folders in the folder-1"); IntStream.rangeClosed(1, 51).forEach(i -> { String folder0Name = "childFolder" + i + RandomStringUtils.randomAlphanumeric(2); From 18bcfc9d3a1313e5cd9993adf10acfeaf63d2baf Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Tue, 5 Nov 2024 11:53:26 +0530 Subject: [PATCH 265/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Some Changes in NodeSizeDetailsTests --- .../rest/nodes/NodeSizeDetailsTests.java | 8 +- .../testdata/sampleLargeContent.txt | 609 +++++++++++++++++- 2 files changed, 604 insertions(+), 13 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java index 93ab5963690..4c8aa5d4365 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java @@ -65,8 +65,8 @@ public void createSizeDetails() throws Exception restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).getSizeDetails(jobId); restClient.assertStatusCodeIs(HttpStatus.OK); restSizeDetailsModel.assertThat().field("sizeInBytes").isNotEmpty(); - Assert.assertTrue((restSizeDetailsModel.getSizeInBytes() > 52000), "Value of sizeInBytes " + restSizeDetailsModel.getSizeInBytes() + " is less than expected 52000"); - Assert.assertTrue((restSizeDetailsModel.getSizeInBytes() < 55000), "Value of sizeInBytes " + restSizeDetailsModel.getSizeInBytes() + " is greater than expected 55000"); + Assert.assertTrue((restSizeDetailsModel.getSizeInBytes() > 8200), "Value of sizeInBytes " + restSizeDetailsModel.getSizeInBytes() + " is less than expected 8200"); + Assert.assertTrue((restSizeDetailsModel.getSizeInBytes() < 8500), "Value of sizeInBytes " + restSizeDetailsModel.getSizeInBytes() + " is greater than expected 8500"); } @@ -167,8 +167,8 @@ public void performanceTestCase() throws InterruptedException RestSizeDetailsModel sizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).getSizeDetails(jobId); restClient.assertStatusCodeIs(HttpStatus.OK); sizeDetailsModel.assertThat().field("sizeInBytes").isNotEmpty(); - Assert.assertTrue(sizeDetailsModel.getSizeInBytes() > 2600000, "Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes() + " is less than expected " + 2600000); - Assert.assertTrue(sizeDetailsModel.getSizeInBytes() < 2800000, "Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes() + " is less than expected " + 2800000); + Assert.assertTrue(sizeDetailsModel.getSizeInBytes() > 410000, "Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes() + " is less than expected " + 410000); + Assert.assertTrue(sizeDetailsModel.getSizeInBytes() < 420000, "Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes() + " is less than expected " + 420000); }); diff --git a/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt b/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt index b9bbd24df2b..c002d4a7cf3 100644 --- a/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt +++ b/packaging/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleLargeContent.txt @@ -1,9 +1,600 @@ -Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. -Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. -Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. -Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. -Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. -Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. -Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. -A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. -It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her. Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated \ No newline at end of file +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. +Sample text. \ No newline at end of file From 52f37ed7060c01c64274d78269e1837badeb6a8f Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 7 Nov 2024 15:37:55 +0530 Subject: [PATCH 266/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Checking size-details feature for solr6 subsystem --- .../rest/nodes/NodeSizeDetailsTests.java | 105 ------------------ .../NodeSizeDetailsServiceImpl.java | 6 +- 2 files changed, 2 insertions(+), 109 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java index 4c8aa5d4365..73d54527fdb 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java @@ -1,22 +1,13 @@ package org.alfresco.rest.nodes; -import static org.alfresco.utility.report.log.Step.STEP; - -import java.util.stream.IntStream; - import org.apache.commons.lang3.RandomStringUtils; import org.springframework.http.HttpStatus; -import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.rest.RestTest; -import org.alfresco.rest.model.RestNodeModel; -import org.alfresco.rest.model.RestSizeDetailsModel; -import org.alfresco.utility.Utility; import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.FolderModel; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.TestGroup; @@ -37,39 +28,6 @@ public void dataPreparation() siteModel = dataSite.usingUser(user1).createPublicRandomSite(); } - /** - * Sanity check for the following api endpoint POST /nodes/{nodeId}/size-details GET /nodes/{nodeId}/size-details/{jobId} - */ - - @TestRail(section = {TestGroup.REST_API, TestGroup.NODES}, executionType = ExecutionType.SANITY) - @Test(groups = {TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY}) - public void createSizeDetails() throws Exception - { - - STEP("Create a folder in the test site."); - folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel()); - - STEP("Upload a text document to the folder."); - restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt")); - RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode(); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - fileNode.assertThat().field("id").isNotNull() - .and().field("name").is("sampleLargeContent.txt") - .and().field("content.mimeType").is(FileType.TEXT_PLAIN.mimeType); - - RestSizeDetailsModel restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).executeSizeDetails(); - restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); - restSizeDetailsModel.assertThat().field("jobId").isNotEmpty(); - - String jobId = restSizeDetailsModel.getJobId(); - restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).getSizeDetails(jobId); - restClient.assertStatusCodeIs(HttpStatus.OK); - restSizeDetailsModel.assertThat().field("sizeInBytes").isNotEmpty(); - Assert.assertTrue((restSizeDetailsModel.getSizeInBytes() > 8200), "Value of sizeInBytes " + restSizeDetailsModel.getSizeInBytes() + " is less than expected 8200"); - Assert.assertTrue((restSizeDetailsModel.getSizeInBytes() < 8500), "Value of sizeInBytes " + restSizeDetailsModel.getSizeInBytes() + " is greater than expected 8500"); - - } - /** * * Unauthenticated user not able to execute POST /nodes/{nodeId}/size-details: 401 STATUS CODE @@ -110,67 +68,4 @@ public void nodeIdNotValid() restClient.authenticateUser(user1).withCoreAPI().usingNode(document).executeSizeDetails(); restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY); } - - /** - * - * Performance testCase - */ - - @TestRail(section = {TestGroup.REST_API, TestGroup.NODES}, executionType = ExecutionType.SANITY) - @Test(groups = {TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY}) - public void performanceTestCase() throws InterruptedException - { - STEP("1. Create a parent folder in the test site."); - FolderModel folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel()); - - STEP("2. Creating a 51 nested folders in the folder-1"); - - IntStream.rangeClosed(1, 51).forEach(i -> { - String folder0Name = "childFolder" + i + RandomStringUtils.randomAlphanumeric(2); - FolderModel folderModel = new FolderModel(); - folderModel.setName(folder0Name); - - FolderModel childFolder = dataContent.usingUser(user1) - .usingSite(siteModel) - .usingResource(folder) - .createFolder(folderModel); - - STEP("Upload a text document to the childFolders."); - restClient.authenticateUser(user1) - .configureRequestSpec() - .addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt")); - - RestNodeModel newNode = restClient.authenticateUser(user1) - .withCoreAPI() - .usingNode(childFolder) - .createNode(); - - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - newNode.assertThat() - .field("id") - .isNotNull() - .and() - .field("name") - .is("sampleLargeContent.txt") - .and() - .field("content.mimeType") - .is(FileType.TEXT_PLAIN.mimeType); - }); - - RestSizeDetailsModel restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).executeSizeDetails(); - restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); - restSizeDetailsModel.assertThat().field("jobId").isNotEmpty(); - String jobId = restSizeDetailsModel.getJobId(); - - Utility.sleep(4000, 60000, () -> { - RestSizeDetailsModel sizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).getSizeDetails(jobId); - restClient.assertStatusCodeIs(HttpStatus.OK); - sizeDetailsModel.assertThat().field("sizeInBytes").isNotEmpty(); - Assert.assertTrue(sizeDetailsModel.getSizeInBytes() > 410000, "Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes() + " is less than expected " + 410000); - Assert.assertTrue(sizeDetailsModel.getSizeInBytes() < 420000, "Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes() + " is less than expected " + 420000); - - }); - - } } diff --git a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java index 2ad69c72519..f2eb02dbecc 100644 --- a/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/node/sizedetails/NodeSizeDetailsServiceImpl.java @@ -57,7 +57,7 @@ public class NodeSizeDetailsServiceImpl implements NodeSizeDetailsService, Initi { private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsServiceImpl.class); private static final String FIELD_FACET = "content.size"; - private static final String FACET_QUERY = "content.size:[0 TO " + Integer.MAX_VALUE + "] \"label\": \"large\",\"group\":\"Size\""; + private static final String FACET_QUERY = "{!afts}content.size:[0 TO " + Integer.MAX_VALUE + "]"; private SearchService searchService; private SimpleCache simpleCache; private TransactionService transactionService; @@ -153,7 +153,6 @@ private void executeSizeCalculation(NodeRef nodeRef, String jobId) finally { putSizeDetails(nodeRef.getId(), nodeSizeDetails); - AuthenticationUtil.clearCurrentSecurityContext(); } }); } @@ -214,7 +213,6 @@ private ResultSet facetQuery(NodeRef nodeRef) { LOG.debug(" After Executing facet query, no. of records found " + resultsWithoutFacet.getNumberFound()); } - searchParameters.addFacetQuery(FACET_QUERY); FieldFacet fieldFacet = new FieldFacet(FIELD_FACET); fieldFacet.setLimitOrNull((int) resultsWithoutFacet.getNumberFound()); @@ -234,7 +232,7 @@ private SearchParameters createSearchParameters(NodeRef nodeRef) SearchParameters searchParameters = new SearchParameters(); searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - searchParameters.setQuery("ANCESTOR:\"" + nodeRef + "\" AND TYPE:content"); + searchParameters.setQuery("ANCESTOR:\"" + nodeRef + "\" AND TYPE:\"cm:content\""); searchParameters.setTrackTotalHits(-1); return searchParameters; } From 4c3eca5660c0da2ef957a704db3e1bb0ea5434f5 Mon Sep 17 00:00:00 2001 From: mohit-singh4 Date: Thu, 7 Nov 2024 16:10:58 +0530 Subject: [PATCH 267/267] [feature/MNT-24127-EndpointToCalculateFolderSize] Checking size-details feature for solr6 subsystem --- .../test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java index 73d54527fdb..e71c65fd145 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodeSizeDetailsTests.java @@ -26,6 +26,7 @@ public void dataPreparation() { user1 = dataUser.createRandomTestUser("User-1"); siteModel = dataSite.usingUser(user1).createPublicRandomSite(); + folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel()); } /**