Пример #1
0
 private void logError(String url, Response.StatusType statusInfo) {
   logger.error(
       "Failed to complete operation on {}. Error message is ({}) : {}.",
       url,
       statusInfo.getStatusCode(),
       statusInfo.getReasonPhrase());
 }
Пример #2
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);
        }
      }
    }
  }
Пример #3
0
  public void addCatalog() {
    Response response = services.getCatalogService().request().post(Entity.xml(catalogItem));

    Response.StatusType statusInfo = response.getStatusInfo();

    if (statusInfo.getStatusCode() == Response.Status.CREATED.getStatusCode())
      status = "User added successfully";
    else status = statusInfo.getReasonPhrase();
  }
Пример #4
0
 @Override
 public String toString() {
   return "ClientResponse{"
       + "method="
       + requestContext.getMethod()
       + ", uri="
       + requestContext.getUri()
       + ", status="
       + status.getStatusCode()
       + ", reason="
       + status.getReasonPhrase()
       + "}";
 }
  @Override
  public void delete(final String code) throws InterruptedException, CrudException {
    try {
      final Response response =
          restApplicationsService.path(toLowerCase.f(code)).request().delete();
      final Response.StatusType statusInfo = response.getStatusInfo();
      log.debug("Response in delete method {}", response);

      if (NO_CONTENT != statusInfo.getStatusCode()) {
        log.error("response status expected {} but got {}", NO_CONTENT, statusInfo.getStatusCode());
        throw new CrudException(format("Impossible de supprimer l'application [%s]", code));
      }
    } catch (Exception e) {
      log.error("error in delete", e);
      if (e instanceof CrudException) {
        throw e;
      }
      throw new InterruptedException(e.getMessage());
    }
  }
Пример #6
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));
    }
  }
Пример #7
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);
    }
  }
  @Override
  public void update(final ApplicationDTO dto) throws InterruptedException, CrudException {
    log.debug("ApplicationDTO in update method {}", dto);
    try {
      final Response response =
          restApplicationsService
              .path(dto.getCode())
              .request()
              .put(entity(dto, MediaType.APPLICATION_JSON_TYPE));
      final Response.StatusType statusInfo = response.getStatusInfo();

      if (!(OK == statusInfo.getStatusCode())) {
        log.error("response status expected {} but got {}", OK, statusInfo.getStatusCode());
        throw new CrudException(format("Impossible de modifier l'application [%s]", dto.getCode()));
      }
    } catch (Exception e) {
      log.error("error in update", e);
      if (e instanceof CrudException) {
        throw e;
      }
      throw new InterruptedException(e.getMessage());
    }
  }
  @Override
  public void add(final ApplicationDTO dto) throws InterruptedException, CrudException {
    log.debug("ApplicationDTO in add method {}", dto);
    try {
      if (exists(dto.getCode())) {
        throw new CrudException("Violation de la contrainte d'unicité");
      }

      final Response response =
          restApplicationsService.request().post(entity(dto, MediaType.APPLICATION_JSON_TYPE));
      final Response.StatusType statusInfo = response.getStatusInfo();

      if (!(CREATED == statusInfo.getStatusCode())) {
        log.error("response status expected {} but got {}", CREATED, statusInfo.getStatusCode());
        throw new CrudException(format("Impossible d'ajouter l'application [%s]", dto.getCode()));
      }
    } catch (Exception e) {
      log.error("error in add", e);
      if (e instanceof CrudException) {
        throw e;
      }
      throw new InterruptedException(e.getMessage());
    }
  }
Пример #10
0
 @Override
 public int getStatus() {
   return status.getStatusCode();
 }
Пример #11
0
 public boolean statusIs(JaxRsResponse JaxRsResponse, Response.StatusType status) {
   return JaxRsResponse.getStatus() == status.getStatusCode();
 }