use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class StageStorage method extractStageIdentifier.
private StageIdentifier extractStageIdentifier(Graph graph) {
String select = "" + "PREFIX cruise: <" + GoOntology.URI + "> " + "SELECT ?pipelineName ?pipelineCounter ?stageName ?stageCounter WHERE {" + " ?pipeline a cruise:Pipeline ." + " ?pipeline cruise:pipelineName ?pipelineName ." + " ?pipeline cruise:pipelineCounter ?pipelineCounter ." + " ?pipeline cruise:hasStage ?stage ." + " ?stage cruise:stageName ?stageName ." + " ?stage cruise:stageCounter ?stageCounter ." + "}";
BoundVariables bv = graph.selectFirst(select);
if (bv == null) {
throw new ShineRuntimeException("Cannot save a stage graph without stage identification information!");
}
StageIdentifier stageIdentifier = new StageIdentifier(bv.getString("pipelineName"), bv.getInt("pipelineCounter"), bv.getString("stageName"), bv.getString("stageCounter"));
return stageIdentifier;
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class SesameGraph method selectFirst.
public BoundVariables selectFirst(String sparqlSelect) {
BoundVariables boundVariables;
TupleQueryResult tupleQueryResult = getTupleQueryResult(sparqlSelect);
try {
if (!tupleQueryResult.hasNext()) {
return null;
}
boundVariables = new SesameBoundVariables(tupleQueryResult.getBindingNames(), tupleQueryResult.next());
if (tupleQueryResult.hasNext()) {
tupleQueryResult.close();
throw new MoreThanOneResultFoundException(sparqlSelect);
}
} catch (QueryEvaluationException e) {
throw new ShineRuntimeException("Could not parse query: <<" + sparqlSelect + ">>", e);
}
return boundVariables;
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class JobResourceImporter method unitTestArtifactPathsForJob.
private List<String> unitTestArtifactPathsForJob(Graph graph, URIReference jobURI) {
String selectArtifactPaths = GoOntology.URI_PREFIX + "prefix xsd: <http://www.w3.org/2001/XMLSchema#> " + "SELECT DISTINCT ?artifactPath WHERE { " + "<" + jobURI.getURIText() + "> cruise:hasArtifacts ?artifacts . " + "?artifacts a cruise:Artifacts . " + "?artifacts cruise:hasArtifact ?artifact . " + "?artifact cruise:artifactPath ?artifactPath . " + "?artifact cruise:artifactType 'unit'^^xsd:string " + "}";
List<BoundVariables> bvs = graph.select(selectArtifactPaths);
List<String> result = new ArrayList<>(bvs.size());
for (BoundVariables bv : bvs) {
result.add(bv.getString("artifactPath"));
}
return result;
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class JobResourceImporter method jobArtifactsPath.
private String jobArtifactsPath(URIReference jobResource, Graph jobsGraph) {
String selectArtifactRoot = GoOntology.URI_PREFIX + "prefix xsd: <http://www.w3.org/2001/XMLSchema#> " + "SELECT DISTINCT ?pathFromArtifactRoot WHERE { " + "<" + jobResource.getURIText() + "> cruise:hasArtifacts ?artifacts . " + " ?artifacts a cruise:Artifacts . " + " ?artifacts cruise:pathFromArtifactRoot ?pathFromArtifactRoot ." + "}";
BoundVariables bv = jobsGraph.selectFirst(selectArtifactRoot);
return (bv == null) ? null : bv.getString("pathFromArtifactRoot");
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class StagesQueryTest method testRunSparqlAgainstMultipleStagesWithEmptyCacheWillPopulateCache.
@Test
public void testRunSparqlAgainstMultipleStagesWithEmptyCacheWillPopulateCache() {
populateStage("p", 1, "s", 2, "http://job/1");
populateStage("p", 2, "s", 2, "http://job/2");
InMemoryCache cache = new InMemoryCache();
StagesQuery stagesQuery = new StagesQuery(graphLoader, cache);
String sparql = "PREFIX cruise:<" + GoOntology.URI + ">" + "SELECT ?job WHERE {" + " ?job a cruise:Job . " + "}";
StageIdentifier stageIdentifierOne = new StageIdentifier("p", 1, "s", "2");
StageIdentifier stageIdentifierTwo = new StageIdentifier("p", 2, "s", "2");
List<TestModel> bvs = stagesQuery.select(sparql, Arrays.asList(stageIdentifierOne, stageIdentifierTwo), new RdfResultMapper<TestModel>() {
public TestModel map(BoundVariables aRow) {
return new TestModel(aRow.getAsString("job"));
}
});
assertEquals(2, bvs.size());
assertEquals(new TestModel("http://job/1"), bvs.get(0));
assertEquals(new TestModel("http://job/2"), bvs.get(1));
assertNotNull(cache.get(new StagesQueryCache.CacheKey(sparql, stageIdentifierOne)));
assertNotNull(cache.get(new StagesQueryCache.CacheKey(sparql, stageIdentifierTwo)));
}
Aggregations