VIVO-773 Update the JENA libraries and adjust to the changes
Replace the JAR files with more current ones. Add a one-line change to BaseInfGraph (from the Jena source), so it will work with Pellet 2.3.1 Adjust all implementations of Graph to include new methods and remove old ones. Add annotations and generics to reduce compiler warnings. Remove all dependencies on RDB, which is no longer supported. This requires considerable refactoring of JenaIngestController, RDFUploadController, listModels.jsp Refactor the ModelMaker uses Remove VitroJenaModelMaker, Revise VitroInterceptingModelMaker to be configurable for Config or Content models Add debug logging code to ModelChangeImpl ChangeSetImpl, RDFServiceJena. Add TDB support: RDFServiceFactoryTDB, RDFServiceTDB Refactor RDFServiceJena and RDFServiceSDB so much of the code can be reused by RDFServiceTDB Accomodate two RDFService instances - one for Configuration models and one for Content models. Changes to RDFServiceUtils, RDFServiceSetup Configuration models use TDB directory in Vitro home directory Handle bulk updating: Jena has deprecated bulk operations, and their models classes no longer use the bulk updaters Create a VitroModelFactory to use instead of the ModelFactory, when bulk updating is required. Create adapter classes: BulkUpdatingModel, BulkUpdatingOntModel, AbstractModelDecorator Make the configuration model setup algorithms uniform Combine ApplicationModelSetup and UserModelSetup into ConfigurationModelsSetup
This commit is contained in:
parent
03c87f49a4
commit
3a2930cdc6
81 changed files with 6293 additions and 1628 deletions
|
@ -36,7 +36,6 @@ log4j.rootLogger=INFO, AllAppender
|
||||||
# These classes are too chatty to display INFO messages.
|
# These classes are too chatty to display INFO messages.
|
||||||
log4j.logger.edu.cornell.mannlib.vitro.webapp.startup.StartupStatus=WARN
|
log4j.logger.edu.cornell.mannlib.vitro.webapp.startup.StartupStatus=WARN
|
||||||
log4j.logger.edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener=WARN
|
log4j.logger.edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener=WARN
|
||||||
log4j.logger.edu.cornell.mannlib.vitro.webapp.dao.jena.RDBGraphGenerator=WARN
|
|
||||||
log4j.logger.edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase=DEBUG
|
log4j.logger.edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase=DEBUG
|
||||||
|
|
||||||
# Spring as a whole is too chatty to display INFO messages.
|
# Spring as a whole is too chatty to display INFO messages.
|
||||||
|
@ -44,7 +43,6 @@ log4j.logger.org.springframework=WARN
|
||||||
|
|
||||||
# suppress odd warnings from libraries
|
# suppress odd warnings from libraries
|
||||||
log4j.logger.com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes=FATAL
|
log4j.logger.com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes=FATAL
|
||||||
log4j.logger.com.hp.hpl.jena.db.impl.PSet_TripleStore_RDB=FATAL
|
|
||||||
log4j.logger.com.hp.hpl.jena.sdb.sql.SDBConnection=ERROR
|
log4j.logger.com.hp.hpl.jena.sdb.sql.SDBConnection=ERROR
|
||||||
log4j.logger.org.openjena.riot=FATAL
|
log4j.logger.org.openjena.riot=FATAL
|
||||||
log4j.logger.org.directwebremoting=FATAL
|
log4j.logger.org.directwebremoting=FATAL
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
webapp/lib/commons-codec-1.6.jar
Normal file
BIN
webapp/lib/commons-codec-1.6.jar
Normal file
Binary file not shown.
Binary file not shown.
BIN
webapp/lib/jena-arq-2.10.1.jar
Normal file
BIN
webapp/lib/jena-arq-2.10.1.jar
Normal file
Binary file not shown.
BIN
webapp/lib/jena-core-2.10.1.jar
Normal file
BIN
webapp/lib/jena-core-2.10.1.jar
Normal file
Binary file not shown.
BIN
webapp/lib/jena-iri-0.9.6.jar
Normal file
BIN
webapp/lib/jena-iri-0.9.6.jar
Normal file
Binary file not shown.
BIN
webapp/lib/jena-sdb-1.3.6.jar
Normal file
BIN
webapp/lib/jena-sdb-1.3.6.jar
Normal file
Binary file not shown.
BIN
webapp/lib/jena-tdb-0.10.0.jar
Normal file
BIN
webapp/lib/jena-tdb-0.10.0.jar
Normal file
Binary file not shown.
Binary file not shown.
BIN
webapp/lib/junit-4.9.jar
Normal file
BIN
webapp/lib/junit-4.9.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
webapp/lib/xercesImpl-2.11.0.jar
Normal file
BIN
webapp/lib/xercesImpl-2.11.0.jar
Normal file
Binary file not shown.
Binary file not shown.
BIN
webapp/lib/xml-apis-1.4.01.jar
Normal file
BIN
webapp/lib/xml-apis-1.4.01.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
544
webapp/src/com/hp/hpl/jena/reasoner/BaseInfGraph.java
Normal file
544
webapp/src/com/hp/hpl/jena/reasoner/BaseInfGraph.java
Normal file
|
@ -0,0 +1,544 @@
|
||||||
|
/*
|
||||||
|
* 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 com.hp.hpl.jena.reasoner;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.graph.*;
|
||||||
|
import com.hp.hpl.jena.graph.compose.MultiUnion;
|
||||||
|
import com.hp.hpl.jena.graph.impl.*;
|
||||||
|
import com.hp.hpl.jena.shared.*;
|
||||||
|
import com.hp.hpl.jena.util.iterator.*;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A base level implementation of the InfGraph interface.
|
||||||
|
*/
|
||||||
|
public abstract class BaseInfGraph extends GraphBase implements InfGraph {
|
||||||
|
|
||||||
|
/** The Reasoner instance which performs all inferences and Tbox lookups */
|
||||||
|
protected Reasoner reasoner;
|
||||||
|
|
||||||
|
/** The graph of raw data which is being reasoned over */
|
||||||
|
protected FGraph fdata;
|
||||||
|
|
||||||
|
/** Flag, if set to true then derivations are recorded */
|
||||||
|
protected boolean recordDerivations;
|
||||||
|
|
||||||
|
/** Flag to record if the preparation call has been made and so the graph is ready for queries */
|
||||||
|
protected volatile boolean isPrepared = false;
|
||||||
|
|
||||||
|
/** version count */
|
||||||
|
protected volatile int version = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Inference graphs share the prefix-mapping of their underlying raw graph.
|
||||||
|
@see com.hp.hpl.jena.graph.Graph#getPrefixMapping()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PrefixMapping getPrefixMapping()
|
||||||
|
{ return getRawGraph().getPrefixMapping(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param data the raw data file to be augmented with entailments
|
||||||
|
* @param reasoner the engine, with associated tbox data, whose find interface
|
||||||
|
* can be used to extract all entailments from the data.
|
||||||
|
*/
|
||||||
|
public BaseInfGraph(Graph data, Reasoner reasoner) {
|
||||||
|
super( );
|
||||||
|
this.fdata = new FGraph( data );
|
||||||
|
this.reasoner = reasoner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Answer the InfCapabilities of this InfGraph.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Capabilities getCapabilities() {
|
||||||
|
if (capabilities == null) {
|
||||||
|
return getReasoner().getGraphCapabilities();
|
||||||
|
} else {
|
||||||
|
return capabilities;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
An InfCapabilities notes that size may not be accurate, and some
|
||||||
|
triples may be irremovable.
|
||||||
|
|
||||||
|
TODO accomodate the properties of the base graph, too.
|
||||||
|
*/
|
||||||
|
public static class InfCapabilities extends AllCapabilities
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean sizeAccurate() { return false; }
|
||||||
|
@Override
|
||||||
|
public boolean deleteAllowed( boolean every ) { return !every; }
|
||||||
|
@Override
|
||||||
|
public boolean iteratorRemoveAllowed() { return false; }
|
||||||
|
@Override
|
||||||
|
public boolean findContractSafe() { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
An InfCapabilities notes that size may not be accurate, and some
|
||||||
|
triples may be irremovable.
|
||||||
|
|
||||||
|
TODO accomodate the properties of the base graph, too.
|
||||||
|
*/
|
||||||
|
public static class InfFindSafeCapabilities extends InfCapabilities
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean findContractSafe() { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@deprecated Bulk update operations are going to be removed.
|
||||||
|
@see GraphUtil for convenience helpers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public BulkUpdateHandler getBulkUpdateHandler()
|
||||||
|
{
|
||||||
|
if (bulkHandler == null) bulkHandler = new InfBulkUpdateHandler( this );
|
||||||
|
return bulkHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
InfBulkUpdateHandler - a bulk update handler specialised for inference
|
||||||
|
graphs by code for <code>removeAll()</code>.
|
||||||
|
*/
|
||||||
|
static class InfBulkUpdateHandler extends SimpleBulkUpdateHandler
|
||||||
|
{
|
||||||
|
public InfBulkUpdateHandler( BaseInfGraph graph )
|
||||||
|
{ super(graph); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public void remove( Node s, Node p, Node o )
|
||||||
|
{
|
||||||
|
BaseInfGraph g = (BaseInfGraph) graph;
|
||||||
|
g.getRawGraph().remove( s, p, o );
|
||||||
|
g.discardState();
|
||||||
|
g.rebind();
|
||||||
|
manager.notifyEvent( graph, GraphEvents.remove( s, p, o ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public void removeAll()
|
||||||
|
{
|
||||||
|
BaseInfGraph g = (BaseInfGraph) graph;
|
||||||
|
g.getRawGraph().clear();
|
||||||
|
g.discardState();
|
||||||
|
g.rebind();
|
||||||
|
g.getEventManager().notifyEvent( g, GraphEvents.removeAll );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove( Node s, Node p, Node o )
|
||||||
|
{
|
||||||
|
getRawGraph().remove( s, p, o );
|
||||||
|
discardState();
|
||||||
|
rebind();
|
||||||
|
getEventManager().notifyEvent( this, GraphEvents.remove( s, p, o ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
getRawGraph().clear() ;
|
||||||
|
discardState();
|
||||||
|
rebind();
|
||||||
|
getEventManager().notifyEvent( this, GraphEvents.removeAll );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransactionHandler getTransactionHandler()
|
||||||
|
{ return new InfTransactionHandler( this ); }
|
||||||
|
|
||||||
|
public static class InfTransactionHandler
|
||||||
|
extends TransactionHandlerBase implements TransactionHandler
|
||||||
|
{
|
||||||
|
protected final BaseInfGraph base;
|
||||||
|
|
||||||
|
public InfTransactionHandler( BaseInfGraph base )
|
||||||
|
{ this.base = base; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean transactionsSupported()
|
||||||
|
{ return getBaseHandler().transactionsSupported(); }
|
||||||
|
|
||||||
|
protected TransactionHandler getBaseHandler()
|
||||||
|
{ return base.getRawGraph().getTransactionHandler(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void begin()
|
||||||
|
{ getBaseHandler().begin(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void abort()
|
||||||
|
{ getBaseHandler().abort();
|
||||||
|
base.rebind(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void commit()
|
||||||
|
{ getBaseHandler().commit(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
discard any state that depends on the content of fdata, because
|
||||||
|
it's just been majorly trashed, solid gone.
|
||||||
|
*/
|
||||||
|
protected void discardState()
|
||||||
|
{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the raw RDF data Graph being processed (i.e. the argument
|
||||||
|
* to the Reasonder.bind call that created this InfGraph).
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Graph getRawGraph() {
|
||||||
|
return fdata.getGraph();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the Reasoner which is being used to answer queries to this graph.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Reasoner getReasoner() {
|
||||||
|
return reasoner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace the underlying data graph for this inference graph and start any
|
||||||
|
* inferences over again. This is primarily using in setting up ontology imports
|
||||||
|
* processing to allow an imports multiunion graph to be inserted between the
|
||||||
|
* inference graph and the raw data, before processing.
|
||||||
|
* @param data the new raw data graph
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void rebind(Graph data) {
|
||||||
|
fdata = new FGraph(data);
|
||||||
|
isPrepared = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cause the inference graph to reconsult the underlying graph to take
|
||||||
|
* into account changes. Normally changes are made through the InfGraph's add and
|
||||||
|
* remove calls are will be handled appropriately. However, in some cases changes
|
||||||
|
* are made "behind the InfGraph's back" and this forces a full reconsult of
|
||||||
|
* the changed data.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void rebind() {
|
||||||
|
version++;
|
||||||
|
isPrepared = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset any internal caches. Some systems, such as the tabled backchainer,
|
||||||
|
* retain information after each query. A reset will wipe this information preventing
|
||||||
|
* unbounded memory use at the expense of more expensive future queries. A reset
|
||||||
|
* does not cause the raw data to be reconsulted and so is less expensive than a rebind.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
version++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform any initial processing and caching. This call is optional. Most
|
||||||
|
* engines either have negligable set up work or will perform an implicit
|
||||||
|
* "prepare" if necessary. The call is provided for those occasions where
|
||||||
|
* substantial preparation work is possible (e.g. running a forward chaining
|
||||||
|
* rule system) and where an application might wish greater control over when
|
||||||
|
* this prepration is done.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void prepare() {
|
||||||
|
// Default is to do no preparation
|
||||||
|
isPrepared = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a derivations graph. The rule reasoners typically create a
|
||||||
|
* graph containing those triples added to the base graph due to rule firings.
|
||||||
|
* In some applications it can useful to be able to access those deductions
|
||||||
|
* directly, without seeing the raw data which triggered them. In particular,
|
||||||
|
* this allows the forward rules to be used as if they were rewrite transformation
|
||||||
|
* rules.
|
||||||
|
* @return the deductions graph, if relevant for this class of inference
|
||||||
|
* engine or null if not.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Graph getDeductionsGraph() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test a global boolean property of the graph. This might included
|
||||||
|
* properties like consistency, OWLSyntacticValidity etc.
|
||||||
|
* It remains to be seen what level of generality is needed here. We could
|
||||||
|
* replace this by a small number of specific tests for common concepts.
|
||||||
|
* @param property the URI of the property to be tested
|
||||||
|
* @return a Node giving the value of the global property, this may
|
||||||
|
* be a boolean literal, some other literal value (e.g. a size).
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Node getGlobalProperty(Node property) {
|
||||||
|
throw new ReasonerException("Global property not implemented: " + property);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience version of getGlobalProperty which can only return
|
||||||
|
* a boolean result.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean testGlobalProperty(Node property) {
|
||||||
|
Node resultNode = getGlobalProperty(property);
|
||||||
|
if (resultNode.isLiteral()) {
|
||||||
|
Object result = resultNode.getLiteralValue();
|
||||||
|
if (result instanceof Boolean) {
|
||||||
|
return ((Boolean)result).booleanValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ReasonerException("Global property test returned non-boolean value" +
|
||||||
|
"\nTest was: " + property +
|
||||||
|
"\nResult was: " + resultNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the consistency of the bound data. This normally tests
|
||||||
|
* the validity of the bound instance data against the bound
|
||||||
|
* schema data.
|
||||||
|
* @return a ValidityReport structure
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ValidityReport validate() {
|
||||||
|
checkOpen();
|
||||||
|
return new StandardValidityReport();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An extension of the Graph.find interface which allows the caller to
|
||||||
|
* encode complex expressions in RDF and then refer to those expressions
|
||||||
|
* within the query triple. For example, one might encode a class expression
|
||||||
|
* and then ask if there are any instances of this class expression in the
|
||||||
|
* InfGraph.
|
||||||
|
* @param subject the subject Node of the query triple, may be a Node in
|
||||||
|
* the graph or a node in the parameter micro-graph or null
|
||||||
|
* @param property the property to be retrieved or null
|
||||||
|
* @param object the object Node of the query triple, may be a Node in
|
||||||
|
* the graph or a node in the parameter micro-graph.
|
||||||
|
* @param param a small graph encoding an expression which the subject and/or
|
||||||
|
* object nodes refer.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ExtendedIterator<Triple> find(Node subject, Node property, Node object, Graph param) {
|
||||||
|
return cloneWithPremises(param).find(subject, property, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an iterator over Triples.
|
||||||
|
*
|
||||||
|
* <p>This code used to have the .filterKeep component uncommented. We
|
||||||
|
* think this is because of earlier history, before .matches on a literal node
|
||||||
|
* was implemented as sameValueAs rather than equals. If it turns out that
|
||||||
|
* the filter is needed, it can be commented back in, AND a corresponding
|
||||||
|
* filter added to find(Node x 3) -- and test cases, of course.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ExtendedIterator<Triple> graphBaseFind(TripleMatch m) {
|
||||||
|
return graphBaseFind(m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject())
|
||||||
|
// .filterKeep(new TripleMatchFilter(m.asTriple()))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an iterator over Triples.
|
||||||
|
* This implementation assumes that the underlying findWithContinuation
|
||||||
|
* will have also consulted the raw data.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ExtendedIterator<Triple> graphBaseFind(Node subject, Node property, Node object) {
|
||||||
|
return findWithContinuation(new TriplePattern(subject, property, object), fdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended find interface used in situations where the implementator
|
||||||
|
* may or may not be able to answer the complete query. It will
|
||||||
|
* attempt to answer the pattern but if its answers are not known
|
||||||
|
* to be complete then it will also pass the request on to the nested
|
||||||
|
* Finder to append more results.
|
||||||
|
* @param pattern a TriplePattern to be matched against the data
|
||||||
|
* @param continuation either a Finder or a normal Graph which
|
||||||
|
* will be asked for additional match results if the implementor
|
||||||
|
* may not have completely satisfied the query.
|
||||||
|
*/
|
||||||
|
abstract public ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder continuation);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic pattern lookup interface.
|
||||||
|
* This implementation assumes that the underlying findWithContinuation
|
||||||
|
* will have also consulted the raw data.
|
||||||
|
* @param pattern a TriplePattern to be matched against the data
|
||||||
|
* @return a ExtendedIterator over all Triples in the data set
|
||||||
|
* that match the pattern
|
||||||
|
*/
|
||||||
|
public ExtendedIterator<Triple> find(TriplePattern pattern) {
|
||||||
|
checkOpen();
|
||||||
|
return findWithContinuation(pattern, fdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch on/off drivation logging
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setDerivationLogging(boolean logOn) {
|
||||||
|
recordDerivations = logOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the derivation of the given triple (which is the result of
|
||||||
|
* some previous find operation).
|
||||||
|
* Not all reasoneers will support derivations.
|
||||||
|
* @return an iterator over Derivation records or null if there is no derivation information
|
||||||
|
* available for this triple.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Iterator<Derivation> getDerivation(Triple triple) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of triples in the just the base graph
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int graphBaseSize() {
|
||||||
|
checkOpen();
|
||||||
|
return fdata.getGraph().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Answer true iff this graph is empty. [Used to be in QueryHandler, but moved in
|
||||||
|
here because it's a more primitive operation.]
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return fdata.getGraph().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free all resources, any further use of this Graph is an error.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
if (!closed) {
|
||||||
|
fdata.getGraph().close();
|
||||||
|
fdata = null;
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a version stamp for this graph which can be
|
||||||
|
* used to fast-fail concurrent modification exceptions.
|
||||||
|
*/
|
||||||
|
public int getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add one triple to the data graph, run any rules triggered by
|
||||||
|
* the new data item, recursively adding any generated triples.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void performAdd(Triple t) {
|
||||||
|
version++;
|
||||||
|
this.requirePrepared();
|
||||||
|
fdata.getGraph().add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the triple t (if possible) from the set belonging to this graph.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void performDelete(Triple t) {
|
||||||
|
version++;
|
||||||
|
this.requirePrepared();
|
||||||
|
fdata.getGraph().delete(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the schema graph, if any, bound into this inference graph.
|
||||||
|
*/
|
||||||
|
public abstract Graph getSchemaGraph();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a new inference graph which is a clone of the current graph
|
||||||
|
* together with an additional set of data premises. The default
|
||||||
|
* implementation loses ALL partial deductions so far. Some subclasses
|
||||||
|
* may be able to a more efficient job.
|
||||||
|
*/
|
||||||
|
public InfGraph cloneWithPremises(Graph premises) {
|
||||||
|
MultiUnion union = new MultiUnion();
|
||||||
|
Graph raw = getRawGraph();
|
||||||
|
union.addGraph( raw );
|
||||||
|
union.setBaseGraph( raw );
|
||||||
|
union.addGraph( premises );
|
||||||
|
Graph schema = getSchemaGraph();
|
||||||
|
if (schema != null) {
|
||||||
|
if (schema instanceof BaseInfGraph) {
|
||||||
|
BaseInfGraph ischema = (BaseInfGraph)schema;
|
||||||
|
Graph sschema = ischema.getSchemaGraph();
|
||||||
|
if (sschema != null) union.addGraph( sschema );
|
||||||
|
Graph rschema = ischema.getRawGraph();
|
||||||
|
if (rschema != null) union.addGraph( rschema );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return getReasoner().bind(union);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Answer true iff this graph has been through the <code>prepare()</code> step.
|
||||||
|
For testing purposes.
|
||||||
|
* @return Whether the graph is prepared
|
||||||
|
*/
|
||||||
|
public synchronized boolean isPrepared()
|
||||||
|
{ return isPrepared; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset prepared state to false
|
||||||
|
*/
|
||||||
|
protected synchronized void setPreparedState(boolean state) {
|
||||||
|
this.isPrepared = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the graph is prepared and calls {@link #prepare()} if it is not
|
||||||
|
*/
|
||||||
|
protected synchronized void requirePrepared() {
|
||||||
|
if (!this.isPrepared) this.prepare();
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.Syntax;
|
import com.hp.hpl.jena.query.Syntax;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.sparql.resultset.ResultSetFormat;
|
import com.hp.hpl.jena.sparql.resultset.ResultsFormat;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
|
@ -31,13 +31,13 @@ public class SparqlQueryBuilderServlet extends BaseEditController {
|
||||||
|
|
||||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||||
|
|
||||||
protected static HashMap<String,ResultSetFormat>formatSymbols = new HashMap<String,ResultSetFormat>();
|
protected static HashMap<String,ResultsFormat>formatSymbols = new HashMap<String,ResultsFormat>();
|
||||||
static{
|
static{
|
||||||
formatSymbols.put( ResultSetFormat.syntaxXML.getSymbol(), ResultSetFormat.syntaxXML);
|
formatSymbols.put( ResultsFormat.FMT_RS_XML.getSymbol(), ResultsFormat.FMT_RS_XML);
|
||||||
formatSymbols.put( ResultSetFormat.syntaxRDF_XML.getSymbol(), ResultSetFormat.syntaxRDF_XML);
|
formatSymbols.put( ResultsFormat.FMT_RDF_XML.getSymbol(), ResultsFormat.FMT_RDF_XML);
|
||||||
formatSymbols.put( ResultSetFormat.syntaxRDF_N3.getSymbol(), ResultSetFormat.syntaxRDF_N3);
|
formatSymbols.put( ResultsFormat.FMT_RDF_N3.getSymbol(), ResultsFormat.FMT_RDF_N3);
|
||||||
formatSymbols.put( ResultSetFormat.syntaxText.getSymbol() , ResultSetFormat.syntaxText);
|
formatSymbols.put( ResultsFormat.FMT_TEXT.getSymbol() , ResultsFormat.FMT_TEXT);
|
||||||
formatSymbols.put( ResultSetFormat.syntaxJSON.getSymbol() , ResultSetFormat.syntaxJSON);
|
formatSymbols.put( ResultsFormat.FMT_RS_JSON.getSymbol() , ResultsFormat.FMT_RS_JSON);
|
||||||
formatSymbols.put( "vitro:csv", null);
|
formatSymbols.put( "vitro:csv", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,11 +52,11 @@ public class SparqlQueryBuilderServlet extends BaseEditController {
|
||||||
|
|
||||||
protected static HashMap<String, String>mimeTypes = new HashMap<String,String>();
|
protected static HashMap<String, String>mimeTypes = new HashMap<String,String>();
|
||||||
static{
|
static{
|
||||||
mimeTypes.put( ResultSetFormat.syntaxXML.getSymbol() , "text/xml" );
|
mimeTypes.put( ResultsFormat.FMT_RS_XML.getSymbol() , "text/xml" );
|
||||||
mimeTypes.put( ResultSetFormat.syntaxRDF_XML.getSymbol(), "application/rdf+xml" );
|
mimeTypes.put( ResultsFormat.FMT_RDF_XML.getSymbol(), "application/rdf+xml" );
|
||||||
mimeTypes.put( ResultSetFormat.syntaxRDF_N3.getSymbol(), "text/plain" );
|
mimeTypes.put( ResultsFormat.FMT_RDF_N3.getSymbol(), "text/plain" );
|
||||||
mimeTypes.put( ResultSetFormat.syntaxText.getSymbol() , "text/plain");
|
mimeTypes.put( ResultsFormat.FMT_TEXT.getSymbol() , "text/plain");
|
||||||
mimeTypes.put( ResultSetFormat.syntaxJSON.getSymbol(), "application/javascript" );
|
mimeTypes.put( ResultsFormat.FMT_RS_JSON.getSymbol(), "application/javascript" );
|
||||||
mimeTypes.put( "vitro:csv", "text/csv");
|
mimeTypes.put( "vitro:csv", "text/csv");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,15 +100,6 @@ public class SparqlQueryBuilderServlet extends BaseEditController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doHelp(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
|
private void doHelp(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
|
||||||
|
|
||||||
//res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(req);
|
|
||||||
|
|
||||||
/* Code change completed */
|
|
||||||
|
|
||||||
// nac26: 2009-09-25 - this was causing problems in safari on localhost installations because the href did not include the context. The edit.css is not being used here anyway (or anywhere else for that matter)
|
|
||||||
// req.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""+portal.getThemeDir()+"css/edit.css\"/>");
|
|
||||||
req.setAttribute("title","SPARQL Query Builder");
|
req.setAttribute("title","SPARQL Query Builder");
|
||||||
req.setAttribute("bodyJsp", "/admin/sparql.jsp");
|
req.setAttribute("bodyJsp", "/admin/sparql.jsp");
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.apache.commons.io.IOUtils;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
import com.hp.hpl.jena.query.ResultSetFactory;
|
import com.hp.hpl.jena.query.ResultSetFactory;
|
||||||
import com.hp.hpl.jena.query.ResultSetFormatter;
|
import com.hp.hpl.jena.query.ResultSetFormatter;
|
||||||
import com.hp.hpl.jena.sparql.resultset.ResultSetFormat;
|
import com.hp.hpl.jena.sparql.resultset.ResultsFormat;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
|
@ -56,7 +56,7 @@ abstract class SparqlQueryApiResultSetProducer extends SparqlQueryApiExecutor {
|
||||||
pipeWithReplacement(rawResult, out);
|
pipeWithReplacement(rawResult, out);
|
||||||
} else {
|
} else {
|
||||||
ResultSet rs = ResultSetFactory.fromJSON(rawResult);
|
ResultSet rs = ResultSetFactory.fromJSON(rawResult);
|
||||||
ResultSetFormat format = ResultSetFormat.lookup(mediaType
|
ResultsFormat format = ResultsFormat.lookup(mediaType
|
||||||
.getJenaResponseFormat());
|
.getJenaResponseFormat());
|
||||||
ResultSetFormatter.output(out, rs, format);
|
ResultSetFormatter.output(out, rs, format);
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ class IndividualTemplateLocator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If still no custom template defined, and inferencing is asynchronous (under RDB), check
|
// If still no custom template defined and inferencing is asynchronous, check
|
||||||
// the superclasses of the vclass for a custom template specification.
|
// the superclasses of the vclass for a custom template specification.
|
||||||
SimpleReasoner simpleReasoner = (SimpleReasoner) ctx.getAttribute(SimpleReasoner.class.getName());
|
SimpleReasoner simpleReasoner = (SimpleReasoner) ctx.getAttribute(SimpleReasoner.class.getName());
|
||||||
if (customTemplate == null && simpleReasoner != null && simpleReasoner.isABoxReasoningAsynchronous()) {
|
if (customTemplate == null && simpleReasoner != null && simpleReasoner.isABoxReasoningAsynchronous()) {
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class JenaCsv2RdfController extends JenaIngestController {
|
||||||
forwardToFileUploadError(ex.getMessage(),request,response);
|
forwardToFileUploadError(ex.getMessage(),request,response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ModelMaker maker = getVitroJenaModelMaker(request);
|
ModelMaker maker = getModelMaker(request);
|
||||||
Boolean csv2rdf = true;
|
Boolean csv2rdf = true;
|
||||||
JenaIngestUtils utils = new JenaIngestUtils();
|
JenaIngestUtils utils = new JenaIngestUtils();
|
||||||
List<Model> resultList = new ArrayList<Model>();
|
List<Model> resultList = new ArrayList<Model>();
|
||||||
|
|
|
@ -67,6 +67,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
|
@ -122,28 +123,28 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
ModelMaker maker = getVitroJenaModelMaker(vreq);
|
ModelMaker maker = getModelMaker(vreq);
|
||||||
String modelType = getModelType(vreq);
|
ModelMakerID modelType = getModelType(vreq);
|
||||||
|
|
||||||
String actionStr = vreq.getParameter("action");
|
String actionStr = vreq.getParameter("action");
|
||||||
actionStr = (actionStr != null) ? actionStr : "";
|
actionStr = (actionStr != null) ? actionStr : "";
|
||||||
|
|
||||||
if("listModels".equals(actionStr)) {
|
if("listModels".equals(actionStr)) {
|
||||||
processListModelsRequest(vreq, maker, modelType);
|
processListModelsRequest(vreq, maker, modelType);
|
||||||
} else if("rdbModels".equals(actionStr)){
|
} else if("configModels".equals(actionStr)){
|
||||||
processRDBModelsRequest(vreq, maker, modelType);
|
processConfigModelsRequest(vreq);
|
||||||
} else if("sdbModels".equals(actionStr)){
|
} else if("contentModels".equals(actionStr)){
|
||||||
processSDBModelsRequest(vreq, maker, modelType);
|
processContentModelsRequest(vreq);
|
||||||
} else if("createModel".equals(actionStr)) {
|
} else if("createModel".equals(actionStr)) {
|
||||||
processCreateModelRequest(vreq, maker, modelType);
|
processCreateModelRequest(vreq, maker, modelType);
|
||||||
} else if("removeModel".equals(actionStr)) {
|
} else if("removeModel".equals(actionStr)) {
|
||||||
processRemoveModelRequest(vreq, maker, modelType);
|
processRemoveModelRequest(vreq, maker, modelType);
|
||||||
} else if("loadRDFData".equals(actionStr)) {
|
} else if("loadRDFData".equals(actionStr)) {
|
||||||
processLoadRDFDataRequest(vreq, maker, modelType);
|
processLoadRDFDataRequest(vreq, maker);
|
||||||
} else if("cleanLiterals".equals(actionStr)) {
|
} else if("cleanLiterals".equals(actionStr)) {
|
||||||
processCleanLiteralsRequest(vreq, maker, modelType);
|
processCleanLiteralsRequest(vreq);
|
||||||
} else if("outputModel".equals(actionStr)) {
|
} else if("outputModel".equals(actionStr)) {
|
||||||
processOutputModelRequest(vreq, response, maker, modelType);
|
processOutputModelRequest(vreq, response);
|
||||||
return; // don't attempt to display a JSP
|
return; // don't attempt to display a JSP
|
||||||
} else if("clearModel".equals(actionStr)) {
|
} else if("clearModel".equals(actionStr)) {
|
||||||
processClearModelRequest(vreq, maker, modelType);
|
processClearModelRequest(vreq, maker, modelType);
|
||||||
|
@ -152,35 +153,35 @@ public class JenaIngestController extends BaseEditController {
|
||||||
} else if("detachModel".equals(actionStr)) {
|
} else if("detachModel".equals(actionStr)) {
|
||||||
processDetachModelRequest(vreq, maker, modelType);
|
processDetachModelRequest(vreq, maker, modelType);
|
||||||
} else if("renameBNodes".equals(actionStr)) {
|
} else if("renameBNodes".equals(actionStr)) {
|
||||||
processRenameBNodesRequest(vreq, maker, modelType);
|
processRenameBNodesRequest(vreq, maker);
|
||||||
} else if("renameBNodesURISelect".equals(actionStr)){
|
} else if("renameBNodesURISelect".equals(actionStr)){
|
||||||
processRenameBNodesURISelectRequest(vreq, maker, modelType);
|
processRenameBNodesURISelectRequest(vreq, maker);
|
||||||
} else if("smushSingleModel".equals(actionStr)) {
|
} else if("smushSingleModel".equals(actionStr)) {
|
||||||
processSmushSingleModelRequest(vreq, maker, modelType);
|
processSmushSingleModelRequest(vreq);
|
||||||
} else if("connectDB".equals(actionStr)) {
|
} else if("connectDB".equals(actionStr)) {
|
||||||
processConnectDBRequest(vreq, maker, modelType);
|
processConnectDBRequest(vreq);
|
||||||
} else if("csv2rdf".equals(actionStr)) {
|
} else if("csv2rdf".equals(actionStr)) {
|
||||||
processCsv2rdfRequest(vreq, maker, modelType);
|
processCsv2rdfRequest(vreq);
|
||||||
} else if("processStrings".equals(actionStr)) {
|
} else if("processStrings".equals(actionStr)) {
|
||||||
processProcessStringsRequest(vreq, maker, modelType);
|
processProcessStringsRequest(vreq);
|
||||||
} else if("splitPropertyValues".equals(actionStr)) {
|
} else if("splitPropertyValues".equals(actionStr)) {
|
||||||
processSplitPropertyValuesRequest(vreq, maker, modelType);
|
processSplitPropertyValuesRequest(vreq);
|
||||||
} else if("subtractModels".equals(actionStr)) {
|
} else if("subtractModels".equals(actionStr)) {
|
||||||
processSubtractModelRequest(vreq, maker, modelType);
|
processSubtractModelRequest(vreq);
|
||||||
} else if("executeWorkflow".equals(actionStr)) {
|
} else if("executeWorkflow".equals(actionStr)) {
|
||||||
processExecuteWorkflowRequest(vreq, maker, modelType);
|
processExecuteWorkflowRequest(vreq);
|
||||||
} else if("executeSparql".equals(actionStr)) {
|
} else if("executeSparql".equals(actionStr)) {
|
||||||
processExecuteSparqlRequest(vreq, maker, modelType);
|
processExecuteSparqlRequest(vreq);
|
||||||
} else if ("generateTBox".equals(actionStr)) {
|
} else if ("generateTBox".equals(actionStr)) {
|
||||||
processGenerateTBoxRequest(vreq, maker, modelType);
|
processGenerateTBoxRequest(vreq);
|
||||||
} else if("permanentURI".equals(actionStr)){
|
} else if("permanentURI".equals(actionStr)){
|
||||||
processPermanentURIRequest(vreq, maker, modelType);
|
processPermanentURIRequest(vreq, maker);
|
||||||
} else if("mergeResources".equals(actionStr)){
|
} else if("mergeResources".equals(actionStr)){
|
||||||
processMergeResourceRequest(vreq, maker, modelType);
|
processMergeResourceRequest(vreq);
|
||||||
} else if("renameResource".equals(actionStr)){
|
} else if("renameResource".equals(actionStr)){
|
||||||
processRenameResourceRequest(vreq, response, maker, modelType);
|
processRenameResourceRequest(vreq);
|
||||||
} else if("mergeResult".equals(actionStr)){
|
} else if("mergeResult".equals(actionStr)){
|
||||||
processMergeResultRequest(vreq, response, maker, modelType);
|
processMergeResultRequest(vreq, response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +190,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
request.setAttribute("bodyJsp",INGEST_MENU_JSP);
|
request.setAttribute("bodyJsp",INGEST_MENU_JSP);
|
||||||
}
|
}
|
||||||
|
|
||||||
maker = getVitroJenaModelMaker(vreq);
|
maker = getModelMaker(vreq);
|
||||||
request.setAttribute("modelNames", maker.listModels().toList());
|
request.setAttribute("modelNames", maker.listModels().toList());
|
||||||
|
|
||||||
RequestDispatcher rd = request.getRequestDispatcher(
|
RequestDispatcher rd = request.getRequestDispatcher(
|
||||||
|
@ -203,27 +204,27 @@ public class JenaIngestController extends BaseEditController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processListModelsRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processListModelsRequest(VitroRequest vreq, ModelMaker maker, ModelMakerID modelType) {
|
||||||
showModelList(vreq, maker, modelType);
|
showModelList(vreq, maker, modelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUsingMainStoreForIngest(HttpServletRequest req) {
|
protected static boolean isUsingMainStoreForIngest(HttpServletRequest req) {
|
||||||
return CONFIGURATION != req.getSession().getAttribute(WHICH_MODEL_MAKER);
|
return CONFIGURATION != req.getSession().getAttribute(WHICH_MODEL_MAKER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRDBModelsRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processConfigModelsRequest(VitroRequest vreq) {
|
||||||
ModelMaker vjmm = ModelAccess.on(getServletContext()).getModelMaker(CONFIGURATION);
|
ModelMaker vjmm = ModelAccess.on(getServletContext()).getModelMaker(CONFIGURATION);
|
||||||
vreq.getSession().setAttribute(WHICH_MODEL_MAKER, CONFIGURATION);
|
vreq.getSession().setAttribute(WHICH_MODEL_MAKER, CONFIGURATION);
|
||||||
showModelList(vreq, vjmm, "rdb");
|
showModelList(vreq, vjmm, CONFIGURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSDBModelsRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processContentModelsRequest(VitroRequest vreq) {
|
||||||
ModelMaker vsmm = ModelAccess.on(getServletContext()).getModelMaker(CONTENT);
|
ModelMaker vsmm = ModelAccess.on(getServletContext()).getModelMaker(CONTENT);
|
||||||
vreq.getSession().setAttribute(WHICH_MODEL_MAKER, CONTENT);
|
vreq.getSession().setAttribute(WHICH_MODEL_MAKER, CONTENT);
|
||||||
showModelList(vreq, vsmm, "sdb");
|
showModelList(vreq, vsmm, CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCreateModelRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processCreateModelRequest(VitroRequest vreq, ModelMaker maker, ModelMakerID modelType) {
|
||||||
String modelName = vreq.getParameter("modelName");
|
String modelName = vreq.getParameter("modelName");
|
||||||
|
|
||||||
if (modelName != null) {
|
if (modelName != null) {
|
||||||
|
@ -242,13 +243,13 @@ public class JenaIngestController extends BaseEditController {
|
||||||
throw new RuntimeException("the model name must be a valid URI");
|
throw new RuntimeException("the model name must be a valid URI");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vreq.setAttribute("modelType", modelType);
|
vreq.setAttribute("modelType", modelType.toString());
|
||||||
vreq.setAttribute("title","Create New Model");
|
vreq.setAttribute("title","Create New Model");
|
||||||
vreq.setAttribute("bodyJsp",CREATE_MODEL_JSP);
|
vreq.setAttribute("bodyJsp",CREATE_MODEL_JSP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRemoveModelRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processRemoveModelRequest(VitroRequest vreq, ModelMaker maker, ModelMakerID modelType) {
|
||||||
String modelName = vreq.getParameter("modelName");
|
String modelName = vreq.getParameter("modelName");
|
||||||
if (modelName!=null) {
|
if (modelName!=null) {
|
||||||
doRemoveModel(modelName, maker);
|
doRemoveModel(modelName, maker);
|
||||||
|
@ -256,7 +257,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
showModelList(vreq, maker, modelType);
|
showModelList(vreq, maker, modelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processClearModelRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processClearModelRequest(VitroRequest vreq, ModelMaker maker, ModelMakerID modelType) {
|
||||||
String modelName = vreq.getParameter("modelName");
|
String modelName = vreq.getParameter("modelName");
|
||||||
if (modelName != null) {
|
if (modelName != null) {
|
||||||
doClearModel(modelName,maker);
|
doClearModel(modelName,maker);
|
||||||
|
@ -264,7 +265,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
showModelList(vreq, maker, modelType);
|
showModelList(vreq, maker, modelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processLoadRDFDataRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processLoadRDFDataRequest(VitroRequest vreq, ModelMaker maker) {
|
||||||
String docLoc = vreq.getParameter("docLoc");
|
String docLoc = vreq.getParameter("docLoc");
|
||||||
String filePath = vreq.getParameter("filePath");
|
String filePath = vreq.getParameter("filePath");
|
||||||
String modelName = vreq.getParameter("modelName");
|
String modelName = vreq.getParameter("modelName");
|
||||||
|
@ -281,9 +282,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processOutputModelRequest(VitroRequest vreq,
|
private void processOutputModelRequest(VitroRequest vreq,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response) {
|
||||||
ModelMaker maker,
|
|
||||||
String modelType) {
|
|
||||||
String modelNameStr = vreq.getParameter("modelName");
|
String modelNameStr = vreq.getParameter("modelName");
|
||||||
Model model = getModel(modelNameStr,vreq);
|
Model model = getModel(modelNameStr,vreq);
|
||||||
JenaOutputUtils.setNameSpacePrefixes(model,vreq.getWebappDaoFactory());
|
JenaOutputUtils.setNameSpacePrefixes(model,vreq.getWebappDaoFactory());
|
||||||
|
@ -310,7 +309,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCleanLiteralsRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processCleanLiteralsRequest(VitroRequest vreq) {
|
||||||
String modelNameStr = vreq.getParameter("modelName");
|
String modelNameStr = vreq.getParameter("modelName");
|
||||||
Model model = getModel(modelNameStr,vreq);
|
Model model = getModel(modelNameStr,vreq);
|
||||||
doCleanLiterals(model);
|
doCleanLiterals(model);
|
||||||
|
@ -318,7 +317,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
vreq.setAttribute("bodyJsp",INGEST_MENU_JSP);
|
vreq.setAttribute("bodyJsp",INGEST_MENU_JSP);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processAttachModelRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processAttachModelRequest(VitroRequest vreq, ModelMaker maker, ModelMakerID modelType) {
|
||||||
String modelName = vreq.getParameter("modelName");
|
String modelName = vreq.getParameter("modelName");
|
||||||
if (modelName != null) {
|
if (modelName != null) {
|
||||||
doAttachModel(modelName,maker);
|
doAttachModel(modelName,maker);
|
||||||
|
@ -326,15 +325,15 @@ public class JenaIngestController extends BaseEditController {
|
||||||
showModelList(vreq, maker, modelType);
|
showModelList(vreq, maker, modelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processDetachModelRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processDetachModelRequest(VitroRequest vreq, ModelMaker maker, ModelMakerID modelType) {
|
||||||
String modelName = vreq.getParameter("modelName");
|
String modelName = vreq.getParameter("modelName");
|
||||||
if (modelName != null) {
|
if (modelName != null) {
|
||||||
doDetachModel(modelName,maker);
|
doDetachModel(modelName);
|
||||||
}
|
}
|
||||||
showModelList(vreq, maker, modelType);
|
showModelList(vreq, maker, modelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRenameBNodesRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processRenameBNodesRequest(VitroRequest vreq, ModelMaker maker) {
|
||||||
String[] sourceModel = vreq.getParameterValues("sourceModelName");
|
String[] sourceModel = vreq.getParameterValues("sourceModelName");
|
||||||
JenaIngestUtils utils = new JenaIngestUtils();
|
JenaIngestUtils utils = new JenaIngestUtils();
|
||||||
if(sourceModel != null && sourceModel.length != 0) {
|
if(sourceModel != null && sourceModel.length != 0) {
|
||||||
|
@ -359,19 +358,19 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRenameBNodesURISelectRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processRenameBNodesURISelectRequest(VitroRequest vreq, ModelMaker maker) {
|
||||||
String namespaceEtcStr = vreq.getParameter("namespaceEtcStr");
|
String namespaceEtcStr = vreq.getParameter("namespaceEtcStr");
|
||||||
String pattern = vreq.getParameter("pattern");
|
String pattern = vreq.getParameter("pattern");
|
||||||
String concatenate = vreq.getParameter("concatenate");
|
String concatenate = vreq.getParameter("concatenate");
|
||||||
String[] sourceModel = (String[]) vreq.getParameterValues("sourceModelName");
|
String[] sourceModel = vreq.getParameterValues("sourceModelName");
|
||||||
if(namespaceEtcStr != null) {
|
if(namespaceEtcStr != null) {
|
||||||
if (namespaceEtcStr.isEmpty()) {
|
if (namespaceEtcStr.isEmpty()) {
|
||||||
if ("true".equals(vreq.getParameter("csv2rdf"))) {
|
if ("true".equals(vreq.getParameter("csv2rdf"))) {
|
||||||
processCsv2rdfRequest(vreq, maker, modelType);
|
processCsv2rdfRequest(vreq);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
vreq.setAttribute("errorMsg", "Please enter a value.");
|
vreq.setAttribute("errorMsg", "Please enter a value.");
|
||||||
processRenameBNodesRequest(vreq, maker, modelType);
|
processRenameBNodesRequest(vreq, maker);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -390,7 +389,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSmushSingleModelRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processSmushSingleModelRequest(VitroRequest vreq) {
|
||||||
String propertyURIStr = vreq.getParameter("propertyURI");
|
String propertyURIStr = vreq.getParameter("propertyURI");
|
||||||
if (propertyURIStr != null) {
|
if (propertyURIStr != null) {
|
||||||
doSmushSingleModel(vreq);
|
doSmushSingleModel(vreq);
|
||||||
|
@ -402,19 +401,15 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processConnectDBRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processConnectDBRequest(VitroRequest vreq) {
|
||||||
String jdbcUrl = vreq.getParameter("jdbcUrl");
|
String jdbcUrl = vreq.getParameter("jdbcUrl");
|
||||||
String tripleStore = vreq.getParameter("tripleStore");
|
String tripleStore = vreq.getParameter("tripleStore");
|
||||||
if (jdbcUrl != null) {
|
if (jdbcUrl != null) {
|
||||||
doConnectDB(vreq);
|
doConnectDB(vreq);
|
||||||
if ("SDB".equals(tripleStore)) {
|
if ("SDB".equals(tripleStore)) {
|
||||||
getServletContext().setAttribute("modelT", "sdb");
|
|
||||||
getServletContext().setAttribute("info", "SDB models");
|
|
||||||
vreq.setAttribute("modelType", "sdb");
|
vreq.setAttribute("modelType", "sdb");
|
||||||
vreq.setAttribute("infoLine", "SDB models");
|
vreq.setAttribute("infoLine", "SDB models");
|
||||||
} else {
|
} else {
|
||||||
getServletContext().setAttribute("modelT", "rdb");
|
|
||||||
getServletContext().setAttribute("info", "RDB models");
|
|
||||||
vreq.setAttribute("modelType", "rdb");
|
vreq.setAttribute("modelType", "rdb");
|
||||||
vreq.setAttribute("infoLine", "RDB models");
|
vreq.setAttribute("infoLine", "RDB models");
|
||||||
}
|
}
|
||||||
|
@ -429,7 +424,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCsv2rdfRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processCsv2rdfRequest(VitroRequest vreq) {
|
||||||
String csvUrl = vreq.getParameter("csvUrl");
|
String csvUrl = vreq.getParameter("csvUrl");
|
||||||
if (csvUrl != null) {
|
if (csvUrl != null) {
|
||||||
/*doExecuteCsv2Rdf(vreq);*/
|
/*doExecuteCsv2Rdf(vreq);*/
|
||||||
|
@ -441,7 +436,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processProcessStringsRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processProcessStringsRequest(VitroRequest vreq) {
|
||||||
String className = vreq.getParameter("className");
|
String className = vreq.getParameter("className");
|
||||||
if (className != null) {
|
if (className != null) {
|
||||||
doProcessStrings(vreq);
|
doProcessStrings(vreq);
|
||||||
|
@ -453,7 +448,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSplitPropertyValuesRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processSplitPropertyValuesRequest(VitroRequest vreq) {
|
||||||
String splitRegex = vreq.getParameter("splitRegex");
|
String splitRegex = vreq.getParameter("splitRegex");
|
||||||
if (splitRegex != null) {
|
if (splitRegex != null) {
|
||||||
doSplitPropertyValues(vreq);
|
doSplitPropertyValues(vreq);
|
||||||
|
@ -465,7 +460,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSubtractModelRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processSubtractModelRequest(VitroRequest vreq) {
|
||||||
String modela = vreq.getParameter("modela");
|
String modela = vreq.getParameter("modela");
|
||||||
if (modela != null) {
|
if (modela != null) {
|
||||||
doSubtractModels(vreq);
|
doSubtractModels(vreq);
|
||||||
|
@ -477,7 +472,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processExecuteWorkflowRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processExecuteWorkflowRequest(VitroRequest vreq) {
|
||||||
String workflowURIStr = vreq.getParameter("workflowURI");
|
String workflowURIStr = vreq.getParameter("workflowURI");
|
||||||
String workflowStepURIStr = vreq.getParameter("workflowStepURI");
|
String workflowStepURIStr = vreq.getParameter("workflowStepURI");
|
||||||
if (workflowURIStr != null && workflowStepURIStr != null) {
|
if (workflowURIStr != null && workflowStepURIStr != null) {
|
||||||
|
@ -489,7 +484,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
OntModel jenaOntModel = (OntModel) getModel("vitro:jenaOntModel",vreq);
|
OntModel jenaOntModel = (OntModel) getModel("vitro:jenaOntModel",vreq);
|
||||||
vreq.setAttribute("workflowSteps", new JenaIngestWorkflowProcessor(
|
vreq.setAttribute("workflowSteps", new JenaIngestWorkflowProcessor(
|
||||||
jenaOntModel.getIndividual(workflowURIStr),
|
jenaOntModel.getIndividual(workflowURIStr),
|
||||||
getVitroJenaModelMaker(vreq)).getWorkflowSteps(null));
|
getModelMaker(vreq)).getWorkflowSteps(null));
|
||||||
vreq.setAttribute("title", "Choose Workflow Step");
|
vreq.setAttribute("title", "Choose Workflow Step");
|
||||||
vreq.setAttribute("bodyJsp", WORKFLOW_STEP_JSP);
|
vreq.setAttribute("bodyJsp", WORKFLOW_STEP_JSP);
|
||||||
} else {
|
} else {
|
||||||
|
@ -508,7 +503,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processExecuteSparqlRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processExecuteSparqlRequest(VitroRequest vreq) {
|
||||||
String sparqlQueryStr = vreq.getParameter("sparqlQueryStr");
|
String sparqlQueryStr = vreq.getParameter("sparqlQueryStr");
|
||||||
OntModel jenaOntModel = ModelAccess.on(getServletContext()).getJenaOntModel();
|
OntModel jenaOntModel = ModelAccess.on(getServletContext()).getJenaOntModel();
|
||||||
jenaOntModel.enterCriticalSection(Lock.READ);
|
jenaOntModel.enterCriticalSection(Lock.READ);
|
||||||
|
@ -521,12 +516,12 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
/*ass92*/
|
/*ass92*/
|
||||||
OntologyDao daoObj = vreq.getUnfilteredWebappDaoFactory().getOntologyDao();
|
OntologyDao daoObj = vreq.getUnfilteredWebappDaoFactory().getOntologyDao();
|
||||||
List ontologiesObj = daoObj.getAllOntologies();
|
List<Ontology> ontologiesObj = daoObj.getAllOntologies();
|
||||||
ArrayList prefixList = new ArrayList();
|
List<String> prefixList = new ArrayList<>();
|
||||||
if(ontologiesObj !=null && ontologiesObj.size()>0){
|
if(ontologiesObj !=null && ontologiesObj.size()>0){
|
||||||
Iterator ontItr = ontologiesObj.iterator();
|
Iterator<Ontology> ontItr = ontologiesObj.iterator();
|
||||||
while(ontItr.hasNext()){
|
while(ontItr.hasNext()){
|
||||||
Ontology ont = (Ontology) ontItr.next();
|
Ontology ont = ontItr.next();
|
||||||
prefixList.add(ont.getPrefix() == null ? "(not yet specified)" : ont.getPrefix());
|
prefixList.add(ont.getPrefix() == null ? "(not yet specified)" : ont.getPrefix());
|
||||||
prefixList.add(ont.getURI() == null ? "" : ont.getURI());
|
prefixList.add(ont.getURI() == null ? "" : ont.getURI());
|
||||||
}
|
}
|
||||||
|
@ -576,7 +571,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processGenerateTBoxRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processGenerateTBoxRequest(VitroRequest vreq) {
|
||||||
String testParam = vreq.getParameter("sourceModelName");
|
String testParam = vreq.getParameter("sourceModelName");
|
||||||
if (testParam != null) {
|
if (testParam != null) {
|
||||||
doGenerateTBox(vreq);
|
doGenerateTBox(vreq);
|
||||||
|
@ -588,7 +583,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processPermanentURIRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processPermanentURIRequest(VitroRequest vreq, ModelMaker maker) {
|
||||||
String modelName = vreq.getParameter("modelName");
|
String modelName = vreq.getParameter("modelName");
|
||||||
String oldModel = vreq.getParameter("oldModel");
|
String oldModel = vreq.getParameter("oldModel");
|
||||||
String newModel = vreq.getParameter("newModel");
|
String newModel = vreq.getParameter("newModel");
|
||||||
|
@ -599,7 +594,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
newNamespace = (dNamespace != null) ? dNamespace : newNamespace;
|
newNamespace = (dNamespace != null) ? dNamespace : newNamespace;
|
||||||
if(modelName!=null){
|
if(modelName!=null){
|
||||||
Model m = maker.getModel(modelName);
|
Model m = maker.getModel(modelName);
|
||||||
ArrayList namespaceList = new ArrayList();
|
List<String> namespaceList = new ArrayList<>();
|
||||||
ResIterator resItr = m.listResourcesWithProperty((Property)null);
|
ResIterator resItr = m.listResourcesWithProperty((Property)null);
|
||||||
if(resItr!=null){
|
if(resItr!=null){
|
||||||
while(resItr.hasNext()){
|
while(resItr.hasNext()){
|
||||||
|
@ -625,7 +620,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processMergeResourceRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
|
private void processMergeResourceRequest(VitroRequest vreq) {
|
||||||
String uri1 = vreq.getParameter("uri1"); // get primary uri
|
String uri1 = vreq.getParameter("uri1"); // get primary uri
|
||||||
String uri2 = vreq.getParameter("uri2"); // get secondary uri
|
String uri2 = vreq.getParameter("uri2"); // get secondary uri
|
||||||
String usePrimaryLabelOnly = vreq.getParameter("usePrimaryLabelOnly");
|
String usePrimaryLabelOnly = vreq.getParameter("usePrimaryLabelOnly");
|
||||||
|
@ -655,10 +650,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRenameResourceRequest(VitroRequest vreq,
|
private void processRenameResourceRequest(VitroRequest vreq) {
|
||||||
HttpServletResponse response,
|
|
||||||
ModelMaker maker,
|
|
||||||
String modelType) {
|
|
||||||
String oldNamespace = vreq.getParameter("oldNamespace");
|
String oldNamespace = vreq.getParameter("oldNamespace");
|
||||||
String newNamespace = vreq.getParameter("newNamespace");
|
String newNamespace = vreq.getParameter("newNamespace");
|
||||||
String errorMsg = "";
|
String errorMsg = "";
|
||||||
|
@ -679,7 +671,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
vreq.setAttribute("title","Rename Resource");
|
vreq.setAttribute("title","Rename Resource");
|
||||||
vreq.setAttribute("bodyJsp",RENAME_RESOURCE);
|
vreq.setAttribute("bodyJsp",RENAME_RESOURCE);
|
||||||
} else {
|
} else {
|
||||||
String result = doRename(oldNamespace, newNamespace, response);
|
String result = doRename(oldNamespace, newNamespace);
|
||||||
vreq.setAttribute("result",result);
|
vreq.setAttribute("result",result);
|
||||||
vreq.setAttribute("title","Rename Resources");
|
vreq.setAttribute("title","Rename Resources");
|
||||||
vreq.setAttribute("bodyJsp",RENAME_RESULT);
|
vreq.setAttribute("bodyJsp",RENAME_RESULT);
|
||||||
|
@ -691,9 +683,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processMergeResultRequest(VitroRequest vreq,
|
private void processMergeResultRequest(VitroRequest vreq,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response) {
|
||||||
ModelMaker maker,
|
|
||||||
String modelType) {
|
|
||||||
|
|
||||||
Model lmodel = (Model) vreq.getSession().getAttribute("leftoverModel");
|
Model lmodel = (Model) vreq.getSession().getAttribute("leftoverModel");
|
||||||
response.setContentType("RDF/XML-ABBREV");
|
response.setContentType("RDF/XML-ABBREV");
|
||||||
|
@ -709,16 +699,23 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getModelType(VitroRequest vreq) {
|
/**
|
||||||
|
* Get the model type from the request, or from the session.
|
||||||
|
*/
|
||||||
|
protected ModelMakerID getModelType(VitroRequest vreq) {
|
||||||
String modelType = vreq.getParameter("modelType");
|
String modelType = vreq.getParameter("modelType");
|
||||||
if (modelType == null) {
|
if (modelType != null) {
|
||||||
if (isUsingMainStoreForIngest(vreq)) {
|
if (modelType.equals(CONFIGURATION.toString())) {
|
||||||
modelType = "sdb";
|
return CONFIGURATION;
|
||||||
} else {
|
} else {
|
||||||
modelType = "rdb";
|
return CONTENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return modelType;
|
if (vreq.getSession().getAttribute(WHICH_MODEL_MAKER) == CONFIGURATION) {
|
||||||
|
return CONFIGURATION;
|
||||||
|
} else {
|
||||||
|
return CONTENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doCreateModel(String modelName, ModelMaker modelMaker) {
|
private void doCreateModel(String modelName, ModelMaker modelMaker) {
|
||||||
|
@ -727,7 +724,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
|
|
||||||
private void doRemoveModel(String modelName, ModelMaker modelMaker) {
|
private void doRemoveModel(String modelName, ModelMaker modelMaker) {
|
||||||
//Try to detach first since it cause problems to remove an attached model.
|
//Try to detach first since it cause problems to remove an attached model.
|
||||||
doDetachModel(modelName, modelMaker);
|
doDetachModel(modelName);
|
||||||
log.debug("Removing " + modelName + " from webapp");
|
log.debug("Removing " + modelName + " from webapp");
|
||||||
modelMaker.removeModel(modelName);
|
modelMaker.removeModel(modelName);
|
||||||
}
|
}
|
||||||
|
@ -779,7 +776,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
|
|
||||||
private void doAttachModel(String modelName, ModelMaker modelMaker) {
|
private void doAttachModel(String modelName, ModelMaker modelMaker) {
|
||||||
if (attachedModels.containsKey(modelName)) {
|
if (attachedModels.containsKey(modelName)) {
|
||||||
doDetachModel(modelName, modelMaker);
|
doDetachModel(modelName);
|
||||||
}
|
}
|
||||||
Model m = ModelFactory.createDefaultModel();
|
Model m = ModelFactory.createDefaultModel();
|
||||||
m.add(modelMaker.getModel(modelName));
|
m.add(modelMaker.getModel(modelName));
|
||||||
|
@ -788,7 +785,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
log.info("Attached " + modelName + " (" + m.hashCode() + ") to webapp");
|
log.info("Attached " + modelName + " (" + m.hashCode() + ") to webapp");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doDetachModel(String modelName, ModelMaker modelMaker) {
|
private void doDetachModel(String modelName) {
|
||||||
Model m = attachedModels.get(modelName);
|
Model m = attachedModels.get(modelName);
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -804,7 +801,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
|
|
||||||
Boolean csv2rdf = false;
|
Boolean csv2rdf = false;
|
||||||
try {
|
try {
|
||||||
csv2rdf = (Boolean) Boolean.parseBoolean(vreq.getParameter("csv2rdf"));
|
csv2rdf = Boolean.parseBoolean(vreq.getParameter("csv2rdf"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
|
@ -987,17 +984,17 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
Model additionsModel = ModelFactory.createDefaultModel();
|
Model additionsModel = ModelFactory.createDefaultModel();
|
||||||
Model retractionsModel = ModelFactory.createDefaultModel();
|
Model retractionsModel = ModelFactory.createDefaultModel();
|
||||||
Class stringProcessorClass = Class.forName(className);
|
Class<?> stringProcessorClass = Class.forName(className);
|
||||||
Object processor = stringProcessorClass.newInstance();
|
Object processor = stringProcessorClass.newInstance();
|
||||||
Class[] methArgs = {String.class};
|
Class<?>[] methArgs = {String.class};
|
||||||
Method meth = stringProcessorClass.getMethod(methodName,methArgs);
|
Method meth = stringProcessorClass.getMethod(methodName,methArgs);
|
||||||
Property prop = ResourceFactory.createProperty(propertyName);
|
Property prop = ResourceFactory.createProperty(propertyName);
|
||||||
Property newProp = ResourceFactory.createProperty(newPropertyName);
|
Property newProp = ResourceFactory.createProperty(newPropertyName);
|
||||||
destination.enterCriticalSection(Lock.READ);
|
destination.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
ClosableIterator closeIt = destination.listStatements((Resource)null,prop,(RDFNode)null);
|
ClosableIterator<Statement> closeIt = destination.listStatements((Resource)null,prop,(RDFNode)null);
|
||||||
for (Iterator stmtIt = closeIt; stmtIt.hasNext(); ) {
|
for (Iterator<Statement> stmtIt = closeIt; stmtIt.hasNext(); ) {
|
||||||
Statement stmt = (Statement) stmtIt.next();
|
Statement stmt = stmtIt.next();
|
||||||
if (stmt.getObject().isLiteral()) {
|
if (stmt.getObject().isLiteral()) {
|
||||||
Literal lit = (Literal) stmt.getObject();
|
Literal lit = (Literal) stmt.getObject();
|
||||||
String lex = lit.getLexicalForm();
|
String lex = lit.getLexicalForm();
|
||||||
|
@ -1047,10 +1044,10 @@ public class JenaIngestController extends BaseEditController {
|
||||||
Model additionsModel = ModelFactory.createDefaultModel();
|
Model additionsModel = ModelFactory.createDefaultModel();
|
||||||
model.enterCriticalSection(Lock.WRITE);
|
model.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
ClosableIterator closeIt = model.listStatements();
|
ClosableIterator<Statement> closeIt = model.listStatements();
|
||||||
try {
|
try {
|
||||||
for (Iterator stmtIt = closeIt; stmtIt.hasNext();) {
|
for (Iterator<Statement> stmtIt = closeIt; stmtIt.hasNext();) {
|
||||||
Statement stmt = (Statement) stmtIt.next();
|
Statement stmt = stmtIt.next();
|
||||||
if (stmt.getObject().isLiteral()) {
|
if (stmt.getObject().isLiteral()) {
|
||||||
Literal lit = (Literal) stmt.getObject();
|
Literal lit = (Literal) stmt.getObject();
|
||||||
String lex = lit.getLexicalForm();
|
String lex = lit.getLexicalForm();
|
||||||
|
@ -1099,11 +1096,11 @@ public class JenaIngestController extends BaseEditController {
|
||||||
String workflowStepURI = vreq.getParameter("workflowStepURI");
|
String workflowStepURI = vreq.getParameter("workflowStepURI");
|
||||||
OntModel jenaOntModel = (OntModel) getModel("vitro:jenaOntModel",vreq);
|
OntModel jenaOntModel = (OntModel) getModel("vitro:jenaOntModel",vreq);
|
||||||
new JenaIngestWorkflowProcessor(
|
new JenaIngestWorkflowProcessor(
|
||||||
jenaOntModel.getIndividual(workflowURI),getVitroJenaModelMaker(
|
jenaOntModel.getIndividual(workflowURI),getModelMaker(
|
||||||
vreq)).run(jenaOntModel.getIndividual(workflowStepURI));
|
vreq)).run(jenaOntModel.getIndividual(workflowStepURI));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String doRename(String oldNamespace,String newNamespace,HttpServletResponse response){
|
private String doRename(String oldNamespace,String newNamespace){
|
||||||
String uri = null;
|
String uri = null;
|
||||||
String result = null;
|
String result = null;
|
||||||
Integer counter = 0;
|
Integer counter = 0;
|
||||||
|
@ -1200,13 +1197,12 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showModelList(VitroRequest vreq, ModelMaker maker, String modelType) {
|
protected void showModelList(VitroRequest vreq, ModelMaker maker, ModelMakerID modelType) {
|
||||||
if(modelType.equals("rdb")){
|
vreq.setAttribute("modelType", modelType.toString());
|
||||||
vreq.setAttribute("modelType", "rdb");
|
if(modelType == CONTENT){
|
||||||
vreq.setAttribute("infoLine", "RDB models");
|
vreq.setAttribute("infoLine", "Main Store models");
|
||||||
} else {
|
} else {
|
||||||
vreq.setAttribute("modelType", "sdb");
|
vreq.setAttribute("infoLine", "Configuration models");
|
||||||
vreq.setAttribute("infoLine", "main store models");
|
|
||||||
}
|
}
|
||||||
vreq.setAttribute("modelNames", maker.listModels().toList());
|
vreq.setAttribute("modelNames", maker.listModels().toList());
|
||||||
vreq.setAttribute("bodyAttr", "onLoad=\"init()\"");
|
vreq.setAttribute("bodyAttr", "onLoad=\"init()\"");
|
||||||
|
@ -1222,6 +1218,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
this.collator = vreq.getCollator();
|
this.collator = vreq.getCollator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int compare(String s1, String s2) {
|
public int compare(String s1, String s2) {
|
||||||
return collator.compare(s1, s2);
|
return collator.compare(s1, s2);
|
||||||
}
|
}
|
||||||
|
@ -1229,10 +1226,10 @@ public class JenaIngestController extends BaseEditController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Model getModel(String name, HttpServletRequest request) {
|
public static Model getModel(String name, HttpServletRequest request) {
|
||||||
return getVitroJenaModelMaker(request).getModel(name);
|
return getModelMaker(request).getModel(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static ModelMaker getVitroJenaModelMaker(HttpServletRequest req){
|
protected static ModelMaker getModelMaker(HttpServletRequest req){
|
||||||
ServletContext ctx = req.getSession().getServletContext();
|
ServletContext ctx = req.getSession().getServletContext();
|
||||||
if (isUsingMainStoreForIngest(req)) {
|
if (isUsingMainStoreForIngest(req)) {
|
||||||
return ModelAccess.on(ctx).getModelMaker(CONTENT);
|
return ModelAccess.on(ctx).getModelMaker(CONTENT);
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class JenaXMLFileUpload extends JenaIngestController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelMaker modelMaker = getVitroJenaModelMaker(vreq);
|
ModelMaker modelMaker = getModelMaker(vreq);
|
||||||
String targetModel = request.getParameter("targetModel");
|
String targetModel = request.getParameter("targetModel");
|
||||||
if (targetModel == null) {
|
if (targetModel == null) {
|
||||||
throw new ServletException("targetModel not specified.");
|
throw new ServletException("targetModel not specified.");
|
||||||
|
@ -172,7 +172,7 @@ public class JenaXMLFileUpload extends JenaIngestController {
|
||||||
request.setAttribute("title","Upload file and convert to RDF");
|
request.setAttribute("title","Upload file and convert to RDF");
|
||||||
request.setAttribute("bodyJsp","/jenaIngest/xmlFileUpload.jsp");
|
request.setAttribute("bodyJsp","/jenaIngest/xmlFileUpload.jsp");
|
||||||
|
|
||||||
request.setAttribute("modelNames", getVitroJenaModelMaker(vreq).listModels().toList());
|
request.setAttribute("modelNames", getModelMaker(vreq).listModels().toList());
|
||||||
request.setAttribute("models", null);
|
request.setAttribute("models", null);
|
||||||
|
|
||||||
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.jena;
|
package edu.cornell.mannlib.vitro.webapp.controller.jena;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONFIGURATION;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -36,6 +38,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||||
|
@ -65,6 +68,7 @@ public class RDFUploadController extends JenaIngestController {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void doPost(HttpServletRequest req,
|
public void doPost(HttpServletRequest req,
|
||||||
HttpServletResponse response) throws ServletException, IOException {
|
HttpServletResponse response) throws ServletException, IOException {
|
||||||
if (!isAuthorizedToDisplayPage(req, response,
|
if (!isAuthorizedToDisplayPage(req, response,
|
||||||
|
@ -249,7 +253,7 @@ public class RDFUploadController extends JenaIngestController {
|
||||||
String modelName = request.getParameter("modelName");
|
String modelName = request.getParameter("modelName");
|
||||||
String docLoc = request.getParameter("docLoc");
|
String docLoc = request.getParameter("docLoc");
|
||||||
String languageStr = request.getParameter("language");
|
String languageStr = request.getParameter("language");
|
||||||
ModelMaker maker = getVitroJenaModelMaker(request);
|
ModelMaker maker = getModelMaker(request);
|
||||||
|
|
||||||
if (modelName == null) {
|
if (modelName == null) {
|
||||||
request.setAttribute("title","Load RDF Data");
|
request.setAttribute("title","Load RDF Data");
|
||||||
|
@ -261,7 +265,7 @@ public class RDFUploadController extends JenaIngestController {
|
||||||
} finally {
|
} finally {
|
||||||
rdfService.close();
|
rdfService.close();
|
||||||
}
|
}
|
||||||
String modelType = getModelType(request);
|
ModelMakerID modelType = getModelType(request);
|
||||||
showModelList(request, maker, modelType);
|
showModelList(request, maker, modelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +283,7 @@ public class RDFUploadController extends JenaIngestController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private RDFService getRDFService(VitroRequest vreq, ModelMaker maker, String modelName) {
|
private RDFService getRDFService(VitroRequest vreq, ModelMaker maker, String modelName) {
|
||||||
if (JenaIngestController.isUsingMainStoreForIngest(vreq)) {
|
if (isUsingMainStoreForIngest(vreq)) {
|
||||||
log.debug("Using main RDFService");
|
log.debug("Using main RDFService");
|
||||||
return RDFServiceUtils.getRDFServiceFactory(
|
return RDFServiceUtils.getRDFServiceFactory(
|
||||||
getServletContext()).getRDFService();
|
getServletContext()).getRDFService();
|
||||||
|
|
|
@ -39,7 +39,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||||
* VitroModelSource.openModel(name)
|
* VitroModelSource.openModel(name)
|
||||||
* VitroModelSource.openModelIfPresent(string)
|
* VitroModelSource.openModelIfPresent(string)
|
||||||
* ServletContext.getAttribute("pelletOntModel")
|
* ServletContext.getAttribute("pelletOntModel")
|
||||||
* VitroJenaModelMaker
|
|
||||||
* JenaDataSourceSetupBase.getApplicationDataSource(ctx)
|
* JenaDataSourceSetupBase.getApplicationDataSource(ctx)
|
||||||
* JenaDataSourceSetupBase.getStartupDataset()
|
* JenaDataSourceSetupBase.getStartupDataset()
|
||||||
* HttpSession.getAttribute("jenaAuditModel")
|
* HttpSession.getAttribute("jenaAuditModel")
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.openjena.atlas.lib.Pair;
|
import org.apache.jena.atlas.lib.Pair;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,9 @@ import com.hp.hpl.jena.graph.Graph;
|
||||||
import com.hp.hpl.jena.graph.GraphEventManager;
|
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||||
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
||||||
import com.hp.hpl.jena.graph.Node;
|
import com.hp.hpl.jena.graph.Node;
|
||||||
import com.hp.hpl.jena.graph.Reifier;
|
|
||||||
import com.hp.hpl.jena.graph.TransactionHandler;
|
import com.hp.hpl.jena.graph.TransactionHandler;
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
import com.hp.hpl.jena.graph.TripleMatch;
|
import com.hp.hpl.jena.graph.TripleMatch;
|
||||||
import com.hp.hpl.jena.graph.query.QueryHandler;
|
|
||||||
import com.hp.hpl.jena.shared.AddDeniedException;
|
import com.hp.hpl.jena.shared.AddDeniedException;
|
||||||
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
||||||
import com.hp.hpl.jena.shared.PrefixMapping;
|
import com.hp.hpl.jena.shared.PrefixMapping;
|
||||||
|
@ -84,6 +82,7 @@ public class BlankNodeFilteringGraph implements Graph {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public BulkUpdateHandler getBulkUpdateHandler() {
|
public BulkUpdateHandler getBulkUpdateHandler() {
|
||||||
return graph.getBulkUpdateHandler();
|
return graph.getBulkUpdateHandler();
|
||||||
}
|
}
|
||||||
|
@ -103,11 +102,6 @@ public class BlankNodeFilteringGraph implements Graph {
|
||||||
return graph.getPrefixMapping();
|
return graph.getPrefixMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Reifier getReifier() {
|
|
||||||
return graph.getReifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GraphStatisticsHandler getStatisticsHandler() {
|
public GraphStatisticsHandler getStatisticsHandler() {
|
||||||
return graph.getStatisticsHandler();
|
return graph.getStatisticsHandler();
|
||||||
|
@ -133,13 +127,18 @@ public class BlankNodeFilteringGraph implements Graph {
|
||||||
return graph.isIsomorphicWith(arg0);
|
return graph.isIsomorphicWith(arg0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public QueryHandler queryHandler() {
|
|
||||||
return graph.queryHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return graph.size();
|
return graph.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
graph.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Node arg0, Node arg1, Node arg2) {
|
||||||
|
graph.remove(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,9 @@ import com.hp.hpl.jena.graph.Graph;
|
||||||
import com.hp.hpl.jena.graph.GraphEventManager;
|
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||||
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
||||||
import com.hp.hpl.jena.graph.Node;
|
import com.hp.hpl.jena.graph.Node;
|
||||||
import com.hp.hpl.jena.graph.Reifier;
|
|
||||||
import com.hp.hpl.jena.graph.TransactionHandler;
|
import com.hp.hpl.jena.graph.TransactionHandler;
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
import com.hp.hpl.jena.graph.TripleMatch;
|
import com.hp.hpl.jena.graph.TripleMatch;
|
||||||
import com.hp.hpl.jena.graph.query.QueryHandler;
|
|
||||||
import com.hp.hpl.jena.shared.AddDeniedException;
|
import com.hp.hpl.jena.shared.AddDeniedException;
|
||||||
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
||||||
import com.hp.hpl.jena.shared.PrefixMapping;
|
import com.hp.hpl.jena.shared.PrefixMapping;
|
||||||
|
@ -51,6 +49,11 @@ public class DifferenceGraph implements Graph {
|
||||||
g.delete(arg0);
|
g.delete(arg0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Node arg0, Node arg1, Node arg2) {
|
||||||
|
g.remove(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dependsOn(Graph arg0) {
|
public boolean dependsOn(Graph arg0) {
|
||||||
return g.dependsOn(arg0);
|
return g.dependsOn(arg0);
|
||||||
|
@ -71,6 +74,7 @@ public class DifferenceGraph implements Graph {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public BulkUpdateHandler getBulkUpdateHandler() {
|
public BulkUpdateHandler getBulkUpdateHandler() {
|
||||||
return g.getBulkUpdateHandler();
|
return g.getBulkUpdateHandler();
|
||||||
}
|
}
|
||||||
|
@ -90,11 +94,6 @@ public class DifferenceGraph implements Graph {
|
||||||
return g.getPrefixMapping();
|
return g.getPrefixMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Reifier getReifier() {
|
|
||||||
return g.getReifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GraphStatisticsHandler getStatisticsHandler() {
|
public GraphStatisticsHandler getStatisticsHandler() {
|
||||||
return g.getStatisticsHandler();
|
return g.getStatisticsHandler();
|
||||||
|
@ -120,11 +119,6 @@ public class DifferenceGraph implements Graph {
|
||||||
return g.isIsomorphicWith(arg0);
|
return g.isIsomorphicWith(arg0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public QueryHandler queryHandler() {
|
|
||||||
return g.queryHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return g.size() - subtract.size();
|
return g.size() - subtract.size();
|
||||||
|
@ -135,4 +129,9 @@ public class DifferenceGraph implements Graph {
|
||||||
g.add(arg0);
|
g.add(arg0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
g.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,118 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import org.apache.commons.collections.iterators.EmptyIterator;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
|
||||||
import com.hp.hpl.jena.graph.Node;
|
|
||||||
import com.hp.hpl.jena.graph.Reifier;
|
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
|
||||||
import com.hp.hpl.jena.graph.TripleMatch;
|
|
||||||
import com.hp.hpl.jena.shared.ReificationStyle;
|
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
|
||||||
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
|
||||||
|
|
||||||
public class EmptyReifier implements Reifier {
|
|
||||||
|
|
||||||
private Graph g;
|
|
||||||
|
|
||||||
public EmptyReifier(Graph g) {
|
|
||||||
this.g = g;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Triple getTriple(Node arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExtendedIterator<Node> allNodes() {
|
|
||||||
return WrappedIterator.create(Collections.EMPTY_LIST.iterator());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExtendedIterator<Node> allNodes(Triple arg0) {
|
|
||||||
return WrappedIterator.create(Collections.EMPTY_LIST.iterator());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExtendedIterator<Triple> find(TripleMatch arg0) {
|
|
||||||
return g.find(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExtendedIterator<Triple> findEither(TripleMatch arg0, boolean arg1) {
|
|
||||||
return WrappedIterator.create(EmptyIterator.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExtendedIterator<Triple> findExposed(TripleMatch arg0) {
|
|
||||||
return WrappedIterator.create(EmptyIterator.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Graph getParentGraph() {
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ReificationStyle getStyle() {
|
|
||||||
return ReificationStyle.Minimal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handledAdd(Triple arg0) {
|
|
||||||
g.add(arg0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handledRemove(Triple arg0) {
|
|
||||||
g.delete(arg0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasTriple(Node arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasTriple(Triple arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Node reifyAs(Node arg0, Triple arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(Triple arg0) {
|
|
||||||
g.delete(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(Node arg0, Triple arg1) {
|
|
||||||
g.delete(arg1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return g.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -13,7 +13,7 @@ import java.util.Map;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.openjena.atlas.lib.Pair;
|
import org.apache.jena.atlas.lib.Pair;
|
||||||
|
|
||||||
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
||||||
import com.hp.hpl.jena.ontology.ConversionException;
|
import com.hp.hpl.jena.ontology.ConversionException;
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.db.DBConnection;
|
|
||||||
import com.hp.hpl.jena.db.GraphRDB;
|
|
||||||
import com.hp.hpl.jena.db.IDBConnection;
|
|
||||||
import com.hp.hpl.jena.db.ModelRDB;
|
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class RDBGraphGenerator implements SQLGraphGenerator {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(RDBGraphGenerator.class.getName());
|
|
||||||
|
|
||||||
private DataSource ds = null;
|
|
||||||
private Connection connection = null;
|
|
||||||
private String dbTypeStr = null;
|
|
||||||
private String graphID = null;
|
|
||||||
|
|
||||||
public RDBGraphGenerator(DataSource ds, String dbTypeStr, String graphID) {
|
|
||||||
this.ds = ds;
|
|
||||||
this.dbTypeStr = dbTypeStr;
|
|
||||||
this.graphID = graphID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGraphClosed() {
|
|
||||||
try {
|
|
||||||
return (connection == null || connection.isClosed());
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Graph generateGraph() {
|
|
||||||
try {
|
|
||||||
// if (log.isDebugEnabled()) {
|
|
||||||
// log.debug(ds.getNumActive() + " active SQL connections");
|
|
||||||
// log.debug(ds.getNumIdle() + " idle SQL connections");
|
|
||||||
// }
|
|
||||||
if ( ( this.connection != null ) && ( !this.connection.isClosed() ) ) {
|
|
||||||
this.connection.close();
|
|
||||||
}
|
|
||||||
this.connection = ds.getConnection();
|
|
||||||
IDBConnection idbConn = new DBConnection(this.connection, dbTypeStr);
|
|
||||||
Graph requestedProperties = null;
|
|
||||||
boolean modelExists = idbConn.containsModel(graphID);
|
|
||||||
if (!modelExists) {
|
|
||||||
requestedProperties = ModelRDB.getDefaultModelProperties(idbConn).getGraph();
|
|
||||||
}
|
|
||||||
Graph graphRDB = new GraphRDB(idbConn, graphID, requestedProperties, GraphRDB.OPTIMIZE_ALL_REIFICATIONS_AND_HIDE_NOTHING, !modelExists);
|
|
||||||
return graphRDB;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error(e, e);
|
|
||||||
throw new RuntimeException("SQLException: unable to regenerate graph", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection getConnection() {
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,12 @@ import java.util.Iterator;
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.Node;
|
import com.hp.hpl.jena.graph.Node;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
|
import com.hp.hpl.jena.query.LabelExistsException;
|
||||||
|
import com.hp.hpl.jena.query.ReadWrite;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
import com.hp.hpl.jena.sparql.core.DatasetGraph;
|
import com.hp.hpl.jena.sparql.core.DatasetGraph;
|
||||||
|
import com.hp.hpl.jena.sparql.util.Context;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
|
||||||
|
@ -66,4 +69,73 @@ public class RDFServiceDataset implements Dataset {
|
||||||
return nameList.iterator();
|
return nameList.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addNamedModel(String uri, Model model)
|
||||||
|
throws LabelExistsException {
|
||||||
|
Iterator<Node> graphNodes = g.listGraphNodes();
|
||||||
|
while (graphNodes.hasNext()) {
|
||||||
|
Node graphNode = graphNodes.next();
|
||||||
|
if (graphNode.hasURI(uri)) {
|
||||||
|
throw new LabelExistsException("Can't add named model '"+ uri
|
||||||
|
+ "': model already exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g.addGraph(Node.createURI(uri), model.getGraph());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Context getContext() {
|
||||||
|
return g.getContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeNamedModel(String uri) {
|
||||||
|
g.removeGraph(Node.createURI(uri));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void replaceNamedModel(String uri, Model model) {
|
||||||
|
removeNamedModel(uri);
|
||||||
|
addNamedModel(uri, model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDefaultModel(Model model) {
|
||||||
|
g.setDefaultGraph(model.getGraph());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsTransactions() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInTransaction() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void begin(ReadWrite arg0) {
|
||||||
|
throw new UnsupportedOperationException(this.getClass().getSimpleName()
|
||||||
|
+ " does not support transactions.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void commit() {
|
||||||
|
throw new UnsupportedOperationException(this.getClass().getSimpleName()
|
||||||
|
+ " does not support transactions.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void abort() {
|
||||||
|
throw new UnsupportedOperationException(this.getClass().getSimpleName()
|
||||||
|
+ " does not support transactions.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void end() {
|
||||||
|
throw new UnsupportedOperationException(this.getClass().getSimpleName()
|
||||||
|
+ " does not support transactions.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,12 @@ public class RDFServiceDatasetGraph implements DatasetGraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addGraph(Node arg0, Graph arg1) {
|
public void add(Node g, Node s, Node p, Node o) {
|
||||||
|
add(new Quad(g, s, p, o));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addGraph(Node uri, Graph arg1) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +84,11 @@ public class RDFServiceDatasetGraph implements DatasetGraph {
|
||||||
getGraphFor(arg0).delete(new Triple(arg0.getSubject(), arg0.getPredicate(), arg0.getObject()));
|
getGraphFor(arg0).delete(new Triple(arg0.getSubject(), arg0.getPredicate(), arg0.getObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Node g, Node s, Node p, Node o) {
|
||||||
|
delete(new Quad(g, s, p, o));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAny(Node arg0, Node arg1, Node arg2, Node arg3) {
|
public void deleteAny(Node arg0, Node arg1, Node arg2, Node arg3) {
|
||||||
// TODO check this
|
// TODO check this
|
||||||
|
@ -99,9 +109,9 @@ public class RDFServiceDatasetGraph implements DatasetGraph {
|
||||||
public Iterator<Quad> find(Node graph, Node subject, Node predicate, Node object) {
|
public Iterator<Quad> find(Node graph, Node subject, Node predicate, Node object) {
|
||||||
if (!isVar(subject) && !isVar(predicate) && !isVar(object) &&!isVar(graph)) {
|
if (!isVar(subject) && !isVar(predicate) && !isVar(object) &&!isVar(graph)) {
|
||||||
if (contains(subject, predicate, object, graph)) {
|
if (contains(subject, predicate, object, graph)) {
|
||||||
return new SingletonIterator(new Triple(subject, predicate, object));
|
return new SingletonIterator<Quad>(new Quad(subject, predicate, object, graph));
|
||||||
} else {
|
} else {
|
||||||
return WrappedIterator.create(Collections.EMPTY_LIST.iterator());
|
return WrappedIterator.create(Collections.<Quad>emptyIterator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer findQuery = new StringBuffer("SELECT * WHERE { \n");
|
StringBuffer findQuery = new StringBuffer("SELECT * WHERE { \n");
|
||||||
|
@ -153,7 +163,6 @@ public class RDFServiceDatasetGraph implements DatasetGraph {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,6 +222,4 @@ public class RDFServiceDatasetGraph implements DatasetGraph {
|
||||||
return (node == null || node.isVariable() || node == Node.ANY);
|
return (node == null || node.isVariable() || node == Node.ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,19 +16,15 @@ import com.hp.hpl.jena.graph.Graph;
|
||||||
import com.hp.hpl.jena.graph.GraphEventManager;
|
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||||
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
||||||
import com.hp.hpl.jena.graph.Node;
|
import com.hp.hpl.jena.graph.Node;
|
||||||
import com.hp.hpl.jena.graph.Reifier;
|
|
||||||
import com.hp.hpl.jena.graph.TransactionHandler;
|
import com.hp.hpl.jena.graph.TransactionHandler;
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
import com.hp.hpl.jena.graph.TripleMatch;
|
import com.hp.hpl.jena.graph.TripleMatch;
|
||||||
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
||||||
import com.hp.hpl.jena.graph.impl.SimpleEventManager;
|
import com.hp.hpl.jena.graph.impl.SimpleEventManager;
|
||||||
import com.hp.hpl.jena.graph.query.QueryHandler;
|
|
||||||
import com.hp.hpl.jena.graph.query.SimpleQueryHandler;
|
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
import com.hp.hpl.jena.rdf.listeners.StatementListener;
|
import com.hp.hpl.jena.rdf.listeners.StatementListener;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
import com.hp.hpl.jena.shared.AddDeniedException;
|
import com.hp.hpl.jena.shared.AddDeniedException;
|
||||||
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
||||||
import com.hp.hpl.jena.shared.PrefixMapping;
|
import com.hp.hpl.jena.shared.PrefixMapping;
|
||||||
|
@ -41,6 +37,7 @@ import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
|
||||||
public class RDFServiceGraph implements GraphWithPerform {
|
public class RDFServiceGraph implements GraphWithPerform {
|
||||||
|
@ -52,8 +49,6 @@ public class RDFServiceGraph implements GraphWithPerform {
|
||||||
private BulkUpdateHandler bulkUpdateHandler;
|
private BulkUpdateHandler bulkUpdateHandler;
|
||||||
private PrefixMapping prefixMapping = new PrefixMappingImpl();
|
private PrefixMapping prefixMapping = new PrefixMappingImpl();
|
||||||
private GraphEventManager eventManager;
|
private GraphEventManager eventManager;
|
||||||
private Reifier reifier = new EmptyReifier(this);
|
|
||||||
private QueryHandler queryHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a SparqlGraph for the union of named graphs in a remote repository
|
* Returns a SparqlGraph for the union of named graphs in a remote repository
|
||||||
|
@ -174,6 +169,13 @@ public class RDFServiceGraph implements GraphWithPerform {
|
||||||
performDelete(arg0);
|
performDelete(arg0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Node subject, Node predicate, Node object) {
|
||||||
|
for (Triple t : find(subject, predicate, object).toList()) {
|
||||||
|
delete(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dependsOn(Graph arg0) {
|
public boolean dependsOn(Graph arg0) {
|
||||||
return false; // who knows?
|
return false; // who knows?
|
||||||
|
@ -230,9 +232,9 @@ public class RDFServiceGraph implements GraphWithPerform {
|
||||||
public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) {
|
public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) {
|
||||||
if (!isVar(subject) && !isVar(predicate) && !isVar(object)) {
|
if (!isVar(subject) && !isVar(predicate) && !isVar(object)) {
|
||||||
if (contains(subject, predicate, object)) {
|
if (contains(subject, predicate, object)) {
|
||||||
return new SingletonIterator(new Triple(subject, predicate, object));
|
return new SingletonIterator<Triple>(new Triple(subject, predicate, object));
|
||||||
} else {
|
} else {
|
||||||
return WrappedIterator.create(Collections.EMPTY_LIST.iterator());
|
return WrappedIterator.create(Collections.<Triple>emptyIterator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer findQuery = new StringBuffer("SELECT * WHERE { \n");
|
StringBuffer findQuery = new StringBuffer("SELECT * WHERE { \n");
|
||||||
|
@ -296,11 +298,6 @@ public class RDFServiceGraph implements GraphWithPerform {
|
||||||
return prefixMapping;
|
return prefixMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Reifier getReifier() {
|
|
||||||
return reifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GraphStatisticsHandler getStatisticsHandler() {
|
public GraphStatisticsHandler getStatisticsHandler() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -329,54 +326,60 @@ public class RDFServiceGraph implements GraphWithPerform {
|
||||||
"by SPARQL graphs");
|
"by SPARQL graphs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public QueryHandler queryHandler() {
|
|
||||||
if (queryHandler == null) {
|
|
||||||
queryHandler = new SimpleQueryHandler(this);
|
|
||||||
}
|
|
||||||
return queryHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
int size = find(null, null, null).toList().size();
|
int size = find(null, null, null).toList().size();
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
removeAll();
|
||||||
|
}
|
||||||
|
|
||||||
private final static Capabilities capabilities = new Capabilities() {
|
private final static Capabilities capabilities = new Capabilities() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean addAllowed() {
|
public boolean addAllowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean addAllowed(boolean everyTriple) {
|
public boolean addAllowed(boolean everyTriple) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean canBeEmpty() {
|
public boolean canBeEmpty() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean deleteAllowed() {
|
public boolean deleteAllowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean deleteAllowed(boolean everyTriple) {
|
public boolean deleteAllowed(boolean everyTriple) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean findContractSafe() {
|
public boolean findContractSafe() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean handlesLiteralTyping() {
|
public boolean handlesLiteralTyping() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean iteratorRemoveAllowed() {
|
public boolean iteratorRemoveAllowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean sizeAccurate() {
|
public boolean sizeAccurate() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +443,7 @@ public class RDFServiceGraph implements GraphWithPerform {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Model createRDFServiceModel(final RDFServiceGraph g) {
|
public static Model createRDFServiceModel(final RDFServiceGraph g) {
|
||||||
Model m = ModelFactory.createModelForGraph(g);
|
Model m = VitroModelFactory.createModelForGraph(g);
|
||||||
m.register(new StatementListener() {
|
m.register(new StatementListener() {
|
||||||
@Override
|
@Override
|
||||||
public void notifyEvent(Model m, Object event) {
|
public void notifyEvent(Model m, Object event) {
|
||||||
|
|
|
@ -10,16 +10,17 @@ import java.util.List;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
import com.hp.hpl.jena.graph.Graph;
|
||||||
|
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||||
import com.hp.hpl.jena.graph.GraphEvents;
|
import com.hp.hpl.jena.graph.GraphEvents;
|
||||||
import com.hp.hpl.jena.graph.Node;
|
import com.hp.hpl.jena.graph.Node;
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
import com.hp.hpl.jena.sparql.util.graph.GraphFactory;
|
import com.hp.hpl.jena.sparql.graph.GraphFactory;
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
||||||
|
@ -27,14 +28,15 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
|
||||||
public class RDFServiceGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
public class RDFServiceGraphBulkUpdater implements BulkUpdateHandler {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(RDFServiceGraphBulkUpdater.class);
|
private static final Log log = LogFactory.getLog(RDFServiceGraphBulkUpdater.class);
|
||||||
private RDFServiceGraph graph;
|
private final RDFServiceGraph graph;
|
||||||
|
private final GraphEventManager manager;
|
||||||
|
|
||||||
public RDFServiceGraphBulkUpdater(RDFServiceGraph graph) {
|
public RDFServiceGraphBulkUpdater(RDFServiceGraph graph) {
|
||||||
super(graph);
|
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
|
this.manager = graph.getEventManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,6 +107,34 @@ public class RDFServiceGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Triple[] arg0) {
|
||||||
|
Graph g = GraphFactory.createPlainGraph();
|
||||||
|
for (int i = 0 ; i < arg0.length ; i++) {
|
||||||
|
g.add(arg0[i]);
|
||||||
|
}
|
||||||
|
delete(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(List<Triple> arg0) {
|
||||||
|
Graph g = GraphFactory.createPlainGraph();
|
||||||
|
for (Triple t : arg0) {
|
||||||
|
g.add(t);
|
||||||
|
}
|
||||||
|
delete(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Iterator<Triple> arg0) {
|
||||||
|
Graph g = GraphFactory.createPlainGraph();
|
||||||
|
while (arg0.hasNext()) {
|
||||||
|
Triple t = arg0.next();
|
||||||
|
g.add(t);
|
||||||
|
}
|
||||||
|
delete(g);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Graph g, boolean withReifications) {
|
public void delete(Graph g, boolean withReifications) {
|
||||||
delete(g);
|
delete(g);
|
||||||
|
@ -159,7 +189,7 @@ public class RDFServiceGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
||||||
manager.notifyEvent(graph, GraphEvents.remove(s, p, o));
|
manager.notifyEvent(graph, GraphEvents.remove(s, p, o));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeAll(Graph g, Node s, Node p, Node o)
|
private static void removeAll(Graph g, Node s, Node p, Node o)
|
||||||
{
|
{
|
||||||
if (!(g instanceof RDFServiceGraph)) {
|
if (!(g instanceof RDFServiceGraph)) {
|
||||||
removeAllTripleByTriple(g, s, p, o);
|
removeAllTripleByTriple(g, s, p, o);
|
||||||
|
@ -245,7 +275,7 @@ public class RDFServiceGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
||||||
* see http://www.python.org/doc/2.5.2/ref/strings.html
|
* see http://www.python.org/doc/2.5.2/ref/strings.html
|
||||||
* or see jena's n3 grammar jena/src/com/hp/hpl/jena/n3/n3.g
|
* or see jena's n3 grammar jena/src/com/hp/hpl/jena/n3/n3.g
|
||||||
*/
|
*/
|
||||||
protected static void pyString(StringBuffer sbuff, String s)
|
private static void pyString(StringBuffer sbuff, String s)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < s.length(); i++) {
|
for (int i = 0; i < s.length(); i++) {
|
||||||
char c = s.charAt(i);
|
char c = s.charAt(i);
|
||||||
|
@ -280,7 +310,7 @@ public class RDFServiceGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeAllTripleByTriple(Graph g, Node s, Node p, Node o)
|
private static void removeAllTripleByTriple(Graph g, Node s, Node p, Node o)
|
||||||
{
|
{
|
||||||
ExtendedIterator<Triple> it = g.find( s, p, o );
|
ExtendedIterator<Triple> it = g.find( s, p, o );
|
||||||
try {
|
try {
|
||||||
|
@ -295,9 +325,4 @@ public class RDFServiceGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeAll( Graph g )
|
|
||||||
{
|
|
||||||
g.getBulkUpdateHandler().delete(g);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService.ModelSerializationFormat;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService.ModelSerializationFormat;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
||||||
|
|
||||||
public class RDFServiceModelMaker implements ModelMaker {
|
public class RDFServiceModelMaker implements ModelMaker {
|
||||||
|
|
||||||
|
@ -199,10 +200,7 @@ public class RDFServiceModelMaker implements ModelMaker {
|
||||||
Graph bnodeFilteringGraph = new BlankNodeFilteringGraph(model.getGraph());
|
Graph bnodeFilteringGraph = new BlankNodeFilteringGraph(model.getGraph());
|
||||||
Model bnodeFilteringModel = ModelFactory.createModelForGraph(bnodeFilteringGraph);
|
Model bnodeFilteringModel = ModelFactory.createModelForGraph(bnodeFilteringGraph);
|
||||||
|
|
||||||
BulkUpdateHandler bulkUpdateHandler = model.getGraph().getBulkUpdateHandler();
|
Model specialUnionModel = VitroModelFactory.createUnion(bnodeFilteringModel, bnodeModel);
|
||||||
Model unionModel = ModelFactory.createUnion(bnodeFilteringModel, bnodeModel);
|
|
||||||
Graph specialGraph = new SpecialBulkUpdateHandlerGraph(unionModel.getGraph(), bulkUpdateHandler);
|
|
||||||
Model specialUnionModel = ModelFactory.createModelForGraph(specialGraph);
|
|
||||||
bnodeFilteringModel.register(new BlankNodeStatementListener(bnodeModel));
|
bnodeFilteringModel.register(new BlankNodeStatementListener(bnodeModel));
|
||||||
|
|
||||||
return specialUnionModel;
|
return specialUnionModel;
|
||||||
|
|
|
@ -11,16 +11,14 @@ import com.hp.hpl.jena.graph.Graph;
|
||||||
import com.hp.hpl.jena.graph.GraphEventManager;
|
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||||
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
||||||
import com.hp.hpl.jena.graph.Node;
|
import com.hp.hpl.jena.graph.Node;
|
||||||
import com.hp.hpl.jena.graph.Reifier;
|
|
||||||
import com.hp.hpl.jena.graph.TransactionHandler;
|
import com.hp.hpl.jena.graph.TransactionHandler;
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
import com.hp.hpl.jena.graph.TripleMatch;
|
import com.hp.hpl.jena.graph.TripleMatch;
|
||||||
import com.hp.hpl.jena.graph.query.QueryHandler;
|
|
||||||
import com.hp.hpl.jena.shared.AddDeniedException;
|
import com.hp.hpl.jena.shared.AddDeniedException;
|
||||||
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
||||||
import com.hp.hpl.jena.shared.PrefixMapping;
|
import com.hp.hpl.jena.shared.PrefixMapping;
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
import com.hp.hpl.jena.vocabulary.DAML_OIL;
|
import com.hp.hpl.jena.vocabulary.DCTerms;
|
||||||
import com.hp.hpl.jena.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
|
|
||||||
public class RegeneratingGraph implements Graph, Regenerable {
|
public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
|
@ -40,6 +38,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
this.generator = graphGenerator;
|
this.generator = graphGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void regenerate() {
|
public void regenerate() {
|
||||||
this.g = generator.generateGraph();
|
this.g = generator.generateGraph();
|
||||||
}
|
}
|
||||||
|
@ -49,25 +48,25 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
*/
|
*/
|
||||||
private void sendTestQuery() {
|
private void sendTestQuery() {
|
||||||
this.g.contains(
|
this.g.contains(
|
||||||
DAML_OIL.Thing.asNode(),RDF.type.asNode(),DAML_OIL.Thing.asNode());
|
DCTerms.Agent.asNode(),RDF.type.asNode(),DCTerms.Agent.asNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void finalize() {
|
protected void finalize() {
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
g.close();
|
g.close();
|
||||||
if (generator instanceof RDBGraphGenerator) {
|
|
||||||
((RDBGraphGenerator) generator).getConnection().close();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
regenerate();
|
regenerate();
|
||||||
g.close();
|
g.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean contains(Triple arg0) {
|
public boolean contains(Triple arg0) {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -78,6 +77,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean contains(Node arg0, Node arg1, Node arg2) {
|
public boolean contains(Node arg0, Node arg1, Node arg2) {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -88,6 +88,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void delete(Triple arg0) throws DeleteDeniedException {
|
public void delete(Triple arg0) throws DeleteDeniedException {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -98,6 +99,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean dependsOn(Graph arg0) {
|
public boolean dependsOn(Graph arg0) {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -108,7 +110,8 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtendedIterator find(TripleMatch arg0) {
|
@Override
|
||||||
|
public ExtendedIterator<Triple> find(TripleMatch arg0) {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
return g.find(arg0);
|
return g.find(arg0);
|
||||||
|
@ -118,7 +121,8 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtendedIterator find(Node arg0, Node arg1, Node arg2) {
|
@Override
|
||||||
|
public ExtendedIterator<Triple> find(Node arg0, Node arg1, Node arg2) {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
return g.find(arg0,arg1,arg2);
|
return g.find(arg0,arg1,arg2);
|
||||||
|
@ -128,6 +132,8 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
public BulkUpdateHandler getBulkUpdateHandler() {
|
public BulkUpdateHandler getBulkUpdateHandler() {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -139,6 +145,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Capabilities getCapabilities() {
|
public Capabilities getCapabilities() {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -151,6 +158,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public GraphEventManager getEventManager() {
|
public GraphEventManager getEventManager() {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -163,6 +171,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public PrefixMapping getPrefixMapping() {
|
public PrefixMapping getPrefixMapping() {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -175,18 +184,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Reifier getReifier() {
|
@Override
|
||||||
try {
|
|
||||||
regenerateIfClosed();
|
|
||||||
sendTestQuery();
|
|
||||||
return g.getReifier();
|
|
||||||
} catch (Exception e) {
|
|
||||||
regenerate();
|
|
||||||
return g.getReifier();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public GraphStatisticsHandler getStatisticsHandler() {
|
public GraphStatisticsHandler getStatisticsHandler() {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -199,6 +197,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public TransactionHandler getTransactionHandler() {
|
public TransactionHandler getTransactionHandler() {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -211,6 +210,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isClosed() {
|
public boolean isClosed() {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -222,6 +222,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -233,6 +234,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isIsomorphicWith(Graph arg0) {
|
public boolean isIsomorphicWith(Graph arg0) {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -243,19 +245,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public QueryHandler queryHandler() {
|
|
||||||
try {
|
|
||||||
regenerateIfClosed();
|
|
||||||
sendTestQuery();
|
|
||||||
return g.queryHandler();
|
|
||||||
} catch (Exception e) {
|
|
||||||
regenerate();
|
|
||||||
return g.queryHandler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -267,6 +257,7 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public void add(Triple arg0) throws AddDeniedException {
|
public void add(Triple arg0) throws AddDeniedException {
|
||||||
try {
|
try {
|
||||||
regenerateIfClosed();
|
regenerateIfClosed();
|
||||||
|
@ -277,6 +268,28 @@ public class RegeneratingGraph implements Graph, Regenerable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
try {
|
||||||
|
regenerateIfClosed();
|
||||||
|
g.clear();
|
||||||
|
} catch (Exception e) {
|
||||||
|
regenerate();
|
||||||
|
g.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Node arg0, Node arg1, Node arg2) {
|
||||||
|
try {
|
||||||
|
regenerateIfClosed();
|
||||||
|
g.remove(arg0, arg1, arg2);
|
||||||
|
} catch (Exception e) {
|
||||||
|
regenerate();
|
||||||
|
g.remove(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void regenerateIfClosed() {
|
private void regenerateIfClosed() {
|
||||||
if (generator.isGraphClosed()) {
|
if (generator.isGraphClosed()) {
|
||||||
regenerate();
|
regenerate();
|
||||||
|
|
|
@ -9,6 +9,13 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
||||||
import com.hp.hpl.jena.graph.Capabilities;
|
import com.hp.hpl.jena.graph.Capabilities;
|
||||||
|
@ -16,14 +23,11 @@ import com.hp.hpl.jena.graph.Graph;
|
||||||
import com.hp.hpl.jena.graph.GraphEventManager;
|
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||||
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
||||||
import com.hp.hpl.jena.graph.Node;
|
import com.hp.hpl.jena.graph.Node;
|
||||||
import com.hp.hpl.jena.graph.Reifier;
|
|
||||||
import com.hp.hpl.jena.graph.TransactionHandler;
|
import com.hp.hpl.jena.graph.TransactionHandler;
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
import com.hp.hpl.jena.graph.TripleMatch;
|
import com.hp.hpl.jena.graph.TripleMatch;
|
||||||
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
||||||
import com.hp.hpl.jena.graph.impl.SimpleEventManager;
|
import com.hp.hpl.jena.graph.impl.SimpleEventManager;
|
||||||
import com.hp.hpl.jena.graph.query.QueryHandler;
|
|
||||||
import com.hp.hpl.jena.graph.query.SimpleQueryHandler;
|
|
||||||
import com.hp.hpl.jena.query.Query;
|
import com.hp.hpl.jena.query.Query;
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
|
@ -39,18 +43,6 @@ import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
import com.hp.hpl.jena.util.iterator.SingletonIterator;
|
import com.hp.hpl.jena.util.iterator.SingletonIterator;
|
||||||
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
||||||
|
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
|
||||||
|
|
||||||
public class SparqlGraph implements GraphWithPerform {
|
public class SparqlGraph implements GraphWithPerform {
|
||||||
|
|
||||||
private String endpointURI;
|
private String endpointURI;
|
||||||
|
@ -61,10 +53,6 @@ public class SparqlGraph implements GraphWithPerform {
|
||||||
private BulkUpdateHandler bulkUpdateHandler;
|
private BulkUpdateHandler bulkUpdateHandler;
|
||||||
private PrefixMapping prefixMapping = new PrefixMappingImpl();
|
private PrefixMapping prefixMapping = new PrefixMappingImpl();
|
||||||
private GraphEventManager eventManager;
|
private GraphEventManager eventManager;
|
||||||
private Reifier reifier = new EmptyReifier(this);
|
|
||||||
private GraphStatisticsHandler graphStatisticsHandler;
|
|
||||||
private TransactionHandler transactionHandler;
|
|
||||||
private QueryHandler queryHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a SparqlGraph for the union of named graphs in a remote repository
|
* Returns a SparqlGraph for the union of named graphs in a remote repository
|
||||||
|
@ -205,6 +193,18 @@ public class SparqlGraph implements GraphWithPerform {
|
||||||
performDelete(arg0);
|
performDelete(arg0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
removeAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Node subject, Node predicate, Node object) {
|
||||||
|
for (Triple t: find(subject, predicate, object).toList()) {
|
||||||
|
delete(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dependsOn(Graph arg0) {
|
public boolean dependsOn(Graph arg0) {
|
||||||
return false; // who knows?
|
return false; // who knows?
|
||||||
|
@ -261,9 +261,9 @@ public class SparqlGraph implements GraphWithPerform {
|
||||||
public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) {
|
public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) {
|
||||||
if (!isVar(subject) && !isVar(predicate) && !isVar(object)) {
|
if (!isVar(subject) && !isVar(predicate) && !isVar(object)) {
|
||||||
if (contains(subject, predicate, object)) {
|
if (contains(subject, predicate, object)) {
|
||||||
return new SingletonIterator(new Triple(subject, predicate, object));
|
return new SingletonIterator<Triple>(new Triple(subject, predicate, object));
|
||||||
} else {
|
} else {
|
||||||
return WrappedIterator.create(Collections.EMPTY_LIST.iterator());
|
return WrappedIterator.create(Collections.<Triple>emptyIterator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer findQuery = new StringBuffer("SELECT * WHERE { \n");
|
StringBuffer findQuery = new StringBuffer("SELECT * WHERE { \n");
|
||||||
|
@ -335,14 +335,6 @@ public class SparqlGraph implements GraphWithPerform {
|
||||||
return prefixMapping;
|
return prefixMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Reifier getReifier() {
|
|
||||||
//if (reifier == null) {
|
|
||||||
// reifier = new SimpleReifier(this, ReificationStyle.Standard);
|
|
||||||
//}
|
|
||||||
return reifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GraphStatisticsHandler getStatisticsHandler() {
|
public GraphStatisticsHandler getStatisticsHandler() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -372,14 +364,6 @@ public class SparqlGraph implements GraphWithPerform {
|
||||||
"by SPARQL graphs");
|
"by SPARQL graphs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public QueryHandler queryHandler() {
|
|
||||||
if (queryHandler == null) {
|
|
||||||
queryHandler = new SimpleQueryHandler(this);
|
|
||||||
}
|
|
||||||
return queryHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
int size = find(null, null, null).toList().size();
|
int size = find(null, null, null).toList().size();
|
||||||
|
@ -388,38 +372,47 @@ public class SparqlGraph implements GraphWithPerform {
|
||||||
|
|
||||||
private final static Capabilities capabilities = new Capabilities() {
|
private final static Capabilities capabilities = new Capabilities() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean addAllowed() {
|
public boolean addAllowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean addAllowed(boolean everyTriple) {
|
public boolean addAllowed(boolean everyTriple) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean canBeEmpty() {
|
public boolean canBeEmpty() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean deleteAllowed() {
|
public boolean deleteAllowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean deleteAllowed(boolean everyTriple) {
|
public boolean deleteAllowed(boolean everyTriple) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean findContractSafe() {
|
public boolean findContractSafe() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean handlesLiteralTyping() {
|
public boolean handlesLiteralTyping() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean iteratorRemoveAllowed() {
|
public boolean iteratorRemoveAllowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean sizeAccurate() {
|
public boolean sizeAccurate() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -455,13 +448,11 @@ public class SparqlGraph implements GraphWithPerform {
|
||||||
|
|
||||||
// log.info((System.currentTimeMillis() - startTime1) + " to execute via sesame");
|
// log.info((System.currentTimeMillis() - startTime1) + " to execute via sesame");
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
Query askQuery = QueryFactory.create(queryStr);
|
Query askQuery = QueryFactory.create(queryStr);
|
||||||
QueryExecution qe = QueryExecutionFactory.sparqlService(endpointURI, askQuery);
|
QueryExecution qe = QueryExecutionFactory.sparqlService(endpointURI, askQuery);
|
||||||
try {
|
try {
|
||||||
return new ResultSetMem(qe.execSelect());
|
return new ResultSetMem(qe.execSelect());
|
||||||
} finally {
|
} finally {
|
||||||
//log.info((System.currentTimeMillis() - startTime) + " to execute via Jena");
|
|
||||||
qe.close();
|
qe.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -505,5 +496,4 @@ public class SparqlGraph implements GraphWithPerform {
|
||||||
// sbuff.append(hexstr);
|
// sbuff.append(hexstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
import com.hp.hpl.jena.sparql.util.graph.GraphFactory;
|
import com.hp.hpl.jena.sparql.graph.GraphFactory;
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
|
|
||||||
public class SparqlGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
public class SparqlGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
||||||
|
|
|
@ -17,7 +17,6 @@ import com.hp.hpl.jena.graph.Triple;
|
||||||
import com.hp.hpl.jena.graph.TripleMatch;
|
import com.hp.hpl.jena.graph.TripleMatch;
|
||||||
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
||||||
import com.hp.hpl.jena.shared.AddDeniedException;
|
import com.hp.hpl.jena.shared.AddDeniedException;
|
||||||
import com.hp.hpl.jena.sparql.util.NodeFactory;
|
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
||||||
|
|
||||||
|
@ -51,7 +50,7 @@ public class SparqlGraphMultilingual extends SparqlGraph implements GraphWithPer
|
||||||
&& t.getObject().getLiteral().getDatatypeURI() == null) {
|
&& t.getObject().getLiteral().getDatatypeURI() == null) {
|
||||||
log.info("adding language tag");
|
log.info("adding language tag");
|
||||||
super.performAdd(Triple.create(t.getSubject(),
|
super.performAdd(Triple.create(t.getSubject(),
|
||||||
t.getPredicate(), NodeFactory.createLiteralNode(
|
t.getPredicate(), Node.createLiteral(
|
||||||
t.getObject().getLiteralLexicalForm(), langs.get(0), null)));
|
t.getObject().getLiteralLexicalForm(), langs.get(0), null)));
|
||||||
} else {
|
} else {
|
||||||
log.info("adding original triple " + t);
|
log.info("adding original triple " + t);
|
||||||
|
|
|
@ -1,111 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
|
||||||
import com.hp.hpl.jena.graph.Capabilities;
|
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
|
||||||
import com.hp.hpl.jena.graph.GraphEventManager;
|
|
||||||
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
|
||||||
import com.hp.hpl.jena.graph.Node;
|
|
||||||
import com.hp.hpl.jena.graph.Reifier;
|
|
||||||
import com.hp.hpl.jena.graph.TransactionHandler;
|
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
|
||||||
import com.hp.hpl.jena.graph.TripleMatch;
|
|
||||||
import com.hp.hpl.jena.graph.query.QueryHandler;
|
|
||||||
import com.hp.hpl.jena.shared.AddDeniedException;
|
|
||||||
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
|
||||||
import com.hp.hpl.jena.shared.PrefixMapping;
|
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
|
||||||
|
|
||||||
public class SpecialBulkUpdateHandlerGraph implements Graph {
|
|
||||||
|
|
||||||
private Graph g;
|
|
||||||
private BulkUpdateHandler b;
|
|
||||||
|
|
||||||
public SpecialBulkUpdateHandlerGraph(Graph g, BulkUpdateHandler b) {
|
|
||||||
this.g = g;
|
|
||||||
this.b = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Triple arg0) throws AddDeniedException {
|
|
||||||
g.add(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
g.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean contains(Node arg0, Node arg1, Node arg2) {
|
|
||||||
return g.contains(arg0, arg1, arg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean contains(Triple arg0) {
|
|
||||||
return g.contains(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(Triple arg0) throws DeleteDeniedException {
|
|
||||||
g.delete(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean dependsOn(Graph arg0) {
|
|
||||||
return g.dependsOn(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExtendedIterator<Triple> find(Node arg0, Node arg1, Node arg2) {
|
|
||||||
return g.find(arg0, arg1, arg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExtendedIterator<Triple> find(TripleMatch arg0) {
|
|
||||||
return g.find(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BulkUpdateHandler getBulkUpdateHandler() {
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Capabilities getCapabilities() {
|
|
||||||
return g.getCapabilities();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GraphEventManager getEventManager() {
|
|
||||||
return g.getEventManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrefixMapping getPrefixMapping() {
|
|
||||||
return g.getPrefixMapping();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Reifier getReifier() {
|
|
||||||
return g.getReifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GraphStatisticsHandler getStatisticsHandler() {
|
|
||||||
return g.getStatisticsHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransactionHandler getTransactionHandler() {
|
|
||||||
return g.getTransactionHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isClosed() {
|
|
||||||
return g.isClosed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return g.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIsomorphicWith(Graph arg0) {
|
|
||||||
return g.isIsomorphicWith(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public QueryHandler queryHandler() {
|
|
||||||
return g.queryHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size() {
|
|
||||||
return g.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,21 +2,13 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.*;
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.DISPLAY;
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.INFERRED_FULL;
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.UNION_FULL;
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.*;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.GraphMaker;
|
import com.hp.hpl.jena.graph.GraphMaker;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
@ -26,10 +18,6 @@ import com.hp.hpl.jena.shared.AlreadyExistsException;
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
import com.hp.hpl.jena.util.iterator.NiceIterator;
|
import com.hp.hpl.jena.util.iterator.NiceIterator;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A decorator on top of a model maker. It looks for requests on particular
|
* A decorator on top of a model maker. It looks for requests on particular
|
||||||
* URIs, and shunts them to the pre-made models on ModelAccess.
|
* URIs, and shunts them to the pre-made models on ModelAccess.
|
||||||
|
@ -44,13 +32,11 @@ import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
||||||
*/
|
*/
|
||||||
public class VitroInterceptingModelMaker implements ModelMaker {
|
public class VitroInterceptingModelMaker implements ModelMaker {
|
||||||
private final ModelMaker innerMM;
|
private final ModelMaker innerMM;
|
||||||
private final ServletContext ctx;
|
|
||||||
private final Map<String, Model> specialMap;
|
private final Map<String, Model> specialMap;
|
||||||
|
|
||||||
public VitroInterceptingModelMaker(ModelMaker innerMM, ServletContext ctx) {
|
public VitroInterceptingModelMaker(ModelMaker innerMM, Map<String, Model> specialMap) {
|
||||||
this.innerMM = innerMM;
|
this.innerMM = innerMM;
|
||||||
this.ctx = ctx;
|
this.specialMap = Collections.unmodifiableMap(new HashMap<>(specialMap));
|
||||||
this.specialMap = populateSpecialMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -147,33 +133,6 @@ public class VitroInterceptingModelMaker implements ModelMaker {
|
||||||
// Intercepting mechanism
|
// Intercepting mechanism
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
private Map<String, Model> populateSpecialMap() {
|
|
||||||
Map<String, Model> map = new HashMap<>();
|
|
||||||
|
|
||||||
map.put("vitro:jenaOntModel",
|
|
||||||
ModelAccess.on(ctx).getOntModel(UNION_FULL));
|
|
||||||
map.put("vitro:baseOntModel", ModelAccess.on(ctx)
|
|
||||||
.getOntModel(BASE_FULL));
|
|
||||||
map.put("vitro:inferenceOntModel",
|
|
||||||
ModelAccess.on(ctx).getOntModel(INFERRED_FULL));
|
|
||||||
map.put(JENA_DISPLAY_METADATA_MODEL,
|
|
||||||
ModelAccess.on(ctx).getOntModel(DISPLAY));
|
|
||||||
map.put(JENA_DISPLAY_TBOX_MODEL,
|
|
||||||
ModelAccess.on(ctx).getOntModel(DISPLAY_TBOX));
|
|
||||||
map.put(JENA_DISPLAY_DISPLAY_MODEL,
|
|
||||||
ModelAccess.on(ctx).getOntModel(DISPLAY_DISPLAY));
|
|
||||||
map.put(JENA_USER_ACCOUNTS_MODEL,
|
|
||||||
ModelAccess.on(ctx).getOntModel(USER_ACCOUNTS));
|
|
||||||
map.put(JENA_TBOX_ASSERTIONS_MODEL,
|
|
||||||
ModelAccess.on(ctx).getOntModel(BASE_TBOX));
|
|
||||||
map.put(JENA_TBOX_INF_MODEL,
|
|
||||||
ModelAccess.on(ctx).getOntModel(INFERRED_TBOX));
|
|
||||||
map.put(JENA_APPLICATION_METADATA_MODEL,
|
|
||||||
ModelAccess.on(ctx).getOntModel(APPLICATION_METADATA));
|
|
||||||
|
|
||||||
return Collections.unmodifiableMap(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Collection<String> getSpecialNames() {
|
private Collection<String> getSpecialNames() {
|
||||||
return specialMap.keySet();
|
return specialMap.keySet();
|
||||||
}
|
}
|
||||||
|
@ -191,7 +150,7 @@ public class VitroInterceptingModelMaker implements ModelMaker {
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public SetsExtendedIterator(Collection<String>... collections) {
|
public SetsExtendedIterator(Collection<String>... collections) {
|
||||||
Set<String> set = new HashSet<>();
|
Set<String> set = new TreeSet<>();
|
||||||
for (Collection<String> c : collections) {
|
for (Collection<String> c : collections) {
|
||||||
set.addAll(c);
|
set.addAll(c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,328 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.db.DBConnection;
|
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
|
||||||
import com.hp.hpl.jena.graph.GraphMaker;
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelReader;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
|
||||||
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a bit of a nutty idea but we'll see if it works. This can wrap an RDBModelMaker and return a memory model
|
|
||||||
* synced with the underlying RDB model. Note, however, that a Jena RDBModelMaker won't auto-reconnect. Maybe I can
|
|
||||||
* revisit the reconnecting IDBConnection issue or make a special RDBModelMaker that uses the reconnection system.
|
|
||||||
*
|
|
||||||
* @author bjl23
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class VitroJenaModelMaker implements ModelMaker {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(VitroJenaModelMaker.class);
|
|
||||||
private static final String DEFAULT_DRIVER = "com.mysql.jdbc.Driver";
|
|
||||||
|
|
||||||
private String jdbcUrl;
|
|
||||||
private String username;
|
|
||||||
private String password;
|
|
||||||
private String dbTypeStr;
|
|
||||||
private DataSource dataSource;
|
|
||||||
private HashMap<String,Model> modelCache;
|
|
||||||
private HttpServletRequest request = null;
|
|
||||||
|
|
||||||
public VitroJenaModelMaker(String jdbcUrl, String username, String password, String dbTypeStr, ServletContext ctx) {
|
|
||||||
this.jdbcUrl = jdbcUrl;
|
|
||||||
this.username = username;
|
|
||||||
this.password = password;
|
|
||||||
this.dbTypeStr = dbTypeStr;
|
|
||||||
String driverName = ConfigurationProperties.getBean(ctx).getProperty(
|
|
||||||
"VitroConnection.DataSource.driver");
|
|
||||||
// This property is no longer used?
|
|
||||||
// We'll change it all around in 1.2 anyway.
|
|
||||||
if(driverName == null) {
|
|
||||||
driverName = DEFAULT_DRIVER;
|
|
||||||
}
|
|
||||||
this.dataSource = JenaDataSourceSetupBase.makeBasicDataSource(
|
|
||||||
driverName,
|
|
||||||
jdbcUrl, username, password, ctx);
|
|
||||||
modelCache = new HashMap<String,Model>();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected HashMap<String,Model> getCache() {
|
|
||||||
return this.modelCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
// So, in theory, this should close database connections and drop references
|
|
||||||
// to in-memory models and all that kind of stuff.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model createModel(String arg0) {
|
|
||||||
Model specialModel = null;
|
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
|
||||||
Model cachedModel = modelCache.get(arg0);
|
|
||||||
if (cachedModel != null) {
|
|
||||||
log.debug("Returning "+arg0+" ("+cachedModel.hashCode()+") from cache");
|
|
||||||
return cachedModel;
|
|
||||||
} else {
|
|
||||||
Model newModel = makeDBModel(arg0);
|
|
||||||
modelCache.put(arg0,newModel);
|
|
||||||
log.debug("Returning "+arg0+" ("+newModel.hashCode()+") from cache");
|
|
||||||
return newModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model createModel(String arg0, boolean arg1) {
|
|
||||||
Model specialModel = null;
|
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
|
||||||
Model cachedModel = modelCache.get(arg0);
|
|
||||||
if (cachedModel != null) {
|
|
||||||
return cachedModel;
|
|
||||||
} else {
|
|
||||||
Model newModel = makeDBModel(arg0);
|
|
||||||
modelCache.put(arg0,newModel);
|
|
||||||
return newModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GraphMaker getGraphMaker() {
|
|
||||||
throw new UnsupportedOperationException(this.getClass().getName() +
|
|
||||||
" does not support getGraphMaker()");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasModel(String arg0) {
|
|
||||||
DBConnection conn = new DBConnection(jdbcUrl, username, password, dbTypeStr);
|
|
||||||
try {
|
|
||||||
return ModelFactory.createModelRDBMaker(conn).hasModel(arg0);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException sqle) {
|
|
||||||
throw new RuntimeException(sqle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExtendedIterator listModels() {
|
|
||||||
DBConnection conn = new DBConnection(jdbcUrl, username, password, dbTypeStr);
|
|
||||||
try {
|
|
||||||
List<String> modelList = ModelFactory.createModelRDBMaker(conn).listModels().toList();
|
|
||||||
return WrappedIterator.create(modelList.iterator());
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException sqle) {
|
|
||||||
throw new RuntimeException(sqle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model openModel(String arg0, boolean arg1) {
|
|
||||||
Model specialModel = null;
|
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
|
||||||
Model cachedModel = modelCache.get(arg0);
|
|
||||||
if (cachedModel != null) {
|
|
||||||
return cachedModel;
|
|
||||||
} else {
|
|
||||||
Model newModel = makeDBModel(arg0);
|
|
||||||
modelCache.put(arg0,newModel);
|
|
||||||
return newModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeModel(String arg0) {
|
|
||||||
Model m = modelCache.get(arg0);
|
|
||||||
if (m != null) {
|
|
||||||
m.close();
|
|
||||||
modelCache.remove(arg0);
|
|
||||||
}
|
|
||||||
DBConnection conn = new DBConnection(jdbcUrl, username, password, dbTypeStr);
|
|
||||||
try {
|
|
||||||
ModelFactory.createModelRDBMaker(conn).removeModel(arg0);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException sqle) {
|
|
||||||
throw new RuntimeException(sqle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Model addDescription(Model arg0, Resource arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Model createModelOver(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Model getDescription() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Model getDescription(Resource arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model createDefaultModel() {
|
|
||||||
throw new UnsupportedOperationException(this.getClass().getName() +
|
|
||||||
" does not support createDefaultModel()");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model createFreshModel() {
|
|
||||||
throw new UnsupportedOperationException(this.getClass().getName() +
|
|
||||||
" does not support createFreshModel()"); }
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Model createModel() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Model getModel() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model openModel(String arg0) {
|
|
||||||
Model specialModel = null;
|
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
|
||||||
Model cachedModel = modelCache.get(arg0);
|
|
||||||
if (cachedModel != null) {
|
|
||||||
return cachedModel;
|
|
||||||
} else {
|
|
||||||
Model newModel = makeDBModel(arg0);
|
|
||||||
modelCache.put(arg0,newModel);
|
|
||||||
return newModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model openModelIfPresent(String arg0) {
|
|
||||||
Model specialModel = null;
|
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
|
||||||
Model cachedModel = modelCache.get(arg0);
|
|
||||||
if (cachedModel != null) {
|
|
||||||
return cachedModel;
|
|
||||||
} else {
|
|
||||||
Model newModel = makeDBModel(arg0);
|
|
||||||
modelCache.put(arg0,newModel);
|
|
||||||
return newModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model getModel(String arg0) {
|
|
||||||
Model specialModel = null;
|
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
|
||||||
Model cachedModel = modelCache.get(arg0);
|
|
||||||
if (cachedModel != null) {
|
|
||||||
return cachedModel;
|
|
||||||
} else {
|
|
||||||
Model newModel = makeDBModel(arg0);
|
|
||||||
modelCache.put(arg0,newModel);
|
|
||||||
return newModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model getModel(String arg0, ModelReader arg1) {
|
|
||||||
Model specialModel = null;
|
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
|
||||||
Model cachedModel = modelCache.get(arg0);
|
|
||||||
if (cachedModel != null) {
|
|
||||||
return cachedModel;
|
|
||||||
} else {
|
|
||||||
Model newModel = makeDBModel(arg0);
|
|
||||||
modelCache.put(arg0,newModel);
|
|
||||||
return newModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will trap for strings like "vitro:jenaOntModel" and return the
|
|
||||||
* appropriate in-memory model used by the current webapp context.
|
|
||||||
* To use this functionality, the VitroJenaModelMaker must be constructed
|
|
||||||
* with a VitroRequest parameter
|
|
||||||
*/
|
|
||||||
private Model getSpecialModel(String modelName) {
|
|
||||||
if (request != null) {
|
|
||||||
if ("vitro:jenaOntModel".equals(modelName)) {
|
|
||||||
return ModelAccess.on(request.getSession()).getJenaOntModel();
|
|
||||||
} else if ("vitro:baseOntModel".equals(modelName)) {
|
|
||||||
return ModelAccess.on(request.getSession()).getBaseOntModel();
|
|
||||||
} else if ("vitro:inferenceOntModel".equals(modelName)) {
|
|
||||||
return ModelAccess.on(request.getSession()).getInferenceOntModel();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private OntModel makeDBModel(String jenaDbModelName) {
|
|
||||||
OntModel memCache = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
RDBGraphGenerator gen = new RDBGraphGenerator(dataSource, dbTypeStr, jenaDbModelName);
|
|
||||||
Graph g = gen.generateGraph();
|
|
||||||
Model m = ModelFactory.createModelForGraph(g);
|
|
||||||
memCache.add(m);
|
|
||||||
memCache.register(new MemToDBModelSynchronizer(gen));
|
|
||||||
m.close();
|
|
||||||
try {
|
|
||||||
gen.getConnection().close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.warn("Unable to close connection for graph", e);
|
|
||||||
}
|
|
||||||
// This next piece is so that we return a fresh model object each time so we don't get cross-contamination of extra listeners, etc.
|
|
||||||
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ModelFactory.createUnion(memCache, ModelFactory.createDefaultModel()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -17,7 +17,6 @@ import com.hp.hpl.jena.iri.IRIFactory;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.ontology.OntResource;
|
import com.hp.hpl.jena.ontology.OntResource;
|
||||||
import com.hp.hpl.jena.query.DataSource;
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.query.DatasetFactory;
|
import com.hp.hpl.jena.query.DatasetFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
@ -155,7 +154,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
|
|
||||||
public static Dataset makeInMemoryDataset(Model assertions,
|
public static Dataset makeInMemoryDataset(Model assertions,
|
||||||
Model inferences) {
|
Model inferences) {
|
||||||
DataSource dataset = DatasetFactory.create();
|
Dataset dataset = DatasetFactory.createMem();
|
||||||
OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
if (assertions != null) {
|
if (assertions != null) {
|
||||||
dataset.addNamedModel(
|
dataset.addNamedModel(
|
||||||
|
@ -177,20 +176,20 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
return this.properties;
|
return this.properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String checkURI(String uriStr) {
|
public String checkURI(String uriStr) {
|
||||||
return checkURI(uriStr, true);
|
return checkURI(uriStr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String checkURI(String uriStr, boolean checkUniqueness) {
|
public String checkURI(String uriStr, boolean checkUniqueness) {
|
||||||
uriStr = (uriStr == null) ? " " : uriStr;
|
uriStr = (uriStr == null) ? " " : uriStr;
|
||||||
boolean validURI = true;
|
|
||||||
String errorMsg = "";
|
String errorMsg = "";
|
||||||
String duplicateMsg = "URI is already in use. " +
|
String duplicateMsg = "URI is already in use. " +
|
||||||
"Please enter another URI. ";
|
"Please enter another URI. ";
|
||||||
IRIFactory factory = IRIFactory.jenaImplementation();
|
IRIFactory factory = IRIFactory.jenaImplementation();
|
||||||
IRI iri = factory.create( uriStr );
|
IRI iri = factory.create( uriStr );
|
||||||
if (iri.hasViolation(false) ) {
|
if (iri.hasViolation(false) ) {
|
||||||
validURI = false;
|
|
||||||
errorMsg += (iri.violations(false).next())
|
errorMsg += (iri.violations(false).next())
|
||||||
.getShortMessage() + " ";
|
.getShortMessage() + " ";
|
||||||
} else if (checkUniqueness) {
|
} else if (checkUniqueness) {
|
||||||
|
@ -198,11 +197,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
if(existingURI) {
|
if(existingURI) {
|
||||||
errorMsg+="Not a valid URI. Please enter another URI. ";
|
errorMsg+="Not a valid URI. Please enter another URI. ";
|
||||||
errorMsg+=duplicateMsg;
|
errorMsg+=duplicateMsg;
|
||||||
//the original code included an extra line "Not a valid URI. Please enter another URI. "
|
|
||||||
//in the error message in addition to the duplicate error message in the case where the uri
|
|
||||||
//is in the subject position of any of the statements in the system - but not so where the
|
|
||||||
//uri was only in the object position or was a propery. In this code, the same error message
|
|
||||||
//is returned for all duplicate uris
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (errorMsg.length()>0) ? errorMsg : null;
|
return (errorMsg.length()>0) ? errorMsg : null;
|
||||||
|
@ -211,32 +205,35 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
|
|
||||||
|
|
||||||
//Check if URI already in use or not either as resource OR as property
|
//Check if URI already in use or not either as resource OR as property
|
||||||
|
@Override
|
||||||
public boolean hasExistingURI(String uriStr) {
|
public boolean hasExistingURI(String uriStr) {
|
||||||
OntModel ontModel = ontModelSelector.getFullModel();
|
OntModel ontModel = ontModelSelector.getFullModel();
|
||||||
return URIUtils.hasExistingURI(uriStr, ontModel);
|
return URIUtils.hasExistingURI(uriStr, ontModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
|
||||||
|
|
||||||
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
|
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
|
||||||
return new WebappDaoFactoryJena(this, userURI);
|
return new WebappDaoFactoryJena(this, userURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getUserURI() {
|
public String getUserURI() {
|
||||||
return userURI;
|
return userURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* **************** accessors ***************** */
|
/* **************** accessors ***************** */
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDefaultNamespace() {
|
public String getDefaultNamespace() {
|
||||||
return config.getDefaultNamespace();
|
return config.getDefaultNamespace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<String> getPreferredLanguages() {
|
public List<String> getPreferredLanguages() {
|
||||||
return config.getPreferredLanguages();
|
return config.getPreferredLanguages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Set<String> getNonuserNamespaces() {
|
public Set<String> getNonuserNamespaces() {
|
||||||
return config.getNonUserNamespaces();
|
return config.getNonUserNamespaces();
|
||||||
}
|
}
|
||||||
|
@ -253,6 +250,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
return this.pelletListener;
|
return this.pelletListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<String> getCommentsForResource(String resourceURI) {
|
public List<String> getCommentsForResource(String resourceURI) {
|
||||||
List<String> commentList = new LinkedList<String>();
|
List<String> commentList = new LinkedList<String>();
|
||||||
OntModel ontModel = ontModelSelector.getFullModel();
|
OntModel ontModel = ontModelSelector.getFullModel();
|
||||||
|
@ -276,6 +274,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
return commentList;
|
return commentList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IndividualDao getIndividualDao() {
|
public IndividualDao getIndividualDao() {
|
||||||
if (entityWebappDao != null)
|
if (entityWebappDao != null)
|
||||||
return entityWebappDao;
|
return entityWebappDao;
|
||||||
|
@ -283,6 +282,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
return entityWebappDao = new IndividualDaoJena(this);
|
return entityWebappDao = new IndividualDaoJena(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ApplicationDao getApplicationDao() {
|
public ApplicationDao getApplicationDao() {
|
||||||
if (applicationDao != null) {
|
if (applicationDao != null) {
|
||||||
return applicationDao;
|
return applicationDao;
|
||||||
|
@ -291,6 +291,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public VClassGroupDao getVClassGroupDao() {
|
public VClassGroupDao getVClassGroupDao() {
|
||||||
if (vClassGroupDao != null)
|
if (vClassGroupDao != null)
|
||||||
return vClassGroupDao;
|
return vClassGroupDao;
|
||||||
|
@ -298,6 +299,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
return vClassGroupDao = new VClassGroupDaoJena(this);
|
return vClassGroupDao = new VClassGroupDaoJena(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public PropertyGroupDao getPropertyGroupDao() {
|
public PropertyGroupDao getPropertyGroupDao() {
|
||||||
if (propertyGroupDao != null)
|
if (propertyGroupDao != null)
|
||||||
return propertyGroupDao;
|
return propertyGroupDao;
|
||||||
|
@ -305,6 +307,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
return propertyGroupDao = new PropertyGroupDaoJena(this);
|
return propertyGroupDao = new PropertyGroupDaoJena(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public UserAccountsDao getUserAccountsDao() {
|
public UserAccountsDao getUserAccountsDao() {
|
||||||
if (userAccountsDao != null)
|
if (userAccountsDao != null)
|
||||||
return userAccountsDao;
|
return userAccountsDao;
|
||||||
|
@ -313,6 +316,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
DataPropertyStatementDao dataPropertyStatementDao = null;
|
DataPropertyStatementDao dataPropertyStatementDao = null;
|
||||||
|
@Override
|
||||||
public DataPropertyStatementDao getDataPropertyStatementDao() {
|
public DataPropertyStatementDao getDataPropertyStatementDao() {
|
||||||
if( dataPropertyStatementDao == null )
|
if( dataPropertyStatementDao == null )
|
||||||
dataPropertyStatementDao = new DataPropertyStatementDaoJena(
|
dataPropertyStatementDao = new DataPropertyStatementDaoJena(
|
||||||
|
@ -321,6 +325,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
DatatypeDao datatypeDao = null;
|
DatatypeDao datatypeDao = null;
|
||||||
|
@Override
|
||||||
public DatatypeDao getDatatypeDao() {
|
public DatatypeDao getDatatypeDao() {
|
||||||
if( datatypeDao == null )
|
if( datatypeDao == null )
|
||||||
datatypeDao = new DatatypeDaoJena(this);
|
datatypeDao = new DatatypeDaoJena(this);
|
||||||
|
@ -328,6 +333,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
DataPropertyDao dataPropertyDao = null;
|
DataPropertyDao dataPropertyDao = null;
|
||||||
|
@Override
|
||||||
public DataPropertyDao getDataPropertyDao() {
|
public DataPropertyDao getDataPropertyDao() {
|
||||||
if( dataPropertyDao == null )
|
if( dataPropertyDao == null )
|
||||||
dataPropertyDao = new DataPropertyDaoJena(rdfService, dwf, this);
|
dataPropertyDao = new DataPropertyDaoJena(rdfService, dwf, this);
|
||||||
|
@ -342,6 +348,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectPropertyStatementDao objectPropertyStatementDao = null;
|
ObjectPropertyStatementDao objectPropertyStatementDao = null;
|
||||||
|
@Override
|
||||||
public ObjectPropertyStatementDao getObjectPropertyStatementDao() {
|
public ObjectPropertyStatementDao getObjectPropertyStatementDao() {
|
||||||
if( objectPropertyStatementDao == null )
|
if( objectPropertyStatementDao == null )
|
||||||
// TODO supply a valid RDFService as the first argument if we keep this
|
// TODO supply a valid RDFService as the first argument if we keep this
|
||||||
|
@ -352,6 +359,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private OntologyDao ontologyDao = null;
|
private OntologyDao ontologyDao = null;
|
||||||
|
@Override
|
||||||
public OntologyDao getOntologyDao() {
|
public OntologyDao getOntologyDao() {
|
||||||
if( ontologyDao == null )
|
if( ontologyDao == null )
|
||||||
ontologyDao = new OntologyDaoJena(this);
|
ontologyDao = new OntologyDaoJena(this);
|
||||||
|
@ -359,6 +367,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectPropertyDao objectPropertyDao = null;
|
private ObjectPropertyDao objectPropertyDao = null;
|
||||||
|
@Override
|
||||||
public ObjectPropertyDao getObjectPropertyDao() {
|
public ObjectPropertyDao getObjectPropertyDao() {
|
||||||
if( objectPropertyDao == null )
|
if( objectPropertyDao == null )
|
||||||
objectPropertyDao = new ObjectPropertyDaoJena(
|
objectPropertyDao = new ObjectPropertyDaoJena(
|
||||||
|
@ -367,6 +376,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private PropertyInstanceDao propertyInstanceDao = null;
|
private PropertyInstanceDao propertyInstanceDao = null;
|
||||||
|
@Override
|
||||||
public PropertyInstanceDao getPropertyInstanceDao() {
|
public PropertyInstanceDao getPropertyInstanceDao() {
|
||||||
if( propertyInstanceDao == null )
|
if( propertyInstanceDao == null )
|
||||||
propertyInstanceDao = new PropertyInstanceDaoJena(rdfService, dwf, this);
|
propertyInstanceDao = new PropertyInstanceDaoJena(rdfService, dwf, this);
|
||||||
|
@ -374,6 +384,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected VClassDao vClassDao = null;
|
protected VClassDao vClassDao = null;
|
||||||
|
@Override
|
||||||
public VClassDao getVClassDao() {
|
public VClassDao getVClassDao() {
|
||||||
if( vClassDao == null )
|
if( vClassDao == null )
|
||||||
vClassDao = new VClassDaoJena(this, config.isUnderlyingStoreReasoned());
|
vClassDao = new VClassDaoJena(this, config.isUnderlyingStoreReasoned());
|
||||||
|
|
|
@ -7,10 +7,11 @@ import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.SWITCH_TO_D
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_DISPLAY_MODEL_PARAM;
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_DISPLAY_MODEL_PARAM;
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_MODEL_PARAM;
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_MODEL_PARAM;
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_TBOX_MODEL_PARAM;
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_TBOX_MODEL_PARAM;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService.CONFIGURATION;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService.CONTENT;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -23,14 +24,16 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroModelSource;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroModelSource;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle model switching, if requested for the editing framework.
|
* Handle model switching, if requested for the editing framework.
|
||||||
|
@ -97,13 +100,9 @@ public class ModelSwitcher {
|
||||||
|
|
||||||
// If they asked for other models by URI, set them.
|
// If they asked for other models by URI, set them.
|
||||||
if (anyOtherSpecialProperties(vreq)) {
|
if (anyOtherSpecialProperties(vreq)) {
|
||||||
DataSource bds = JenaDataSourceSetupBase.getApplicationDataSource(_context);
|
OntModel mainOntModel = createSpecialModel(vreq, USE_MODEL_PARAM);
|
||||||
String dbType = ConfigurationProperties.getBean(_context)
|
OntModel tboxOntModel = createSpecialModel(vreq, USE_TBOX_MODEL_PARAM);
|
||||||
.getProperty("VitroConnection.DataSource.dbtype", "MySQL");
|
OntModel displayOntModel = createSpecialModel(vreq, USE_DISPLAY_MODEL_PARAM);
|
||||||
|
|
||||||
OntModel mainOntModel = createSpecialModel(vreq, USE_MODEL_PARAM, bds, dbType);
|
|
||||||
OntModel tboxOntModel = createSpecialModel(vreq, USE_TBOX_MODEL_PARAM, bds, dbType);
|
|
||||||
OntModel displayOntModel = createSpecialModel(vreq, USE_DISPLAY_MODEL_PARAM, bds, dbType);
|
|
||||||
|
|
||||||
vreq.setAttribute(VitroRequest.ID_FOR_ABOX_MODEL, vreq.getParameter(USE_MODEL_PARAM));
|
vreq.setAttribute(VitroRequest.ID_FOR_ABOX_MODEL, vreq.getParameter(USE_MODEL_PARAM));
|
||||||
vreq.setAttribute(VitroRequest.ID_FOR_WRITE_MODEL, vreq.getParameter(USE_MODEL_PARAM));
|
vreq.setAttribute(VitroRequest.ID_FOR_WRITE_MODEL, vreq.getParameter(USE_MODEL_PARAM));
|
||||||
|
@ -160,23 +159,39 @@ public class ModelSwitcher {
|
||||||
* @throws IllegalStateException
|
* @throws IllegalStateException
|
||||||
* if it's not found.
|
* if it's not found.
|
||||||
*/
|
*/
|
||||||
private OntModel createSpecialModel(VitroRequest vreq, String key,
|
private OntModel createSpecialModel(VitroRequest vreq, String key) {
|
||||||
DataSource bds, String dbType) {
|
|
||||||
if (!isParameterPresent(vreq, key)) {
|
if (!isParameterPresent(vreq, key)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String modelUri = vreq.getParameter(key);
|
String modelUri = vreq.getParameter(key);
|
||||||
Model model = JenaDataSourceSetupBase.makeDBModel(bds, modelUri,
|
|
||||||
OntModelSpec.OWL_MEM,
|
OntModel ont = findModelInRdfService(vreq, modelUri, CONFIGURATION);
|
||||||
JenaDataSourceSetupBase.TripleStoreType.RDB, dbType, vreq.getSession().getServletContext());
|
if (ont == null) {
|
||||||
if (model != null) {
|
ont = findModelInRdfService(vreq, modelUri, CONTENT);
|
||||||
return ModelFactory
|
}
|
||||||
.createOntologyModel(OntModelSpec.OWL_MEM, model);
|
if (ont == null) {
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Main Model Uri " + modelUri
|
throw new IllegalStateException("Main Model Uri " + modelUri
|
||||||
+ " did not retrieve model");
|
+ " did not retrieve model");
|
||||||
}
|
}
|
||||||
|
return ont;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OntModel findModelInRdfService(VitroRequest vreq, String modelUri,
|
||||||
|
WhichService which) {
|
||||||
|
try {
|
||||||
|
RDFService rdfService = RDFServiceUtils.getRDFService(vreq, which);
|
||||||
|
if (!rdfService.getGraphURIs().contains(modelUri)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Model m = new RDFServiceDataset(rdfService).getNamedModel(modelUri);
|
||||||
|
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, m);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("failed to find model: '" + modelUri + "' in RDFService "
|
||||||
|
+ which, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,15 +26,12 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.openjena.atlas.lib.Pair;
|
import org.apache.jena.atlas.lib.Pair;
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
//import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
||||||
|
@ -52,10 +49,10 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.HideFromDisplayByP
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SpecialBulkUpdateHandlerGraph;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
@ -197,19 +194,20 @@ public class RequestModelsPrep implements Filter {
|
||||||
|
|
||||||
// Anything derived from the ABOX is not memory-mapped, so create
|
// Anything derived from the ABOX is not memory-mapped, so create
|
||||||
// versions from the short-term RDF service.
|
// versions from the short-term RDF service.
|
||||||
OntModel baseABoxModel = createNamedModelFromDataset(dataset,
|
OntModel baseABoxModel = VitroModelFactory.createOntologyModel(dataset
|
||||||
JENA_DB_MODEL);
|
.getNamedModel(JENA_DB_MODEL));
|
||||||
OntModel inferenceABoxModel = createNamedModelFromDataset(dataset,
|
OntModel inferenceABoxModel = VitroModelFactory
|
||||||
JENA_INF_MODEL);
|
.createOntologyModel(dataset.getNamedModel(JENA_INF_MODEL));
|
||||||
OntModel unionABoxModel = createCombinedBulkUpdatingModel(
|
OntModel unionABoxModel = VitroModelFactory.createUnion(
|
||||||
baseABoxModel, inferenceABoxModel);
|
baseABoxModel, inferenceABoxModel);
|
||||||
|
|
||||||
OntModel baseFullModel = createCombinedBulkUpdatingModel(baseABoxModel,
|
OntModel baseFullModel = VitroModelFactory.createUnion(baseABoxModel,
|
||||||
ModelAccess.on(vreq).getOntModel(ModelID.BASE_TBOX));
|
ModelAccess.on(vreq).getOntModel(ModelID.BASE_TBOX));
|
||||||
OntModel inferenceFullModel = createCombinedModel(inferenceABoxModel,
|
OntModel inferenceFullModel = VitroModelFactory.createUnion(
|
||||||
|
inferenceABoxModel,
|
||||||
ModelAccess.on(vreq).getOntModel(ModelID.INFERRED_TBOX));
|
ModelAccess.on(vreq).getOntModel(ModelID.INFERRED_TBOX));
|
||||||
OntModel unionFullModel = ModelFactory.createOntologyModel(
|
OntModel unionFullModel = VitroModelFactory.createOntologyModel(
|
||||||
OntModelSpec.OWL_MEM, dataset.getDefaultModel());
|
dataset.getDefaultModel());
|
||||||
|
|
||||||
ModelAccess.on(vreq).setOntModel(ModelID.BASE_ABOX, baseABoxModel);
|
ModelAccess.on(vreq).setOntModel(ModelID.BASE_ABOX, baseABoxModel);
|
||||||
ModelAccess.on(vreq).setOntModel(ModelID.INFERRED_ABOX, inferenceABoxModel);
|
ModelAccess.on(vreq).setOntModel(ModelID.INFERRED_ABOX, inferenceABoxModel);
|
||||||
|
@ -224,24 +222,6 @@ public class RequestModelsPrep implements Filter {
|
||||||
ModelAccess.on(vreq).setOntModel(modelId, contextModel);
|
ModelAccess.on(vreq).setOntModel(modelId, contextModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OntModel createNamedModelFromDataset(Dataset dataset, String name) {
|
|
||||||
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, dataset.getNamedModel(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
private OntModel createCombinedModel(OntModel oneModel, OntModel otherModel) {
|
|
||||||
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
|
||||||
ModelFactory.createUnion(oneModel, otherModel));
|
|
||||||
}
|
|
||||||
|
|
||||||
private OntModel createCombinedBulkUpdatingModel(OntModel baseModel,
|
|
||||||
OntModel otherModel) {
|
|
||||||
BulkUpdateHandler bulkUpdateHandler = baseModel.getGraph().getBulkUpdateHandler();
|
|
||||||
Graph unionGraph = ModelFactory.createUnion(baseModel, otherModel).getGraph();
|
|
||||||
Model unionModel = ModelFactory.createModelForGraph(
|
|
||||||
new SpecialBulkUpdateHandlerGraph(unionGraph, bulkUpdateHandler));
|
|
||||||
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, unionModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create an OntModelSelector that will hold the un-language-filtered models. */
|
/** Create an OntModelSelector that will hold the un-language-filtered models. */
|
||||||
private OntModelSelector createLanguageNeutralOntModelSelector(
|
private OntModelSelector createLanguageNeutralOntModelSelector(
|
||||||
VitroRequest vreq) {
|
VitroRequest vreq) {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,209 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.adapters;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
||||||
|
import com.hp.hpl.jena.graph.Graph;
|
||||||
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFReaderF;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
|
import com.hp.hpl.jena.rdf.model.impl.ModelCom;
|
||||||
|
import com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl;
|
||||||
|
import com.hp.hpl.jena.rdf.model.impl.StatementImpl;
|
||||||
|
import com.hp.hpl.jena.shared.WrappedIOException;
|
||||||
|
import com.hp.hpl.jena.util.iterator.Map1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A model that still handles bulk updates in the old-fashioned way: with a
|
||||||
|
* BulkUpdateHandler.
|
||||||
|
*/
|
||||||
|
public class BulkUpdatingModel extends ModelCom {
|
||||||
|
private static final RDFReaderF readerFactory = new RDFReaderFImpl();
|
||||||
|
|
||||||
|
private final BulkUpdateHandler buh;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public BulkUpdatingModel(Graph base) {
|
||||||
|
super(base);
|
||||||
|
this.buh = base.getBulkUpdateHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BulkUpdatingModel(Graph base, BulkUpdateHandler buh) {
|
||||||
|
super(base);
|
||||||
|
this.buh = buh;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model add(StmtIterator iter) {
|
||||||
|
try {
|
||||||
|
buh.add(asTriples(iter));
|
||||||
|
} finally {
|
||||||
|
iter.close();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model add(Model m) {
|
||||||
|
return add(m, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@Override
|
||||||
|
public Model add(Model m, boolean suppressReifications) {
|
||||||
|
// suppressReifications is a no-op.
|
||||||
|
buh.add(m.getGraph());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model read(String url) {
|
||||||
|
Model m = ModelFactory.createDefaultModel();
|
||||||
|
readerFactory.getReader().read(m, url);
|
||||||
|
buh.add(m.getGraph());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model read(Reader reader, String base) {
|
||||||
|
Model m = ModelFactory.createDefaultModel();
|
||||||
|
readerFactory.getReader().read(m, reader, base);
|
||||||
|
buh.add(m.getGraph());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model read(InputStream reader, String base) {
|
||||||
|
Model m = ModelFactory.createDefaultModel();
|
||||||
|
readerFactory.getReader().read(m, reader, base);
|
||||||
|
buh.add(m.getGraph());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model read(String url, String lang) {
|
||||||
|
Model m = ModelFactory.createDefaultModel();
|
||||||
|
readerFactory.getReader(lang).read(m, url);
|
||||||
|
buh.add(m.getGraph());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model read(String url, String base, String lang) {
|
||||||
|
try {
|
||||||
|
InputStream is = new URL(url).openStream();
|
||||||
|
try {
|
||||||
|
read(is, base, lang);
|
||||||
|
} finally {
|
||||||
|
if (null != is) {
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new WrappedIOException(e);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model read(Reader reader, String base, String lang) {
|
||||||
|
Model m = ModelFactory.createDefaultModel();
|
||||||
|
readerFactory.getReader(lang).read(m, reader, base);
|
||||||
|
buh.add(m.getGraph());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model read(InputStream reader, String base, String lang) {
|
||||||
|
Model m = ModelFactory.createDefaultModel();
|
||||||
|
readerFactory.getReader(lang).read(m, reader, base);
|
||||||
|
buh.add(m.getGraph());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model remove(StmtIterator iter) {
|
||||||
|
buh.delete(asTriples(iter));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model remove(Model m) {
|
||||||
|
return remove(m, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public Model remove(Model m, boolean suppressReifications) {
|
||||||
|
buh.delete(m.getGraph());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model removeAll() {
|
||||||
|
buh.removeAll();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model add(Statement[] statements) {
|
||||||
|
buh.add(StatementImpl.asTriples(statements));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model add(List<Statement> statements) {
|
||||||
|
add(statements.toArray(new Statement[statements.size()]));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Model remove(Statement[] statements) {
|
||||||
|
buh.delete(StatementImpl.asTriples(statements));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model remove(List<Statement> statements) {
|
||||||
|
remove(statements.toArray(new Statement[statements.size()]));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "<" + this.getClass().getSimpleName() + " " + getGraph() + ">";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Iterator<Triple> asTriples(StmtIterator it) {
|
||||||
|
return it.mapWith(mapAsTriple);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map1<Statement, Triple> mapAsTriple = new Map1<Statement, Triple>() {
|
||||||
|
@Override
|
||||||
|
public Triple map1(Statement s) {
|
||||||
|
return s.asTriple();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,132 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.adapters;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
||||||
|
import com.hp.hpl.jena.graph.Capabilities;
|
||||||
|
import com.hp.hpl.jena.graph.Graph;
|
||||||
|
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||||
|
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
||||||
|
import com.hp.hpl.jena.graph.Node;
|
||||||
|
import com.hp.hpl.jena.graph.TransactionHandler;
|
||||||
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
|
import com.hp.hpl.jena.graph.TripleMatch;
|
||||||
|
import com.hp.hpl.jena.shared.AddDeniedException;
|
||||||
|
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
||||||
|
import com.hp.hpl.jena.shared.PrefixMapping;
|
||||||
|
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Graph wrapper uses a BulkUpdatingHandler different from the one owned by
|
||||||
|
* the wrapped Graph.
|
||||||
|
*/
|
||||||
|
public class SpecialBulkUpdatingGraph implements Graph {
|
||||||
|
|
||||||
|
private Graph g;
|
||||||
|
private BulkUpdateHandler b;
|
||||||
|
|
||||||
|
public SpecialBulkUpdatingGraph(Graph g, BulkUpdateHandler b) {
|
||||||
|
this.g = g;
|
||||||
|
this.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Triple arg0) throws AddDeniedException {
|
||||||
|
g.add(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
g.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Node arg0, Node arg1, Node arg2) {
|
||||||
|
return g.contains(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Triple arg0) {
|
||||||
|
return g.contains(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Triple arg0) throws DeleteDeniedException {
|
||||||
|
g.delete(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dependsOn(Graph arg0) {
|
||||||
|
return g.dependsOn(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExtendedIterator<Triple> find(Node arg0, Node arg1, Node arg2) {
|
||||||
|
return g.find(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExtendedIterator<Triple> find(TripleMatch arg0) {
|
||||||
|
return g.find(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BulkUpdateHandler getBulkUpdateHandler() {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Capabilities getCapabilities() {
|
||||||
|
return g.getCapabilities();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GraphEventManager getEventManager() {
|
||||||
|
return g.getEventManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PrefixMapping getPrefixMapping() {
|
||||||
|
return g.getPrefixMapping();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GraphStatisticsHandler getStatisticsHandler() {
|
||||||
|
return g.getStatisticsHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransactionHandler getTransactionHandler() {
|
||||||
|
return g.getTransactionHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() {
|
||||||
|
return g.isClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return g.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIsomorphicWith(Graph arg0) {
|
||||||
|
return g.isIsomorphicWith(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return g.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
g.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Node arg0, Node arg1, Node arg2) {
|
||||||
|
g.remove(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.adapters;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
||||||
|
import com.hp.hpl.jena.graph.Graph;
|
||||||
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make models that will do proper bulk updates.
|
||||||
|
*/
|
||||||
|
public class VitroModelFactory {
|
||||||
|
|
||||||
|
public static OntModel createOntologyModel() {
|
||||||
|
return new BulkUpdatingOntModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OntModel createOntologyModel(Model model) {
|
||||||
|
return new BulkUpdatingOntModel(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Model createUnion(Model baseModel, Model otherModel) {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
BulkUpdateHandler buh = baseModel.getGraph().getBulkUpdateHandler();
|
||||||
|
|
||||||
|
Graph unionGraph = ModelFactory.createUnion(baseModel, otherModel)
|
||||||
|
.getGraph();
|
||||||
|
return new BulkUpdatingModel(unionGraph, buh);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OntModel createUnion(OntModel baseModel, OntModel otherModel) {
|
||||||
|
return new BulkUpdatingOntModel(createUnion((Model) baseModel,
|
||||||
|
(Model) otherModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Model createModelForGraph(Graph g) {
|
||||||
|
return new BulkUpdatingModel(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -90,4 +90,13 @@ public class ChangeSetImpl implements ChangeSet {
|
||||||
public List<Object> getPostChangeEvents() {
|
public List<Object> getPostChangeEvents() {
|
||||||
return this.postChangeEvents;
|
return this.postChangeEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ChangeSetImpl [preconditionQuery=" + preconditionQuery
|
||||||
|
+ ", queryType=" + queryType + ", modelChanges=" + modelChanges
|
||||||
|
+ ", preChangeEvents=" + preChangeEvents
|
||||||
|
+ ", postChangeEvents=" + postChangeEvents + "]";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl;
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
@ -66,4 +70,26 @@ public class ModelChangeImpl implements ModelChange {
|
||||||
public void setGraphURI(String graphURI) {
|
public void setGraphURI(String graphURI) {
|
||||||
this.graphURI = graphURI;
|
this.graphURI = graphURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ModelChangeImpl [serializedModel="
|
||||||
|
+ streamToString(serializedModel) + ", serializationFormat="
|
||||||
|
+ serializationFormat + ", operation=" + operation
|
||||||
|
+ ", graphURI=" + graphURI + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String streamToString(InputStream stream) {
|
||||||
|
if (!stream.markSupported()) {
|
||||||
|
return String.valueOf(stream);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
stream.mark(Integer.MAX_VALUE);
|
||||||
|
List<String> lines = IOUtils.readLines(stream);
|
||||||
|
stream.reset();
|
||||||
|
return String.valueOf(lines);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return "Failed to read input stream: " + e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import com.hp.hpl.jena.query.ResultSet;
|
||||||
import com.hp.hpl.jena.query.ResultSetFactory;
|
import com.hp.hpl.jena.query.ResultSetFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.sparql.resultset.ResultSetFormat;
|
import com.hp.hpl.jena.sparql.resultset.ResultsFormat;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
@ -26,32 +26,44 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory;
|
||||||
|
|
||||||
public class RDFServiceUtils {
|
public class RDFServiceUtils {
|
||||||
|
private static final Log log = LogFactory.getLog(RDFServiceUtils.class);
|
||||||
static Log log = LogFactory.getLog(RDFServiceUtils.class);
|
|
||||||
|
|
||||||
private static final String RDFSERVICEFACTORY_ATTR =
|
private static final String RDFSERVICEFACTORY_ATTR =
|
||||||
RDFServiceUtils.class.getName() + ".RDFServiceFactory";
|
RDFServiceUtils.class.getName() + ".RDFServiceFactory";
|
||||||
|
|
||||||
|
public enum WhichService {CONTENT, CONFIGURATION}
|
||||||
|
|
||||||
public static RDFServiceFactory getRDFServiceFactory(ServletContext context) {
|
public static RDFServiceFactory getRDFServiceFactory(ServletContext context) {
|
||||||
Object o = context.getAttribute(RDFSERVICEFACTORY_ATTR);
|
return getRDFServiceFactory(context, WhichService.CONTENT);
|
||||||
if (o instanceof RDFServiceFactory) {
|
}
|
||||||
RDFServiceFactory factory = (RDFServiceFactory) o;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Every factory is wrapped in a logger, so we can dynamically
|
* Every factory is wrapped in a logger, so we can dynamically enable or
|
||||||
* enable or disable logging.
|
* disable logging.
|
||||||
*/
|
*/
|
||||||
|
public static RDFServiceFactory getRDFServiceFactory(
|
||||||
|
ServletContext context, WhichService which) {
|
||||||
|
String attribute = RDFSERVICEFACTORY_ATTR + "." + which.name();
|
||||||
|
Object o = context.getAttribute(attribute);
|
||||||
|
if (o instanceof RDFServiceFactory) {
|
||||||
|
RDFServiceFactory factory = (RDFServiceFactory) o;
|
||||||
return new LoggingRDFServiceFactory(factory);
|
return new LoggingRDFServiceFactory(factory);
|
||||||
} else {
|
} else {
|
||||||
log.error("Expecting an RDFServiceFactory on the context, but found " + o);
|
throw new IllegalStateException(
|
||||||
return null;
|
"Expecting an RDFServiceFactory on the context at '"
|
||||||
|
+ attribute + "', but found " + o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setRDFServiceFactory(ServletContext context,
|
public static void setRDFServiceFactory(ServletContext context,
|
||||||
RDFServiceFactory factory) {
|
RDFServiceFactory factory) {
|
||||||
context.setAttribute(RDFSERVICEFACTORY_ATTR, factory);
|
setRDFServiceFactory(context, factory, WhichService.CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setRDFServiceFactory(ServletContext context,
|
||||||
|
RDFServiceFactory factory, WhichService which) {
|
||||||
|
String attribute = RDFSERVICEFACTORY_ATTR + "." + which.name();
|
||||||
|
context.setAttribute(attribute, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputStream toInputStream(String serializedRDF) {
|
public static InputStream toInputStream(String serializedRDF) {
|
||||||
|
@ -69,16 +81,16 @@ public class RDFServiceUtils {
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResultSetFormat getJenaResultSetFormat(ResultFormat resultFormat) {
|
public static ResultsFormat getJenaResultSetFormat(ResultFormat resultFormat) {
|
||||||
switch(resultFormat) {
|
switch(resultFormat) {
|
||||||
case JSON:
|
case JSON:
|
||||||
return ResultSetFormat.syntaxJSON;
|
return ResultsFormat.FMT_RS_JSON;
|
||||||
case CSV:
|
case CSV:
|
||||||
return ResultSetFormat.syntaxCSV;
|
return ResultsFormat.FMT_RS_CSV;
|
||||||
case XML:
|
case XML:
|
||||||
return ResultSetFormat.syntaxXML;
|
return ResultsFormat.FMT_RS_XML;
|
||||||
case TEXT:
|
case TEXT:
|
||||||
return ResultSetFormat.syntaxText;
|
return ResultsFormat.FMT_TEXT;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("unsupported ResultFormat");
|
throw new RuntimeException("unsupported ResultFormat");
|
||||||
}
|
}
|
||||||
|
@ -112,8 +124,12 @@ public class RDFServiceUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RDFService getRDFService(VitroRequest vreq) {
|
public static RDFService getRDFService(VitroRequest vreq) {
|
||||||
|
return getRDFService(vreq, WhichService.CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RDFService getRDFService(VitroRequest vreq, WhichService which) {
|
||||||
return getRDFServiceFactory(
|
return getRDFServiceFactory(
|
||||||
vreq.getSession().getServletContext()).getRDFService();
|
vreq.getSession().getServletContext(), which).getRDFService();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResultSet sparqlSelectQuery(String query, RDFService rdfService) {
|
public static ResultSet sparqlSelectQuery(String query, RDFService rdfService) {
|
||||||
|
|
|
@ -14,15 +14,12 @@ import com.hp.hpl.jena.graph.Graph;
|
||||||
import com.hp.hpl.jena.graph.GraphEventManager;
|
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||||
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
||||||
import com.hp.hpl.jena.graph.Node;
|
import com.hp.hpl.jena.graph.Node;
|
||||||
import com.hp.hpl.jena.graph.Reifier;
|
|
||||||
import com.hp.hpl.jena.graph.TransactionHandler;
|
import com.hp.hpl.jena.graph.TransactionHandler;
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
import com.hp.hpl.jena.graph.TripleMatch;
|
import com.hp.hpl.jena.graph.TripleMatch;
|
||||||
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
||||||
import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler;
|
import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler;
|
||||||
import com.hp.hpl.jena.graph.impl.SimpleEventManager;
|
import com.hp.hpl.jena.graph.impl.SimpleEventManager;
|
||||||
import com.hp.hpl.jena.graph.query.QueryHandler;
|
|
||||||
import com.hp.hpl.jena.graph.query.SimpleQueryHandler;
|
|
||||||
import com.hp.hpl.jena.shared.AddDeniedException;
|
import com.hp.hpl.jena.shared.AddDeniedException;
|
||||||
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
||||||
import com.hp.hpl.jena.shared.PrefixMapping;
|
import com.hp.hpl.jena.shared.PrefixMapping;
|
||||||
|
@ -30,7 +27,6 @@ import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.EmptyReifier;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceImpl;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceImpl;
|
||||||
|
|
||||||
|
@ -44,8 +40,6 @@ public class ListeningGraph implements GraphWithPerform {
|
||||||
private BulkUpdateHandler bulkUpdateHandler;
|
private BulkUpdateHandler bulkUpdateHandler;
|
||||||
private GraphEventManager eventManager;
|
private GraphEventManager eventManager;
|
||||||
private PrefixMapping prefixMapping = new PrefixMappingImpl();
|
private PrefixMapping prefixMapping = new PrefixMappingImpl();
|
||||||
private Reifier reifier = new EmptyReifier(this);
|
|
||||||
private QueryHandler queryHandler;
|
|
||||||
|
|
||||||
public ListeningGraph(String graphURI, RDFServiceImpl rdfServiceImpl) {
|
public ListeningGraph(String graphURI, RDFServiceImpl rdfServiceImpl) {
|
||||||
this.graphURI = graphURI;
|
this.graphURI = graphURI;
|
||||||
|
@ -80,6 +74,7 @@ public class ListeningGraph implements GraphWithPerform {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
// Nothing to close.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,6 +104,20 @@ public class ListeningGraph implements GraphWithPerform {
|
||||||
return WrappedIterator.create(triplist.iterator());
|
return WrappedIterator.create(triplist.iterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
for (Triple t: find(null, null, null).toList()) {
|
||||||
|
delete(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Node subject, Node predicate, Node object) {
|
||||||
|
for (Triple t: find(subject, predicate, object).toList()) {
|
||||||
|
delete(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BulkUpdateHandler getBulkUpdateHandler() {
|
public BulkUpdateHandler getBulkUpdateHandler() {
|
||||||
if (this.bulkUpdateHandler == null) {
|
if (this.bulkUpdateHandler == null) {
|
||||||
|
@ -135,11 +144,6 @@ public class ListeningGraph implements GraphWithPerform {
|
||||||
return prefixMapping;
|
return prefixMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Reifier getReifier() {
|
|
||||||
return reifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GraphStatisticsHandler getStatisticsHandler() {
|
public GraphStatisticsHandler getStatisticsHandler() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -147,13 +151,11 @@ public class ListeningGraph implements GraphWithPerform {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransactionHandler getTransactionHandler() {
|
public TransactionHandler getTransactionHandler() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClosed() {
|
public boolean isClosed() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,14 +170,6 @@ public class ListeningGraph implements GraphWithPerform {
|
||||||
"by SPARQL graphs");
|
"by SPARQL graphs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public QueryHandler queryHandler() {
|
|
||||||
if (queryHandler == null) {
|
|
||||||
queryHandler = new SimpleQueryHandler(this);
|
|
||||||
}
|
|
||||||
return queryHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
int size = find(null, null, null).toList().size();
|
int size = find(null, null, null).toList().size();
|
||||||
|
@ -184,38 +178,47 @@ public class ListeningGraph implements GraphWithPerform {
|
||||||
|
|
||||||
private final static Capabilities capabilities = new Capabilities() {
|
private final static Capabilities capabilities = new Capabilities() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean addAllowed() {
|
public boolean addAllowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean addAllowed(boolean everyTriple) {
|
public boolean addAllowed(boolean everyTriple) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean canBeEmpty() {
|
public boolean canBeEmpty() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean deleteAllowed() {
|
public boolean deleteAllowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean deleteAllowed(boolean everyTriple) {
|
public boolean deleteAllowed(boolean everyTriple) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean findContractSafe() {
|
public boolean findContractSafe() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean handlesLiteralTyping() {
|
public boolean handlesLiteralTyping() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean iteratorRemoveAllowed() {
|
public boolean iteratorRemoveAllowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean sizeAccurate() {
|
public boolean sizeAccurate() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,20 @@ package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.log4j.lf5.util.StreamUtils;
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.Node;
|
|
||||||
import com.hp.hpl.jena.graph.Triple;
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
import com.hp.hpl.jena.query.DataSource;
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.query.DatasetFactory;
|
import com.hp.hpl.jena.query.DatasetFactory;
|
||||||
import com.hp.hpl.jena.query.Query;
|
import com.hp.hpl.jena.query.Query;
|
||||||
|
@ -49,11 +49,61 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
||||||
|
|
||||||
protected abstract DatasetWrapper getDatasetWrapper();
|
protected abstract DatasetWrapper getDatasetWrapper();
|
||||||
|
|
||||||
|
@Override
|
||||||
public abstract boolean changeSetUpdate(ChangeSet changeSet) throws RDFServiceException;
|
public abstract boolean changeSetUpdate(ChangeSet changeSet) throws RDFServiceException;
|
||||||
|
|
||||||
|
protected void notifyListenersOfPreChangeEvents(ChangeSet changeSet) {
|
||||||
|
for (Object o : changeSet.getPreChangeEvents()) {
|
||||||
|
this.notifyListenersOfEvent(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void insureThatInputStreamsAreResettable(ChangeSet changeSet) throws IOException {
|
||||||
|
for (ModelChange modelChange: changeSet.getModelChanges()) {
|
||||||
|
if (!modelChange.getSerializedModel().markSupported()) {
|
||||||
|
byte[] bytes = IOUtils.toByteArray(modelChange.getSerializedModel());
|
||||||
|
modelChange.setSerializedModel(new ByteArrayInputStream(bytes));
|
||||||
|
}
|
||||||
|
modelChange.getSerializedModel().mark(Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void applyChangeSetToModel(ChangeSet changeSet, Dataset dataset) {
|
||||||
|
for (ModelChange modelChange: changeSet.getModelChanges()) {
|
||||||
|
dataset.getLock().enterCriticalSection(Lock.WRITE);
|
||||||
|
try {
|
||||||
|
Model model = (modelChange.getGraphURI() == null) ?
|
||||||
|
dataset.getDefaultModel() :
|
||||||
|
dataset.getNamedModel(modelChange.getGraphURI());
|
||||||
|
operateOnModel(model, modelChange, dataset);
|
||||||
|
} finally {
|
||||||
|
dataset.getLock().leaveCriticalSection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void notifyListenersOfChanges(ChangeSet changeSet)
|
||||||
|
throws IOException {
|
||||||
|
for (ModelChange modelChange: changeSet.getModelChanges()) {
|
||||||
|
modelChange.getSerializedModel().reset();
|
||||||
|
Model model = ModelFactory.createModelForGraph(
|
||||||
|
new ListeningGraph(modelChange.getGraphURI(), this));
|
||||||
|
operateOnModel(model, modelChange, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void notifyListenersOfPostChangeEvents(ChangeSet changeSet) {
|
||||||
|
for (Object o : changeSet.getPostChangeEvents()) {
|
||||||
|
this.notifyListenersOfEvent(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void operateOnModel(Model model, ModelChange modelChange, Dataset dataset) {
|
protected void operateOnModel(Model model, ModelChange modelChange, Dataset dataset) {
|
||||||
model.enterCriticalSection(Lock.WRITE);
|
model.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
dumpOperation(model, modelChange);
|
||||||
|
}
|
||||||
if (modelChange.getOperation() == ModelChange.Operation.ADD) {
|
if (modelChange.getOperation() == ModelChange.Operation.ADD) {
|
||||||
model.read(modelChange.getSerializedModel(), null,
|
model.read(modelChange.getSerializedModel(), null,
|
||||||
getSerializationFormatString(modelChange.getSerializationFormat()));
|
getSerializationFormatString(modelChange.getSerializationFormat()));
|
||||||
|
@ -71,6 +121,62 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As a debug statement, log info about the model change operation: add or
|
||||||
|
* delete, model URI, model class, punctuation count, beginning of the
|
||||||
|
* string.
|
||||||
|
*/
|
||||||
|
private void dumpOperation(Model model, ModelChange modelChange) {
|
||||||
|
String op = String.valueOf(modelChange.getOperation());
|
||||||
|
|
||||||
|
byte[] changeBytes = new byte[0];
|
||||||
|
try {
|
||||||
|
modelChange.getSerializedModel().mark(Integer.MAX_VALUE);
|
||||||
|
changeBytes = StreamUtils
|
||||||
|
.getBytes(modelChange.getSerializedModel());
|
||||||
|
modelChange.getSerializedModel().reset();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// leave it empty.
|
||||||
|
}
|
||||||
|
|
||||||
|
int puncCount = 0;
|
||||||
|
boolean inUri = false;
|
||||||
|
boolean inQuotes = false;
|
||||||
|
for (byte b : changeBytes) {
|
||||||
|
if (inQuotes) {
|
||||||
|
if (b == '"') {
|
||||||
|
inQuotes = false;
|
||||||
|
}
|
||||||
|
} else if (inUri) {
|
||||||
|
if (b == '>') {
|
||||||
|
inUri = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (b == '"') {
|
||||||
|
inQuotes = true;
|
||||||
|
} else if (b == '<') {
|
||||||
|
inUri = true;
|
||||||
|
} else if ((b == ',') || (b == ';') || (b == '.')) {
|
||||||
|
puncCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String changeString = new String(changeBytes).replace('\n', ' ');
|
||||||
|
|
||||||
|
String graphUri = modelChange.getGraphURI();
|
||||||
|
int delimHere = Math.max(graphUri.lastIndexOf('#'),
|
||||||
|
graphUri.lastIndexOf('/'));
|
||||||
|
String graphLocalName = graphUri.substring(delimHere + 1);
|
||||||
|
|
||||||
|
String modelClassName = model.getClass().getSimpleName();
|
||||||
|
|
||||||
|
log.debug(String
|
||||||
|
.format(">>>>OPERATION: %3.3s %03dpunc, name='%s', class=%s, start=%.200s",
|
||||||
|
op, puncCount, graphLocalName, modelClassName,
|
||||||
|
changeString));
|
||||||
|
}
|
||||||
|
|
||||||
private void removeBlankNodesWithSparqlUpdate(Dataset dataset, Model model, String graphURI) {
|
private void removeBlankNodesWithSparqlUpdate(Dataset dataset, Model model, String graphURI) {
|
||||||
|
|
||||||
List<Statement> blankNodeStatements = new ArrayList<Statement>();
|
List<Statement> blankNodeStatements = new ArrayList<Statement>();
|
||||||
|
@ -112,7 +218,7 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
||||||
QueryExecution qee = QueryExecutionFactory.create(treeFinderQuery, blankNodeModel);
|
QueryExecution qee = QueryExecutionFactory.create(treeFinderQuery, blankNodeModel);
|
||||||
try {
|
try {
|
||||||
Model tree = qee.execDescribe();
|
Model tree = qee.execDescribe();
|
||||||
DataSource ds = DatasetFactory.create();
|
Dataset ds = DatasetFactory.createMem();
|
||||||
if (graphURI == null) {
|
if (graphURI == null) {
|
||||||
ds.setDefaultModel(dataset.getDefaultModel());
|
ds.setDefaultModel(dataset.getDefaultModel());
|
||||||
} else {
|
} else {
|
||||||
|
@ -195,7 +301,7 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
||||||
Query construct = QueryFactory.create(queryBuff.toString());
|
Query construct = QueryFactory.create(queryBuff.toString());
|
||||||
// make a plain dataset to force the query to be run in a way that
|
// make a plain dataset to force the query to be run in a way that
|
||||||
// won't overwhelm MySQL with too many joins
|
// won't overwhelm MySQL with too many joins
|
||||||
DataSource ds = DatasetFactory.create();
|
Dataset ds = DatasetFactory.createMem();
|
||||||
if (graphURI == null) {
|
if (graphURI == null) {
|
||||||
ds.setDefaultModel(dataset.getDefaultModel());
|
ds.setDefaultModel(dataset.getDefaultModel());
|
||||||
} else {
|
} else {
|
||||||
|
@ -259,15 +365,6 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getHexString(Node node) {
|
|
||||||
String label = node.getBlankNodeLabel().replaceAll("\\W", "").toUpperCase();
|
|
||||||
if (label.length() > 7) {
|
|
||||||
return label.substring(label.length() - 7);
|
|
||||||
} else {
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final boolean WHERE_CLAUSE = true;
|
private static final boolean WHERE_CLAUSE = true;
|
||||||
|
|
||||||
private void addStatementPatterns(List<Statement> stmts, StringBuffer patternBuff, boolean whereClause) {
|
private void addStatementPatterns(List<Statement> stmts, StringBuffer patternBuff, boolean whereClause) {
|
||||||
|
@ -298,7 +395,7 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getRDFResultStream(String query, boolean construct,
|
private InputStream getRDFResultStream(String query, boolean construct,
|
||||||
ModelSerializationFormat resultFormat) throws RDFServiceException {
|
ModelSerializationFormat resultFormat) {
|
||||||
DatasetWrapper dw = getDatasetWrapper();
|
DatasetWrapper dw = getDatasetWrapper();
|
||||||
try {
|
try {
|
||||||
Dataset d = dw.getDataset();
|
Dataset d = dw.getDataset();
|
||||||
|
@ -407,6 +504,7 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getGraphMetadata() throws RDFServiceException {
|
public void getGraphMetadata() throws RDFServiceException {
|
||||||
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -414,11 +512,6 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
||||||
// nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notifyListeners(Triple triple, ModelChange.Operation operation, String graphURI) {
|
|
||||||
super.notifyListeners(triple, operation, graphURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected QueryExecution createQueryExecution(String queryString, Query q, Dataset d) {
|
protected QueryExecution createQueryExecution(String queryString, Query q, Dataset d) {
|
||||||
return QueryExecutionFactory.create(q, d);
|
return QueryExecutionFactory.create(q, d);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,10 @@ import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.DataSource;
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.query.DatasetFactory;
|
import com.hp.hpl.jena.query.DatasetFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
||||||
|
@ -41,7 +39,7 @@ public class RDFServiceModel extends RDFServiceJena implements RDFService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DatasetWrapper getDatasetWrapper() {
|
protected DatasetWrapper getDatasetWrapper() {
|
||||||
DataSource d = DatasetFactory.create();
|
Dataset d = DatasetFactory.createMem();
|
||||||
if (modelName == null) {
|
if (modelName == null) {
|
||||||
d.setDefaultModel(this.model);
|
d.setDefaultModel(this.model);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,16 +2,13 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.sdb;
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.sdb;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -19,21 +16,16 @@ import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.query.Query;
|
import com.hp.hpl.jena.query.Query;
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
import com.hp.hpl.jena.sdb.SDBFactory;
|
import com.hp.hpl.jena.sdb.SDBFactory;
|
||||||
import com.hp.hpl.jena.sdb.Store;
|
import com.hp.hpl.jena.sdb.Store;
|
||||||
import com.hp.hpl.jena.sdb.StoreDesc;
|
import com.hp.hpl.jena.sdb.StoreDesc;
|
||||||
import com.hp.hpl.jena.sdb.sql.SDBConnection;
|
import com.hp.hpl.jena.sdb.sql.SDBConnection;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.StaticDatasetFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.StaticDatasetFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.ListeningGraph;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.RDFServiceJena;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.RDFServiceJena;
|
||||||
|
|
||||||
public class RDFServiceSDB extends RDFServiceJena implements RDFService {
|
public class RDFServiceSDB extends RDFServiceJena implements RDFService {
|
||||||
|
@ -63,8 +55,8 @@ public class RDFServiceSDB extends RDFServiceJena implements RDFService {
|
||||||
if (staticDatasetFactory != null) {
|
if (staticDatasetFactory != null) {
|
||||||
return staticDatasetFactory.getDatasetWrapper();
|
return staticDatasetFactory.getDatasetWrapper();
|
||||||
}
|
}
|
||||||
SDBConnection conn = new SDBConnection(ds.getConnection());
|
SDBConnection sdbConn = new SDBConnection(ds.getConnection());
|
||||||
return new DatasetWrapper(getDataset(conn), conn);
|
return new DatasetWrapper(getDataset(sdbConn), sdbConn);
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
log.error(sqle, sqle);
|
log.error(sqle, sqle);
|
||||||
throw new RuntimeException(sqle);
|
throw new RuntimeException(sqle);
|
||||||
|
@ -82,93 +74,72 @@ public class RDFServiceSDB extends RDFServiceJena implements RDFService {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBConnection conn = null;
|
SDBConnection sdbConn = getSDBConnection();
|
||||||
|
Dataset dataset = getDataset(sdbConn);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = new SDBConnection(getConnection());
|
insureThatInputStreamsAreResettable(changeSet);
|
||||||
|
|
||||||
|
beginTransaction(sdbConn);
|
||||||
|
|
||||||
|
notifyListenersOfPreChangeEvents(changeSet);
|
||||||
|
applyChangeSetToModel(changeSet, dataset);
|
||||||
|
|
||||||
|
commitTransaction(sdbConn);
|
||||||
|
|
||||||
|
notifyListenersOfChanges(changeSet);
|
||||||
|
notifyListenersOfPostChangeEvents(changeSet);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e, e);
|
||||||
|
abortTransaction(sdbConn);
|
||||||
|
throw new RDFServiceException(e);
|
||||||
|
} finally {
|
||||||
|
close(sdbConn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SDBConnection getSDBConnection() throws RDFServiceException {
|
||||||
|
try {
|
||||||
|
Connection c = (conn != null) ? conn : ds.getConnection();
|
||||||
|
return new SDBConnection(c);
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
log.error(sqle, sqle);
|
log.error(sqle, sqle);
|
||||||
throw new RDFServiceException(sqle);
|
throw new RDFServiceException(sqle);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dataset dataset = getDataset(conn);
|
|
||||||
boolean transaction = conn.getTransactionHandler().transactionsSupported();
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
if (transaction) {
|
|
||||||
conn.getTransactionHandler().begin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Object o : changeSet.getPreChangeEvents()) {
|
private void close(SDBConnection sdbConn) {
|
||||||
this.notifyListenersOfEvent(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<ModelChange> csIt = changeSet.getModelChanges().iterator();
|
|
||||||
while (csIt.hasNext()) {
|
|
||||||
ModelChange modelChange = csIt.next();
|
|
||||||
if (!modelChange.getSerializedModel().markSupported()) {
|
|
||||||
byte[] bytes = IOUtils.toByteArray(modelChange.getSerializedModel());
|
|
||||||
modelChange.setSerializedModel(new ByteArrayInputStream(bytes));
|
|
||||||
}
|
|
||||||
modelChange.getSerializedModel().mark(Integer.MAX_VALUE);
|
|
||||||
dataset.getLock().enterCriticalSection(Lock.WRITE);
|
|
||||||
try {
|
|
||||||
Model model = (modelChange.getGraphURI() == null)
|
|
||||||
? dataset.getDefaultModel()
|
|
||||||
: dataset.getNamedModel(modelChange.getGraphURI());
|
|
||||||
operateOnModel(model, modelChange, dataset);
|
|
||||||
} finally {
|
|
||||||
dataset.getLock().leaveCriticalSection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transaction) {
|
|
||||||
conn.getTransactionHandler().commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// notify listeners of triple changes
|
|
||||||
csIt = changeSet.getModelChanges().iterator();
|
|
||||||
while (csIt.hasNext()) {
|
|
||||||
ModelChange modelChange = csIt.next();
|
|
||||||
modelChange.getSerializedModel().reset();
|
|
||||||
Model model = ModelFactory.createModelForGraph(
|
|
||||||
new ListeningGraph(modelChange.getGraphURI(), this));
|
|
||||||
operateOnModel(model, modelChange, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Object o : changeSet.getPostChangeEvents()) {
|
|
||||||
this.notifyListenersOfEvent(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e, e);
|
|
||||||
if (transaction) {
|
|
||||||
conn.getTransactionHandler().abort();
|
|
||||||
}
|
|
||||||
throw new RDFServiceException(e);
|
|
||||||
} finally {
|
|
||||||
close(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Connection getConnection() throws SQLException {
|
|
||||||
return (conn != null) ? conn : ds.getConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void close(SDBConnection sdbConn) {
|
|
||||||
if (!sdbConn.getSqlConnection().equals(conn)) {
|
if (!sdbConn.getSqlConnection().equals(conn)) {
|
||||||
sdbConn.close();
|
sdbConn.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Dataset getDataset(SDBConnection conn) {
|
private Dataset getDataset(SDBConnection sdbConn) {
|
||||||
Store store = SDBFactory.connectStore(conn, storeDesc);
|
Store store = SDBFactory.connectStore(sdbConn, storeDesc);
|
||||||
store.getLoader().setUseThreading(false);
|
store.getLoader().setUseThreading(false);
|
||||||
return SDBFactory.connectDataset(store);
|
return SDBFactory.connectDataset(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void beginTransaction(SDBConnection sdbConn) {
|
||||||
|
if (sdbConn.getTransactionHandler().transactionsSupported()) {
|
||||||
|
sdbConn.getTransactionHandler().begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void commitTransaction(SDBConnection sdbConn) {
|
||||||
|
if (sdbConn.getTransactionHandler().transactionsSupported()) {
|
||||||
|
sdbConn.getTransactionHandler().commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void abortTransaction(SDBConnection sdbConn) {
|
||||||
|
if (sdbConn.getTransactionHandler().transactionsSupported()) {
|
||||||
|
sdbConn.getTransactionHandler().abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final Pattern OPTIONAL_PATTERN = Pattern.compile("optional", Pattern.CASE_INSENSITIVE);
|
private static final Pattern OPTIONAL_PATTERN = Pattern.compile("optional", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
private static final Pattern GRAPH_PATTERN = Pattern.compile("graph", Pattern.CASE_INSENSITIVE);
|
private static final Pattern GRAPH_PATTERN = Pattern.compile("graph", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
public class RDFServiceFactoryTDB implements RDFServiceFactory {
|
||||||
|
private static final Log log = LogFactory
|
||||||
|
.getLog(RDFServiceFactoryTDB.class);
|
||||||
|
|
||||||
|
|
||||||
|
private final RDFServiceTDB service;
|
||||||
|
|
||||||
|
public RDFServiceFactoryTDB(String directoryPath) throws IOException {
|
||||||
|
this.service = new RDFServiceTDB(directoryPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RDFService getRDFService() {
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RDFService getShortTermRDFService() {
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerListener(ChangeListener changeListener)
|
||||||
|
throws RDFServiceException {
|
||||||
|
service.registerListener(changeListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unregisterListener(ChangeListener changeListener)
|
||||||
|
throws RDFServiceException {
|
||||||
|
service.unregisterListener(changeListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
|
import com.hp.hpl.jena.tdb.TDB;
|
||||||
|
import com.hp.hpl.jena.tdb.TDBFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.RDFServiceJena;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
public class RDFServiceTDB extends RDFServiceJena {
|
||||||
|
private static final Log log = LogFactory.getLog(RDFServiceTDB.class);
|
||||||
|
|
||||||
|
private final Dataset dataset;
|
||||||
|
|
||||||
|
public RDFServiceTDB(String directoryPath) throws IOException {
|
||||||
|
Path tdbDir = Paths.get(directoryPath);
|
||||||
|
|
||||||
|
if (!Files.exists(tdbDir)) {
|
||||||
|
Path parentDir = tdbDir.getParent();
|
||||||
|
if (!Files.exists(parentDir)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Cannot create TDB directory '" + tdbDir
|
||||||
|
+ "': parent directory does not exist.");
|
||||||
|
}
|
||||||
|
Files.createDirectory(tdbDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dataset = TDBFactory.createDataset(directoryPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DatasetWrapper getDatasetWrapper() {
|
||||||
|
return new DatasetWrapper(dataset);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean changeSetUpdate(ChangeSet changeSet)
|
||||||
|
throws RDFServiceException {
|
||||||
|
|
||||||
|
if (changeSet.getPreconditionQuery() != null
|
||||||
|
&& !isPreconditionSatisfied(changeSet.getPreconditionQuery(),
|
||||||
|
changeSet.getPreconditionQueryType())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
insureThatInputStreamsAreResettable(changeSet);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Change Set: " + changeSet);
|
||||||
|
}
|
||||||
|
notifyListenersOfPreChangeEvents(changeSet);
|
||||||
|
|
||||||
|
applyChangeSetToModel(changeSet, dataset);
|
||||||
|
TDB.sync(dataset);
|
||||||
|
|
||||||
|
notifyListenersOfChanges(changeSet);
|
||||||
|
notifyListenersOfPostChangeEvents(changeSet);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e, e);
|
||||||
|
throw new RDFServiceException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,117 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
import javax.servlet.ServletContextListener;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setups the Application Configuration TBox and ABox. This is sometimes
|
|
||||||
* called the display model.
|
|
||||||
*
|
|
||||||
* @author bdc34
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ApplicationModelSetup extends JenaDataSourceSetupBase
|
|
||||||
implements ServletContextListener {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(
|
|
||||||
ApplicationModelSetup.class.getName());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup the application configuration model. It is frequently called the
|
|
||||||
* display model. If this is a new DB, populate the display model with the
|
|
||||||
* initial data.
|
|
||||||
*
|
|
||||||
* Also load any files that get loaded to the display model at each tomcat
|
|
||||||
* startup.
|
|
||||||
*
|
|
||||||
* Also, at each start of tomcat, load The display TBox and the
|
|
||||||
* display/display model.
|
|
||||||
*/
|
|
||||||
private void setupDisplayModel(DataSource bds, ServletContext ctx,
|
|
||||||
StartupStatus ss) {
|
|
||||||
|
|
||||||
// display, editing and navigation Model
|
|
||||||
try {
|
|
||||||
Model displayDbModel = makeDBModel(bds,
|
|
||||||
JENA_DISPLAY_METADATA_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
|
||||||
RDFFilesLoader.loadFirstTimeFiles(ctx, "display", displayDbModel, displayDbModel.isEmpty());
|
|
||||||
|
|
||||||
OntModel displayModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
|
||||||
displayModel.add(displayDbModel);
|
|
||||||
displayModel.getBaseModel().register(new ModelSynchronizer(displayDbModel));
|
|
||||||
ModelAccess.on(ctx).setDisplayModel(displayModel);
|
|
||||||
|
|
||||||
//at each startup load all RDF files from directory to sub-models of display model
|
|
||||||
RDFFilesLoader.loadEveryTimeFiles(ctx, "display", displayModel);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
log.error("Unable to load user application configuration model", t);
|
|
||||||
ss.fatal(this, "Unable to load user application configuration model", t);
|
|
||||||
}
|
|
||||||
|
|
||||||
//display tbox - currently reading in every time
|
|
||||||
try {
|
|
||||||
Model displayTboxModel = makeDBModel(bds,
|
|
||||||
JENA_DISPLAY_TBOX_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
|
||||||
|
|
||||||
OntModel appTBOXModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
|
||||||
appTBOXModel.add(displayTboxModel);
|
|
||||||
appTBOXModel.getBaseModel().register(new ModelSynchronizer(displayTboxModel));
|
|
||||||
ModelAccess.on(ctx).setOntModel(ModelID.DISPLAY_TBOX, appTBOXModel);
|
|
||||||
|
|
||||||
//Reading in every time, needs to be cleared/removed every time
|
|
||||||
RDFFilesLoader.loadEveryTimeFiles(ctx, "displayTbox", appTBOXModel);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
log.error("Unable to load user application configuration model TBOX", t);
|
|
||||||
ss.fatal(this, "Unable to load user application configuration model TBOX", t);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Display Display model, currently reading in every time
|
|
||||||
try {
|
|
||||||
Model displayDisplayModel = makeDBModel(bds,
|
|
||||||
JENA_DISPLAY_DISPLAY_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
|
||||||
|
|
||||||
OntModel appDisplayDisplayModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
|
||||||
appDisplayDisplayModel.add(displayDisplayModel);
|
|
||||||
appDisplayDisplayModel.getBaseModel().register(new ModelSynchronizer(displayDisplayModel));
|
|
||||||
ModelAccess.on(ctx).setOntModel(ModelID.DISPLAY_DISPLAY, appDisplayDisplayModel);
|
|
||||||
|
|
||||||
//Reading in every time, needs to be cleared/removed every time
|
|
||||||
RDFFilesLoader.loadEveryTimeFiles(ctx, "displayDisplay", appDisplayDisplayModel);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
log.error("Unable to load user application configuration model Display Model", t);
|
|
||||||
ss.fatal(this, "Unable to load user application configuration model Display Model", t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contextDestroyed(ServletContextEvent arg0) {
|
|
||||||
// does nothing.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
|
||||||
ServletContext ctx = sce.getServletContext();
|
|
||||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
|
||||||
DataSource bds = getApplicationDataSource(ctx);
|
|
||||||
|
|
||||||
setupDisplayModel(bds, ctx, ss);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService.CONFIGURATION;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the models that use the CONFIGURATION RDFService. They are all mapped
|
||||||
|
* to memory-based models.
|
||||||
|
*
|
||||||
|
* TODO This should be divorced from JenaDataSourceSetupBase, which it only uses
|
||||||
|
* for constants.
|
||||||
|
*/
|
||||||
|
public class ConfigurationModelsSetup extends JenaDataSourceSetupBase implements
|
||||||
|
ServletContextListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
ServletContext ctx = sce.getServletContext();
|
||||||
|
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||||
|
|
||||||
|
try {
|
||||||
|
setupModel(ctx, JENA_DISPLAY_METADATA_MODEL, "display",
|
||||||
|
ModelID.DISPLAY);
|
||||||
|
|
||||||
|
setupModel(ctx, JENA_DISPLAY_TBOX_MODEL, "displayTbox",
|
||||||
|
ModelID.DISPLAY_TBOX);
|
||||||
|
|
||||||
|
setupModel(ctx, JENA_DISPLAY_DISPLAY_MODEL, "displayDisplay",
|
||||||
|
ModelID.DISPLAY_DISPLAY);
|
||||||
|
|
||||||
|
ss.info(this, "Set up the display models.");
|
||||||
|
|
||||||
|
setupModel(ctx, JENA_USER_ACCOUNTS_MODEL, "auth",
|
||||||
|
ModelID.USER_ACCOUNTS);
|
||||||
|
|
||||||
|
ss.info(this, "Set up the user accounts model.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
ss.fatal(this, e.getMessage(), e.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupModel(ServletContext ctx, String modelUri,
|
||||||
|
String modelPath, ModelID modelId) {
|
||||||
|
try {
|
||||||
|
Dataset dataset = getConfigurationModelsDataset(ctx);
|
||||||
|
OntModel baseModel = getNamedOntModel(modelUri, dataset);
|
||||||
|
|
||||||
|
loadFirstTimeFiles(ctx, modelPath, baseModel);
|
||||||
|
loadEveryTimeFiles(ctx, modelPath, baseModel);
|
||||||
|
|
||||||
|
OntModel memoryModel = wrapWithMemoryModel(baseModel);
|
||||||
|
ModelAccess.on(ctx).setOntModel(modelId, memoryModel);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to create the '" + modelPath
|
||||||
|
+ "' model (" + modelUri + ").", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dataset getConfigurationModelsDataset(ServletContext ctx) {
|
||||||
|
RDFServiceFactory factory = RDFServiceUtils.getRDFServiceFactory(ctx,
|
||||||
|
CONFIGURATION);
|
||||||
|
return new RDFServiceDataset(factory.getRDFService());
|
||||||
|
}
|
||||||
|
|
||||||
|
private OntModel getNamedOntModel(String modelUri, Dataset dataset) {
|
||||||
|
Model model = dataset.getNamedModel(modelUri);
|
||||||
|
return VitroModelFactory.createOntologyModel(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadFirstTimeFiles(ServletContext ctx, String modelPath,
|
||||||
|
OntModel baseModel) {
|
||||||
|
RDFFilesLoader.loadFirstTimeFiles(ctx, modelPath, baseModel,
|
||||||
|
baseModel.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private OntModel wrapWithMemoryModel(OntModel baseModel) {
|
||||||
|
OntModel memoryModel = VitroModelFactory.createOntologyModel();
|
||||||
|
memoryModel.add(baseModel);
|
||||||
|
memoryModel.getBaseModel().register(new ModelSynchronizer(baseModel));
|
||||||
|
return memoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadEveryTimeFiles(ServletContext ctx, String modelPath,
|
||||||
|
OntModel memoryModel) {
|
||||||
|
RDFFilesLoader.loadEveryTimeFiles(ctx, modelPath, memoryModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextDestroyed(ServletContextEvent arg0) {
|
||||||
|
// Nothing to tear down.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,13 +13,9 @@ import javax.servlet.ServletContextEvent;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ResIterator;
|
import com.hp.hpl.jena.rdf.model.ResIterator;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
@ -36,10 +32,10 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SpecialBulkUpdateHandlerGraph;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
|
@ -77,8 +73,8 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
OntModel inferenceABoxModel = createNamedModelFromDataset(dataset, JENA_INF_MODEL);
|
OntModel inferenceABoxModel = createNamedModelFromDataset(dataset, JENA_INF_MODEL);
|
||||||
OntModel baseTBoxModel = createdMemoryMappedModel(dataset, JENA_TBOX_ASSERTIONS_MODEL, "tbox assertions");
|
OntModel baseTBoxModel = createdMemoryMappedModel(dataset, JENA_TBOX_ASSERTIONS_MODEL, "tbox assertions");
|
||||||
OntModel inferenceTBoxModel = createdMemoryMappedModel(dataset, JENA_TBOX_INF_MODEL, "tbox inferences");
|
OntModel inferenceTBoxModel = createdMemoryMappedModel(dataset, JENA_TBOX_INF_MODEL, "tbox inferences");
|
||||||
OntModel unionABoxModel = createCombinedBulkUpdatingModel(baseABoxModel, inferenceABoxModel);
|
OntModel unionABoxModel = VitroModelFactory.createUnion(baseABoxModel, inferenceABoxModel);
|
||||||
OntModel unionTBoxModel = createCombinedBulkUpdatingModel(baseTBoxModel, inferenceTBoxModel);
|
OntModel unionTBoxModel = VitroModelFactory.createUnion(baseTBoxModel, inferenceTBoxModel);
|
||||||
|
|
||||||
|
|
||||||
if (isFirstStartup()) {
|
if (isFirstStartup()) {
|
||||||
|
@ -92,9 +88,9 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
RDFFilesLoader.loadEveryTimeFiles(ctx, "tbox", baseTBoxModel);
|
RDFFilesLoader.loadEveryTimeFiles(ctx, "tbox", baseTBoxModel);
|
||||||
|
|
||||||
log.info("Setting up full models");
|
log.info("Setting up full models");
|
||||||
OntModel baseFullModel = createCombinedBulkUpdatingModel(baseABoxModel, baseTBoxModel);
|
OntModel baseFullModel = VitroModelFactory.createUnion(baseABoxModel, baseTBoxModel);
|
||||||
OntModel inferenceFullModel = createCombinedModel(inferenceABoxModel, inferenceTBoxModel);
|
OntModel inferenceFullModel = VitroModelFactory.createUnion(inferenceABoxModel, inferenceTBoxModel);
|
||||||
OntModel unionFullModel = ModelFactory.createOntologyModel(DB_ONT_MODEL_SPEC, dataset.getDefaultModel());
|
OntModel unionFullModel = VitroModelFactory.createOntologyModel(dataset.getDefaultModel());
|
||||||
|
|
||||||
models.setOntModel(ModelID.APPLICATION_METADATA, applicationMetadataModel);
|
models.setOntModel(ModelID.APPLICATION_METADATA, applicationMetadataModel);
|
||||||
|
|
||||||
|
@ -130,13 +126,13 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
}
|
}
|
||||||
|
|
||||||
private OntModel createNamedModelFromDataset(Dataset dataset, String name) {
|
private OntModel createNamedModelFromDataset(Dataset dataset, String name) {
|
||||||
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, dataset.getNamedModel(name));
|
return VitroModelFactory.createOntologyModel(dataset.getNamedModel(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private OntModel createdMemoryMappedModel(Dataset dataset, String name, String label) {
|
private OntModel createdMemoryMappedModel(Dataset dataset, String name, String label) {
|
||||||
try {
|
try {
|
||||||
Model dbModel = dataset.getNamedModel(name);
|
Model dbModel = dataset.getNamedModel(name);
|
||||||
OntModel memoryModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel memoryModel = VitroModelFactory.createOntologyModel();
|
||||||
|
|
||||||
if (dbModel != null) {
|
if (dbModel != null) {
|
||||||
long begin = System.currentTimeMillis();
|
long begin = System.currentTimeMillis();
|
||||||
|
@ -151,20 +147,6 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private OntModel createCombinedModel(OntModel oneModel, OntModel otherModel) {
|
|
||||||
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
|
||||||
ModelFactory.createUnion(oneModel, otherModel));
|
|
||||||
}
|
|
||||||
|
|
||||||
private OntModel createCombinedBulkUpdatingModel(OntModel baseModel,
|
|
||||||
OntModel otherModel) {
|
|
||||||
BulkUpdateHandler bulkUpdateHandler = baseModel.getGraph().getBulkUpdateHandler();
|
|
||||||
Graph unionGraph = ModelFactory.createUnion(baseModel, otherModel).getGraph();
|
|
||||||
Model unionModel = ModelFactory.createModelForGraph(
|
|
||||||
new SpecialBulkUpdateHandlerGraph(unionGraph, bulkUpdateHandler));
|
|
||||||
return ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC, unionModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private long secondsSince(long startTime) {
|
private long secondsSince(long startTime) {
|
||||||
return (System.currentTimeMillis() - startTime) / 1000;
|
return (System.currentTimeMillis() - startTime) / 1000;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +162,7 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
*/
|
*/
|
||||||
private void initializeApplicationMetadata(ServletContext ctx,
|
private void initializeApplicationMetadata(ServletContext ctx,
|
||||||
OntModel applicationMetadataModel) {
|
OntModel applicationMetadataModel) {
|
||||||
OntModel temporaryAMModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel temporaryAMModel = VitroModelFactory.createOntologyModel();
|
||||||
RDFFilesLoader.loadFirstTimeFiles(ctx, "applicationMetadata", temporaryAMModel, true);
|
RDFFilesLoader.loadFirstTimeFiles(ctx, "applicationMetadata", temporaryAMModel, true);
|
||||||
setPortalUriOnFirstTime(temporaryAMModel, ctx);
|
setPortalUriOnFirstTime(temporaryAMModel, ctx);
|
||||||
applicationMetadataModel.add(temporaryAMModel);
|
applicationMetadataModel.add(temporaryAMModel);
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONFIGURATION;
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONTENT;
|
|
||||||
|
|
||||||
import java.beans.PropertyVetoException;
|
import java.beans.PropertyVetoException;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
@ -15,32 +12,15 @@ import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.query.Query;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
|
||||||
import com.hp.hpl.jena.query.QueryFactory;
|
|
||||||
import com.hp.hpl.jena.query.Syntax;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
|
||||||
import com.hp.hpl.jena.sdb.Store;
|
import com.hp.hpl.jena.sdb.Store;
|
||||||
import com.hp.hpl.jena.sdb.StoreDesc;
|
import com.hp.hpl.jena.sdb.StoreDesc;
|
||||||
import com.hp.hpl.jena.sdb.store.DatabaseType;
|
|
||||||
import com.hp.hpl.jena.sdb.store.LayoutType;
|
|
||||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDaoCon;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDaoCon;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDBGraphGenerator;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RegeneratingGraph;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SDBGraphGenerator;
|
|
||||||
|
|
||||||
public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
private static final String VITRO_DEFAULT_NAMESPACE = "Vitro.defaultNamespace";
|
private static final String VITRO_DEFAULT_NAMESPACE = "Vitro.defaultNamespace";
|
||||||
|
@ -142,39 +122,13 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
|
|
||||||
return jdbcUrl;
|
return jdbcUrl;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets up a Model and DB connection using values from
|
|
||||||
* a properties file.
|
|
||||||
*/
|
|
||||||
public final Model makeDBModelFromConfigurationProperties(
|
|
||||||
String jenaDbModelName,
|
|
||||||
OntModelSpec jenaDbOntModelSpec, ServletContext ctx) {
|
|
||||||
|
|
||||||
String jdbcUrl = getJdbcUrl(ctx);
|
|
||||||
|
|
||||||
String username = ConfigurationProperties.getBean(ctx).getProperty(
|
|
||||||
"VitroConnection.DataSource.username");
|
|
||||||
String password = ConfigurationProperties.getBean(ctx).getProperty(
|
|
||||||
"VitroConnection.DataSource.password");
|
|
||||||
DataSource ds = makeC3poDataSource(
|
|
||||||
getDbDriverClassName(ctx), jdbcUrl, username, password, ctx);
|
|
||||||
// DataSource ds = makeBasicDataSource(
|
|
||||||
// getDbDriverClassName(ctx), jdbcUrl, username, password, ctx);
|
|
||||||
jenaDbOntModelSpec = (jenaDbOntModelSpec != null)
|
|
||||||
? jenaDbOntModelSpec
|
|
||||||
: DB_ONT_MODEL_SPEC;
|
|
||||||
|
|
||||||
return makeDBModel(ds, jenaDbModelName, jenaDbOntModelSpec, ctx);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up a DataSource using values from
|
* Sets up a DataSource using values from
|
||||||
* a properties file.
|
* a properties file.
|
||||||
*/
|
*/
|
||||||
public final DataSource makeDataSourceFromConfigurationProperties(
|
protected final DataSource makeDataSourceFromConfigurationProperties(
|
||||||
ServletContext ctx) {
|
ServletContext ctx) {
|
||||||
String dbDriverClassname = ConfigurationProperties.getBean(ctx)
|
String dbDriverClassname = ConfigurationProperties.getBean(ctx)
|
||||||
.getProperty("VitroConnection.DataSource.driver",
|
.getProperty("VitroConnection.DataSource.driver",
|
||||||
|
@ -303,10 +257,6 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum TripleStoreType {
|
|
||||||
RDB, SDB
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isFirstStartup() {
|
public static boolean isFirstStartup() {
|
||||||
return firstStartup;
|
return firstStartup;
|
||||||
}
|
}
|
||||||
|
@ -315,67 +265,6 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
firstStartup = true;
|
firstStartup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Model makeDBModel(DataSource ds,
|
|
||||||
String jenaDbModelname,
|
|
||||||
OntModelSpec jenaDbOntModelSpec,
|
|
||||||
ServletContext ctx) {
|
|
||||||
return makeDBModel(
|
|
||||||
ds, jenaDbModelname, jenaDbOntModelSpec, TripleStoreType.RDB, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Model makeDBModel(DataSource ds,
|
|
||||||
String jenaDbModelName,
|
|
||||||
OntModelSpec jenaDbOntModelSpec,
|
|
||||||
TripleStoreType storeType, ServletContext ctx) {
|
|
||||||
return makeDBModel (ds, jenaDbModelName, jenaDbOntModelSpec, storeType,
|
|
||||||
getDbType(ctx), ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Model makeDBModel(DataSource ds,
|
|
||||||
String jenaDbModelName,
|
|
||||||
OntModelSpec jenaDbOntModelSpec,
|
|
||||||
TripleStoreType storeType, String dbType,
|
|
||||||
ServletContext ctx) {
|
|
||||||
Model dbModel = null;
|
|
||||||
try {
|
|
||||||
// open the db model
|
|
||||||
try {
|
|
||||||
Graph g = null;
|
|
||||||
switch (storeType) {
|
|
||||||
case RDB:
|
|
||||||
g = new RegeneratingGraph(
|
|
||||||
new RDBGraphGenerator(
|
|
||||||
ds, dbType, jenaDbModelName));
|
|
||||||
break;
|
|
||||||
case SDB:
|
|
||||||
String layoutStr = ConfigurationProperties.getBean(ctx)
|
|
||||||
.getProperty(
|
|
||||||
"VitroConnection.DataSource.sdb.layout",
|
|
||||||
"layout2/hash");
|
|
||||||
String dbtypeStr = ConfigurationProperties.getBean(ctx)
|
|
||||||
.getProperty("VitroConnection.DataSource.dbtype",
|
|
||||||
"MySQL");
|
|
||||||
StoreDesc desc = new StoreDesc(
|
|
||||||
LayoutType.fetch(layoutStr),
|
|
||||||
DatabaseType.fetch(dbtypeStr) );
|
|
||||||
g = new RegeneratingGraph(
|
|
||||||
new SDBGraphGenerator(
|
|
||||||
ds, desc, jenaDbModelName));
|
|
||||||
break;
|
|
||||||
default: throw new RuntimeException (
|
|
||||||
"Unsupported store type " + storeType);
|
|
||||||
}
|
|
||||||
dbModel = ModelFactory.createModelForGraph(g);
|
|
||||||
//log.debug("Using database at " + ds.getUrl());
|
|
||||||
} catch (Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
|
||||||
return dbModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getDefaultNamespace(ServletContext ctx) {
|
protected String getDefaultNamespace(ServletContext ctx) {
|
||||||
String dns = ConfigurationProperties.getBean(ctx).getProperty(
|
String dns = ConfigurationProperties.getBean(ctx).getProperty(
|
||||||
VITRO_DEFAULT_NAMESPACE);
|
VITRO_DEFAULT_NAMESPACE);
|
||||||
|
@ -388,7 +277,7 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getDbType(ServletContext ctx) {
|
private static String getDbType(ServletContext ctx) {
|
||||||
return ConfigurationProperties.getBean(ctx).getProperty( // database type
|
return ConfigurationProperties.getBean(ctx).getProperty(
|
||||||
"VitroConnection.DataSource.dbtype", "MySQL");
|
"VitroConnection.DataSource.dbtype", "MySQL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,50 +301,6 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
return (o instanceof Dataset) ? ((Dataset) o) : null;
|
return (o instanceof Dataset) ? ((Dataset) o) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected OntModel ontModelFromContextAttribute(ServletContext ctx,
|
|
||||||
String attribute) {
|
|
||||||
OntModel ontModel;
|
|
||||||
Object attributeValue = ctx.getAttribute(attribute);
|
|
||||||
if (attributeValue != null && attributeValue instanceof OntModel) {
|
|
||||||
ontModel = (OntModel) attributeValue;
|
|
||||||
} else {
|
|
||||||
ontModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
|
||||||
ctx.setAttribute(attribute, ontModel);
|
|
||||||
}
|
|
||||||
return ontModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void repairAppMetadataModel(Model applicationMetadataModel,
|
|
||||||
Model aboxAssertions,
|
|
||||||
Model aboxInferences) {
|
|
||||||
|
|
||||||
log.info("Moving application metadata from ABox to dedicated model");
|
|
||||||
getAppMetadata(aboxAssertions, applicationMetadataModel);
|
|
||||||
getAppMetadata(aboxInferences, applicationMetadataModel);
|
|
||||||
aboxAssertions.remove(applicationMetadataModel);
|
|
||||||
aboxInferences.remove(applicationMetadataModel);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void getAppMetadata(Model source, Model target) {
|
|
||||||
|
|
||||||
String amdQuery = "DESCRIBE ?x WHERE { " +
|
|
||||||
"{?x a <" + VitroVocabulary.PORTAL +"> } UNION " +
|
|
||||||
"{?x a <" + VitroVocabulary.PROPERTYGROUP +"> } UNION " +
|
|
||||||
"{?x a <" + VitroVocabulary.CLASSGROUP +"> } } ";
|
|
||||||
|
|
||||||
try {
|
|
||||||
Query q = QueryFactory.create(amdQuery, Syntax.syntaxARQ);
|
|
||||||
QueryExecution qe = QueryExecutionFactory.create(q, source);
|
|
||||||
qe.execDescribe(target);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("unable to create the application metadata model",e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String STOREDESC_ATTR = "storeDesc";
|
private static final String STOREDESC_ATTR = "storeDesc";
|
||||||
private static final String STORE_ATTR = "kbStore";
|
private static final String STORE_ATTR = "kbStore";
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,29 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.APPLICATION_METADATA;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.BASE_FULL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.BASE_TBOX;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.DISPLAY;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.DISPLAY_DISPLAY;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.DISPLAY_TBOX;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.INFERRED_FULL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.INFERRED_TBOX;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.UNION_FULL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.USER_ACCOUNTS;
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONFIGURATION;
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONFIGURATION;
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONTENT;
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONTENT;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_DISPLAY_DISPLAY_MODEL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_DISPLAY_METADATA_MODEL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_DISPLAY_TBOX_MODEL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_USER_ACCOUNTS_MODEL;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
|
@ -11,13 +32,14 @@ import javax.servlet.ServletContextEvent;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroInterceptingModelMaker;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroInterceptingModelMaker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,31 +57,62 @@ public class ModelMakerSetup extends JenaDataSourceSetupBase implements
|
||||||
createConfigurationModelMaker(ctx);
|
createConfigurationModelMaker(ctx);
|
||||||
createContentModelMaker(ctx);
|
createContentModelMaker(ctx);
|
||||||
|
|
||||||
ss.info(this, "Created model makers and model source");
|
ss.info(this, "Created model makers.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createConfigurationModelMaker(ServletContext ctx) {
|
private void createConfigurationModelMaker(ServletContext ctx) {
|
||||||
String jdbcUrl = getJdbcUrl(ctx);
|
RDFServiceFactory rdfServiceFactory = RDFServiceUtils
|
||||||
String dbtypeStr = ConfigurationProperties.getBean(ctx).getProperty(
|
.getRDFServiceFactory(ctx, WhichService.CONFIGURATION);
|
||||||
"VitroConnection.DataSource.dbtype", "MySQL");
|
RDFServiceModelMaker configMM = new RDFServiceModelMaker(
|
||||||
String username = ConfigurationProperties.getBean(ctx).getProperty(
|
rdfServiceFactory);
|
||||||
"VitroConnection.DataSource.username");
|
Map<String, Model> specials = populateConfigurationSpecialMap(ctx);
|
||||||
String password = ConfigurationProperties.getBean(ctx).getProperty(
|
VitroInterceptingModelMaker viMM = new VitroInterceptingModelMaker(
|
||||||
"VitroConnection.DataSource.password");
|
configMM, specials);
|
||||||
VitroJenaModelMaker vjmm = new VitroJenaModelMaker(jdbcUrl, username,
|
ModelAccess.on(ctx).setModelMaker(CONFIGURATION, viMM);
|
||||||
password, dbtypeStr, ctx);
|
|
||||||
VitroInterceptingModelMaker vimm = new VitroInterceptingModelMaker(
|
|
||||||
vjmm, ctx);
|
|
||||||
ModelAccess.on(ctx).setModelMaker(CONFIGURATION, vimm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createContentModelMaker(ServletContext ctx) {
|
private void createContentModelMaker(ServletContext ctx) {
|
||||||
RDFServiceFactory rdfServiceFactory = RDFServiceUtils
|
RDFServiceFactory rdfServiceFactory = RDFServiceUtils
|
||||||
.getRDFServiceFactory(ctx);
|
.getRDFServiceFactory(ctx);
|
||||||
RDFServiceModelMaker vsmm = new RDFServiceModelMaker(rdfServiceFactory);
|
RDFServiceModelMaker contentMM = new RDFServiceModelMaker(
|
||||||
VitroInterceptingModelMaker vimm = new VitroInterceptingModelMaker(
|
rdfServiceFactory);
|
||||||
vsmm, ctx);
|
Map<String, Model> specials = populateContentSpecialMap(ctx);
|
||||||
ModelAccess.on(ctx).setModelMaker(CONTENT, vimm);
|
VitroInterceptingModelMaker viMM = new VitroInterceptingModelMaker(
|
||||||
|
contentMM, specials);
|
||||||
|
ModelAccess.on(ctx).setModelMaker(CONTENT, viMM);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Model> populateConfigurationSpecialMap(
|
||||||
|
ServletContext ctx) {
|
||||||
|
Map<String, Model> map = new HashMap<>();
|
||||||
|
map.put(JENA_DISPLAY_METADATA_MODEL,
|
||||||
|
ModelAccess.on(ctx).getOntModel(DISPLAY));
|
||||||
|
map.put(JENA_DISPLAY_TBOX_MODEL,
|
||||||
|
ModelAccess.on(ctx).getOntModel(DISPLAY_TBOX));
|
||||||
|
map.put(JENA_DISPLAY_DISPLAY_MODEL,
|
||||||
|
ModelAccess.on(ctx).getOntModel(DISPLAY_DISPLAY));
|
||||||
|
map.put(JENA_USER_ACCOUNTS_MODEL,
|
||||||
|
ModelAccess.on(ctx).getOntModel(USER_ACCOUNTS));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Model> populateContentSpecialMap(ServletContext ctx) {
|
||||||
|
Map<String, Model> map = new HashMap<>();
|
||||||
|
|
||||||
|
map.put("vitro:jenaOntModel",
|
||||||
|
ModelAccess.on(ctx).getOntModel(UNION_FULL));
|
||||||
|
map.put("vitro:baseOntModel", ModelAccess.on(ctx)
|
||||||
|
.getOntModel(BASE_FULL));
|
||||||
|
map.put("vitro:inferenceOntModel",
|
||||||
|
ModelAccess.on(ctx).getOntModel(INFERRED_FULL));
|
||||||
|
map.put(JENA_TBOX_ASSERTIONS_MODEL,
|
||||||
|
ModelAccess.on(ctx).getOntModel(BASE_TBOX));
|
||||||
|
map.put(JENA_TBOX_INF_MODEL,
|
||||||
|
ModelAccess.on(ctx).getOntModel(INFERRED_TBOX));
|
||||||
|
map.put(JENA_APPLICATION_METADATA_MODEL, ModelAccess.on(ctx)
|
||||||
|
.getOntModel(APPLICATION_METADATA));
|
||||||
|
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService.CONFIGURATION;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
@ -25,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.sdb.RDFServiceFactorySDB;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.sdb.RDFServiceFactorySDB;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb.RDFServiceFactoryTDB;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql.RDFServiceSparql;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql.RDFServiceSparql;
|
||||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
|
@ -56,11 +61,21 @@ implements javax.servlet.ServletContextListener {
|
||||||
//RDFServiceFactory factory = RDFServiceUtils.getRDFServiceFactory(ctx);
|
//RDFServiceFactory factory = RDFServiceUtils.getRDFServiceFactory(ctx);
|
||||||
//RDFServiceUtils.setRDFServiceFactory(ctx, new SameAsFilteringRDFServiceFactory(factory));
|
//RDFServiceUtils.setRDFServiceFactory(ctx, new SameAsFilteringRDFServiceFactory(factory));
|
||||||
|
|
||||||
} catch (SQLException e) {
|
useTDBForConfigurationModels(ctx);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
ss.fatal(this, "Exception in RDFServiceSetup", e);
|
ss.fatal(this, "Exception in RDFServiceSetup", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void useTDBForConfigurationModels(ServletContext ctx) throws IOException {
|
||||||
|
String vitroHome = ConfigurationProperties.getBean(ctx).getProperty(
|
||||||
|
"vitro.home") ;
|
||||||
|
String directoryPath = vitroHome + File.separatorChar + "tdbModels";
|
||||||
|
RDFServiceFactory factory = new RDFServiceFactoryTDB(directoryPath);
|
||||||
|
RDFServiceUtils.setRDFServiceFactory(ctx, factory, CONFIGURATION);
|
||||||
|
}
|
||||||
|
|
||||||
private void useEndpoint(String endpointURI, String updateEndpointURI, ServletContext ctx) {
|
private void useEndpoint(String endpointURI, String updateEndpointURI, ServletContext ctx) {
|
||||||
|
|
||||||
RDFService rdfService = null;
|
RDFService rdfService = null;
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
}
|
}
|
||||||
// reload the display model since the TBoxUpdater may have
|
// reload the display model since the TBoxUpdater may have
|
||||||
// modified it
|
// modified it
|
||||||
new ApplicationModelSetup().contextInitialized(sce);
|
new ConfigurationModelsSetup().contextInitialized(sce);
|
||||||
} catch (Exception ioe) {
|
} catch (Exception ioe) {
|
||||||
ss.fatal(this, "Exception updating knowledge base for ontology changes: ", ioe);
|
ss.fatal(this, "Exception updating knowledge base for ontology changes: ", ioe);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
import javax.servlet.ServletContextListener;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup the user account model. If it does not exist in the database, create
|
|
||||||
* and populate it.
|
|
||||||
*/
|
|
||||||
public class UserModelSetup extends JenaDataSourceSetupBase implements
|
|
||||||
ServletContextListener {
|
|
||||||
private static final Log log = LogFactory.getLog(UserModelSetup.class
|
|
||||||
.getName());
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
|
||||||
ServletContext ctx = sce.getServletContext();
|
|
||||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
|
||||||
|
|
||||||
DataSource bds = getApplicationDataSource(ctx);
|
|
||||||
if (bds == null) {
|
|
||||||
ss.fatal(
|
|
||||||
this,
|
|
||||||
"A DataSource must be setup before ModelSetup "
|
|
||||||
+ "is run. Make sure that JenaPersistentDataSourceSetup runs before "
|
|
||||||
+ "ModelSetup.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setupUserAccountModel(bds, ctx, ss);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contextDestroyed(ServletContextEvent arg0) {
|
|
||||||
// Does nothing.
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupUserAccountModel(DataSource bds, ServletContext ctx,
|
|
||||||
StartupStatus ss) {
|
|
||||||
try {
|
|
||||||
Model userAccountsDbModel = makeDBModel(bds,
|
|
||||||
JENA_USER_ACCOUNTS_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
|
||||||
OntModel userAccountsModel = ModelFactory
|
|
||||||
.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
|
||||||
|
|
||||||
userAccountsModel.add(userAccountsDbModel);
|
|
||||||
userAccountsModel.getBaseModel().register(
|
|
||||||
new ModelSynchronizer(userAccountsDbModel));
|
|
||||||
|
|
||||||
// This is used in Selenium testing, to load accounts from a file.
|
|
||||||
RDFFilesLoader.loadFirstTimeFiles(ctx, "auth", userAccountsModel,
|
|
||||||
userAccountsDbModel.isEmpty());
|
|
||||||
// This gets the permissions configuration.
|
|
||||||
RDFFilesLoader.loadEveryTimeFiles(ctx, "auth", userAccountsModel);
|
|
||||||
|
|
||||||
ModelAccess.on(ctx).setUserAccountsModel(userAccountsModel);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
log.error("Unable to load user accounts model from DB", t);
|
|
||||||
ss.fatal(this, "Unable to load user accounts model from DB", t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -58,7 +58,7 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
protected boolean isVClass(String vClassUri) {
|
protected boolean isVClass(String vClassUri) {
|
||||||
boolean isVClass = individual.isVClass(vClassUri);
|
boolean isVClass = individual.isVClass(vClassUri);
|
||||||
// If reasoning is asynchronous (under RDB), this inference may not have been made yet.
|
// If reasoning is asynchronous, this inference may not have been made yet.
|
||||||
// Check the superclasses of the individual's vclass.
|
// Check the superclasses of the individual's vclass.
|
||||||
SimpleReasoner simpleReasoner = (SimpleReasoner) ctx.getAttribute(SimpleReasoner.class.getName());
|
SimpleReasoner simpleReasoner = (SimpleReasoner) ctx.getAttribute(SimpleReasoner.class.getName());
|
||||||
if (!isVClass && simpleReasoner != null && simpleReasoner.isABoxReasoningAsynchronous()) {
|
if (!isVClass && simpleReasoner != null && simpleReasoner.isABoxReasoningAsynchronous()) {
|
||||||
|
|
|
@ -121,8 +121,8 @@ public class SparqlQueryApiExecutorTest extends AbstractTestClass {
|
||||||
+ "<http://here.edu/subject> <http://here.edu/predicate> <http://here.edu/object> .\n";
|
+ "<http://here.edu/subject> <http://here.edu/predicate> <http://here.edu/object> .\n";
|
||||||
private static final String CONSTRUCT_RESULT_TURTLE = "" //
|
private static final String CONSTRUCT_RESULT_TURTLE = "" //
|
||||||
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" //
|
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" //
|
||||||
+ "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n" //
|
|
||||||
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" //
|
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" //
|
||||||
|
+ "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n" //
|
||||||
+ "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" //
|
+ "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" //
|
||||||
+ "\n" //
|
+ "\n" //
|
||||||
+ "<http://here.edu/subject>\n" //
|
+ "<http://here.edu/subject>\n" //
|
||||||
|
@ -173,8 +173,8 @@ public class SparqlQueryApiExecutorTest extends AbstractTestClass {
|
||||||
+ " <http://here.edu/object> .\n";
|
+ " <http://here.edu/object> .\n";
|
||||||
private static final String DESCRIBE_RESULT_TURTLE = "" //
|
private static final String DESCRIBE_RESULT_TURTLE = "" //
|
||||||
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" //
|
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" //
|
||||||
+ "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n" //
|
|
||||||
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" //
|
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" //
|
||||||
|
+ "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n" //
|
||||||
+ "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" //
|
+ "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" //
|
||||||
+ "\n" //
|
+ "\n" //
|
||||||
+ "<http://here.edu/subject>\n" //
|
+ "<http://here.edu/subject>\n" //
|
||||||
|
@ -424,7 +424,7 @@ public class SparqlQueryApiExecutorTest extends AbstractTestClass {
|
||||||
rdfService, queryString, acceptHeader);
|
rdfService, queryString, acceptHeader);
|
||||||
executor.executeAndFormat(out);
|
executor.executeAndFormat(out);
|
||||||
|
|
||||||
assertEquals(message, expected, out.toString().replace("\r", ""));
|
assertEquals(message, expected.replaceAll("\\s+", " "), out.toString().replaceAll("\\s+", " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeWithInvalidAcceptHeader(String message,
|
private void executeWithInvalidAcceptHeader(String message,
|
||||||
|
|
|
@ -24,8 +24,7 @@ edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaPersistentDataSourceSetup
|
||||||
|
|
||||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.RDFServiceSetup
|
edu.cornell.mannlib.vitro.webapp.servlet.setup.RDFServiceSetup
|
||||||
|
|
||||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.ApplicationModelSetup
|
edu.cornell.mannlib.vitro.webapp.servlet.setup.ConfigurationModelsSetup
|
||||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.UserModelSetup
|
|
||||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.ContentModelSetup
|
edu.cornell.mannlib.vitro.webapp.servlet.setup.ContentModelSetup
|
||||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.ModelMakerSetup
|
edu.cornell.mannlib.vitro.webapp.servlet.setup.ModelMakerSetup
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function init(){
|
function init(){
|
||||||
var infoLine = document.information.info.value;
|
var modelType = document.ingesting.modelType.value;
|
||||||
if(infoLine == "RDB models"){
|
if(modelType == "CONFIGURATION"){
|
||||||
document.rdbform.submit.disabled="true";
|
document.showConfigurationModelsForm.submit.disabled="true";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
document.sdbform.submit.disabled="true";
|
document.showContentModelsForm.submit.disabled="true";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -27,26 +27,23 @@ function init(){
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<form name="sdbform" action="ingest" method="get">
|
<form name="showContentModelsForm" action="ingest" method="get">
|
||||||
<input type="hidden" name="action" value="sdbModels"/>
|
<input type="hidden" name="action" value="contentModels"/>
|
||||||
<input type="submit" name="submit" value="Main Store Models"/>
|
<input type="submit" name="submit" value="Main Store Models"/>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<form name="rdbform" action="ingest" method="get">
|
<form name="showConfigurationModelsForm" action="ingest" method="get">
|
||||||
<input type="hidden" name="action" value="rdbModels"/>
|
<input type="hidden" name="action" value="configModels"/>
|
||||||
<input type="submit" name="submit" value="RDB Models"/>
|
<input type="submit" name="submit" value="Configuration Models"/>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<form action="ingest" method="get">
|
<form name="ingesting" action="ingest" method="get">
|
||||||
<input type="hidden" name="action" value="createModel"/>
|
<input type="hidden" name="action" value="createModel"/>
|
||||||
<input type="hidden" name="modelType" value="${modelType}"/>
|
<input type="hidden" name="modelType" value="${modelType}"/>
|
||||||
<input type="submit" name="submit" value="Create Model"/>
|
<input type="submit" name="submit" value="Create Model"/>
|
||||||
</form>
|
|
||||||
<form name="information">
|
|
||||||
<input type="hidden" name="info" value="${infoLine}"/>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
Currently showing <font color="red">${infoLine}</font>
|
Currently showing <font color="red">${infoLine}</font>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue