It’s also possible to create associations on nodes that already exist, let’s add some more to our “My Gadget” fdk:gadget node. Before we do that though upload another image to the “My Gadgets” folder and some more content to represent another review, do it via ReST API or UI.
To create another child association we use the same URL we used earlier to retrieve the list of secondary child associations (nodes/{sourceId}/secondary-children) except this time we POST to it. Sending the body below will create another child association to the 2nd image with node ID 3e76d633-5dad-475e-bc9d-26a33ec64e11:
{ "childId": "3e76d633-5dad-475e-bc9d-26a33ec64e11", "assocType": "fdk:images" }
Here is how the call looks like:
$ curl -H "Content-Type: application/json" -d '{"childId":"3e76d633-5dad-475e-bc9d-26a33ec64e11", "assocType":"fdk:images"}' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/74351ea7-8c72-44e4-829c-7d606a8682c7/secondary-children | jq 100 161 0 85 100 76 1328 1187 --:--:-- --:--:-- --:--:-- 2515 { "entry": { "assocType": "fdk:images", "childId": "3e76d633-5dad-475e-bc9d-26a33ec64e11" } }
We can do the same thing to create another peer association by POSTing the following data to nodes/{sourceId}/targets (second review node ID = 80983f1e-ef4e-4285-bd08-94a343923192):
{ "targetId": "80983f1e-ef4e-4285-bd08-94a343923192", "assocType": "fdk:reviews" }
Here is how the call looks like:
$ curl -H "Content-Type: application/json" -d '{"targetId":"80983f1e-ef4e-4285-bd08-94a343923192", "assocType":"fdk:reviews"}' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/74351ea7-8c72-44e4-829c-7d606a8682c7/targets | jq 100 161 0 85 100 76 1328 1187 --:--:-- --:--:-- --:--:-- 2515 { "entry": { "targetId": "80983f1e-ef4e-4285-bd08-94a343923192", "assocType": "fdk:reviews" } }
If you now do a GET on the same URLs you should now see two fdk:images child associations and three peer associations, two of type fdk:reviews and one of type fdk:company.
Alfresco has a feature called multi-filing, this is where a node can appear in multiple folders, think of it as a unix symbolic link. This feature has been available via the CMIS API for a long time but it’s now exposed via the v1 ReST API too.
When we navigate around the repository we’re actually following the cm:contains child association, to make a node appear in multiple folders we can create a secondary child association from the folder to the node. To make the review text we uploaded in the beginning also appear in the /Company Home folder POST the following body to nodes/{companyHomeFolderId}/secondary-children
{ "childId": "{reviewTextId}", "assocType": "cm:contains" }
To find out the node ID for the company home folder you can go to
in Share.Here is how this call looks like:
$ curl -H "Content-Type: application/json" -d '{"childId":"581baebd-3814-4cd0-884a-3179f2dac0ac", "assocType":"cm:contains"}' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/695c2c56-3ba0-4539-b301-12bd9bb47712/secondary-children | jq 100 161 0 85 100 76 1328 1187 --:--:-- --:--:-- --:--:-- 2515 { "entry": { "assocType": "cm:contains", "childId": "581baebd-3814-4cd0-884a-3179f2dac0ac" } }
The review file now has two parent folders but only one is the primary parent. If we use the Share UI and double click on the review file in the Company Home folder a details page is displayed for the file with breadcrumbs showing the My Gadget folder as the parent because it’s the primary parent folder.
If we request a listing of the Company Home folder secondary children using: http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/{companyHomeId}/secondary-children?include=association
We can find out if a child association is primary or not.
By asking for the association information to be included we can see that the gadget-review.txt node is a secondary child association via the isPrimary flag, this allows clients to handle these “linked” nodes differently (i.e. restrict deletion).
$ curl -X GET -H 'Accept: application/json' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/695c2c56-3ba0-4539-b301-12bd9bb47712/secondary-children?include=association' | jq { "list": { "pagination": { "count": 1, "hasMoreItems": false, "totalItems": 1, "skipCount": 0, "maxItems": 100 }, "entries": [ { "entry": { ... "name": "gadget-review.txt", "association": { "isPrimary": false, "assocType": "cm:contains" }, ... } } ] } }