You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2010/01/25 18:40:10 UTC

svn commit: r902892 - in /incubator/clerezza/issues/CLEREZZA-70: org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ org.apache.clerezza.platform.content/src/main/resources/org/apache/clerezza/platform/content/stati...

Author: reto
Date: Mon Jan 25 17:40:09 2010
New Revision: 902892

URL: http://svn.apache.org/viewvc?rev=902892&view=rev
Log:
CLEREZZA-70: Incorporated review comments

Added:
    incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/MGraphUtilsTest.java
Modified:
    incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/Editor.java
    incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/resources/org/apache/clerezza/platform/content/staticweb/scripts/tria-disco.js
    incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java

Modified: incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/Editor.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/Editor.java?rev=902892&r1=902891&r2=902892&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/Editor.java (original)
+++ incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/Editor.java Mon Jan 25 17:40:09 2010
@@ -39,6 +39,9 @@
 
 import org.osgi.framework.Bundle;
 import org.osgi.service.component.ComponentContext;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.clerezza.jaxrs.utils.TrailingSlash;
@@ -58,11 +61,11 @@
  * using the Discobits ontology
  *
  * @author rbn
- * @scr.component
- * @scr.service interface="java.lang.Object"
- * @scr.property name="javax.ws.rs" type="Boolean" value="true"
  *
  */
+@Component
+@Service(Object.class)
+@Property(name="javax.ws.rs", boolValue=true)
 @Path("tools/editor")
 public class Editor {
 	
@@ -117,25 +120,19 @@
 			tcManager.getMGraph(graphUri);
 		return new GraphNode(uri, mGraph);
 	}
-	/*
-	 * note that without specifying consumes the subsequent method using
-	 * @FormParam is never selected
+
+	/**
+	 * replaces the subgraph serialized with RDF/XML in <code>revokedString
+	 * </code> with the one from <code>assertedString</code>.
+	 *
+	 * @param graphUri the graph within which the replacement has to take place or null
+	 * for the content graph
+	 * @param assertedString the asserted Graph as RDF/XML
+	 * @param revokedString the revoked Graph as RDF/XML
 	 */
-	/*@POST
-	@Path("post")
-	@Consumes({"application/rdf+xml", "text/rdf+n3","application/n-triples","application/turtle","application/n3","text/n3","text/turtle"})
-	public void postDiscobit(@QueryParam("resource") UriRef uri, 
-			@QueryParam("graph") UriRef graphUri, Graph graph) {
-		final MGraph mGraph = graphUri == null ? cgProvider.getContentGraph() :
-			tcManager.getMGraph(graphUri);
-		new SimpleDiscobitsHandler(mGraph).remove(uri);
-		mGraph.addAll(graph);
-	}*/
-	
 	@POST
 	@Path("post")
