protected void checkAddPackageItem(NodeRef child, boolean wasCalled) { int times = wasCalled ? 1 : 0; verify(nodeService, times(times)).addChild(eq(PCKG_NODE), eq(child), eq(ASSOC_PACKAGE_CONTAINS), (QName) any()); }
@Override protected void updateAssociations(NodeService nodeService) { List<ChildAssociationRef> existingChildren = nodeService.getChildAssocs(sourceNodeRef); for (ChildAssociationRef assoc : existingChildren) { if (assoc.getChildRef().equals(targetNodeRef)) { if (logger.isWarnEnabled()) { logger.warn("Attempt to add existing child association prevented. " + assoc); } return; } } // We are following the behaviour of the JSF client here in using the same // QName value for the 3rd and 4th parameters in the below call. nodeService.addChild(sourceNodeRef, targetNodeRef, assocQName, assocQName); } }
@Override protected void updateAssociations(NodeService nodeService) { List<ChildAssociationRef> existingChildren = nodeService.getChildAssocs(sourceNodeRef); for (ChildAssociationRef assoc : existingChildren) { if (assoc.getChildRef().equals(targetNodeRef)) { if (logger.isWarnEnabled()) { logger.warn("Attempt to add existing child association prevented. " + assoc); } return; } } // We are following the behaviour of the JSF client here in using the same // QName value for the 3rd and 4th parameters in the below call. nodeService.addChild(sourceNodeRef, targetNodeRef, assocQName, assocQName); } }
public void addAuthorityToZones(String authorityName, Set<String> zones) { if ((zones != null) && (zones.size() > 0)) { Set<NodeRef> zoneRefs = new HashSet<NodeRef>(zones.size() * 2); for (String authorityZone : zones) { zoneRefs.add(getOrCreateZone(authorityZone)); } NodeRef authRef = getAuthorityOrNull(authorityName); if (authRef != null) { // Normalize the user name if necessary if (AuthorityType.getAuthorityType(authorityName) == AuthorityType.USER) { authorityName = (String) nodeService.getProperty(authRef, ContentModel.PROP_USERNAME); } nodeService.addChild(zoneRefs, authRef, ContentModel.ASSOC_IN_ZONE, QName.createQName("cm", authorityName, namespacePrefixResolver)); } } }
public void addAuthorityToZones(String authorityName, Set<String> zones) { if ((zones != null) && (zones.size() > 0)) { Set<NodeRef> zoneRefs = new HashSet<NodeRef>(zones.size() * 2); for (String authorityZone : zones) { zoneRefs.add(getOrCreateZone(authorityZone)); } NodeRef authRef = getAuthorityOrNull(authorityName); if (authRef != null) { // Normalize the user name if necessary if (AuthorityType.getAuthorityType(authorityName) == AuthorityType.USER) { authorityName = (String) nodeService.getProperty(authRef, ContentModel.PROP_USERNAME); } nodeService.addChild(zoneRefs, authRef, ContentModel.ASSOC_IN_ZONE, QName.createQName("cm", authorityName, namespacePrefixResolver)); } } }
/** * 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(); }
/** * 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(); }
public void createAuthority(String name, String authorityDisplayName, Set<String> authorityZones) { HashMap<QName, Serializable> props = new HashMap<QName, Serializable>(); /* MNT-11749 : Alfresco allows to create authorities with different char cases, but disallow duplicates */ props.put(ContentModel.PROP_NAME, DigestUtils.md5Hex(name)); props.put(ContentModel.PROP_AUTHORITY_NAME, name); props.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); NodeRef childRef; NodeRef authorityContainerRef = getAuthorityContainer(); childRef = nodeService.createNode(authorityContainerRef, ContentModel.ASSOC_CHILDREN, QName.createQName("cm", name, namespacePrefixResolver), ContentModel.TYPE_AUTHORITY_CONTAINER, props).getChildRef(); if (authorityZones != null) { Set<NodeRef> zoneRefs = new HashSet<NodeRef>(authorityZones.size() * 2); String currentUserDomain = tenantService.getCurrentUserDomain(); for (String authorityZone : authorityZones) { zoneRefs.add(getOrCreateZone(authorityZone)); zoneAuthorityCache.remove(new Pair<String, String>(currentUserDomain, authorityZone)); } zoneAuthorityCache.remove(new Pair<String, String>(currentUserDomain, null)); nodeService.addChild(zoneRefs, childRef, ContentModel.ASSOC_IN_ZONE, QName.createQName("cm", name, namespacePrefixResolver)); } authorityLookupCache.put(cacheKey(name), childRef); }
public void createAuthority(String name, String authorityDisplayName, Set<String> authorityZones) { HashMap<QName, Serializable> props = new HashMap<QName, Serializable>(); /* MNT-11749 : Alfresco allows to create authorities with different char cases, but disallow duplicates */ props.put(ContentModel.PROP_NAME, DigestUtils.md5Hex(name)); props.put(ContentModel.PROP_AUTHORITY_NAME, name); props.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); NodeRef childRef; NodeRef authorityContainerRef = getAuthorityContainer(); childRef = nodeService.createNode(authorityContainerRef, ContentModel.ASSOC_CHILDREN, QName.createQName("cm", name, namespacePrefixResolver), ContentModel.TYPE_AUTHORITY_CONTAINER, props).getChildRef(); if (authorityZones != null) { Set<NodeRef> zoneRefs = new HashSet<NodeRef>(authorityZones.size() * 2); String currentUserDomain = tenantService.getCurrentUserDomain(); for (String authorityZone : authorityZones) { zoneRefs.add(getOrCreateZone(authorityZone)); zoneAuthorityCache.remove(new Pair<String, String>(currentUserDomain, authorityZone)); } zoneAuthorityCache.remove(new Pair<String, String>(currentUserDomain, null)); nodeService.addChild(zoneRefs, childRef, ContentModel.ASSOC_IN_ZONE, QName.createQName("cm", name, namespacePrefixResolver)); } authorityLookupCache.put(cacheKey(name), childRef); }
/** * Test addChild */ @Test public void testAddChild() { try { this.versionStoreNodeService.addChild( this.dummyNodeRef, this.dummyNodeRef, this.dummyQName, this.dummyQName); fail("This operation is not supported."); } catch (UnsupportedOperationException exception) { if (exception.getMessage() != MSG_ERR) { fail("Unexpected exception raised during method excution: " + exception.getMessage()); } } }
private void addPackageItems(final NodeRef packageRef) { for (NodeRef item : addItems) { String name = (String) nodeService.getProperty(item, ContentModel.PROP_NAME); if (name == null) { name = GUID.generate(); } String localName = QName.createValidLocalName(name); QName qName = QName.createQName(CM_URL, localName); behaviourFilter.disableBehaviour(item, ContentModel.ASPECT_AUDITABLE); try { nodeService.addChild(packageRef, item, PCKG_CONTAINS, qName); } finally { behaviourFilter.enableBehaviour(item, ContentModel.ASPECT_AUDITABLE); } } }
private void addPackageItems(final NodeRef packageRef) { for (NodeRef item : addItems) { String name = (String) nodeService.getProperty(item, ContentModel.PROP_NAME); if (name == null) { name = GUID.generate(); } String localName = QName.createValidLocalName(name); QName qName = QName.createQName(CM_URL, localName); behaviourFilter.disableBehaviour(item, ContentModel.ASPECT_AUDITABLE); try { nodeService.addChild(packageRef, item, PCKG_CONTAINS, qName); } finally { behaviourFilter.enableBehaviour(item, ContentModel.ASPECT_AUDITABLE); } } }
public void testNoOldRenditionAndNoDestinationSpecifiedAndParentIsNotSource() { String localName = "Foo"; QName assocName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, localName); NodeRef parent = new NodeRef("http://test/parentId"); ChildAssociationRef parentAssoc = makeAssoc(parent, destination, assocName, false); Map<QName, Serializable> indexProps = Collections.singletonMap(ContentModel.PROP_IS_INDEXED, (Serializable) Boolean.FALSE); when(nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS, assocName, ContentModel.TYPE_CONTENT, indexProps)) .thenReturn(parentAssoc); RenditionLocation location = new RenditionLocationImpl(parent, null, localName); RenditionNodeManager manager = new RenditionNodeManager(source, null, location, definition, nodeService, renditionService, behaviourFilter); ChildAssociationRef result = manager.findOrCreateRenditionNode(); assertEquals(parentAssoc, result); // Check the rendition association is created. verify(nodeService).addChild(source, destination, RenditionModel.ASSOC_RENDITION, renditionName); }
@Test public void testAddBogusChild() throws Exception { // create a bogus reference NodeRef bogusChildRef = new NodeRef(rootNodeRef.getStoreRef(), "BOGUS"); try { nodeService.addChild(rootNodeRef, bogusChildRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName("BOGUS_PATH")); fail("Failed to detect invalid child node reference"); } catch (InvalidNodeRefException e) { // expected } }
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 testExcessTargetsOfOneToOneAssocs() 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_ONE); nodeService.createAssociation(source, target2, TEST_ASSOC_NODE_ONE_ONE); NodeRef parent = createNode("parent", TEST_TYPE_WITH_CHILD_ASSOCS, null); NodeRef child1 = createNode("child1", TEST_TYPE_WITHOUT_ANYTHING, null); NodeRef child2 = createNode("child2", TEST_TYPE_WITHOUT_ANYTHING, null); nodeService.addChild(parent, child1, TEST_ASSOC_CHILD_ONE_ONE, QName.createQName(NAMESPACE, "one-to-one-first")); nodeService.addChild(parent, child2, TEST_ASSOC_CHILD_ONE_ONE, QName.createQName(NAMESPACE, "one-to-one-second")); NodeRef aspectSource = createNode("aspectSource", TEST_TYPE_WITHOUT_ANYTHING, null); nodeService.addAspect(aspectSource, TEST_ASPECT_WITH_ASSOC, null); NodeRef aspectTarget1 = createNode("aspectTarget1", TEST_TYPE_WITHOUT_ANYTHING, null); NodeRef aspectTarget2 = createNode("aspectTarget2", TEST_TYPE_WITHOUT_ANYTHING, null); nodeService.createAssociation(aspectSource, aspectTarget1, TEST_ASSOC_ASPECT_ONE_ONE); nodeService.createAssociation(aspectSource, aspectTarget2, TEST_ASSOC_ASPECT_ONE_ONE); checkIntegrityExpectFailure("Failed to detect excess target cardinality for one-to-one assocs", 3); }
@Test public void testOnDeleteChildAssociationTrigger() { 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(); this.nodeService.addChild( nodeRef, nodeRef2, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN); TestRuleType ruleType = createTestRuleType(ON_DELETE_CHILD_ASSOCIATION_TRIGGER); assertFalse(ruleType.rulesTriggered); // Try and trigger the type this.nodeService.removeChild(nodeRef, nodeRef2); // Check to see if the rule type has been triggered assertTrue(ruleType.rulesTriggered); }
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(); }
@Override public NodeRef execute() throws Throwable { NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome(); String folder1 = GUID.generate(); FileInfo folderInfo1 = fileFolderService.create(companyHomeNodeRef, folder1, ContentModel.TYPE_FOLDER); assertNotNull(folderInfo1); String folder2 = GUID.generate(); FileInfo folderInfo2 = fileFolderService.create(companyHomeNodeRef, folder2, ContentModel.TYPE_FOLDER); assertNotNull(folderInfo2); // Create folder11 as a subfolder of folder1 String folder11 = GUID.generate(); FileInfo folderInfo11 = fileFolderService.create(folderInfo1.getNodeRef(), folder11, ContentModel.TYPE_FOLDER); assertNotNull(folderInfo11); // Add folder2 as second parent for folder11 nodeService.addChild(folderInfo2.getNodeRef(), folderInfo11.getNodeRef(), ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS); return folderInfo11.getNodeRef(); } });
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); }