mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
[feature/MNT-24127-EndpointToCalculateFolderSize] Added Endpoint to calculate folder size
This commit is contained in:
@@ -78,12 +78,16 @@ import org.springframework.extensions.webscripts.Status;
|
||||
@EntityResource(name="nodes", title = "Nodes")
|
||||
public class NodesEntityResource implements
|
||||
EntityResourceAction.ReadById<Node>, EntityResourceAction.Delete, EntityResourceAction.Update<Node>,
|
||||
BinaryResourceAction.Read, BinaryResourceAction.Update<Node>, EntityResourceAction.CalculateFolderSize<Map<String, Object>>, EntityResourceAction.RetrieveFolderSize<Map<String, Object>>, InitializingBean
|
||||
BinaryResourceAction.Read, BinaryResourceAction.Update<Node>, InitializingBean
|
||||
{
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NodesEntityResource.class);
|
||||
|
||||
private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid";
|
||||
private static final String NODEID_NOT_FOUND = "Searched nodeId does not exist";
|
||||
private static final String STATUS = "status";
|
||||
private static final String COMPLETED = "Completed";
|
||||
private static final String FOLDER = "folder";
|
||||
private Nodes nodes;
|
||||
private DirectAccessUrlHelper directAccessUrlHelper;
|
||||
private SearchService searchService;
|
||||
@@ -287,12 +291,13 @@ public class NodesEntityResource implements
|
||||
* If NodeId does not exist, EntityNotFoundException (status 404).
|
||||
* If nodeId does not represent a folder, InvalidNodeTypeException (status 422).
|
||||
*/
|
||||
@Override
|
||||
@Operation("calculate-folder-size")
|
||||
@WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder", successStatus = Status.STATUS_ACCEPTED)
|
||||
public Map<String, Object> createById(String nodeId, Parameters params)
|
||||
@WebApiParameters({@WebApiParam(name = "nodeId", title = "The unique id of Execution Job", description = "A single nodeId")})
|
||||
public Map<String, Object> calculateFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateNode(nodeId);
|
||||
int maxItems = Math.min(params.getPaging().getMaxItems(), 1000);
|
||||
int maxItems = Math.min(parameters.getPaging().getMaxItems(), 1000);
|
||||
QName qName = nodeService.getType(nodeRef);
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
validatePermissions(nodeRef, nodeId);
|
||||
@@ -314,10 +319,10 @@ public class NodesEntityResource implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Operation("get-folder-size")
|
||||
@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")})
|
||||
public Map<String, Object> readByNodeId(String nodeId, Parameters parameters)
|
||||
public Map<String, Object> getFolderSize(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@@ -110,9 +110,6 @@ public class ResourceInspector
|
||||
|
||||
ALL_ENTITY_RESOURCE_INTERFACES.add(MultiPartResourceAction.Create.class);
|
||||
|
||||
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.CalculateFolderSize.class);
|
||||
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.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);
|
||||
@@ -171,9 +168,6 @@ public class ResourceInspector
|
||||
|
||||
findOperation(MultiPartResourceAction.Create.class, POST, helper);
|
||||
|
||||
findOperation(EntityResourceAction.CalculateFolderSize.class, POST, helper);
|
||||
findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helper);
|
||||
|
||||
boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class);
|
||||
if (noAuth)
|
||||
{
|
||||
@@ -300,9 +294,6 @@ public class ResourceInspector
|
||||
|
||||
findOperation(MultiPartRelationshipResourceAction.Create.class, POST, helper);
|
||||
|
||||
findOperation(EntityResourceAction.CalculateFolderSize.class, POST, helper);
|
||||
findOperation(EntityResourceAction.RetrieveFolderSize.class, GET, helper);
|
||||
|
||||
boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class);
|
||||
if (noAuth)
|
||||
{
|
||||
|
@@ -161,26 +161,4 @@ public interface EntityResourceAction
|
||||
*/
|
||||
public void deleteSet(Parameters params, WithResponse withResponse);
|
||||
}
|
||||
|
||||
interface CalculateFolderSize<E> extends ResourceAction
|
||||
{
|
||||
String STATUS = "status";
|
||||
String COMPLETED = "Completed";
|
||||
String FOLDER = "folder";
|
||||
/**
|
||||
* Calculate the size of Folder Node.
|
||||
*
|
||||
* @param nodeId Entity resource context for this relationship.
|
||||
* @param params implementation may choose to restrict the set to be deleted based on params (ie. not necessarily "all")
|
||||
*/
|
||||
E createById(String nodeId,Parameters params);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP GET - Retrieve an entity by its unique id
|
||||
*/
|
||||
interface RetrieveFolderSize<E> extends ResourceAction
|
||||
{
|
||||
E readByNodeId (String nodeId, Parameters parameters) throws EntityNotFoundException;
|
||||
}
|
||||
}
|
||||
|
@@ -219,16 +219,6 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
|
||||
Object result = entityGetter.readById(params.getEntityId(), params, withResponse);
|
||||
return result;
|
||||
}
|
||||
else if (EntityResourceAction.RetrieveFolderSize.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(EntityResourceAction.RetrieveFolderSize.class))
|
||||
{
|
||||
throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
EntityResourceAction.RetrieveFolderSize<?> relationGetter = (EntityResourceAction.RetrieveFolderSize<?>) resource.getResource();
|
||||
Object result = relationGetter.readByNodeId(params.getEntityId(), params);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsupportedResourceOperationException();
|
||||
@@ -248,6 +238,16 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
|
||||
CollectionWithPagingInfo<?> relations = relationGetter.readAll(params.getEntityId(),params);
|
||||
return relations;
|
||||
}
|
||||
else if (RelationshipResourceAction.ReadById.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadById.class))
|
||||
{
|
||||
throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
RelationshipResourceAction.ReadById<?> relationGetter = (RelationshipResourceAction.ReadById<?>) resource.getResource();
|
||||
Object result = relationGetter.readById(params.getEntityId(), params.getRelationshipId(), params);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadWithResponse.class))
|
||||
|
@@ -93,10 +93,6 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
|
||||
{
|
||||
throw new UnsupportedResourceOperationException("POST is executed against a collection URL");
|
||||
}
|
||||
else if ("calculateSize".equals(operationName))
|
||||
{
|
||||
return Params.valueOf(entityId, params, "", req);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object postedObj = processRequest(resourceMeta, operation, req);
|
||||
@@ -321,16 +317,6 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
|
||||
return wrapWithCollectionWithPaging(created);
|
||||
}
|
||||
}
|
||||
else if (EntityResourceAction.CalculateFolderSize.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(EntityResourceAction.CalculateFolderSize.class))
|
||||
{
|
||||
throw new DeletedResourceException("(POST by id) " + resource.getMetaData().getUniqueId());
|
||||
}
|
||||
EntityResourceAction.CalculateFolderSize<?> relationGetter = (EntityResourceAction.CalculateFolderSize<?>) resource.getResource();
|
||||
Object result = relationGetter.createById(params.getEntityId(),params);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
case RELATIONSHIP:
|
||||
|
@@ -105,7 +105,8 @@ 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_CALCULATESIZE = "folder-size";
|
||||
private static final String URL_CALCULATEFOLDERSIZE = "calculate-folder-size";
|
||||
private static final String URL_GETFOLDERSIZE = "get-folder-size";
|
||||
|
||||
protected static final String TYPE_CM_FOLDER = "cm:folder";
|
||||
protected static final String TYPE_CM_CONTENT = "cm:content";
|
||||
@@ -1122,9 +1123,13 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
restDauConfig.setEnabled(false);
|
||||
}
|
||||
|
||||
protected String getFolderSizeUrl(String nodeId)
|
||||
protected String getCalculateFolderSizeUrl(String nodeId)
|
||||
{
|
||||
return URL_NODES + "/" + nodeId + "/" + URL_CALCULATESIZE;
|
||||
return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE;
|
||||
}
|
||||
protected String getFolderSizeDataUrl(String nodeId)
|
||||
{
|
||||
return URL_NODES + "/" + nodeId + "/" + URL_GETFOLDERSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -126,7 +126,7 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest
|
||||
params.put("maxItems", "100");
|
||||
|
||||
// Perform POST request
|
||||
HttpResponse response = post(getFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202);
|
||||
HttpResponse response = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202);
|
||||
// Validate response and parsed document
|
||||
assertNotNull("Response should not be null", response);
|
||||
|
||||
@@ -153,7 +153,7 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user1);
|
||||
|
||||
// Check if response and JSON parsing were successful
|
||||
HttpResponse response = getSingle(getFolderSizeUrl(folderId), null, 200);
|
||||
HttpResponse response = getSingle(getFolderSizeDataUrl(folderId), null, 200);
|
||||
assertNotNull(response);
|
||||
|
||||
String jsonResponse = String.valueOf(response.getJsonResponse());
|
||||
@@ -177,12 +177,12 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest
|
||||
public void testHTTPStatus() throws Exception
|
||||
{
|
||||
setRequestContext(null);
|
||||
delete(getFolderSizeUrl(folderId), folderId, null, 401);
|
||||
delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401);
|
||||
|
||||
setRequestContext(user1);
|
||||
NodeTarget tgt = new NodeTarget();
|
||||
tgt.setTargetParentId(folderId);
|
||||
HttpResponse response = post(getFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404);
|
||||
HttpResponse response = post(getCalculateFolderSizeUrl(UUID.randomUUID().toString()), toJsonAsStringNonNull(tgt), null, 404);
|
||||
assertNotNull(response);
|
||||
|
||||
// Create a folder within the site document's library.
|
||||
@@ -194,7 +194,7 @@ public class NodeFolderSizeApiTest extends AbstractBaseApiTest
|
||||
params.put("maxItems", "100");
|
||||
|
||||
// Perform POST request
|
||||
response = post(getFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422);
|
||||
response = post(getCalculateFolderSizeUrl(nestedFolderId), toJsonAsStringNonNull(params), 422);
|
||||
assertNotNull(response);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user