Esempio n. 1
0
  private void updateBinary(ZdoModel model) throws IOException {
    try (InputStream in = model.getContent()) {
      Response.StatusType statusInfo =
          ClientBuilder.newClient()
              .target(fitTransactionToUrl(model.getUrl()))
              .request()
              .put(Entity.entity(in, model.get(ZdoTerms.mimeType)))
              .getStatusInfo();

      if (statusInfo.getFamily() != Response.Status.Family.SUCCESSFUL) {
        logError(model.getUrl(), statusInfo);
        throw new IOException("Failed to update resource " + model.getUrl());
      } else {
        model.setUrl(model.getUrl() + "/fcr:metadata");
        patchMetadata(model);
        model.setUrl(
            model.getUrl().substring(0, model.getUrl().length() - "/fcr:metadata".length()));

        // Also update triplestore
        model.stripPossibleBadUrlEnding(); // strip fcr:metadata
        if (transactionPath == null) {
          sparqlOnDemandIndexer.update(model);
        } else { // If in transaction, triplestore operations are delayed till its end
          toUpdate.add(model);
        }
      }
    }
  }
Esempio n. 2
0
  public void patchMetadata(ZdoModel model) {
    // Warning: this does not go to triplestore
    // Warning: this will work only for this use case but fail miserably if used for something else
    /*  We tried to update fedora with the updateMetadata() method, but it fails with 400.
    This happens only when using transaction and trying to update metadata node that was just inserted.
    Theory is, that fedora does not realize this operation should be on temporary transaction node
    and tries to perform update on non-transaction node (which does not exist until transaction is committed.
    Hence, we use this sparql workaround that does not have this error.
    */
    String updateString = "INSERT {   \n";
    StmtIterator iter = model.listStatements();
    if (!iter.hasNext()) {
      return; // If there is nothing to update, return
    }
    while (iter.hasNext()) {
      Statement statement = iter.next();
      String subject = statement.getSubject().getURI();
      String predicate = statement.getPredicate().getURI();
      if (!predicate.startsWith("http://inqool.cz/zdo/") && !predicate.startsWith(DCTerms.NS)) {
        continue;
      }
      String value = statement.getObject().asLiteral().getString();

      String updateLine =
          " <" + fitTransactionToUrl(subject) + "> <" + predicate + "> \"" + value + "\".\n";
      updateString += updateLine;
    }
    updateString += "}\nWHERE { }";

    Response response =
        ClientBuilder.newClient()
            .target(fitTransactionToUrl(model.getUrl()))
            .request()
            .method("PATCH", Entity.entity(updateString, "application/sparql-update"));

    if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
      logError(model.getUrl(), response.getStatusInfo());
      throw new RuntimeException("Failed to update resource " + model.getUrl());
    }
  }
Esempio n. 3
0
  public void delete(String url) {
    Response.StatusType statusInfo =
        ClientBuilder.newClient()
            .target(fitTransactionToUrl(url))
            .request()
            .delete()
            .getStatusInfo();

    if (statusInfo.getFamily() != Response.Status.Family.SUCCESSFUL) {
      logError(fitTransactionToUrl(url), statusInfo);
      // Delete operations mostly fail because the item already is not there - which can be
      // considered a desired state, so no exception
      /*throw new IOException("Failed to update resource " + fitTransactionToUrl(url));*/
    }

    // Also update triplestore
    if (transactionPath == null) {
      sparqlOnDemandIndexer.remove(removeTransactionFromUrl(url));
    } else { // If in transaction, triplestore operations are delayed till its end
      toDelete.add(removeTransactionFromUrl(url));
    }
  }
Esempio n. 4
0
  private void updateMetadata(ZdoModel model) throws IOException {
    Response.StatusType statusInfo =
        ClientBuilder.newClient()
            .target(fitTransactionToUrl(model.getUrl()))
            .request()
            .put(Entity.entity(model, RDF_SERIALIZATION))
            .getStatusInfo();

    if (statusInfo.getFamily() != Response.Status.Family.SUCCESSFUL) {
      logError(fitTransactionToUrl(model.getUrl()), statusInfo);
      throw new IOException("Failed to update resource " + fitTransactionToUrl(model.getUrl()));
    }

    model.removeAllValuesOfProperty(ZdoTerms.fedoraLastModified);
    if (ZdoType.isAbovePageCategory(model.get(ZdoTerms.zdoType))) {
      model.add(
          model.getSubject(),
          ZdoTerms.fedoraLastModified,
          OffsetDateTime.now().toString(),
          XSDDatatype.XSDdateTime);
      if (model.get(ZdoTerms.fedoraCreated) == null) {
        model.add(
            model.getSubject(),
            ZdoTerms.fedoraCreated,
            OffsetDateTime.now().toString(),
            XSDDatatype.XSDdateTime);
      }
    } else {
      model.removeAllValuesOfProperty(ZdoTerms.fedoraCreated);
    }

    // Also update triplestore
    model.stripPossibleBadUrlEnding(); // strip fcr:metadata
    if (transactionPath == null) {
      sparqlOnDemandIndexer.update(model);
    } else { // If in transaction, triplestore operations are delayed till its end
      toUpdate.add(model);
    }
  }