Search in sources :

Example 16 with Graph

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

the class StageResourceImporter method load.

public Graph load(StageIdentifier stageIdentifier, TempGraphFactory tempGraphFactory, final XSLTTransformerRegistry transformerRegistry) throws GoIntegrationException {
    LOGGER.debug("Attempting to import stage with url <{}> !", stageIdentifier);
    long importStartingTime = System.currentTimeMillis();
    try {
        Stage stage = stageFinder.findStageWithIdentifier(stageIdentifier);
        String baseUri = "https://localhost:8154/go";
        Graph graph = loadIsolatedStageGraph(stageIdentifier, tempGraphFactory, transformerRegistry, stage, baseUri);
        importPipeline(pipelineInstanceLoader.loadPipelineForShine(stage.getPipelineId()), graph, transformerRegistry, baseUri);
        importJobs(graph, transformerRegistry, stage, baseUri);
        return graph;
    } finally {
        LOGGER.debug("Done importing stage with url <{}> with {} ms!", stageIdentifier, System.currentTimeMillis() - importStartingTime);
    }
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) Stage(com.thoughtworks.go.domain.Stage)

Example 17 with Graph

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

the class StageResourceImporter method importPipeline.

private void importPipeline(PipelineInstanceModel pipelineInstance, Graph graph, XSLTTransformerRegistry transformerRegistry, String baseUri) throws GoIntegrationException {
    final GoGRDDLResourceRDFizer pipeline = new GoGRDDLResourceRDFizer("pipeline", XSLTTransformerRegistry.CRUISE_PIPELINE_GRAPH_GRDDL_XSL, graph, transformerRegistry, xmlApiService);
    Graph pipelineGraph = pipeline.importURIUsingGRDDL(new PipelineXmlViewModel(pipelineInstance), baseUri);
    graph.addTriplesFromGraph(pipelineGraph);
}
Also used : PipelineXmlViewModel(com.thoughtworks.go.server.domain.xml.PipelineXmlViewModel) Graph(com.thoughtworks.studios.shine.semweb.Graph) GoGRDDLResourceRDFizer(com.thoughtworks.studios.shine.cruise.GoGRDDLResourceRDFizer)

Example 18 with Graph

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

the class StageStorage method load.

public Graph load(StageIdentifier stageIdentifier) {
    String fileName = stagePath(stageIdentifier);
    try {
        InputStream inputStream = new BufferedInputStream(new FileInputStream(fileName));
        Graph tempGraph = new InMemoryTempGraphFactory().createTempGraph();
        tempGraph.addTriplesFromTurtle(inputStream);
        inputStream.close();
        return tempGraph;
    } catch (IOException e) {
        throw new ShineRuntimeException(String.format("Unable to read stage n3 file for " + stageIdentifier + "(file: %s). This should never happen.", fileName), e);
    }
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) InMemoryTempGraphFactory(com.thoughtworks.studios.shine.semweb.sesame.InMemoryTempGraphFactory) FileInputStream(java.io.FileInputStream)

Example 19 with Graph

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

the class GRDDLTransformer method transform.

public Graph transform(final Document inputDoc, TempGraphFactory graphFactory) throws GrddlTransformException {
    final DocumentResult result = new DocumentResult();
    try {
        xsltTransformerRegistry.transformWithCorrectClassLoader(key, new XSLTTransformerExecutor<Void>() {

            @Override
            public Void execute(Transformer transformer) throws TransformerException {
                DocumentSource source = new DocumentSource(inputDoc);
                transformer.transform(source, result);
                return null;
            }
        });
        // TODO: likely need to optimize with some sort of streaming document reader here
        Graph graph = graphFactory.createTempGraph();
        graph.addTriplesFromRDFXMLAbbrev(new StringReader(result.getDocument().asXML()));
        return graph;
    } catch (ShineRuntimeException e) {
        LOGGER.error("Could not convert to a graph. The document was: \n{}", result.getDocument().asXML(), e);
        throw e;
    } catch (TransformerException e) {
        LOGGER.warn("Could not perform grddl transform. The document was: \n{}", result.getDocument().asXML(), e);
        throw new GrddlTransformException(e);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) Graph(com.thoughtworks.studios.shine.semweb.Graph) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) DocumentResult(org.dom4j.io.DocumentResult) DocumentSource(org.dom4j.io.DocumentSource) StringReader(java.io.StringReader) TransformerException(javax.xml.transform.TransformerException)

Example 20 with Graph

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

the class SesameGraph method close.

public void close() {
    try {
        for (Graph tempGraph : tempGraphs) {
            tempGraph.close();
        }
        tempGraphs.clear();
        conn.commit();
        conn.close();
    } catch (RepositoryException e) {
        throw new ShineRuntimeException("Could not close graph!", e);
    }
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException)

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