Java Code Examples for org.apache.olingo.commons.api.data.Property#setType()

The following examples show how to use org.apache.olingo.commons.api.data.Property#setType() . 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: AtomTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * @return
 */
private Entity createEntity() {
  Entity en = new Entity();
  Property p1 = new Property();
  p1.setName("Id");
  p1.setType("Int64");
  p1.setValue(ValueType.PRIMITIVE, Long.valueOf(123));
  en.addProperty(p1);
  
  Property p2 = new Property();
  p2.setName("Name");
  p2.setType("String");
  p2.setValue(ValueType.PRIMITIVE, "ABC");
  en.addProperty(p2);
  return en;
}
 
Example 3
Source File: JSONTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * @return
 */
private Entity createEntity() {
  Entity en = new Entity();
  Property p1 = new Property();
  p1.setName("Id");
  p1.setType("Int64");
  p1.setValue(ValueType.PRIMITIVE, Long.valueOf(123));
  en.addProperty(p1);
  
  Property p2 = new Property();
  p2.setName("Name");
  p2.setType("String");
  p2.setValue(ValueType.PRIMITIVE, "ABC");
  en.addProperty(p2);
  return en;
}
 
Example 4
Source File: Services.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount{paren:[\\(\\)]*}")
public Response functionGetEmployeesCount(
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @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 Property property = new Property();
    property.setType("Edm.Int32");
    property.setValue(ValueType.PRIMITIVE, 2);
    final ResWrap<Property> container = new ResWrap<Property>(
        URI.create(Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
        property);

    return xml.createResponse(
        null,
        xml.writeProperty(acceptType, container),
        null,
        acceptType);
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}
 
Example 5
Source File: Services.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/Accounts({entityId})/MyGiftCard/Microsoft.Test.OData.Services.ODataWCFService.GetActualAmount({param:.*})")
public Response functionGetActualAmount(
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @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 Property property = new Property();
    property.setType("Edm.Double");
    property.setValue(ValueType.PRIMITIVE, 41.79);

    final ResWrap<Property> container = new ResWrap<Property>((URI) null, null, property);

    return xml.createResponse(
        null,
        xml.writeProperty(acceptType, container),
        null,
        acceptType);
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}
 
Example 6
Source File: Services.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/GetDefaultColor()")
public Response functionGetDefaultColor(
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @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 Property property = new Property();
    property.setType("Microsoft.Test.OData.Services.ODataWCFService.Color");
    property.setValue(ValueType.ENUM, "Red");
    final ResWrap<Property> container = new ResWrap<Property>(
        URI.create(Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
        property);

    return xml.createResponse(
        null,
        xml.writeProperty(acceptType, container),
        null,
        acceptType);
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}
 
Example 7
Source File: Services.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/GetProductsByAccessLevel({param:.*})")
public Response functionGetProductsByAccessLevel(
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @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 Property property = new Property();
    property.setType("Collection(String)");
    final List<String> value = Arrays.asList("Cheetos", "Mushrooms", "Apple", "Car", "Computer");
    property.setValue(ValueType.COLLECTION_PRIMITIVE, value);
    final ResWrap<Property> container = new ResWrap<Property>(
        URI.create(Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
        property);

    return xml.createResponse(
        null,
        xml.writeProperty(acceptType, container),
        null,
        acceptType);
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}
 
Example 8
Source File: Services.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/GetBossEmails({param:.*})")
public Response functionGetBossEmails(
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @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 Property property = new Property();
    property.setType("Collection(Edm.String)");
    property.setValue(ValueType.COLLECTION_PRIMITIVE,
        Arrays.asList("[email protected]", "[email protected]"));
    final ResWrap<Property> container = new ResWrap<Property>(
        URI.create(Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
        property);

    return xml.createResponse(null, xml.writeProperty(acceptType, container), null, acceptType);
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}
 
Example 9
Source File: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private Property consumePropertyNode(final String name, final EdmType type, final boolean isCollection,
    final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
    final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException {
  Property property = new Property();
  property.setName(name);
  property.setType(type.getFullQualifiedName().getFullQualifiedNameAsString());
  if (isCollection) {
    consumePropertyCollectionNode(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping, jsonNode,
        property);
  } else {
    consumePropertySingleNode(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping, jsonNode,
        property);
  }
  return property;
}
 
Example 10
Source File: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void consumePropertySingleNode(final String name, final EdmType type,
    final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
    final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode, final Property property)
    throws DeserializerException {
  switch (type.getKind()) {
  case PRIMITIVE:
  case DEFINITION:
  case ENUM:
    Object value = readPrimitiveValue(name, (EdmPrimitiveType) type,
        isNullable, maxLength, precision, scale, isUnicode, mapping, jsonNode);
    property.setValue(type.getKind() == EdmTypeKind.ENUM ? ValueType.ENUM : ValueType.PRIMITIVE,
        value);
    break;
  case COMPLEX:
    EdmType derivedType = getDerivedType((EdmComplexType) type,
        jsonNode);
    property.setType(derivedType.getFullQualifiedName()
        .getFullQualifiedNameAsString());

    value = readComplexNode(name, derivedType, isNullable, jsonNode);
    property.setValue(ValueType.COMPLEX, value);
    break;
  default:
    throw new DeserializerException("Invalid Type Kind for a property found: " + type.getKind(),
        DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, name);
  }
}
 
Example 11
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);
  }
}