Search in sources :

Example 26 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class XMLArtifactImporter method importXML.

private void importXML(Graph graph, URIReference parentJob, Document doc) {
    for (XMLRDFizer handler : handlers) {
        if (handler.canHandle(doc)) {
            try {
                Graph artifactGraph = handler.importFile(parentJob.getURIText(), doc);
                LOGGER.debug("Imported a total of {} triples in artifact.", artifactGraph.size());
                graph.addTriplesFromGraph(artifactGraph);
                return;
            } catch (Exception e) {
                LOGGER.warn("{} was unable to handle document it said it could.  Exception happened while importing artifacts for job: {}...", handler.getClass().getName(), parentJob, e);
            }
        }
    }
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) XMLRDFizer(com.thoughtworks.studios.shine.semweb.XMLRDFizer) IOException(java.io.IOException) DocumentException(org.dom4j.DocumentException) SAXException(org.xml.sax.SAXException)

Example 27 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class SesameGraph method createTempGraph.

public Graph createTempGraph() {
    try {
        if (!conn.isOpen()) {
            throw new IllegalStateException("Cannot create a temp graph on a closed graph!");
        }
        Repository inMemRepos = InMemoryRepositoryFactory.emptyRepository();
        String contextURI = null;
        if (contextResource.length > 0) {
            contextURI = contextResource[0].stringValue();
        }
        Graph tempGraph = new SesameGraph(inMemRepos.getConnection(), contextURI);
        tempGraphs.add(tempGraph);
        return tempGraph;
    } catch (RepositoryException ex) {
        throw new ShineRuntimeException("Unable to create temp graph!", ex);
    }
}
Also used : Repository(org.openrdf.repository.Repository) Graph(com.thoughtworks.studios.shine.semweb.Graph) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException)

Example 28 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class StageResourceImporterTest method canLoadAllStageInfoAfterImportIt.

@Test
public void canLoadAllStageInfoAfterImportIt() throws Exception {
    TestFailureSetup.SavedStage savedStage = failureSetup.setupPipelineInstanceWithoutTestXmlStubbing(true, null, new Date());
    Pipeline pipeline = savedStage.pipeline;
    Graph graph = importer.load(savedStage.stageId, graphFactory, new XSLTTransformerRegistry());
    String pipelineUrl = PipelineXmlViewModel.httpUrlForPipeline(baseUrl, pipeline.getId(), pipeline.getName());
    Stage stage = savedStage.stage;
    String stageUrl = new StageXmlViewModel(stage).httpUrl(baseUrl);
    String jobUrl = new JobXmlViewModel(stage.getJobInstances().get(0)).httpUrl(baseUrl);
    String ask = "" + "PREFIX cruise: <" + GoOntology.URI + "> " + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> " + "ASK WHERE {" + "  <" + pipelineUrl + "> a cruise:Pipeline ." + "  <" + pipelineUrl + "> cruise:hasStage <" + stageUrl + "> ." + "  <" + stageUrl + "> a cruise:Stage ." + "  <" + stageUrl + "> cruise:hasJob <" + jobUrl + "> ." + "  <" + jobUrl + "> a cruise:Job . " + "}";
    assertAskIsTrue(graph, ask);
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) StageXmlViewModel(com.thoughtworks.go.server.domain.xml.StageXmlViewModel) JobXmlViewModel(com.thoughtworks.go.server.domain.xml.JobXmlViewModel) TestFailureSetup(com.thoughtworks.go.server.dao.sparql.TestFailureSetup) Stage(com.thoughtworks.go.domain.Stage) XSLTTransformerRegistry(com.thoughtworks.studios.shine.semweb.grddl.XSLTTransformerRegistry) Date(java.util.Date) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 29 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class StageResourceImporterTest method shouldNotImportPreviousNextPipelinePointer.

