mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-4863 Add method validateOrLookupNode without path.
This commit is contained in:
@@ -39,6 +39,8 @@ import org.alfresco.rest.api.model.LockInfo;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.api.model.PathInfo;
|
||||
import org.alfresco.rest.api.model.UserInfo;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
@@ -208,6 +210,16 @@ public interface Nodes
|
||||
NodeRef validateNode(StoreRef storeRef, String nodeId);
|
||||
NodeRef validateNode(String nodeId);
|
||||
NodeRef validateNode(NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* Check that the specified id refers to a valid node.
|
||||
*
|
||||
* @param nodeId The node id to look up using SpacesStore or an alias like -root-.
|
||||
* @return The node ref.
|
||||
* @throws InvalidArgumentException if the specified node id is not a valid format.
|
||||
* @throws EntityNotFoundException if the specified node was not found in the database.
|
||||
*/
|
||||
NodeRef validateOrLookupNode(String nodeId);
|
||||
NodeRef validateOrLookupNode(String nodeId, String path);
|
||||
|
||||
boolean nodeMatches(NodeRef nodeRef, Set<QName> expectedTypes, Set<QName> excludedTypes);
|
||||
|
@@ -189,7 +189,7 @@ public class CategoriesImpl implements Categories
|
||||
@Override
|
||||
public List<Category> listCategoriesForNode(final String nodeId, final Parameters parameters)
|
||||
{
|
||||
final NodeRef contentNodeRef = nodes.validateOrLookupNode(nodeId, null);
|
||||
final NodeRef contentNodeRef = nodes.validateOrLookupNode(nodeId);
|
||||
verifyReadPermission(contentNodeRef);
|
||||
verifyNodeType(contentNodeRef);
|
||||
|
||||
@@ -211,7 +211,7 @@ public class CategoriesImpl implements Categories
|
||||
throw new InvalidArgumentException(NOT_A_VALID_CATEGORY);
|
||||
}
|
||||
|
||||
final NodeRef contentNodeRef = nodes.validateOrLookupNode(nodeId, null);
|
||||
final NodeRef contentNodeRef = nodes.validateOrLookupNode(nodeId);
|
||||
verifyChangePermission(contentNodeRef);
|
||||
verifyNodeType(contentNodeRef);
|
||||
|
||||
@@ -237,7 +237,7 @@ public class CategoriesImpl implements Categories
|
||||
public void unlinkNodeFromCategory(final StoreRef storeRef, final String nodeId, final String categoryId, final Parameters parameters)
|
||||
{
|
||||
final NodeRef categoryNodeRef = getCategoryNodeRef(storeRef, categoryId);
|
||||
final NodeRef contentNodeRef = nodes.validateOrLookupNode(nodeId, null);
|
||||
final NodeRef contentNodeRef = nodes.validateOrLookupNode(nodeId);
|
||||
verifyChangePermission(contentNodeRef);
|
||||
verifyNodeType(contentNodeRef);
|
||||
|
||||
|
@@ -649,6 +649,11 @@ public class NodesImpl implements Nodes
|
||||
return nodeService.getPrimaryParent(nodeRef).getParentRef();
|
||||
}
|
||||
|
||||
public NodeRef validateOrLookupNode(String nodeId)
|
||||
{
|
||||
return validateOrLookupNode(nodeId);
|
||||
}
|
||||
|
||||
public NodeRef validateOrLookupNode(String nodeId, String path)
|
||||
{
|
||||
NodeRef parentNodeRef;
|
||||
@@ -1356,7 +1361,7 @@ public class NodesImpl implements Nodes
|
||||
|
||||
private void calculateRelativePath(String parentFolderNodeId, Node node)
|
||||
{
|
||||
NodeRef rootNodeRef = validateOrLookupNode(parentFolderNodeId, null);
|
||||
NodeRef rootNodeRef = validateOrLookupNode(parentFolderNodeId);
|
||||
try
|
||||
{
|
||||
// get the path elements
|
||||
@@ -1741,7 +1746,7 @@ public class NodesImpl implements Nodes
|
||||
@Override
|
||||
public void deleteNode(String nodeId, Parameters parameters)
|
||||
{
|
||||
NodeRef nodeRef = validateOrLookupNode(nodeId, null);
|
||||
NodeRef nodeRef = validateOrLookupNode(nodeId);
|
||||
|
||||
if (isSpecialNode(nodeRef, getNodeType(nodeRef)))
|
||||
{
|
||||
@@ -1785,7 +1790,7 @@ public class NodesImpl implements Nodes
|
||||
validateProperties(nodeInfo.getProperties(), EXCLUDED_NS, Arrays.asList());
|
||||
|
||||
// check that requested parent node exists and it's type is a (sub-)type of folder
|
||||
NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
|
||||
NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId);
|
||||
|
||||
// node name - mandatory
|
||||
String nodeName = nodeInfo.getName();
|
||||
@@ -2290,7 +2295,7 @@ public class NodesImpl implements Nodes
|
||||
validateAspects(nodeInfo.getAspectNames(), EXCLUDED_NS, EXCLUDED_ASPECTS);
|
||||
validateProperties(nodeInfo.getProperties(), EXCLUDED_NS, Arrays.asList());
|
||||
|
||||
final NodeRef nodeRef = validateOrLookupNode(nodeId, null);
|
||||
final NodeRef nodeRef = validateOrLookupNode(nodeId);
|
||||
|
||||
QName nodeTypeQName = getNodeType(nodeRef);
|
||||
|
||||
@@ -2523,8 +2528,8 @@ public class NodesImpl implements Nodes
|
||||
throw new InvalidArgumentException("Missing targetParentId");
|
||||
}
|
||||
|
||||
final NodeRef parentNodeRef = validateOrLookupNode(targetParentId, null);
|
||||
final NodeRef sourceNodeRef = validateOrLookupNode(sourceNodeId, null);
|
||||
final NodeRef parentNodeRef = validateOrLookupNode(targetParentId);
|
||||
final NodeRef sourceNodeRef = validateOrLookupNode(sourceNodeId);
|
||||
|
||||
FileInfo fi = moveOrCopyImpl(sourceNodeRef, parentNodeRef, name, isCopy);
|
||||
return getFolderOrDocument(fi.getNodeRef().getId(), parameters);
|
||||
@@ -2954,7 +2959,7 @@ public class NodesImpl implements Nodes
|
||||
throw new InvalidArgumentException("The request content-type is not multipart: "+parentFolderNodeId);
|
||||
}
|
||||
|
||||
NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
|
||||
NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId);
|
||||
if (!nodeMatches(parentNodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), null, false))
|
||||
{
|
||||
throw new InvalidArgumentException("NodeId of folder is expected: " + parentNodeRef.getId());
|
||||
@@ -3385,7 +3390,7 @@ public class NodesImpl implements Nodes
|
||||
@Override
|
||||
public Node lock(String nodeId, LockInfo lockInfo, Parameters parameters)
|
||||
{
|
||||
NodeRef nodeRef = validateOrLookupNode(nodeId, null);
|
||||
NodeRef nodeRef = validateOrLookupNode(nodeId);
|
||||
|
||||
if (isSpecialNode(nodeRef, getNodeType(nodeRef)))
|
||||
{
|
||||
@@ -3424,7 +3429,7 @@ public class NodesImpl implements Nodes
|
||||
@Override
|
||||
public Node unlock(String nodeId, Parameters parameters)
|
||||
{
|
||||
NodeRef nodeRef = validateOrLookupNode(nodeId, null);
|
||||
NodeRef nodeRef = validateOrLookupNode(nodeId);
|
||||
|
||||
if (isSpecialNode(nodeRef, getNodeType(nodeRef)))
|
||||
{
|
||||
|
@@ -185,7 +185,7 @@ public class QueriesImpl implements Queries, InitializingBean
|
||||
String rootNodeId = parameters.getParameter(PARAM_ROOT_NODE_ID);
|
||||
if (rootNodeId != null)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(rootNodeId, null);
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(rootNodeId);
|
||||
query.append("PATH:\"").append(getQNamePath(nodeRef.getId())).append("//*\" AND (");
|
||||
}
|
||||
if (term != null)
|
||||
|
@@ -695,7 +695,7 @@ public class RenditionsImpl implements Renditions, ResourceLoaderAware
|
||||
{
|
||||
if (versionLabelId != null)
|
||||
{
|
||||
nodeRef = nodes.validateOrLookupNode(nodeRef.getId(), null);
|
||||
nodeRef = nodes.validateOrLookupNode(nodeRef.getId());
|
||||
VersionHistory vh = versionService.getVersionHistory(nodeRef);
|
||||
if (vh != null)
|
||||
{
|
||||
|
@@ -117,7 +117,7 @@ public class TagsImpl implements Tags
|
||||
|
||||
public List<Tag> addTags(String nodeId, final List<Tag> tags)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId);
|
||||
if (!typeConstraint.matches(nodeRef))
|
||||
{
|
||||
throw new UnsupportedResourceOperationException("Cannot tag this node");
|
||||
@@ -241,7 +241,7 @@ public class TagsImpl implements Tags
|
||||
|
||||
public CollectionWithPagingInfo<Tag> getTags(String nodeId, Parameters params)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId);
|
||||
PagingResults<Pair<NodeRef, String>> results = taggingService.getTags(nodeRef, Util.getPagingRequest(params.getPaging()));
|
||||
Integer totalItems = results.getTotalResultCount().getFirst();
|
||||
List<Pair<NodeRef, String>> page = results.getPage();
|
||||
|
@@ -134,7 +134,7 @@ public class RestRuleModelMapper implements RestModelMapper<Rule, org.alfresco.s
|
||||
public org.alfresco.service.cmr.rule.Rule toServiceModel(Rule restRuleModel)
|
||||
{
|
||||
final org.alfresco.service.cmr.rule.Rule serviceRule = new org.alfresco.service.cmr.rule.Rule();
|
||||
final NodeRef nodeRef = (restRuleModel.getId() != null) ? nodes.validateOrLookupNode(restRuleModel.getId(), null) : null;
|
||||
final NodeRef nodeRef = (restRuleModel.getId() != null) ? nodes.validateOrLookupNode(restRuleModel.getId()) : null;
|
||||
serviceRule.setNodeRef(nodeRef);
|
||||
serviceRule.setTitle(restRuleModel.getName());
|
||||
serviceRule.setDescription(restRuleModel.getDescription());
|
||||
|
@@ -129,7 +129,7 @@ public class RestRuleSimpleConditionModelMapper implements RestModelMapper<Simpl
|
||||
parameterValues.put(InCategoryEvaluator.PARAM_CATEGORY_ASPECT, ContentModel.ASPECT_GEN_CLASSIFIABLE);
|
||||
try
|
||||
{
|
||||
parameterValues.put(InCategoryEvaluator.PARAM_CATEGORY_VALUE, nodes.validateOrLookupNode(parameter, null));
|
||||
parameterValues.put(InCategoryEvaluator.PARAM_CATEGORY_VALUE, nodes.validateOrLookupNode(parameter));
|
||||
} catch (EntityNotFoundException e) {
|
||||
throw new InvalidArgumentException(CATEGORY_INVALID_MSG);
|
||||
}
|
||||
|
@@ -173,7 +173,7 @@ public class ActionParameterConverter
|
||||
}
|
||||
else if (typeQName.isMatch(DataTypeDefinition.NODE_REF))
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(stringValue, null);
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(stringValue);
|
||||
if (permissionService.hasReadPermission(nodeRef) != ALLOWED)
|
||||
{
|
||||
throw new EntityNotFoundException(stringValue);
|
||||
|
@@ -72,7 +72,7 @@ public class NodeValidator
|
||||
{
|
||||
try
|
||||
{
|
||||
final NodeRef nodeRef = nodes.validateOrLookupNode(folderNodeId, null);
|
||||
final NodeRef nodeRef = nodes.validateOrLookupNode(folderNodeId);
|
||||
validatePermission(requireChangePermission, nodeRef);
|
||||
verifyNodeType(nodeRef, ContentModel.TYPE_FOLDER, null);
|
||||
|
||||
|
@@ -31,13 +31,9 @@ import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.rest.framework.resource.parameters.SortColumn;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RelationshipResource(name = "action-definitions", entityResource = NodesEntityResource.class, title = "Node action definitions")
|
||||
public class NodeActionDefinitionsRelation extends AbstractNodeRelation
|
||||
implements RelationshipResourceAction.Read<ActionDefinition>
|
||||
@@ -59,7 +55,7 @@ public class NodeActionDefinitionsRelation extends AbstractNodeRelation
|
||||
@Override
|
||||
public CollectionWithPagingInfo<ActionDefinition> readAll(String entityResourceId, Parameters params)
|
||||
{
|
||||
NodeRef parentNodeRef = nodes.validateOrLookupNode(entityResourceId, null);
|
||||
NodeRef parentNodeRef = nodes.validateOrLookupNode(entityResourceId);
|
||||
return actions.getActionDefinitions(parentNodeRef, params);
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,11 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.nodes;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.rest.antlr.WhereClauseParser;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
@@ -41,11 +46,6 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QNamePattern;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Node Parents
|
||||
*
|
||||
@@ -67,7 +67,7 @@ public class NodeParentsRelation extends AbstractNodeRelation implements Relatio
|
||||
@WebApiDescription(title = "Return a list of parent nodes based on child assocs")
|
||||
public CollectionWithPagingInfo<Node> readAll(String childNodeId, Parameters parameters)
|
||||
{
|
||||
NodeRef childNodeRef = nodes.validateOrLookupNode(childNodeId, null);
|
||||
NodeRef childNodeRef = nodes.validateOrLookupNode(childNodeId);
|
||||
|
||||
QNamePattern assocTypeQNameParam = RegexQNamePattern.MATCH_ALL;
|
||||
|
||||
|
@@ -25,6 +25,8 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.nodes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
@@ -41,8 +43,6 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.QNamePattern;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Node Secondary Children
|
||||
*
|
||||
@@ -71,7 +71,7 @@ public class NodeSecondaryChildrenRelation extends AbstractNodeRelation implemen
|
||||
@WebApiDescription(title = "Return a paged list of secondary child nodes based on child assocs")
|
||||
public CollectionWithPagingInfo<Node> readAll(String parentNodeId, Parameters parameters)
|
||||
{
|
||||
NodeRef parentNodeRef = nodes.validateOrLookupNode(parentNodeId, null);
|
||||
NodeRef parentNodeRef = nodes.validateOrLookupNode(parentNodeId);
|
||||
|
||||
QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);
|
||||
|
||||
|
@@ -25,6 +25,8 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.nodes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
@@ -35,8 +37,6 @@ import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QNamePattern;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Node Sources - list node (peer) associations from target to sources
|
||||
*
|
||||
@@ -54,7 +54,7 @@ public class NodeSourcesRelation extends AbstractNodeRelation implements Relatio
|
||||
@WebApiDescription(title = "Return a paged list of sources nodes based on (peer) assocs")
|
||||
public CollectionWithPagingInfo<Node> readAll(String targetNodeId, Parameters parameters)
|
||||
{
|
||||
NodeRef targetNodeRef = nodes.validateOrLookupNode(targetNodeId, null);
|
||||
NodeRef targetNodeRef = nodes.validateOrLookupNode(targetNodeId);
|
||||
|
||||
QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);
|
||||
|
||||
|
@@ -25,6 +25,8 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.nodes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.AssocTarget;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
@@ -40,8 +42,6 @@ import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.namespace.QNamePattern;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Node Targets
|
||||
*
|
||||
@@ -64,7 +64,7 @@ public class NodeTargetsRelation extends AbstractNodeRelation implements
|
||||
@WebApiDescription(title = "Return a paged list of target nodes based on (peer) assocs")
|
||||
public CollectionWithPagingInfo<Node> readAll(String sourceNodeId, Parameters parameters)
|
||||
{
|
||||
NodeRef sourceNodeRef = nodes.validateOrLookupNode(sourceNodeId, null);
|
||||
NodeRef sourceNodeRef = nodes.validateOrLookupNode(sourceNodeId);
|
||||
|
||||
QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);
|
||||
|
||||
|
@@ -25,6 +25,13 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.nodes;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.directurl.DirectAccessUrlDisabledException;
|
||||
import org.alfresco.repo.node.integrity.IntegrityException;
|
||||
@@ -65,13 +72,6 @@ import org.alfresco.util.ParameterCheck;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Node Versions - version history
|
||||
*
|
||||
@@ -117,7 +117,7 @@ public class NodeVersionsRelation extends AbstractNodeRelation implements
|
||||
@WebApiDescription(title = "Return version history as a paged list of version node infos")
|
||||
public CollectionWithPagingInfo<Node> readAll(String nodeId, Parameters parameters)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId);
|
||||
|
||||
VersionHistory vh = versionService.getVersionHistory(nodeRef);
|
||||
|
||||
@@ -293,7 +293,7 @@ public class NodeVersionsRelation extends AbstractNodeRelation implements
|
||||
|
||||
public Version findVersion(String nodeId, String versionLabelId)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId);
|
||||
VersionHistory vh = versionService.getVersionHistory(nodeRef);
|
||||
if (vh != null)
|
||||
{
|
||||
|
@@ -128,7 +128,7 @@ public class CategoriesImplTest
|
||||
{
|
||||
given(authorityServiceMock.hasAdminAuthority()).willReturn(true);
|
||||
given(nodesMock.validateNode(CATEGORY_ID)).willReturn(CATEGORY_NODE_REF);
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID, null)).willReturn(CONTENT_NODE_REF);
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willReturn(CONTENT_NODE_REF);
|
||||
given(nodesMock.isSubClass(any(), any(), anyBoolean())).willReturn(true);
|
||||
given(typeConstraint.matches(any())).willReturn(true);
|
||||
given(permissionServiceMock.hasReadPermission(any())).willReturn(AccessStatus.ALLOWED);
|
||||
@@ -900,7 +900,7 @@ public class CategoriesImplTest
|
||||
// when
|
||||
final List<Category> actualLinkedCategories = objectUnderTest.linkNodeToCategories(CONTENT_NODE_ID, categoryLinks, parametersMock);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID);
|
||||
then(permissionServiceMock).should().hasPermission(CONTENT_NODE_REF, PermissionService.CHANGE_PERMISSIONS);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(typeConstraint).should().matches(CONTENT_NODE_REF);
|
||||
@@ -1011,12 +1011,12 @@ public class CategoriesImplTest
|
||||
@Test
|
||||
public void testLinkNodeToCategories_withInvalidNodeId()
|
||||
{
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID, null)).willThrow(EntityNotFoundException.class);
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willThrow(EntityNotFoundException.class);
|
||||
|
||||
// when
|
||||
final Throwable actualException = catchThrowable(() -> objectUnderTest.linkNodeToCategories(CONTENT_NODE_ID, List.of(CATEGORY), parametersMock));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID);
|
||||
then(permissionServiceMock).shouldHaveNoInteractions();
|
||||
then(nodeServiceMock).shouldHaveNoInteractions();
|
||||
assertThat(actualException)
|
||||
@@ -1031,7 +1031,7 @@ public class CategoriesImplTest
|
||||
// when
|
||||
final Throwable actualException = catchThrowable(() -> objectUnderTest.linkNodeToCategories(CONTENT_NODE_ID, List.of(CATEGORY), parametersMock));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID);
|
||||
then(permissionServiceMock).should().hasPermission(CONTENT_NODE_REF, PermissionService.CHANGE_PERMISSIONS);
|
||||
then(nodeServiceMock).shouldHaveNoInteractions();
|
||||
assertThat(actualException)
|
||||
@@ -1118,7 +1118,7 @@ public class CategoriesImplTest
|
||||
objectUnderTest.unlinkNodeFromCategory(CONTENT_NODE_ID, CATEGORY_ID, parametersMock);
|
||||
|
||||
then(nodesMock).should().validateNode(CATEGORY_ID);
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID);
|
||||
then(permissionServiceMock).should().hasPermission(CONTENT_NODE_REF, PermissionService.CHANGE_PERMISSIONS);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(typeConstraint).should().matches(CONTENT_NODE_REF);
|
||||
@@ -1155,7 +1155,7 @@ public class CategoriesImplTest
|
||||
// when
|
||||
final List<Category> actualCategories = objectUnderTest.listCategoriesForNode(CONTENT_NODE_ID, parametersMock);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID);
|
||||
then(permissionServiceMock).should().hasReadPermission(CONTENT_NODE_REF);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(typeConstraint).should().matches(CONTENT_NODE_REF);
|
||||
@@ -1176,12 +1176,12 @@ public class CategoriesImplTest
|
||||
@Test
|
||||
public void testListCategoriesForNode_withInvalidNodeId()
|
||||
{
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID, null)).willThrow(EntityNotFoundException.class);
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willThrow(EntityNotFoundException.class);
|
||||
|
||||
// when
|
||||
final Throwable actualException = catchThrowable(() -> objectUnderTest.listCategoriesForNode(CONTENT_NODE_ID, parametersMock));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID);
|
||||
then(nodeServiceMock).shouldHaveNoInteractions();
|
||||
assertThat(actualException)
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
@@ -1195,7 +1195,7 @@ public class CategoriesImplTest
|
||||
// when
|
||||
final Throwable actualException = catchThrowable(() -> objectUnderTest.listCategoriesForNode(CONTENT_NODE_ID, parametersMock));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(CONTENT_NODE_ID);
|
||||
then(permissionServiceMock).should().hasReadPermission(CONTENT_NODE_REF);
|
||||
then(nodeServiceMock).shouldHaveNoInteractions();
|
||||
assertThat(actualException)
|
||||
|
@@ -422,7 +422,7 @@ public class TagsImplTest
|
||||
@Test
|
||||
public void testAddTags()
|
||||
{
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID, null)).willReturn(CONTENT_NODE_REF);
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willReturn(CONTENT_NODE_REF);
|
||||
given(typeConstraintMock.matches(CONTENT_NODE_REF)).willReturn(true);
|
||||
List<Pair<String, NodeRef>> pairs = List.of(new Pair<>("tagA", new NodeRef("tag://A/")), new Pair<>("tagB", new NodeRef("tag://B/")));
|
||||
List<String> tagNames = pairs.stream().map(Pair::getFirst).collect(toList());
|
||||
@@ -438,7 +438,7 @@ public class TagsImplTest
|
||||
@Test(expected = InvalidArgumentException.class)
|
||||
public void testAddTagsToInvalidNode()
|
||||
{
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID, null)).willThrow(new InvalidArgumentException());
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willThrow(new InvalidArgumentException());
|
||||
List<Tag> tags = List.of(Tag.builder().tag("tag1").create());
|
||||
|
||||
objectUnderTest.addTags(CONTENT_NODE_ID, tags);
|
||||
@@ -447,7 +447,7 @@ public class TagsImplTest
|
||||
@Test(expected = UnsupportedResourceOperationException.class)
|
||||
public void testAddTagsToWrongTypeOfNode()
|
||||
{
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID, null)).willReturn(CONTENT_NODE_REF);
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willReturn(CONTENT_NODE_REF);
|
||||
given(typeConstraintMock.matches(CONTENT_NODE_REF)).willReturn(false);
|
||||
|
||||
List<Tag> tags = List.of(Tag.builder().tag("tag1").create());
|
||||
@@ -458,7 +458,7 @@ public class TagsImplTest
|
||||
@Test
|
||||
public void testGetTagsForNode()
|
||||
{
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID, null)).willReturn(CONTENT_NODE_REF);
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willReturn(CONTENT_NODE_REF);
|
||||
given(parametersMock.getPaging()).willReturn(pagingMock);
|
||||
List<Pair<NodeRef, String>> pairs = List.of(new Pair<>(new NodeRef("tag://A/"), "tagA"), new Pair<>(new NodeRef("tag://B/"), "tagB"));
|
||||
given(taggingServiceMock.getTags(eq(CONTENT_NODE_REF), any(PagingRequest.class))).willReturn(pagingResultsMock);
|
||||
@@ -474,7 +474,7 @@ public class TagsImplTest
|
||||
@Test (expected = InvalidArgumentException.class)
|
||||
public void testGetTagsFromInvalidNode()
|
||||
{
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID, null)).willThrow(new InvalidArgumentException());
|
||||
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willThrow(new InvalidArgumentException());
|
||||
|
||||
objectUnderTest.getTags(CONTENT_NODE_ID, parametersMock);
|
||||
}
|
||||
|
@@ -134,7 +134,7 @@ public class RestRuleModelMapperTest
|
||||
// when
|
||||
final org.alfresco.service.cmr.rule.Rule actualRuleModel = objectUnderTest.toServiceModel(rule);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(RULE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(RULE_ID);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(actionMapperMock).should().toServiceModel(List.of(action));
|
||||
then(actionMapperMock).shouldHaveNoMoreInteractions();
|
||||
|
@@ -275,7 +275,7 @@ public class RestRuleSimpleConditionModelMapperTest
|
||||
{
|
||||
final SimpleCondition simpleCondition = createSimpleCondition(PARAM_CATEGORY);
|
||||
final NodeRef defaultNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, PARAMETER_DEFAULT);
|
||||
given(nodesMock.validateOrLookupNode(PARAMETER_DEFAULT, null)).willReturn(defaultNodeRef);
|
||||
given(nodesMock.validateOrLookupNode(PARAMETER_DEFAULT)).willReturn(defaultNodeRef);
|
||||
|
||||
// when
|
||||
final ActionCondition actualActionCondition = objectUnderTest.toServiceModel(simpleCondition);
|
||||
|
@@ -44,7 +44,6 @@ import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
|
||||
import org.alfresco.repo.action.executer.CheckInActionExecuter;
|
||||
import org.alfresco.repo.action.executer.CheckOutActionExecuter;
|
||||
@@ -129,8 +128,8 @@ public class ActionParameterConverterTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
given(nodes.validateOrLookupNode(DUMMY_FOLDER_NODE_ID, null)).willReturn(DUMMY_FOLDER_NODE);
|
||||
given(nodes.validateOrLookupNode(DUMMY_SCRIPT_NODE_ID, null)).willReturn(DUMMY_SCRIPT_NODE);
|
||||
given(nodes.validateOrLookupNode(DUMMY_FOLDER_NODE_ID)).willReturn(DUMMY_FOLDER_NODE);
|
||||
given(nodes.validateOrLookupNode(DUMMY_SCRIPT_NODE_ID)).willReturn(DUMMY_SCRIPT_NODE);
|
||||
given(permissionService.hasReadPermission(DUMMY_FOLDER_NODE)).willReturn(ALLOWED);
|
||||
given(permissionService.hasReadPermission(DUMMY_SCRIPT_NODE)).willReturn(ALLOWED);
|
||||
}
|
||||
@@ -598,7 +597,7 @@ public class ActionParameterConverterTest
|
||||
String permissionDeniedNodeId = "permission://denied/node";
|
||||
final Map<String, Serializable> params = Map.of(PARAM_DESTINATION_FOLDER, permissionDeniedNodeId);
|
||||
NodeRef permissionDeniedNode = new NodeRef(permissionDeniedNodeId);
|
||||
given(nodes.validateOrLookupNode(permissionDeniedNodeId, null)).willReturn(permissionDeniedNode);
|
||||
given(nodes.validateOrLookupNode(permissionDeniedNodeId)).willReturn(permissionDeniedNode);
|
||||
given(permissionService.hasReadPermission(permissionDeniedNode)).willReturn(DENIED);
|
||||
|
||||
given(actionService.getActionDefinition(name)).willReturn(actionDefinition);
|
||||
|
@@ -101,7 +101,7 @@ public class NodeValidatorTest
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
MockitoAnnotations.openMocks(this);
|
||||
given(nodesMock.validateOrLookupNode(eq(FOLDER_NODE_ID), any())).willReturn(folderNodeRef);
|
||||
given(nodesMock.validateOrLookupNode(FOLDER_NODE_ID)).willReturn(folderNodeRef);
|
||||
given(nodesMock.validateNode(RULE_SET_ID)).willReturn(ruleSetNodeRef);
|
||||
given(nodesMock.validateNode(RULE_ID)).willReturn(ruleNodeRef);
|
||||
given(nodesMock.nodeMatches(any(), any(), any())).willReturn(true);
|
||||
@@ -115,7 +115,7 @@ public class NodeValidatorTest
|
||||
// when
|
||||
final NodeRef nodeRef = nodeValidator.validateFolderNode(FOLDER_NODE_ID, false);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID);
|
||||
then(nodesMock).should().nodeMatches(folderNodeRef, Set.of(TYPE_FOLDER), null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasReadPermission(folderNodeRef);
|
||||
@@ -128,13 +128,13 @@ public class NodeValidatorTest
|
||||
@Test
|
||||
public void testValidateFolderNode_notExistingFolder()
|
||||
{
|
||||
given(nodesMock.validateOrLookupNode(any(), any())).willThrow(new EntityNotFoundException(FOLDER_NODE_ID));
|
||||
given(nodesMock.validateOrLookupNode(FOLDER_NODE_ID)).willThrow(new EntityNotFoundException(FOLDER_NODE_ID));
|
||||
|
||||
//when
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(
|
||||
() -> nodeValidator.validateFolderNode(FOLDER_NODE_ID, false));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class NodeValidatorTest
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> nodeValidator.validateFolderNode(FOLDER_NODE_ID, false));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID);
|
||||
then(nodesMock).should().nodeMatches(folderNodeRef, Set.of(TYPE_FOLDER), null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
@@ -431,11 +431,12 @@ public class NodeValidatorTest
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
private void resetNodesMock() {
|
||||
private void resetNodesMock()
|
||||
{
|
||||
reset(nodesMock);
|
||||
given(nodesMock.validateOrLookupNode(eq(FOLDER_NODE_ID), any())).willReturn(folderNodeRef);
|
||||
given(nodesMock.validateOrLookupNode(FOLDER_NODE_ID)).willReturn(folderNodeRef);
|
||||
given(nodesMock.validateNode(RULE_SET_ID)).willReturn(ruleSetNodeRef);
|
||||
given(nodesMock.validateNode(RULE_ID)).willReturn(ruleNodeRef);
|
||||
given(nodesMock.nodeMatches(ruleSetNodeRef, Set.of(ContentModel.TYPE_SYSTEM_FOLDER), null)).willReturn(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,10 +37,8 @@ import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyBoolean;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.notNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.notNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -186,7 +184,7 @@ public class ResultMapperTests
|
||||
when(sr.getVersionService()).thenReturn(versionService);
|
||||
when(sr.getNodeService()).thenReturn(nodeService);
|
||||
|
||||
when(nodes.validateOrLookupNode(nullable(String.class), nullable(String.class))).thenAnswer(invocation ->
|
||||
when(nodes.validateOrLookupNode(nullable(String.class))).thenAnswer(invocation ->
|
||||
{
|
||||
Object[] args = invocation.getArguments();
|
||||
String aNode = (String)args[0];
|
||||
|
Reference in New Issue
Block a user