Java Code Examples for org.apache.olingo.commons.api.data.Entity#setMediaETag()

The following examples show how to use org.apache.olingo.commons.api.data.Entity#setMediaETag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityMediaWithMetadataFull() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
  final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
  entity.setMediaETag("W/\\\"08D25949E3BFB7AB\\\"");
  InputStream result = serializerFullMetadata
      .entity(metadata, edmEntitySet.getEntityType(), entity,
          EntitySerializerOptions.with().contextURL(ContextURL.with()
              .entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()).build())
      .getContent();
  final String resultString = IOUtils.toString(result);
  final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia/$entity\","
      + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
      + "\"@odata.mediaEtag\":\"W/\\\\\\\"08D25949E3BFB7AB\\\\\\\"\",\"@odata.mediaContentType\":\"image/svg+xml\","
      + "\"@odata.mediaEditLink\":\"ESMedia(1)/$value\","
      + "\"@odata.type\":\"#olingo.odata.test1.ETMedia\",\"@odata.id\":\"ESMedia(1)\","
      + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":1}";
  Assert.assertEquals(expectedResult, resultString);
}
 
Example 2
Source File: ODataJsonSerializerv01Test.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityMediaWithMetadataFull() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
  final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
  entity.setMediaETag("W/\\\"08D25949E3BFB7AB\\\"");
  InputStream result = serializerFullMetadata
      .entity(metadata, edmEntitySet.getEntityType(), entity,
          EntitySerializerOptions.with().contextURL(ContextURL.with()
              .entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()).build())
      .getContent();
  final String resultString = IOUtils.toString(result);
  final String expectedResult = "{\"@context\":\"$metadata#ESMedia/$entity\","
      + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\","
      + "\"@mediaEtag\":\"W/\\\\\\\"08D25949E3BFB7AB\\\\\\\"\",\"@mediaContentType\":\"image/svg+xml\","
      + "\"@mediaEditLink\":\"ESMedia(1)/$value\","
      + "\"@type\":\"#olingo.odata.test1.ETMedia\",\"@id\":\"ESMedia(1)\","
      + "\"PropertyInt16@type\":\"#Int16\",\"PropertyInt16\":1}";
  Assert.assertEquals(expectedResult, resultString);
}
 
Example 3
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private EntityCollection createESMedia(final Edm edm, final OData odata) {
  EntityCollection entityCollection = new EntityCollection();

  Entity entity = new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 1))
      .addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("darkturquoise")));
  entity.setMediaContentType("image/svg+xml");
  entity.setMediaETag("W/\"1\"");
  entity.getMediaEditLinks().add(buildMediaLink("ESMedia", "ESMedia(1)/$value"));
  entityCollection.getEntities().add(entity);

  entity = new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 2))
      .addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("royalblue")));
  entity.setMediaContentType("image/svg+xml");
  entity.setMediaETag("W/\"2\"");
  entity.getMediaEditLinks().add(buildMediaLink("ESMedia", "ESMedia(2)/$value"));
  entityCollection.getEntities().add(entity);

  entity = new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 3))
      .addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("crimson")));
  entity.setMediaContentType("image/svg+xml");
  entity.setMediaETag("W/\"3\"");
  entity.getMediaEditLinks().add(buildMediaLink("ESMedia", "ESMedia(3)/$value"));
  entityCollection.getEntities().add(entity);

  entity = new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 4))
      .addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("black")));
  entity.setMediaContentType("image/svg+xml");
  entity.setMediaETag("W/\"4\"");
  entity.getMediaEditLinks().add(buildMediaLink("ESMedia", "ESMedia(4)/$value"));
  entityCollection.getEntities().add(entity);

  setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETMedia));
  createEntityId(edm, odata, "ESMedia", entityCollection);
  createOperations("ESMedia", entityCollection, EntityTypeProvider.nameETMedia);
  return entityCollection;
}
 
Example 4
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private EntityCollection createESMediaStream(final Edm edm, final OData odata) {
  EntityCollection entityCollection = new EntityCollection();

  Entity entity = new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 1))
      .addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("darkturquoise")));
  entity.setMediaContentType("image/svg+xml");
  entity.setMediaETag("W/\"1\"");
  entity.getMediaEditLinks().add(buildMediaLink("ESMediaStream", "ESMediaStream(1)/$value"));
  entityCollection.getEntities().add(entity);

  entity = new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 2))
      .addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("royalblue")));
  entity.setMediaContentType("image/svg+xml");
  entity.setMediaETag("W/\"2\"");
  entity.getMediaEditLinks().add(buildMediaLink("ESMediaStream", "ESMediaStream(2)/$value"));
  entityCollection.getEntities().add(entity);

  entity = new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 3))
      .addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("crimson")));
  entity.setMediaContentType("image/svg+xml");
  entity.setMediaETag("W/\"3\"");
  entity.getMediaEditLinks().add(buildMediaLink("ESMediaStream", "ESMediaStream(3)/$value"));
  entityCollection.getEntities().add(entity);

  entity = new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 4))
      .addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("black")));
  entity.setMediaContentType("image/svg+xml");
  entity.setMediaETag("W/\"4\"");
  entity.getMediaEditLinks().add(buildMediaLink("ESMediaStream", "ESMediaStream(4)/$value"));
  entityCollection.getEntities().add(entity);

  setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETMedia));
  createEntityId(edm, odata, "ESMediaStream", entityCollection);
  createOperations("ESMediaStream", entityCollection, EntityTypeProvider.nameETMedia);
  return entityCollection;
}
 
