simpleCache)
- {
- this.simpleCache = simpleCache;
- }
-
- public void setDefaultItems(int defaultItems)
- {
- this.defaultItems = defaultItems;
- }
-
@Override
public void afterPropertiesSet()
{
@@ -286,34 +237,32 @@ public class NodesEntityResource implements
}
/**
- * 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)
+ @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")})
- public Map calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse)
+ public NodeSizeDetails 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);
+ NodeSizeDetails nodeSizeDetails = sizeDetails.calculateNodeSize(nodeId);
+ if(nodeSizeDetails == null)
+ {
+ withResponse.setStatus(Status.STATUS_ACCEPTED);
+ }
+ else
+ {
+ withResponse.setStatus(Status.STATUS_OK);
+ }
+ return nodeSizeDetails;
}
catch (Exception alfrescoRuntimeError)
{
@@ -322,64 +271,4 @@ public class NodesEntityResource implements
}
}
- @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({"size"})
- public Map getFolderSize(String nodeId) throws EntityNotFoundException
- {
- 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()))
- {
- 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;
- }
- }
- else
- {
- result.put(STATUS,NOT_INITIATED);
- }
- return result;
- }
- catch (Exception ex)
- {
- LOG.error("Exception occurred in NodesEntityResource:getFolderSize {}", ex.getMessage());
- throw ex; // Rethrow with original stack trace
- }
- }
-
- /**
- * 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/framework/core/ResourceInspector.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/ResourceInspector.java
index 89ed9b13c2..146450667e 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.MultiPartRelation
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 class ResourceInspector
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 fd8591317d..87ee84c074 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.EntityResourceAct
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 @@ import java.util.Map;
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 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
}
}
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 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
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 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
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 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
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 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
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 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
BinaryResource prop = getter.readProperty(params.getEntityId(), params.getRelationshipId(), params, withResponse);
return prop;
}
- else
- {
- throw new UnsupportedResourceOperationException();
- }
}
else
{
@@ -345,7 +327,7 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
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 223b8f9400..8e8a321c07 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/repository/src/test/java/org/alfresco/AppContext01TestSuite.java b/repository/src/test/java/org/alfresco/AppContext01TestSuite.java
index c7f78a960c..53da9d4cf2 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 @@ import org.junit.runners.Suite;
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 4c2ce3335d..f9168af16a 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.junit.Test;
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 class NodeSizeActionExecuterTest extends BaseSpringTest
// 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 class NodeSizeActionExecuterTest extends BaseSpringTest
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 class NodeSizeActionExecuterTest extends BaseSpringTest
@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