Index: oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/command/AbstractCommand.java =================================================================== --- oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/command/AbstractCommand.java (revision 1387935) +++ oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/command/AbstractCommand.java (working copy) @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.api.command; - -/** - * Base implementation of {@link Command}. - * - * @param The result type of the {@code Command}. - * - * @author BlobStore interface deals with all blob related operations of the {@link MicroKernel}. - * - *

- * Since binary storage and node storage most likely use different backend technologies two separate interfaces for - * these operations are provided. - *

- * - *

- * This interface is not only a partly {@code MicroKernel} but also provides a different layer of abstraction by - * converting the {@link String} parameters into higher level objects to ease the development for implementors of the - * {@code MicroKernel}. - *

- * - * @see NodeStore - * - * @author
- * It adds some functionality for retries and other non business logic related actions (i.e. logging, performance - * tracking, etc). - *

- * - * @see
Command Pattern - * @see CommandExecutor - * - * @param - * The result type of the {@code Command}. - * - * @author Command Pattern. - * - *

- * The implementation of this class contains the business logic to execute a command. - *

- * - * @see Command Pattern - * @see Command - * - * @author JSOP diff of this commit. - * - * @return The {@link String} representing the diff. - */ - String getDiff(); - - /** - * Returns the {@link List} of {@link Instruction}s which were created from the diff. - * - * @see #getDiff() - * - * @return The {@link List} of {@link Instruction}s. - */ - List getInstructions(); - - /** - * Returns the message of the commit. - * - * @return The message. - */ - String getMessage(); - - /** - * Returns the path of the root node of this commit. - * - * @return The path of the root node. - */ - String getPath(); - - /** - * Returns the revision id of this commit if known already, else this will return {@code null}. The revision - * id will be determined only after the commit has been successfully performed. - * - * @see #setRevisionId(String) - * - * @return The revision id of this commit or {@code null}. - */ - String getRevisionId(); - - /** - * Sets the revision id of this commit. - * - * @see #getRevisionId() - * - * @param revisionId The revision id to set. - */ - void setRevisionId(String revisionId); - - - /** - * Returns the timestamp of this commit. - * - * @return The timestamp of this commit. - */ - long getTimestamp(); -} Index: oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/CommitBuilder.java =================================================================== --- oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/CommitBuilder.java (revision 1387935) +++ oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/CommitBuilder.java (working copy) @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl.builder; - -import org.apache.jackrabbit.mongomk.api.model.Commit; -import org.apache.jackrabbit.mongomk.api.model.Instruction.AddNodeInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.AddPropertyInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.CopyNodeInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.MoveNodeInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.RemoveNodeInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.SetPropertyInstruction; -import org.apache.jackrabbit.mongomk.impl.json.DefaultJsopHandler; -import org.apache.jackrabbit.mongomk.impl.json.JsopParser; -import org.apache.jackrabbit.mongomk.impl.model.AddNodeInstructionImpl; -import org.apache.jackrabbit.mongomk.impl.model.AddPropertyInstructionImpl; -import org.apache.jackrabbit.mongomk.impl.model.CommitImpl; -import org.apache.jackrabbit.mongomk.impl.model.CopyNodeInstructionImpl; -import org.apache.jackrabbit.mongomk.impl.model.MoveNodeInstructionImpl; -import org.apache.jackrabbit.mongomk.impl.model.RemoveNodeInstructionImpl; -import org.apache.jackrabbit.mongomk.impl.model.SetPropertyInstructionImpl; - -/** - * A builder to convert a JSOP diff into a {@link Commit}. - * - * @author instructions = commit.getInstructions(); - Assert.assertEquals(6, instructions.size()); - InstructionAssert.assertAddNodeInstruction((AddNodeInstruction) instructions.get(0), "/a"); - InstructionAssert.assertAddPropertyInstruction((AddPropertyInstruction) instructions.get(1), "/a", "int", 1); - InstructionAssert.assertAddNodeInstruction((AddNodeInstruction) instructions.get(2), "/a/b"); - InstructionAssert.assertAddPropertyInstruction((AddPropertyInstruction) instructions.get(3), "/a/b", "string", - "foo"); - InstructionAssert.assertAddNodeInstruction((AddNodeInstruction) instructions.get(4), "/a/c"); - InstructionAssert.assertAddPropertyInstruction((AddPropertyInstruction) instructions.get(5), "/a/c", "bool", - true); - } - - @Test - public void testSimpleCopy() throws Exception { - StringBuilder sb = new StringBuilder(); - sb.append("*\"a\" : \"b\"\n"); - sb.append("*\"a/b\" : \"a/c\"\n"); - - Commit commit = this.buildAndAssertCommit(sb.toString()); - List instructions = commit.getInstructions(); - assertEquals(2, instructions.size()); - InstructionAssert.assertCopyNodeInstruction((CopyNodeInstruction) instructions.get(0), "/", "/a", "/b"); - InstructionAssert.assertCopyNodeInstruction((CopyNodeInstruction) instructions.get(1), "/", "/a/b", "/a/c"); - } - - @Test - public void testSimpleMove() throws Exception { - StringBuilder sb = new StringBuilder(); - sb.append(">\"a\" : \"b\"\n"); - sb.append(">\"a/b\" : \"a/c\"\n"); - - Commit commit = this.buildAndAssertCommit(sb.toString()); - List instructions = commit.getInstructions(); - assertEquals(2, instructions.size()); - InstructionAssert.assertMoveNodeInstruction((MoveNodeInstruction) instructions.get(0), "/", "/a", "/b"); - InstructionAssert.assertMoveNodeInstruction((MoveNodeInstruction) instructions.get(1), "/", "/a/b", "/a/c"); - } - - @Test - public void testSimpleRemove() throws Exception { - StringBuilder sb = new StringBuilder(); - sb.append("-\"a\""); - // TODO properties - - Commit commit = this.buildAndAssertCommit(sb.toString()); - - List instructions = commit.getInstructions(); - assertEquals(1, instructions.size()); - InstructionAssert.assertRemoveNodeInstruction((RemoveNodeInstruction) instructions.get(0), "/a"); - } - - @Test - public void testSimpleSet() throws Exception { - StringBuilder sb = new StringBuilder(); - sb.append("^\"a\" : \"b\"\n"); - - Commit commit = this.buildAndAssertCommit(sb.toString()); - - List instructions = commit.getInstructions(); - assertEquals(1, instructions.size()); - InstructionAssert.assertSetPropertyInstruction((SetPropertyInstruction) instructions.get(0), "/", "a", "b"); - } - - private Commit buildAndAssertCommit(String commitString) throws Exception { - Commit commit = CommitBuilder.build(ROOT, commitString, MESSAGE); - - assertNotNull(commit); - assertEquals(MESSAGE, commit.getMessage()); - assertNull(commit.getRevisionId()); - return commit; - } -} Index: oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitImpl.java =================================================================== --- oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitImpl.java (revision 1387935) +++ oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitImpl.java (working copy) @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl.model; - -import java.util.Collections; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - -import org.apache.jackrabbit.mongomk.api.model.Commit; -import org.apache.jackrabbit.mongomk.api.model.Instruction; - - -/** - * Implementation of {@link Commit}. - * - * @author - * Each event callback has an empty default implementation. An implementor may choose the appropriate methods to - * overwrite. - *

- */ -public class DefaultJsopHandler { - - /** - * Event: A node has been added. - * - * @param parentPath The path where the node was added to. - * @param name The name of the added node. - */ - public void nodeAdded(String parentPath, String name) { - // No-op - } - - /** - * Event: A node was copied. - * - * @param rootPath The root path where the copy took place. - * @param oldPath The old path of the node (relative to the root path). - * @param newPath The new path of the node (relative to the root path). - */ - public void nodeCopied(String rootPath, String oldPath, String newPath) { - // No-op - } - - /** - * Event: A node was moved. - * - * @param rootPath The root path where the copy took place. - * @param oldPath The old path of the node (relative to the root path). - * @param newPath The new path of the node (relative to the root path). - */ - public void nodeMoved(String rootPath, String oldPath, String newPath) { - // No-op - } - - /** - * Event: A node was removed. - * - * @param parentPath The path where the node was removed from. - * @param name The name of the node. - */ - public void nodeRemoved(String parentPath, String name) { - // No-op - } - - /** - * Event: A property was added. - * - * @param path The path of the node where the property was added. - * @param key The key of the property. - * @param value The value of the property. - */ - public void propertyAdded(String path, String key, Object value) { - // No-op - } - - /** - * Event: A property was set. - * - * @param path The path of the node where the property was set. - * @param key The key of the property. - * @param value The value of the property. - */ - public void propertySet(String path, String key, Object value) { - // No-op - } -} Index: oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/model/Instruction.java =================================================================== --- oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/model/Instruction.java (revision 1387935) +++ oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/model/Instruction.java (working copy) @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.api.model; - -/** - * An {@code Instruction} is an abstraction of a single
JSOP - * operation. - * - *

- * Each operation is a concrete subinterface of {@code Instruction} and extending it by the specific properties of the - * operation. There is no exact 1 : 1 mapping between a {@code JSOP} operation and a subinterface, i.e. in {@code JSOP} - * there is one add operation for adding nodes and properties whereas there are two specific subinterfaces; one for - * adding a node and one for adding a property. - *

- * - * @author "+" STRING ":" (ATOM | ARRAY) - */ - public interface AddPropertyInstruction extends Instruction { - - /** - * Returns the key of the property to add. - * - * @return The key. - */ - String getKey(); - - /** - * Returns the value of the property to add. - * - * @return The value. - */ - Object getValue(); - } - - /** - * The copy node operation => "*" STRING ":" STRING - */ - public interface CopyNodeInstruction extends Instruction { - - /** - * Returns the destination path. - * - * @return the destination path. - */ - String getDestPath(); - - /** - * Returns the source path. - * - * @return the source path. - */ - String getSourcePath(); - } - - /** - * The move node operation => ">" STRING ":" STRING - */ - public interface MoveNodeInstruction extends Instruction { - - /** - * Returns the destination path. - * - * @return the destination path. - */ - String getDestPath(); - - /** - * Returns the source path. - * - * @return the source path. - */ - String getSourcePath(); - } - - /** - * The remove node operation => "-" STRING - */ - public interface RemoveNodeInstruction extends Instruction { - } - - /** - * The set property operation => "^" STRING ":" ATOM | ARRAY - */ - public interface SetPropertyInstruction extends Instruction { - - /** - * Returns the key of the property to set. - * - * @return The key. - */ - String getKey(); - - /** - * Returns the value of the property to set. - * - * @return The value. - */ - Object getValue(); - } -} \ No newline at end of file Index: oak-mongomk-impl/src/test/java/org/apache/jackrabbit/mongomk/impl/InstructionAssert.java =================================================================== --- oak-mongomk-impl/src/test/java/org/apache/jackrabbit/mongomk/impl/InstructionAssert.java (revision 1387935) +++ oak-mongomk-impl/src/test/java/org/apache/jackrabbit/mongomk/impl/InstructionAssert.java (working copy) @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl; - -import static junit.framework.Assert.assertEquals; - -import org.apache.jackrabbit.mongomk.api.model.Instruction.AddNodeInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.AddPropertyInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.CopyNodeInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.MoveNodeInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.RemoveNodeInstruction; -import org.apache.jackrabbit.mongomk.api.model.Instruction.SetPropertyInstruction; - - -/** - * @author Visitor to iterate through a list of - * {@code Instruction}s without the need to use {@code instanceof} on each item. - */ -public interface InstructionVisitor { - - /** - * Visits a {@code AddNodeInstruction}. - * - * @param instruction - * The instruction. - */ - void visit(AddNodeInstruction instruction); - - /** - * Visits a {@code AddPropertyInstruction}. - * - * @param instruction The instruction. - */ - void visit(AddPropertyInstruction instruction); - - /** - * Visits a {@code CopyNodeInstruction}. - * - * @param instruction The instruction. - */ - void visit(CopyNodeInstruction instruction); - - /** - * Visits a {@code MoveNodeInstruction}. - * - * @param instruction The instruction. - */ - void visit(MoveNodeInstruction instruction); - - /** - * Visits a {@code RemoveNodeInstruction}. - * - * @param instruction The instruction. - */ - void visit(RemoveNodeInstruction instruction); - - /** - * Visits a {@code SetPropertyInstruction}. - * - * @param instruction The instruction. - */ - void visit(SetPropertyInstruction instruction); -} \ No newline at end of file Index: oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java =================================================================== --- oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java (revision 1387935) +++ oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java (working copy) @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl.json; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.apache.jackrabbit.mk.json.JsopBuilder; -import org.apache.jackrabbit.mongomk.api.model.Node; -import org.apache.jackrabbit.mongomk.impl.NodeFilter; -import org.json.JSONArray; -import org.json.JSONObject; - - -/** - * FIXME - [Mete] This should really merge with MicroKernelImpl#toJson. - * - * JSON related utility classes. - * - * @author properties = node.getProperties(); - if (properties != null) { - for (Map.Entry entry : properties.entrySet()) { - String key = entry.getKey(); - if (filter == null || filter.includeProperty(key)) { - Object value = entry.getValue(); - builder.key(key); - if (value instanceof String) { - builder.value(value.toString()); - } else { - builder.encodedValue(value.toString()); - } - } - } - } - - long childCount = node.getChildCount(); - if (inclVirtualProps) { - if (filter == null || filter.includeProperty(":childNodeCount")) { - // :childNodeCount is by default always included - // unless it is explicitly excluded in the filter - builder.key(":childNodeCount").value(childCount); - } - // FIXME [Mete] See if :hash is still being used. - /*check whether :hash has been explicitly included - if (filter != null) { - NameFilter nf = filter.getPropertyFilter(); - if (nf != null - && nf.getInclusionPatterns().contains(":hash") - && !nf.getExclusionPatterns().contains(":hash")) { - builder.key(":hash").value(rep.getRevisionStore().getId(node).toString()); - } - } - */ - } - - // FIXME [Mete] There's still some more work here. - Iterator entries = node.getChildEntries(offset, maxChildNodes); - while (entries.hasNext()) { - Node child = entries.next(); - int numSiblings = 0; - if (maxChildNodes != -1 && ++numSiblings > maxChildNodes) { - break; - } - builder.key(child.getName()); - if ((depth == -1) || (currentDepth < depth)) { - convertToJson(builder, child, depth, currentDepth + 1, offset, - maxChildNodes, inclVirtualProps, filter); - } else { - builder.object(); - builder.endObject(); - } - } - - builder.endObject(); - } - - private static Object convertJsonValue(Object jsonObject) throws Exception { - if (jsonObject == JSONObject.NULL) { - return null; - } - - if (jsonObject instanceof JSONArray) { - List elements = new LinkedList(); - JSONArray dummyArray = (JSONArray) jsonObject; - for (int i = 0; i < dummyArray.length(); ++i) { - Object raw = dummyArray.get(i); - Object parsed = convertJsonValue(raw); - elements.add(parsed); - } - return elements; - } - - return jsonObject; - } - - private JsonUtil() { - // no instantiation - } -} Index: oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java =================================================================== --- oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java (revision 1387935) +++ oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java (working copy) @@ -1,202 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl.json; - -import javax.xml.parsers.SAXParser; - -import org.apache.jackrabbit.mk.json.JsopReader; -import org.apache.jackrabbit.mk.json.JsopTokenizer; -import org.apache.jackrabbit.oak.commons.PathUtils; - -/** - * An event based parser for JSOP. - * - *

- * This parser is similar to a {@link SAXParser} using a callback ({@code DefaultHandler}) to inform about certain - * events during parsing,i.e. node was added, node was removed, etc. This relieves the implementor from the burden of - * performing a semantic analysis of token which are being parsed. - *

- * - *

- * The underlying token parser is the {@link JsopTokenizer}. - *

- * - * @author ': { - parseOpMoved(); - break; - } - case '^': { - parseOpSet(); - break; - } - case '-': { - parseOpRemoved(); - break; - } - default: - throw new IllegalStateException("Unknown operation: " + (char) token); - } - } - } - - private void parseOpAdded(String currentPath) throws Exception { - String subPath = tokenizer.readString(); - String path = PathUtils.concat(currentPath, subPath); - - tokenizer.read(':'); - - if (tokenizer.matches('{')) { - String parentPath = PathUtils.denotesRoot(path) ? "" : PathUtils.getParentPath(path); - String nodeName = PathUtils.denotesRoot(path) ? "/" : PathUtils.getName(path); - defaultHandler.nodeAdded(parentPath, nodeName); - - if (!tokenizer.matches('}')) { - do { - int pos = tokenizer.getLastPos(); - String propName = tokenizer.readString(); - tokenizer.read(':'); - - if (tokenizer.matches('{')) { // parse a nested node - tokenizer.setPos(pos); // resetting to last post b/c parseOpAdded expects the whole json - tokenizer.read(); - parseOpAdded(path); - } else { // parse property - String valueAsString = tokenizer.readRawValue().trim(); - Object value = JsonUtil.convertJsonValue(valueAsString); - - defaultHandler.propertyAdded(path, propName, value); - } - } while (tokenizer.matches(',')); - - tokenizer.read('}'); // explicitly close the bracket - } - } - } - - private void parseOpCopied() throws Exception { - int pos = tokenizer.getLastPos(); - String subPath = tokenizer.readString(); - String srcPath = PathUtils.concat(path, subPath); - if (!PathUtils.isAbsolute(srcPath)) { - throw new Exception("Absolute path expected: " + srcPath + ", pos: " + pos); - } - tokenizer.read(':'); - String targetPath = tokenizer.readString(); - if (!PathUtils.isAbsolute(targetPath)) { - targetPath = PathUtils.concat(path, targetPath); - if (!PathUtils.isAbsolute(targetPath)) { - throw new Exception("Absolute path expected: " + targetPath + ", pos: " + pos); - } - } - defaultHandler.nodeCopied(path, srcPath, targetPath); - } - - private void parseOpMoved() throws Exception { - int pos = tokenizer.getLastPos(); - String subPath = tokenizer.readString(); - String srcPath = PathUtils.concat(path, subPath); - if (!PathUtils.isAbsolute(srcPath)) { - throw new Exception("Absolute path expected: " + srcPath + ", pos: " + pos); - } - tokenizer.read(':'); - pos = tokenizer.getLastPos(); - String targetPath = tokenizer.readString(); - if (!PathUtils.isAbsolute(targetPath)) { - targetPath = PathUtils.concat(path, targetPath); - if (!PathUtils.isAbsolute(targetPath)) { - throw new Exception("absolute path expected: " + targetPath + ", pos: " + pos); - } - } - defaultHandler.nodeMoved(path, srcPath, targetPath); - } - - private void parseOpSet() throws Exception { - int pos = tokenizer.getLastPos(); - String subPath = tokenizer.readString(); - tokenizer.read(':'); - String value; - if (tokenizer.matches(JsopReader.NULL)) { - value = null; - } else { - value = tokenizer.readRawValue().trim(); - } - String targetPath = PathUtils.concat(path, subPath); - if (!PathUtils.isAbsolute(targetPath)) { - throw new Exception("Absolute path expected: " + targetPath + ", pos: " + pos); - } - String parentPath = PathUtils.getParentPath(targetPath); - String propName = PathUtils.getName(targetPath); - defaultHandler.propertySet(parentPath, propName, JsonUtil.convertJsonValue(value)); - } - - private void parseOpRemoved() throws Exception { - int pos = tokenizer.getLastPos(); - String subPath = tokenizer.readString(); - String targetPath = PathUtils.concat(path, subPath); - if (!PathUtils.isAbsolute(targetPath)) { - throw new Exception("Absolute path expected: " + targetPath + ", pos: " + pos); - } - defaultHandler.nodeRemoved(path, subPath); - } -} \ No newline at end of file Index: oak-mongomk-impl/src/test/java/org/apache/jackrabbit/mongomk/impl/json/JsopParserTest.java =================================================================== --- oak-mongomk-impl/src/test/java/org/apache/jackrabbit/mongomk/impl/json/JsopParserTest.java (revision 1387935) +++ oak-mongomk-impl/src/test/java/org/apache/jackrabbit/mongomk/impl/json/JsopParserTest.java (working copy) @@ -1,543 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl.json; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -import org.apache.jackrabbit.mongomk.impl.json.DefaultJsopHandler; -import org.apache.jackrabbit.mongomk.impl.json.JsopParser; -import org.junit.Assert; -import org.junit.Test; - -/** - * @author nodesAdded; - private final List nodesCopied; - private final List nodesMoved; - private final List nodesRemoved; - private final List propertiesAdded; - private final List propertiesSet; - - CountingHandler() { - this.nodesAdded = new LinkedList(); - this.nodesCopied = new LinkedList(); - this.nodesMoved = new LinkedList(); - this.nodesRemoved = new LinkedList(); - this.propertiesAdded = new LinkedList(); - this.propertiesSet = new LinkedList(); - } - - public void assertNodeCopied(String parentPath, String oldPath, String newPath) { - NodeMoved expected = new NodeMoved(parentPath, oldPath, newPath); - - int firstIndex = this.nodesCopied.indexOf(expected); - int lastIndex = this.nodesCopied.lastIndexOf(expected); - - Assert.assertTrue(firstIndex != -1); - Assert.assertEquals(firstIndex, lastIndex); - } - - public void assertNodeMoved(String parentPath, String oldPath, String newPath) { - NodeMoved expected = new NodeMoved(parentPath, oldPath, newPath); - - int firstIndex = this.nodesMoved.indexOf(expected); - int lastIndex = this.nodesMoved.lastIndexOf(expected); - - Assert.assertTrue(firstIndex != -1); - Assert.assertEquals(firstIndex, lastIndex); - } - - public void assertNodeRemoved(String path, String name) { - Node expected = new Node(path, name); - - int firstIndex = this.nodesRemoved.indexOf(expected); - int lastIndex = this.nodesRemoved.lastIndexOf(expected); - - Assert.assertTrue(firstIndex != -1); - Assert.assertEquals(firstIndex, lastIndex); - } - - public void assertNoOfNodesCopied(int num) { - Assert.assertEquals(num, this.nodesCopied.size()); - } - - public void assertNoOfNodesMoved(int num) { - Assert.assertEquals(num, this.nodesMoved.size()); - } - - public void assertNoOfNodesRemoved(int num) { - Assert.assertEquals(num, this.nodesRemoved.size()); - } - - public void assertNoOfPropertiesSet(int num) { - Assert.assertEquals(num, this.propertiesSet.size()); - } - - public void assertPropertiesAdded(int num) { - Assert.assertEquals(num, this.propertiesAdded.size()); - } - - @Override - public void nodeAdded(String path, String name) { - this.nodesAdded.add(new Node(path, name)); - } - - @Override - public void nodeCopied(String rootPath, String oldPath, String newPath) { - this.nodesCopied.add(new NodeMoved(rootPath, oldPath, newPath)); - } - - @Override - public void nodeMoved(String rootPath, String oldPath, String newPath) { - this.nodesMoved.add(new NodeMoved(rootPath, oldPath, newPath)); - } - - @Override - public void nodeRemoved(String path, String name) { - this.nodesRemoved.add(new Node(path, name)); - } - - @Override - public void propertyAdded(String path, String key, Object value) { - this.propertiesAdded.add(new Property(path, key, value)); - } - - @Override - public void propertySet(String path, String key, Object value) { - this.propertiesSet.add(new Property(path, key, value)); - } - - void assertNodeAdded(String path, String name) { - Node expected = new Node(path, name); - - int firstIndex = this.nodesAdded.indexOf(expected); - int lastIndex = this.nodesAdded.lastIndexOf(expected); - - Assert.assertTrue(firstIndex != -1); - Assert.assertEquals(firstIndex, lastIndex); - } - - void assertPropertyAdded(String path, String key, Object value) { - Property expected = new Property(path, key, value); - - int firstIndex = this.propertiesAdded.indexOf(expected); - int lastIndex = this.propertiesAdded.lastIndexOf(expected); - - Assert.assertTrue(firstIndex != -1); - Assert.assertEquals(firstIndex, lastIndex); - } - - void assertPropertySet(String path, String key, Object value) { - Property expected = new Property(path, key, value); - - int firstIndex = this.propertiesSet.indexOf(expected); - int lastIndex = this.propertiesSet.lastIndexOf(expected); - - Assert.assertTrue(firstIndex != -1); - Assert.assertEquals(firstIndex, lastIndex); - } - - void assetNoOfNodesAdded(int num) { - Assert.assertEquals(num, this.nodesAdded.size()); - } - - } - - @Test - public void testAddNestedNodes() throws Exception { - String rootPath = "/"; - StringBuilder sb = new StringBuilder(); - sb.append("+\"a\" : { \"integer\" : 123 ,\"b\" : { \"double\" : 123.456 , \"d\" : {} } , \"c\" : { \"string\" : \"string\" }}"); - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); - - jsopParser.parse(); - - countingHandler.assetNoOfNodesAdded(4); - countingHandler.assertNodeAdded("/", "a"); - countingHandler.assertNodeAdded("/a", "b"); - countingHandler.assertNodeAdded("/a/b", "d"); - countingHandler.assertNodeAdded("/a", "c"); - - countingHandler.assertPropertiesAdded(3); - countingHandler.assertPropertyAdded("/a", "integer", 123); - countingHandler.assertPropertyAdded("/a/b", "double", 123.456); - countingHandler.assertPropertyAdded("/a/c", "string", "string"); - } - - @Test - public void testAddNodesAndProperties() throws Exception { - String rootPath = "/"; - StringBuilder sb = new StringBuilder(); - sb.append("+\"a\" : { \"int\" : 1 } \n"); - sb.append("+\"a/b\" : { \"string\" : \"foo\" } \n"); - sb.append("+\"a/c\" : { \"bool\" : true }"); - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); - - jsopParser.parse(); - - countingHandler.assetNoOfNodesAdded(3); - countingHandler.assertNodeAdded("/", "a"); - countingHandler.assertNodeAdded("/a", "b"); - countingHandler.assertNodeAdded("/a", "c"); - - countingHandler.assertPropertiesAdded(3); - countingHandler.assertPropertyAdded("/a", "int", Integer.valueOf(1)); - countingHandler.assertPropertyAdded("/a/b", "string", "foo"); - countingHandler.assertPropertyAdded("/a/c", "bool", Boolean.TRUE); - } - - @Test - public void testAddNodesAndPropertiesSeparately() throws Exception { - String rootPath = "/"; - StringBuilder sb = new StringBuilder(); - sb.append("+\"a\" : {} \n"); - sb.append("+\"a\" : { \"int\" : 1 } \n"); - sb.append("+\"a/b\" : {} \n"); - sb.append("+\"a/b\" : { \"string\" : \"foo\" } \n"); - sb.append("+\"a/c\" : {} \n"); - sb.append("+\"a/c\" : { \"bool\" : true }"); - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); - - jsopParser.parse(); - - countingHandler.assetNoOfNodesAdded(6); - - countingHandler.assertPropertiesAdded(3); - countingHandler.assertPropertyAdded("/a", "int", Integer.valueOf(1)); - countingHandler.assertPropertyAdded("/a/b", "string", "foo"); - countingHandler.assertPropertyAdded("/a/c", "bool", Boolean.TRUE); - } - - @Test - public void testAddPropertiesWithComplexArray() throws Exception { - String rootPath = "/"; - String jsop = "+ \"a\" : { \"array_complex\" : [ 123, 123.456, true, false, null, \"string\", [1,2,3,4,5] ] }"; - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, jsop, countingHandler); - - jsopParser.parse(); - - countingHandler.assertPropertiesAdded(1); - countingHandler.assertPropertyAdded( - "/a", - "array_complex", - Arrays.asList(new Object[] { 123, 123.456, true, false, null, "string", - Arrays.asList(new Object[] { 1, 2, 3, 4, 5 }) })); - } - - @Test - public void testAddWithEmptyPath() throws Exception { - String rootPath = ""; - StringBuilder sb = new StringBuilder(); - sb.append("+\"/\" : { \"int\" : 1 } \n"); - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); - - jsopParser.parse(); - - countingHandler.assetNoOfNodesAdded(1); - countingHandler.assertNodeAdded("", "/"); - - countingHandler.assertPropertiesAdded(1); - countingHandler.assertPropertyAdded("/", "int", Integer.valueOf(1)); - } - - @Test - public void testSimpleAddNodes() throws Exception { - String rootPath = "/"; - StringBuilder sb = new StringBuilder(); - sb.append("+\"a\" : {} \n"); - sb.append("+\"a/b\" : {} \n"); - sb.append("+\"a/c\" : {}"); - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); - - jsopParser.parse(); - - countingHandler.assetNoOfNodesAdded(3); - countingHandler.assertNodeAdded("/", "a"); - countingHandler.assertNodeAdded("/a", "b"); - countingHandler.assertNodeAdded("/a", "c"); - } - - @Test - public void testSimpleAddProperties() throws Exception { - String rootPath = "/"; - StringBuilder sb = new StringBuilder(); - sb.append("+ \"a\" : {}"); - sb.append("+ \"a\" : { \"integer\" : 123, \"double\" : 123.456, \"true\" : true, \"false\" : false, \"null\" : null, \"string\" : \"string\", \"array\" : [1,2,3,4,5] }"); - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); - - jsopParser.parse(); - - countingHandler.assertPropertiesAdded(7); - countingHandler.assertPropertyAdded("/a", "integer", 123); - countingHandler.assertPropertyAdded("/a", "double", 123.456); - countingHandler.assertPropertyAdded("/a", "true", true); - countingHandler.assertPropertyAdded("/a", "false", false); - countingHandler.assertPropertyAdded("/a", "null", null); - countingHandler.assertPropertyAdded("/a", "string", "string"); - countingHandler.assertPropertyAdded("/a", "array", Arrays.asList(new Object[] { 1, 2, 3, 4, 5 })); - } - - @Test - public void testSimpleCopyNodes() throws Exception { - String rootPath = "/"; - StringBuilder sb = new StringBuilder(); - sb.append("*\"a\" : \"b\"\n"); - sb.append("*\"a/b\" : \"a/c\"\n"); - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); - jsopParser.parse(); - - countingHandler.assertNoOfNodesCopied(2); - countingHandler.assertNodeCopied("/", "/a", "/b"); - countingHandler.assertNodeCopied("/", "/a/b", "/a/c"); - } - - @Test - public void testSimpleMoveNodes() throws Exception { - String rootPath = "/"; - StringBuilder sb = new StringBuilder(); - sb.append(">\"a\" : \"b\"\n"); - sb.append(">\"a/b\" : \"a/c\"\n"); - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); - jsopParser.parse(); - - countingHandler.assertNoOfNodesMoved(2); - countingHandler.assertNodeMoved("/", "/a", "/b"); - countingHandler.assertNodeMoved("/", "/a/b", "/a/c"); - } - - @Test - public void testSimpleRemoveNodes() throws Exception { - String rootPath = "/"; - String jsop = "-\"a\""; - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, jsop, countingHandler); - - jsopParser.parse(); - - countingHandler.assertNoOfNodesRemoved(1); - countingHandler.assertNodeRemoved("/", "a"); - } - - @Test - public void testSimpleSetNodes() throws Exception { - String rootPath = "/"; - StringBuilder sb = new StringBuilder(); - sb.append("^\"a\" : \"b\""); - - CountingHandler countingHandler = new CountingHandler(); - JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); - jsopParser.parse(); - - countingHandler.assertNoOfPropertiesSet(1); - // TODO - Is this correct? - countingHandler.assertPropertySet("/", "a", "b"); - } -} Index: oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoMicroKernel.java =================================================================== --- oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoMicroKernel.java (revision 1387935) +++ oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoMicroKernel.java (working copy) @@ -1,213 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl; - -import java.io.InputStream; - -import org.apache.jackrabbit.mk.api.MicroKernel; -import org.apache.jackrabbit.mk.api.MicroKernelException; -import org.apache.jackrabbit.mongomk.api.BlobStore; -import org.apache.jackrabbit.mongomk.api.NodeStore; -import org.apache.jackrabbit.mongomk.api.model.Commit; -import org.apache.jackrabbit.mongomk.api.model.Node; -import org.apache.jackrabbit.mongomk.impl.builder.CommitBuilder; -import org.apache.jackrabbit.mongomk.impl.json.JsonUtil; - -/** - * The {@code MongoDB} implementation of the {@link MicroKernel}. - * - *

