Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNT-24127] Added endpoint implementation to calculating folder size. #2485

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c0344ff
[APPS-2564]: Added endpoint to get Folder Size.
mohit-singh4 Mar 1, 2024
136f46e
[APPS-2564]: Added endpoint to get Folder Size.
mohit-singh4 Mar 4, 2024
93426b3
[APPS-2564]: Added endpoint to get Folder Size.
mohit-singh4 Mar 4, 2024
66cb894
[APPS-2564]: Added endpoint to get Folder Size.
mohit-singh4 Mar 4, 2024
2732e40
[MNT-24127] Developed endpoint for calculating the size of a folder
mohit-singh4 Mar 4, 2024
412af05
[MNT-24127] Added endpoint implementation to calculating folder size.
mohit-singh4 Mar 5, 2024
3c6f3fe
Merge branch 'master' of github.com:Alfresco/alfresco-community-repo …
mohit-singh4 Mar 5, 2024
37ec24c
[MNT-24127] Added endpoint implementation to calculating folder size.
mohit-singh4 Mar 5, 2024
8036b31
Merge branch 'feature/MNT-24127-AddSizeEndpoint' of github.com:Alfres…
mohit-singh4 Mar 5, 2024
bbebfec
Revert "[MNT-24127] Added endpoint implementation to calculating fold…
mohit-singh4 Mar 5, 2024
9f2c0ee
[MNT-24127] Added endpoint implementation to calculating folder size.
mohit-singh4 Mar 5, 2024
fed237c
[MNT-24127] Added endpoint implementation to calculating folder size.
mohit-singh4 Mar 5, 2024
b564b3e
[force] Force release for 2024-03-03.
alfresco-build Mar 3, 2024
562ae8c
[maven-release-plugin][skip ci] prepare release 23.3.0.6
alfresco-build Mar 3, 2024
28246ef
[maven-release-plugin][skip ci] prepare for next development iteration
alfresco-build Mar 3, 2024
a5dc122
Revert "[MNT-24127] Added endpoint implementation to calculating fold…
mohit-singh4 Mar 5, 2024
8260a18
[MNT-24127] Added endpoint implementation to calculating folder size.
mohit-singh4 Mar 5, 2024
263c1be
[MNT-24127] Added endpoint implementation to calculating folder size.
mohit-singh4 Mar 5, 2024
032033d
[MNT-24127] Added endpoint implementation to calculating folder size …
mohit-singh4 Mar 11, 2024
c9bae75
Merge remote-tracking branch 'origin/feature/MNT-24127-AddSizeEndpoin…
mohit-singh4 Mar 11, 2024
4309c89
[MNT-24127] Added endpoint implementation to calculating folder size.
mohit-singh4 Mar 11, 2024
473e368
[MNT-24127] Added endpoint implementation to calculating folder size.
mohit-singh4 Mar 11, 2024
2d8231e
[MNT-24127] Added rest endpoint implementation to calculating folder …
mohit-singh4 Mar 12, 2024
b0d64de
[MNT-24127] Added rest endpoint implementation to calculating folder …
mohit-singh4 Mar 12, 2024
68153fb
[MNT-24127] Added rest endpoint implementation to calculating folder …
mohit-singh4 Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions remote-api/src/main/java/org/alfresco/rest/api/Nodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ default DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, boolean attachm

void validateProperties(Map<String, Object> properties, List<String> excludedNS, List<QName> excludedProperties);

/**
* Get the size of Folder.
*
* @param nodeId String
* @return Map Object.
*/
Map<String, Object> getFolderSize(String nodeId);