@Test
public void shouldNotImportPreviousNextPipelinePointer() throws Exception {
    TestFailureSetup.SavedStage savedStageFirst = failureSetup.setupPipelineInstanceWithoutTestXmlStubbing(true, null, new Date());
    TestFailureSetup.SavedStage savedStageSecond = failureSetup.setupPipelineInstanceWithoutTestXmlStubbing(true, null, new Date());
    TestFailureSetup.SavedStage savedStageThird = failureSetup.setupPipelineInstanceWithoutTestXmlStubbing(true, null, new Date());
    Graph graph = importer.load(savedStageSecond.stageId, graphFactory, new XSLTTransformerRegistry());
    Pipeline pipelineSecond = savedStageSecond.pipeline;
    assertTrue(graph.containsResourceWithURI(PipelineXmlViewModel.httpUrlForPipeline(baseUrl, pipelineSecond.getId(), pipelineSecond.getName())));
    Pipeline pipelineFirst = savedStageFirst.pipeline;
    assertFalse(graph.containsResourceWithURI(PipelineXmlViewModel.httpUrlForPipeline(baseUrl, pipelineFirst.getId(), pipelineFirst.getName())));
    Pipeline pipelineThird = savedStageThird.pipeline;
    assertFalse(graph.containsResourceWithURI(PipelineXmlViewModel.httpUrlForPipeline(baseUrl, pipelineThird.getId(), pipelineThird.getName())));
    String askForPreviousPointer = "" + "PREFIX cruise: <" + GoOntology.URI + "> " + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> " + "ASK WHERE {" + "  [] cruise:previousPipeline [] . " + "}";
    assertAskIsFalse(graph, askForPreviousPointer);
    String askForNextPointer = "" + "PREFIX cruise: <" + GoOntology.URI + "> " + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> " + "ASK WHERE {" + "  [] cruise:nextPipeline [] . " + "}";
    assertAskIsFalse(graph, askForNextPointer);
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) TestFailureSetup(com.thoughtworks.go.server.dao.sparql.TestFailureSetup) XSLTTransformerRegistry(com.thoughtworks.studios.shine.semweb.grddl.XSLTTransformerRegistry) Date(java.util.Date) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 30 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class GRDDLTransformerTest method checkXMLBecomesRDF.

@Test
public void checkXMLBecomesRDF() throws Exception {
    String inputXML = "<foo>bar</foo>";
    String xsl = "" + "<?xml version='1.0' encoding='UTF-8'?>" + "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " + "xmlns:ex='http://www.example.com/ontology.owl#' " + "xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' version='1.0'>" + "<xsl:template match='/'>" + "<rdf:RDF>" + "<xsl:apply-templates />" + "</rdf:RDF>" + "</xsl:template>" + "<xsl:template match='foo'>" + "<ex:Foo>" + "<ex:hasBar rdf:datatype='http://www.w3.org/2001/XMLSchema#string'><xsl:value-of select='.'/></ex:hasBar>" + "</ex:Foo>" + "</xsl:template>" + "</xsl:stylesheet>";
    String ask = "prefix ex: <http://www.example.com/ontology.owl#> " + "prefix xsd: <http://www.w3.org/2001/XMLSchema#> " + "ASK WHERE { " + "?foo a ex:Foo ; " + "ex:hasBar 'bar'^^xsd:string . " + "}" + "";
    InputStream xslAsStream = new ByteArrayInputStream(xsl.getBytes());
    InputStream xmlAsStream = new ByteArrayInputStream(inputXML.getBytes());
    GRDDLTransformer transformer = new GRDDLTransformer(transformerForXSLStream(xslAsStream, "foo.xml"), "foo.xml");
    Graph graph = transformer.transform(xmlAsStream, new InMemoryTempGraphFactory());
    assertAskIsTrue(graph, (ask));
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InMemoryTempGraphFactory(com.thoughtworks.studios.shine.semweb.sesame.InMemoryTempGraphFactory) Test(org.junit.Test)

Aggregations

Graph (com.thoughtworks.studios.shine.semweb.Graph)41 Test (org.junit.Test)26 InMemoryTempGraphFactory (com.thoughtworks.studios.shine.semweb.sesame.InMemoryTempGraphFactory)18 File (java.io.File)7 JobXmlViewModel (com.thoughtworks.go.server.domain.xml.JobXmlViewModel)5 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)5 InputStream (java.io.InputStream)5 TestFailureSetup (com.thoughtworks.go.server.dao.sparql.TestFailureSetup)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Date (java.util.Date)4 Pipeline (com.thoughtworks.go.domain.Pipeline)3 Stage (com.thoughtworks.go.domain.Stage)3 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 StageXmlViewModel (com.thoughtworks.go.server.domain.xml.StageXmlViewModel)3 XSLTTransformerRegistry (com.thoughtworks.studios.shine.semweb.grddl.XSLTTransformerRegistry)3 Modification (com.thoughtworks.go.domain.materials.Modification)2 GoGRDDLResourceRDFizer (com.thoughtworks.studios.shine.cruise.GoGRDDLResourceRDFizer)2 BoundVariables (com.thoughtworks.studios.shine.semweb.BoundVariables)2 IOException (java.io.IOException)2 Transformer (javax.xml.transform.Transformer)2