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

The following examples show how to use org.apache.olingo.commons.api.data.Property#getValueType() . 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: ODataJsonSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void writePrimitiveCollection(final EdmPrimitiveType type, final Property property,
    final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
    final Boolean isUnicode, final JsonGenerator json)
    throws IOException, SerializerException {
  json.writeStartArray();
  for (Object value : property.asCollection()) {
    switch (property.getValueType()) {
    case COLLECTION_PRIMITIVE:
    case COLLECTION_ENUM:
    case COLLECTION_GEOSPATIAL:
      try {
        writePrimitiveValue(property.getName(), type, value, isNullable,
            maxLength, precision, scale, isUnicode, json);
      } catch (EdmPrimitiveTypeException e) {
        throw new SerializerException("Wrong value for property!", e,
            SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
            property.getName(), property.getValue().toString());
      }
      break;
    default:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    }
  }
  json.writeEndArray();
}
 
Example 2
Source File: JsonDeltaSerializerWithNavigations.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void writeComplexCollection(final ServiceMetadata metadata, final EdmComplexType type,
    final Property property,
    final Set<List<String>> selectedPaths, final JsonGenerator json)
    throws IOException, SerializerException {
  json.writeStartArray();
  for (Object value : property.asCollection()) {
    switch (property.getValueType()) {
    case COLLECTION_COMPLEX:
      json.writeStartObject();
      if (isODataMetadataFull) {
        json.writeStringField(Constants.JSON_TYPE, "#" +
            type.getFullQualifiedName().getFullQualifiedNameAsString());
      }
      writeComplexValue(metadata, type, ((ComplexValue) value).getValue(), selectedPaths, json);
      json.writeEndObject();
      break;
    default:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    }
  }
  json.writeEndArray();
}
 
Example 3
Source File: JsonDeltaSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void writeComplexCollection(final ServiceMetadata metadata, final EdmComplexType type,
    final Property property,
    final Set<List<String>> selectedPaths, final JsonGenerator json)
    throws IOException, SerializerException {
  json.writeStartArray();
  for (Object value : property.asCollection()) {
    switch (property.getValueType()) {
    case COLLECTION_COMPLEX:
      json.writeStartObject();
      if (isODataMetadataFull) {
        json.writeStringField(Constants.JSON_TYPE, "#" +
            type.getFullQualifiedName().getFullQualifiedNameAsString());
      }
      writeComplexValue(metadata, type, ((ComplexValue) value).getValue(), selectedPaths, json);
      json.writeEndObject();
      break;
    default:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    }
  }
  json.writeEndArray();
}
 
Example 4
Source File: ODataXmlSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void writePrimitiveCollection(final EdmPrimitiveType type, final Property property,
    final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
    final Boolean isUnicode, final String xml10InvalidCharReplacement,
    final XMLStreamWriter writer) throws XMLStreamException, EdmPrimitiveTypeException, SerializerException {
  for (Object value : property.asCollection()) {
    writer.writeStartElement(METADATA, Constants.ELEM_ELEMENT, NS_METADATA);
    switch (property.getValueType()) {
    case COLLECTION_PRIMITIVE:
    case COLLECTION_ENUM:
      writePrimitiveValue(type, value, isNullable, maxLength, precision,
          scale, isUnicode, xml10InvalidCharReplacement, writer);
      break;
    case COLLECTION_GEOSPATIAL:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    default:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    }
    writer.writeEndElement();
  }
}
 
Example 5
Source File: ODataJsonSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void writeComplexCollection(final ServiceMetadata metadata, final EdmComplexType type,
    final Property property,
    final Set<List<String>> selectedPaths, final JsonGenerator json, 
    Set<List<String>> expandedPaths, Linked linked, ExpandOption expand)
    throws IOException, SerializerException {
  json.writeStartArray();
  EdmComplexType derivedType = type;
  Set<List<String>> expandedPaths1 = expandedPaths != null && !expandedPaths.isEmpty() ? 
      expandedPaths : ExpandSelectHelper.getExpandedItemsPath(expand);
  for (Object value : property.asCollection()) {
    expandedPaths = expandedPaths1;
    derivedType = ((ComplexValue) value).getTypeName()!=null ? metadata.getEdm().getComplexType
        (new FullQualifiedName(((ComplexValue) value).getTypeName())): type;          
    switch (property.getValueType()) {
    case COLLECTION_COMPLEX:
      json.writeStartObject();
      if (isODataMetadataFull || (!isODataMetadataNone && !derivedType.equals(type))) {
           json.writeStringField(constants.getType(), "#" + 
               derivedType.getFullQualifiedName().getFullQualifiedNameAsString());
      }
      expandedPaths = expandedPaths == null || expandedPaths.isEmpty() ? null :
        ExpandSelectHelper.getReducedExpandItemsPaths(expandedPaths, property.getName());
      writeComplexValue(metadata, derivedType, ((ComplexValue) value).getValue(), 
          selectedPaths, json, expandedPaths, (ComplexValue) value, expand, property.getName());
      json.writeEndObject();
      break;
    default:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    }
  }
  json.writeEndArray();
}
 
