Search in sources :

Example 1 with StorageConflictException

use of org.trellisldp.api.StorageConflictException in project trellis by trellis-ldp.

the class DBResourceService method storeResource.

private void storeResource(final Metadata metadata, final Dataset dataset, final Instant time, final OperationType opType) {
    try {
        jdbi.useTransaction(handle -> {
            final int resourceId = updateResource(handle, metadata, dataset, time, opType == OperationType.DELETE);
            updateDescription(handle, resourceId, dataset, batchSize);
            updateAcl(handle, resourceId, dataset, batchSize);
            updateExtra(handle, resourceId, metadata.getIdentifier(), dataset);
            extensions.forEach((ext, graph) -> dataset.getGraph(graph).filter(g -> !"acl".equals(ext)).ifPresent(g -> updateExtension(handle, resourceId, ext, g)));
            if (opType == OperationType.DELETE) {
                // Verify that the container really is empty
                final String query = "SELECT EXISTS(SELECT 1 FROM resource WHERE is_part_of = ?)";
                if (Boolean.TRUE.equals(handle.select(query, metadata.getIdentifier().getIRIString()).map((rs, ctx) -> rs.getBoolean(1)).one())) {
                    throw new StorageConflictException("Cannot delete non-empty containers");
                }
            }
        });
    } catch (final TrellisRuntimeException ex) {
        throw ex;
    } catch (final Exception ex) {
        throw new TrellisRuntimeException("Could not update data for " + metadata.getIdentifier(), ex);
    }
}
Also used : IdentifierService(org.trellisldp.api.IdentifierService) TrellisRuntimeException(org.trellisldp.api.TrellisRuntimeException) PreparedBatch(org.jdbi.v3.core.statement.PreparedBatch) Optional.of(java.util.Optional.of) NTRIPLES(org.apache.jena.riot.Lang.NTRIPLES) Resource(org.trellisldp.api.Resource) PreferAudit(org.trellisldp.vocabulary.Trellis.PreferAudit) Collectors.toMap(java.util.stream.Collectors.toMap) Arrays.asList(java.util.Arrays.asList) JenaCommonsRDF.toJena(org.apache.jena.commonsrdf.JenaCommonsRDF.toJena) Map(java.util.Map) Handle(org.jdbi.v3.core.Handle) Graph(org.apache.commons.rdf.api.Graph) Set(java.util.Set) Instant(java.time.Instant) UncheckedIOException(java.io.UncheckedIOException) CompletionStage(java.util.concurrent.CompletionStage) StorageConflictException(org.trellisldp.api.StorageConflictException) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Arrays.stream(java.util.Arrays.stream) Instant.now(java.time.Instant.now) DBUtils.getObjectLang(org.trellisldp.jdbc.DBUtils.getObjectLang) PreferAccessControl(org.trellisldp.vocabulary.Trellis.PreferAccessControl) Supplier(java.util.function.Supplier) RDF(org.apache.commons.rdf.api.RDF) Triple(org.apache.commons.rdf.api.Triple) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Metadata(org.trellisldp.api.Metadata) ResourceService(org.trellisldp.api.ResourceService) DBUtils.getObjectDatatype(org.trellisldp.jdbc.DBUtils.getObjectDatatype) DataSource(javax.sql.DataSource) Collections.singletonMap(java.util.Collections.singletonMap) LDP(org.trellisldp.vocabulary.LDP) Dataset(org.apache.commons.rdf.api.Dataset) DBUtils.getObjectValue(org.trellisldp.jdbc.DBUtils.getObjectValue) Jdbi(org.jdbi.v3.core.Jdbi) BinaryMetadata(org.trellisldp.api.BinaryMetadata) RDFFactory(org.trellisldp.api.RDFFactory) CompletableFuture.runAsync(java.util.concurrent.CompletableFuture.runAsync) Logger(org.slf4j.Logger) StringWriter(java.io.StringWriter) IOException(java.io.IOException) TrellisUtils(org.trellisldp.api.TrellisUtils) IRI(org.apache.commons.rdf.api.IRI) OA(org.trellisldp.vocabulary.OA) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) RDFDataMgr(org.apache.jena.riot.RDFDataMgr) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Update(org.jdbi.v3.core.statement.Update) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) PreferUserManaged(org.trellisldp.vocabulary.Trellis.PreferUserManaged) TrellisRuntimeException(org.trellisldp.api.TrellisRuntimeException) StorageConflictException(org.trellisldp.api.StorageConflictException) TrellisRuntimeException(org.trellisldp.api.TrellisRuntimeException) UncheckedIOException(java.io.UncheckedIOException) StorageConflictException(org.trellisldp.api.StorageConflictException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 UncheckedIOException (java.io.UncheckedIOException)1 Instant (java.time.Instant)1 Instant.now (java.time.Instant.now)1 Arrays.asList (java.util.Arrays.asList)1 Arrays.stream (java.util.Arrays.stream)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Collections.unmodifiableSet (java.util.Collections.unmodifiableSet)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.of (java.util.Optional.of)1 Set (java.util.Set)1 CompletableFuture.runAsync (java.util.concurrent.CompletableFuture.runAsync)1 CompletionStage (java.util.concurrent.CompletionStage)1 Supplier (java.util.function.Supplier)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 PostConstruct (javax.annotation.PostConstruct)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1