From 4c800c25c539cb1442885453000a76b896315adb Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Fri, 9 Jan 2009 12:43:46 +0000 Subject: [PATCH] Merged DEV/JASONH to HEAD 12565: JCR - fix ALFCOM-1655 (supercedes part of r12170) 12644: JCR - fix extra testcase for ALFCOM-1655 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12650 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/jcr/item/ItemTest.java | 128 ++++++++++++++++++ .../java/org/alfresco/jcr/item/NodeImpl.java | 36 ++++- source/java/org/alfresco/jcr/test/myModel.xml | 71 ++++++++++ .../org/alfresco/jcr/test/test-context.xml | 1 + 4 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 source/java/org/alfresco/jcr/item/ItemTest.java create mode 100644 source/java/org/alfresco/jcr/test/myModel.xml diff --git a/source/java/org/alfresco/jcr/item/ItemTest.java b/source/java/org/alfresco/jcr/item/ItemTest.java new file mode 100644 index 0000000000..e4d5370dbb --- /dev/null +++ b/source/java/org/alfresco/jcr/item/ItemTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2005-2008 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.jcr.item; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; + +import org.alfresco.jcr.test.BaseJCRTest; + + +/** + * One-off item tests - sanity checks for bug fixes + * + * @author janv + */ +public class ItemTest extends BaseJCRTest +{ + protected Session session; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + } + + public void test_ALFCOM_1655() throws RepositoryException + { + SimpleCredentials user = new SimpleCredentials("admin", "admin".toCharArray()); + + session = repository.login(user, getWorkspace()); + + try + { + Node rootNode = session.getRootNode(); + assertNotNull(rootNode); + + Node aNode = rootNode.addNode("A1","my:a"); + assertNotNull(aNode); + + Node bNode = aNode.addNode("B1","my:b"); + assertNotNull(bNode); + + aNode = rootNode.addNode("A2","cm:folder"); + assertNotNull(aNode); + + bNode = aNode.addNode("B2","cm:folder"); + assertNotNull(bNode); + + Node cNode = rootNode.addNode("C1","my:c"); + assertNotNull(cNode); + + aNode = cNode.addNode("A3","my:a"); + assertNotNull(aNode); + + bNode = cNode.addNode("B3","my:b"); + assertNotNull(bNode); + + session.save(); + } + finally + { + if (session != null) { session.logout(); } + } + + session = repository.login(user, getWorkspace()); + + try + { + Node rootNode = session.getRootNode(); + assertNotNull(rootNode); + + Node aNode = rootNode.getNode("A1"); + assertNotNull(aNode); + + Node bNode = aNode.getNode("B1"); + assertNotNull(bNode); + + aNode = rootNode.getNode("A2"); + assertNotNull(aNode); + + bNode = aNode.getNode("B2"); + assertNotNull(bNode); + + Node cNode = rootNode.getNode("C1"); + assertNotNull(cNode); + + aNode = cNode.getNode("A3"); + assertNotNull(aNode); + + bNode = cNode.getNode("B3"); + assertNotNull(bNode); + } + finally + { + if (session != null) { session.logout(); } + } + } +} diff --git a/source/java/org/alfresco/jcr/item/NodeImpl.java b/source/java/org/alfresco/jcr/item/NodeImpl.java index b13ecbea1a..d45192067e 100644 --- a/source/java/org/alfresco/jcr/item/NodeImpl.java +++ b/source/java/org/alfresco/jcr/item/NodeImpl.java @@ -241,22 +241,48 @@ public class NodeImpl extends ItemImpl implements Node Set aspects = nodeService.getAspects(nodeRef); ClassDefinition classDef = dictionaryService.getAnonymousType(type, aspects); Map childAssocs = classDef.getChildAssociations(); + for (ChildAssociationDefinition childAssocDef : childAssocs.values()) { QName targetClass = childAssocDef.getTargetClass().getName(); - if (dictionaryService.isSubClass(nodeType, targetClass)) + if (nodeType.equals(targetClass)) { - if (nodeTypeChildAssocDef != null) - { - throw new AlfrescoRuntimeException("Cannot determine child association for node type '" + nodeType + " within parent " + nodeRef); - } + // exact match nodeTypeChildAssocDef = childAssocDef; + break; } } + + if (nodeTypeChildAssocDef == null) + { + for (ChildAssociationDefinition childAssocDef : childAssocs.values()) + { + QName targetClass = childAssocDef.getTargetClass().getName(); + if (dictionaryService.isSubClass(nodeType, targetClass)) + { + if (childAssocDef.getSourceClass().getName().equals(type)) + { + // matching parent type + nodeTypeChildAssocDef = childAssocDef; + break; + } + + if (nodeTypeChildAssocDef != null) + { + // more than one match + throw new AlfrescoRuntimeException("Cannot determine child association for node type '" + nodeType + " within parent " + nodeRef); + } + + nodeTypeChildAssocDef = childAssocDef; + } + } + } + if (nodeTypeChildAssocDef == null) { throw new AlfrescoRuntimeException("Cannot determine child association for node type '" + nodeType + " within parent " + nodeRef); } + return nodeTypeChildAssocDef; } diff --git a/source/java/org/alfresco/jcr/test/myModel.xml b/source/java/org/alfresco/jcr/test/myModel.xml new file mode 100644 index 0000000000..f142e93f43 --- /dev/null +++ b/source/java/org/alfresco/jcr/test/myModel.xml @@ -0,0 +1,71 @@ + + + My test model + 1.0 + + + + + + + + + + + + + + A + cm:folder + + + + my:b + false + false + + + + + my:baseAspect + + + + + B + cm:folder + + my:baseAspect + + + + + C + cm:folder + + + + false + true + + + sys:base + false + true + + false + + + + + + + + + + Base Aspect + + + + + \ No newline at end of file diff --git a/source/java/org/alfresco/jcr/test/test-context.xml b/source/java/org/alfresco/jcr/test/test-context.xml index 275822ea4f..00037c113f 100644 --- a/source/java/org/alfresco/jcr/test/test-context.xml +++ b/source/java/org/alfresco/jcr/test/test-context.xml @@ -10,6 +10,7 @@ org/alfresco/jcr/test/testModel.xml + org/alfresco/jcr/test/myModel.xml