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

The following examples show how to use org.apache.olingo.commons.api.data.Entity#setMediaContentType() . 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: 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 2
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 3
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 4
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 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: 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 7
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;
}
 
Example 8
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public void updateMedia(final Entity entity, final String mediaContentType, final byte[] data) {
  entity.getProperties().remove(entity.getProperty(MEDIA_PROPERTY_NAME));
  entity.addProperty(new Property(null, MEDIA_PROPERTY_NAME, ValueType.PRIMITIVE, data));
  entity.setMediaContentType(mediaContentType);
}
 
Example 9
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public void updateMedia(final Entity entity, final String mediaContentType, final byte[] data) {
  entity.getProperties().remove(entity.getProperty(MEDIA_PROPERTY_NAME));
  entity.addProperty(new Property(null, MEDIA_PROPERTY_NAME, ValueType.PRIMITIVE, data));
  entity.setMediaContentType(mediaContentType);
}