- * This class will transform and delegate to instances of {@link NodeStore} and {@link BlobStore}. - *

- * - * @author
0 && nodeFilter != null && nodeFilter.getChildNodeFilter() != null) { - // Both an offset > 0 and a filter on node names have been specified... - throw new IllegalArgumentException("offset > 0 with child node filter"); - } - - try { - // FIXME [Mete] Should filter, offset, and maxChildNodes be handled in Mongo instead? - Node rootNode = nodeStore.getNodes(path, revisionId, depth, offset, maxChildNodes, filter); - if (rootNode == null) { - return null; - } - return JsonUtil.convertToJson(rootNode, depth, (int)offset, maxChildNodes, true, nodeFilter); - } catch (Exception e) { - throw new MicroKernelException(e); - } - } - - @Override - public String getRevisionHistory(long since, int maxEntries, String path) throws MicroKernelException { - return nodeStore.getRevisionHistory(since, maxEntries, path); - } - - @Override - public String merge(String branchRevisionId, String message) throws MicroKernelException { - throw new UnsupportedOperationException("Merge is currently not supported."); - } - - @Override - public boolean nodeExists(String path, String revisionId) throws MicroKernelException { - boolean exists = false; - - try { - String revId = null; - if (revisionId != null) { - revId = new String(revisionId); - } - - exists = nodeStore.nodeExists(path, revId); - } catch (Exception e) { - throw new MicroKernelException(e); - } - - return exists; - } - - @Override - public int read(String blobId, long pos, byte[] buff, int off, int length) throws MicroKernelException { - int totalBytes = -1; - - try { - totalBytes = blobStore.readBlob(blobId, pos, buff, off, length); - } catch (Exception e) { - throw new MicroKernelException(e); - } - - return totalBytes; - } - - @Override - public String waitForCommit(String oldHeadRevisionId, long timeout) throws MicroKernelException, - InterruptedException { - return nodeStore.waitForCommit(oldHeadRevisionId, timeout); - } - - @Override - public String write(InputStream in) throws MicroKernelException { - String blobId = null; - - try { - blobId = blobStore.writeBlob(in); - } catch (Exception e) { - throw new MicroKernelException(e); - } - - return blobId; - } -} \ No newline at end of file Index: oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java =================================================================== --- oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java (revision 1387935) +++ oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java (working copy) @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl.model; - -import org.apache.jackrabbit.mongomk.api.model.InstructionVisitor; -import org.apache.jackrabbit.mongomk.api.model.Instruction.MoveNodeInstruction; - -public class MoveNodeInstructionImpl implements MoveNodeInstruction { - private final String destPath; - private final String path; - private final String sourcePath; - - public MoveNodeInstructionImpl(String path, String sourcePath, String destPath) { - this.path = path; - this.sourcePath = sourcePath; - this.destPath = destPath; - } - - @Override - public void accept(InstructionVisitor visitor) { - visitor.visit(this); - } - - @Override - public String getDestPath() { - return destPath; - } - - @Override - public String getPath() { - return path; - } - - @Override - public String getSourcePath() { - return sourcePath; - } -} Index: oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/model/Node.java =================================================================== --- oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/model/Node.java (revision 1387935) +++ oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/model/Node.java (working copy) @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.api.model; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * A higher level object representing a node. - * - * @author expectedChildren = expected.getChildren(); - Set actualChildren = actual.getChildren(); - - if (expectedChildren == null) { - Assert.assertNull(actualChildren); - } else { - Assert.assertNotNull(actualChildren); - Assert.assertEquals(expectedChildren.size(), actualChildren.size()); - - for (Node expectedChild : expectedChildren) { - boolean valid = false; - for (Node actualChild : actualChildren) { - if (expectedChild.getName().equals(actualChild.getName())) { - assertDeepEquals(expectedChild, actualChild); - valid = true; - - break; - } - } - - Assert.assertTrue(valid); - } - } - } - - public static void assertEquals(Collection expecteds, Collection actuals) { - Assert.assertEquals(expecteds.size(), actuals.size()); - - for (Node expected : expecteds) { - boolean valid = false; - for (Node actual : actuals) { - if (expected.getPath().equals(actual.getPath())) { - assertEquals(expected, actual); - valid = true; - - break; - } - } - - Assert.assertTrue(valid); - } - } - - public static void assertEquals(Node expected, Node actual) { - Assert.assertEquals(expected.getName(), actual.getName()); - Assert.assertEquals(expected.getPath(), actual.getPath()); - - String expectedRevisionId = expected.getRevisionId(); - String actualRevisionId = actual.getRevisionId(); - - if (expectedRevisionId == null) { - Assert.assertNull(actualRevisionId); - } - if (actualRevisionId == null) { - Assert.assertNull(expectedRevisionId); - } - - if ((actualRevisionId != null) && (expectedRevisionId != null)) { - Assert.assertEquals(expectedRevisionId, actualRevisionId); - } - - Map expectedProperties = expected.getProperties(); - Map actualProperties = actual.getProperties(); - - if (expectedProperties == null) { - Assert.assertNull(actualProperties); - } - - if (actualProperties == null) { - Assert.assertNull(expectedProperties); - } - - if ((actualProperties != null) && (expectedProperties != null)) { - Assert.assertEquals(expectedProperties, actualProperties); - } - } - - private NodeAssert() { - // no instantiation - } -} Index: oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilder.java =================================================================== --- oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilder.java (revision 1387935) +++ oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilder.java (working copy) @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl.builder; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.apache.jackrabbit.mongomk.api.model.Node; -import org.apache.jackrabbit.mongomk.impl.json.JsonUtil; -import org.apache.jackrabbit.mongomk.impl.model.NodeImpl; -import org.apache.jackrabbit.oak.commons.PathUtils; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * A builder to create {@link Node}s from JSON - * strings. - * - * @author properties = null; - for (@SuppressWarnings("rawtypes") - Iterator iterator = jsonObject.keys(); iterator.hasNext();) { - String key = (String) iterator.next(); - Object value = jsonObject.get(key); - - if (value instanceof JSONObject) { - String childPath = PathUtils.concat(realPath, key); - - Node childNode = parseNode(childPath, (JSONObject) value); - node.addChild(childNode); - } else { - if (properties == null) { - properties = new HashMap(); - } - - Object converted = JsonUtil.convertJsonValue(value.toString()); - properties.put(key, converted); - } - } - - node.setProperties(properties); - - return node; - } -} Index: oak-mongomk-impl/src/test/java/org/apache/jackrabbit/mongomk/builder/NodeBuilderTest.java =================================================================== --- oak-mongomk-impl/src/test/java/org/apache/jackrabbit/mongomk/builder/NodeBuilderTest.java (revision 1387935) +++ oak-mongomk-impl/src/test/java/org/apache/jackrabbit/mongomk/builder/NodeBuilderTest.java (working copy) @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.builder; - -import org.apache.jackrabbit.mongomk.api.model.Node; -import org.apache.jackrabbit.mongomk.impl.NodeAssert; -import org.apache.jackrabbit.mongomk.impl.builder.NodeBuilder; -import org.apache.jackrabbit.mongomk.impl.model.NodeImpl; -import org.junit.Test; - - -/** - * @author l = new ArrayList(); - t.read('['); - do { - l.add(t.readString()); - } while (t.matches(',')); - t.read(']'); - return l.toArray(new String[l.size()]); - } - - NameFilter getChildNodeFilter() { - return nodeFilter; - } - - NameFilter getPropertyFilter() { - return propFilter; - } - - boolean includeNode(String name) { - return nodeFilter == null || nodeFilter.matches(name); - } - - public boolean includeProperty(String name) { - return propFilter == null || propFilter.matches(name); - } -} \ No newline at end of file Index: oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/NodeImpl.java =================================================================== --- oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/NodeImpl.java (revision 1387935) +++ oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/NodeImpl.java (working copy) @@ -1,324 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl.model; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.jackrabbit.mk.util.RangeIterator; -import org.apache.jackrabbit.mongomk.api.model.Node; -import org.apache.jackrabbit.oak.commons.PathUtils; - - -/** - * Implementation of {@link Node}. - * - * @author descendants) { - Set children = node.getChildren(); - if (children != null) { - for (Node child : children) { - descendants.add(child); - this.getDescendantsRecursive(child, descendants); - } - } - } -} Index: oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/NodeStore.java =================================================================== --- oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/NodeStore.java (revision 1387935) +++ oak-mongomk-api/src/main/java/org/apache/jackrabbit/mongomk/api/NodeStore.java (working copy) @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.api; - -import org.apache.jackrabbit.mk.api.MicroKernel; -import org.apache.jackrabbit.mongomk.api.model.Commit; -import org.apache.jackrabbit.mongomk.api.model.Node; - -/** - * The NodeStore interface deals with all node related operations of the {@link MicroKernel}. - * - *

- * Since binary storage and node storage most likely use different backend technologies two separate interfaces for - * these operations are provided. - *

- * - *

- * This interface is not only a partly {@code MicroKernel} but also provides a different layer of abstraction by - * converting the {@link String} parameters into higher level objects to ease the development for implementors of the - * {@code MicroKernel}. - *

- * - * @see BlobStore - * - * @author
- - - - - 4.0.0 - - - org.apache.jackrabbit - oak-parent - 0.5-SNAPSHOT - - - oak-mongomk-api - - - - org.apache.jackrabbit - oak-mk - ${project.version} - - - - Index: oak-mongomk-impl/pom.xml =================================================================== --- oak-mongomk-impl/pom.xml (revision 1387935) +++ oak-mongomk-impl/pom.xml (working copy) @@ -1,73 +0,0 @@ - - - - - - 4.0.0 - - - org.apache.jackrabbit - oak-parent - 0.5-SNAPSHOT - - - oak-mongomk-impl - - - - junit - junit - test - - - org.apache.jackrabbit - oak-mk - ${project.version} - - - org.json - json - 20090211 - - - org.apache.jackrabbit - oak-mongomk-api - ${project.version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - test-jar - - - - - - - - Index: oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/RemoveNodeInstructionImpl.java =================================================================== --- oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/RemoveNodeInstructionImpl.java (revision 1387935) +++ oak-mongomk-impl/src/main/java/org/apache/jackrabbit/mongomk/impl/model/RemoveNodeInstructionImpl.java (working copy) @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.mongomk.impl.model; - -import org.apache.jackrabbit.mongomk.api.model.InstructionVisitor; -import org.apache.jackrabbit.mongomk.api.model.Instruction.RemoveNodeInstruction; -import org.apache.jackrabbit.oak.commons.PathUtils; - - -/** - * Implementation of {@link RemoveNodeInstruction}. - * - * @author The result type of the {@code Command}. + * + * @author BlobStore interface deals with all blob related operations of the {@link MicroKernel}. + * + *

+ * Since binary storage and node storage most likely use different backend technologies two separate interfaces for + * these operations are provided. + *

+ * + *

+ * This interface is not only a partly {@code MicroKernel} but also provides a different layer of abstraction by + * converting the {@link String} parameters into higher level objects to ease the development for implementors of the + * {@code MicroKernel}. + *

+ * + * @see NodeStore + * + * @author
+ * It adds some functionality for retries and other non business logic related actions (i.e. logging, performance + * tracking, etc). + *

+ * + * @see
Command Pattern + * @see CommandExecutor + * + * @param + * The result type of the {@code Command}. + * + * @author Command Pattern. + * + *

+ * The implementation of this class contains the business logic to execute a command. + *

+ * + * @see Command Pattern + * @see Command + * + * @author JSOP diff of this commit. + * + * @return The {@link String} representing the diff. + */ + String getDiff(); + + /** + * Returns the {@link List} of {@link Instruction}s which were created from the diff. + * + * @see #getDiff() + * + * @return The {@link List} of {@link Instruction}s. + */ + List getInstructions(); + + /** + * Returns the message of the commit. + * + * @return The message. + */ + String getMessage(); + + /** + * Returns the path of the root node of this commit. + * + * @return The path of the root node. + */ + String getPath(); + + /** + * Returns the revision id of this commit if known already, else this will return {@code null}. The revision + * id will be determined only after the commit has been successfully performed. + * + * @see #setRevisionId(String) + * + * @return The revision id of this commit or {@code null}. + */ + String getRevisionId(); + + /** + * Sets the revision id of this commit. + * + * @see #getRevisionId() + * + * @param revisionId The revision id to set. + */ + void setRevisionId(String revisionId); + + + /** + * Returns the timestamp of this commit. + * + * @return The timestamp of this commit. + */ + long getTimestamp(); +} Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Commit.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/CommitBuilder.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/CommitBuilder.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/CommitBuilder.java (working copy) @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl.builder; + +import org.apache.jackrabbit.mongomk.api.model.Commit; +import org.apache.jackrabbit.mongomk.api.model.Instruction.AddNodeInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.AddPropertyInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.CopyNodeInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.MoveNodeInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.RemoveNodeInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.SetPropertyInstruction; +import org.apache.jackrabbit.mongomk.impl.json.DefaultJsopHandler; +import org.apache.jackrabbit.mongomk.impl.json.JsopParser; +import org.apache.jackrabbit.mongomk.impl.model.AddNodeInstructionImpl; +import org.apache.jackrabbit.mongomk.impl.model.AddPropertyInstructionImpl; +import org.apache.jackrabbit.mongomk.impl.model.CommitImpl; +import org.apache.jackrabbit.mongomk.impl.model.CopyNodeInstructionImpl; +import org.apache.jackrabbit.mongomk.impl.model.MoveNodeInstructionImpl; +import org.apache.jackrabbit.mongomk.impl.model.RemoveNodeInstructionImpl; +import org.apache.jackrabbit.mongomk.impl.model.SetPropertyInstructionImpl; + +/** + * A builder to convert a JSOP diff into a {@link Commit}. + * + * @author instructions = commit.getInstructions(); + Assert.assertEquals(6, instructions.size()); + InstructionAssert.assertAddNodeInstruction((AddNodeInstruction) instructions.get(0), "/a"); + InstructionAssert.assertAddPropertyInstruction((AddPropertyInstruction) instructions.get(1), "/a", "int", 1); + InstructionAssert.assertAddNodeInstruction((AddNodeInstruction) instructions.get(2), "/a/b"); + InstructionAssert.assertAddPropertyInstruction((AddPropertyInstruction) instructions.get(3), "/a/b", "string", + "foo"); + InstructionAssert.assertAddNodeInstruction((AddNodeInstruction) instructions.get(4), "/a/c"); + InstructionAssert.assertAddPropertyInstruction((AddPropertyInstruction) instructions.get(5), "/a/c", "bool", + true); + } + + @Test + public void testSimpleCopy() throws Exception { + StringBuilder sb = new StringBuilder(); + sb.append("*\"a\" : \"b\"\n"); + sb.append("*\"a/b\" : \"a/c\"\n"); + + Commit commit = this.buildAndAssertCommit(sb.toString()); + List instructions = commit.getInstructions(); + assertEquals(2, instructions.size()); + InstructionAssert.assertCopyNodeInstruction((CopyNodeInstruction) instructions.get(0), "/", "/a", "/b"); + InstructionAssert.assertCopyNodeInstruction((CopyNodeInstruction) instructions.get(1), "/", "/a/b", "/a/c"); + } + + @Test + public void testSimpleMove() throws Exception { + StringBuilder sb = new StringBuilder(); + sb.append(">\"a\" : \"b\"\n"); + sb.append(">\"a/b\" : \"a/c\"\n"); + + Commit commit = this.buildAndAssertCommit(sb.toString()); + List instructions = commit.getInstructions(); + assertEquals(2, instructions.size()); + InstructionAssert.assertMoveNodeInstruction((MoveNodeInstruction) instructions.get(0), "/", "/a", "/b"); + InstructionAssert.assertMoveNodeInstruction((MoveNodeInstruction) instructions.get(1), "/", "/a/b", "/a/c"); + } + + @Test + public void testSimpleRemove() throws Exception { + StringBuilder sb = new StringBuilder(); + sb.append("-\"a\""); + // TODO properties + + Commit commit = this.buildAndAssertCommit(sb.toString()); + + List instructions = commit.getInstructions(); + assertEquals(1, instructions.size()); + InstructionAssert.assertRemoveNodeInstruction((RemoveNodeInstruction) instructions.get(0), "/a"); + } + + @Test + public void testSimpleSet() throws Exception { + StringBuilder sb = new StringBuilder(); + sb.append("^\"a\" : \"b\"\n"); + + Commit commit = this.buildAndAssertCommit(sb.toString()); + + List instructions = commit.getInstructions(); + assertEquals(1, instructions.size()); + InstructionAssert.assertSetPropertyInstruction((SetPropertyInstruction) instructions.get(0), "/", "a", "b"); + } + + private Commit buildAndAssertCommit(String commitString) throws Exception { + Commit commit = CommitBuilder.build(ROOT, commitString, MESSAGE); + + assertNotNull(commit); + assertEquals(MESSAGE, commit.getMessage()); + assertNull(commit.getRevisionId()); + return commit; + } +} Property changes on: oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/builder/CommitBuilderImplTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitImpl.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitImpl.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitImpl.java (working copy) @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl.model; + +import java.util.Collections; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; + +import org.apache.jackrabbit.mongomk.api.model.Commit; +import org.apache.jackrabbit.mongomk.api.model.Instruction; + + +/** + * Implementation of {@link Commit}. + * + * @author + * Each event callback has an empty default implementation. An implementor may choose the appropriate methods to + * overwrite. + *

+ */ +public class DefaultJsopHandler { + + /** + * Event: A node has been added. + * + * @param parentPath The path where the node was added to. + * @param name The name of the added node. + */ + public void nodeAdded(String parentPath, String name) { + // No-op + } + + /** + * Event: A node was copied. + * + * @param rootPath The root path where the copy took place. + * @param oldPath The old path of the node (relative to the root path). + * @param newPath The new path of the node (relative to the root path). + */ + public void nodeCopied(String rootPath, String oldPath, String newPath) { + // No-op + } + + /** + * Event: A node was moved. + * + * @param rootPath The root path where the copy took place. + * @param oldPath The old path of the node (relative to the root path). + * @param newPath The new path of the node (relative to the root path). + */ + public void nodeMoved(String rootPath, String oldPath, String newPath) { + // No-op + } + + /** + * Event: A node was removed. + * + * @param parentPath The path where the node was removed from. + * @param name The name of the node. + */ + public void nodeRemoved(String parentPath, String name) { + // No-op + } + + /** + * Event: A property was added. + * + * @param path The path of the node where the property was added. + * @param key The key of the property. + * @param value The value of the property. + */ + public void propertyAdded(String path, String key, Object value) { + // No-op + } + + /** + * Event: A property was set. + * + * @param path The path of the node where the property was set. + * @param key The key of the property. + * @param value The value of the property. + */ + public void propertySet(String path, String key, Object value) { + // No-op + } +} Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/DefaultJsopHandler.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Instruction.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Instruction.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Instruction.java (working copy) @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.api.model; + +/** + * An {@code Instruction} is an abstraction of a single
JSOP + * operation. + * + *

+ * Each operation is a concrete subinterface of {@code Instruction} and extending it by the specific properties of the + * operation. There is no exact 1 : 1 mapping between a {@code JSOP} operation and a subinterface, i.e. in {@code JSOP} + * there is one add operation for adding nodes and properties whereas there are two specific subinterfaces; one for + * adding a node and one for adding a property. + *

+ * + * @author "+" STRING ":" (ATOM | ARRAY) + */ + public interface AddPropertyInstruction extends Instruction { + + /** + * Returns the key of the property to add. + * + * @return The key. + */ + String getKey(); + + /** + * Returns the value of the property to add. + * + * @return The value. + */ + Object getValue(); + } + + /** + * The copy node operation => "*" STRING ":" STRING + */ + public interface CopyNodeInstruction extends Instruction { + + /** + * Returns the destination path. + * + * @return the destination path. + */ + String getDestPath(); + + /** + * Returns the source path. + * + * @return the source path. + */ + String getSourcePath(); + } + + /** + * The move node operation => ">" STRING ":" STRING + */ + public interface MoveNodeInstruction extends Instruction { + + /** + * Returns the destination path. + * + * @return the destination path. + */ + String getDestPath(); + + /** + * Returns the source path. + * + * @return the source path. + */ + String getSourcePath(); + } + + /** + * The remove node operation => "-" STRING + */ + public interface RemoveNodeInstruction extends Instruction { + } + + /** + * The set property operation => "^" STRING ":" ATOM | ARRAY + */ + public interface SetPropertyInstruction extends Instruction { + + /** + * Returns the key of the property to set. + * + * @return The key. + */ + String getKey(); + + /** + * Returns the value of the property to set. + * + * @return The value. + */ + Object getValue(); + } +} \ No newline at end of file Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Instruction.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/InstructionAssert.java =================================================================== --- oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/InstructionAssert.java (revision 0) +++ oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/InstructionAssert.java (working copy) @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl; + +import static junit.framework.Assert.assertEquals; + +import org.apache.jackrabbit.mongomk.api.model.Instruction.AddNodeInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.AddPropertyInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.CopyNodeInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.MoveNodeInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.RemoveNodeInstruction; +import org.apache.jackrabbit.mongomk.api.model.Instruction.SetPropertyInstruction; + + +/** + * @author Visitor to iterate through a list of + * {@code Instruction}s without the need to use {@code instanceof} on each item. + */ +public interface InstructionVisitor { + + /** + * Visits a {@code AddNodeInstruction}. + * + * @param instruction + * The instruction. + */ + void visit(AddNodeInstruction instruction); + + /** + * Visits a {@code AddPropertyInstruction}. + * + * @param instruction The instruction. + */ + void visit(AddPropertyInstruction instruction); + + /** + * Visits a {@code CopyNodeInstruction}. + * + * @param instruction The instruction. + */ + void visit(CopyNodeInstruction instruction); + + /** + * Visits a {@code MoveNodeInstruction}. + * + * @param instruction The instruction. + */ + void visit(MoveNodeInstruction instruction); + + /** + * Visits a {@code RemoveNodeInstruction}. + * + * @param instruction The instruction. + */ + void visit(RemoveNodeInstruction instruction); + + /** + * Visits a {@code SetPropertyInstruction}. + * + * @param instruction The instruction. + */ + void visit(SetPropertyInstruction instruction); +} \ No newline at end of file Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/InstructionVisitor.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java (working copy) @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl.json; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.jackrabbit.mk.json.JsopBuilder; +import org.apache.jackrabbit.mongomk.api.model.Node; +import org.apache.jackrabbit.mongomk.impl.NodeFilter; +import org.json.JSONArray; +import org.json.JSONObject; + + +/** + * FIXME - [Mete] This should really merge with MicroKernelImpl#toJson. + * + * JSON related utility classes. + * + * @author properties = node.getProperties(); + if (properties != null) { + for (Map.Entry entry : properties.entrySet()) { + String key = entry.getKey(); + if (filter == null || filter.includeProperty(key)) { + Object value = entry.getValue(); + builder.key(key); + if (value instanceof String) { + builder.value(value.toString()); + } else { + builder.encodedValue(value.toString()); + } + } + } + } + + long childCount = node.getChildCount(); + if (inclVirtualProps) { + if (filter == null || filter.includeProperty(":childNodeCount")) { + // :childNodeCount is by default always included + // unless it is explicitly excluded in the filter + builder.key(":childNodeCount").value(childCount); + } + // FIXME [Mete] See if :hash is still being used. + /*check whether :hash has been explicitly included + if (filter != null) { + NameFilter nf = filter.getPropertyFilter(); + if (nf != null + && nf.getInclusionPatterns().contains(":hash") + && !nf.getExclusionPatterns().contains(":hash")) { + builder.key(":hash").value(rep.getRevisionStore().getId(node).toString()); + } + } + */ + } + + // FIXME [Mete] There's still some more work here. + Iterator entries = node.getChildEntries(offset, maxChildNodes); + while (entries.hasNext()) { + Node child = entries.next(); + int numSiblings = 0; + if (maxChildNodes != -1 && ++numSiblings > maxChildNodes) { + break; + } + builder.key(child.getName()); + if ((depth == -1) || (currentDepth < depth)) { + convertToJson(builder, child, depth, currentDepth + 1, offset, + maxChildNodes, inclVirtualProps, filter); + } else { + builder.object(); + builder.endObject(); + } + } + + builder.endObject(); + } + + private static Object convertJsonValue(Object jsonObject) throws Exception { + if (jsonObject == JSONObject.NULL) { + return null; + } + + if (jsonObject instanceof JSONArray) { + List elements = new LinkedList(); + JSONArray dummyArray = (JSONArray) jsonObject; + for (int i = 0; i < dummyArray.length(); ++i) { + Object raw = dummyArray.get(i); + Object parsed = convertJsonValue(raw); + elements.add(parsed); + } + return elements; + } + + return jsonObject; + } + + private JsonUtil() { + // no instantiation + } +} Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java (working copy) @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl.json; + +import javax.xml.parsers.SAXParser; + +import org.apache.jackrabbit.mk.json.JsopReader; +import org.apache.jackrabbit.mk.json.JsopTokenizer; +import org.apache.jackrabbit.oak.commons.PathUtils; + +/** + * An event based parser for JSOP. + * + *

+ * This parser is similar to a {@link SAXParser} using a callback ({@code DefaultHandler}) to inform about certain + * events during parsing,i.e. node was added, node was removed, etc. This relieves the implementor from the burden of + * performing a semantic analysis of token which are being parsed. + *

+ * + *

+ * The underlying token parser is the {@link JsopTokenizer}. + *

+ * + * @author ': { + parseOpMoved(); + break; + } + case '^': { + parseOpSet(); + break; + } + case '-': { + parseOpRemoved(); + break; + } + default: + throw new IllegalStateException("Unknown operation: " + (char) token); + } + } + } + + private void parseOpAdded(String currentPath) throws Exception { + String subPath = tokenizer.readString(); + String path = PathUtils.concat(currentPath, subPath); + + tokenizer.read(':'); + + if (tokenizer.matches('{')) { + String parentPath = PathUtils.denotesRoot(path) ? "" : PathUtils.getParentPath(path); + String nodeName = PathUtils.denotesRoot(path) ? "/" : PathUtils.getName(path); + defaultHandler.nodeAdded(parentPath, nodeName); + + if (!tokenizer.matches('}')) { + do { + int pos = tokenizer.getLastPos(); + String propName = tokenizer.readString(); + tokenizer.read(':'); + + if (tokenizer.matches('{')) { // parse a nested node + tokenizer.setPos(pos); // resetting to last post b/c parseOpAdded expects the whole json + tokenizer.read(); + parseOpAdded(path); + } else { // parse property + String valueAsString = tokenizer.readRawValue().trim(); + Object value = JsonUtil.convertJsonValue(valueAsString); + + defaultHandler.propertyAdded(path, propName, value); + } + } while (tokenizer.matches(',')); + + tokenizer.read('}'); // explicitly close the bracket + } + } + } + + private void parseOpCopied() throws Exception { + int pos = tokenizer.getLastPos(); + String subPath = tokenizer.readString(); + String srcPath = PathUtils.concat(path, subPath); + if (!PathUtils.isAbsolute(srcPath)) { + throw new Exception("Absolute path expected: " + srcPath + ", pos: " + pos); + } + tokenizer.read(':'); + String targetPath = tokenizer.readString(); + if (!PathUtils.isAbsolute(targetPath)) { + targetPath = PathUtils.concat(path, targetPath); + if (!PathUtils.isAbsolute(targetPath)) { + throw new Exception("Absolute path expected: " + targetPath + ", pos: " + pos); + } + } + defaultHandler.nodeCopied(path, srcPath, targetPath); + } + + private void parseOpMoved() throws Exception { + int pos = tokenizer.getLastPos(); + String subPath = tokenizer.readString(); + String srcPath = PathUtils.concat(path, subPath); + if (!PathUtils.isAbsolute(srcPath)) { + throw new Exception("Absolute path expected: " + srcPath + ", pos: " + pos); + } + tokenizer.read(':'); + pos = tokenizer.getLastPos(); + String targetPath = tokenizer.readString(); + if (!PathUtils.isAbsolute(targetPath)) { + targetPath = PathUtils.concat(path, targetPath); + if (!PathUtils.isAbsolute(targetPath)) { + throw new Exception("absolute path expected: " + targetPath + ", pos: " + pos); + } + } + defaultHandler.nodeMoved(path, srcPath, targetPath); + } + + private void parseOpSet() throws Exception { + int pos = tokenizer.getLastPos(); + String subPath = tokenizer.readString(); + tokenizer.read(':'); + String value; + if (tokenizer.matches(JsopReader.NULL)) { + value = null; + } else { + value = tokenizer.readRawValue().trim(); + } + String targetPath = PathUtils.concat(path, subPath); + if (!PathUtils.isAbsolute(targetPath)) { + throw new Exception("Absolute path expected: " + targetPath + ", pos: " + pos); + } + String parentPath = PathUtils.getParentPath(targetPath); + String propName = PathUtils.getName(targetPath); + defaultHandler.propertySet(parentPath, propName, JsonUtil.convertJsonValue(value)); + } + + private void parseOpRemoved() throws Exception { + int pos = tokenizer.getLastPos(); + String subPath = tokenizer.readString(); + String targetPath = PathUtils.concat(path, subPath); + if (!PathUtils.isAbsolute(targetPath)) { + throw new Exception("Absolute path expected: " + targetPath + ", pos: " + pos); + } + defaultHandler.nodeRemoved(path, subPath); + } +} \ No newline at end of file Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/json/JsopParserTest.java =================================================================== --- oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/json/JsopParserTest.java (revision 0) +++ oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/json/JsopParserTest.java (working copy) @@ -0,0 +1,543 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl.json; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import org.apache.jackrabbit.mongomk.impl.json.DefaultJsopHandler; +import org.apache.jackrabbit.mongomk.impl.json.JsopParser; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author nodesAdded; + private final List nodesCopied; + private final List nodesMoved; + private final List nodesRemoved; + private final List propertiesAdded; + private final List propertiesSet; + + CountingHandler() { + this.nodesAdded = new LinkedList(); + this.nodesCopied = new LinkedList(); + this.nodesMoved = new LinkedList(); + this.nodesRemoved = new LinkedList(); + this.propertiesAdded = new LinkedList(); + this.propertiesSet = new LinkedList(); + } + + public void assertNodeCopied(String parentPath, String oldPath, String newPath) { + NodeMoved expected = new NodeMoved(parentPath, oldPath, newPath); + + int firstIndex = this.nodesCopied.indexOf(expected); + int lastIndex = this.nodesCopied.lastIndexOf(expected); + + Assert.assertTrue(firstIndex != -1); + Assert.assertEquals(firstIndex, lastIndex); + } + + public void assertNodeMoved(String parentPath, String oldPath, String newPath) { + NodeMoved expected = new NodeMoved(parentPath, oldPath, newPath); + + int firstIndex = this.nodesMoved.indexOf(expected); + int lastIndex = this.nodesMoved.lastIndexOf(expected); + + Assert.assertTrue(firstIndex != -1); + Assert.assertEquals(firstIndex, lastIndex); + } + + public void assertNodeRemoved(String path, String name) { + Node expected = new Node(path, name); + + int firstIndex = this.nodesRemoved.indexOf(expected); + int lastIndex = this.nodesRemoved.lastIndexOf(expected); + + Assert.assertTrue(firstIndex != -1); + Assert.assertEquals(firstIndex, lastIndex); + } + + public void assertNoOfNodesCopied(int num) { + Assert.assertEquals(num, this.nodesCopied.size()); + } + + public void assertNoOfNodesMoved(int num) { + Assert.assertEquals(num, this.nodesMoved.size()); + } + + public void assertNoOfNodesRemoved(int num) { + Assert.assertEquals(num, this.nodesRemoved.size()); + } + + public void assertNoOfPropertiesSet(int num) { + Assert.assertEquals(num, this.propertiesSet.size()); + } + + public void assertPropertiesAdded(int num) { + Assert.assertEquals(num, this.propertiesAdded.size()); + } + + @Override + public void nodeAdded(String path, String name) { + this.nodesAdded.add(new Node(path, name)); + } + + @Override + public void nodeCopied(String rootPath, String oldPath, String newPath) { + this.nodesCopied.add(new NodeMoved(rootPath, oldPath, newPath)); + } + + @Override + public void nodeMoved(String rootPath, String oldPath, String newPath) { + this.nodesMoved.add(new NodeMoved(rootPath, oldPath, newPath)); + } + + @Override + public void nodeRemoved(String path, String name) { + this.nodesRemoved.add(new Node(path, name)); + } + + @Override + public void propertyAdded(String path, String key, Object value) { + this.propertiesAdded.add(new Property(path, key, value)); + } + + @Override + public void propertySet(String path, String key, Object value) { + this.propertiesSet.add(new Property(path, key, value)); + } + + void assertNodeAdded(String path, String name) { + Node expected = new Node(path, name); + + int firstIndex = this.nodesAdded.indexOf(expected); + int lastIndex = this.nodesAdded.lastIndexOf(expected); + + Assert.assertTrue(firstIndex != -1); + Assert.assertEquals(firstIndex, lastIndex); + } + + void assertPropertyAdded(String path, String key, Object value) { + Property expected = new Property(path, key, value); + + int firstIndex = this.propertiesAdded.indexOf(expected); + int lastIndex = this.propertiesAdded.lastIndexOf(expected); + + Assert.assertTrue(firstIndex != -1); + Assert.assertEquals(firstIndex, lastIndex); + } + + void assertPropertySet(String path, String key, Object value) { + Property expected = new Property(path, key, value); + + int firstIndex = this.propertiesSet.indexOf(expected); + int lastIndex = this.propertiesSet.lastIndexOf(expected); + + Assert.assertTrue(firstIndex != -1); + Assert.assertEquals(firstIndex, lastIndex); + } + + void assetNoOfNodesAdded(int num) { + Assert.assertEquals(num, this.nodesAdded.size()); + } + + } + + @Test + public void testAddNestedNodes() throws Exception { + String rootPath = "/"; + StringBuilder sb = new StringBuilder(); + sb.append("+\"a\" : { \"integer\" : 123 ,\"b\" : { \"double\" : 123.456 , \"d\" : {} } , \"c\" : { \"string\" : \"string\" }}"); + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); + + jsopParser.parse(); + + countingHandler.assetNoOfNodesAdded(4); + countingHandler.assertNodeAdded("/", "a"); + countingHandler.assertNodeAdded("/a", "b"); + countingHandler.assertNodeAdded("/a/b", "d"); + countingHandler.assertNodeAdded("/a", "c"); + + countingHandler.assertPropertiesAdded(3); + countingHandler.assertPropertyAdded("/a", "integer", 123); + countingHandler.assertPropertyAdded("/a/b", "double", 123.456); + countingHandler.assertPropertyAdded("/a/c", "string", "string"); + } + + @Test + public void testAddNodesAndProperties() throws Exception { + String rootPath = "/"; + StringBuilder sb = new StringBuilder(); + sb.append("+\"a\" : { \"int\" : 1 } \n"); + sb.append("+\"a/b\" : { \"string\" : \"foo\" } \n"); + sb.append("+\"a/c\" : { \"bool\" : true }"); + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); + + jsopParser.parse(); + + countingHandler.assetNoOfNodesAdded(3); + countingHandler.assertNodeAdded("/", "a"); + countingHandler.assertNodeAdded("/a", "b"); + countingHandler.assertNodeAdded("/a", "c"); + + countingHandler.assertPropertiesAdded(3); + countingHandler.assertPropertyAdded("/a", "int", Integer.valueOf(1)); + countingHandler.assertPropertyAdded("/a/b", "string", "foo"); + countingHandler.assertPropertyAdded("/a/c", "bool", Boolean.TRUE); + } + + @Test + public void testAddNodesAndPropertiesSeparately() throws Exception { + String rootPath = "/"; + StringBuilder sb = new StringBuilder(); + sb.append("+\"a\" : {} \n"); + sb.append("+\"a\" : { \"int\" : 1 } \n"); + sb.append("+\"a/b\" : {} \n"); + sb.append("+\"a/b\" : { \"string\" : \"foo\" } \n"); + sb.append("+\"a/c\" : {} \n"); + sb.append("+\"a/c\" : { \"bool\" : true }"); + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); + + jsopParser.parse(); + + countingHandler.assetNoOfNodesAdded(6); + + countingHandler.assertPropertiesAdded(3); + countingHandler.assertPropertyAdded("/a", "int", Integer.valueOf(1)); + countingHandler.assertPropertyAdded("/a/b", "string", "foo"); + countingHandler.assertPropertyAdded("/a/c", "bool", Boolean.TRUE); + } + + @Test + public void testAddPropertiesWithComplexArray() throws Exception { + String rootPath = "/"; + String jsop = "+ \"a\" : { \"array_complex\" : [ 123, 123.456, true, false, null, \"string\", [1,2,3,4,5] ] }"; + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, jsop, countingHandler); + + jsopParser.parse(); + + countingHandler.assertPropertiesAdded(1); + countingHandler.assertPropertyAdded( + "/a", + "array_complex", + Arrays.asList(new Object[] { 123, 123.456, true, false, null, "string", + Arrays.asList(new Object[] { 1, 2, 3, 4, 5 }) })); + } + + @Test + public void testAddWithEmptyPath() throws Exception { + String rootPath = ""; + StringBuilder sb = new StringBuilder(); + sb.append("+\"/\" : { \"int\" : 1 } \n"); + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); + + jsopParser.parse(); + + countingHandler.assetNoOfNodesAdded(1); + countingHandler.assertNodeAdded("", "/"); + + countingHandler.assertPropertiesAdded(1); + countingHandler.assertPropertyAdded("/", "int", Integer.valueOf(1)); + } + + @Test + public void testSimpleAddNodes() throws Exception { + String rootPath = "/"; + StringBuilder sb = new StringBuilder(); + sb.append("+\"a\" : {} \n"); + sb.append("+\"a/b\" : {} \n"); + sb.append("+\"a/c\" : {}"); + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); + + jsopParser.parse(); + + countingHandler.assetNoOfNodesAdded(3); + countingHandler.assertNodeAdded("/", "a"); + countingHandler.assertNodeAdded("/a", "b"); + countingHandler.assertNodeAdded("/a", "c"); + } + + @Test + public void testSimpleAddProperties() throws Exception { + String rootPath = "/"; + StringBuilder sb = new StringBuilder(); + sb.append("+ \"a\" : {}"); + sb.append("+ \"a\" : { \"integer\" : 123, \"double\" : 123.456, \"true\" : true, \"false\" : false, \"null\" : null, \"string\" : \"string\", \"array\" : [1,2,3,4,5] }"); + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); + + jsopParser.parse(); + + countingHandler.assertPropertiesAdded(7); + countingHandler.assertPropertyAdded("/a", "integer", 123); + countingHandler.assertPropertyAdded("/a", "double", 123.456); + countingHandler.assertPropertyAdded("/a", "true", true); + countingHandler.assertPropertyAdded("/a", "false", false); + countingHandler.assertPropertyAdded("/a", "null", null); + countingHandler.assertPropertyAdded("/a", "string", "string"); + countingHandler.assertPropertyAdded("/a", "array", Arrays.asList(new Object[] { 1, 2, 3, 4, 5 })); + } + + @Test + public void testSimpleCopyNodes() throws Exception { + String rootPath = "/"; + StringBuilder sb = new StringBuilder(); + sb.append("*\"a\" : \"b\"\n"); + sb.append("*\"a/b\" : \"a/c\"\n"); + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); + jsopParser.parse(); + + countingHandler.assertNoOfNodesCopied(2); + countingHandler.assertNodeCopied("/", "/a", "/b"); + countingHandler.assertNodeCopied("/", "/a/b", "/a/c"); + } + + @Test + public void testSimpleMoveNodes() throws Exception { + String rootPath = "/"; + StringBuilder sb = new StringBuilder(); + sb.append(">\"a\" : \"b\"\n"); + sb.append(">\"a/b\" : \"a/c\"\n"); + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); + jsopParser.parse(); + + countingHandler.assertNoOfNodesMoved(2); + countingHandler.assertNodeMoved("/", "/a", "/b"); + countingHandler.assertNodeMoved("/", "/a/b", "/a/c"); + } + + @Test + public void testSimpleRemoveNodes() throws Exception { + String rootPath = "/"; + String jsop = "-\"a\""; + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, jsop, countingHandler); + + jsopParser.parse(); + + countingHandler.assertNoOfNodesRemoved(1); + countingHandler.assertNodeRemoved("/", "a"); + } + + @Test + public void testSimpleSetNodes() throws Exception { + String rootPath = "/"; + StringBuilder sb = new StringBuilder(); + sb.append("^\"a\" : \"b\""); + + CountingHandler countingHandler = new CountingHandler(); + JsopParser jsopParser = new JsopParser(rootPath, sb.toString(), countingHandler); + jsopParser.parse(); + + countingHandler.assertNoOfPropertiesSet(1); + // TODO - Is this correct? + countingHandler.assertPropertySet("/", "a", "b"); + } +} Property changes on: oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/json/JsopParserTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoMicroKernel.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoMicroKernel.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoMicroKernel.java (working copy) @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl; + +import java.io.InputStream; + +import org.apache.jackrabbit.mk.api.MicroKernel; +import org.apache.jackrabbit.mk.api.MicroKernelException; +import org.apache.jackrabbit.mongomk.api.BlobStore; +import org.apache.jackrabbit.mongomk.api.NodeStore; +import org.apache.jackrabbit.mongomk.api.model.Commit; +import org.apache.jackrabbit.mongomk.api.model.Node; +import org.apache.jackrabbit.mongomk.impl.builder.CommitBuilder; +import org.apache.jackrabbit.mongomk.impl.json.JsonUtil; + +/** + * The {@code MongoDB} implementation of the {@link MicroKernel}. + * + *

+ * This class will transform and delegate to instances of {@link NodeStore} and {@link BlobStore}. + *

+ * + * @author
0 && nodeFilter != null && nodeFilter.getChildNodeFilter() != null) { + // Both an offset > 0 and a filter on node names have been specified... + throw new IllegalArgumentException("offset > 0 with child node filter"); + } + + try { + // FIXME [Mete] Should filter, offset, and maxChildNodes be handled in Mongo instead? + Node rootNode = nodeStore.getNodes(path, revisionId, depth, offset, maxChildNodes, filter); + if (rootNode == null) { + return null; + } + return JsonUtil.convertToJson(rootNode, depth, (int)offset, maxChildNodes, true, nodeFilter); + } catch (Exception e) { + throw new MicroKernelException(e); + } + } + + @Override + public String getRevisionHistory(long since, int maxEntries, String path) throws MicroKernelException { + return nodeStore.getRevisionHistory(since, maxEntries, path); + } + + @Override + public String merge(String branchRevisionId, String message) throws MicroKernelException { + throw new UnsupportedOperationException("Merge is currently not supported."); + } + + @Override + public boolean nodeExists(String path, String revisionId) throws MicroKernelException { + boolean exists = false; + + try { + String revId = null; + if (revisionId != null) { + revId = new String(revisionId); + } + + exists = nodeStore.nodeExists(path, revId); + } catch (Exception e) { + throw new MicroKernelException(e); + } + + return exists; + } + + @Override + public int read(String blobId, long pos, byte[] buff, int off, int length) throws MicroKernelException { + int totalBytes = -1; + + try { + totalBytes = blobStore.readBlob(blobId, pos, buff, off, length); + } catch (Exception e) { + throw new MicroKernelException(e); + } + + return totalBytes; + } + + @Override + public String waitForCommit(String oldHeadRevisionId, long timeout) throws MicroKernelException, + InterruptedException { + return nodeStore.waitForCommit(oldHeadRevisionId, timeout); + } + + @Override + public String write(InputStream in) throws MicroKernelException { + String blobId = null; + + try { + blobId = blobStore.writeBlob(in); + } catch (Exception e) { + throw new MicroKernelException(e); + } + + return blobId; + } +} \ No newline at end of file Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoMicroKernel.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java (working copy) @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl.model; + +import org.apache.jackrabbit.mongomk.api.model.InstructionVisitor; +import org.apache.jackrabbit.mongomk.api.model.Instruction.MoveNodeInstruction; + +public class MoveNodeInstructionImpl implements MoveNodeInstruction { + private final String destPath; + private final String path; + private final String sourcePath; + + public MoveNodeInstructionImpl(String path, String sourcePath, String destPath) { + this.path = path; + this.sourcePath = sourcePath; + this.destPath = destPath; + } + + @Override + public void accept(InstructionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String getDestPath() { + return destPath; + } + + @Override + public String getPath() { + return path; + } + + @Override + public String getSourcePath() { + return sourcePath; + } +} Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Node.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Node.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Node.java (working copy) @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.api.model; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * A higher level object representing a node. + * + * @author expectedChildren = expected.getChildren(); + Set actualChildren = actual.getChildren(); + + if (expectedChildren == null) { + Assert.assertNull(actualChildren); + } else { + Assert.assertNotNull(actualChildren); + Assert.assertEquals(expectedChildren.size(), actualChildren.size()); + + for (Node expectedChild : expectedChildren) { + boolean valid = false; + for (Node actualChild : actualChildren) { + if (expectedChild.getName().equals(actualChild.getName())) { + assertDeepEquals(expectedChild, actualChild); + valid = true; + + break; + } + } + + Assert.assertTrue(valid); + } + } + } + + public static void assertEquals(Collection expecteds, Collection actuals) { + Assert.assertEquals(expecteds.size(), actuals.size()); + + for (Node expected : expecteds) { + boolean valid = false; + for (Node actual : actuals) { + if (expected.getPath().equals(actual.getPath())) { + assertEquals(expected, actual); + valid = true; + + break; + } + } + + Assert.assertTrue(valid); + } + } + + public static void assertEquals(Node expected, Node actual) { + Assert.assertEquals(expected.getName(), actual.getName()); + Assert.assertEquals(expected.getPath(), actual.getPath()); + + String expectedRevisionId = expected.getRevisionId(); + String actualRevisionId = actual.getRevisionId(); + + if (expectedRevisionId == null) { + Assert.assertNull(actualRevisionId); + } + if (actualRevisionId == null) { + Assert.assertNull(expectedRevisionId); + } + + if ((actualRevisionId != null) && (expectedRevisionId != null)) { + Assert.assertEquals(expectedRevisionId, actualRevisionId); + } + + Map expectedProperties = expected.getProperties(); + Map actualProperties = actual.getProperties(); + + if (expectedProperties == null) { + Assert.assertNull(actualProperties); + } + + if (actualProperties == null) { + Assert.assertNull(expectedProperties); + } + + if ((actualProperties != null) && (expectedProperties != null)) { + Assert.assertEquals(expectedProperties, actualProperties); + } + } + + private NodeAssert() { + // no instantiation + } +} Property changes on: oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/NodeAssert.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilder.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilder.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilder.java (working copy) @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl.builder; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.jackrabbit.mongomk.api.model.Node; +import org.apache.jackrabbit.mongomk.impl.json.JsonUtil; +import org.apache.jackrabbit.mongomk.impl.model.NodeImpl; +import org.apache.jackrabbit.oak.commons.PathUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * A builder to create {@link Node}s from JSON + * strings. + * + * @author properties = null; + for (@SuppressWarnings("rawtypes") + Iterator iterator = jsonObject.keys(); iterator.hasNext();) { + String key = (String) iterator.next(); + Object value = jsonObject.get(key); + + if (value instanceof JSONObject) { + String childPath = PathUtils.concat(realPath, key); + + Node childNode = parseNode(childPath, (JSONObject) value); + node.addChild(childNode); + } else { + if (properties == null) { + properties = new HashMap(); + } + + Object converted = JsonUtil.convertJsonValue(value.toString()); + properties.put(key, converted); + } + } + + node.setProperties(properties); + + return node; + } +} Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilder.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilderTest.java =================================================================== --- oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilderTest.java (revision 0) +++ oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/builder/NodeBuilderTest.java (working copy) @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl.builder; + +import org.apache.jackrabbit.mongomk.api.model.Node; +import org.apache.jackrabbit.mongomk.impl.NodeAssert; +import org.apache.jackrabbit.mongomk.impl.builder.NodeBuilder; +import org.apache.jackrabbit.mongomk.impl.model.NodeImpl; +import org.junit.Test; + + +/** + * @author l = new ArrayList(); + t.read('['); + do { + l.add(t.readString()); + } while (t.matches(',')); + t.read(']'); + return l.toArray(new String[l.size()]); + } + + NameFilter getChildNodeFilter() { + return nodeFilter; + } + + NameFilter getPropertyFilter() { + return propFilter; + } + + boolean includeNode(String name) { + return nodeFilter == null || nodeFilter.matches(name); + } + + public boolean includeProperty(String name) { + return propFilter == null || propFilter.matches(name); + } +} \ No newline at end of file Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/NodeFilter.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/NodeImpl.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/NodeImpl.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/NodeImpl.java (working copy) @@ -0,0 +1,324 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.impl.model; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.jackrabbit.mk.util.RangeIterator; +import org.apache.jackrabbit.mongomk.api.model.Node; +import org.apache.jackrabbit.oak.commons.PathUtils; + + +/** + * Implementation of {@link Node}. + * + * @author descendants) { + Set children = node.getChildren(); + if (children != null) { + for (Node child : children) { + descendants.add(child); + this.getDescendantsRecursive(child, descendants); + } + } + } +} Property changes on: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/NodeImpl.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/NodeStore.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/NodeStore.java (revision 0) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/NodeStore.java (working copy) @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.api; + +import org.apache.jackrabbit.mk.api.MicroKernel; +import org.apache.jackrabbit.mongomk.api.model.Commit; +import org.apache.jackrabbit.mongomk.api.model.Node; + +/** + * The NodeStore interface deals with all node related operations of the {@link MicroKernel}. + * + *

+ * Since binary storage and node storage most likely use different backend technologies two separate interfaces for + * these operations are provided. + *

+ * + *

+ * This interface is not only a partly {@code MicroKernel} but also provides a different layer of abstraction by + * converting the {@link String} parameters into higher level objects to ease the development for implementors of the + * {@code MicroKernel}. + *

+ * + * @see BlobStore + * + * @author
b->c->d. + List instructions = new LinkedList(); + instructions.add(new AddNodeInstructionImpl("/", "a")); + instructions.add(new AddNodeInstructionImpl("/a", "b")); + instructions.add(new AddNodeInstructionImpl("/a/b", "c")); + instructions.add(new AddNodeInstructionImpl("/a/b/c", "d")); - @Test - public void grandParentDelete() throws Exception { - // Add a->b->c->d. - List instructions = new LinkedList(); - instructions.add(new AddNodeInstructionImpl("/", "a")); - instructions.add(new AddNodeInstructionImpl("/a", "b")); - instructions.add(new AddNodeInstructionImpl("/a/b", "c")); - instructions.add(new AddNodeInstructionImpl("/a/b/c", "d")); + Commit commit = new CommitImpl("Add nodes", "/", "TODO", instructions); + CommitCommandMongo command = new CommitCommandMongo(mongoConnection, + commit); + command.execute(); - Commit commit = new CommitImpl("Add nodes", "/", "TODO", instructions); - CommitCommandMongo command = new CommitCommandMongo(mongoConnection, - commit); - command.execute(); + // Remove b. + instructions = new LinkedList(); + instructions.add(new RemoveNodeInstructionImpl("/a", "b")); + commit = new CommitImpl("Delete /b", "/a", "-b", instructions); + command = new CommitCommandMongo(mongoConnection, commit); + command.execute(); - // Remove b. - instructions = new LinkedList(); - instructions.add(new RemoveNodeInstructionImpl("/a", "b")); - commit = new CommitImpl("Delete /b", "/a", "-b", instructions); - command = new CommitCommandMongo(mongoConnection, commit); - command.execute(); + // Check for d. + NodeExistsCommandMongo existsCommand = new NodeExistsCommandMongo( + mongoConnection, "/a/b/c/d", null); + boolean exists = existsCommand.execute(); + assertFalse(exists); + } - // Check for d. - NodeExistsCommandMongo existsCommand = new NodeExistsCommandMongo( - mongoConnection, "/a/b/c/d", null); - boolean exists = existsCommand.execute(); - assertFalse(exists); - } + @Test + public void existsInOldRevNotInNewRev() throws Exception { + SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection); + String rev1 = scenario.create(); + String rev2 = scenario.delete_A(); - @Test - public void existsInOldRevNotInNewRev() throws Exception { - SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection); - String rev1 = scenario.create(); - String rev2 = scenario.delete_A(); + NodeExistsCommandMongo command = new NodeExistsCommandMongo( + mongoConnection, "/a", rev1); + boolean exists = command.execute(); + assertTrue(exists); - NodeExistsCommandMongo command = new NodeExistsCommandMongo( - mongoConnection, "/a", rev1); - boolean exists = command.execute(); - assertTrue(exists); + command = new NodeExistsCommandMongo(mongoConnection, "/a", rev2); + exists = command.execute(); + assertFalse(exists); + } - command = new NodeExistsCommandMongo(mongoConnection, "/a", rev2); - exists = command.execute(); - assertFalse(exists); - } + @Test + public void siblingDelete() throws Exception { + SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection); + scenario.create(); - @Test - public void siblingDelete() throws Exception { - SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection); - scenario.create(); + scenario.delete_B(); + NodeExistsCommandMongo command = new NodeExistsCommandMongo( + mongoConnection, "/a/b", null); + boolean exists = command.execute(); + assertFalse(exists); - scenario.delete_B(); - NodeExistsCommandMongo command = new NodeExistsCommandMongo( - mongoConnection, "/a/b", null); - boolean exists = command.execute(); - assertFalse(exists); + command = new NodeExistsCommandMongo(mongoConnection, "/a/c", null); + exists = command.execute(); + assertTrue(exists); + } - command = new NodeExistsCommandMongo(mongoConnection, "/a/c", null); - exists = command.execute(); - assertTrue(exists); - } + @Test + @Ignore + public void testNodeNotFound() throws Exception { - @Test - public void testNodeNotFound() throws Exception { + // adds nodes /a,/a/b,/a/b/c , checks if node a exists + List instructions = new LinkedList(); - // adds nodes /a,/a/b,/a/b/c , checks if node a exists - List instructions = new LinkedList(); + // commit node /a + instructions.add(new AddNodeInstructionImpl("/", "a")); + Commit commit1 = new CommitImpl("/", "+a : {}", "Add node a", + instructions); + CommitCommandMongo command = new CommitCommandMongo(mongoConnection, + commit1); + command.execute(); - // commit node /a - instructions.add(new AddNodeInstructionImpl("/", "a")); - Commit commit1 = new CommitImpl("/", "+a : {}", "Add node a", - instructions); - CommitCommandMongo command = new CommitCommandMongo(mongoConnection, - commit1); - command.execute(); + // commit node /a/b + instructions = new LinkedList(); + instructions.add(new AddNodeInstructionImpl("/a", "b")); + Commit commit2 = new CommitImpl("/a", "+b : {}", "Add node a/b", + instructions); + command = new CommitCommandMongo(mongoConnection, commit2); + command.execute(); - // commit node /a/b - instructions = new LinkedList(); - instructions.add(new AddNodeInstructionImpl("/a", "b")); - Commit commit2 = new CommitImpl("/a", "+b : {}", "Add node a/b", - instructions); - command = new CommitCommandMongo(mongoConnection, commit2); - command.execute(); + // commit node /a/b/c + instructions = new LinkedList(); + instructions.add(new AddNodeInstructionImpl("/a/b", "c")); + Commit commit3 = new CommitImpl("a/b", "+c : {}", "Add node a/b/c", + instructions); + command = new CommitCommandMongo(mongoConnection, commit3); + command.execute(); - // commit node /a/b/c - instructions = new LinkedList(); - instructions.add(new AddNodeInstructionImpl("/a/b", "c")); - Commit commit3 = new CommitImpl("a/b", "+c : {}", "Add node a/b/c", - instructions); - command = new CommitCommandMongo(mongoConnection, commit3); - command.execute(); + // verify if node a is visible in the head revision + NodeExistsCommandMongo isNodeVisible = new NodeExistsCommandMongo( + mongoConnection, "/a", null); + boolean exists = isNodeVisible.execute(); + assertTrue("The node a is not found in the head revision!", exists); - // verify if node a is visible in the head revision - NodeExistsCommandMongo isNodeVisible = new NodeExistsCommandMongo( - mongoConnection, "/a", null); - boolean exists = isNodeVisible.execute(); - assertTrue("The node a is not found in the head revision!", exists); + } - } - - @Test - public void testTreeDepth() throws Exception { + @Test + @Ignore + public void testTreeDepth() throws Exception { - String path = "/"; - List instructions = new LinkedList(); + String path = "/"; + List instructions = new LinkedList(); - for (int i = 0; i < 1000; i++) { - instructions.clear(); - instructions.add(new AddNodeInstructionImpl(path, "N" + i)); - Commit commit1 = new CommitImpl(path, "+N" + i + " : {}", - "Add node N" + i, instructions); - CommitCommandMongo command = new CommitCommandMongo( - mongoConnection, commit1); - command.execute(); - path = (path.endsWith("/")) ? (path = path + "N" + i) - : (path = path + "/N" + i); - //System.out.println("*********" + path.length() + "*****"); - } - - } + for (int i = 0; i < 1000; i++) { + instructions.clear(); + instructions.add(new AddNodeInstructionImpl(path, "N" + i)); + Commit commit1 = new CommitImpl(path, "+N" + i + " : {}", + "Add node N" + i, instructions); + CommitCommandMongo command = new CommitCommandMongo( + mongoConnection, commit1); + command.execute(); + path = (path.endsWith("/")) ? (path = path + "N" + i) + : (path = path + "/N" + i); + //System.out.println("*********" + path.length() + "*****"); + } + + } } Index: oak-mongomk/pom.xml =================================================================== --- oak-mongomk/pom.xml (revision 1387935) +++ oak-mongomk/pom.xml (working copy) @@ -30,8 +30,32 @@ oak-mongomk + Oak Mongo MicroKernel + + + + org.apache.jackrabbit + oak-mk + ${project.version} + + + + + org.mongodb + mongo-java-driver + 2.7.3 + + + + + log4j + log4j + 1.2.16 + + + commons-io commons-io @@ -43,6 +67,13 @@ 1.6 + org.json + json + 20090211 + + + + junit junit test @@ -53,38 +84,7 @@ 3.1 test - - log4j - log4j - 1.2.16 - - - org.apache.jackrabbit - oak-mongomk-api - ${project.version} - - - org.apache.jackrabbit - oak-mongomk-impl - ${project.version} - - - org.mongodb - mongo-java-driver - 2.7.3 - - - org.apache.jackrabbit - oak-commons - 0.5-SNAPSHOT - - - org.apache.jackrabbit - oak-mongomk-impl - ${project.version} - test-jar - test - +