private ChildAssociationRef createCategoryInternal(NodeRef parent, String name) { if (!nodeService.exists(parent)) { throw new AlfrescoRuntimeException("Missing category?"); } String uri = nodeService.getPrimaryParent(parent).getQName().getNamespaceURI(); String validLocalName = QName.createValidLocalName(name); ChildAssociationRef newCategory = publicNodeService.createNode(parent, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(uri, validLocalName), ContentModel.TYPE_CATEGORY); publicNodeService.setProperty(newCategory.getChildRef(), ContentModel.PROP_NAME, name); return newCategory; }
@Override public Void execute() throws Throwable { for(NodeRef nodeRef : nodesToDelete) { nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null); nodeService.deleteNode(nodeRef); } return null; } }, true, true);
/** * Creates a new secondary association between the current node and the specified child node. * The association is given the same name as the child node's primary association. * * Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call {@link #save()} first. * * @param node node to add as a child of this node */ public void addNode(ScriptNode node) { ParameterCheck.mandatory("node", node); ChildAssociationRef childAssocRef = this.nodeService.getPrimaryParent(node.nodeRef); nodeService.addChild(this.nodeRef, node.nodeRef, ContentModel.ASSOC_CONTAINS, childAssocRef.getQName()); reset(); }
@Override public void onDeleteAssociation(AssociationRef nodeAssocRef) { // The act:actionSchedule type must have the association, so remove the source when the // association is deleted. NodeRef actionScheduleNodeRef = nodeAssocRef.getSourceRef(); if (nodeService.exists(actionScheduleNodeRef) && !nodeService.hasAspect(actionScheduleNodeRef, ContentModel.ASPECT_PENDING_DELETE)) { // Delete the source nodeService.deleteNode(actionScheduleNodeRef); } }
public Void execute() throws Exception { if (!nodeService.exists(archivedNodeRef)) { // Node has disappeared return null; } invokeBeforePurgeNode(archivedNodeRef); nodeService.deleteNode(archivedNodeRef); return null; } };
private NodeRef lookupParentNodeRef(final NodeRef nodeRef) throws JSONException { NodeRef parentNodeRef = null; if (nodeService.exists(nodeRef)) { parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef(); } return parentNodeRef; }
NodeRef rootNodeRef = nodeService.getRootNode(storeRef); NodeRef nodeRef = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName("pathA"), List<StoreRef> storeRefs = nodeService.getStores(); assertTrue("Store should still exist", nodeService.exists(storeRef)); assertTrue("Node should still exist", nodeService.exists(rootNodeRef)); nodeService.deleteStore(storeRef); storeRefs = nodeService.getStores(); assertFalse("Deleted store should not present in list of stores", storeRefs.contains(storeRef)); assertFalse("Store should still exist", nodeService.exists(storeRef)); assertFalse("Node should still exist", nodeService.exists(rootNodeRef));
public Object execute() throws Exception { StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); return null; } };
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(); }
@Test public void testAddProperties() throws Exception { Map<QName, Serializable> properties = nodeService.getProperties(rootNodeRef); // Add an aspect with a default value nodeService.addAspect(rootNodeRef, ASPECT_QNAME_TEST_TITLED, null); assertNull("Expected null property", nodeService.getProperty(rootNodeRef, PROP_QNAME_TEST_TITLE)); assertNull("Expected null property", nodeService.getProperty(rootNodeRef, PROP_QNAME_TEST_DESCRIPTION)); // Now add a map of two properties and check Map<QName, Serializable> addProperties = new HashMap<QName, Serializable>(11); addProperties.put(PROP_QNAME_TEST_TITLE, "Title"); addProperties.put(PROP_QNAME_TEST_DESCRIPTION, "Description"); nodeService.addProperties(rootNodeRef, addProperties); // Check Map<QName, Serializable> checkProperties = nodeService.getProperties(rootNodeRef); assertEquals("Title", checkProperties.get(PROP_QNAME_TEST_TITLE)); assertEquals("Description", checkProperties.get(PROP_QNAME_TEST_DESCRIPTION)); }
public void testRemoveTargetsOfMandatoryAssocs() 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(); // remove target nodes nodeService.deleteNode(target); nodeService.deleteNode(child); nodeService.deleteNode(aspectTarget); checkIntegrityExpectFailure("Failed to detect removal of mandatory assoc targets", 3); }
// create new content node within company home // assign name String name = "Foundation API sample (" + System.currentTimeMillis() + ")"; // create content node NodeService nodeService = registry.getNodeService(); ChildAssociationRef association = nodeService.createNode( companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name), ContentModel.TYPE_CONTENT);
@Override public NodeRef doWork() throws Exception { NodeRef system = getSystemContainer(nodeService, repositoryHelper); NodeRef container = nodeService.createNode( system, ContentModel.ASSOC_CHILDREN, childName, ContentModel.TYPE_CONTAINER ).getChildRef(); nodeService.setProperty(container, ContentModel.PROP_NAME, childName.getLocalName()); return container; } });
nodeService.addProperties(nodeRef, properties); nodeService.setProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, "Hello"); "Expected French value property", "Bonjour", nodeService.getProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE)); "Expected English value property", "Hello", nodeService.getProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE));
@Override public NodeRef execute() throws Throwable { NodeRef contentNodeRef = RuleServiceCoverageTest.this.nodeService.createNode( RuleServiceCoverageTest.this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT).getChildRef(); RuleServiceCoverageTest.this.nodeService.addAspect(contentNodeRef, ContentModel.ASPECT_NO_CONTENT, null); return contentNodeRef; } });
@Override public void delete(NodeRef nodeRef) { apiFacet.getNodeService().deleteNode(nodeRef); }
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 doWork() { nodeService.addAspect(nodeRef, QuickShareModel.ASPECT_QSHARE, props); 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); } }
@Override public Void execute() throws Throwable { assertEquals(0, taggingService.findTagScope(testData.container1).getTags().size()); assertEquals(0, taggingService.findTagScope(testData.container2).getTags().size()); assertEquals(1, nodeService.getChildAssocs(testData.container1).size()); // Now update the folder to add in tags Map<QName, Serializable> taggedFolderProps = new HashMap<QName, Serializable>(1); List<NodeRef> tagsList = new ArrayList<NodeRef>(); tagsList.add(testData.tagFoo1); tagsList.add(testData.tagFoo3); taggedFolderProps.put(ContentModel.ASPECT_TAGGABLE, (Serializable) tagsList); nodeService.addProperties(testData.taggedFolder, taggedFolderProps); return null; } });