Search in sources :

Example 6 with RepositoryException

use of org.openrdf.repository.RepositoryException in project gocd by gocd.

the class SesameGraphTest method checkWhenAddStatementWithIntObjectExplodesItThrowsAShineRuntimeException.

@Test(expected = ShineRuntimeException.class)
public void checkWhenAddStatementWithIntObjectExplodesItThrowsAShineRuntimeException() throws RepositoryException {
    RDFProperty property = new RDFProperty("http://www.example.com/ontology#foo");
    RepositoryConnection badConnection = mock(RepositoryConnection.class);
    doThrow(new RepositoryException("")).when(badConnection).add((org.openrdf.model.Resource) any(), (org.openrdf.model.URI) any(), (org.openrdf.model.Literal) any());
    org.openrdf.model.ValueFactory stubValueFactory = mock(org.openrdf.model.ValueFactory.class);
    when(badConnection.getValueFactory()).thenReturn(stubValueFactory);
    SesameURIReference stubSubject = mock(SesameURIReference.class);
    when(stubSubject.getSesameNativeResource()).thenReturn(null);
    URIReference stubPredicate = mock(URIReference.class);
    when(stubPredicate.getURIText()).thenReturn("");
    SesameGraph badGraph = new SesameGraph(badConnection, null);
    badGraph.addStatement(stubSubject, property, 3);
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) RepositoryException(org.openrdf.repository.RepositoryException) Test(org.junit.Test)

Example 7 with RepositoryException

use of org.openrdf.repository.RepositoryException in project gocd by gocd.

the class SesameGraphTest method checkWhenAddTriplesFromGraphExplodesItThrowsShineRuntimeException.

@Test(expected = ShineRuntimeException.class)
public void checkWhenAddTriplesFromGraphExplodesItThrowsShineRuntimeException() throws RepositoryException {
    RepositoryConnection badConnection = mock(RepositoryConnection.class);
    doThrow(new RepositoryException("")).when(badConnection).getStatements((org.openrdf.model.Resource) any(), (org.openrdf.model.URI) any(), (org.openrdf.model.Value) any(), anyBoolean());
    SesameGraph otherGraph = new SesameGraph(badConnection, null);
    SesameGraph badGraph = new SesameGraph(badConnection, null);
    badGraph.addTriplesFromGraph(otherGraph);
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) RepositoryException(org.openrdf.repository.RepositoryException) Test(org.junit.Test)

Example 8 with RepositoryException

use of org.openrdf.repository.RepositoryException in project stanbol by apache.

the class RdfIndexingSource method loadRepositoryConfig.

/**
     * @param repoConfigFile
     * @return
     */
private RepositoryConfig loadRepositoryConfig(File repoConfigFile) {
    Repository configRepo = new SailRepository(new MemoryStore());
    RepositoryConnection con = null;
    try {
        configRepo.initialize();
        con = configRepo.getConnection();
        //We need to load the configuration into a context
        org.openrdf.model.URI configContext = con.getValueFactory().createURI("urn:stanbol.entityhub:indexing.source.sesame:config.context");
        RDFFormat format = Rio.getParserFormatForFileName(repoConfigFile.getName());
        try {
            con.add(new InputStreamReader(new FileInputStream(repoConfigFile), Charset.forName("UTF-8")), baseUri, format, configContext);
        } catch (RDFParseException e) {
            throw new IllegalArgumentException("Unable to parsed '" + repoConfigFile + "' using RDF format '" + format + "'!", e);
        } catch (IOException e) {
            throw new IllegalArgumentException("Unable to access '" + repoConfigFile + "'!", e);
        }
        con.commit();
    } catch (RepositoryException e) {
        throw new IllegalStateException("Unable to load '" + repoConfigFile + "' to inmemory Sail!", e);
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (RepositoryException e) {
            /* ignore */
            }
        }
    }
    Set<String> repoNames;
    RepositoryConfig repoConfig;
    try {
        repoNames = RepositoryConfigUtil.getRepositoryIDs(configRepo);
        if (repoNames.size() == 1) {
            repoConfig = RepositoryConfigUtil.getRepositoryConfig(configRepo, repoNames.iterator().next());
            repoConfig.validate();
        } else if (repoNames.size() > 1) {
            throw new IllegalArgumentException("Repository configuration file '" + repoConfigFile + "' MUST only contain a single repository configuration!");
        } else {
            throw new IllegalArgumentException("Repository configuration file '" + repoConfigFile + "' DOES NOT contain a repository configuration!");
        }
    } catch (RepositoryException e) {
        throw new IllegalStateException("Unable to read RepositoryConfiguration form the " + "in-memory Sail!", e);
    } catch (RepositoryConfigException e) {
        throw new IllegalArgumentException("Repository Configuration in '" + repoConfigFile + "is not valid!", e);
    } finally {
        try {
            configRepo.shutDown();
        } catch (RepositoryException e) {
        /* ignore */
        }
    }
    if (repoConfig.getRepositoryImplConfig() == null) {
        throw new IllegalArgumentException("Missing RepositoryImpl config for " + "config " + repoConfig.getID() + " of file " + repoConfigFile + "!");
    }
    return repoConfig;
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) RepositoryConfig(org.openrdf.repository.config.RepositoryConfig) InputStreamReader(java.io.InputStreamReader) SailRepository(org.openrdf.repository.sail.SailRepository) RepositoryException(org.openrdf.repository.RepositoryException) IOException(java.io.IOException) RepositoryConfigException(org.openrdf.repository.config.RepositoryConfigException) FileInputStream(java.io.FileInputStream) MemoryStore(org.openrdf.sail.memory.MemoryStore) Repository(org.openrdf.repository.Repository) SailRepository(org.openrdf.repository.sail.SailRepository) URI(org.openrdf.model.URI) RDFFormat(org.openrdf.rio.RDFFormat) RDFParseException(org.openrdf.rio.RDFParseException)

