Hi,

See attached patch for how I'd solve the issue for the current path. Currently this causes testGetNode(org.apache.jackrabbit.test.api.PathPropertyTest) to fail which is due to the path value not being stored correctly (i.e. as oak path instead of as jcr path). We'd need to complete the Value related implementations first to support this.

For paths containing .. I think we could do something along the lines of:

absPath = PathUtils.concat(this.path, relPath);
normalizedAbsPath = getOakPath(absPath)
normalizedRelPath = PathUtils.relativize(this.path, normalizedAbsPath);

Michael

On 9.5.12 17:00, Julian Reschke wrote:
Hi,

I just discovered that we have tests that do not do anything meaningful
because we didn't have test data in the repo. I just fixed that for
./property (see TestContentLoader).

This exposed three issues:

1) missing Date->long/double/decimal value conversions. I have added
those for now in ValueImpl (not core); is this correct, Angela?

2) we didn't round-trip a relative path of ".". Now we do, but I'm not
sure I got the mapping correct. What is a same-node reference in Oak
path syntax? "." or empty string? I also fear that we need to be able to
round-trip relative paths like "../foo/bar" in path values, which we
currently do not. Do we need a "normalize" flag???

3) Node.getNode(".") failed because it looked for a child called ".". If
have added a hack to make this work, but I'm wondering how to do this
properly.

Best regards, Julian



On 2012-05-09 17:52, [email protected] wrote:
Author: reschke
Date: Wed May 9 15:52:35 2012
New Revision: 1336250

URL: http://svn.apache.org/viewvc?rev=1336250&view=rev
Log:
OAK-6: add test content for property tests; add value conversion for
dates, handle "." paths in path-typed properties

Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java

jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java

jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java

jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java


Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java

URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java?rev=1336250&r1=1336249&r2=1336250&view=diff

==============================================================================

---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
Wed May 9 15:52:35 2012
@@ -143,6 +143,11 @@ public class NamePathMapperImpl implemen
}
}

+ // empty path: map to "."
+ if (oakPath.length() == 0) {
+ return ".";
+ }
+
// root path is special-cased early on so it does not need to
// be considered here
oakPath.deleteCharAt(oakPath.length() - 1);
@@ -228,6 +233,11 @@ public class NamePathMapperImpl implemen
}
}

+ // empty path: map to "."
+ if (jcrPath.length() == 0) {
+ return ".";
+ }
+
jcrPath.deleteCharAt(jcrPath.length() - 1);
return jcrPath.toString();
}

Modified:
jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java

URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java?rev=1336250&r1=1336249&r2=1336250&view=diff

==============================================================================

---
jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
(original)
+++
jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
Wed May 9 15:52:35 2012
@@ -16,16 +16,22 @@
*/
package org.apache.jackrabbit.oak.jcr;

+import java.util.Calendar;
+
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.ValueFactory;

public class TestContentLoader {

public void loadTestContent(Session session) throws RepositoryException {

- getOrAddNode(session.getRootNode(), "testdata");
+ Node data = getOrAddNode(session.getRootNode(), "testdata");
+ addPropertyTestData(getOrAddNode(data, "property"));
+
session.save();
}

@@ -36,4 +42,20 @@ public class TestContentLoader {
return node.addNode(name);
}
}
+
+ /**
+ * Creates a boolean, double, long, calendar and a path property at the
+ * given node.
+ */
+ private void addPropertyTestData(Node node) throws
RepositoryException {
+ node.setProperty("boolean", true);
+ node.setProperty("double", Math.PI);
+ node.setProperty("long", 90834953485278298l);
+ Calendar c = Calendar.getInstance();
+ c.set(2005, 6, 18, 17, 30);
+ node.setProperty("calendar", c);
+ ValueFactory factory = node.getSession().getValueFactory();
+ node.setProperty("path", factory.createValue("/", PropertyType.PATH));
+ node.setProperty("multi", new String[] { "one", "two", "three" });
+ }
}

Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java

URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1336250&r1=1336249&r2=1336250&view=diff

==============================================================================

---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Wed May 9 15:52:35 2012
@@ -365,6 +365,12 @@ public class NodeImpl extends ItemImpl i
checkStatus();

String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
+
+ // TODO: hack
+ if (".".equals(oakPath)) {
+ return this;
+ }
+
NodeDelegate nd = dlg.getChild(oakPath);
if (nd == null) {
throw new PathNotFoundException(relPath);

Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java

URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java?rev=1336250&r1=1336249&r2=1336250&view=diff

==============================================================================

---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
Wed May 9 15:52:35 2012
@@ -113,7 +113,13 @@ class ValueImpl implements Value {
@Override
public BigDecimal getDecimal() throws RepositoryException {
try {
- return value.getDecimal();
+ switch (getType()) {
+ case PropertyType.DATE:
+ Calendar cal = getDate();
+ return BigDecimal.valueOf(cal.getTimeInMillis());
+ default:
+ return value.getDecimal();
+ }
} catch (NumberFormatException e) {
throw new ValueFormatException("Incompatible type " +
PropertyType.nameFromValue(getType()));
}
@@ -125,7 +131,13 @@ class ValueImpl implements Value {
@Override
public double getDouble() throws RepositoryException {
try {
- return value.getDouble();
+ switch (getType()) {
+ case PropertyType.DATE:
+ Calendar cal = getDate();
+ return cal.getTimeInMillis();
+ default:
+ return value.getDouble();
+ }
} catch (NumberFormatException e) {
throw new ValueFormatException("Incompatible type " +
PropertyType.nameFromValue(getType()));
}
@@ -137,7 +149,13 @@ class ValueImpl implements Value {
@Override
public long getLong() throws RepositoryException {
try {
- return value.getLong();
+ switch (getType()) {
+ case PropertyType.DATE:
+ Calendar cal = getDate();
+ return cal.getTimeInMillis();
+ default:
+ return value.getLong();
+ }
} catch (NumberFormatException e) {
throw new ValueFormatException("Incompatible type " +
PropertyType.nameFromValue(getType()));
}




Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>MacRoman
===================================================================
--- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java   
(revision 1336286)
+++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java   
(revision )
@@ -365,12 +365,6 @@
         checkStatus();
 
         String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
-        
-        // TODO: hack
-        if (".".equals(oakPath)) {
-            return this;
-        }
-        
         NodeDelegate nd = dlg.getChild(oakPath);
         if (nd == null) {
             throw new PathNotFoundException(relPath);
Index: 
oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>MacRoman
===================================================================
--- 
oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
   (revision 1336286)
+++ 
oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
   (revision )
@@ -131,6 +131,10 @@
             return null;
         }
 
+        if (elements.isEmpty()) {
+            return "";
+        }
+
         StringBuilder oakPath = new StringBuilder();
         for (String element : elements) {
             if (element.isEmpty()) {
@@ -143,11 +147,6 @@
             }
         }
 
-        // empty path: map to "."
-        if (oakPath.length() == 0) {
-            return ".";
-        }
-        
         // root path is special-cased early on so it does not need to
         // be considered here
         oakPath.deleteCharAt(oakPath.length() - 1);
@@ -221,6 +220,10 @@
 
         JcrPathParser.parse(oakPath, listener);
 
+        if (elements.isEmpty()) {
+            return ".";
+        }
+
         StringBuilder jcrPath = new StringBuilder();
         for (String element : elements) {
             if (element.isEmpty()) {
@@ -231,11 +234,6 @@
                 jcrPath.append(element);
                 jcrPath.append('/');
             }
-        }
-
-        // empty path: map to "."
-        if (jcrPath.length() == 0) {
-            return ".";
         }
 
         jcrPath.deleteCharAt(jcrPath.length() - 1);

Reply via email to