This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-nosql-mongodb-resourceprovider.git
commit 07f157268ea6eb93271b6e0f4d9178e048357b52 Author: Stefan Seifert <[email protected]> AuthorDate: Mon Sep 14 21:19:29 2015 +0000 SLING-5024 Sling NoSQL Resource Provider for MongoDB (based on nosql.generic) git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1703061 13f79535-47bb-0310-9956-ffa450edef68 --- README.md | 22 +++ pom.xml | 171 +++++++++++++++++++++++ src/main/couchbase-views/ancestorPath.js | 40 ++++++ src/main/couchbase-views/ancestorPathTester.html | 84 +++++++++++ src/main/couchbase-views/parentPath.js | 37 +++++ src/main/couchbase-views/parentPathTester.html | 82 +++++++++++ 6 files changed, 436 insertions(+) diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc6f114 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +Apache Sling NoSQL MongoDB Resource Provider +============================================ + +Sling ResourceProvider implementation that uses [MongoDB](https://www.mongodb.org/) NoSQL database as persistence. + +Based on the "Apache Sling NoSQL Generic Resource Provider". + + +Configuration on deployment +--------------------------- + +* Create a factory configuration for "Apache Sling NoSQL MongoDB Resource Provider Factory" to define the root of the resource tree that should be stored in MongoDB, and MongoDB connection string, database name and collection name. + + +Run integration tests +--------------------- + +To run the integration tests you have to set up a real MongoDB server and run the tests with this command line (inserting the correct parameters): + +``` +mvn -Pmongodb-integration-test -DconnectionString=localhost:27017 -Ddatabase=sling -Dcollection=resources integration-test +``` diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..26adc53 --- /dev/null +++ b/pom.xml @@ -0,0 +1,171 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.sling</groupId> + <artifactId>sling</artifactId> + <version>24</version> + <relativePath/> + </parent> + + <artifactId>org.apache.sling.nosql.mongodb-resourceprovider</artifactId> + <version>0.5.0-SNAPSHOT</version> + <packaging>bundle</packaging> + + <name>Apache Sling NoSQL MongoDB Resource Provider</name> + <description>Resource Provider with MongoDB Persistence for Apache Sling.</description> + + <scm> + <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/nosql/mongodb-resourceprovider</connection> + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/nosql/mongodb-resourceprovider</developerConnection> + <url>http://svn.apache.org/viewvc/sling/trunk/contrib/nosql/mongodb-resourceprovider</url> + </scm> + + <properties> + <sling.java.version>7</sling.java.version> + </properties> + + <dependencies> + + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.nosql.generic</artifactId> + <version>0.5.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.mongodb</groupId> + <artifactId>mongo-java-driver</artifactId> + <version>3.0.4</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.osgi</artifactId> + <version>2.2.2</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.sling-mock</artifactId> + <version>1.5.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.logging-mock</artifactId> + <version>1.0.0</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.nosql.generic</artifactId> + <classifier>tests</classifier> + <version>0.5.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + <version>2.0</version> + <scope>test</scope> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <testFailureIgnore>false</testFailureIgnore> + <includes> + <include>**/*Test.java</include> + </includes> + <excludes> + <exclude>**/*IT.java</exclude> + </excludes> + </configuration> + </plugin> + + </plugins> + </build> + + <profiles> + + <!-- + Profile for Integration tests with a real MongoDB server running. + You have to set JVM parameters for MongoDB host and bucket name, e.g. + mvn -Pmongodb-integration-test -DmongodbHosts=localhost:8091 -DbucketName=test integration-test + --> + <profile> + <id>mongodb-integration-test</id> + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + <configuration> + <includes> + <include>**/*IT.java</include> + </includes> + <excludes> + <exclude>**/*Test.java</exclude> + </excludes> + </configuration> + </plugin> + + </plugins> + </build> + </profile> + + </profiles> + +</project> diff --git a/src/main/couchbase-views/ancestorPath.js b/src/main/couchbase-views/ancestorPath.js new file mode 100644 index 0000000..f8cd94b --- /dev/null +++ b/src/main/couchbase-views/ancestorPath.js @@ -0,0 +1,40 @@ +/* + * 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. + */ +/* + * Emits for each document the all parent paths - allowing to fetch children and their decendants by path. + * Includes the path of the item itself. + */ +function(doc, meta) { + + // handle only sling resource documents with a valid path + if (!(meta.id.indexOf("sling-resource:")==0 && doc.path && doc.data)) { + return; + } + var pathParts = doc.path.split("/"); + if (pathParts.length < 3) { + return; + } + + while (pathParts.length >= 2) { + // remove last element to get parent path + var parentPath = pathParts.join("/"); + emit(parentPath, null); + pathParts.pop(); + } +} diff --git a/src/main/couchbase-views/ancestorPathTester.html b/src/main/couchbase-views/ancestorPathTester.html new file mode 100644 index 0000000..9933e6f --- /dev/null +++ b/src/main/couchbase-views/ancestorPathTester.html @@ -0,0 +1,84 @@ +<!DOCTYPE html> +<!-- + * 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. +--> +<html> + <head> + <title>Couchbase View Tester</title> + <style>body { font-family: Courier }</style> + </head> + <body> + +<script> + +var emit = function(key, value) { + document.write("[" + key + "]" + "<br/>"); +} + +var testFunction = function(doc, meta) { + + // handle only sling resource documents with a valid path + if (!(meta.id.indexOf("sling-resource:")==0 && doc.path && doc.data)) { + return; + } + var pathParts = doc.path.split("/"); + if (pathParts.length < 3) { + return; + } + + while (pathParts.length >= 2) { + // remove last element to get parent path + var parentPath = pathParts.join("/"); + emit(parentPath, null); + pathParts.pop(); + } +}; + +var testInput = [ + null, + "", + "abc", + "/", + "/content", + "/content/node1", + "/content/node1/node2", + "/content/node1/node2/node3", + "/content/node1/node2/node3/node4" +]; + +</script> + + <table border="1"> + <tr> + <th>Input</th> + <th>Output</th> + </tr> +<script> +for (var i=0; i < testInput.length; i++) { + document.write("<tr>") + document.write("<td>" + testInput[i] + "</td>") + document.write("<td>") + testFunction({path: testInput[i], data: {}}, {id: "sling-resource:doc" + i}); + document.write("</td>") + document.write("</tr>") +} +</script> + </table> + + </body> +</html> diff --git a/src/main/couchbase-views/parentPath.js b/src/main/couchbase-views/parentPath.js new file mode 100644 index 0000000..54c4c1f --- /dev/null +++ b/src/main/couchbase-views/parentPath.js @@ -0,0 +1,37 @@ +/* + * 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. + */ +/* + * Emits for each document the direct parent path - allowing to fetch direct children by path. + */ +function(doc, meta) { + + // handle only sling resource documents with a valid path + if (!(meta.id.indexOf("sling-resource:")==0 && doc.path && doc.data)) { + return; + } + var pathParts = doc.path.split("/"); + if (pathParts.length < 3) { + return; + } + + // remove last element to get parent path + pathParts.pop(); + var parentPath = pathParts.join("/"); + emit(parentPath, null); +} diff --git a/src/main/couchbase-views/parentPathTester.html b/src/main/couchbase-views/parentPathTester.html new file mode 100644 index 0000000..efcc2d1 --- /dev/null +++ b/src/main/couchbase-views/parentPathTester.html @@ -0,0 +1,82 @@ +<!DOCTYPE html> +<!-- + * 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. +--> +<html> + <head> + <title>Couchbase View Tester</title> + <style>body { font-family: Courier }</style> + </head> + <body> + +<script> + +var emit = function(key, value) { + document.write("[" + key + "]" + "<br/>"); +} + +var testFunction = function(doc, meta) { + + // handle only sling resource documents with a valid path + if (!(meta.id.indexOf("sling-resource:")==0 && doc.path && doc.data)) { + return; + } + var pathParts = doc.path.split("/"); + if (pathParts.length < 3) { + return; + } + + // remove last element to get parent path + pathParts.pop(); + var parentPath = pathParts.join("/"); + emit(parentPath, null); +}; + +var testInput = [ + null, + "", + "abc", + "/", + "/content", + "/content/node1", + "/content/node1/node2", + "/content/node1/node2/node3", + "/content/node1/node2/node3/node4" +]; + +</script> + + <table border="1"> + <tr> + <th>Input</th> + <th>Output</th> + </tr> +<script> +for (var i=0; i < testInput.length; i++) { + document.write("<tr>") + document.write("<td>" + testInput[i] + "</td>") + document.write("<td>") + testFunction({path: testInput[i], data: {}}, {id: "sling-resource:doc" + i}); + document.write("</td>") + document.write("</tr>") +} +</script> + </table> + + </body> +</html> -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
