Author: reto
Date: Sat Mar  6 12:05:49 2010
New Revision: 919751

URL: http://svn.apache.org/viewvc?rev=919751&view=rev
Log:
CLEREZZA-146: Added GraphManagement interface supporting smushing

Added:
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagement.java
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagementPermission.java
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/Smush.java
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/resources/org/apache/clerezza/rdf/web/core/graph-management.ssp
Modified:
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/
   (props changed)
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/pom.xml

Propchange: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sat Mar  6 12:05:49 2010
@@ -1,2 +1,3 @@
-target
 .project
+target
+nbactions.xml

Modified: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/pom.xml?rev=919751&r1=919750&r2=919751&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/pom.xml
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/pom.xml
 Sat Mar  6 12:05:49 2010
@@ -55,5 +55,10 @@
                        <groupId>org.apache.clerezza</groupId>
                        
<artifactId>org.apache.clerezza.rdf.web.ontologies</artifactId>
                </dependency>
+        <dependency>
+         <groupId>org.apache.clerezza</groupId>
+         <artifactId>org.apache.clerezza.platform.dashboard.core</artifactId>
+        </dependency>
        </dependencies>
 </project>
+

Added: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagement.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagement.java?rev=919751&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagement.java
 (added)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagement.java
 Sat Mar  6 12:05:49 2010
@@ -0,0 +1,124 @@
+/*
+ * 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.web.core;
+
+import java.net.URL;
+import java.security.AccessControlException;
+import java.security.AccessController;
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+import org.apache.clerezza.jaxrs.utils.TrailingSlash;
+import org.apache.clerezza.platform.dashboard.GlobalMenuItem;
+import org.apache.clerezza.platform.dashboard.GlobalMenuItemsProvider;
+import org.apache.clerezza.platform.typerendering.RenderletManager;
+import 
org.apache.clerezza.platform.typerendering.scalaserverpages.ScalaServerPagesRenderlet;
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.access.security.TcPermission;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.PLATFORM;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.ontologies.TCPROVIDER;
+import org.apache.clerezza.rdf.utils.GraphNode;
+import org.apache.clerezza.rdf.web.ontologies.GRAPHMANAGEMENT;
+import org.apache.felix.scr.annotations.Services;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * This JAX-RS resource provides an interface designed to allow various 
management
+ * functions on triple collections. The URI path of this resource is
+ * "/admin/graph-management".
+ * 
+ * @author reto
+ */
+...@component
+...@services({
+       @Service(value = Object.class),
+       @Service(value = GlobalMenuItemsProvider.class)
+})
+...@property(name="javax.ws.rs", boolValue=true)
+...@path("/admin/graph-management")
+public class GraphManagement implements GlobalMenuItemsProvider {
+
+       @Reference
+       private TcManager tcManager;
+
+       @Reference
+       private RenderletManager renderletManager;
+
+       protected void activate(ComponentContext componentContext) {
+               URL templateURL = 
getClass().getResource("graph-management.ssp");
+               
renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
+                               new UriRef(templateURL.toString()), 
GRAPHMANAGEMENT.GraphManagementPage,
+                               "naked", MediaType.APPLICATION_XHTML_XML_TYPE, 
true);
+       }
+
+       @GET
+       public GraphNode mainPage(@Context UriInfo uriInfo) {
+               TrailingSlash.enforcePresent(uriInfo);
+               final SimpleMGraph resultGraph = new SimpleMGraph();
+               GraphNode graphNode = new GraphNode(new BNode(), resultGraph);
+               Set<UriRef> tripleCollections = 
tcManager.listTripleCollections();
+               for (UriRef uriRef : tripleCollections) {
+                       graphNode.addProperty(GRAPHMANAGEMENT.tripleCollection, 
uriRef);
+                       final TripleCollection tripleCollection = 
tcManager.getTriples(uriRef);
+                       resultGraph.add(new 
TripleImpl(uriRef,GRAPHMANAGEMENT.size,
+                                       
LiteralFactory.getInstance().createTypedLiteral(
+                                       tripleCollection.size())));
+                       if (tripleCollection instanceof Graph) {
+                               resultGraph.add(new TripleImpl(uriRef,RDF.type, 
TCPROVIDER.Graph));
+                       } else {
+                               resultGraph.add(new TripleImpl(uriRef,RDF.type, 
TCPROVIDER.MGraph));
+                       }
+               }
+               graphNode.addProperty(RDF.type, 
GRAPHMANAGEMENT.GraphManagementPage);
+               graphNode.addProperty(RDF.type, PLATFORM.HeadedPage);
+               return graphNode;
+       }
+
+       @Override
+       public Set<GlobalMenuItem> getMenuItems() {
+
+               Set<GlobalMenuItem> items = new HashSet<GlobalMenuItem>();
+               try {
+                       AccessController.checkPermission(
+                                       new GraphManagementPermission());
+               } catch (AccessControlException e) {
+                       return items;
+               }
+               String path = "/admin/graph-management";
+               items.add(new GlobalMenuItem(path, "GM", "Graph Management", 
5," System Tools"));
+               return items;
+       }
+
+}

Added: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagementPermission.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagementPermission.java?rev=919751&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagementPermission.java
 (added)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/GraphManagementPermission.java
 Sat Mar  6 12:05:49 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.web.core;
