public void addNodeToDownload(NodeRef downloadNode, NodeRef nodeToAdd) { nodeService.createAssociation(downloadNode, nodeToAdd, DownloadModel.ASSOC_REQUESTED_NODES); if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Node added to Download-NodeRef '") .append(downloadNode).append("'. RequestedNode=") .append(nodeToAdd); log.debug(msg.toString()); } }
public void addNodeToDownload(NodeRef downloadNode, NodeRef nodeToAdd) { nodeService.createAssociation(downloadNode, nodeToAdd, DownloadModel.ASSOC_REQUESTED_NODES); if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Node added to Download-NodeRef '") .append(downloadNode).append("'. RequestedNode=") .append(nodeToAdd); log.debug(msg.toString()); } }
@Override public Void execute() throws Throwable { nodeService.createAssociation(testContext.sourceNodeRef, testContext.targetNodeRef, assocQName); return null; } };
public void process(NodeRef entry) throws Throwable { nodeService.removeAspect(entry, ImapModel.ASPECT_IMAP_FOLDER_NONSUBSCRIBED); for (ChildAssociationRef userRef : users) { nodeService.createAssociation(userRef.getChildRef(), entry, ImapModel.ASSOC_IMAP_UNSUBSCRIBED); } }
public void process(NodeRef entry) throws Throwable { nodeService.removeAspect(entry, ImapModel.ASPECT_IMAP_FOLDER_NONSUBSCRIBED); for (ChildAssociationRef userRef : users) { nodeService.createAssociation(userRef.getChildRef(), entry, ImapModel.ASSOC_IMAP_UNSUBSCRIBED); } }
@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); } }
@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); } }
private NodeRef createAttachmentFolder(NodeRef messageRef, String attachmentsFolderName) { NodeRef attachmentsFolderRef = null; NodeRef parentFolder = nodeService.getPrimaryParent(messageRef).getParentRef(); attachmentsFolderRef = fileFolderService.create(parentFolder, attachmentsFolderName, ContentModel.TYPE_FOLDER).getNodeRef(); nodeService.createAssociation(messageRef, attachmentsFolderRef, ImapModel.ASSOC_IMAP_ATTACHMENTS_FOLDER); return attachmentsFolderRef; }
private NodeRef createAttachmentFolder(NodeRef messageRef, String attachmentsFolderName) { NodeRef attachmentsFolderRef = null; NodeRef parentFolder = nodeService.getPrimaryParent(messageRef).getParentRef(); attachmentsFolderRef = fileFolderService.create(parentFolder, attachmentsFolderName, ContentModel.TYPE_FOLDER).getNodeRef(); nodeService.createAssociation(messageRef, attachmentsFolderRef, ImapModel.ASSOC_IMAP_ATTACHMENTS_FOLDER); return attachmentsFolderRef; }
public void unsubscribe(AlfrescoImapUser user, String mailbox) { if (logger.isDebugEnabled()) { logger.debug("Unsubscribing: " + user + ", " + mailbox); } AlfrescoImapFolder mailFolder = getOrCreateMailbox(user, mailbox, true, false); if(mailFolder.getFolderInfo() != null) { PersonService personService = serviceRegistry.getPersonService(); NodeRef userRef = personService.getPerson(user.getLogin()); nodeService.createAssociation(userRef, mailFolder.getFolderInfo().getNodeRef(), ImapModel.ASSOC_IMAP_UNSUBSCRIBED); } else { // perhaps the folder has been deleted by another async process? logger.debug("Unable to find folder to unsubscribe"); } }
public void unsubscribe(AlfrescoImapUser user, String mailbox) { if (logger.isDebugEnabled()) { logger.debug("Unsubscribing: " + user + ", " + mailbox); } AlfrescoImapFolder mailFolder = getOrCreateMailbox(user, mailbox, true, false); if(mailFolder.getFolderInfo() != null) { PersonService personService = serviceRegistry.getPersonService(); NodeRef userRef = personService.getPerson(user.getLogin()); nodeService.createAssociation(userRef, mailFolder.getFolderInfo().getNodeRef(), ImapModel.ASSOC_IMAP_UNSUBSCRIBED); } else { // perhaps the folder has been deleted by another async process? logger.debug("Unable to find folder to unsubscribe"); } }
@Override public PostInfo createReply(PostInfo parentPost, String contents) { // Sanity check what we were given if (parentPost.getNodeRef() == null) { throw new IllegalArgumentException("Can't reply to a post that was never persisted"); } if (parentPost.getTopic() == null) { throw new IllegalArgumentException("Can't reply to a post with no attached topic"); } // Have the post created PostInfo reply = createPost(parentPost.getTopic(), contents); // Now make it a reply nodeService.createAssociation( reply.getNodeRef(), parentPost.getNodeRef(), ContentModel.ASSOC_REFERENCES); // All done return reply; }
public void testExcessTargetsOfOneToManyAssocs() throws Exception { NodeRef source = createNode("abc", TEST_TYPE_WITH_ASSOCS, null); NodeRef target1 = createNode("target1", TEST_TYPE_WITHOUT_ANYTHING, null); NodeRef target2 = createNode("target2", TEST_TYPE_WITHOUT_ANYTHING, null); nodeService.createAssociation(source, target1, TEST_ASSOC_NODE_ONE_MANY); nodeService.createAssociation(source, target2, TEST_ASSOC_NODE_ONE_MANY); checkIntegrityExpectFailure("Failed to detect excess source cardinality for one-to-many assocs", 1); }
/** * 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); }
/** * 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); }
@Test public void testCreateAssociation() throws Exception { NodeRef createDownloadNode = createDownloadNode(); NodeRef node2 = nodeService.getChildByName(virtualFolder1NodeRef, ContentModel.ASSOC_CONTAINS, "Node2"); nodeService.createAssociation(createDownloadNode, node2, DownloadModel.ASSOC_REQUESTED_NODES); }
public void testCreateTargetOfAssocsWithMandatorySourcesPresent() throws Exception { // this is the target of 3 assoc types where the source cardinality is 1..1 NodeRef targetAndChild = createNode("targetAndChild", TEST_TYPE_WITHOUT_ANYTHING, null); NodeRef source = createNode("source", TEST_TYPE_WITH_ASSOCS, null); nodeService.createAssociation(source, targetAndChild, TEST_ASSOC_NODE_ONE_ONE); NodeRef parent = createNode("parent", TEST_TYPE_WITH_CHILD_ASSOCS, null); nodeService.addChild(parent, targetAndChild, TEST_ASSOC_CHILD_ONE_ONE, QName.createQName(NAMESPACE, "mandatoryChild")); NodeRef aspected = createNode("aspectNode", TEST_TYPE_WITHOUT_ANYTHING, null); nodeService.addAspect(aspected, TEST_ASPECT_WITH_ASSOC, null); nodeService.createAssociation(aspected, targetAndChild, TEST_ASSOC_ASPECT_ONE_ONE); checkIntegrityNoFailure(); }
public void testCreateSourceOfAssocsWithMandatoryTargetsPresent() throws Exception { NodeRef source = createNode("abc", TEST_TYPE_WITH_ASSOCS, null); NodeRef target = createNode("target", TEST_TYPE_WITHOUT_ANYTHING, null); nodeService.createAssociation(source, target, TEST_ASSOC_NODE_ONE_ONE); NodeRef parent = createNode("parent", TEST_TYPE_WITH_CHILD_ASSOCS, null); NodeRef child = createNode("child", TEST_TYPE_WITHOUT_ANYTHING, null); nodeService.addChild(parent, child, TEST_ASSOC_CHILD_ONE_ONE, QName.createQName(NAMESPACE, "one-to-one")); NodeRef aspectSource = createNode("aspectSource", TEST_TYPE_WITHOUT_ANYTHING, null); nodeService.addAspect(aspectSource, TEST_ASPECT_WITH_ASSOC, null); NodeRef aspectTarget = createNode("aspectTarget", TEST_TYPE_WITHOUT_ANYTHING, null); nodeService.createAssociation(aspectSource, aspectTarget, TEST_ASSOC_ASPECT_ONE_ONE); checkIntegrityNoFailure(); }
@Test 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) { // expected } }
@Test public void testOnCreateOriginalAssociationTrigger() { NodeRef nodeRef = this.nodeService.createNode( this.rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTAINER).getChildRef(); NodeRef nodeRef2 = this.nodeService.createNode( this.rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTAINER).getChildRef(); TestRuleType ruleType = createTestRuleType(ON_CREATE_ASSOCIATION_TRIGGER); assertFalse(ruleType.rulesTriggered); // Try and trigger the type this.nodeService.createAssociation(nodeRef, nodeRef2, ContentModel.ASSOC_ORIGINAL); // Check to see if the rule type has been triggered assertFalse(ruleType.rulesTriggered); }