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

The following examples show how to use org.apache.olingo.commons.api.data.Entity#setEditLink() . 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: Services.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/StoredPIs(1000)")
public Response getStoredPI(@Context final UriInfo uriInfo) {
  final Entity entity = new Entity();
  entity.setType("Microsoft.Test.OData.Services.ODataWCFService.StoredPI");
  final Property id = new Property();
  id.setType("Edm.Int32");
  id.setName("StoredPIID");
  id.setValue(ValueType.PRIMITIVE, 1000);
  entity.getProperties().add(id);
  final Link edit = new Link();
  edit.setHref(uriInfo.getRequestUri().toASCIIString());
  edit.setRel("edit");
  edit.setTitle("StoredPI");
  entity.setEditLink(edit);

  final ByteArrayOutputStream content = new ByteArrayOutputStream();
  final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
  try {
    jsonSerializer.write(writer, new ResWrap<Entity>((URI) null, null, entity));
    return xml.createResponse(new ByteArrayInputStream(content.toByteArray()), null, Accept.JSON_FULLMETA);
  } catch (Exception e) {
    LOG.error("While creating StoredPI", e);
    return xml.createFaultResponse(Accept.JSON_FULLMETA.toString(), e);
  }
}
 
Example 2
Source File: EdmAssistedJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void metadataMin() throws Exception {
  final ServiceMetadata metadata = oData.createServiceMetadata(null, Collections.<EdmxReference> emptyList(),
      new MetadataETagSupport("W/\"42\""));
  Entity entity = new Entity();
  entity.setType("Namespace.EntityType");
  entity.setId(URI.create("ID"));
  entity.setETag("W/\"1000\"");
  Link link = new Link();
  link.setHref("editLink");
  entity.setEditLink(link);
  entity.setMediaContentSource(URI.create("media"));
  entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE,
      UUID.fromString("12345678-ABCD-1234-CDEF-123456789012")));
  EntityCollection entityCollection = new EntityCollection();
  entityCollection.getEntities().add(entity);
  Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1)\","
      + "\"@odata.metadataEtag\":\"W/\\\"42\\\"\",\"value\":[{"
      + "\"@odata.etag\":\"W/\\\"1000\\\"\","
      + "\"Property1\":\"12345678-abcd-1234-cdef-123456789012\","
      + "\"@odata.editLink\":\"editLink\","
      + "\"@odata.mediaReadLink\":\"editLink/$value\"}]}",
      serialize(serializerMin, metadata, null, entityCollection, null));
}
 
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: Services.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/Products({entityId})/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails({param:.*})")
public Response functionGetProductDetails(
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @PathParam("entityId") final String entityId,
    @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {

  try {
    final Accept acceptType;
    if (StringUtils.isNotBlank(format)) {
      acceptType = Accept.valueOf(format.toUpperCase());
    } else {
      acceptType = Accept.parse(accept);
    }

    final Entity entry = new Entity();
    entry.setType("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail");
    final Property productId = new Property();
    productId.setName("ProductID");
    productId.setType("Edm.Int32");
    productId.setValue(ValueType.PRIMITIVE, Integer.valueOf(entityId));
    entry.getProperties().add(productId);
    final Property productDetailId = new Property();
    productDetailId.setName("ProductDetailID");
    productDetailId.setType("Edm.Int32");
    productDetailId.setValue(ValueType.PRIMITIVE, 2);
    entry.getProperties().add(productDetailId);

    final Link link = new Link();
    link.setRel("edit");
    link.setHref(URI.create(
        Constants.get(ConstantKey.DEFAULT_SERVICE_URL)
            + "ProductDetails(ProductID=6,ProductDetailID=1)").toASCIIString());
    entry.setEditLink(link);

    final EntityCollection feed = new EntityCollection();
    feed.getEntities().add(entry);

    final ResWrap<EntityCollection> container = new ResWrap<EntityCollection>(
        URI.create(Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + "ProductDetail"), null,
        feed);

    return xml.createResponse(
        null,
        xml.writeEntitySet(acceptType, container),
        null,
        acceptType);
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}
 
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;
}