+
+import java.security.Permission;
+
+/**
+ * Permission to use the Graph-Management page. Nothe that the user
+ * additioonally needs permssion on the TripleCollections they manipulate.
+ *
+ * @author reto
+ */
+public class GraphManagementPermission extends Permission {
+
+
+       public GraphManagementPermission() {
+               super("Graph Management permission");
+       }
+       /**
+        * 
+        * @param target ignored
+        * @param action ignored
+        */
+       public GraphManagementPermission(String target, String actions) {
+               super("Graph Management permission");
+       }
+
+       @Override
+       public boolean implies(Permission permission) {
+               return equals(permission);
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               return getClass().equals(obj.getClass());
+       }
+
+       @Override
+       public int hashCode() {
+               return 77985;
+       }
+
+       @Override
+       public String getActions() {
+               return "";
+       }
+
+}

Added: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/Smush.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/Smush.java?rev=919751&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/Smush.java
 (added)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/Smush.java
 Sat Mar  6 12:05:49 2010
@@ -0,0 +1,89 @@
+/*
+ * 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.web.core;
+
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.apache.clerezza.jaxrs.utils.RedirectUtil;
+import org.apache.clerezza.platform.typerendering.RenderletManager;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.FOAF;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.PLATFORM;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.utils.Smusher;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * Provides a method to remove duplicate noded from (aka smush) a Graph
+ * 
+ * @author reto
+ */
+...@component
+...@service(Object.class)
+...@property(name="javax.ws.rs", boolValue=true)
+...@path("/admin/graph-management/smush")
+public class Smush {
+       private final UriRef tBoxName = new 
UriRef("http://tpf.localhost/tbox.graph";);
+
+       @Reference
+       private TcManager tcManager;
+
+       @Reference
+       private RenderletManager renderletManager;
+
+       private TripleCollection tBox;
+
+       protected void activate(ComponentContext componentContext) {
+               try {
+                       //getting the tBox here means no read right on Tbox is 
necessary
+                       //when smushing
+                       tBox = tcManager.getTriples(tBoxName);
+               } catch (NoSuchEntityException e) {
+                       tBox = new SimpleMGraph();
+                       tBox.add(new TripleImpl(FOAF.mbox, RDF.type, 
OWL.InverseFunctionalProperty));
+                       tBox.add(new TripleImpl(FOAF.mbox_sha1sum, RDF.type, 
OWL.InverseFunctionalProperty));
+                       tBox.add(new TripleImpl(PLATFORM.userName, RDF.type, 
OWL.InverseFunctionalProperty));
+                       tBox = tcManager.createGraph(tBoxName, tBox);
+               }
+       }
+
+
+       
+       @POST
+       public Response smush(@Context UriInfo uriInfo, @FormParam("graphName") 
UriRef graphName) {
+               MGraph mGraph = tcManager.getMGraph(graphName);
+               Smusher.smush(mGraph, tBox);
+               return RedirectUtil.createSeeOtherResponse("./", uriInfo);
+       }
+}

Added: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/resources/org/apache/clerezza/rdf/web/core/graph-management.ssp
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/resources/org/apache/clerezza/rdf/web/core/graph-management.ssp?rev=919751&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/resources/org/apache/clerezza/rdf/web/core/graph-management.ssp
 (added)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.web/org.apache.clerezza.rdf.web.core/src/main/resources/org/apache/clerezza/rdf/web/core/graph-management.ssp
 Sat Mar  6 12:05:49 2010
@@ -0,0 +1,33 @@
+def gm(s: Any) = new UriRef("http://clerezza.org/2010/03/graph-management#"+s)
+def rdf(s: Any) = new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#"+s)
+def tcp(s: Any) = new UriRef("http://clerezza.org/2009/06/tcprovider#"+s)
+
+resultDocModifier.setTitle("Manage Triple Collections");
+resultDocModifier.addNodes2Elem("tx-module", <h1>Manage Triple 
Collections</h1>);
+
+import org.apache.clerezza.rdf.scala.utils.RichGraphNode
+
+<div id="tx-content">
+<table>
+       <tr><th>Name</th><th>Size</th><th>type</th><th>Actions</th></tr>
+                               {for (tc <- (res/gm("tripleCollection"))) yield
+                                       <tr>
+                                               <td>{tc*}</td>
+                                               <td>{tc/gm("size")*}</td>
+                                               <td>{if 
((tc/rdf("type")).indexOf(new RichGraphNode(
+                                               new GraphNode(tcp("MGraph"), 
res.getGraph))) != -1) {
+                                               <span>MGraph</span> } else {
+                                               <span>Graph</span>
+                                               }
+                                               }
+                                               </td>
+                                               <td>{ifx 
((tc/rdf("type")).indexOf(new RichGraphNode(
+                                               new GraphNode(tcp("MGraph"), 
res.getGraph))) != -1) {<form action="smush" method="post"><div>
+                                                       <input type="hidden" 
name="graphName" value={tc*} />
+                                               <input type="submit" 
value="smush" /></div></form>}
+                                               }</td>
+                                       </tr>
+                               }
+</table>
+<p><a href="/graph/upload-form">UploadGraph</a></p>
+</div>


Reply via email to