Exemplo n.º 1
0
  @Override
  public ODataResponse deleteEntity(DeleteUriInfo uriInfo, String contentType)
      throws ODataException {
    LOG.debug("Deleting Entity: " + uriInfo);

    if ("Cars".equals(uriInfo.getTargetEntitySet().getName())) {
      int key = getKeyValue(uriInfo.getKeyPredicates().get(0));

      // if there is no entry with this key available, one should return
      // "404 Not Found"
      // return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();

      // now one can delete the entry with this particular key in the
      // backend...

    } else if ("Manufacturers".equals(uriInfo.getTargetEntitySet().getName())) {
      int key = getKeyValue(uriInfo.getKeyPredicates().get(0));
      // now one can delete the entry with this particular key in the
      // backend...
    }

    // we can return Status Code 204 No Content because the URI Parsing
    // already guarantees that
    // a) only valid URIs are dispatched (also checked against the metadata)
    // b) 404 Not Found is already returned above, when the entry does not
    // exist
    return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
  }
Exemplo n.º 2
0
  @Override
  public ODataResponse updateEntity(
      PutMergePatchUriInfo uriInfo,
      InputStream content,
      String requestContentType,
      boolean merge,
      String contentType)
      throws ODataException {
    LOG.debug("Updating Entity: " + uriInfo);

    EntityProviderReadProperties properties =
        EntityProviderReadProperties.init().mergeSemantic(false).build();

    ODataEntry entry =
        EntityProvider.readEntry(
            requestContentType, uriInfo.getTargetEntitySet(), content, properties);
    // if something goes wrong in deserialization this is managed via the
    // ExceptionMapper,
    // no need for an application to do exception handling here an convert
    // the exceptions in HTTP exceptions

    Map<String, Object> data = entry.getProperties();

    if ("Cars".equals(uriInfo.getTargetEntitySet().getName())) {
      int key = getKeyValue(uriInfo.getKeyPredicates().get(0));

      // if there is no entry with this key available, one should return
      // "404 Not Found"
      // return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();

      // now one can use the data to create the entry in the backend ...
      String model = (String) data.get("Model");
      // ...
    } else if ("Manufacturers".equals(uriInfo.getTargetEntitySet().getName())) {
      int key = getKeyValue(uriInfo.getKeyPredicates().get(0));
      // now one can use the data to create the entry in the backend ...
    }

    // we can return Status Code 204 No Content because the URI Parsing
    // already guarantees that
    // a) only valid URIs are dispatched (also checked against the metadata)
    // b) 404 Not Found is already returned above, when the entry does not
    // exist
    return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
  }