use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-remote-api by Alfresco.
the class NodeSourcesRelation method readAll.
/**
* List sources
*
* @param targetNodeId String id of target node
*/
@Override
@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);
QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);
List<AssociationRef> assocRefs = nodeAssocService.getSourceAssocs(targetNodeRef, assocTypeQNameParam);
return listNodePeerAssocs(assocRefs, parameters, false);
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-remote-api by Alfresco.
the class NodeTargetsRelation method readAll.
/**
* List targets
*
* @param sourceNodeId String id of source node
*/
@Override
@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);
QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);
List<AssociationRef> assocRefs = nodeAssocService.getTargetAssocs(sourceNodeRef, assocTypeQNameParam);
return listNodePeerAssocs(assocRefs, parameters, true);
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-remote-api by Alfresco.
the class NodeBrowserPost method getAssocs.
/**
* Gets the current node associations
*
* @return associations
*/
public List<PeerAssociation> getAssocs(NodeRef nodeRef) {
List<AssociationRef> refs = null;
try {
refs = getNodeService().getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
} catch (UnsupportedOperationException err) {
// some stores do not support associations
// but we doesn't want NPE in code below
refs = new ArrayList<AssociationRef>();
}
List<PeerAssociation> assocs = new ArrayList<PeerAssociation>(refs.size());
for (AssociationRef ref : refs) {
assocs.add(new PeerAssociation(ref.getTypeQName(), ref.getSourceRef(), ref.getTargetRef()));
}
return assocs;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-remote-api by Alfresco.
the class FormRestApiJsonPost_Test method testRemoveAssociationsFromNode.
/**
* This test method attempts to remove an existing association between two existing
* nodes.
*/
public void testRemoveAssociationsFromNode() throws Exception {
List<NodeRef> associatedNodes;
checkOriginalAssocsBeforeChanges();
// Remove an association
JSONObject jsonPostData = new JSONObject();
String assocsToRemove = associatedDoc_B.toString();
jsonPostData.put(ASSOC_CM_REFERENCES_REMOVED, assocsToRemove);
String jsonPostString = jsonPostData.toString();
sendRequest(new PostRequest(referencingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
// Check the now updated associations via the node service
List<AssociationRef> modifiedAssocs = nodeService.getTargetAssocs(referencingDocNodeRef, RegexQNamePattern.MATCH_ALL);
assertEquals(1, modifiedAssocs.size());
// Extract the target nodeRefs to make them easier to examine
associatedNodes = new ArrayList<NodeRef>(5);
for (AssociationRef assocRef : modifiedAssocs) {
associatedNodes.add(assocRef.getTargetRef());
}
assertTrue(associatedNodes.contains(associatedDoc_A));
// The Rest API should also give us the modified assocs.
/*Response response = sendRequest(new GetRequest(referencingNodeUpdateUrl), 200);
String jsonRspString = response.getContentAsString();
JSONObject jsonGetResponse = new JSONObject(jsonRspString);
JSONObject jsonData = (JSONObject)jsonGetResponse.get("data");
assertNotNull(jsonData);
JSONObject jsonFormData = (JSONObject)jsonData.get("formData");
assertNotNull(jsonFormData);
String jsonAssocs = (String)jsonFormData.get(ASSOC_CM_REFERENCES);
// We expect exactly 1 assoc on the test node
assertEquals(1, jsonAssocs.split(",").length);
for (AssociationRef assocRef : modifiedAssocs)
{
assertTrue(jsonAssocs.contains(assocRef.getTargetRef().toString()));
}*/
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-remote-api by Alfresco.
the class TestPeople method deleteAvatarDirect.
private void deleteAvatarDirect(NodeRef personRef) {
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(personRef).stream().filter(x -> x.getTypeQName().equals(ContentModel.ASSOC_PREFERENCE_IMAGE)).collect(Collectors.toList());
if (assocs.size() > 0) {
nodeService.deleteNode(assocs.get(0).getChildRef());
}
// remove old association if it exists
List<AssociationRef> refs = nodeService.getTargetAssocs(personRef, ContentModel.ASSOC_AVATAR);
if (refs.size() == 1) {
NodeRef existingRef = refs.get(0).getTargetRef();
nodeService.removeAssociation(personRef, existingRef, ContentModel.ASSOC_AVATAR);
}
if (assocs.size() > 1 || refs.size() > 1) {
fail(String.format("Pref images: %d, Avatar assocs: %d", assocs.size(), refs.size()));
}
}
Aggregations