Author: reto
Date: Fri May 20 17:25:59 2011
New Revision: 1125477
URL: http://svn.apache.org/viewvc?rev=1125477&view=rev
Log:
CLEREZZA-540: added new GraphNodeProvider
Added:
incubator/clerezza/trunk/parent/platform.graphnodeprovider/
- copied from r1124453, incubator/clerezza/trunk/parent/rdf.storage.web/
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/GraphNodeProvider.scala
Removed:
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/WebProxy.scala
Modified:
incubator/clerezza/trunk/parent/platform.graphnodeprovider/pom.xml
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/resources/OSGI-INF/serviceComponents.xml
incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml
incubator/clerezza/trunk/parent/pom.xml
Modified: incubator/clerezza/trunk/parent/platform.graphnodeprovider/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.graphnodeprovider/pom.xml?rev=1125477&r1=1124453&r2=1125477&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/platform.graphnodeprovider/pom.xml
(original)
+++ incubator/clerezza/trunk/parent/platform.graphnodeprovider/pom.xml Fri May
20 17:25:59 2011
@@ -5,12 +5,12 @@
<artifactId>parent</artifactId>
<version>0.2-incubating-SNAPSHOT</version>
</parent>
- <artifactId>rdf.storage.web</artifactId>
+ <artifactId>platform.graphnodeprovider</artifactId>
<version>0.1-incubating-SNAPSHOT</version>
<packaging>bundle</packaging>
- <name>Clerezza - SCB Caching Web Storage Provider</name>
- <description>A (currently read-only) storage provider retrieving graphs
from the web. It
- implements a caching proxy, relying on another provider for storing
triples.</description>
+ <name>Clerezza - Platform GraphNodeProvider</name>
+ <description>A service that provided GraphNodes for URIs with as
underlying BaseGraph sources considered
+ authoritative for that resource.</description>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
@@ -20,6 +20,26 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>platform</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>platform.config</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>platform.graphprovider.content</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>platform.users.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>platform.usermanager</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.ontologies</artifactId>
@@ -40,10 +60,6 @@
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</dependency>
- <dependency>
- <groupId>javax.ws.rs</groupId>
- <artifactId>jsr311-api</artifactId>
- </dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
Modified:
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/resources/OSGI-INF/serviceComponents.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/resources/OSGI-INF/serviceComponents.xml?rev=1125477&r1=1124453&r2=1125477&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/resources/OSGI-INF/serviceComponents.xml
(original)
+++
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/resources/OSGI-INF/serviceComponents.xml
Fri May 20 17:25:59 2011
@@ -1,17 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
- <scr:component enabled="true"
name="org.apache.clerezza.rdf.storage.web.WebProxy">
- <implementation
class="org.apache.clerezza.rdf.storage.web.WebProxy"/>
+ <scr:component enabled="true"
name="org.apache.clerezza.platform.graphnodeprovider.GraphNodeProvider">
+ <implementation
class="org.apache.clerezza.platform.graphnodeprovider.GraphNodeProvider"/>
<service servicefactory="false">
- <provide
interface="org.apache.clerezza.rdf.storage.web.WebProxy"/>
- <provide
interface="org.apache.clerezza.rdf.core.access.WeightedTcProvider"/>
+ <provide
interface="org.apache.clerezza.platform.graphnodeprovider.GraphNodeProvider"/>
</service>
- <!-- hard coded <property name="weight" type="Integer" value="0"/> -->
- <reference name="weightedTcProvider"
interface="org.apache.clerezza.rdf.core.access.WeightedTcProvider"
- cardinality="1..n" policy="dynamic"
bind="bindWeightedTcProvider" unbind="unbindWeightedTcProvider"/>
- <reference name="parser"
interface="org.apache.clerezza.rdf.core.serializedform.Parser"
- cardinality="1..1" policy="static" bind="bindParser"
unbind="unbindParser"/>
+ <reference name="tcManager"
interface="org.apache.clerezza.rdf.core.access.TcManager"
+ cardinality="1..1" policy="static" bind="bindTcManager"
unbind="unbindTcManager"/>
+ <reference name="platformConfig"
interface="org.apache.clerezza.platform.config.PlatformConfig"
+ cardinality="1..1" policy="static" bind="bindPlatformConfig"
unbind="unbindPlatformConfig"/>
+ <reference name="cggProvider"
interface="org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider"
+ cardinality="1..1" policy="static" bind="bindCgProvider"
unbind="unbindCgProvider"/>
+ <reference name="webIdGraphsService"
interface="org.apache.clerezza.platform.users.WebIdGraphsService"
+ cardinality="1..1" policy="static" bind="bindWebIdGraphsService"
unbind="unbindWebIdGraphsService"/>
+ <reference name="userManager"
interface="org.apache.clerezza.platform.usermanager.UserManager"
+ cardinality="1..1" policy="static" bind="bindUserManager"
unbind="unbindUserManager"/>
</scr:component>
</components>
Added:
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/GraphNodeProvider.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/GraphNodeProvider.scala?rev=1125477&view=auto
==============================================================================
---
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/GraphNodeProvider.scala
(added)
+++
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/GraphNodeProvider.scala
Fri May 20 17:25:59 2011
@@ -0,0 +1,220 @@
+/*
+ * 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.platform.graphnodeprovider
+
+
+import org.osgi.service.component.ComponentContext
+import java.io.IOException
+import java.net.{HttpURLConnection, URL}
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat
+import org.apache.clerezza.rdf.core.serializedform.Parser
+import org.slf4j.scala._
+import org.apache.clerezza.rdf.core.access._
+import org.apache.clerezza.rdf.core.impl.AbstractMGraph
+import org.apache.clerezza.rdf.core._
+import org.apache.clerezza.platform.config.PlatformConfig
+import org.apache.clerezza.platform.Constants
+import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider
+import org.apache.clerezza.platform.users.WebIdGraphsService
+import javax.ws.rs.core.UriInfo
+import org.apache.clerezza.rdf.utils.{UnionMGraph,
UriMutatingTripleCollection, GraphNode}
+import java.util.concurrent.locks.Lock
+import org.apache.clerezza.platform.usermanager.UserManager
+import java.security.{PrivilegedAction, PrivilegedExceptionAction,
PrivilegedActionException, AccessController}
+
+/**
+ * A service that returns a GraphNode for a specified named resource, the
returned GraphNode has
+ * as BaseGraph the ContententGraph provided by the ContentGraphProvider and
the for remote uris the
+ * Graphs they dereference to and for local URIs with a path-section starting
with /user/{username}/
+ * the local-public-graph of that user.
+ */
+class GraphNodeProvider extends Logging {
+
+ /**
+ *Get a GraphNode for the specified resource, see class comments for
details.
+ */
+ def get(uriRef: UriRef): GraphNode = {
+
+ def existsInGraph(nodeUri: UriRef, tc: LockableMGraph): Boolean
=
+ {
+ var readLock: Lock = tc.getLock.readLock
+ readLock.lock
+ try {
+ return tc.filter(nodeUri, null,
null).hasNext || tc.filter(null, null, nodeUri).hasNext
+ }
+ finally {
+ readLock.unlock
+ }
+ }
+
+ val uriString = uriRef.getUnicodeString
+
+ val uriPath = {
+ val uri = new java.net.URI(uriRef.getUnicodeString)
+ uri.getPath
+ }
+
+ lazy val uriAuthority = {
+ val uri = new java.net.URI(uriRef.getUnicodeString)
+ uri.getAuthority
+ }
+
+ val isLocal: Boolean = {
+ import scala.collection.JavaConversions._
+ //we assume all non http* uris to be local
+ !uriString.toLowerCase.startsWith("http") ||
platformConfig.getBaseUris.exists(baseUri =>
uriString.startsWith(baseUri.getUnicodeString))
+ }
+
+ val anyHostUri = new UriRef(Constants.ALL_HOSTS_URI_PREFIX +
uriPath)
+
+ var mGraphs: List[TripleCollection] = Nil
+
+ def addToUnion(mGraph: LockableMGraph) {
+ //adding uncondinionately if (existsInGraph(uriRef,
mGraph)) {
+ mGraphs ::= mGraph
+ //}
+ if (isLocal) {
+ if (existsInGraph(anyHostUri, mGraph)) {
+ mGraphs ::= new
UriMutatingTripleCollection(mGraph, Constants.ALL_HOSTS_URI_PREFIX + '/',
uriAuthority)
+ }
+ }
+ }
+
+ val cgGraph = cgProvider.getContentGraph
+
+ addToUnion(cgGraph)
+
+ if (isLocal && uriPath.startsWith("/user/")) {
+ val nextSlash = uriPath.indexOf('/',6)
+ if (nextSlash != -1) {
+ val userName = uriPath.substring(6, nextSlash)
+ val webIdOption =
AccessController.doPrivileged(new PrivilegedAction[Option[UriRef]]() {
+ def run(): Option[UriRef] = {
+ val userNode: GraphNode
= userManager.getUserInSystemGraph(userName)
+ userNode.getNode match {
+ case u: UriRef
=> Some(u)
+ case _ => None
+ }
+ }
+ }
+ )
+ webIdOption match {
+ case Some(u) => {
+ val webIdInfo =
webIdGraphsService.getWebIdInfo(u)
+
addToUnion(webIdInfo.localPublicUserData)
+ }
+ case None => ;
+ }
+ }
+ }
+
+ if (!isLocal) {
+ /**
+ * As the resource might identify something other than
a document we use this to find the redirect location
+ */
+ lazy val redirectLocationString = {
+ val acceptHeader = "application/rdf+xml,*/*;q.1"
+ val url = new URL(uriString)
+ val connection = url.openConnection()
+ connection match {
+ case hc : HttpURLConnection => {
+
hc.setRequestMethod("HEAD");
+
hc.setInstanceFollowRedirects(false)
+
hc.addRequestProperty("Accept", acceptHeader)
+ hc.getResponseCode
match {
+ case
HttpURLConnection.HTTP_SEE_OTHER => {
+
val location = hc.getHeaderField("Location")
+
if (location == null) {
+
throw new RuntimeException("No Location Headers in 303 response")
+
}
+
location
+ }
+ case _ =>
uriString
+ }
+ }
+ case _ => uriString
+ }
+ }
+
+ //TODO add method to WebProxy to get the graph location
location
+ val graphUriString = {
+ val hashPos = uriString.indexOf('#')
+ if (hashPos != -1) {
+ uriString.substring(0, hashPos)
+ } else {
+ redirectLocationString
+ }
+ }
+
+ addToUnion(tcManager.getMGraph(new
UriRef(graphUriString)))
+ }
+
+ val unionMGraph = new UnionMGraph(mGraphs:_*);
+ new GraphNode(uriRef, unionMGraph)
+ }
+
+ private var tcManager: TcManager = null;
+
+ protected def bindTcManager(tcManager: TcManager) = {
+ this.tcManager = tcManager
+ }
+
+ protected def unbindTcManager(tcManager: TcManager) = {
+ this.tcManager = null
+ }
+
+ private var platformConfig: PlatformConfig = null;
+
+ protected def bindPlatformConfig(c: PlatformConfig) = {
+ this.platformConfig = c
+ }
+
+ protected def unbindPlatformConfig(c: PlatformConfig) = {
+ this.platformConfig = null
+ }
+
+ private var cgProvider: ContentGraphProvider = null
+ protected def bindCgProvider(p: ContentGraphProvider) {
+ this.cgProvider = p
+ }
+ protected def unbindCgProvider(p: ContentGraphProvider) {
+ this.cgProvider = null
+ }
+
+ private var webIdGraphsService: WebIdGraphsService = null
+ protected def bindWebIdGraphsService(webIdGraphsService:
WebIdGraphsService): Unit = {
+ this.webIdGraphsService = webIdGraphsService
+ }
+
+ protected def unbindWebIdGraphsService(webIdGraphsService:
WebIdGraphsService): Unit = {
+ this.webIdGraphsService = null
+ }
+
+ private var userManager: UserManager = null
+
+ protected def bindUserManager(userManager: UserManager): Unit = {
+ this.userManager = userManager
+ }
+
+ protected def unbindUserManager(userManager: UserManager): Unit = {
+ this.userManager = null
+ }
+
+}
Modified:
incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml?rev=1125477&r1=1125476&r2=1125477&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml
(original)
+++
incubator/clerezza/trunk/parent/platform.launcher.storageless.parent/pom.xml
Fri May 20 17:25:59 2011
@@ -182,6 +182,11 @@
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
+ <artifactId>platform.graphnodeprovider</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
<artifactId>platform.usermanager</artifactId>
<scope>runtime</scope>
</dependency>
Modified: incubator/clerezza/trunk/parent/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/pom.xml?rev=1125477&r1=1125476&r2=1125477&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/pom.xml (original)
+++ incubator/clerezza/trunk/parent/pom.xml Fri May 20 17:25:59 2011
@@ -60,6 +60,7 @@
<module>platform.documentation</module>
<module>platform.documentation.viewer</module>
<module>platform.enrichment</module>
+ <module>platform.graphnodeprovider</module>
<module>platform.graphprovider.content</module>
<module>platform.language</module>
<module>platform.launcher.storageless.parent</module>
@@ -728,6 +729,11 @@
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
+
<artifactId>platform.graphnodeprovider</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
<artifactId>platform.dashboard</artifactId>
<version>0.4-incubating-SNAPSHOT</version>
</dependency>