mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
[feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details
This commit is contained in:
@@ -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);
|
||||
}
|
@@ -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.io.Serializable;
|
||||
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 class SizeDetailsImpl implements SizeDetails
|
||||
* 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 class SizeDetailsImpl implements SizeDetails
|
||||
}
|
||||
|
||||
LOG.debug("Executing NodeSizeActionExecuter from calculateNodeSize method");
|
||||
return executorResultToSizeDetails(simpleCache.get(nodeRef.getId()));
|
||||
return executorResultToSizeDetail(simpleCache.get(nodeRef.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,10 +128,10 @@ public class SizeDetailsImpl implements SizeDetails
|
||||
Map<String, Object > 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 @@ public class SizeDetailsImpl implements SizeDetails
|
||||
/**
|
||||
* Converting action executor response to their respective model class.
|
||||
*/
|
||||
private NodeSizeDetails executorResultToSizeDetails(final Map<String,Object> result)
|
||||
private NodeSizeDetail executorResultToSizeDetail(final Map<String,Object> 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 @@ public class SizeDetailsImpl implements SizeDetails
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@@ -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 class NodeSizeDetails
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NodeSizeDetails{" +
|
||||
return "NodeSizeDetail{" +
|
||||
"nodeId='" + nodeId + '\'' +
|
||||
", size='" + size + '\'' +
|
||||
", calculatedAt='" + calculatedAt + '\'' +
|
@@ -31,17 +31,14 @@ import java.io.InputStream;
|
||||
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 class NodesEntityResource implements
|
||||
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 class NodesEntityResource implements
|
||||
* <p>
|
||||
* 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 class NodesEntityResource implements
|
||||
{
|
||||
withResponse.setStatus(Status.STATUS_OK);
|
||||
}
|
||||
return nodeSizeDetails;
|
||||
return nodeSizeDetail;
|
||||
}
|
||||
|
||||
}
|
@@ -996,7 +996,7 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="sizeDetails" class="org.alfresco.rest.api.impl.SizeDetailsImpl">
|
||||
<bean id="sizeDetail" class="org.alfresco.rest.api.impl.SizeDetailImpl">
|
||||
<property name="nodes" ref="nodes" />
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
<property name="permissionService" ref="permissionService"/>
|
||||
@@ -1007,10 +1007,10 @@
|
||||
|
||||
<bean id="SizeDetails" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="proxyInterfaces">
|
||||
<value>org.alfresco.rest.api.SizeDetails</value>
|
||||
<value>org.alfresco.rest.api.SizeDetail</value>
|
||||
</property>
|
||||
<property name="target">
|
||||
<ref bean="sizeDetails" />
|
||||
<ref bean="sizeDetail" />
|
||||
</property>
|
||||
<property name="interceptorNames">
|
||||
<list>
|
||||
@@ -1171,7 +1171,7 @@
|
||||
<bean class="org.alfresco.rest.api.nodes.NodesEntityResource">
|
||||
<property name="nodes" ref="Nodes" />
|
||||
<property name="directAccessUrlHelper" ref="directAccessUrlHelper" />
|
||||
<property name="sizeDetails" ref="SizeDetails" />
|
||||
<property name="sizeDetail" ref="SizeDetails" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.rest.api.nodes.NodeCommentsRelation">
|
||||
|
@@ -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 @@ import org.junit.runners.Suite;
|
||||
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
|
||||
{
|
||||
|
@@ -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 @@ import org.junit.runners.Suite;
|
||||
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
|
||||
{
|
||||
|
@@ -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.mock;
|
||||
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 class SizeDetailsImplTest
|
||||
action = mock(Action.class);
|
||||
SimpleCache<Serializable, Map<String, Object>> 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 class SizeDetailsImplTest
|
||||
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 class SizeDetailsImplTest
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@@ -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";
|
||||
|
@@ -62,9 +62,9 @@ import static org.junit.Assert.assertNull;
|
||||
*/
|
||||
@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 @@ public class NodeSizeDetailsTest extends AbstractBaseApiTest
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.error("Exception occured in NodeSizeDetailsTest:addToDocumentLibrary {}", e.getMessage());
|
||||
LOG.error("Exception occured in NodeSizeDetailTest:addToDocumentLibrary {}", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
Reference in New Issue
Block a user