From 5c01cca0ab0b36e2c5f5ea50713cac4d59257577 Mon Sep 17 00:00:00 2001 From: grahamtriggs Date: Wed, 21 Oct 2015 11:53:06 +0100 Subject: [PATCH] [VIVO-1031] Performance improvements to editor management page --- ...EditorsToInformationResourceGenerator.java | 81 ++++++++++++++++--- 1 file changed, 68 insertions(+), 13 deletions(-) diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorsToInformationResourceGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorsToInformationResourceGenerator.java index bb14fa36..928362cc 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorsToInformationResourceGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorsToInformationResourceGenerator.java @@ -12,6 +12,11 @@ import java.util.Map.Entry; import javax.servlet.http.HttpSession; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -308,6 +313,44 @@ public class AddEditorsToInformationResourceGenerator extends VivoBaseGenerator editConfiguration.setFormSpecificData(formSpecificData); } + private static String EDITORSHIPS_MODEL = "" + + "PREFIX core: \n" + + "PREFIX afn: \n" + + "PREFIX rdfs: \n" + + "PREFIX foaf: \n" + + "CONSTRUCT\n" + + "{\n" + + " ?subject core:relatedBy ?editorshipURI .\n" + + " ?editorshipURI a core:Editorship .\n" + + " ?editorshipURI core:relates ?editorURI .\n" + + " ?editorshipURI core:rank ?rank.\n" + + " ?editorURI a foaf:Person .\n" + + " ?editorURI rdfs:label ?editorName .\n" + + "}\n" + + "WHERE\n" + + "{\n" + + " {\n" + + " ?subject core:relatedBy ?editorshipURI .\n" + + " ?editorshipURI a core:Editorship .\n" + + " ?editorshipURI core:relates ?editorURI .\n" + + " ?editorURI a foaf:Person .\n" + + " }\n" + + " UNION\n" + + " {\n" + + " ?subject core:relatedBy ?editorshipURI .\n" + + " ?editorshipURI a core:Editorship .\n" + + " ?editorshipURI core:relates ?editorURI .\n" + + " ?editorURI a foaf:Person .\n" + + " ?editorURI rdfs:label ?editorName .\n" + + " }\n" + + " UNION\n" + + " {\n" + + " ?subject core:relatedBy ?editorshipURI .\n" + + " ?editorshipURI a core:Editorship .\n" + + " ?editorshipURI core:rank ?rank.\n" + + " }\n" + + "}\n"; + private static String EDITORSHIPS_QUERY = "" + "PREFIX core: \n" + "PREFIX afn: \n" @@ -325,19 +368,31 @@ public class AddEditorsToInformationResourceGenerator extends VivoBaseGenerator private List getExistingEditorships(String subjectUri, VitroRequest vreq) { - - String queryStr = QueryUtils.subUriForQueryVar(this.getEditorshipsQuery(), "subject", subjectUri); - log.debug("Query string is: " + queryStr); - List> editorships = new ArrayList>(); - try { - ResultSet results = QueryUtils.getQueryResults(queryStr, vreq); - while (results.hasNext()) { - QuerySolution soln = results.nextSolution(); - RDFNode node = soln.get("editorshipURI"); - if (node.isURIResource()) { - editorships.add(QueryUtils.querySolutionToStringValueMap(soln)); - } - } + RDFService rdfService = vreq.getRDFService(); + + List> editorships = new ArrayList>(); + try { + String constructStr = QueryUtils.subUriForQueryVar(EDITORSHIPS_MODEL, "subject", subjectUri); + + Model constructedModel = ModelFactory.createDefaultModel(); + rdfService.sparqlConstructQuery(constructStr, constructedModel); + + String queryStr = QueryUtils.subUriForQueryVar(this.getEditorshipsQuery(), "subject", subjectUri); + log.debug("Query string is: " + queryStr); + + QueryExecution qe = QueryExecutionFactory.create(queryStr, constructedModel); + try { + ResultSet results = qe.execSelect(); + while (results.hasNext()) { + QuerySolution soln = results.nextSolution(); + RDFNode node = soln.get("editorshipURI"); + if (node.isURIResource()) { + editorships.add(QueryUtils.querySolutionToStringValueMap(soln)); + } + } + } finally { + qe.close(); + } } catch (Exception e) { log.error(e, e); }