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);
}
}
}
}
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);
}
}
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);
}
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);
}
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));
}
Aggregations