mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1)
128134 jvonka: v1 REST API: minor bug fix(es) to error handling when creating node with assocs + sanity api tests REPO-476, REPO-477 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129126 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -57,7 +57,6 @@ import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.QuickShareLinks;
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.AssocTarget;
|
||||
import org.alfresco.rest.api.model.ContentInfo;
|
||||
import org.alfresco.rest.api.model.Document;
|
||||
import org.alfresco.rest.api.model.Folder;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
@@ -136,8 +135,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.extensions.surf.util.Content;
|
||||
import org.springframework.extensions.webscripts.servlet.FormData;
|
||||
import org.springframework.http.InvalidMediaTypeException;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -361,6 +358,12 @@ public class NodesImpl implements Nodes
|
||||
@Override
|
||||
public NodeRef validateNode(String nodeId)
|
||||
{
|
||||
//belts-and-braces
|
||||
if (nodeId == null)
|
||||
{
|
||||
throw new InvalidArgumentException("Missing nodeId");
|
||||
}
|
||||
|
||||
return validateNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
|
||||
}
|
||||
|
||||
@@ -1678,11 +1681,17 @@ public class NodesImpl implements Nodes
|
||||
|
||||
for (AssocChild assoc : entities)
|
||||
{
|
||||
String childId = assoc.getChildId();
|
||||
if (childId == null)
|
||||
{
|
||||
throw new InvalidArgumentException("Missing childId");
|
||||
}
|
||||
|
||||
QName assocTypeQName = getAssocType(assoc.getAssocType());
|
||||
|
||||
try
|
||||
{
|
||||
NodeRef childNodeRef = validateNode(assoc.getChildId());
|
||||
NodeRef childNodeRef = validateNode(childId);
|
||||
|
||||
String nodeName = (String)nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
|
||||
QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
|
||||
@@ -1712,11 +1721,14 @@ public class NodesImpl implements Nodes
|
||||
|
||||
for (AssocTarget assoc : entities)
|
||||
{
|
||||
String targetNodeId = assoc.getTargetId();
|
||||
if (targetNodeId == null)
|
||||
{
|
||||
throw new InvalidArgumentException("Missing targetId");
|
||||
}
|
||||
|
||||
String assocTypeStr = assoc.getAssocType();
|
||||
QName assocTypeQName = getAssocType(assocTypeStr);
|
||||
|
||||
String targetNodeId = assoc.getTargetId();
|
||||
|
||||
try
|
||||
{
|
||||
NodeRef tgtNodeRef = validateNode(targetNodeId);
|
||||
|
@@ -1488,6 +1488,8 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
||||
response = post(getNodeChildrenUrl(myFolderNodeId), user1, toJsonAsStringNonNull(n), 201);
|
||||
String f2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
|
||||
|
||||
String f3Id = createFolder(user1, myFolderNodeId, "f3").getId();
|
||||
|
||||
try
|
||||
{
|
||||
Paging paging = getPaging(0, 100);
|
||||
@@ -1506,13 +1508,42 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
||||
|
||||
|
||||
// -ve test - minor: error code if creating a cyclic child assoc (REPO-475)
|
||||
String myNodeId = getMyNodeId(user1);
|
||||
n = new Node();
|
||||
n.setName("my-folder-1");
|
||||
n.setName("my-folder");
|
||||
n.setNodeType(TYPE_CM_FOLDER);
|
||||
AssocChild assocChild = new AssocChild(myNodeId, "cm:contains");
|
||||
AssocChild assocChild = new AssocChild(myFolderNodeId, "cm:contains");
|
||||
n.setSecondaryChildren(Collections.singletonList(assocChild));
|
||||
post(getNodeChildrenUrl(myNodeId), user1, RestApiUtil.toJsonAsStringNonNull(n), 400);
|
||||
post(getNodeChildrenUrl(myFolderNodeId), user1, RestApiUtil.toJsonAsStringNonNull(n), 400);
|
||||
|
||||
// -ve tests - missing targetId / childId or assocType
|
||||
|
||||
n = new Node();
|
||||
n.setName("my-folder");
|
||||
n.setNodeType(TYPE_CM_FOLDER);
|
||||
assocChild = new AssocChild(null, ASSOC_TYPE_CM_CONTAINS);
|
||||
n.setSecondaryChildren(Collections.singletonList(assocChild));
|
||||
post(getNodeChildrenUrl(f3Id), user1, RestApiUtil.toJsonAsStringNonNull(n), 400);
|
||||
|
||||
n = new Node();
|
||||
n.setName("my-folder");
|
||||
n.setNodeType(TYPE_CM_FOLDER);
|
||||
assocChild = new AssocChild(f2Id, null);
|
||||
n.setSecondaryChildren(Collections.singletonList(assocChild));
|
||||
post(getNodeChildrenUrl(f3Id), user1, RestApiUtil.toJsonAsStringNonNull(n), 400);
|
||||
|
||||
n = new Node();
|
||||
n.setName("my-folder");
|
||||
n.setNodeType(TYPE_CM_FOLDER);
|
||||
tgt = new AssocTarget(null, ASSOC_TYPE_CM_REFERENCES);
|
||||
n.setTargets(Collections.singletonList(tgt));
|
||||
post(getNodeChildrenUrl(f3Id), user1, RestApiUtil.toJsonAsStringNonNull(n), 400);
|
||||
|
||||
n = new Node();
|
||||
n.setName("my-folder");
|
||||
n.setNodeType(TYPE_CM_FOLDER);
|
||||
tgt = new AssocTarget(f2Id, null);
|
||||
n.setTargets(Collections.singletonList(tgt));
|
||||
post(getNodeChildrenUrl(f3Id), user1, RestApiUtil.toJsonAsStringNonNull(n), 400);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -1520,6 +1551,7 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
||||
Map<String, String> params = Collections.singletonMap(Nodes.PARAM_PERMANENT, "true");
|
||||
delete(URL_NODES, user1, f1Id, params, 204);
|
||||
delete(URL_NODES, user1, f2Id, params, 204);
|
||||
delete(URL_NODES, user1, f3Id, params, 204);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user