Example 9 with RepositoryException

use of org.openrdf.repository.RepositoryException in project stanbol by apache.

the class RdfIndexingSource method close.

@Override
public void close() {
    //first close still active RdfEntityDataIterator instances
    for (EntityDataIterator edi : entityDataIterators) {
        edi.close();
    }
    //close connections used for LDPath and EntityDataProvider
    ungetLdPathConnection();
    ungetEntityDataProviderConnection();
    //finally shutdown the repository
    if (shutdownRepository) {
        try {
            repository.shutDown();
        } catch (RepositoryException e) {
            log.warn("Error while closing Sesame Connection", e);
        }
    }
}
Also used : RepositoryException(org.openrdf.repository.RepositoryException) EntityDataIterator(org.apache.stanbol.entityhub.indexing.core.EntityDataIterator)

Example 10 with RepositoryException

use of org.openrdf.repository.RepositoryException in project stanbol by apache.

the class RdfResourceImporter method importResource.

@Override
public ResourceState importResource(InputStream is, String resourceName) throws IOException {
    log.info("> importing {}:", resourceName);
    RDFFormat rdfFormat = Rio.getParserFormatForFileName(resourceName);
    if (rdfFormat == null) {
        log.info("  ... unable to detect RDF format for {}", resourceName);
        log.info("  ... resource '{}' will not be imported", resourceName);
        return ResourceState.IGNORED;
    } else {
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            con.add(new InputStreamReader(is, UTF8), baseUri, rdfFormat, contexts);
            con.commit();
            return ResourceState.LOADED;
        } catch (RDFParseException e) {
            log.error("  ... unable to parser RDF file " + resourceName + " (format: " + rdfFormat + ")", e);
            return ResourceState.ERROR;
        } catch (RepositoryException e) {
            throw new IllegalArgumentException("Repository Exception while " + resourceName + "!", e);
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (RepositoryException e1) {
                /* ignore */
                }
            }
        }
    }
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) InputStreamReader(java.io.InputStreamReader) RepositoryException(org.openrdf.repository.RepositoryException) RDFFormat(org.openrdf.rio.RDFFormat) RDFParseException(org.openrdf.rio.RDFParseException)

Aggregations

RepositoryException (org.openrdf.repository.RepositoryException)36 RepositoryConnection (org.openrdf.repository.RepositoryConnection)20 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)12 URI (org.openrdf.model.URI)12 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)10 Test (org.junit.Test)7 RdfRepresentation (org.apache.stanbol.entityhub.model.sesame.RdfRepresentation)5 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)5 IOException (java.io.IOException)4 Value (org.openrdf.model.Value)4 Repository (org.openrdf.repository.Repository)4 InputStreamReader (java.io.InputStreamReader)3 SparqlFieldQuery (org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery)3 BindingSet (org.openrdf.query.BindingSet)3 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)3 TupleQueryResult (org.openrdf.query.TupleQueryResult)3 SailRepository (org.openrdf.repository.sail.SailRepository)3 Graph (com.thoughtworks.studios.shine.semweb.Graph)2 RdfValueFactory (org.apache.stanbol.entityhub.model.sesame.RdfValueFactory)2 Model (org.openrdf.model.Model)2