Example 5
Source File: TransactionalEntityManager.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private Entity copyEntity(final Entity entity) {
  final Entity newEntity = new Entity();
  newEntity.setBaseURI(entity.getBaseURI());
  newEntity.setEditLink(entity.getEditLink());
  newEntity.setETag(entity.getETag());
  newEntity.setId(entity.getId());
  newEntity.setMediaContentSource(entity.getMediaContentSource());
  newEntity.setMediaContentType(entity.getMediaContentType());
  newEntity.setSelfLink(entity.getSelfLink());
  newEntity.setMediaETag(entity.getMediaETag());
  newEntity.setType(entity.getType());
  newEntity.getProperties().addAll(entity.getProperties());
  
  return newEntity;
}
 
Example 6
Source File: TransactionalEntityManager.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private Entity copyEntity(final Entity entity) {
  final Entity newEntity = new Entity();
  newEntity.setBaseURI(entity.getBaseURI());
  newEntity.setEditLink(entity.getEditLink());
  newEntity.setETag(entity.getETag());
  newEntity.setId(entity.getId());
  newEntity.setMediaContentSource(entity.getMediaContentSource());
  newEntity.setMediaContentType(entity.getMediaContentType());
  newEntity.setSelfLink(entity.getSelfLink());
  newEntity.setMediaETag(entity.getMediaETag());
  newEntity.setType(entity.getType());
  newEntity.getProperties().addAll(entity.getProperties());
  
  return newEntity;
}
 
Example 7
Source File: TransactionalEntityManager.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private Entity copyEntity(final Entity entity) {
  final Entity newEntity = new Entity();
  newEntity.setBaseURI(entity.getBaseURI());
  newEntity.setEditLink(entity.getEditLink());
  newEntity.setETag(entity.getETag());
  newEntity.setId(entity.getId());
  newEntity.setMediaContentSource(entity.getMediaContentSource());
  newEntity.setMediaContentType(entity.getMediaContentType());
  newEntity.setSelfLink(entity.getSelfLink());
  newEntity.setMediaETag(entity.getMediaETag());
  newEntity.setType(entity.getType());
  newEntity.getProperties().addAll(entity.getProperties());
  
  return newEntity;
}
 
Example 8
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public void setMedia(final Entity entity, final byte[] media, final String type) {
  entity.getProperties().remove(entity.getProperty(MEDIA_PROPERTY_NAME));
  entity.addProperty(DataCreator.createPrimitive(MEDIA_PROPERTY_NAME, media));
  entity.setMediaContentType(type);
  entity.setMediaETag("W/\"" + UUID.randomUUID() + "\"");
}
 
Example 9
Source File: ODataBinderImpl.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public Entity getEntity(final ClientEntity odataEntity) {
  final Entity entity = new Entity();

  entity.setType(odataEntity.getTypeName() == null ? null : odataEntity.getTypeName().toString());

  // -------------------------------------------------------------
  // Add edit and self link
  // -------------------------------------------------------------
  final URI odataEditLink = odataEntity.getEditLink();
  if (odataEditLink != null) {
    final Link editLink = new Link();
    editLink.setTitle(entity.getType());
    editLink.setHref(odataEditLink.toASCIIString());
    editLink.setRel(Constants.EDIT_LINK_REL);
    entity.setEditLink(editLink);
  }

  if (odataEntity.isReadOnly()) {
    final Link selfLink = new Link();
    selfLink.setTitle(entity.getType());
    selfLink.setHref(odataEntity.getLink().toASCIIString());
    selfLink.setRel(Constants.SELF_LINK_REL);
    entity.setSelfLink(selfLink);
  }
  // -------------------------------------------------------------

  links(odataEntity, entity);

  // -------------------------------------------------------------
  // Append edit-media links
  // -------------------------------------------------------------
  for (ClientLink link : odataEntity.getMediaEditLinks()) {
    LOG.debug("Append edit-media link\n{}", link);
    entity.getMediaEditLinks().add(getLink(link));
  }
  // -------------------------------------------------------------

  if (odataEntity.isMediaEntity()) {
    entity.setMediaContentSource(odataEntity.getMediaContentSource());
    entity.setMediaContentType(odataEntity.getMediaContentType());
    entity.setMediaETag(odataEntity.getMediaETag());
  }

  for (ClientProperty property : odataEntity.getProperties()) {
    entity.getProperties().add(getProperty(property));
  }

  entity.setId(odataEntity.getId());
  annotations(odataEntity, entity);
  return entity;
}