Example 6
Source File: JsonDeltaSerializerWithNavigations.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void writePrimitiveCollection(final EdmPrimitiveType type, final Property property,
    final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
    final Boolean isUnicode, final JsonGenerator json)
    throws IOException, SerializerException {
  json.writeStartArray();
  for (Object value : property.asCollection()) {
    switch (property.getValueType()) {
    case COLLECTION_PRIMITIVE:
    case COLLECTION_ENUM:
      try {
        writePrimitiveValue(property.getName(), type, value, isNullable,
            maxLength, precision, scale, isUnicode, json);
      } catch (EdmPrimitiveTypeException e) {
        throw new SerializerException("Wrong value for property!", e,
            SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
            property.getName(), property.getValue().toString());
      }
      break;
    case COLLECTION_GEOSPATIAL:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    default:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    }
  }
  json.writeEndArray();
}
 
Example 7
Source File: JsonDeltaSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void writePrimitiveCollection(final EdmPrimitiveType type, final Property property,
    final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
    final Boolean isUnicode, final JsonGenerator json)
    throws IOException, SerializerException {
  json.writeStartArray();
  for (Object value : property.asCollection()) {
    switch (property.getValueType()) {
    case COLLECTION_PRIMITIVE:
    case COLLECTION_ENUM:
      try {
        writePrimitiveValue(property.getName(), type, value, isNullable,
            maxLength, precision, scale, isUnicode, json);
      } catch (EdmPrimitiveTypeException e) {
        throw new SerializerException("Wrong value for property!", e,
            SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
            property.getName(), property.getValue().toString());
      }
      break;
    case COLLECTION_GEOSPATIAL:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    default:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    }
  }
  json.writeEndArray();
}
 
Example 8
Source File: ODataXmlSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void writeComplexCollection(final ServiceMetadata metadata,
    final EdmComplexType type, final Property property, final Set<List<String>> selectedPaths,
    final String xml10InvalidCharReplacement, final XMLStreamWriter writer, 
    Set<List<String>> expandedPaths, Linked linked, ExpandOption expand)
    throws XMLStreamException, SerializerException {
  EdmComplexType complexType = type;
  Set<List<String>> expandedPaths1 = expandedPaths != null && !expandedPaths.isEmpty() ? 
      expandedPaths : ExpandSelectHelper.getExpandedItemsPath(expand);
  for (Object value : property.asCollection()) {
    expandedPaths = expandedPaths1;
    writer.writeStartElement(METADATA, Constants.ELEM_ELEMENT, NS_METADATA);
    String typeName = ((ComplexValue)value).getTypeName();
    String propertyType = typeName != null ? typeName :property.getType();
    if (derivedComplexType(type, propertyType ) != null) {
      writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, propertyType);
    }
    if(typeName!=null && !propertyType.equals(type.getFullQualifiedName().getFullQualifiedNameAsString())){
      complexType = (EdmComplexType) (metadata.getEdm().getComplexType(new FullQualifiedName(propertyType)));
    }else{
      complexType = type;
    }
    switch (property.getValueType()) {
    case COLLECTION_COMPLEX:
      expandedPaths = expandedPaths == null || expandedPaths.isEmpty() ? null :
        ExpandSelectHelper.getReducedExpandItemsPaths(expandedPaths, property.getName());
      writeComplexValue(metadata, complexType,
          ((ComplexValue) value).getValue(), selectedPaths,
          xml10InvalidCharReplacement, writer, expandedPaths, (ComplexValue) value, expand, property.getName());
      break;
    default:
      throw new SerializerException("Property type not yet supported!",
          SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
    }
    writer.writeEndElement();
  }
}