Adding proof of concept SPARQL update VIVO-101
This commit is contained in:
parent
54f79f2ea7
commit
463453111d
6 changed files with 199 additions and 8 deletions
|
@ -9,8 +9,6 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -61,7 +59,10 @@ public class IndexBuilder extends VitroBackgroundThread {
|
|||
|
||||
/** Indicates that a stop of the indexing objects has been requested. */
|
||||
private volatile boolean stopRequested = false;
|
||||
|
||||
|
||||
/** Indicates that new updates should not be started. */
|
||||
private boolean deferNewUpdates = false;
|
||||
|
||||
/** Length of time to wait before looking for work (if not wakened sooner). */
|
||||
public static final long MAX_IDLE_INTERVAL = 1000 * 60 /* msec */ ;
|
||||
|
||||
|
@ -163,7 +164,7 @@ public class IndexBuilder extends VitroBackgroundThread {
|
|||
* This will re-index Individuals were added with addToChanged().
|
||||
*/
|
||||
public synchronized void doUpdateIndex() {
|
||||
log.debug("callto doUpdateIndex()");
|
||||
log.debug("call to doUpdateIndex()");
|
||||
//wake up thread and it will attempt to index anything in changedUris
|
||||
this.notifyAll();
|
||||
}
|
||||
|
@ -184,12 +185,33 @@ public class IndexBuilder extends VitroBackgroundThread {
|
|||
this.notifyAll();
|
||||
this.interrupt();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calling this will cause the IndexBuider to no start a new index update
|
||||
* until unpuase is called. This is intended to allow a large change
|
||||
* without slowing it down with incremental search index updates.
|
||||
*/
|
||||
public synchronized void pause(){
|
||||
this.deferNewUpdates = true;
|
||||
}
|
||||
|
||||
public synchronized void unpause(){
|
||||
if( deferNewUpdates == true ){
|
||||
this.deferNewUpdates = false;
|
||||
this.notifyAll();
|
||||
this.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(! stopRequested ){
|
||||
try{
|
||||
if( reindexRequested ){
|
||||
if ( deferNewUpdates ){
|
||||
log.debug("there is no indexing working to do, waiting for work");
|
||||
synchronized (this) { this.wait(MAX_IDLE_INTERVAL); }
|
||||
}
|
||||
else if ( reindexRequested ){
|
||||
setWorkLevel(WorkLevel.WORKING, FLAG_REBUILDING);
|
||||
log.debug("full re-index requested");
|
||||
|
||||
|
@ -198,7 +220,8 @@ public class IndexBuilder extends VitroBackgroundThread {
|
|||
notifyListeners( IndexingEventListener.EventTypes.FINISH_FULL_REBUILD );
|
||||
|
||||
setWorkLevel(WorkLevel.IDLE);
|
||||
}else{
|
||||
}
|
||||
else{
|
||||
boolean workToDo = false;
|
||||
synchronized (changedStmts ){
|
||||
workToDo = !changedStmts.isEmpty();
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.update.GraphStore;
|
||||
import com.hp.hpl.jena.update.GraphStoreFactory;
|
||||
import com.hp.hpl.jena.update.UpdateAction;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||
|
||||
/**
|
||||
* Test to experement with Jena ARQ SPARQL update and the RDFServiceDataset.
|
||||
*/
|
||||
public class SparqlUpdateTestDataGetter implements DataGetter{
|
||||
private static final Log log = LogFactory.getLog(SparqlUpdateTestDataGetter.class);
|
||||
|
||||
VitroRequest vreq;
|
||||
ServletContext context;
|
||||
|
||||
/**
|
||||
* Constructor with display model and data getter URI that will be called by reflection.
|
||||
*/
|
||||
public SparqlUpdateTestDataGetter(VitroRequest vreq ){
|
||||
if( vreq == null )
|
||||
throw new IllegalArgumentException("VitroRequest may not be null.");
|
||||
this.vreq = vreq;
|
||||
this.context = vreq.getSession().getServletContext();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String,Object> getData( Map<String, Object> valueMap ) {
|
||||
HashMap<String, Object> data = new HashMap<String,Object>();
|
||||
|
||||
String update = vreq.getParameter("update");
|
||||
|
||||
if( update != null && !update.trim().isEmpty()){
|
||||
try{
|
||||
IndexBuilder.getBuilder(context).pause();
|
||||
Dataset ds = new RDFServiceDataset( vreq.getUnfilteredRDFService() );
|
||||
GraphStore graphStore = GraphStoreFactory.create(ds);
|
||||
log.warn("The SPARQL update is '"+vreq.getParameter("update")+"'");
|
||||
UpdateAction.parseExecute( vreq.getParameter("update") , graphStore );
|
||||
}finally{
|
||||
IndexBuilder.getBuilder(context).unpause();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data.put("bodyTemplate", "page-sparqlUpdateTest.ftl");
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
|
@ -63,7 +63,7 @@ public class BrowseDataGetter implements PageDataGetter {
|
|||
return DisplayVocabulary.HOME_PAGE_TYPE;
|
||||
}
|
||||
|
||||
//Get data servuice
|
||||
//Get data service
|
||||
@Override
|
||||
public String getDataServiceUrl() {
|
||||
return UrlBuilder.getUrl("/dataservice?getSolrIndividualsByVClass=1&vclassId=");
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.update.GraphStore;
|
||||
import com.hp.hpl.jena.update.GraphStoreFactory;
|
||||
import com.hp.hpl.jena.update.UpdateAction;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||
|
||||
/**
|
||||
* Test to experement with Jena ARQ SPARQL update and the RDFServiceDataset.
|
||||
*/
|
||||
public class SparqlUpdateTestDataGetter implements PageDataGetter{
|
||||
private static final Log log = LogFactory.getLog(SparqlUpdateTestDataGetter.class);
|
||||
|
||||
@Override
|
||||
public Map<String,Object>
|
||||
getData(ServletContext context,
|
||||
VitroRequest vreq, String pageUri,
|
||||
Map<String, Object> page )
|
||||
{
|
||||
HashMap<String, Object> data = new HashMap<String,Object>();
|
||||
|
||||
Dataset ds = new RDFServiceDataset( vreq.getUnfilteredRDFService() );
|
||||
GraphStore graphStore = GraphStoreFactory.create(ds);
|
||||
|
||||
log.warn("The SPARQL update is '"+vreq.getParameter("update")+"'");
|
||||
|
||||
UpdateAction.parseExecute( vreq.getParameter("update") , graphStore );
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType(){
|
||||
return PageDataGetterUtils.generateDataGetterTypeURI(SparqlUpdateTestDataGetter.class.getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDataServiceUrl() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject convertToJSON(Map<String, Object> map, VitroRequest vreq) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
22
webapp/web/WEB-INF/ontologies/app/sparqlTestMenu.n3
Normal file
22
webapp/web/WEB-INF/ontologies/app/sparqlTestMenu.n3
Normal file
|
@ -0,0 +1,22 @@
|
|||
# $This file is distributed under the terms of the license in /doc/license.txt$
|
||||
|
||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
||||
@prefix display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> .
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
|
||||
### Test page for SPARQL UPDATE ###
|
||||
### Not For Production ###
|
||||
display:SparqlTestMenuItem
|
||||
a display:NavigationElement ;
|
||||
display:linkText "SPARQL Update Test";
|
||||
display:toPage display:SparqlUpdateTestPage .
|
||||
|
||||
display:SparqlUpdateTestPage
|
||||
a display:Page ;
|
||||
display:title "SPARQL Update Test" ;
|
||||
display:urlMapping "/sparqlUpdateTest" ;
|
||||
display:hasDataGetter display:sparqlUpdateDataGetter .
|
||||
|
||||
display:sparqlUpdateDataGetter
|
||||
a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlUpdateTestDataGetter> .
|
|
@ -0,0 +1,12 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<h3>SPARQL Update Test</h3>
|
||||
|
||||
<p>This is an expermental SPARQL update service.</p>
|
||||
|
||||
<form action="${urls.base}/sparqlUpdateTest" method="post">
|
||||
<p>
|
||||
<textarea name="update" rows="20" cols="80" ></textarea>
|
||||
<input type="submit" />
|
||||
</p>
|
||||
</form>
|
Loading…
Add table
Add a link
Reference in a new issue