/**
* API Constants - query parameters, etc
Expand Down
36 changes: 36 additions & 0 deletions remote-api/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3555,6 +3555,42 @@
});
}
}
/**
*
* @param folderNodeId
*/
@Override
public Map<String, Object> getFolderSize(String folderNodeId){

NodeRef nodeRef = this.validateNode(folderNodeId);
long size=this.getNodeSize(nodeRef);
int k = 1024;
String[] sizes = {"Bytes", "KB", "MB", "GB", "TB", "PB"};
int i = (int) Math.floor(Math.log(size) / Math.log(k));
float finalSize = Float.parseFloat(String.valueOf((size / Math.pow(k, i))));
Fixed Show fixed Hide fixed
Map<String, Object> response = new HashMap<>();
response.put("id", folderNodeId);
response.put("size", String.valueOf(finalSize + " " + sizes[i]));
return response;
}

protected long getNodeSize(NodeRef nodeRef){

long size=0;
Fixed Show fixed Hide fixed
// Collecting current node size.
ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
try {
size = contentData.getSize();
} catch (Exception e) {
size = 0;
}
List<ChildAssociationRef> chilAssocsList = nodeService.getChildAssocs(nodeRef);
for (ChildAssociationRef childAssociationRef : chilAssocsList) {
NodeRef childNodeRef = childAssociationRef.getChildRef();
size = size + getNodeSize(childNodeRef);
}
return size;
}

/**
* @author Jamal Kaabi-Mofrad
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.api.nodes;

import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.resource.RelationshipResource;
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
import org.alfresco.util.ParameterCheck;
import org.springframework.beans.factory.InitializingBean;

import java.util.Map;

/**
* Node
*
* - folder size
*
* @author Mohit Singh
*/
@RelationshipResource(name = "size", entityResource = NodesEntityResource.class, title = "Folder size")
public class NodeFolderSizeRelation implements
RelationshipResourceAction.FolderSize<Map<String, Object>>, InitializingBean
{
private Nodes nodes;

public void setNodes(Nodes nodes)
{
this.nodes = nodes;
}

@Override
public void afterPropertiesSet()
{
ParameterCheck.mandatory("nodes", this.nodes);
}

/**
* Folder Size - returns a size of 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 !
*
* If NodeId does not exist, EntityNotFoundException (status 404).
* If NodeId does not represent a folder, InvalidArgumentException (status 400).
*/
@Override
@WebApiDescription(title = "Size of folder",description = "Return a size of folder")
public Map<String, Object> readAll(String nodeId)
{
return nodes.getFolderSize(nodeId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public class ResourceInspector
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.DeleteSetWithResponse.class);

ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(MultiPartRelationshipResourceAction.Create.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.FolderSize.class);

ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Read.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Delete.class);
Expand Down Expand Up @@ -291,6 +292,7 @@ private static List<ResourceMetadata> inspectRelationship(RelationshipResource a
findOperation(RelationshipResourceAction.DeleteSetWithResponse.class, DELETE, helper);

findOperation(MultiPartRelationshipResourceAction.Create.class, POST, helper);
findOperation(RelationshipResourceAction.FolderSize.class, GET, helper);

boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class);
if (noAuth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,13 @@
*/
public void deleteSet(String entityResourceId, Parameters params, WithResponse withResponse);
}
public static interface FolderSize<E> extends ResourceAction
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
{
/**
* Return the size of Folder.
*
* @param nodeId Entity resource context for this relationship.
*/
public E readAll(String nodeId);
Fixed Show fixed Hide fixed
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ else if (EntityResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resour
CollectionWithPagingInfo<?> relations = relationGetter.readAll(params.getEntityId(),params);
return relations;
}
else if (RelationshipResourceAction.FolderSize.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.FolderSize.class))
{
throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.FolderSize<Map<String, Object>> relationGetter = (RelationshipResourceAction.FolderSize<Map<String, Object>>) resource.getResource();
Object result = relationGetter.readAll(params.getEntityId());
return result;
}
else
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadWithResponse.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1768,4 +1768,8 @@
</list>
</property>
</bean>

<bean class="org.alfresco.rest.api.nodes.NodeFolderSizeRelation">
<property name="nodes" ref="Nodes" />
</bean>
</beans>
Loading