Search in sources :

Example 66 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class RepositoryConfig method export.

/**
 * Exports the configuration into RDF using the given repositoryNode
 *
 * @param model
 *        target RDF collection
 * @param repositoryNode
 * @since 2.3
 */
public void export(Model model, Resource repositoryNode) {
    ValueFactory vf = SimpleValueFactory.getInstance();
    model.setNamespace(RDFS.NS);
    model.setNamespace(XMLSchema.NS);
    model.setNamespace("rep", NAMESPACE);
    model.add(repositoryNode, RDF.TYPE, REPOSITORY);
    if (id != null) {
        model.add(repositoryNode, REPOSITORYID, vf.createLiteral(id));
    }
    if (title != null) {
        model.add(repositoryNode, RDFS.LABEL, vf.createLiteral(title));
    }
    if (implConfig != null) {
        Resource implNode = implConfig.export(model);
        model.add(repositoryNode, REPOSITORYIMPL, implNode);
    }
}
Also used : Resource(org.eclipse.rdf4j.model.Resource) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory)

Example 67 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class RepositoryConfigUtil method removeRepositoryConfigs.

/**
 * Removes one or more Repository configurations from a Repository. Nothing happens when this Repository
 * does not contain configurations for these Repository IDs.
 *
 * @param repository
 *        The Repository to remove the configurations from.
 * @param repositoryIDs
 *        The IDs of the Repositories whose configurations need to be removed.
 * @throws RepositoryException
 *         Whenever access to the Repository's RepositoryConnection causes a RepositoryException.
 * @throws RepositoryConfigException
 */
@Deprecated
public static boolean removeRepositoryConfigs(Repository repository, String... repositoryIDs) throws RepositoryException, RepositoryConfigException {
    boolean changed = false;
    RepositoryConnection con = repository.getConnection();
    try {
        con.begin();
        for (String id : repositoryIDs) {
            Resource context = getContext(con, id);
            if (context != null) {
                con.clear(context);
                con.remove(context, RDF.TYPE, REPOSITORY_CONTEXT);
                changed = true;
            }
        }
        con.commit();
    } finally {
        con.close();
    }
    return changed;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Resource(org.eclipse.rdf4j.model.Resource)

Example 68 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class RepositoryConfigUtil method getRepositoryConfig.

@Deprecated
public static RepositoryConfig getRepositoryConfig(Repository repository, String repositoryID) throws RepositoryConfigException, RepositoryException {
    RepositoryConnection con = repository.getConnection();
    try {
        Statement idStatement = getIDStatement(con, repositoryID);
        if (idStatement == null) {
            // No such config
            return null;
        }
        Resource repositoryNode = idStatement.getSubject();
        Resource context = idStatement.getContext();
        if (context == null) {
            throw new RepositoryException("No configuration context for repository " + repositoryID);
        }
        Model contextGraph = QueryResults.asModel(con.getStatements(null, null, null, true, context));
        return RepositoryConfig.create(contextGraph, repositoryNode);
    } finally {
        con.close();
    }
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Statement(org.eclipse.rdf4j.model.Statement) Resource(org.eclipse.rdf4j.model.Resource) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Example 69 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class Connections method consumeRDFCollection.

/**
 * Retrieve all {@link Statement}s that together form the RDF Collection starting with the supplied start
 * resource and send them to the supplied {@link Consumer}.
 *
 * @param conn
 *        the {@link RepositoryConnection} to use for statement retrieval.
 * @param head
 *        the start resource of the RDF Collection. May not be {@code null}.
 * @param collectionConsumer
 *        a {@link Consumer} function to which all retrieved statements will be reported. May not be
 *        {@code null}.
 * @param contexts
 *        the context(s) from which to read the RDF Collection. This argument is an optional vararg and
 *        can be left out.
 * @throws RepositoryException
 *         if an error occurred while reading the collection statements, for example if a cycle is
 *         detected in the RDF collection, or some other anomaly which makes it non-wellformed.
 * @see RDFCollections
 * @see <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Schema 1.1 section on Collection
 *      vocabulary</a>.
 */
public static void consumeRDFCollection(RepositoryConnection conn, Resource head, Consumer<Statement> collectionConsumer, Resource... contexts) throws RepositoryException {
    GetStatementOptional statementSupplier = (s, p, o, c) -> getStatement(conn, s, p, o, c);
    Function<String, Supplier<RepositoryException>> exceptionSupplier = Repositories::repositoryException;
    RDFCollections.extract(statementSupplier, head, collectionConsumer, exceptionSupplier, contexts);
}
Also used : Resource(org.eclipse.rdf4j.model.Resource) Collection(java.util.Collection) RepositoryResult(org.eclipse.rdf4j.repository.RepositoryResult) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Model(org.eclipse.rdf4j.model.Model) Value(org.eclipse.rdf4j.model.Value) Objects(java.util.Objects) Consumer(java.util.function.Consumer) RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) RDFCollections(org.eclipse.rdf4j.model.util.RDFCollections) Statement(org.eclipse.rdf4j.model.Statement) GetStatementOptional(org.eclipse.rdf4j.model.util.GetStatementOptional) Optional(java.util.Optional) IRI(org.eclipse.rdf4j.model.IRI) GetStatementOptional(org.eclipse.rdf4j.model.util.GetStatementOptional) Supplier(java.util.function.Supplier)

Example 70 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class RDFCollectionsTest method testNonWellformedCollection.

@Test
public void testNonWellformedCollection() {
    Resource head = vf.createBNode();
    Model m = RDFCollections.asRDF(values, head, new TreeModel());
    m.remove(null, RDF.REST, RDF.NIL);
    try {
        RDFCollections.asValues(m, head, new ArrayList<Value>());
        fail("collection missing terminator should result in error");
    } catch (ModelException e) {
    // fall through, expected
    }
    m = RDFCollections.asRDF(values, head, new TreeModel());
    m.add(head, RDF.REST, head);
    try {
        RDFCollections.asValues(m, head, new ArrayList<Value>());
        fail("collection with cycle should result in error");
    } catch (ModelException e) {
    // fall through, expected
    }
    // supply incorrect head node
    try {
        RDFCollections.asValues(m, vf.createBNode(), new ArrayList<Value>());
        fail("resource that is not a collection should result in error");
    } catch (ModelException e) {
    // fall through, expected
    }
}
Also used : TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Value(org.eclipse.rdf4j.model.Value) Test(org.junit.Test)

Aggregations

Resource (org.eclipse.rdf4j.model.Resource)90 IRI (org.eclipse.rdf4j.model.IRI)37 Value (org.eclipse.rdf4j.model.Value)30 Test (org.junit.Test)16 Statement (org.eclipse.rdf4j.model.Statement)15 Model (org.eclipse.rdf4j.model.Model)12 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)12 BNode (org.eclipse.rdf4j.model.BNode)11 IOException (java.io.IOException)9 Literal (org.eclipse.rdf4j.model.Literal)9 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)7 StringWriter (java.io.StringWriter)6 ParsedIRI (org.eclipse.rdf4j.common.net.ParsedIRI)6 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)6 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)6 TreeModel (org.eclipse.rdf4j.model.impl.TreeModel)6 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)6 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)6 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)5 ArrayList (java.util.ArrayList)4