[simal] r2235 committed - Configure Joseki SPARQL query engine from Java code when initialising ...

2 views
Skip to first unread message

si...@googlecode.com

unread,
Apr 13, 2011, 1:42:13 PM4/13/11
to simal-...@googlegroups.com
Revision: 2235
Author: sander.v...@oucs.ox.ac.uk
Date: Wed Apr 13 10:36:51 2011
Log: Configure Joseki SPARQL query engine from Java code when
initialising Simal to ensure the right repository is used (fixes Issue 303).
http://code.google.com/p/simal/source/detail?r=2235

Deleted:
/trunk/uk.ac.osswatch.simal.web/src/main/resources/joseki-config.ttl
Modified:

/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.html

/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.java

/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/UserApplication.java
/trunk/uk.ac.osswatch.simal.web/src/main/webapp/WEB-INF/web.xml

/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/TestBase.java

=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/resources/joseki-config.ttl
Wed Feb 3 10:48:02 2010
+++ /dev/null
@@ -1,112 +0,0 @@
-#
-# Copyright 2010 University of Oxford
-#
-# 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
-#
-# 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.
-#
-#
-
-## --------------------------------------------------------------
-## This file is written in N3 / Turtle
-## It is an RDF graph - order of RDF triples does not matter
-## to the machine but it does help people who need to edit this file.
-
-@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
-@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
-
-@prefix module: <http://joseki.org/2003/06/module#> .
-@prefix joseki: <http://joseki.org/2005/06/configuration#> .
-@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
-@prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
-
-## Note: web.xml must be in-step with this file.
-## for each service,
-
-## Note: adding rdfs:label to blank nodes will cause Joseki
-## to print that in log messages.
-
-## See also file:joseki-config-example.ttl
-
-
-## --------------------------------------------------------------
-## About this configuration
-
-<> rdfs:label "Joseki Configuration File - TDB example" .
-
-# Stripped down to support one service that exposes an
-# TDB store as a SPARQL endpoint for query.
-
-[] rdf:type joseki:Server .
-
-## --------------------------------------------------------------
-## Services
-
-## Services are the points that request are sent to.
-## serviceRef that will be used to match requests to services,
-## not some resource URI for the description.
-
-## Note that the service reference and the routing of incoming
-## requests by URI as defined by web.xml have to align.
-
-# Service 1
-# General purpose SPARQL processor, no dataset, expects the
-# request to specify the dataset (either by parameters in the
-# protocol request or in the query itself).
-
-<#service1>
- rdf:type joseki:Service ;
- rdfs:label "SPARQL-TDB" ;
- joseki:serviceRef "joseki/sparql" ; # web.xml just route
this name to Joseki
- joseki:dataset <#dataset> ;
- joseki:processor joseki:ProcessorSPARQL ;
- .
-
-## --------------------------------------------------------------
-## Datasets
-
-## Initialize TDB.
-
-[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
-tdb:DatasetTDB rdfs:subClassOf ja:RDFDataset .
-tdb:GraphTDB rdfs:subClassOf ja:Model .
-
-## ---- A whole dataset managed by TDB
-<#dataset> rdf:type tdb:DatasetTDB ;
-## this works:
-## tdb:location "C:\\dev\\simal\\simal-webapp\\Simal_TDB" ;
- tdb:location "simal_TDB" ;
- .
-
-## --------------------------------------------------------------
-## Processors
-
-joseki:ProcessorSPARQL
- rdfs:label "General SPARQL processor" ;
- rdf:type joseki:Processor ;
- module:implementation joseki:ImplSPARQL ;
-
- # Parameters - this processor processes FROM/FROM NAMED
- joseki:allowExplicitDataset "true"^^xsd:boolean ;
- joseki:allowWebLoading "true"^^xsd:boolean ;
- ## And has no locking policy (it loads data each time).
- ## The default is mutex (one request at a time)
- joseki:lockingPolicy joseki:lockingPolicyNone ;
- .
-
-joseki:ImplSPARQL
- rdf:type joseki:ServiceImpl ;
- module:className
- <java:org.joseki.processors.SPARQL> .
-
-# End:
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.html
Fri Jan 8 09:33:39 2010
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.html
Wed Apr 13 10:36:51 2011
@@ -51,8 +51,8 @@
<td wicket:id="propertiesFile">Properties filepath</td>
</tr>
<tr>
- <td>RDF Repository Dir</td>
- <td wicket:id="repositoryDir">Repository Dir</td>
+ <td>RDF Repository Location</td>
+ <td wicket:id="repositoryLocation">Repository Location</td>
</tr>
<tr>
<td>Update from PTSW:</td>
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.java
Thu Mar 17 09:54:23 2011
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.java
Wed Apr 13 10:36:51 2011
@@ -46,6 +46,7 @@
import uk.ac.osswatch.simal.importData.PTSWImport;
import uk.ac.osswatch.simal.importData.Pims;
import uk.ac.osswatch.simal.model.ModelSupport;
+import uk.ac.osswatch.simal.model.jena.simal.JenaDatabaseSupport;
import uk.ac.osswatch.simal.rdf.DuplicateURIException;
import uk.ac.osswatch.simal.rdf.ISimalRepository;
import uk.ac.osswatch.simal.rdf.SimalException;
@@ -93,8 +94,7 @@
.getProperty(SimalProperties.PROPERTY_SIMAL_INSTANCE_ID)));
add(new Label("propertiesFile",
SimalProperties.getLocalPropertiesFile()
.toString()));
- add(new Label("repositoryDir", SimalProperties
- .getProperty(SimalProperties.PROPERTY_RDF_DATA_DIR)));
+ add(new Label("repositoryLocation",
JenaDatabaseSupport.getDatabasePath()));
if (UserApplication.getScheduledPtswStatus()) {
add(new Label("PTSWUpdaterStatus", "True"));
} else {
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/UserApplication.java
Thu Mar 17 09:54:23 2011
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/UserApplication.java
Wed Apr 13 10:36:51 2011
@@ -17,6 +17,7 @@
* under the License. *
*/

+import java.io.IOError;
import java.net.URL;
import java.util.Timer;

@@ -30,10 +31,19 @@
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.util.convert.ConverterLocator;
+import org.joseki.DatasetDesc;
+import org.joseki.Processor;
+import org.joseki.RDFServer;
+import org.joseki.Registry;
+import org.joseki.Service;
+import org.joseki.ServiceRegistry;
+import org.joseki.processors.SPARQL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import uk.ac.osswatch.simal.SimalRepositoryFactory;
+import uk.ac.osswatch.simal.model.jena.simal.JenaDatabaseSupport;
+import
uk.ac.osswatch.simal.model.jena.simal.JenaDatabaseSupport.JenaDatabaseType;
import uk.ac.osswatch.simal.rdf.ISimalRepository;
import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
import uk.ac.osswatch.simal.schedule.ImportPTSWTask;
@@ -49,6 +59,15 @@
import uk.ac.osswatch.simal.wicket.widgets.WidgetInstancePage;
import uk.ac.osswatch.simal.wicket.widgets.WookieServerConnection;

+import com.hp.hpl.jena.assembler.JA;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
+import com.hp.hpl.jena.tdb.TDB;
+import com.hp.hpl.jena.vocabulary.RDF;
+import com.hp.hpl.jena.vocabulary.RDFS;
+
/**
* The UserApp is the main user facing appliation. This application allows
users
* to view Simal registries.
@@ -92,7 +111,16 @@
mountBookmarkablePage("/category", CategoryDetailPage.class);

mountBookmarkablePage("/widgets", WidgetInstancePage.class);
- }
+
+ try {
+ initRepository(true);
+ initSparqlQueryEngine();
+ } catch (SimalRepositoryException e) {
+ LOGGER.error("Could not initialize repository. Error: " +
e.getMessage(), e);
+ // TODO there must be a more elegant way in Wicket, but couldn't
find it:
+ throw new IOError(e);
+ }
+ }

@Override
public Class<UserHomePage> getHomePage() {
@@ -117,14 +145,37 @@
public static ISimalRepository getRepository()
throws SimalRepositoryException {
if (repository == null) {
- repository = SimalRepositoryFactory.getInstance();
- repository.setIsTest(isTest);
- if (!repository.isInitialised()) {
- repository.initialise();
- }
+ initRepository(true);
}
return repository;
}
+
+ /**
+ * Initialise the Simal repository, if not yet initialised.
+ * @throws SimalRepositoryException
+ */
+ public static void initRepository() throws SimalRepositoryException {
+ initRepository(false);
+ }
+
+ /**
+ * Initialise the Simal repository.
+ *
+ * @param forceInit
+ * If true, force initialisation, if false don't initialise if
+ * already done so.
+ * @throws SimalRepositoryException
+ */
+ private static void initRepository(boolean forceInit)
+ throws SimalRepositoryException {
+ if (repository == null || forceInit) {
+ repository = SimalRepositoryFactory.getInstance();
+ repository.setIsTest(isTest);
+ if (!repository.isInitialised()) {
+ repository.initialise();
+ }
+ }
+ }

/**
* Destroy the repository object used by this application.
@@ -211,4 +262,40 @@
}
return wookieServerConnection;
}
-}
+
+ /**
+ * Initialise Joseki configuration to allow SPARQL querying of the
+ * Jena back-end.
+ */
+ private void initSparqlQueryEngine() {
+ ServiceRegistry myReg = new ServiceRegistry();
+ Processor proc = new SPARQL();
+ String baseRootURI = "#dataset";
+ String serviceURI = "joseki/sparql";
+
+ String dbPath = JenaDatabaseSupport.getDatabasePath();
+
+ if (dbPath != null
+ && JenaDatabaseSupport.getType().equals(JenaDatabaseType.TDB)) {
+ Model model = ModelFactory.createDefaultModel();
+ Resource baseResource = model.createResource(baseRootURI);
+ Resource datasetTDB = ResourceFactory.createResource(TDB.namespace
+ + "DatasetTDB");
+ model.add(baseResource, RDF.type, datasetTDB);
+ model.add(baseResource,
+ ResourceFactory.createProperty(TDB.namespace, "location"),
dbPath);
+ model.add(datasetTDB, RDFS.subClassOf,
+ ResourceFactory.createResource(JA.uri + "RDFDataset"));
+
+ DatasetDesc datasetDesc = new DatasetDesc(baseResource);
+ datasetDesc.initialize();
+
+ Service handler = new Service(proc, serviceURI, datasetDesc);
+ myReg.add(serviceURI, handler);
+
+ Registry.add(RDFServer.ServiceRegistryName, myReg);
+ } else {
+ LOGGER.warn("Could not initialise Joseki, dbPath == " + dbPath);
+ }
+ }
+}
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/webapp/WEB-INF/web.xml Tue Apr
12 07:22:01 2011
+++ /trunk/uk.ac.osswatch.simal.web/src/main/webapp/WEB-INF/web.xml Wed Apr
13 10:36:51 2011
@@ -43,13 +43,6 @@
<servlet>
<servlet-name>SPARQL service processor</servlet-name>
<servlet-class>org.joseki.http.Servlet</servlet-class>
-
- <!-- Configuration file -->
- <init-param>
- <param-name>org.joseki.rdfserver.config</param-name>
- <param-value>joseki-config.ttl</param-value>
- </init-param>
-
</servlet>

<!-- Simal REST API -->
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/TestBase.java
Wed Feb 9 19:34:23 2011
+++
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/TestBase.java
Wed Apr 13 10:36:51 2011
@@ -44,8 +44,9 @@

@BeforeClass
public static void setUpBeforeClass() throws SimalRepositoryException {
+ logger.error(" ************* QQQQQQQQQQQQQQ ********");
UserApplication.setIsTest(true);
- UserApplication.getRepository(); // this initialises the repository
and adds test data
+ UserApplication.initRepository(); // this initialises the repository
and adds test data

IProject project =
SimalRepositoryFactory.getProjectService().findProjectBySeeAlso(TEST_PROJECT_SEEALSO);
projectURI = project.getURI();

Reply all
Reply to author
Forward
0 new messages