-
Notifications
You must be signed in to change notification settings - Fork 82
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 To Calculate Folder Size #2709
Changes from 28 commits
80cb5b6
7daf9c0
2bf9dac
e1d3469
e5617d8
9b0337c
b1ad278
95e256b
a16ac95
9d9d5ee
c3e03ca
2deb4f4
c2a5948
44ecf9f
5deb2b4
ea9231c
63d6de7
9d313bd
5e024c9
6aaa24d
9180053
8424c1b
d4ef724
dfcfa87
5ec0609
ef4d1d8
2b2a754
3f8be2b
6040b13
98a9d64
1f1d80d
a2e48a4
bf7f6da
d0e3c69
87ea444
5f7b97b
2022c38
f9f199d
225c521
b47e055
88d10f2
9578891
4e86bb7
10b436d
3c7f5b5
1c8c6ff
6798785
464fc20
2a1ee7d
ec22805
4edc87c
2f35962
43ca025
6206be9
b3b8b91
244d10f
4a43eaa
742ab36
0f6bb34
3287937
9f109e9
4fbca55
af7ebb0
3581f54
76611fd
0ce1745
044b054
b88af16
4faa421
5e9a99d
2c879c7
586990d
51f8142
7a16e30
58cd9db
fbfcdfe
aa2acb1
1073677
44f4299
873dfe2
0c5cc98
e5dfe0e
6af94b0
7f2aaeb
b9f0b8d
50cd40a
420100e
17ddfdb
25ba6ef
90e6bb8
bd6d21f
a61c1e9
8f8045e
fcc393e
0e34ea7
0a38c0c
be674a2
33626b4
1e0d40a
6711904
94006dc
76fdba7
d0f133d
7300e5b
1287ab4
933a0e6
cb9c051
8927470
c01445b
569d9e8
a225f66
0721099
f3f099d
ed3c189
b431077
9f28594
a9878d9
5279b99
dca8b79
f0549d1
4a0ca9a
c854cd7
2fb2f31
6153c12
a8c87f7
83d7986
c3a0ebc
c9e6ab2
2642067
46240eb
9606d8e
5a1ea33
6191003
cfbae04
3f86162
f4c36ad
16f93ad
29d17ec
5117604
d690797
5e711c1
142529d
7eff128
d3b9ef1
00bfbff
385254b
2469ff3
6a8d9e0
f86142c
d92f599
21b8354
7af7c29
fed54a3
a9901ef
a9bae63
a31adb1
a747e7b
2da3ce6
9782555
a620e91
0959f82
98a3469
d1c3ca5
280bbf6
c603a77
aa8bff4
e40afc1
3b49f50
817548a
ed20ea1
6f1138f
1e42e13
47799cd
4c6633b
289011b
1516ab9
e1949ee
0b8612d
5cd8ea2
8fa7f9c
3b7601f
3450f9b
6aaffe4
76239a9
269a621
4fa084b
cc612bf
674bcb6
1048c43
681b0ef
e0bc0e6
5b14722
697f8d8
40efd93
38e5f56
aecb029
c071099
79e2cb6
18901c7
1027bc1
d386924
013cfb1
26c79b4
2603547
ba393a5
e33feb2
b7a3a5a
ebce052
7187b5b
b8d08f0
c320d77
76f5375
29d25ea
16e57ae
855ab53
74cc4c0
9692257
d49d4c2
7f95d62
6d6fbbe
3922c07
28e5f76
f399135
29e76f3
05e2bcd
7a74f79
8388a1d
fae21b6
e9d8b1e
bfa3f04
e65e0d5
f8fd9b4
ed42c00
1745693
3e6be45
b271bf5
9d0de45
1295f70
4bf216a
d4294cf
63814e0
7a3a05f
8ba10aa
1f25b13
c7ef004
36a1649
18bcfc9
52f37ed
6aec711
4c3eca5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
/* | ||
* #%L | ||
* Alfresco Remote API | ||
* %% | ||
* Copyright (C) 2005 - 2024 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.model.FolderSizeModel; | ||
import org.alfresco.repo.action.executer.NodeSizeActionExecuter; | ||
import org.alfresco.repo.security.permissions.AccessDeniedException; | ||
import org.alfresco.rest.api.Nodes; | ||
import org.alfresco.rest.api.model.Node; | ||
import org.alfresco.rest.api.model.NodePermissions; | ||
import org.alfresco.rest.framework.WebApiDescription; | ||
import org.alfresco.rest.framework.WebApiParam; | ||
import org.alfresco.rest.framework.WebApiParameters; | ||
import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException; | ||
import org.alfresco.rest.framework.resource.RelationshipResource; | ||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; | ||
import org.alfresco.rest.framework.resource.parameters.Parameters; | ||
import org.alfresco.service.ServiceRegistry; | ||
import org.alfresco.service.cmr.action.Action; | ||
import org.alfresco.service.cmr.action.ActionService; | ||
import org.alfresco.service.cmr.repository.NodeRef; | ||
import org.alfresco.service.cmr.repository.NodeService; | ||
import org.alfresco.service.cmr.search.SearchService; | ||
import org.alfresco.service.cmr.security.AccessStatus; | ||
import org.alfresco.service.cmr.security.PermissionService; | ||
import org.alfresco.service.namespace.QName; | ||
import org.alfresco.util.ParameterCheck; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.extensions.webscripts.Status; | ||
|
||
import java.io.Serializable; | ||
import java.util.*; | ||
|
||
/** | ||
* Node Size | ||
* | ||
* - get folder size | ||
* | ||
*/ | ||
@RelationshipResource(name = "calculateSize", entityResource = NodesEntityResource.class, title = "Calculate size") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public class NodeFolderSizeRelation implements | ||
RelationshipResourceAction.CalculateSize<Map<String, Object>>, | ||
RelationshipResourceAction.ReadById<Map<String, Object>>, | ||
InitializingBean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. format change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
private Nodes nodes; | ||
private SearchService searchService; | ||
private ServiceRegistry serviceRegistry; | ||
private PermissionService permissionService; | ||
private NodeService nodeService; | ||
private ActionService actionService; | ||
static final String NOT_A_VALID_NODEID = "Node Id does not refer to a valid type [folder type]"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make the field private There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
/** | ||
* The logger | ||
*/ | ||
private static final Log LOGGER = LogFactory.getLog(NodeFolderSizeRelation.class); | ||
|
||
|
||
/** | ||
* The class that wraps the ReST APIs from core. | ||
*/ | ||
|
||
public void setNodes(Nodes nodes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
this.nodes = nodes; | ||
} | ||
|
||
public void setSearchService(SearchService searchService) { | ||
this.searchService = searchService; | ||
} | ||
|
||
public void setServiceRegistry(ServiceRegistry serviceRegistry) { | ||
this.serviceRegistry = serviceRegistry; | ||
this.permissionService = serviceRegistry.getPermissionService(); | ||
} | ||
|
||
public void setNodeService(NodeService nodeService) { | ||
this.nodeService = nodeService; | ||
} | ||
|
||
public void setActionService(ActionService actionService) { | ||
this.actionService = actionService; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
ParameterCheck.mandatory("nodes", this.nodes); | ||
} | ||
|
||
/** | ||
* Folder Size - returns size 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 ! | ||
* <p> | ||
* If NodeId does not exist, EntityNotFoundException (status 404). | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we mention the return type as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
@Override | ||
@WebApiDescription(title = "Calculating Folder Size", description = "Calculating size of a folder/file", successStatus = Status.STATUS_ACCEPTED) | ||
public Map<String, Object> createById(String nodeId, Parameters params) { | ||
|
||
NodeRef nodeRef = nodes.validateNode(nodeId); | ||
nodeService.setProperty(nodeRef, FolderSizeModel.PROP_STATUS, "IN-PROGRESS"); | ||
Node nodeInfo = nodes.getNode(nodeId); | ||
NodePermissions nodePerms = nodeInfo.getPermissions(); | ||
int maxItems = params.getPaging().getMaxItems(); | ||
QName qName = nodeService.getType(nodeRef); | ||
|
||
if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) | ||
{ | ||
throw new AccessDeniedException("permissions.err_access_denied"); | ||
} | ||
|
||
if(!"folder".equals(qName.getLocalName())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just check if for multi-lingual also the name qualified name is folder? |
||
{ | ||
throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); | ||
} | ||
|
||
try | ||
{ | ||
Action folderSizeAction = actionService.createAction(NodeSizeActionExecuter.NAME); | ||
folderSizeAction.setTrackStatus(true); | ||
folderSizeAction.setExecuteAsynchronously(true); | ||
folderSizeAction.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems); | ||
actionService.executeAction(folderSizeAction, nodeRef, false, true); | ||
Map<String, Object> result = new HashMap<>(); | ||
result.put("executionId", nodeId); | ||
return result; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The business logic code should not be within the API definition; it should instead be placed within the service implementation. See all the relevant implementations in the |
||
} | ||
catch (Exception ex) | ||
{ | ||
LOGGER.error("Exception occured in NodeFolderSizeRelation:createById "+ex.getMessage()); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
@WebApiDescription(title = "Returns Folder Node Size", description = "Returning a Folder Node Size") | ||
@WebApiParameters({ | ||
@WebApiParam(name = "nodeId", title = "The unique id of the Node being addressed", description = "A single node id")}) | ||
public Map<String, Object> readById(String nodeId, String id, Parameters parameters) | ||
|
||
{ | ||
NodeRef nodeRef = nodes.validateNode(nodeId); | ||
Node nodeInfo = nodes.getNode(nodeId); | ||
NodePermissions nodePerms = nodeInfo.getPermissions(); | ||
QName qName = nodeService.getType(nodeRef); | ||
|
||
if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) | ||
{ | ||
throw new AccessDeniedException("permissions.err_access_denied"); | ||
} | ||
|
||
if(!"folder".equals(qName.getLocalName())) | ||
{ | ||
throw new InvalidNodeTypeException(NOT_A_VALID_NODEID); | ||
} | ||
|
||
try | ||
{ | ||
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef); | ||
Map<String, Object> result = new HashMap<>(); | ||
|
||
if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT)) { | ||
result.put("status", "NOT INITIATED"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove space in status There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
String status = (String) properties.get(FolderSizeModel.PROP_STATUS); | ||
if ("IN-PROGRESS".equals(status)) { | ||
result.put("status", status); | ||
} else { | ||
Map<String, Object> mapResult = (Map<String, Object>) properties.get(FolderSizeModel.PROP_OUTPUT); | ||
mapResult.put("status", status); | ||
result = mapResult; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can return directly mapResult here right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we cannot return result map directly here, as we are keeping output in the same. |
||
} | ||
} | ||
return result; | ||
} | ||
catch (Exception ex) | ||
{ | ||
LOGGER.error("Exception occured in NodeFolderSizeRelation:readById "+ex.getMessage()); | ||
} | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,10 @@ else if (StringUtils.isNotBlank(relationshipId)) | |
{ | ||
throw new UnsupportedResourceOperationException("POST is executed against a collection URL"); | ||
} | ||
else if ("calculateSize".equals(operationName)) | ||
{ | ||
return Params.valueOf(entityId, params, "", req); | ||
} | ||
else | ||
{ | ||
Object postedRel = processRequest(resourceMeta, operation, req); | ||
|
@@ -366,6 +370,16 @@ public Object executeAction(ResourceWithMetadata resource, Params params, WithRe | |
return wrapWithCollectionWithPaging(createdRel); | ||
} | ||
} | ||
else if (RelationshipResourceAction.CalculateSize.class.isAssignableFrom(resource.getResource().getClass())) | ||
{ | ||
if (resource.getMetaData().isDeleted(RelationshipResourceAction.CalculateSize.class)) | ||
{ | ||
throw new DeletedResourceException("(GET by id) " + resource.getMetaData().getUniqueId()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the exception. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
RelationshipResourceAction.CalculateSize<?> relationGetter = (RelationshipResourceAction.CalculateSize<?>) resource.getResource(); | ||
Object result = relationGetter.createById(params.getEntityId(),params); | ||
return result; | ||
} | ||
} | ||
case OPERATION: | ||
return executeOperation(resource, params, withResponse); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add functional description about the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done