jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1136368 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Thu, 16 Jun 2011 10:48:45 GMT
Author: mduerig
Date: Thu Jun 16 10:48:45 2011
New Revision: 1136368

URL: http://svn.apache.org/viewvc?rev=1136368&view=rev
Log:
spi2microkernel prototype (WIP)
write: set primary type

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1136368&r1=1136367&r2=1136368&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Thu Jun 16 10:48:45 2011
@@ -385,7 +385,7 @@ public class RepositoryServiceImpl exten
             try {
                 StringBuilder sb = new StringBuilder();
                 JsonBuilder.create(sb)
-                    .value(Paths.translateQName(NameConstants.JCR_PRIMARYTYPE), Paths.translateQName(nodetypeName))
+                    .value(Paths.translateQName(NameConstants.JCR_PRIMARYTYPE), nodetypeName.toString())
                     .build();
 
                 jsop.append('+').append(target(parentId, nodeName)).append(" : ").append(sb.toString()).append('\n');
@@ -438,8 +438,7 @@ public class RepositoryServiceImpl exten
         }
 
         public void setPrimaryType(NodeId nodeId, Name primaryNodeTypeName) throws RepositoryException
{
-            // todo implement setPrimaryType
-            throw new UnsupportedRepositoryOperationException("setPrimaryType");
+            setProperty(nodeId, NameConstants.JCR_PRIMARYTYPE, Values.create(primaryNodeTypeName));
         }
 
         public void move(NodeId srcNodeId, NodeId destParentNodeId, Name destName) throws
RepositoryException {

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java?rev=1136368&r1=1136367&r2=1136368&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
Thu Jun 16 10:48:45 2011
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.Listener;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.NodeInfoBuilder;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.PropertyInfoBuilder;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 
@@ -208,11 +209,15 @@ public final class ItemInfos {
 
         @Override
         public boolean primitive(Object value) throws ParseException, IOException {
-            if (currentKey.startsWith(":")) {  // ignore other internal values
-                return !infoListener.done();
-            }
-
             try {
+                if (Paths.translateQName(NameConstants.JCR_PRIMARYTYPE).equals(currentKey))
{
+                    nodeInfoBuilder.setPrimaryType(Values.create(value).getName());
+                }
+                
+                if (currentKey.startsWith(":")) {  // ignore other internal values
+                    return !infoListener.done();
+                }
+
                 if (propertyInfoBuilder == null) {
                     nodeInfoBuilder.createPropertyInfo()
                         .setName(Paths.translateName(currentKey))

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java?rev=1136368&r1=1136367&r2=1136368&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
Thu Jun 16 10:48:45 2011
@@ -20,6 +20,7 @@
 package org.apache.jackrabbit.spi2microkernel.util;
 
 import org.apache.jackrabbit.mk.json.JsonBuilder;
+import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
@@ -195,6 +196,10 @@ public final class Values {
         }
     }
 
+    public static String create(Name name) {
+        return typeEncode(PropertyType.NAME, JsonBuilder.escape(name.toString()));
+    }
+
     public static String create(QValue value) throws RepositoryException {
         int type = value.getType();
         
@@ -261,7 +266,7 @@ public final class Values {
     private static String typeEncode(int type, String value) {
         return "\"" + TYPES[type] + ':' + value + '\"';
     }
-    
+
     private static QValue create(boolean value) {
         try {
             return FACTORY.create(value);

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1136368&r1=1136367&r2=1136368&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Thu Jun 16 10:48:45 2011
@@ -20,6 +20,9 @@ package org.apache.jackrabbit.spi2microk
 
 import org.apache.jackrabbit.mk.MicroKernelFactory;
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.json.JsonBuilder;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi2microkernel.util.Paths;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -37,6 +40,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.RepositoryFactory;
 import javax.jcr.Session;
 import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.math.BigDecimal;
@@ -64,6 +68,9 @@ public class RepositoryTest {
         MicroKernel mk = MicroKernelFactory.getInstance(URL + ";clean");
         String head = mk.getHeadRevision();
 
+        String ptUnstructured = '\"' + JsonBuilder.escape(Paths.translateQName(NameConstants.JCR_PRIMARYTYPE))
+ "\":" +
+                "\"7:" + NodeType.NT_UNSTRUCTURED + '\"';
+
         if (!mk.nodeExists("/default", head)) {
             head = mk.commit("/",
                 "+\"default\" : {" +
@@ -75,7 +82,7 @@ public class RepositoryTest {
         }
 
         if (!mk.nodeExists("/default/{}" + testNode, head)) {
-            mk.commit("/default", "+\"{}" + testNode + "\" : {}", head);
+            mk.commit("/default", "+\"{}" + testNode + "\" : {" + ptUnstructured + '}', head);
         }
 
         mk.dispose();
@@ -728,6 +735,26 @@ public class RepositoryTest {
         }
     }
 
+    @Test
+    public void setPrimaryType() throws RepositoryException {
+        Node testNode = getNode(testPath);
+        assertEquals("nt:unstructured", testNode.getPrimaryNodeType().getName());
+        assertEquals("nt:unstructured", testNode.getProperty("jcr:primaryType").getString());
+
+        testNode.setPrimaryType("nt:base");
+        testNode.getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            testNode = session2.getNode(testPath);
+            assertEquals("nt:base", testNode.getPrimaryNodeType().getName());
+            assertEquals("nt:base", testNode.getProperty("jcr:primaryType").getString());
+        }
+        finally {
+            session2.logout();
+        }
+    }
+
     //------------------------------------------< private >---
 
     private void addProperty(Node parentNode, String name, Value value) throws RepositoryException
{



Mime
View raw message