mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
[MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas]
This commit is contained in:
@@ -135,7 +135,6 @@ public class NodeFolderSizeRelation implements RelationshipResourceAction.Calcul
|
||||
Map<String, Object> 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 class NodeFolderSizeRelation implements RelationshipResourceAction.Calcul
|
||||
|
||||
@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<String, Object> readById(String nodeId, String id, Parameters parameters)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateNode(nodeId);
|
||||
|
@@ -40,13 +40,17 @@ 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;
|
||||
|
||||
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
|
||||
*/
|
||||
|
@@ -48,6 +48,7 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* NodeSizeActionExecuter
|
||||
@@ -116,7 +117,6 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase
|
||||
|
||||
NodeRef nodeRef = actionedUponNodeRef;
|
||||
long totalSize = 0;
|
||||
long resultSize;
|
||||
ResultSet results;
|
||||
boolean isCalculationCompleted = false;
|
||||
|
||||
@@ -139,11 +139,25 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase
|
||||
|
||||
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);
|
||||
List<NodeRef> 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;
|
||||
totalSize+=resultSize.longValue();
|
||||
|
||||
if (results.getNodeRefs().size() <= totalItems || results.getNodeRefs().size() <= maxItems)
|
||||
{
|
||||
@@ -176,6 +190,7 @@ public class NodeSizeActionExecuter extends ActionExecuterAbstractBase
|
||||
if(isCalculationCompleted)
|
||||
{
|
||||
nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) response);
|
||||
nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user