VIVO-1248 extend SparqlQueryRunner, and combine with older attempts. (#36)

* VIVO-1247, remove duplicate code used with ConfigurationBeanLoader.

Now that the @Property annotation includes cardinality parameters, we can remove a lot of duplicate code.

* Ignore artifacts that Eclipse creates.

* VIVO-1248 Remove references to older SPARQL utils

edu.cornell.mannlib.vitro.webapp.utils.sparql package
edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner
This commit is contained in:
Jim Blake 2017-01-03 13:19:48 -05:00 committed by GitHub
parent 15638f6ac1
commit da0b68f001
3 changed files with 27 additions and 21 deletions

5
.gitignore vendored
View file

@ -17,3 +17,8 @@ utilities/rdbmigration/.work
**/target
**/overlays
# Eclipse artifacts
**/.settings
**/.classpath
**/.project

View file

@ -4,7 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.searchindex.extensions;
import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.ALLTEXT;
import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.ALLTEXTUNSTEMMED;
import static edu.cornell.mannlib.vitro.webapp.utils.sparql.SelectQueryRunner.createQueryContext;
import static edu.cornell.mannlib.vitro.webapp.utils.sparqlrunner.SparqlQueryRunner.createSelectQueryContext;
import java.util.ArrayList;
import java.util.Collection;
@ -222,25 +222,26 @@ public class LabelsAcrossContextNodes implements IndexingUriFinder,
private void addLabelsFromAllContextNodeClasses(Individual ind,
SearchInputDocument doc) {
addValuesToTextFields(doc,
createQueryContext(rdfService, LABELS_WITHOUT_RESTRICTION)
addValuesToTextFields(
doc,
createSelectQueryContext(rdfService, LABELS_WITHOUT_RESTRICTION)
.bindVariableToUri("uri", ind.getURI())
.bindVariableToUri("incoming", incomingPropertyUri)
.bindVariableToUri("outgoing", outgoingPropertyUri)
.execute().getStringFields("label").flatten());
.execute().toStringFields("label").flatten());
}
private void addLabelsFromContextNodeClass(Individual ind,
SearchInputDocument doc, String contextNodeClass) {
addValuesToTextFields(
doc,
createQueryContext(rdfService,
createSelectQueryContext(rdfService,
LABELS_FOR_SPECIFIC_CONTEXT_NODE_TYPE)
.bindVariableToUri("uri", ind.getURI())
.bindVariableToUri("nodeType", contextNodeClass)
.bindVariableToUri("incoming", incomingPropertyUri)
.bindVariableToUri("outgoing", outgoingPropertyUri)
.execute().getStringFields("label").flatten());
.execute().toStringFields("label").flatten());
}
private void addValuesToTextFields(SearchInputDocument doc,
@ -329,23 +330,23 @@ public class LabelsAcrossContextNodes implements IndexingUriFinder,
}
private Set<String> locatePartnersWithoutRestriction(String uri) {
return createQueryContext(rdfService,
return createSelectQueryContext(rdfService,
LOCATE_PARTNERS_WITHOUT_RESTRICTION)
.bindVariableToUri("uri", uri)
.bindVariableToUri("incoming", incomingPropertyUri)
.bindVariableToUri("outgoing", outgoingPropertyUri).execute()
.getStringFields("partner").flattenToSet();
.toStringFields("partner").flattenToSet();
}
private Collection<? extends String> locatePartnersAcrossContextNodeClass(
String uri, String contextNodeClass) {
return createQueryContext(rdfService,
return createSelectQueryContext(rdfService,
LOCATE_PARTNERS_ON_CONTEXT_NODE_TYPE)
.bindVariableToUri("uri", uri)
.bindVariableToUri("nodeType", contextNodeClass)
.bindVariableToUri("incoming", incomingPropertyUri)
.bindVariableToUri("outgoing", outgoingPropertyUri).execute()
.getStringFields("partner").flattenToSet();
.toStringFields("partner").flattenToSet();
}
private boolean isIncomingStatementOnAcceptableContextNode(Statement stmt) {
@ -368,9 +369,9 @@ public class LabelsAcrossContextNodes implements IndexingUriFinder,
}
private Set<String> getTypes(String uri) {
return createQueryContext(rdfService, GET_TYPES)
.bindVariableToUri("uri", uri).execute()
.getStringFields("type").flattenToSet();
return createSelectQueryContext(rdfService, GET_TYPES)
.bindVariableToUri("uri", uri).execute().toStringFields("type")
.flattenToSet();
}
private Set<String> locateOtherPartners(Statement stmt) {
@ -382,12 +383,12 @@ public class LabelsAcrossContextNodes implements IndexingUriFinder,
String objectUri = (stmt.getObject().isURIResource()) ? stmt
.getObject().asResource().getURI() : "NO_MATCH";
return createQueryContext(rdfService,
return createSelectQueryContext(rdfService,
LOCATE_OTHER_PARTNERS_ON_THIS_NODE)
.bindVariableToUri("contextNode", nodeUri)
.bindVariableToUri("uri", objectUri)
.bindVariableToUri("outgoing", outgoingPropertyUri).execute()
.getStringFields("partner").flattenToSet();
.toStringFields("partner").flattenToSet();
}
private List<String> filterByType(Collection<String> uris) {

View file

@ -18,15 +18,14 @@ import org.apache.jena.rdf.model.Resource;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProfile;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProxyEditingRights;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsRootUser;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner;
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner.QueryParser;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.sparqlrunner.ResultSetParser;
import edu.cornell.mannlib.vitro.webapp.utils.sparqlrunner.SparqlQueryRunner;
import edu.cornell.mannlib.vivo.orcid.controller.OrcidIntegrationController;
/**
@ -122,8 +121,9 @@ public class OrcidIdDataGetter implements DataGetter {
private List<OrcidInfo> runSparqlQuery(String individualUri) {
String queryStr = String.format(QUERY_TEMPLATE, individualUri,
ORCID_ID, ORCID_IS_CONFIRMED);
SparqlQueryRunner runner = new SparqlQueryRunner(vreq.getJenaOntModel());
return runner.executeSelect(new OrcidResultParser(), queryStr);
return SparqlQueryRunner
.createSelectQueryContext(vreq.getJenaOntModel(), queryStr)
.execute().parse(new OrcidResultParser());
}
private Map<String, Object> buildMap(boolean isAuthorizedToConfirm,
@ -154,7 +154,7 @@ public class OrcidIdDataGetter implements DataGetter {
/**
* Parse the results of the SPARQL query.
*/
private static class OrcidResultParser extends QueryParser<List<OrcidInfo>> {
private static class OrcidResultParser extends ResultSetParser<List<OrcidInfo>> {
@Override
protected List<OrcidInfo> defaultValue() {
return Collections.emptyList();