void doDelete(final HttpServletRequest req, final HttpServletResponse resp) {
    try {
      // Parse out the required API versions.
      final AcceptAPIVersion acceptVersion = parseAcceptAPIVersion(req);

      // Prepare response.
      prepareResponse(req, resp);

      // Validate request.
      preprocessRequest(req);
      rejectIfNoneMatch(req);

      final Map<String, String[]> parameters = req.getParameterMap();
      final DeleteRequest request =
          Requests.newDeleteRequest(getResourceName(req)).setRevision(getIfMatch(req));
      for (final Map.Entry<String, String[]> p : parameters.entrySet()) {
        final String name = p.getKey();
        final String[] values = p.getValue();
        if (parseCommonParameter(name, values, request)) {
          continue;
        } else {
          request.setAdditionalParameter(name, asSingleValue(name, values));
        }
      }
      doRequest(req, resp, acceptVersion, request);
    } catch (final Exception e) {
      fail(req, resp, e);
    }
  }
Ejemplo n.º 2
0
  /**
   * Deletes the specified object from the object set.
   *
   * <p>{@inheritDoc}
   *
   * @throws NotFoundException if the specified object could not be found.
   * @throws ForbiddenException if access to the object is forbidden.
   * @throws ConflictException if version is required but is {@code null}.
   * @throws PreconditionFailedException if version did not match the existing object in the set.
   */
  @Override
  public ResourceResponse delete(DeleteRequest request) throws ResourceException {
    if (request.getResourcePathObject().size() < 2) {
      throw new NotFoundException(
          "The object identifier did not include sufficient information to determine the object type and identifier of the object to update: "
              + request.getResourcePath());
    }

    if (request.getRevision() == null || "".equals(request.getRevision())) {
      throw new ConflictException(
          "Object passed into delete does not have revision it expects set.");
    }

    final String type = request.getResourcePathObject().parent().toString();
    final String localId = request.getResourcePathObject().leaf();

    int ver =
        DocumentUtil.parseVersion(
            request.getRevision()); // This throws ConflictException if parse fails

    ODatabaseDocumentTx db = getConnection();
    try {
      ODocument existingDoc = predefinedQueries.getByID(localId, type, db);
      if (existingDoc == null) {
        throw new NotFoundException(
            "Object does not exist for delete on: " + request.getResourcePath());
      }

      db.delete(existingDoc.getIdentity(), new OSimpleVersion(ver));
      logger.debug("delete for id succeeded: {} revision: {}", localId, request.getRevision());
      return DocumentUtil.toResource(existingDoc);
    } catch (ODatabaseException ex) {
      // Without transaction the concurrent modification exception gets nested instead
      if (isCauseConcurrentModificationException(ex, 10)) {
        throw new PreconditionFailedException(
            "Delete rejected as current Object revision is different than expected by caller, the object has changed since retrieval. "
                + ex.getMessage(),
            ex);
      } else {
        throw ex;
      }

    } catch (OConcurrentModificationException ex) {
      throw new PreconditionFailedException(
          "Delete rejected as current Object revision is different than expected by caller, the object has changed since retrieval."
              + ex.getMessage(),
          ex);
    } catch (RuntimeException e) {
      throw e;
    } finally {
      if (db != null) {
        db.close();
      }
    }
  }
Ejemplo n.º 3
0
 /**
  * TODO: Description.
  *
  * @throws SynchronizationException TODO.
  */
 void delete() throws SynchronizationException {
   if (_id != null) { // forgiving delete
     try {
       DeleteRequest r = Requests.newDeleteRequest(linkId(_id));
       r.setRevision(_rev);
       mapping
           .getService()
           .getConnectionFactory()
           .getConnection()
           .delete(mapping.getService().getServerContext(), r);
     } catch (ResourceException ose) {
       LOGGER.warn("Failed to delete link", ose);
       throw new SynchronizationException(ose);
     }
     clear();
   }
 }
Ejemplo n.º 4
0
  /**
   * Removes the <code>Dictionary</code> for the given <code>pid</code>. If such a dictionary does
   * not exist, this method has no effect.
   *
   * @param pid The identifier of the dictionary to delet.
   * @throws IOException If an error occurrs deleting the dictionary. This exception must not be
   *     thrown if no dictionary with the given identifier exists.
   */
  public void delete(String pid) throws IOException {
    logger.debug("delete call for {}", pid);
    Object removed = tempStore.remove(pid);
    if (removed != null) {
      logger.debug("Deleted {} from temporary store", pid);
    }
    try {
      if (isReady(0) && requireRepository) {
        String id = pidToId(pid);
        boolean retry;
        String rev = null;
        do {
          retry = false;
          try {

            ReadRequest readRequest = Requests.newReadRequest(id);
            Map<String, Object> existing = repo.read(readRequest).getContent().asMap();
            if (existing != null) {
              rev = (String) existing.get("_rev");
              DeleteRequest r = Requests.newDeleteRequest(id);
              r.setRevision(rev);
              repo.delete(r);
              logger.debug("Deleted {}", pid);
            }
          } catch (PreconditionFailedException ex) {
            logger.debug("Concurrent change during delete, retrying {} {}", pid, rev);
            retry = true;
          } catch (NotFoundException ex) {
            // If it doesn't exists (anymore) that's fine
          }
        } while (retry);
      }
    } catch (ResourceException ex) {
      throw new IOException(
          "Failed to delete configuration + " + pid + " in repository: " + ex.getMessage(), ex);
    }
  }