-	public void postDiscobit(@QueryParam("resource") UriRef uri,
-			@QueryParam("graph") UriRef graphUri,
+	public void postDiscobit(@QueryParam("graph") UriRef graphUri,
 			@FormParam("assert") String assertedString,
 			@FormParam("revoke") String revokedString) {
 		MessageBodyReader<Graph> graphReader = providers.getMessageBodyReader(Graph.class, Graph.class, null,rdfXmlType);

Modified: incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/resources/org/apache/clerezza/platform/content/staticweb/scripts/tria-disco.js
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/resources/org/apache/clerezza/platform/content/staticweb/scripts/tria-disco.js?rev=902892&r1=902891&r2=902892&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/resources/org/apache/clerezza/platform/content/staticweb/scripts/tria-disco.js (original)
+++ incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content/src/main/resources/org/apache/clerezza/platform/content/staticweb/scripts/tria-disco.js Mon Jan 25 17:40:09 2010
@@ -5,9 +5,9 @@
 
 TriaDisco.putData = function(rdfSymbol, store, previousStore, noContainerCreation) {
     var xhr = Util.XMLHTTPFactory();
-    var postUrl = "post?resource="+rdfSymbol.uri;
+    var postUrl = "post";
 	if (TriaDisco.graphUri != null) {
-		postUrl += "&graph="+TriaDisco.graphUri
+		postUrl += "?graph="+TriaDisco.graphUri
 	}
     xhr.open('POST', postUrl, false);
 

Modified: incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java?rev=902892&r1=902891&r2=902892&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java (original)
+++ incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java Mon Jan 25 17:40:09 2010
@@ -1,18 +1,20 @@
 /*
- *  Copyright 2010 reto.
+ * 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
  *
- *  Licensed 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
  *
- *       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.
- *  under the License.
+ * 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.clerezza.rdf.utils;
@@ -72,9 +74,6 @@
 			}
 			final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples);
 			NonLiteral subject = triple.getSubject();
-			if (subject instanceof BNode) {
-				subject = null;
-			}
 			Graph context = objectGN.getNodeContext();
 			Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null);
 			while (potentialIter.hasNext()) {
@@ -98,7 +97,7 @@
 			if (triple == null) {
 				break;
 			}
-			final GraphNode subjectGN = new GraphNode(triple.getObject(), unGroundedTriples);
+			final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples);
 			Resource object = triple.getObject();
 			if (object instanceof BNode) {
 				object = null;

Added: incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/MGraphUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/MGraphUtilsTest.java?rev=902892&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/MGraphUtilsTest.java (added)
+++ incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/MGraphUtilsTest.java Mon Jan 25 17:40:09 2010
@@ -0,0 +1,115 @@
+/*
+ * 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.clerezza.rdf.utils;
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.utils.MGraphUtils.NoSuchSubGraphException;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class MGraphUtilsTest {
+
+	final UriRef u1 = new UriRef("http://ex.org/1");
+	final UriRef u2 = new UriRef("http://ex.org/2");
+	final UriRef u3 = new UriRef("http://ex.org/3");
+
+	@Test
+	public void removeSubGraph() throws NoSuchSubGraphException {
+		MGraph baseGraph = new SimpleMGraph();
+		{
+			BNode bNode1 = new BNode();
+			BNode bNode2 = new BNode();
+			baseGraph.add(new TripleImpl(u1, u2, bNode2));
+			baseGraph.add(new TripleImpl(bNode2, u2, bNode2));
+			baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
+			baseGraph.add(new TripleImpl(u3, u2, u1));
+		}
+
+		MGraph subGraph = new SimpleMGraph();
+		{
+			BNode bNode1 = new BNode();
+			BNode bNode2 = new BNode();
+			subGraph.add(new TripleImpl(u1, u2, bNode2));
+			subGraph.add(new TripleImpl(bNode2, u2, bNode2));
+			subGraph.add(new TripleImpl(bNode2, u2, bNode1));
+		}
+		MGraphUtils.removeSubGraph(baseGraph, subGraph);
+		Assert.assertEquals(1, baseGraph.size());
+	}
+	
+	/** It is required that the subgraph comprises the whole context of the Bnodes it ioncludes
+	 * 
+	 * @throws org.apache.clerezza.rdf.utils.MGraphUtils.NoSuchSubGraphException
+	 */
+	@Test(expected=NoSuchSubGraphException.class)
+	public void removeIncompleteSubGraph() throws NoSuchSubGraphException {
+		MGraph baseGraph = new SimpleMGraph();
+		{
+			BNode bNode1 = new BNode();
+			BNode bNode2 = new BNode();
+			baseGraph.add(new TripleImpl(u1, u2, bNode2));
+			baseGraph.add(new TripleImpl(bNode2, u2, bNode2));
+			baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
+			baseGraph.add(new TripleImpl(u3, u2, u1));
+		}
+
+		MGraph subGraph = new SimpleMGraph();
+		{
+			BNode bNode1 = new BNode();
+			BNode bNode2 = new BNode();
+			subGraph.add(new TripleImpl(u1, u2, bNode2));
+			subGraph.add(new TripleImpl(bNode2, u2, bNode2));
+		}
+		MGraphUtils.removeSubGraph(baseGraph, subGraph);
+	}
+
+	@Test(expected=NoSuchSubGraphException.class)
+	public void removeInvalidSubGraph() throws NoSuchSubGraphException {
+		MGraph baseGraph = new SimpleMGraph();
+		{
+			BNode bNode1 = new BNode();
+			BNode bNode2 = new BNode();
+			baseGraph.add(new TripleImpl(u1, u2, bNode2));
+			baseGraph.add(new TripleImpl(bNode2, u2, bNode2));
+			baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
+			baseGraph.add(new TripleImpl(u3, u2, u1));
+		}
+
+		MGraph subGraph = new SimpleMGraph();
+		{
+			BNode bNode1 = new BNode();
+			BNode bNode2 = new BNode();
+			subGraph.add(new TripleImpl(u1, u2, bNode2));
+			subGraph.add(new TripleImpl(bNode2, u2, bNode2));
+			baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
+			baseGraph.add(new TripleImpl(bNode2, u2, new BNode()));
+		}
+		MGraphUtils.removeSubGraph(baseGraph, subGraph);
+	}
+
+}