示例#1
0
  private void batchDelete(
      final EntityTypeInvocationHandler handler,
      final ODataEntity entity,
      final ODataChangeset changeset) {

    LOG.debug("Delete '{}'", entity.getEditLink());

    final ODataDeleteRequest req =
        ODataCUDRequestFactory.getDeleteRequest(
            URIUtils.getURI(factory.getServiceRoot(), entity.getEditLink().toASCIIString()));

    if (StringUtils.isNotBlank(handler.getETag())) {
      req.setIfMatch(handler.getETag());
    }

    changeset.addRequest(req);
  }
  @Override
  public ODataEntityUpdateRequest getEntityUpdateRequest(
      final UpdateType type, final ODataEntity entity) {
    if (entity.getEditLink() == null) {
      throw new IllegalArgumentException("No edit link found");
    }

    final ODataEntityUpdateRequest req;

    if (client.getConfiguration().isUseXHTTPMethod()) {
      req = new ODataEntityUpdateRequest(client, HttpMethod.POST, entity.getEditLink(), entity);
      req.setXHTTPMethod(type.getMethod().name());
    } else {
      req = new ODataEntityUpdateRequest(client, type.getMethod(), entity.getEditLink(), entity);
    }

    return req;
  }
  public void delete(
      final ODataPubFormat format,
      final ODataEntity created,
      final boolean includeInline,
      final String baseUri) {

    final Set<URI> toBeDeleted = new HashSet<URI>();
    toBeDeleted.add(created.getEditLink());

    if (includeInline) {
      for (ODataLink link : created.getNavigationLinks()) {
        if (link instanceof ODataInlineEntity) {
          final ODataEntity inline = ((ODataInlineEntity) link).getEntity();
          if (inline.getEditLink() != null) {
            toBeDeleted.add(URIUtils.getURI(baseUri, inline.getEditLink().toASCIIString()));
          }
        }
        if (link instanceof ODataInlineEntitySet) {
          final ODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
          for (ODataEntity entity : inline.getEntities()) {
            if (entity.getEditLink() != null) {
              toBeDeleted.add(URIUtils.getURI(baseUri, entity.getEditLink().toASCIIString()));
            }
          }
        }
      }
    }
    assertFalse(toBeDeleted.isEmpty());

    for (URI link : toBeDeleted) {
      final ODataDeleteRequest deleteReq = client.getCUDRequestFactory().getDeleteRequest(link);
      deleteReq.setFormat(format);
      final ODataDeleteResponse deleteRes = deleteReq.execute();
      assertEquals(204, deleteRes.getStatusCode());
      assertEquals("No Content", deleteRes.getStatusMessage());

      deleteRes.close();
    }
  }
示例#4
0
  private void batchUpdate(
      final EntityTypeInvocationHandler handler,
      final ODataEntity changes,
      final ODataChangeset changeset) {

    LOG.debug("Update '{}'", changes.getEditLink());

    final ODataEntityUpdateRequest req =
        ODataCUDRequestFactory.getEntityUpdateRequest(UpdateType.PATCH, changes);
    req.setPrefer(ODataHeaderValues.preferReturnContent);

    if (StringUtils.isNotBlank(handler.getETag())) {
      req.setIfMatch(handler.getETag());
    }

    changeset.addRequest(req);
  }
  private void readAndWrite(final ODataPubFormat format) {
    final InputStream input = getClass().getResourceAsStream("Customer_-10." + getSuffix(format));
    final ODataEntity entity =
        getClient()
            .getBinder()
            .getODataEntity(
                getClient()
                    .getDeserializer()
                    .toEntry(input, getClient().getResourceFactory().entryClassForFormat(format)));
    assertNotNull(entity);

    assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getName());
    assertTrue(entity.getEditLink().toASCIIString().endsWith("/Customer(-10)"));
    assertEquals(5, entity.getNavigationLinks().size());
    assertEquals(2, entity.getEditMediaLinks().size());

    boolean check = false;

    for (ODataLink link : entity.getNavigationLinks()) {
      if ("Wife".equals(link.getName())
          && (link.getLink().toASCIIString().endsWith("/Customer(-10)/Wife"))) {
        check = true;
      }
    }

    assertTrue(check);

    final ODataEntity written =
        getClient()
            .getBinder()
            .getODataEntity(
                getClient()
                    .getBinder()
                    .getEntry(
                        entity, getClient().getResourceFactory().entryClassForFormat(format)));
    assertEquals(entity, written);
  }