mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
[feature/MNT-24127-EndpointToCalculateFolderSize] Addressing review comments related to calculate and retrieve folder size details
This commit is contained in:
@@ -27,6 +27,8 @@ package org.alfresco.rest.api.impl;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.node.sizedetails.NodeSizeDetailsService;
|
import org.alfresco.repo.node.sizedetails.NodeSizeDetailsService;
|
||||||
import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails;
|
import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails;
|
||||||
@@ -38,7 +40,6 @@ import org.alfresco.rest.framework.core.exceptions.NotFoundException;
|
|||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.util.GUID;
|
import org.alfresco.util.GUID;
|
||||||
import org.alfresco.util.ParameterCheck;
|
import org.alfresco.util.ParameterCheck;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
|
|
||||||
public class SizeDetailsImpl implements SizeDetails, InitializingBean
|
public class SizeDetailsImpl implements SizeDetails, InitializingBean
|
||||||
{
|
{
|
||||||
@@ -62,7 +63,7 @@ public class SizeDetailsImpl implements SizeDetails, InitializingBean
|
|||||||
|
|
||||||
Optional<NodeSizeDetails> nodeSizeDetails = nodeSizeDetailsService.getSizeDetails(nodeId);
|
Optional<NodeSizeDetails> nodeSizeDetails = nodeSizeDetailsService.getSizeDetails(nodeId);
|
||||||
String actionId = nodeSizeDetails.map(NodeSizeDetails::getJobId)
|
String actionId = nodeSizeDetails.map(NodeSizeDetails::getJobId)
|
||||||
.orElseGet(() -> executeSizeDetails(nodeRef));
|
.orElseGet(() -> executeSizeDetails(nodeRef));
|
||||||
|
|
||||||
return new NodeSizeDetails(actionId);
|
return new NodeSizeDetails(actionId);
|
||||||
}
|
}
|
||||||
@@ -78,14 +79,14 @@ public class SizeDetailsImpl implements SizeDetails, InitializingBean
|
|||||||
|
|
||||||
Optional<NodeSizeDetails> optionalDetails = nodeSizeDetailsService.getSizeDetails(nodeId);
|
Optional<NodeSizeDetails> optionalDetails = nodeSizeDetailsService.getSizeDetails(nodeId);
|
||||||
return optionalDetails.map(details -> {
|
return optionalDetails.map(details -> {
|
||||||
String cachedJobId = details.getJobId();
|
String cachedJobId = details.getJobId();
|
||||||
if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId))
|
if (cachedJobId != null && !jobId.equalsIgnoreCase(cachedJobId))
|
||||||
{
|
{
|
||||||
throw new NotFoundException("jobId does not exist");
|
throw new NotFoundException("jobId does not exist");
|
||||||
}
|
}
|
||||||
return details;
|
return details;
|
||||||
})
|
})
|
||||||
.orElseGet(() -> new NodeSizeDetails(nodeId, STATUS.NOT_INITIATED));
|
.orElseGet(() -> new NodeSizeDetails(nodeId, STATUS.NOT_INITIATED));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,4 +116,4 @@ public class SizeDetailsImpl implements SizeDetails, InitializingBean
|
|||||||
ParameterCheck.mandatory("nodeSizeDetailsServiceImpl", this.nodeSizeDetailsService);
|
ParameterCheck.mandatory("nodeSizeDetailsServiceImpl", this.nodeSizeDetailsService);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,9 @@ package org.alfresco.rest.api.nodes;
|
|||||||
|
|
||||||
import java.util.List;
|
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.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails;
|
||||||
import org.alfresco.rest.api.SizeDetails;
|
import org.alfresco.rest.api.SizeDetails;
|
||||||
import org.alfresco.rest.framework.WebApiDescription;
|
import org.alfresco.rest.framework.WebApiDescription;
|
||||||
@@ -39,12 +42,10 @@ 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;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
import org.alfresco.util.ParameterCheck;
|
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")
|
@RelationshipResource(name = "size-details", entityResource = NodesEntityResource.class, title = "Node Size Details")
|
||||||
public class NodeSizeDetailsRelation implements RelationshipResourceAction.ReadById<NodeSizeDetails>,
|
public class NodeSizeDetailsRelation implements RelationshipResourceAction.ReadById<NodeSizeDetails>,
|
||||||
RelationshipResourceAction.Create<NodeSizeDetails>, InitializingBean
|
RelationshipResourceAction.Create<NodeSizeDetails>, InitializingBean
|
||||||
{
|
{
|
||||||
|
|
||||||
private SizeDetails sizeDetails;
|
private SizeDetails sizeDetails;
|
||||||
@@ -62,8 +63,8 @@ public class NodeSizeDetailsRelation implements RelationshipResourceAction.ReadB
|
|||||||
|
|
||||||
@WebApiDescription(title = "Create node-size details request", successStatus = Status.STATUS_ACCEPTED)
|
@WebApiDescription(title = "Create node-size details request", successStatus = Status.STATUS_ACCEPTED)
|
||||||
@WebApiParam(name = "nodeSizeEntity", title = "Node Size Details Request",
|
@WebApiParam(name = "nodeSizeEntity", title = "Node Size Details Request",
|
||||||
description = "Request for processing Node Size.", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT,
|
description = "Request for processing Node Size.", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT,
|
||||||
allowMultiple = false)
|
allowMultiple = false)
|
||||||
@Override
|
@Override
|
||||||
public List<NodeSizeDetails> create(String nodeId, List<NodeSizeDetails> nodeSizeEntity, Parameters parameters)
|
public List<NodeSizeDetails> create(String nodeId, List<NodeSizeDetails> nodeSizeEntity, Parameters parameters)
|
||||||
{
|
{
|
||||||
@@ -71,12 +72,12 @@ public class NodeSizeDetailsRelation implements RelationshipResourceAction.ReadB
|
|||||||
}
|
}
|
||||||
|
|
||||||
@WebApiDescription(title = "Get Node Size Details", description = "Get the Node Size Details")
|
@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",
|
@WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of the Node being addressed",
|
||||||
description = "A single node id"),
|
description = "A single Node id"),
|
||||||
@WebApiParam(name = "jobId", title = "Job Id to get the NodeSizeDetails", description = "JobId") })
|
@WebApiParam(name = "jobId", title = "Job Id to get the NodeSizeDetails", description = "JobId")})
|
||||||
@Override
|
@Override
|
||||||
public NodeSizeDetails readById(String nodeId, String jobId, Parameters parameters)
|
public NodeSizeDetails readById(String nodeId, String jobId, Parameters parameters)
|
||||||
throws RelationshipResourceNotFoundException
|
throws RelationshipResourceNotFoundException
|
||||||
{
|
{
|
||||||
return sizeDetails.getNodeSizeDetails(nodeId, jobId);
|
return sizeDetails.getNodeSizeDetails(nodeId, jobId);
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,9 @@ import java.io.Serializable;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.cache.SimpleCache;
|
import org.alfresco.repo.cache.SimpleCache;
|
||||||
import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl;
|
import org.alfresco.repo.node.sizedetails.NodeSizeDetailsServiceImpl;
|
||||||
@@ -43,8 +46,6 @@ import org.alfresco.rest.api.model.Node;
|
|||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.search.SearchService;
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link SizeDetailsImpl} class.
|
* Unit tests for {@link SizeDetailsImpl} class.
|
||||||
@@ -74,8 +75,6 @@ public class SizeDetailsImplTest
|
|||||||
verify(nodeSizeDetailsServiceImpl).setSimpleCache(simpleCache);
|
verify(nodeSizeDetailsServiceImpl).setSimpleCache(simpleCache);
|
||||||
nodeSizeDetailsServiceImpl.setThreadPoolExecutor(threadPoolExecutor);
|
nodeSizeDetailsServiceImpl.setThreadPoolExecutor(threadPoolExecutor);
|
||||||
sizeDetailsImpl = new SizeDetailsImpl(nodes, nodeSizeDetailsServiceImpl);
|
sizeDetailsImpl = new SizeDetailsImpl(nodes, nodeSizeDetailsServiceImpl);
|
||||||
// sizeDetailsImpl.setNodes(nodes);
|
|
||||||
// sizeDetailsImpl.setNodeSizeDetailsService(nodeSizeDetailsServiceImpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -34,6 +34,17 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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.repo.node.sizedetails.NodeSizeDetailsServiceImpl.NodeSizeDetails;
|
||||||
import org.alfresco.rest.api.Nodes;
|
import org.alfresco.rest.api.Nodes;
|
||||||
import org.alfresco.rest.api.model.Site;
|
import org.alfresco.rest.api.model.Site;
|
||||||
@@ -46,16 +57,6 @@ import org.alfresco.rest.api.tests.client.data.UserInfo;
|
|||||||
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||||
import org.alfresco.service.cmr.security.PermissionService;
|
import org.alfresco.service.cmr.security.PermissionService;
|
||||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
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.
|
* V1 REST API tests for calculating and retrieving Folder size.
|
||||||
@@ -100,7 +101,6 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest
|
|||||||
public void setup() throws Exception
|
public void setup() throws Exception
|
||||||
{
|
{
|
||||||
super.setup();
|
super.setup();
|
||||||
|
|
||||||
setRequestContext(user1);
|
setRequestContext(user1);
|
||||||
|
|
||||||
String siteTitle = "RandomSite" + System.currentTimeMillis();
|
String siteTitle = "RandomSite" + System.currentTimeMillis();
|
||||||
@@ -114,10 +114,7 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case for POST/size-details, which request and calculates the size of a 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 <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/size-details} {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/size-details/<jobId>}
|
||||||
* GET/size-details, which retrieve the SizeDetails of the folder Node.
|
|
||||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/size-details}
|
|
||||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/size-details/<jobId>}
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testPostAndGetFolderSizeDetails() throws Exception
|
public void testPostAndGetFolderSizeDetails() throws Exception
|
||||||
@@ -126,10 +123,10 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest
|
|||||||
HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), 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",
|
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()
|
JSONObject jsonObject = (JSONObject) postResponse.getJsonResponse()
|
||||||
.get("entry");
|
.get("entry");
|
||||||
|
|
||||||
String jobId = (String) jsonObject.get("jobId");
|
String jobId = (String) jsonObject.get("jobId");
|
||||||
assertNotNull("In response, JobId should be present", jobId);
|
assertNotNull("In response, JobId should be present", jobId);
|
||||||
@@ -142,11 +139,11 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest
|
|||||||
HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, 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",
|
assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",
|
||||||
getResponse.getJsonResponse());
|
getResponse.getJsonResponse());
|
||||||
|
|
||||||
NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails(
|
NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails(
|
||||||
(JSONObject) getResponse.getJsonResponse()
|
(JSONObject) getResponse.getJsonResponse()
|
||||||
.get("entry"));
|
.get("entry"));
|
||||||
|
|
||||||
assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus());
|
assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus());
|
||||||
}
|
}
|
||||||
@@ -180,18 +177,18 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest
|
|||||||
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
assertEquals(500, nodes.size());
|
assertEquals(500, nodes.size());
|
||||||
|
|
||||||
//Start Time before triggering POST/size-details API
|
// Start Time before triggering POST/size-details API
|
||||||
LocalTime expectedTime = LocalTime.now()
|
LocalTime expectedTime = LocalTime.now()
|
||||||
.plusSeconds(5);
|
.plusSeconds(5);
|
||||||
|
|
||||||
// Perform POST request
|
// Perform POST request
|
||||||
HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), null, 202);
|
HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), null, 202);
|
||||||
|
|
||||||
assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code",
|
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()
|
JSONObject jsonObject = (JSONObject) postResponse.getJsonResponse()
|
||||||
.get("entry");
|
.get("entry");
|
||||||
|
|
||||||
String jobId = (String) jsonObject.get("jobId");
|
String jobId = (String) jsonObject.get("jobId");
|
||||||
assertNotNull("In response, JobId should be present", jobId);
|
assertNotNull("In response, JobId should be present", jobId);
|
||||||
@@ -204,15 +201,15 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest
|
|||||||
HttpResponse getResponse = getSingle(getNodeSizeDetailsUrl(folderId, 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",
|
assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",
|
||||||
getResponse.getJsonResponse());
|
getResponse.getJsonResponse());
|
||||||
|
|
||||||
NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails(
|
NodeSizeDetails nodeSizeDetails = NodeSizeDetails.parseNodeSizeDetails(
|
||||||
(JSONObject) getResponse.getJsonResponse()
|
(JSONObject) getResponse.getJsonResponse()
|
||||||
.get("entry"));
|
.get("entry"));
|
||||||
|
|
||||||
assertNotNull("We are not getting correct response " + nodeSizeDetails, nodeSizeDetails.getStatus());
|
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();
|
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));
|
||||||
}
|
}
|
||||||
@@ -254,4 +251,4 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest
|
|||||||
{
|
{
|
||||||
return "public";
|
return "public";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user