Search in sources :

Example 6 with BoundVariables

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;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) BoundVariables(com.thoughtworks.studios.shine.semweb.BoundVariables) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException)

Example 7 with BoundVariables

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;
}
Also used : BoundVariables(com.thoughtworks.studios.shine.semweb.BoundVariables) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) MoreThanOneResultFoundException(com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException) TupleQueryResult(org.openrdf.query.TupleQueryResult)

Example 8 with 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;
}
Also used : BoundVariables(com.thoughtworks.studios.shine.semweb.BoundVariables) ArrayList(java.util.ArrayList)

Example 9 with BoundVariables

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");
}
Also used : BoundVariables(com.thoughtworks.studios.shine.semweb.BoundVariables)

Example 10 with BoundVariables

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)));
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) BoundVariables(com.thoughtworks.studios.shine.semweb.BoundVariables) Test(org.junit.Test)

Aggregations

BoundVariables (com.thoughtworks.studios.shine.semweb.BoundVariables)16 Test (org.junit.Test)10 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)3 Graph (com.thoughtworks.studios.shine.semweb.Graph)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)2 TupleQueryResult (org.openrdf.query.TupleQueryResult)2 MoreThanOneResultFoundException (com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException)1 InMemoryTempGraphFactory (com.thoughtworks.studios.shine.semweb.sesame.InMemoryTempGraphFactory)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 LinkedList (java.util.LinkedList)1