Here are the examples of the java api class org.alfresco.service.cmr.repository.AssociationRef taken from open source projects.
1. BaseNodeServiceTest#testGetSourceAssocs()
Project: community-edition
File: BaseNodeServiceTest.java
File: BaseNodeServiceTest.java
public void testGetSourceAssocs() throws Exception { AssociationRef assocRef = createAssociation(); NodeRef sourceRef = assocRef.getSourceRef(); NodeRef targetRef = assocRef.getTargetRef(); QName qname = assocRef.getTypeQName(); // get the source assocs List<AssociationRef> sourceAssocs = nodeService.getSourceAssocs(targetRef, qname); assertEquals("Incorrect number of source assocs", 1, sourceAssocs.size()); assertTrue("Source not found", sourceAssocs.contains(assocRef)); // Check that IDs are present for (AssociationRef sourceAssoc : sourceAssocs) { assertNotNull("Association does not have ID", sourceAssoc.getId()); } }
2. BaseNodeServiceTest#testGetTargetAssocs()
Project: community-edition
File: BaseNodeServiceTest.java
File: BaseNodeServiceTest.java
public void testGetTargetAssocs() throws Exception { AssociationRef assocRef = createAssociation(); NodeRef sourceRef = assocRef.getSourceRef(); NodeRef targetRef = assocRef.getTargetRef(); QName qname = assocRef.getTypeQName(); // get the target assocs List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(sourceRef, qname); assertEquals("Incorrect number of targets", 1, targetAssocs.size()); assertTrue("Target not found", targetAssocs.contains(assocRef)); // Check that IDs are present for (AssociationRef targetAssoc : targetAssocs) { assertNotNull("Association does not have ID", targetAssoc.getId()); } }
3. BaseNodeServiceTest#testDuplicateAssociationDetection()
Project: community-edition
File: BaseNodeServiceTest.java
File: BaseNodeServiceTest.java
public void testDuplicateAssociationDetection() throws Exception { AssociationRef assocRef = createAssociation(); NodeRef sourceRef = assocRef.getSourceRef(); NodeRef targetRef = assocRef.getTargetRef(); QName qname = assocRef.getTypeQName(); try { // attempt repeat nodeService.createAssociation(sourceRef, targetRef, qname); fail("Duplicate assocation not detected"); } catch (AssociationExistsException e) { } }
4. VersionServiceImpl#freezeAssociations()
Project: community-edition
File: VersionServiceImpl.java
File: VersionServiceImpl.java
/** * Freeze associations * * @param versionNodeRef the version node reference * @param associations the list of associations */ private void freezeAssociations(NodeRef versionNodeRef, List<AssociationRef> associations) { for (AssociationRef targetAssoc : associations) { HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>(); // Set the qname of the association properties.put(PROP_QNAME_ASSOC_TYPE_QNAME, targetAssoc.getTypeQName()); // Set the reference property to point to the child node properties.put(ContentModel.PROP_REFERENCE, targetAssoc.getTargetRef()); // Create child version reference this.dbNodeService.createNode(versionNodeRef, CHILD_QNAME_VERSIONED_ASSOCS, CHILD_QNAME_VERSIONED_ASSOCS, TYPE_QNAME_VERSIONED_ASSOC, properties); } }
5. Version2ServiceImpl#freezeAssociations()
Project: community-edition
File: Version2ServiceImpl.java
File: Version2ServiceImpl.java
/** * Freeze associations * * @param versionNodeRef the version node reference * @param associations the list of associations * * @since 3.3 (Ent) */ private void freezeAssociations(NodeRef versionNodeRef, List<AssociationRef> associations) { for (AssociationRef targetAssocRef : associations) { HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>(); QName sourceTypeRef = nodeService.getType(targetAssocRef.getSourceRef()); NodeRef targetRef = targetAssocRef.getTargetRef(); // Set the reference property to point to the target node properties.put(ContentModel.PROP_REFERENCE, targetRef); properties.put(Version2Model.PROP_QNAME_ASSOC_DBID, targetAssocRef.getId()); // Create peer version reference dbNodeService.createNode(versionNodeRef, Version2Model.CHILD_QNAME_VERSIONED_ASSOCS, targetAssocRef.getTypeQName(), sourceTypeRef, properties); } }
6. PeerAssociatedNodeFinder#processExcludedSet()
Project: community-edition
File: PeerAssociatedNodeFinder.java
File: PeerAssociatedNodeFinder.java
/** * @param thisNode NodeRef * @return Set<NodeRef> */ private Set<NodeRef> processExcludedSet(NodeRef thisNode) { Set<NodeRef> results = new HashSet<NodeRef>(89); NodeService nodeService = serviceRegistry.getNodeService(); // Find any peer nodes (filtering as necessary) List<AssociationRef> targets = nodeService.getTargetAssocs(thisNode, RegexQNamePattern.MATCH_ALL); boolean filterPeers = !peerAssociationTypes.isEmpty(); for (AssociationRef target : targets) { if (!filterPeers || !peerAssociationTypes.contains(target.getTypeQName())) { results.add(target.getTargetRef()); } } return results; }
7. ChannelHelper#mapSourceToEnvironment()
Project: community-edition
File: ChannelHelper.java
File: ChannelHelper.java
/** * Given a noderef from the editorial space (e.g. the doclib), this returns the corresponding noderef published to the specified channel. * @param source NodeRef * @param channelNode NodeRef * @param nodeService NodeService * @return NodeRef */ public static NodeRef mapSourceToEnvironment(NodeRef source, final NodeRef channelNode, final NodeService nodeService) { if (source == null || channelNode == null) { return null; } List<AssociationRef> sourceAssocs = nodeService.getSourceAssocs(source, ASSOC_SOURCE); Function<? super AssociationRef, Boolean> acceptor = new Filter<AssociationRef>() { public Boolean apply(AssociationRef assoc) { NodeRef publishedNode = assoc.getSourceRef(); NodeRef parent = nodeService.getPrimaryParent(publishedNode).getParentRef(); return channelNode.equals(parent); } }; AssociationRef assoc = CollectionUtils.findFirst(sourceAssocs, acceptor); return assoc == null ? null : assoc.getSourceRef(); }
8. ImapServiceImpl#getUnsubscribedFolders()
Project: community-edition
File: ImapServiceImpl.java
File: ImapServiceImpl.java
private Set<NodeRef> getUnsubscribedFolders(String userName) { Set<NodeRef> result = new HashSet<NodeRef>(); PersonService personService = serviceRegistry.getPersonService(); NodeRef userRef = personService.getPerson(userName); List<AssociationRef> unsubscribedFodlers = nodeService.getTargetAssocs(userRef, ImapModel.ASSOC_IMAP_UNSUBSCRIBED); for (AssociationRef asocRef : unsubscribedFodlers) { result.add(asocRef.getTargetRef()); } return result; }
9. NodeFormProcessor#getAssociationValues()
Project: community-edition
File: NodeFormProcessor.java
File: NodeFormProcessor.java
@Override protected Map<QName, Serializable> getAssociationValues(NodeRef item) { HashMap<QName, Serializable> assocs = new HashMap<QName, Serializable>(); List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(item, RegexQNamePattern.MATCH_ALL); List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(item); for (ChildAssociationRef childAssoc : childAssocs) { QName name = childAssoc.getTypeQName(); NodeRef target = childAssoc.getChildRef(); addAssocToMap(name, target, assocs); } for (AssociationRef associationRef : targetAssocs) { QName name = associationRef.getTypeQName(); NodeRef target = associationRef.getTargetRef(); if (nodeService.exists(target) && (permissionService.hasPermission(target, PermissionService.READ) == AccessStatus.ALLOWED)) { addAssocToMap(name, target, assocs); } } return assocs; }
10. ContentModelFormProcessor#updateAssociations()
Project: community-edition
File: ContentModelFormProcessor.java
File: ContentModelFormProcessor.java
@Override protected void updateAssociations(NodeService nodeService) { List<AssociationRef> existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName); for (AssociationRef assoc : existingAssocs) { if (assoc.getTargetRef().equals(targetNodeRef)) { if (logger.isWarnEnabled()) { logger.warn("Attempt to add existing association prevented. " + assoc); } return; } } nodeService.createAssociation(sourceNodeRef, targetNodeRef, assocQName); }
11. NodeBrowserPost#getSourceAssocs()
Project: community-edition
File: NodeBrowserPost.java
File: NodeBrowserPost.java
/** * Gets the current source associations * * @return associations */ public List<PeerAssociation> getSourceAssocs(NodeRef nodeRef) { List<AssociationRef> refs = null; try { refs = getNodeService().getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL); } catch (UnsupportedOperationException err) { 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; }
12. NodeBrowserPost#getAssocs()
Project: community-edition
File: NodeBrowserPost.java
File: NodeBrowserPost.java
/** * 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) { 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; }
13. BaseNodeServiceTest#testCreateAndRemoveAssociation()
Project: community-edition
File: BaseNodeServiceTest.java
File: BaseNodeServiceTest.java
public void testCreateAndRemoveAssociation() throws Exception { AssociationRef assocRef = createAssociation(); NodeRef sourceRef = assocRef.getSourceRef(); // create another Map<QName, Serializable> properties = new HashMap<QName, Serializable>(5); fillProperties(TYPE_QNAME_TEST_CONTENT, properties); fillProperties(ASPECT_QNAME_TEST_TITLED, properties); ChildAssociationRef childAssocRef = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName(null, "N3"), TYPE_QNAME_TEST_CONTENT, properties); NodeRef anotherTargetRef = childAssocRef.getChildRef(); AssociationRef anotherAssocRef = nodeService.createAssociation(sourceRef, anotherTargetRef, ASSOC_TYPE_QNAME_TEST_NEXT); Long anotherAssocId = anotherAssocRef.getId(); assertNotNull("Created association does not have an ID", anotherAssocId); AssociationRef anotherAssocRefCheck = nodeService.getAssoc(anotherAssocId); assertEquals("Assoc fetched by ID is incorrect.", anotherAssocRef, anotherAssocRefCheck); // remove assocs List<AssociationRef> assocs = nodeService.getTargetAssocs(sourceRef, ASSOC_TYPE_QNAME_TEST_NEXT); for (AssociationRef assoc : assocs) { nodeService.removeAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName()); } }
14. BaseNodeServiceTest#testTargetAssoc_Ordering()
Project: community-edition
File: BaseNodeServiceTest.java
File: BaseNodeServiceTest.java
public void testTargetAssoc_Ordering() throws Exception { AssociationRef assocRef = createAssociation(); NodeRef sourceRef = assocRef.getSourceRef(); QName qname = assocRef.getTypeQName(); for (int i = 0; i < 99; i++) { assocRef = createAssociation(sourceRef); } // Now get the associations and ensure that they are in order of ID // because they should have been inserted in natural order List<AssociationRef> assocs = nodeService.getTargetAssocs(sourceRef, ASSOC_TYPE_QNAME_TEST_NEXT); Long lastId = 0L; for (AssociationRef associationRef : assocs) { Long id = associationRef.getId(); assertNotNull("Null association ID: " + associationRef, id); assertTrue("Results should be in ID order", id > lastId); lastId = id; } // Now invert the association list Comparator<AssociationRef> descendingId = new Comparator<AssociationRef>() { @Override public int compare(AssociationRef assoc1, AssociationRef assoc2) { return (assoc1.getId().compareTo(assoc2.getId()) * -1); } }; Collections.sort(assocs, descendingId); // Build the target node refs List<NodeRef> targetNodeRefs = new ArrayList<NodeRef>(100); for (AssociationRef associationRef : assocs) { targetNodeRefs.add(associationRef.getTargetRef()); } for (int i = targetNodeRefs.size(); i > 0; i--) { // Reset them nodeService.setAssociations(sourceRef, ASSOC_TYPE_QNAME_TEST_NEXT, targetNodeRefs); // Recheck the order assocs = nodeService.getTargetAssocs(sourceRef, ASSOC_TYPE_QNAME_TEST_NEXT); assertEquals("Incorrect number of results", i, assocs.size()); lastId = Long.MAX_VALUE; for (AssociationRef associationRef : assocs) { Long id = associationRef.getId(); assertNotNull("Null association ID: " + associationRef, id); assertTrue("Results should be in inverse ID order", id < lastId); lastId = id; } // Remove one of the targets targetNodeRefs.remove(0); } setComplete(); endTransaction(); }
15. CopyServiceImplTest#testRelativeLinks()
Project: community-edition
File: CopyServiceImplTest.java
File: CopyServiceImplTest.java
/** * Test that realtive links between nodes are restored once the copy is completed */ public void testRelativeLinks() { QName nodeOneAssocName = QName.createQName("{test}nodeOne"); QName nodeTwoAssocName = QName.createQName("{test}nodeTwo"); QName nodeThreeAssocName = QName.createQName("{test}nodeThree"); QName nodeFourAssocName = QName.createQName("{test}nodeFour"); NodeRef nodeNotCopied = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, nodeOneAssocName, TEST_TYPE_QNAME).getChildRef(); NodeRef nodeOne = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, nodeOneAssocName, TEST_TYPE_QNAME).getChildRef(); NodeRef nodeTwo = nodeService.createNode(nodeOne, TEST_CHILD_ASSOC_TYPE_QNAME, nodeTwoAssocName, TEST_TYPE_QNAME).getChildRef(); NodeRef nodeThree = nodeService.createNode(nodeTwo, TEST_CHILD_ASSOC_TYPE_QNAME, nodeThreeAssocName, TEST_TYPE_QNAME).getChildRef(); NodeRef nodeFour = nodeService.createNode(nodeOne, TEST_CHILD_ASSOC_TYPE_QNAME, nodeFourAssocName, TEST_TYPE_QNAME).getChildRef(); nodeService.addChild(nodeFour, nodeThree, TEST_CHILD_ASSOC_TYPE_QNAME, TEST_CHILD_ASSOC_QNAME); nodeService.createAssociation(nodeTwo, nodeThree, TEST_ASSOC_TYPE_QNAME); nodeService.createAssociation(nodeTwo, nodeNotCopied, TEST_ASSOC_TYPE_QNAME); // Make node one actionable with a rule to copy nodes into node two Map<String, Serializable> params = new HashMap<String, Serializable>(1); params.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, nodeTwo); Rule rule = new Rule(); rule.setRuleType(RuleType.INBOUND); Action action = actionService.createAction(CopyActionExecuter.NAME, params); ActionCondition condition = actionService.createActionCondition(NoConditionEvaluator.NAME); action.addActionCondition(condition); rule.setAction(action); ruleService.saveRule(nodeOne, rule); // Do a deep copy NodeRef nodeOneCopy = copyService.copy(nodeOne, rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}copiedNodeOne"), true); NodeRef nodeTwoCopy = null; NodeRef nodeThreeCopy = null; NodeRef nodeFourCopy = null; //System.out.println( // NodeStoreInspector.dumpNodeStore(nodeService, storeRef)); List<ChildAssociationRef> nodeOneCopyChildren = nodeService.getChildAssocs(nodeOneCopy); assertNotNull(nodeOneCopyChildren); assertEquals(3, nodeOneCopyChildren.size()); for (ChildAssociationRef nodeOneCopyChild : nodeOneCopyChildren) { if (nodeOneCopyChild.getQName().equals(nodeTwoAssocName) == true) { nodeTwoCopy = nodeOneCopyChild.getChildRef(); List<ChildAssociationRef> nodeTwoCopyChildren = nodeService.getChildAssocs(nodeTwoCopy); assertNotNull(nodeTwoCopyChildren); assertEquals(1, nodeTwoCopyChildren.size()); for (ChildAssociationRef nodeTwoCopyChild : nodeTwoCopyChildren) { if (nodeTwoCopyChild.getQName().equals(nodeThreeAssocName) == true) { nodeThreeCopy = nodeTwoCopyChild.getChildRef(); } } } else if (nodeOneCopyChild.getQName().equals(nodeFourAssocName) == true) { nodeFourCopy = nodeOneCopyChild.getChildRef(); } } assertNotNull(nodeTwoCopy); assertNotNull(nodeThreeCopy); assertNotNull(nodeFourCopy); // Check the non primary child assoc List<ChildAssociationRef> children = nodeService.getChildAssocs(nodeFourCopy, RegexQNamePattern.MATCH_ALL, TEST_CHILD_ASSOC_QNAME); assertNotNull(children); assertEquals(1, children.size()); ChildAssociationRef child = children.get(0); assertEquals(child.getChildRef(), nodeThree); // Check the target assoc List<AssociationRef> assocs = nodeService.getTargetAssocs(nodeTwoCopy, TEST_ASSOC_TYPE_QNAME); assertNotNull(assocs); assertEquals(2, assocs.size()); AssociationRef assoc0 = assocs.get(0); assertTrue(assoc0.getTargetRef().equals(nodeThreeCopy) || assoc0.getTargetRef().equals(nodeNotCopied)); AssociationRef assoc1 = assocs.get(1); assertTrue(assoc1.getTargetRef().equals(nodeThreeCopy) || assoc1.getTargetRef().equals(nodeNotCopied)); // Check that the rule parameter values have been made relative List<Rule> rules = ruleService.getRules(nodeOneCopy); assertNotNull(rules); assertEquals(1, rules.size()); Rule copiedRule = rules.get(0); assertNotNull(copiedRule); Action ruleAction = copiedRule.getAction(); assertNotNull(ruleAction); NodeRef value = (NodeRef) ruleAction.getParameterValue(MoveActionExecuter.PARAM_DESTINATION_FOLDER); assertNotNull(value); assertEquals(nodeTwoCopy, value); }
16. RepoSecondaryManifestProcessorImpl#processPeerAssociations()
Project: community-edition
File: RepoSecondaryManifestProcessorImpl.java
File: RepoSecondaryManifestProcessorImpl.java
/** * Process the peer associations * * @param requiredAssocs List<AssociationRef> * @param currentAssocs List<AssociationRef> * @param nodeRef NodeRef * @param isSource boolean */ private void processPeerAssociations(List<AssociationRef> requiredAssocs, List<AssociationRef> currentAssocs, NodeRef nodeRef, boolean isSource) { if (requiredAssocs == null) { requiredAssocs = new ArrayList<AssociationRef>(); } if (currentAssocs == null) { currentAssocs = new ArrayList<AssociationRef>(); } List<AssociationRefKey> keysRequired = new ArrayList<AssociationRefKey>(); List<AssociationRefKey> keysCurrent = new ArrayList<AssociationRefKey>(); /** * Which assocs do we need to add ? * * Need to compare on sourceNodeRef, targetNodeRef and qname but ignore, irrelevant id property * which is why we need to introduce AssociationRefKey */ for (AssociationRef ref : requiredAssocs) { keysRequired.add(new AssociationRefKey(ref)); } for (AssociationRef ref : currentAssocs) { keysCurrent.add(new AssociationRefKey(ref)); } /** * Which assocs do we need to add? */ for (AssociationRefKey ref : keysRequired) { if (!keysCurrent.contains(ref)) { //We don't have an existing association with this required node NodeRef otherNode = isSource ? ref.targetRef : ref.sourceRef; if (nodeService.exists(otherNode)) { //the other node exists in this repo NodeRef parent = isSource ? nodeRef : ref.sourceRef; NodeRef child = isSource ? ref.targetRef : nodeRef; if (log.isDebugEnabled()) { log.debug("need to add peer assoc from:" + parent + ", to:" + child + ", qname:" + ref.assocTypeQName); } nodeService.createAssociation(parent, child, ref.assocTypeQName); } } } // { for (AssociationRefKey ref : keysCurrent) { if (!keysRequired.contains(ref)) { if (log.isDebugEnabled()) { log.debug("need to remove peer assoc from:" + ref.sourceRef + ", to:" + ref.targetRef + ", qname:" + ref.assocTypeQName); } nodeService.removeAssociation(ref.sourceRef, ref.targetRef, ref.assocTypeQName); } } // } }
17. ScheduledPersistedActionServiceImpl#findActionAssociationFromSchedule()
Project: community-edition
File: ScheduledPersistedActionServiceImpl.java
File: ScheduledPersistedActionServiceImpl.java
private AssociationRef findActionAssociationFromSchedule(NodeRef schedule) { List<AssociationRef> assocs = nodeService.getTargetAssocs(schedule, ActionModel.ASSOC_SCHEDULED_ACTION); AssociationRef actionAssoc = null; for (AssociationRef assoc : assocs) { actionAssoc = assoc; } return actionAssoc; }
18. ScheduledPersistedActionServiceImpl#getSchedule()
Project: community-edition
File: ScheduledPersistedActionServiceImpl.java
File: ScheduledPersistedActionServiceImpl.java
/** * Returns the schedule for the specified action, or null if it isn't * currently scheduled. */ public ScheduledPersistedAction getSchedule(Action persistedAction) { NodeRef nodeRef = persistedAction.getNodeRef(); if (nodeRef == null) { // action is not persistent return null; } // locate associated schedule for action List<AssociationRef> assocs = nodeService.getSourceAssocs(nodeRef, ActionModel.ASSOC_SCHEDULED_ACTION); AssociationRef scheduledAssoc = null; for (AssociationRef assoc : assocs) { scheduledAssoc = assoc; } if (scheduledAssoc == null) { // there is no associated schedule return null; } // load the scheduled action return loadPersistentSchedule(scheduledAssoc.getSourceRef()); }
19. AdminNodeBrowseBean#selectToNode()
Project: community-edition
File: AdminNodeBrowseBean.java
File: AdminNodeBrowseBean.java
/** * Action to select association To node * * @return next action */ public String selectToNode() { AssociationRef assocRef = (AssociationRef) getAssocs().getRowData(); NodeRef targetRef = assocRef.getTargetRef(); setNodeRef(targetRef); return "success"; }
20. VirtualNodeServiceExtensionTest#testGetTargetAssocs_download()
Project: community-edition
File: VirtualNodeServiceExtensionTest.java
File: VirtualNodeServiceExtensionTest.java
@Test public void testGetTargetAssocs_download() throws Exception { NodeRef node2 = nodeService.getChildByName(virtualFolder1NodeRef, ContentModel.ASSOC_CONTAINS, "Node2"); List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(node2, DownloadModel.ASSOC_REQUESTED_NODES); assertEquals(0, targetAssocs.size()); // one virtual noderef NodeRef createDownloadNode = createDownloadNode(); nodeService.createAssociation(createDownloadNode, node2, DownloadModel.ASSOC_REQUESTED_NODES); targetAssocs = nodeService.getTargetAssocs(createDownloadNode, ContentModel.ASSOC_CONTAINS); assertEquals(0, targetAssocs.size()); targetAssocs = nodeService.getTargetAssocs(createDownloadNode, DownloadModel.ASSOC_REQUESTED_NODES); assertEquals(1, targetAssocs.size()); // 2 virtual node ref ...associations have to be created again since // they are removed after they are obtained in // order to cleanup temp node refs from repository. NodeRef node2_1 = nodeService.getChildByName(node2, ContentModel.ASSOC_CONTAINS, "Node2_1"); nodeService.createAssociation(createDownloadNode, node2, DownloadModel.ASSOC_REQUESTED_NODES); nodeService.createAssociation(createDownloadNode, node2_1, DownloadModel.ASSOC_REQUESTED_NODES); targetAssocs = nodeService.getTargetAssocs(createDownloadNode, ContentModel.ASSOC_CONTAINS); assertEquals(0, targetAssocs.size()); for (int i = 0; i < 2; i++) { targetAssocs = nodeService.getTargetAssocs(createDownloadNode, DownloadModel.ASSOC_REQUESTED_NODES); assertEquals("Try # " + (i + 1), 2, targetAssocs.size()); } List<NodeRef> targets = new LinkedList<>(); for (AssociationRef assocs : targetAssocs) { targets.add(assocs.getTargetRef()); } assertTrue(targets.contains(node2)); assertTrue(targets.contains(node2_1)); NodeRefExpression downloadAsocsFolderExpr = virtualizationConfigTestBootstrap.getDownloadAssocaiationsFolder(); NodeRef downloadAssocsFolder = downloadAsocsFolderExpr.resolve(); NodeRef tempDownloadSourceAssocs = nodeService.getChildByName(downloadAssocsFolder, ContentModel.ASSOC_CONTAINS, createDownloadNode.getId()); assertNotNull(tempDownloadSourceAssocs); downloadStorage.delete(createDownloadNode); assertFalse("Association information was not removed when removing the source.", nodeService.exists(tempDownloadSourceAssocs)); }
21. RepoTransferReceiverImplTest#associatePeers()
Project: community-edition
File: RepoTransferReceiverImplTest.java
File: RepoTransferReceiverImplTest.java
private void associatePeers(TransferManifestNormalNode source, TransferManifestNormalNode target) { List<AssociationRef> currentReferencedPeers = source.getTargetAssocs(); if (currentReferencedPeers == null) { currentReferencedPeers = new ArrayList<AssociationRef>(); source.setTargetAssocs(currentReferencedPeers); } List<AssociationRef> currentRefereePeers = target.getSourceAssocs(); if (currentRefereePeers == null) { currentRefereePeers = new ArrayList<AssociationRef>(); target.setSourceAssocs(currentRefereePeers); } Set<QName> aspects = source.getAspects(); if (aspects == null) { aspects = new HashSet<QName>(); source.setAspects(aspects); } aspects.add(ContentModel.ASPECT_ATTACHABLE); AssociationRef newAssoc = new AssociationRef(null, source.getNodeRef(), ContentModel.ASSOC_ATTACHMENTS, target.getNodeRef()); currentRefereePeers.add(newAssoc); currentReferencedPeers.add(newAssoc); }
22. MultiTServiceImplTest#setUp()
Project: community-edition
File: MultiTServiceImplTest.java
File: MultiTServiceImplTest.java
@Before public void setUp() throws Exception { multiTServiceImpl = ctx.getBean("tenantService", MultiTServiceImpl.class); tenantAdminService = ctx.getBean("tenantAdminService", TenantAdminService.class); personService = ctx.getBean("PersonService", PersonService.class); tenantService = ctx.getBean("tenantService", TenantService.class); authenticationService = ctx.getBean("AuthenticationService", MutableAuthenticationService.class); transactionService = ctx.getBean("TransactionService", TransactionService.class); nodeService = ctx.getBean("NodeService", NodeService.class); searchService = ctx.getBean("SearchService", SearchService.class); namespaceService = ctx.getBean("NamespaceService", NamespaceService.class); DOMAIN = GUID.generate(); USER1 = GUID.generate(); USER2 = GUID.generate(); USER3 = GUID.generate(); USER2_WITH_DOMAIN = USER2 + TenantService.SEPARATOR + DOMAIN; STRING = GUID.generate(); TENANT_STRING = addDomainToId(STRING, DOMAIN); STRING_WITH_EXISTENT_DOMAIN = TenantService.SEPARATOR + DOMAIN + TenantService.SEPARATOR; STRING_WITH_NONEXITENT_DOMAIN = TenantService.SEPARATOR + STRING + TenantService.SEPARATOR; TENANT_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, addDomainToId("SpacesStore", DOMAIN)); TENANT_NODE_REF = new NodeRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN), ID); TENANT_STORE_REF = new StoreRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN)); TENANT_QNAME = QName.createQName(addDomainToId(NAMESPACE_URI, DOMAIN), LOCAL_NAME); tenantAssocRef = new AssociationRef(TENANT_NODE_REF, QNAME, TENANT_NODE_REF); childAssocRef = new ChildAssociationRef(QNAME, NODE_REF, QNAME, NODE_REF); tenantChildAssocRef = new ChildAssociationRef(QNAME, TENANT_NODE_REF, QNAME, TENANT_NODE_REF); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); mtEnabled = AuthenticationUtil.isMtEnabled(); AuthenticationUtil.setMtEnabled(false); }
23. NodeServiceTest#testGetAssocById()
Project: community-edition
File: NodeServiceTest.java
File: NodeServiceTest.java
@Test public void testGetAssocById() { // Get a node association that doesn't exist AssociationRef assocRef = nodeService.getAssoc(Long.MAX_VALUE); assertNull("Should get null for missing ID of association. ", assocRef); }
24. BaseNodeServiceTest#testGetTargetAssocsByPropertyValue()
Project: community-edition
File: BaseNodeServiceTest.java
File: BaseNodeServiceTest.java
/** * Tests get target associations by property value.</p> * See <b>MNT-14504</b> for more details. * * @throws Exception */ public void testGetTargetAssocsByPropertyValue() throws Exception { // Create test data. AssociationRef assocRef = createAssociation(); NodeRef sourceRef = assocRef.getSourceRef(); createAssociation(sourceRef); NodeRef targetRef = assocRef.getTargetRef(); QName qname = assocRef.getTypeQName(); /* Positive tests of various types that should be accepted by the query. */ List<AssociationRef> targetAssocs = nodeService.getTargetAssocsByPropertyValue(sourceRef, qname, null, null); assertEquals("Incorrect number of targets", 2, targetAssocs.size()); Map<QName, Serializable> checkProperties = new HashMap<QName, Serializable>(); checkProperties.put(ContentModel.PROP_ENABLED, Boolean.TRUE); checkProperties.put(ContentModel.PROP_COUNTER, 100); checkProperties.put(ContentModel.PROP_LATITUDE, new Double(51.521)); checkProperties.put(ContentModel.PROP_SUBJECT, "Hello World"); for (QName propertyQName : checkProperties.keySet()) { Serializable propertyValue = checkProperties.get(propertyQName); nodeService.setProperty(targetRef, propertyQName, propertyValue); targetAssocs = nodeService.getTargetAssocsByPropertyValue(sourceRef, qname, propertyQName, propertyValue); assertEquals("Incorrect number of targets", 1, targetAssocs.size()); assertTrue("Target not found", targetAssocs.contains(assocRef)); AssociationRef targetAssoc = targetAssocs.get(0); // Check that ID is present assertNotNull("Association does not have ID", targetAssoc.getId()); NodeRef targetRefFound = targetAssoc.getTargetRef(); assertEquals("Incorrect value found", propertyValue, this.nodeService.getProperty(targetRefFound, propertyQName)); } // Invalid to search on sys:node-dbid try { targetAssocs = nodeService.getTargetAssocsByPropertyValue(sourceRef, qname, ContentModel.PROP_NODE_DBID, "Fail"); fail("sys:node-dbid not rejected"); } catch (IllegalArgumentException ie) { } // Invalid to search on type MLText. try { Serializable title = (String) nodeService.getProperty(sourceRef, ContentModel.PROP_TITLE); targetAssocs = nodeService.getTargetAssocsByPropertyValue(sourceRef, qname, ContentModel.PROP_NAME, title); fail("MLText type not rejected"); } catch (IllegalArgumentException ie) { } }
25. BaseNodeServiceTest#createAssociation()
Project: community-edition
File: BaseNodeServiceTest.java
File: BaseNodeServiceTest.java
/** * Creates an association between a given source and a new target */ private AssociationRef createAssociation(NodeRef sourceRef) throws Exception { Map<QName, Serializable> properties = new HashMap<QName, Serializable>(5); fillProperties(TYPE_QNAME_TEST_CONTENT, properties); fillProperties(ASPECT_QNAME_TEST_TITLED, properties); if (sourceRef == null) { ChildAssociationRef childAssocRef = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName(null, "N1"), TYPE_QNAME_TEST_CONTENT, properties); sourceRef = childAssocRef.getChildRef(); } ChildAssociationRef childAssocRef = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName(null, "N2"), TYPE_QNAME_TEST_CONTENT, properties); NodeRef targetRef = childAssocRef.getChildRef(); AssociationRef assocRef = nodeService.createAssociation(sourceRef, targetRef, ASSOC_TYPE_QNAME_TEST_NEXT); // done return assocRef; }
26. BaseNodeServiceTest#testRemoveChildByRef()
Project: community-edition
File: BaseNodeServiceTest.java
File: BaseNodeServiceTest.java
public void testRemoveChildByRef() throws Exception { NodeRef parentRef = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName("parent_child"), ContentModel.TYPE_CONTAINER).getChildRef(); ChildAssociationRef pathARef = nodeService.createNode(parentRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName("pathA"), ContentModel.TYPE_CONTAINER); NodeRef childARef = pathARef.getChildRef(); AssociationRef pathDRef = nodeService.createAssociation(parentRef, childARef, ASSOC_TYPE_QNAME_TEST_NEXT); // remove the child - this must cascade nodeService.removeChild(parentRef, childARef); assertFalse("Primary child not deleted", nodeService.exists(childARef)); assertEquals("Child assocs not removed", 0, nodeService.getChildAssocs(parentRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, new RegexQNamePattern(".*", "path*")).size()); assertEquals("Node assoc not removed", 0, nodeService.getTargetAssocs(parentRef, RegexQNamePattern.MATCH_ALL).size()); }
27. CopyServiceImplTest#checkCopiedNode()
Project: community-edition
File: CopyServiceImplTest.java
File: CopyServiceImplTest.java
/** * Check that the copied node contains the state we are expecting * * @param sourceNodeRef the source node reference * @param destinationNodeRef the destination node reference */ private void checkCopiedNode(NodeRef sourceNodeRef, NodeRef destinationNodeRef, boolean newCopy, boolean sameStore, boolean copyChildren) { if (newCopy == true) { if (sameStore == true) { // Check that the copy aspect has been applied to the copy boolean hasCopyAspect = nodeService.hasAspect(destinationNodeRef, ContentModel.ASPECT_COPIEDFROM); assertTrue("Missing aspect: " + ContentModel.ASPECT_COPIEDFROM, hasCopyAspect); List<AssociationRef> assocs = nodeService.getTargetAssocs(destinationNodeRef, ContentModel.ASSOC_ORIGINAL); assertEquals("Expectd exactly one reference back to original", 1, assocs.size()); NodeRef checkSourceNodeRef = assocs.get(0).getTargetRef(); assertEquals("Copy refers to incorrect original source", sourceNodeRef, checkSourceNodeRef); } else { // Check that destiantion has the same id as the source assertEquals(sourceNodeRef.getId(), destinationNodeRef.getId()); } } boolean hasTestAspect = nodeService.hasAspect(destinationNodeRef, TEST_ASPECT_QNAME); assertTrue(hasTestAspect); // Check that all the correct properties have been copied Map<QName, Serializable> destinationProperties = nodeService.getProperties(destinationNodeRef); assertNotNull(destinationProperties); String value1 = (String) destinationProperties.get(PROP1_QNAME_MANDATORY); assertNotNull(value1); assertEquals(TEST_VALUE_1, value1); String value2 = (String) destinationProperties.get(PROP2_QNAME_OPTIONAL); assertNotNull(value2); assertEquals(TEST_VALUE_2, value2); String value3 = (String) destinationProperties.get(PROP3_QNAME_MANDATORY); assertNotNull(value3); assertEquals(TEST_VALUE_1, value3); String value4 = (String) destinationProperties.get(PROP4_QNAME_OPTIONAL); assertNotNull(value4); assertEquals(TEST_VALUE_2, value4); // Check all the target associations have been copied List<AssociationRef> destinationTargets = nodeService.getTargetAssocs(destinationNodeRef, TEST_ASSOC_TYPE_QNAME); assertNotNull(destinationTargets); assertEquals(1, destinationTargets.size()); AssociationRef nodeAssocRef = destinationTargets.get(0); assertNotNull(nodeAssocRef); assertEquals(targetNodeRef, nodeAssocRef.getTargetRef()); // Check all the child associations have been copied List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(destinationNodeRef); assertNotNull(childAssocRefs); int expectedSize = copyChildren ? 2 : 0; if (nodeService.hasAspect(destinationNodeRef, RuleModel.ASPECT_RULES) == true) { expectedSize = expectedSize + 1; } assertEquals(expectedSize, childAssocRefs.size()); for (ChildAssociationRef ref : childAssocRefs) { if (ref.getQName().equals(TEST_CHILD_ASSOC_QNAME2) == true) { // Since this child is non-primary in the source it will always be non-primary in the destination assertFalse(ref.isPrimary()); assertEquals(nonPrimaryChildNodeRef, ref.getChildRef()); } else { if (copyChildren == false) { if (ref.getTypeQName().equals(RuleModel.ASSOC_RULE_FOLDER) == true) { assertTrue(ref.isPrimary()); assertTrue(childNodeRef.equals(ref.getChildRef()) == false); } else { assertFalse(ref.isPrimary()); assertEquals(childNodeRef, ref.getChildRef()); } } else { assertTrue(ref.isPrimary()); assertTrue(childNodeRef.equals(ref.getChildRef()) == false); // TODO need to check that the copied child has all the correct details .. } } } }
28. DownloadRequest#getRequetedNodeRefs()
Project: community-edition
File: DownloadRequest.java
File: DownloadRequest.java
public NodeRef[] getRequetedNodeRefs() { List<NodeRef> requestedNodeRefs = new ArrayList<NodeRef>(requestedNodes.size()); for (AssociationRef requestedNode : requestedNodes) { requestedNodeRefs.add(requestedNode.getTargetRef()); } return requestedNodeRefs.toArray(new NodeRef[requestedNodeRefs.size()]); }
29. ChannelHelper#createMapping()
Project: community-edition
File: ChannelHelper.java
File: ChannelHelper.java
public AssociationRef createMapping(NodeRef source, NodeRef publishedNode) { AssociationRef assoc = nodeService.createAssociation(publishedNode, source, ASSOC_SOURCE); return assoc; }
30. DbNodeServiceImpl#removeAssociation()
Project: community-edition
File: DbNodeServiceImpl.java
File: DbNodeServiceImpl.java
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class) public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) throws InvalidNodeRefException { // The node(s) involved may not be pending deletion checkPendingDelete(sourceRef); checkPendingDelete(targetRef); Pair<Long, NodeRef> sourceNodePair = getNodePairNotNull(sourceRef); Long sourceNodeId = sourceNodePair.getFirst(); Pair<Long, NodeRef> targetNodePair = getNodePairNotNull(targetRef); Long targetNodeId = targetNodePair.getFirst(); AssociationRef assocRef = new AssociationRef(sourceRef, assocTypeQName, targetRef); // Invoke policy behaviours invokeBeforeDeleteAssociation(assocRef); // delete it int assocsDeleted = nodeDAO.removeNodeAssoc(sourceNodeId, targetNodeId, assocTypeQName); if (assocsDeleted > 0) { // Invoke policy behaviours invokeOnDeleteAssociation(assocRef); } }
31. DbNodeServiceImpl#createAssociation()
Project: community-edition
File: DbNodeServiceImpl.java
File: DbNodeServiceImpl.java
@Override @Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class) public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) throws InvalidNodeRefException, AssociationExistsException { // The node(s) involved may not be pending deletion checkPendingDelete(sourceRef); checkPendingDelete(targetRef); Pair<Long, NodeRef> sourceNodePair = getNodePairNotNull(sourceRef); long sourceNodeId = sourceNodePair.getFirst(); Pair<Long, NodeRef> targetNodePair = getNodePairNotNull(targetRef); long targetNodeId = targetNodePair.getFirst(); // we are sure that the association doesn't exist - make it Long assocId = nodeDAO.newNodeAssoc(sourceNodeId, targetNodeId, assocTypeQName, -1); AssociationRef assocRef = new AssociationRef(assocId, sourceRef, assocTypeQName, targetRef); // Invoke policy behaviours invokeOnCreateAssociation(assocRef); // Add missing aspects addAspectsAndPropertiesAssoc(sourceNodePair, assocTypeQName, null, null, null, null, false); return assocRef; }
32. ScriptNode#createAssociation()
Project: community-edition
File: ScriptNode.java
File: ScriptNode.java
/** * Create an association between this node and the specified target node. * * Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call {@link #save()} first. * * @param target Destination node for the association * @param assocType Association type qname (short form or fully qualified) */ public Association createAssociation(ScriptNode target, String assocType) { ParameterCheck.mandatory("Target", target); ParameterCheck.mandatoryString("Association Type Name", assocType); AssociationRef assocRef = this.nodeService.createAssociation(this.nodeRef, target.nodeRef, createQName(assocType)); reset(); return new Association(this.services, assocRef); }
33. ContentModelFormProcessor#updateAssociations()
Project: community-edition
File: ContentModelFormProcessor.java
File: ContentModelFormProcessor.java
@Override protected void updateAssociations(NodeService nodeService) { List<AssociationRef> existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName); boolean assocDoesNotExist = true; for (AssociationRef assoc : existingAssocs) { if (assoc.getTargetRef().equals(targetNodeRef)) { assocDoesNotExist = false; break; } } if (assocDoesNotExist) { if (logger.isWarnEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Attempt to remove non-existent association prevented. ").append(sourceNodeRef).append("|").append(targetNodeRef).append(assocQName); logger.warn(msg.toString()); } return; } nodeService.removeAssociation(sourceNodeRef, targetNodeRef, assocQName); }
34. NodeAssocEntity#getAssociationRef()
Project: community-edition
File: NodeAssocEntity.java
File: NodeAssocEntity.java
/** * Helper method to fetch the association reference */ public AssociationRef getAssociationRef(QNameDAO qnameDAO) { QName assocTypeQName = qnameDAO.getQName(typeQNameId).getSecond(); AssociationRef assocRef = new AssociationRef(id, sourceNode.getNodeRef(), assocTypeQName, targetNode.getNodeRef()); return assocRef; }
35. ScheduledPersistedActionServiceImpl#loadPersistentSchedule()
Project: community-edition
File: ScheduledPersistedActionServiceImpl.java
File: ScheduledPersistedActionServiceImpl.java
protected ScheduledPersistedActionImpl loadPersistentSchedule(NodeRef schedule) { if (!nodeService.exists(schedule)) return null; // create action Action action = null; AssociationRef actionAssoc = findActionAssociationFromSchedule(schedule); if (actionAssoc != null) { action = runtimeActionService.createAction(actionAssoc.getTargetRef()); } // create schedule ScheduledPersistedActionImpl scheduleImpl = new ScheduledPersistedActionImpl(action); scheduleImpl.setPersistedAtNodeRef(schedule); scheduleImpl.setScheduleLastExecutedAt((Date) nodeService.getProperty(schedule, ActionModel.PROP_LAST_EXECUTED_AT)); scheduleImpl.setScheduleStart((Date) nodeService.getProperty(schedule, ActionModel.PROP_START_DATE)); scheduleImpl.setScheduleIntervalCount((Integer) nodeService.getProperty(schedule, ActionModel.PROP_INTERVAL_COUNT)); String period = (String) nodeService.getProperty(schedule, ActionModel.PROP_INTERVAL_PERIOD); if (period != null) { scheduleImpl.setScheduleIntervalPeriod(IntervalPeriod.valueOf(period)); } return scheduleImpl; }
36. ScheduledPersistedActionServiceImpl#updatePersistentSchedule()
Project: community-edition
File: ScheduledPersistedActionServiceImpl.java
File: ScheduledPersistedActionServiceImpl.java
private void updatePersistentSchedule(ScheduledPersistedActionImpl schedule) { NodeRef nodeRef = schedule.getPersistedAtNodeRef(); if (nodeRef == null) throw new IllegalStateException("Must be persisted first"); // update schedule properties nodeService.setProperty(nodeRef, ActionModel.PROP_START_DATE, schedule.getScheduleStart()); nodeService.setProperty(nodeRef, ActionModel.PROP_INTERVAL_COUNT, schedule.getScheduleIntervalCount()); IntervalPeriod period = schedule.getScheduleIntervalPeriod(); nodeService.setProperty(nodeRef, ActionModel.PROP_INTERVAL_PERIOD, period == null ? null : period.name()); // We don't save the last executed at date here, that only gets changed // from within the execution loop // update scheduled action (represented as an association) // NOTE: can only associate to a single action from a schedule (as specified by the action model) // update association to reflect updated schedule AssociationRef actionAssoc = findActionAssociationFromSchedule(nodeRef); NodeRef actionNodeRef = schedule.getActionNodeRef(); try { behaviourFilter.disableBehaviour(ActionModel.TYPE_ACTION_SCHEDULE); if (actionNodeRef == null) { if (actionAssoc != null) { // remove associated action nodeService.removeAssociation(actionAssoc.getSourceRef(), actionAssoc.getTargetRef(), actionAssoc.getTypeQName()); } } else { if (actionAssoc == null) { // create associated action nodeService.createAssociation(nodeRef, actionNodeRef, ActionModel.ASSOC_SCHEDULED_ACTION); } else if (!actionAssoc.getTargetRef().equals(actionNodeRef)) { // associated action has changed... first remove existing association nodeService.removeAssociation(actionAssoc.getSourceRef(), actionAssoc.getTargetRef(), actionAssoc.getTypeQName()); nodeService.createAssociation(nodeRef, actionNodeRef, ActionModel.ASSOC_SCHEDULED_ACTION); } } } finally { behaviourFilter.enableBehaviour(ActionModel.TYPE_ACTION_SCHEDULE); } }
37. CMISConnector#getRelationships()
Project: community-edition
File: CMISConnector.java
File: CMISConnector.java
public List<ObjectData> getRelationships(NodeRef nodeRef, IncludeRelationships includeRelationships) /*, CmisVersion cmisVersion*/ { List<ObjectData> result = new ArrayList<ObjectData>(); if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL)) { // relationships from and to versions are not preserved return result; } // get relationships List<AssociationRef> assocs = new ArrayList<AssociationRef>(); if (includeRelationships == IncludeRelationships.SOURCE || includeRelationships == IncludeRelationships.BOTH) { assocs.addAll(nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL)); } if (includeRelationships == IncludeRelationships.TARGET || includeRelationships == IncludeRelationships.BOTH) { assocs.addAll(nodeService.getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL)); } // filter relationships that not map the CMIS domain model for (AssociationRef assocRef : assocs) { TypeDefinitionWrapper assocTypeDef = getOpenCMISDictionaryService().findAssocType(assocRef.getTypeQName()); if (assocTypeDef == null || getType(assocRef.getSourceRef()) == null || getType(assocRef.getTargetRef()) == null) { continue; } try { result.add(createCMISObject(createNodeInfo(assocRef), null, false, IncludeRelationships.NONE, RENDITION_NONE, false, false)); } catch (AccessDeniedException e) { } catch (CmisObjectNotFoundException e) { }// TODO: Somewhere this has not been wrapped correctly catch (net.sf.acegisecurity.AccessDeniedException e) { } } return result; }
38. FormRestApiJsonPost_Test#testRemoveAssociationsFromNode()
Project: community-edition
File: FormRestApiJsonPost_Test.java
File: FormRestApiJsonPost_Test.java
/** * 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())); }*/ }
39. FormRestApiJsonPost_Test#testAddNewAssociationsToNode()
Project: community-edition
File: FormRestApiJsonPost_Test.java
File: FormRestApiJsonPost_Test.java
/** * This test method attempts to add new associations between existing nodes. */ public void testAddNewAssociationsToNode() throws Exception { List<NodeRef> associatedNodes; checkOriginalAssocsBeforeChanges(); // Add three additional associations JSONObject jsonPostData = new JSONObject(); String assocsToAdd = associatedDoc_C + "," + associatedDoc_D + "," + associatedDoc_E; jsonPostData.put(ASSOC_CM_REFERENCES_ADDED, assocsToAdd); 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(5, 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)); assertTrue(associatedNodes.contains(associatedDoc_B)); assertTrue(associatedNodes.contains(associatedDoc_C)); assertTrue(associatedNodes.contains(associatedDoc_D)); assertTrue(associatedNodes.contains(associatedDoc_E)); // 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 5 assocs on the test node assertEquals(5, jsonAssocs.split(",").length); for (AssociationRef assocRef : modifiedAssocs) { assertTrue(jsonAssocs.contains(assocRef.getTargetRef().toString())); }*/ }
40. NodeTargetsRelation#delete()
Project: community-edition
File: NodeTargetsRelation.java
File: NodeTargetsRelation.java
@Override @WebApiDescription(title = "Remove node assoc(s)") public void delete(String sourceNodeId, String targetNodeId, Parameters parameters) { NodeRef srcNodeRef = nodes.validateNode(sourceNodeId); NodeRef tgtNodeRef = nodes.validateNode(targetNodeId); String assocTypeStr = parameters.getParameter(Nodes.PARAM_ASSOC_TYPE); QNamePattern assocTypeQName = nodes.getAssocType(assocTypeStr, false); if (assocTypeQName == null) { assocTypeQName = RegexQNamePattern.MATCH_ALL; } // note: even if assocType is provided, we currently don't use nodeService.removeAssociation(srcNodeRef, tgtNodeRef, assocTypeQName); // since silent it returns void even if nothing deleted, where as we return 404 boolean found = false; List<AssociationRef> assocRefs = nodeAssocService.getTargetAssocs(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sourceNodeId), assocTypeQName); for (AssociationRef assocRef : assocRefs) { if (assocRef.getTargetRef().equals(tgtNodeRef)) { nodeAssocService.removeAssociation(srcNodeRef, tgtNodeRef, assocRef.getTypeQName()); found = true; } } if (!found) { throw new EntityNotFoundException(sourceNodeId + "," + assocTypeStr + "," + targetNodeId); } }
41. AbstractNodeRelation#listNodePeerAssocs()
Project: community-edition
File: AbstractNodeRelation.java
File: AbstractNodeRelation.java
protected CollectionWithPagingInfo<Node> listNodePeerAssocs(List<AssociationRef> assocRefs, Parameters parameters, boolean returnTarget) { Map<QName, String> qnameMap = new HashMap<>(3); Map<String, UserInfo> mapUserInfo = new HashMap<>(10); List<String> includeParam = parameters.getInclude(); List<Node> collection = new ArrayList<Node>(assocRefs.size()); for (AssociationRef assocRef : assocRefs) { // minimal info by default (unless "include"d otherwise) NodeRef nodeRef = (returnTarget ? assocRef.getTargetRef() : assocRef.getSourceRef()); Node node = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, mapUserInfo); QName assocTypeQName = assocRef.getTypeQName(); if (!EXCLUDED_NS.contains(assocTypeQName.getNamespaceURI())) { String assocType = qnameMap.get(assocTypeQName); if (assocType == null) { assocType = assocTypeQName.toPrefixString(namespaceService); qnameMap.put(assocTypeQName, assocType); } node.setAssociation(new Assoc(assocType)); collection.add(node); } } Paging paging = parameters.getPaging(); return CollectionWithPagingInfo.asPaged(paging, collection, false, collection.size()); }