Beispiel #1
0
  @Test
  public void testReplaceObjectGraphWithErrors() {
    final String pid = getRandomPid();
    final Container object = containerService.findOrCreate(session, pid);

    final Model model =
        createDefaultModel()
            .read(
                toInputStream(
                    "<> <info:some-property> <relative-url> . \n"
                        + "<> <info:some-other-property> <another-relative-url>"),
                subjects.reverse().convert(object).toString(),
                "TTL");
    MalformedRdfException e = null;
    try {
      object.replaceProperties(subjects, model, object.getTriples(subjects, emptySet()));
    } catch (final MalformedRdfException ex) {
      e = ex;
    }

    assertNotNull("Expected an exception to get thrown", e);
    assertEquals("Excepted two nested exceptions", 2, e.getMessage().split("\n").length);
    assertTrue(e.getMessage().contains("/relative-url"));
    assertTrue(e.getMessage().contains("/another-relative-url"));
  }
  /* (non-Javadoc)
   * @see org.fcrepo.kernel.api.models.FedoraResource#replaceProperties
   *     (org.fcrepo.kernel.api.identifiers.IdentifierConverter, com.hp.hpl.jena.rdf.model.Model)
   */
  @Override
  public void replaceProperties(
      final IdentifierConverter<Resource, FedoraResource> idTranslator,
      final Model inputModel,
      final RdfStream originalTriples)
      throws MalformedRdfException {

    final RdfStream replacementStream =
        new RdfStream()
            .namespaces(inputModel.getNsPrefixMap())
            .topic(idTranslator.reverse().convert(this).asNode());

    final GraphDifferencingIterator differencer =
        new GraphDifferencingIterator(inputModel, originalTriples);

    final StringBuilder exceptions = new StringBuilder();
    try {
      new RdfRemover(idTranslator, getSession(), replacementStream.withThisContext(differencer))
          .consume();
    } catch (final ConstraintViolationException e) {
      throw e;
    } catch (final MalformedRdfException e) {
      exceptions.append(e.getMessage());
      exceptions.append("\n");
    }

    try {
      new RdfAdder(
              idTranslator,
              getSession(),
              replacementStream.withThisContext(differencer.notCommon()))
          .consume();
    } catch (final ConstraintViolationException e) {
      throw e;
    } catch (final MalformedRdfException e) {
      exceptions.append(e.getMessage());
    }

    if (exceptions.length() > 0) {
      throw new MalformedRdfException(exceptions.toString());
    }
  }
Beispiel #3
0
  @Test
  public void testUpdatingObjectGraphWithErrors() {
    final String pid = getRandomPid();
    final Container object = containerService.findOrCreate(session, pid);

    MalformedRdfException e = null;
    try {
      object.updateProperties(
          subjects,
          "INSERT DATA { <> <info:some-property> <relative-url> . \n"
              + "<> <info:some-other-property> <another-relative-url> }",
          object.getTriples(subjects, emptySet()));
    } catch (final MalformedRdfException ex) {
      e = ex;
    }

    assertNotNull("Expected an exception to get thrown", e);
    assertEquals("Excepted two nested exceptions", 2, e.getMessage().split("\n").length);
    assertTrue(e.getMessage().contains("/relative-url"));
    assertTrue(e.getMessage().contains("/another-relative-url"));
  }