/** * Assert that no exceptions were thrown while this listener was processing change */ public void assertNoExceptions() { if (!exceptions.isEmpty()) { throw new MalformedRdfException(exceptions.stream().map(Exception::getMessage).collect(joining("\n"))); } } }
@Override public void consume() { stream.forEach(t -> { final Statement s = m.asStatement(t); LOGGER.debug("Operating on triple {}.", s); try { operateOnTriple(s); } catch (final MalformedRdfException e) { exceptions.add(e.getMessage()); } catch (final ConstraintViolationException e) { throw e; } }); if (!exceptions.isEmpty()) { throw new MalformedRdfException(join("\n", exceptions)); } }
private static Calendar extractSingleCalendarValue(final Iterable<Statement> statements, final Property predicate) { Calendar cal = null; for (Statement added : statements) { if (added.getPredicate().equals(predicate)) { if (cal == null) { cal = RelaxedPropertiesHelper.parseExpectedXsdDateTimeValue(added.getObject()); } else { throw new MalformedRdfException(predicate + " may only appear once!"); } } } return cal; }
new RdfRemover(idTranslator, getSession(), diffStream).consume(); } catch (final MalformedRdfException e) { exceptions.append(e.getMessage()); exceptions.append("\n"); } catch (final ConstraintViolationException e) { exceptions.append(e.getMessage()); } catch (final ConstraintViolationException e) { throw e; throw new MalformedRdfException(exceptions.toString());
private static String extractSingleStringValue(final Iterable<Statement> statements, final Property predicate) { String username = null; for (Statement added : statements) { if (added.getPredicate().equals(predicate)) { if (username == null) { username = added.getObject().asLiteral().getString(); } else { throw new MalformedRdfException(predicate + " may only appear once!"); } } } return username; }
protected void operateOnTriple(final Statement input) { try { final Statement t = jcrRdfTools.skolemize(idTranslator, input, stream().topic().toString()); final Resource subject = t.getSubject(); final FedoraResource subjectNode = translator().convert(subject); // if this is a user-managed RDF type assertion, update the node's // mixins. If it isn't, treat it as a "data" property. if (t.getPredicate().equals(type) && t.getObject().isResource()) { final Resource mixinResource = t.getObject().asResource(); if (!isManagedMixin.test(mixinResource)) { LOGGER.debug("Operating on node: {} with mixin: {}.", subjectNode, mixinResource); operateOnMixin(mixinResource, subjectNode); } else { LOGGER.error("Found repository-managed mixin {} in triple {} on which we will not operate.", mixinResource, t); throw new ServerManagedTypeException(String.format( "The repository type (%s) of this resource is system managed.", mixinResource)); } } else { LOGGER.debug("Operating on node: {} from triple: {}.", subjectNode, t); operateOnProperty(t, subjectNode); } } catch (final ConstraintViolationException e) { throw e; } catch (final RepositoryException | RepositoryRuntimeException e) { throw new MalformedRdfException(e.getMessage(), e); } }
/** * Parse the request body as a Model. * * @param requestBodyStream rdf request body * @param contentType content type of body * @param resource the fedora resource * @return Model containing triples from request body * @throws MalformedRdfException in case rdf json cannot be parsed */ private Model parseBodyAsModel(final InputStream requestBodyStream, final MediaType contentType, final FedoraResource resource) throws MalformedRdfException { final Lang format = contentTypeToLang(contentType.toString()); final Model inputModel; try { inputModel = createDefaultModel(); inputModel.read(requestBodyStream, getUri(resource).toString(), format.getName().toUpperCase()); return inputModel; } catch (final RiotException e) { throw new BadRequestException("RDF was not parsable: " + e.getMessage(), e); } catch (final RuntimeIOException e) { if (e.getCause() instanceof JsonParseException) { throw new MalformedRdfException(e.getCause()); } throw new RepositoryRuntimeException(e); } }
node.addMixin(mixinName); } else { throw new MalformedRdfException("Could not persist triple containing type assertion: " + mixinResource.toString() + " because no such mixin/type can be added to this node: "
@Override protected void operateOnTriple(final Statement input) throws MalformedRdfException { try { final Statement t = jcrRdfTools().skolemize(translator(), input, stream().topic().toString()); final Resource subject = t.getSubject(); final FedoraResource subjectNode = translator().convert(subject); // if this is a user-managed RDF type assertion, update the node's // mixins. If it isn't, treat it as a "data" property. if (t.getPredicate().equals(type) && t.getObject().isResource()) { final Resource mixinResource = t.getObject().asResource(); LOGGER.debug("Operating on node: {} with mixin: {}.", subjectNode.getPath(), mixinResource); operateOnMixin(mixinResource, subjectNode); } else { LOGGER.debug("Operating on node: {} from triple: {}.", subjectNode.getPath(), t); operateOnProperty(t, subjectNode); } } catch (final RepositoryException | RepositoryRuntimeException e) { throw new MalformedRdfException(e.getMessage(), e); } }
return valueFactory.createValue(nodeFromGraphSubject, type == WEAKREFERENCE); } catch (final RepositoryRuntimeException e) { throw new MalformedRdfException("Unable to find referenced node", e);