[feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details

This commit is contained in:
mohit-singh4
2024-08-22 17:32:12 +05:30
parent 83d798641a
commit c3a0ebc448
5 changed files with 36 additions and 41 deletions

View File

@@ -61,7 +61,7 @@ public class SizeDetailsImpl implements SizeDetails
private NodeService nodeService;
private PermissionService permissionService;
private ActionService actionService;
private SimpleCache<Serializable,Object> simpleCache;
private SimpleCache<Serializable,Map<String, Object>> simpleCache;
private int defaultItems;
public void setNodes(Nodes nodes)
@@ -84,7 +84,7 @@ public class SizeDetailsImpl implements SizeDetails
this.actionService = actionService;
}
public void setSimpleCache(SimpleCache<Serializable, Object> simpleCache)
public void setSimpleCache(SimpleCache<Serializable, Map<String, Object>> simpleCache)
{
this.simpleCache = simpleCache;
}
@@ -117,13 +117,13 @@ public class SizeDetailsImpl implements SizeDetails
}
LOG.debug("Executing NodeSizeActionExecuter from calculateNodeSize method");
return executorResultToSizeDetails((Map<String, Object>)simpleCache.get(nodeRef.getId()));
return executorResultToSizeDetails(simpleCache.get(nodeRef.getId()));
}
/**
* Executing Action Asynchronously.
*/
private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache<Serializable, Object> simpleCache)
private void executeAction(NodeRef nodeRef, int defaultItems, SimpleCache<Serializable, Map<String, Object>> simpleCache)
{
Map<String, Object > currentStatus = new HashMap<>();
currentStatus.put(STATUS,IN_PROGRESS);

View File

@@ -40,6 +40,7 @@ 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;
@@ -63,7 +64,7 @@ public class SizeDetailsImplTest extends AbstractBaseApiTest
NodeService nodeService = mock(NodeService.class);
PermissionService permissionService = mock(PermissionService.class);
ActionService actionService = mock(ActionService.class);
SimpleCache<Serializable, Object> simpleCache = mock(SimpleCache.class);
SimpleCache<Serializable, Map<String, Object>> simpleCache = mock(SimpleCache.class);
sizeDetailsImpl.setNodes(nodes);
sizeDetailsImpl.setNodeService(nodeService);
@@ -82,7 +83,6 @@ public class SizeDetailsImplTest extends AbstractBaseApiTest
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 class SizeDetailsImplTest extends AbstractBaseApiTest
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);
}

View File

@@ -34,6 +34,9 @@ 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.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.JUnit4;
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.Map;
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 class NodeSizeDetailsTest extends AbstractBaseApiTest
// 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 class NodeSizeDetailsTest extends AbstractBaseApiTest
// 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 class NodeSizeDetailsTest extends AbstractBaseApiTest
// 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 class NodeSizeDetailsTest extends AbstractBaseApiTest
@Test
public void testHTTPStatus() throws Exception
{
// Prepare parameters
Map<String, String> 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<String, String> 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

View File

@@ -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<Serializable,Object> simpleCache;
private SimpleCache<Serializable, Map<String, Object>> simpleCache;
/**
* Set the search service
@@ -84,7 +84,7 @@ public class NodeSizeDetailsActionExecutor extends ActionExecuterAbstractBase
*
* @param simpleCache the cache service
*/
public void setSimpleCache(SimpleCache<Serializable, Object> simpleCache)
public void setSimpleCache(SimpleCache<Serializable, Map<String, Object>> simpleCache)
{
this.simpleCache = simpleCache;
}

View File

@@ -65,7 +65,7 @@ public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest
*
* @param simpleCache the cache service
*/
private SimpleCache<Serializable,Object> simpleCache;
private SimpleCache<Serializable, Map<String,Object>> simpleCache;
/**
* Called at the begining of all tests.
@@ -95,7 +95,7 @@ public class NodeSizeDetailsActionExecutorTest extends BaseSpringTest
// Get the executer instance.
this.executer = (NodeSizeDetailsActionExecutor)this.applicationContext.getBean(NodeSizeDetailsActionExecutor.NAME);
simpleCache = (SimpleCache<Serializable, Object>) this.applicationContext.getBean("folderSizeSharedCache");
simpleCache = (SimpleCache<Serializable, Map<String,Object>>) this.applicationContext.getBean("folderSizeSharedCache");
}
/**