mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
[MNT-24127] Added Endpoint to Calculate Size of the folder with Integration Test Cases [ags][tas]
This commit is contained in:
@@ -130,19 +130,14 @@ public class NodeFolderSizeRelation implements RelationshipResourceAction.Calcul
|
|||||||
{
|
{
|
||||||
NodeRef nodeRef = nodes.validateNode(nodeId);
|
NodeRef nodeRef = nodes.validateNode(nodeId);
|
||||||
Map<String, Object> resetFolderOutput = new HashMap<>();
|
Map<String, Object> resetFolderOutput = new HashMap<>();
|
||||||
resetFolderOutput.put("status","IN-PROGRESS");
|
|
||||||
nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) resetFolderOutput);
|
|
||||||
nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null);
|
|
||||||
Node nodeInfo = nodes.getNode(nodeId);
|
|
||||||
NodePermissions nodePerms = nodeInfo.getPermissions();
|
|
||||||
int maxItems = params.getPaging().getMaxItems();
|
int maxItems = params.getPaging().getMaxItems();
|
||||||
QName qName = nodeService.getType(nodeRef);
|
QName qName = nodeService.getType(nodeRef);
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
resetFolderOutput.put("status","IN-PROGRESS");
|
||||||
|
nodeService.setProperty(nodeRef, FolderSizeModel.PROP_OUTPUT, (Serializable) resetFolderOutput);
|
||||||
|
nodeService.setProperty(nodeRef, FolderSizeModel.PROP_ERROR,null);
|
||||||
|
|
||||||
if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED)
|
validatePermissions(nodeRef, nodeId);
|
||||||
{
|
|
||||||
throw new AccessDeniedException("permissions.err_access_denied");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!"folder".equals(qName.getLocalName()))
|
if(!"folder".equals(qName.getLocalName()))
|
||||||
{
|
{
|
||||||
@@ -174,33 +169,13 @@ public class NodeFolderSizeRelation implements RelationshipResourceAction.Calcul
|
|||||||
public Map<String, Object> readById(String nodeId, String id, Parameters parameters)
|
public Map<String, Object> readById(String nodeId, String id, Parameters parameters)
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = nodes.validateNode(nodeId);
|
NodeRef nodeRef = nodes.validateNode(nodeId);
|
||||||
Node nodeInfo = nodes.getNode(nodeId);
|
validatePermissions(nodeRef, nodeId);
|
||||||
NodePermissions nodePerms = nodeInfo.getPermissions();
|
validateNodeType(nodeRef);
|
||||||
|
|
||||||
// Validate permissions.
|
|
||||||
if (nodePerms != null && permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED)
|
|
||||||
{
|
|
||||||
throw new AccessDeniedException("permissions.err_access_denied");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check node type.
|
|
||||||
QName qName = nodeService.getType(nodeRef);
|
|
||||||
if (!"folder".equals(qName.getLocalName()))
|
|
||||||
{
|
|
||||||
throw new InvalidNodeTypeException(NOT_A_VALID_NODEID);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for specific properties
|
|
||||||
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
|
|
||||||
if (properties.containsKey(FolderSizeModel.PROP_ERROR) && properties.get(FolderSizeModel.PROP_ERROR) != null)
|
|
||||||
{
|
|
||||||
throw new InvalidNodeTypeException(String.valueOf(properties.get(FolderSizeModel.PROP_ERROR)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process properties and return result.
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LOG.info("Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById");
|
LOG.info("Retrieving OUTPUT from ActionExecutor in NodeFolderSizeRelation:readById");
|
||||||
|
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT))
|
if (properties == null || !properties.containsKey(FolderSizeModel.PROP_OUTPUT))
|
||||||
@@ -231,4 +206,34 @@ public class NodeFolderSizeRelation implements RelationshipResourceAction.Calcul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateNodeType(NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
// Check node type.
|
||||||
|
QName qName = nodeService.getType(nodeRef);
|
||||||
|
|
||||||
|
if (!"folder".equals(qName.getLocalName()))
|
||||||
|
{
|
||||||
|
throw new InvalidNodeTypeException(NOT_A_VALID_NODEID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for specific properties
|
||||||
|
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
|
||||||
|
if (properties.containsKey(FolderSizeModel.PROP_ERROR) && properties.get(FolderSizeModel.PROP_ERROR) != null)
|
||||||
|
{
|
||||||
|
throw new InvalidNodeTypeException(String.valueOf(properties.get(FolderSizeModel.PROP_ERROR)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.action.executer;
|
package org.alfresco.repo.action.executer;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.model.FolderSizeModel;
|
import org.alfresco.model.FolderSizeModel;
|
||||||
import org.alfresco.repo.action.ActionImpl;
|
import org.alfresco.repo.action.ActionImpl;
|
||||||
@@ -98,12 +100,11 @@ public class NodeSizeActionExecuterTest extends BaseSpringTest
|
|||||||
@Test
|
@Test
|
||||||
public void testExecution()
|
public void testExecution()
|
||||||
{
|
{
|
||||||
assertEquals(1,1);
|
|
||||||
int maxItems = 100;
|
int maxItems = 100;
|
||||||
ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null);
|
ActionImpl action = new ActionImpl(null, ID, NodeSizeActionExecuter.NAME, null);
|
||||||
action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems);
|
action.setParameterValue(NodeSizeActionExecuter.PAGE_SIZE, maxItems);
|
||||||
this.executer.executeImpl(action, this.nodeRef);
|
this.executer.executeImpl(action, this.nodeRef);
|
||||||
String compareString = this.nodeService.getProperty(this.nodeRef, FolderSizeModel.PROP_STATUS).toString();
|
Map<String, Object> mapResult = (Map<String, Object>)this.nodeService.getProperty(this.nodeRef, FolderSizeModel.PROP_OUTPUT);
|
||||||
assertTrue(compareString != null);
|
assertTrue(mapResult != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user