mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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
This commit is contained in:
128
source/java/org/alfresco/jcr/item/ItemTest.java
Normal file
128
source/java/org/alfresco/jcr/item/ItemTest.java
Normal file
@@ -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(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -241,22 +241,48 @@ public class NodeImpl extends ItemImpl implements Node
|
|||||||
Set<QName> aspects = nodeService.getAspects(nodeRef);
|
Set<QName> aspects = nodeService.getAspects(nodeRef);
|
||||||
ClassDefinition classDef = dictionaryService.getAnonymousType(type, aspects);
|
ClassDefinition classDef = dictionaryService.getAnonymousType(type, aspects);
|
||||||
Map<QName, ChildAssociationDefinition> childAssocs = classDef.getChildAssociations();
|
Map<QName, ChildAssociationDefinition> childAssocs = classDef.getChildAssociations();
|
||||||
|
|
||||||
for (ChildAssociationDefinition childAssocDef : childAssocs.values())
|
for (ChildAssociationDefinition childAssocDef : childAssocs.values())
|
||||||
{
|
{
|
||||||
QName targetClass = childAssocDef.getTargetClass().getName();
|
QName targetClass = childAssocDef.getTargetClass().getName();
|
||||||
if (dictionaryService.isSubClass(nodeType, targetClass))
|
if (nodeType.equals(targetClass))
|
||||||
{
|
{
|
||||||
if (nodeTypeChildAssocDef != null)
|
// exact match
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Cannot determine child association for node type '" + nodeType + " within parent " + nodeRef);
|
|
||||||
}
|
|
||||||
nodeTypeChildAssocDef = childAssocDef;
|
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)
|
if (nodeTypeChildAssocDef == null)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Cannot determine child association for node type '" + nodeType + " within parent " + nodeRef);
|
throw new AlfrescoRuntimeException("Cannot determine child association for node type '" + nodeType + " within parent " + nodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeTypeChildAssocDef;
|
return nodeTypeChildAssocDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
71
source/java/org/alfresco/jcr/test/myModel.xml
Normal file
71
source/java/org/alfresco/jcr/test/myModel.xml
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<model name="my:mytestmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
|
||||||
|
|
||||||
|
<description>My test model</description>
|
||||||
|
<version>1.0</version>
|
||||||
|
|
||||||
|
<imports>
|
||||||
|
<import uri="http://www.alfresco.org/model/system/1.0" prefix="sys"/>
|
||||||
|
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
|
||||||
|
</imports>
|
||||||
|
|
||||||
|
<namespaces>
|
||||||
|
<namespace uri="http://www.alfresco.org/model/my/1.0" prefix="my"/>
|
||||||
|
</namespaces>
|
||||||
|
|
||||||
|
<types>
|
||||||
|
|
||||||
|
<type name="my:a">
|
||||||
|
<title>A</title>
|
||||||
|
<parent>cm:folder</parent>
|
||||||
|
<associations>
|
||||||
|
<child-association name="my:b">
|
||||||
|
<target>
|
||||||
|
<class>my:b</class>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<many>false</many>
|
||||||
|
</target>
|
||||||
|
</child-association>
|
||||||
|
</associations>
|
||||||
|
<mandatory-aspects>
|
||||||
|
<aspect>my:baseAspect</aspect>
|
||||||
|
</mandatory-aspects>
|
||||||
|
</type>
|
||||||
|
|
||||||
|
<type name="my:b">
|
||||||
|
<title>B</title>
|
||||||
|
<parent>cm:folder</parent>
|
||||||
|
<mandatory-aspects>
|
||||||
|
<aspect>my:baseAspect</aspect>
|
||||||
|
</mandatory-aspects>
|
||||||
|
</type>
|
||||||
|
|
||||||
|
<type name="my:c">
|
||||||
|
<title>C</title>
|
||||||
|
<parent>cm:folder</parent>
|
||||||
|
<associations>
|
||||||
|
<child-association name="my:c">
|
||||||
|
<source>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<many>true</many>
|
||||||
|
</source>
|
||||||
|
<target>
|
||||||
|
<class>sys:base</class>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<many>true</many>
|
||||||
|
</target>
|
||||||
|
<duplicate>false</duplicate>
|
||||||
|
</child-association>
|
||||||
|
</associations>
|
||||||
|
</type>
|
||||||
|
|
||||||
|
</types>
|
||||||
|
|
||||||
|
<aspects>
|
||||||
|
|
||||||
|
<aspect name="my:baseAspect">
|
||||||
|
<title>Base Aspect</title>
|
||||||
|
</aspect>
|
||||||
|
|
||||||
|
</aspects>
|
||||||
|
|
||||||
|
</model>
|
@@ -10,6 +10,7 @@
|
|||||||
<property name="models">
|
<property name="models">
|
||||||
<list>
|
<list>
|
||||||
<value>org/alfresco/jcr/test/testModel.xml</value>
|
<value>org/alfresco/jcr/test/testModel.xml</value>
|
||||||
|
<value>org/alfresco/jcr/test/myModel.xml</value>
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
Reference in New Issue
Block a user