Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2)

127447 jvonka: Node Associations - creating/listing primary child assoc type other than cm:contains
   - follow-on fix + test based on review back (create children below content)
   - also -ve test for model integrity excet
   - RA-1092


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127611 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-06-02 22:23:51 +00:00
parent be30635647
commit 0551900f4c
2 changed files with 41 additions and 5 deletions

View File

@@ -1533,11 +1533,6 @@ public class NodesImpl implements Nodes
// check that requested parent node exists and it's type is a (sub-)type of folder
NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
if (! nodeMatches(parentNodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), null, false))
{
throw new InvalidArgumentException("NodeId of folder is expected: "+parentNodeRef.getId());
}
// node name - mandatory
String nodeName = nodeInfo.getName();
if ((nodeName == null) || nodeName.isEmpty())

View File

@@ -1816,9 +1816,11 @@ public class NodeApiTest extends AbstractBaseApiTest
obj.setName("c1");
obj.setNodeType(TYPE_CM_CONTENT);
// assoc type => cm:contains
response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(obj), 201);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String c1Id = nodeResp.getId();
assertEquals(fId, nodeResp.getParentId());
obj = new Node();
obj.setName("c2");
@@ -1827,9 +1829,11 @@ public class NodeApiTest extends AbstractBaseApiTest
assoc.setAssocType(ASSOC_TYPE_CM_PREFERENCE_IMAGE);
obj.setAssociation(assoc);
// assoc type => cm:preferenceImage
response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(obj), 201);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String c2Id = nodeResp.getId();
assertEquals(fId, nodeResp.getParentId());
response = getAll(getNodeChildrenUrl(fId), user1, null, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
@@ -1852,6 +1856,43 @@ public class NodeApiTest extends AbstractBaseApiTest
assertEquals(1, nodes.size());
assertEquals(c2Id, nodes.get(0).getId());
assertTrue(nodes.get(0).getAssociation().getIsPrimary());
//
// test that we can also create children below content
//
obj = new Node();
obj.setName("c3");
obj.setNodeType(TYPE_CM_CONTENT);
nodeUpdate.setAspectNames(Collections.singletonList(ASPECT_CM_PREFERENCES));
// assoc type => cm:contains
response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(obj), 201);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String c3Id = nodeResp.getId();
obj = new Node();
obj.setName("c4");
obj.setNodeType(TYPE_CM_CONTENT);
assoc = new Association();
assoc.setAssocType(ASSOC_TYPE_CM_PREFERENCE_IMAGE);
obj.setAssociation(assoc);
// assoc type => cm:preferenceImage
response = post(getNodeChildrenUrl(c3Id), user1, toJsonAsStringNonNull(obj), 201);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals(c3Id, nodeResp.getParentId());
// -ve test
obj = new Node();
obj.setName("c5");
obj.setNodeType(TYPE_CM_CONTENT);
assoc = new Association();
assoc.setAssocType(ASSOC_TYPE_CM_CONTAINS);
obj.setAssociation(assoc);
// assoc type => cm:contains (requires parent to be a folder !)
post(getNodeChildrenUrl(c3Id), user1, toJsonAsStringNonNull(obj), 422);
}
finally
{