Author: areshetnyak
Date: 2010-02-02 03:18:34 -0500 (Tue, 02 Feb 2010)
New Revision: 1632
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/InmemoryNodeTypeRepository.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/nodetypes/TestGettingExoScriptProperty.java
Log:
EXOJCR-449 : The problem with overdetermination properties in node type was fixed.
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/InmemoryNodeTypeRepository.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/InmemoryNodeTypeRepository.java 2010-02-01
18:23:22 UTC (rev 1631)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/InmemoryNodeTypeRepository.java 2010-02-02
08:18:34 UTC (rev 1632)
@@ -80,7 +80,7 @@
{
hierarchy.addNodeType(nodeType, volatileNodeTypes);
- defsHolder.putDefinitions(nodeType.getName(), nodeType);
+
// put supers
final Set<InternalQName> supers = hierarchy.getSupertypes(nodeType.getName(),
volatileNodeTypes);
@@ -89,6 +89,9 @@
defsHolder.putDefinitions(nodeType.getName(), hierarchy.getNodeType(superName,
volatileNodeTypes));
}
haveTypes = true;
+
+ // put prop def
+ defsHolder.putDefinitions(nodeType.getName(), nodeType);
}
/**
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java 2010-02-01
18:23:22 UTC (rev 1631)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java 2010-02-02
08:18:34 UTC (rev 1632)
@@ -224,27 +224,69 @@
public PropertyDefinitionData[] getAllPropertyDefinitions(final InternalQName...
nodeTypeNames)
{
- final Collection<PropertyDefinitionData> defs = new
HashSet<PropertyDefinitionData>();
+ class Key
+ {
+ private InternalQName name;
- for (final InternalQName ntname : nodeTypeNames)
- {
- for (final PropertyDefinitionData pd :
this.nodeTypeRepository.getNodeType(ntname)
- .getDeclaredPropertyDefinitions())
+ private boolean isMulti;
+
+ public Key(InternalQName name, boolean isMulti)
{
- defs.add(pd);
+ this.name = name;
+ this.isMulti = isMulti;
}
+ /**
+ * {@inheritDoc}
+ */
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + (isMulti ? 1231 : 1237);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean equals(Object obj)
+ {
+ if (!(obj instanceof Key))
+ {
+ return false;
+ }
+
+ Key k = (Key) obj;
+
+ return name.equals(k.name) && isMulti == k.isMulti;
+ }
+ }
+
+ final HashMap<Key, PropertyDefinitionData> defs = new HashMap<Key,
PropertyDefinitionData>();
+
+ for (final InternalQName ntname : nodeTypeNames)
+ {
+
for (final InternalQName suname :
this.nodeTypeRepository.getSupertypes(ntname))
{
for (final PropertyDefinitionData pd :
this.nodeTypeRepository.getNodeType(suname)
- .getDeclaredPropertyDefinitions())
+ .getDeclaredPropertyDefinitions())
{
- defs.add(pd);
+
+ defs.put(new Key(pd.getName(), pd.isMultiple()), pd);
}
}
+
+ for (final PropertyDefinitionData pd :
this.nodeTypeRepository.getNodeType(ntname)
+ .getDeclaredPropertyDefinitions())
+ {
+ defs.put(new Key(pd.getName(), pd.isMultiple()), pd);
+ }
}
-
- return defs.toArray(new PropertyDefinitionData[defs.size()]);
+
+ return defs.values().toArray(new PropertyDefinitionData[defs.size()]);
}
/**
@@ -360,6 +402,7 @@
PropertyDefinitionDatas propertyDefinitions =
this.nodeTypeRepository.getPropertyDefinitions(propertyName, nodeTypeNames);
+
// Try super
if (propertyDefinitions == null)
{
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/nodetypes/TestGettingExoScriptProperty.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/nodetypes/TestGettingExoScriptProperty.java 2010-02-01
18:23:22 UTC (rev 1631)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/nodetypes/TestGettingExoScriptProperty.java 2010-02-02
08:18:34 UTC (rev 1632)
@@ -20,11 +20,14 @@
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.Value;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.NodeTypeIterator;
import javax.jcr.nodetype.NodeTypeManager;
import javax.jcr.nodetype.PropertyDefinition;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.api.nodetype.NodeTypeUtil;
import org.exoplatform.services.jcr.usecases.BaseUsecasesTest;
/**
@@ -38,177 +41,35 @@
public class TestGettingExoScriptProperty
extends BaseUsecasesTest
{
-
- public static final int ANY_PROPERTY_TYPE = -1;
-
- public void testLoadPropertyDef() throws Exception
+ public void testLoadProperyDef3() throws Exception
{
- PropertyDefinition propDef = locatePropertyDef(session, ANY_PROPERTY_TYPE, false,
true, false, false);
-
- System.out.println("\n\n" +propDef.getName() + "\n\n");
-
- assertEquals(true, propDef.isProtected());
-
- if (propDef.getName().equals("exo:script")) {
- assertEquals(false, propDef.isProtected());
- }
- }
-
- public void testExoScriptProperty() throws Exception
- {
- Node rootNode = session.getRootNode();
-
- Node action = rootNode.addNode("123", "exo:scriptAction");
-
- action.setProperty( "exo:name", "exo_name__value");
- action.setProperty( "exo:lifecyclePhase", "add");
- action.setProperty( "exo:roles", new String[] {"*"});
-
- action.setProperty( "exo:script", "exo_script__value");
- session.save();
-
- PropertyDefinition[] propsDef =
action.getPrimaryNodeType().getDeclaredPropertyDefinitions();
-
- for (PropertyDefinition pDef : propsDef)
- {
- if (pDef.getName().equals("exo:script")) {
-
- assertEquals(pDef.isProtected(), false);
- return;
- }
- }
-
- fail("The property definition is not found.");
- }
-
- public void testGetPropDefFromNTM() throws Exception
- {
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+
+ NodeType nt = manager.getNodeType("exo:addMetadataAction");
+
+ PropertyDefinition propDef = null;
+ PropertyDefinition[] propsDef = nt.getPropertyDefinitions();
- NodeType nt = manager.getNodeType("exo:scriptAction");
-
- PropertyDefinition[] propsDef = nt.getDeclaredPropertyDefinitions();
-
+ assertEquals(8, propsDef.length);
+
for (PropertyDefinition pDef : propsDef)
{
- if (pDef.getName().equals("exo:script")) {
- assertEquals(pDef.isProtected(), false);
- return;
+ if (pDef.getName().equals("exo:script"))
+ {
+ propDef = pDef;
}
}
-
- fail("The property definition is not found.");
-
- }
- public static PropertyDefinition locatePropertyDef(Session session, int propertyType,
boolean multiple,
- boolean isProtected, boolean constraints, boolean residual) throws
RepositoryException
- {
-
- NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
- NodeTypeIterator types = manager.getAllNodeTypes();
-
- while (types.hasNext())
+ // will never happen since at least jcr:primaryType of nt:base accomplish the
request
+ if (propDef == null)
{
- NodeType type = types.nextNodeType();
- PropertyDefinition propDefs[] = type.getDeclaredPropertyDefinitions();
- for (int i = 0; i < propDefs.length; i++)
- {
- PropertyDefinition propDef = propDefs[i];
-
- System.out.println("\n\n " + propDef.getName());
+ throw new NotExecutableException("No protected property def found.");
+ }
- if (propertyType != ANY_PROPERTY_TYPE && propDef.getRequiredType() !=
propertyType)
- {
- continue;
- }
+ NodeType nodeType = propDef.getDeclaringNodeType();
+ Value value = NodeTypeUtil.getValueOfType(session, propDef.getRequiredType());
- if (propertyType == ANY_PROPERTY_TYPE && propDef.getRequiredType() ==
PropertyType.UNDEFINED)
- {
- continue;
- }
-
- if (multiple && !propDef.isMultiple())
- {
- continue;
- }
- if (!multiple && propDef.isMultiple())
- {
- continue;
- }
-
- System.out.println("isProtected && !propDef.isProtected()
==" + (isProtected && !propDef.isProtected()));
- if (isProtected && !propDef.isProtected())
- {
- continue;
- }
- if (!isProtected && propDef.isProtected())
- {
- continue;
- }
-
- String vc[] = propDef.getValueConstraints();
- if (!constraints && vc != null && vc.length > 0)
- {
- continue;
- }
- if (constraints)
- {
- // property def with constraints requested
- if (vc == null || vc.length == 0)
- {
- // property def has no constraints
- continue;
- }
- }
-
- if (!residual && propDef.getName().equals("*"))
- {
- continue;
- }
-
- if (residual && !propDef.getName().equals("*"))
- {
- continue;
- }
-
- // also skip property residual property definition if there
- // is another residual definition
- if (residual)
- {
- // check if there is another residual property def
- if (getNumResidualPropDefs(type) > 1)
- {
- continue;
- }
- }
-
- if (!residual)
- {
- // if not looking for a residual property def then there
- // must not be any residual definition at all on the node
- // type
- if (getNumResidualPropDefs(type) > 0)
- {
- continue;
- }
- }
-
- return propDef;
- }
- }
- return null;
+ assertFalse("canSetProperty(String propertyName, Value value) must "
+ + "return false if the property is protected.",
nodeType.canSetProperty(propDef.getName(), value));
}
-
- private static int getNumResidualPropDefs(NodeType type) {
- PropertyDefinition[] pDefs = type.getPropertyDefinitions();
- int residuals = 0;
- for (int j = 0; j < pDefs.length; j++) {
- PropertyDefinition pDef = pDefs[j];
- if (pDef.getName().equals("*")) {
- residuals++;
- }
- }
- return residuals;
- }
}