org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind Java Examples

The following examples show how to use org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind. 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: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void checkEqualityTypes(final Expression left, final Expression right) throws UriParserException {
  checkNoCollection(left);
  checkNoCollection(right);

  final EdmType leftType = getType(left);
  final EdmType rightType = getType(right);
  if (leftType == null || rightType == null || leftType.equals(rightType)) {
    return;
  }

  // Numeric promotion for Edm.Byte and Edm.SByte
  if (isType(leftType, EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte)
      && isType(rightType, EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte)) {
    return;
  }

  if (leftType.getKind() != EdmTypeKind.PRIMITIVE
      || rightType.getKind() != EdmTypeKind.PRIMITIVE
      || !(((EdmPrimitiveType) leftType).isCompatible((EdmPrimitiveType) rightType)
      || ((EdmPrimitiveType) rightType).isCompatible((EdmPrimitiveType) leftType))) {
    throw new UriParserSemanticException("Incompatible types.",
        UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE,
        leftType.getFullQualifiedName().getFullQualifiedNameAsString(),
        rightType.getFullQualifiedName().getFullQualifiedNameAsString());
  }
}
 
Example #2
Source File: Storage.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private static ComplexValue createSpec(String productType, String detail1, String detail2, int powerType) {
    ComplexValue complexValue = new ComplexValue();
    List<Property> complexValueValue = complexValue.getValue();
    complexValueValue.add(new Property(
                                       EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(),
                                       SPEC_PRODUCT_TYPE, ValueType.PRIMITIVE, productType));
    complexValueValue.add(new Property(
                                       EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(),
                                       SPEC_DETAIL_1, ValueType.PRIMITIVE, detail1));
    complexValueValue.add(new Property(
                                       EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(),
                                       SPEC_DETAIL_2, ValueType.PRIMITIVE, detail2));
    complexValueValue.add(new Property(
                                       ET_POWER_TYPE_FQN.getFullQualifiedNameAsString(),
                                       SPEC_POWER_TYPE, ValueType.ENUM, powerType));
    return complexValue;
}
 
Example #3
Source File: ProductEntityProvider.java    From spring-boot-Olingo-oData with Apache License 2.0 6 votes vote down vote up
@Override
public EntityType getEntityType() {
	// create EntityType properties
	Property id = new Property().setName("ID").setType(
			EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
	Property name = new Property().setName("Name").setType(
			EdmPrimitiveTypeKind.String.getFullQualifiedName());
	Property description = new Property().setName("Description").setType(
			EdmPrimitiveTypeKind.String.getFullQualifiedName());

	// create PropertyRef for Key element
	PropertyRef propertyRef = new PropertyRef();
	propertyRef.setPropertyName("ID");

	// configure EntityType
	EntityType entityType = new EntityType();
	entityType.setName(ET_PRODUCT_NAME);
	entityType.setProperties(Arrays.asList(id, name, description));
	entityType.setKey(Arrays.asList(propertyRef));
	
	

	return entityType;
}
 
Example #4
Source File: CategoryEntityProvider.java    From spring-boot-Olingo-oData with Apache License 2.0 6 votes vote down vote up
@Override
public EntityType getEntityType() {
	// create EntityType properties
	Property id = new Property().setName("ID").setType(
			EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
	Property name = new Property().setName("Name").setType(
			EdmPrimitiveTypeKind.String.getFullQualifiedName());
	Property description = new Property().setName("Description").setType(
			EdmPrimitiveTypeKind.String.getFullQualifiedName());

	// create PropertyRef for Key element
	PropertyRef propertyRef = new PropertyRef();
	propertyRef.setPropertyName("ID");

	// configure EntityType
	EntityType entityType = new EntityType();
	entityType.setName(ET_CATEGORY_NAME);
	entityType.setProperties(Arrays.asList(id, name, description));
	entityType.setKey(Arrays.asList(propertyRef));
	

	return entityType;
}
 
Example #5
Source File: PrimitiveValueTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void timeOfDay() throws EdmPrimitiveTypeException {
  final Calendar expected = Calendar.getInstance();
  expected.clear();
  expected.set(2013, 0, 10, 21, 45, 17);

  final ClientValue value = client.getObjectFactory().newPrimitiveValueBuilder()
      .setType(EdmPrimitiveTypeKind.TimeOfDay).setValue(expected).build();
  assertEquals(EdmPrimitiveTypeKind.TimeOfDay, value.asPrimitive().getTypeKind());

  final Calendar actual = value.asPrimitive().toCastValue(Calendar.class);
  assertEquals(expected.get(Calendar.HOUR), actual.get(Calendar.HOUR));
  assertEquals(expected.get(Calendar.MINUTE), actual.get(Calendar.MINUTE));
  assertEquals(expected.get(Calendar.SECOND), actual.get(Calendar.SECOND));

  assertEquals("21:45:17", value.asPrimitive().toString());
}
 
Example #6
Source File: EdmMappingTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void getDataClassForPrimTypeViaMapping() {
  CsdlMapping mapping = new CsdlMapping().setMappedJavaClass(Date.class);
  CsdlProperty property = new CsdlProperty()
      .setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName())
      .setMapping(mapping);
  EdmProperty edmProperty = new EdmPropertyImpl(null, property);

  assertNotNull(edmProperty.getMapping());
  assertEquals(Date.class, edmProperty.getMapping().getMappedJavaClass());

  CsdlParameter parameter = new CsdlParameter()
      .setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName())
      .setMapping(mapping);
  EdmParameter edmParameter = new EdmParameterImpl(null, parameter);

  assertNotNull(edmParameter.getMapping());
  assertEquals(Date.class, edmParameter.getMapping().getMappedJavaClass());
}
 
Example #7
Source File: EdmMappingTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void initialMappingMustBeNull() {
  CsdlProperty property = new CsdlProperty().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
  EdmProperty edmProperty = new EdmPropertyImpl(null, property);
  assertNull(edmProperty.getMapping());

  CsdlParameter parameter = new CsdlParameter().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
  EdmParameter edmParameter = new EdmParameterImpl(null, parameter);
  assertNull(edmParameter.getMapping());

  CsdlEntitySet es = new CsdlEntitySet().setName("test");
  EdmEntitySet edmES = new EdmEntitySetImpl(null, null, es);
  assertNull(edmES.getMapping());

  CsdlSingleton si = new CsdlSingleton().setName("test");
  EdmSingleton edmSi = new EdmSingletonImpl(null, null, si);
  assertNull(edmSi.getMapping());
}
 
Example #8
Source File: AtomGeoValueDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private MultiPolygon multiPolygon(final XMLEventReader reader, final StartElement start,
    final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {

  final List<Polygon> polygons = new ArrayList<>();

  boolean foundEndProperty = false;
  while (reader.hasNext() && !foundEndProperty) {
    final XMLEvent event = reader.nextEvent();

    if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_POLYGON)) {
      polygons.add(polygon(reader, event.asStartElement(), type, null));
    }

    if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
      foundEndProperty = true;
    }
  }

  return new MultiPolygon(GeoUtils.getDimension(type), srid, polygons);
}
 
Example #9
Source File: JsonGeoValueDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private MultiPoint multipoint(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final SRID srid) {
  final MultiPoint multiPoint;

  if (itor.hasNext()) {
    final List<Point> points = new ArrayList<>();
    while (itor.hasNext()) {
      final Iterator<JsonNode> mpItor = itor.next().elements();
      points.add(point(mpItor, type, srid));
    }
    multiPoint = new MultiPoint(GeoUtils.getDimension(type), srid, points);
  } else {
    multiPoint = new MultiPoint(GeoUtils.getDimension(type), srid, Collections.<Point> emptyList());
  }

  return multiPoint;
}
 
Example #10
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test(expected = UriParserSemanticException.class)
public void testPropertyPathExpWithoutProperty() throws Exception {
  final String entitySetName = "ESName";
  final String keyPropertyName = "a";
  EdmProperty keyProperty = mockProperty(keyPropertyName, 
      OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String));
  EdmKeyPropertyRef keyPropertyRef = mockKeyPropertyRef(keyPropertyName, keyProperty);
  EdmEntityType entityType = mockEntityType(keyPropertyName, keyPropertyRef);
  Mockito.when(entityType.getFullQualifiedName()).thenReturn(new FullQualifiedName("test.ETName"));
  EdmEntitySet entitySet = mockEntitySet(entitySetName, entityType);
  EdmEntityContainer container = mockContainer(entitySetName, entitySet);
  Edm mockedEdm = Mockito.mock(Edm.class);
  Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
  
  UriTokenizer tokenizer = new UriTokenizer("a eq \'abc\'");
  new ExpressionParser(mockedEdm, odata).parse(tokenizer, entityType, null, null);
}
 
Example #11
Source File: CoreUtils.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private static EdmTypeInfo guessPrimitiveType(final EdmEnabledODataClient client, final Class<?> clazz) {
  EdmPrimitiveTypeKind bckCandidate = null;

  for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
    final Class<?> target = EdmPrimitiveTypeFactory.getInstance(kind).getDefaultType();

    if (clazz.equals(target)) {
      return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(kind.toString()).build();
    } else if (target.isAssignableFrom(clazz)) {
      bckCandidate = kind;
    } else if (target == Timestamp.class && kind == EdmPrimitiveTypeKind.DateTimeOffset) {
      bckCandidate = kind;
    }
  }

  if (bckCandidate == null) {
    throw new IllegalArgumentException(clazz.getSimpleName() + " is not a simple type");
  } else {
    return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(bckCandidate.toString()).build();
  }
}
 
Example #12
Source File: ODataBinderImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EdmTypeInfo buildTypeInfo(final FullQualifiedName typeName, final String propertyType) {
  EdmTypeInfo typeInfo = null;
  if (typeName == null) {
    if (propertyType != null) {
      typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build();
    }
  } else {
    if (propertyType == null || propertyType.equals(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString())) {
      typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build();
    } else if(isPrimiteveType(typeName)) {
      // Inheritance is not allowed for primitive types, so we use the type given by the EDM.
      typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build();
    } else {
      typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build();
    }
  }
  return typeInfo;
}
 
Example #13
Source File: ODataJsonDeserializerEntityTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void geoMultiLineString() throws Exception {
  final EdmEntityType entityType = mockEntityType(EdmPrimitiveTypeKind.GeometryMultiLineString);
  final Entity entity = deserialize("{\"" + entityType.getPropertyNames().get(0) + "\":{"
      + "\"type\":\"MultiLineString\",\"coordinates\":["
      + "[[1.0,1.0],[2.0,2.0],[3.0,3.0],[4.0,4.0],[5.0,5.0]],"
      + "[[99.5,101.5],[150.0,151.25]]]}}",
      entityType);
  assertTrue(entity.getProperties().get(0).getValue() instanceof MultiLineString);
  final MultiLineString multiLineString = (MultiLineString) entity.getProperties().get(0).getValue();
  assertEquals(Geospatial.Dimension.GEOMETRY, multiLineString.getDimension());
  assertEquals(1, multiLineString.iterator().next().iterator().next().getY(), 0);

  expectException("{\"" + entityType.getPropertyNames().get(0)
      + "\":{\"type\":\"MultiLineString\",\"coordinates\":null}}", entityType,
      ContentType.JSON, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
  expectException("{\"" + entityType.getPropertyNames().get(0)
      + "\":{\"type\":\"MultiLineString\",\"coordinates\":\"1 2 3 4\"}}", entityType,
      ContentType.JSON, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
  expectException("{\"" + entityType.getPropertyNames().get(0)
      + "\":{\"type\":\"MultiLineString\",\"coordinates\":[{\"first\":[[1,2],[3,4]]}]}}", entityType,
      ContentType.JSON, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
}
 
Example #14
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Expression parseExprRel() throws UriParserException, UriValidationException {
  if (tokenizer.next(TokenKind.IsofMethod)) {
    // The isof method is a terminal.  So no further operators are allowed.
    return parseIsOfOrCastMethod(MethodKind.ISOF);
  } else {
    Expression left = parseExprAdd();
    TokenKind operatorTokenKind = ParserHelper.next(tokenizer,
        TokenKind.GreaterThanOperator, TokenKind.GreaterThanOrEqualsOperator,
        TokenKind.LessThanOperator, TokenKind.LessThanOrEqualsOperator);
    // Null for everything other than GT or GE or LT or LE
    while (operatorTokenKind != null) {
      final Expression right = parseExprAdd();
      checkRelationTypes(left, right);
      left = new BinaryImpl(left, tokenToBinaryOperator.get(operatorTokenKind), right,
          odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean));
      operatorTokenKind = ParserHelper.next(tokenizer,
          TokenKind.GreaterThanOperator, TokenKind.GreaterThanOrEqualsOperator,
          TokenKind.LessThanOperator, TokenKind.LessThanOrEqualsOperator);
    }
    return left;
  }
}
 
Example #15
Source File: ODataJsonDeserializerEntityTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void geoMultiPolygon() throws Exception {
  final EdmEntityType entityType = mockEntityType(EdmPrimitiveTypeKind.GeometryMultiPolygon);
  final Entity entity = deserialize("{\"" + entityType.getPropertyNames().get(0) + "\":{"
      + "\"type\":\"MultiPolygon\",\"coordinates\":["
      + "[[[0.0,0.0],[3.0,0.0],[3.0,3.0],[0.0,3.0],[0.0,0.0]],"
      + "[[1.0,1.0],[1.0,2.0],[2.0,2.0],[2.0,1.0],[1.0,1.0]]],"
      + "[[[0.0,0.0],[30.0,0.0],[0.0,30.0],[0.0,0.0]]]]}}",
      entityType);
  final MultiPolygon multiPolygon = (MultiPolygon) entity.getProperties().get(0).getValue();
  assertEquals(1, multiPolygon.iterator().next().getInterior(0).iterator().next().getX(), 0);

  expectException("{\"" + entityType.getPropertyNames().get(0) + "\":{"
      + "\"type\":\"MultiPolygon\",\"coordinates\":[{\"first\":[[[0,0],[3,0],[3,3],[0,3],[0,0]]]}]}}", entityType,
      ContentType.JSON, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
}
 
Example #16
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void geoMultiLineString() throws Exception {
  final EdmEntityType entityType = mockEntityType(EdmPrimitiveTypeKind.GeometryMultiLineString);
  final Entity entity = new Entity()
      .addProperty(new Property(null, entityType.getPropertyNames().get(0), ValueType.GEOSPATIAL,
          new MultiLineString(Dimension.GEOMETRY, null, Arrays.asList(
              new LineString(Dimension.GEOMETRY, null, Arrays.asList(
                  createPoint(1, 1), createPoint(2, 2), createPoint(3, 3), createPoint(4, 4), createPoint(5, 5))),
              new LineString(Dimension.GEOMETRY, null, Arrays.asList(
                  createPoint(99.5, 101.5), createPoint(150, 151.25)))))));
  Assert.assertEquals("{\"" + entityType.getPropertyNames().get(0) + "\":{"
      + "\"type\":\"MultiLineString\",\"coordinates\":["
      + "[[1.0,1.0],[2.0,2.0],[3.0,3.0],[4.0,4.0],[5.0,5.0]],"
      + "[[99.5,101.5],[150.0,151.25]]]}}",
      IOUtils.toString(serializerNoMetadata.entity(metadata, entityType, entity, null).getContent()));
}
 
Example #17
Source File: PrimitiveValueTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void Date() throws EdmPrimitiveTypeException {
  final Calendar expected = Calendar.getInstance();
  expected.clear();
  expected.set(2013, 0, 10);

  final ClientValue value = client.getObjectFactory().newPrimitiveValueBuilder()
      .setType(EdmPrimitiveTypeKind.Date).setValue(expected).build();
  assertEquals(EdmPrimitiveTypeKind.Date, value.asPrimitive().getTypeKind());

  final Calendar actual = value.asPrimitive().toCastValue(Calendar.class);
  assertEquals(expected.get(Calendar.YEAR), actual.get(Calendar.YEAR));
  assertEquals(expected.get(Calendar.MONTH), actual.get(Calendar.MONTH));
  assertEquals(expected.get(Calendar.DATE), actual.get(Calendar.DATE));

  assertEquals("2013-01-10", value.asPrimitive().toString());
}
 
Example #18
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Expression parseExprMul() throws UriParserException, UriValidationException {
  Expression left = parseExprUnary();
  TokenKind operatorTokenKind = ParserHelper.next(tokenizer,
      TokenKind.MulOperator, TokenKind.DivOperator, TokenKind.ModOperator);
  // Null for everything other than MUL or DIV or MOD
  while (operatorTokenKind != null) {
    checkNumericType(left);
    final Expression right = parseExprUnary();
    checkNumericType(right);
    left = new BinaryImpl(left, tokenToBinaryOperator.get(operatorTokenKind), right,
        odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double));
    operatorTokenKind = ParserHelper.next(tokenizer,
        TokenKind.MulOperator, TokenKind.DivOperator, TokenKind.ModOperator);
  }
  return left;
}
 
Example #19
Source File: ApplyParserTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void bottomTop() throws Exception {
  parse("ESTwoKeyNav", "topcount(2,PropertyInt16)")
      .goBottomTop().isMethod(Method.TOP_COUNT)
      .goNumber().isLiteralType(odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.SByte))
      .isLiteral("2");
  parse("ESTwoKeyNav", "topsum(2,PropertyInt16)")
      .goBottomTop().isMethod(Method.TOP_SUM)
      .goValue().isMember().goPath().first().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
  parse("ESTwoKeyNav", "toppercent(2,PropertyInt16)").goBottomTop().isMethod(Method.TOP_PERCENT);

  parse("ESTwoKeyNav", "bottomcount(2,PropertyInt16)").goBottomTop().isMethod(Method.BOTTOM_COUNT);
  parse("ESTwoKeyNav", "bottomsum(2,PropertyInt16)").goBottomTop().isMethod(Method.BOTTOM_SUM);
  parse("ESTwoKeyNav", "bottompercent(2,PropertyInt16)").goBottomTop().isMethod(Method.BOTTOM_PERCENT);

  parseEx("ESTwoKeyNav", "bottompercent(1.2,PropertyInt16)")
      .isExSemantic(UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE);
  parseEx("ESTwoKeyNav", "bottompercent(2,PropertyString)")
      .isExSemantic(UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE);
}
 
Example #20
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
  // this method is called for one of the EntityTypes that are configured in the Schema
  if(ET_PRODUCT_FQN.equals(entityTypeName)){

    //create EntityType properties
    CsdlProperty id = new CsdlProperty().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
    CsdlProperty name = new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
    CsdlProperty  description = new CsdlProperty().setName("Description").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

    // create PropertyRef for Key element
    CsdlPropertyRef propertyRef = new CsdlPropertyRef();
    propertyRef.setName("ID");

    // configure EntityType
    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName(ET_PRODUCT_NAME);
    entityType.setProperties(Arrays.asList(id, name, description));
    entityType.setKey(Collections.singletonList(propertyRef));

    return entityType;
  }

  return null;

}
 
Example #21
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Expression parsePrimitive(final TokenKind primitiveTokenKind) throws UriParserException {
  final String primitiveValueLiteral = tokenizer.getText();
  if (primitiveTokenKind == TokenKind.EnumValue) {
    return createEnumExpression(primitiveValueLiteral);
  } else {
    EdmPrimitiveTypeKind primitiveTypeKind = ParserHelper.tokenToPrimitiveType.get(primitiveTokenKind);
    if (primitiveTypeKind == EdmPrimitiveTypeKind.Int64) {
      primitiveTypeKind = determineIntegerType(primitiveValueLiteral);
    }

    final EdmPrimitiveType type = primitiveTypeKind == null ?
        // Null handling
        null :
        odata.createPrimitiveTypeInstance(primitiveTypeKind);
    return new LiteralImpl(primitiveValueLiteral, type);
  }
}
 
Example #22
Source File: ODataJsonDeserializerEntityTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private EdmEntityType mockEntityType(final EdmPrimitiveTypeKind typeKind) {
  EdmProperty property = Mockito.mock(EdmProperty.class);
  final String name = "Property" + typeKind.name();
  Mockito.when(property.getType()).thenReturn(odata.createPrimitiveTypeInstance(typeKind));
  EdmEntityType entityType = Mockito.mock(EdmEntityType.class);
  Mockito.when(entityType.getFullQualifiedName()).thenReturn(new FullQualifiedName(NAMESPACE, "entityType"));
  Mockito.when(entityType.getPropertyNames()).thenReturn(Arrays.asList(name));
  Mockito.when(entityType.getProperty(name)).thenReturn(property);
  return entityType;
}
 
Example #23
Source File: EdmReturnTypeImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void primitiveCollectionReturnType() {
  CsdlReturnType providerType = new CsdlReturnType().setType(
      new FullQualifiedName("Edm", "String")).setCollection(true);

  EdmReturnType typeImpl = new EdmReturnTypeImpl(mock(EdmProviderImpl.class), providerType);

  EdmType cachedType = typeImpl.getType();
  assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), cachedType);
  assertTrue(typeImpl.isCollection());
  assertTrue(cachedType == typeImpl.getType());
}
 
Example #24
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlComplexType getComplexType(final FullQualifiedName complexTypeName) {
  CsdlComplexType complexType = null;
  if (complexTypeName.equals(CT_ADDRESS_FQN)) {
    complexType = new CsdlComplexType().setName(CT_ADDRESS_NAME)
        .setProperties(Arrays.asList(
            new CsdlProperty()
                .setName("City")
                .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()),
            new CsdlProperty()
            .setName("Country")
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())));
  }
  return complexType;
}
 
Example #25
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void geoNonstandardSRID() throws Exception {
  final EdmEntityType entityType = mockEntityType(EdmPrimitiveTypeKind.GeometryPoint);
  final Entity entity = new Entity()
      .addProperty(new Property(null, entityType.getPropertyNames().get(0), ValueType.GEOSPATIAL,
          new Point(Dimension.GEOMETRY, SRID.valueOf("42"))));
  Assert.assertEquals("{\"PropertyGeometryPoint\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0],"
  		+ "\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:42\"}}}}",
          IOUtils.toString(serializerNoMetadata.entity(metadata, entityType, entity, null).getContent()));
}
 
Example #26
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected void checkNumericType(final Expression expression) throws UriParserException {
  checkNoCollection(expression);
  checkType(expression,
      EdmPrimitiveTypeKind.Int64, EdmPrimitiveTypeKind.Int32, EdmPrimitiveTypeKind.Int16,
      EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte,
      EdmPrimitiveTypeKind.Decimal, EdmPrimitiveTypeKind.Single, EdmPrimitiveTypeKind.Double);
}
 
Example #27
Source File: ApplyParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private EdmType getTypeForAggregateMethod(final StandardMethod method, final EdmType type) {
  if (method == StandardMethod.SUM || method == StandardMethod.AVERAGE || method == StandardMethod.COUNT_DISTINCT) {
    return odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal);
  } else if (method == StandardMethod.MIN || method == StandardMethod.MAX) {
    return type;
  } else {
    return null;
  }
}
 
Example #28
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void geoLineString() throws Exception {
  final EdmEntityType entityType = mockEntityType(EdmPrimitiveTypeKind.GeometryLineString);
  final Entity entity = new Entity()
      .addProperty(new Property(null, entityType.getPropertyNames().get(0), ValueType.GEOSPATIAL,
          new LineString(Dimension.GEOMETRY, null, Arrays.asList(
              createPoint(1, 1), createPoint(2, 2), createPoint(3, 3), createPoint(4, 4), createPoint(5, 5)))));
  Assert.assertEquals("{\"" + entityType.getPropertyNames().get(0) + "\":{"
      + "\"type\":\"LineString\",\"coordinates\":[[1.0,1.0],[2.0,2.0],[3.0,3.0],[4.0,4.0],[5.0,5.0]]}}",
      IOUtils.toString(serializerNoMetadata.entity(metadata, entityType, entity, null).getContent()));
}
 
Example #29
Source File: FilterParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public FilterOption parse(UriTokenizer tokenizer, final EdmType referencedType,
    final Collection<String> crossjoinEntitySetNames, final Map<String, AliasQueryOption> aliases)
    throws UriParserException, UriValidationException {
  final Expression filterExpression = new ExpressionParser(edm, odata)
      .parse(tokenizer, referencedType, crossjoinEntitySetNames, aliases);
  final EdmType type = ExpressionParser.getType(filterExpression);
  if (type == null || type.equals(odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean))) {
    return new FilterOptionImpl().setExpression(filterExpression);
  } else {
    throw new UriParserSemanticException("Filter expressions must be boolean.",
        UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE,
        "Edm.Boolean", type.getFullQualifiedName().getFullQualifiedNameAsString());
  }
}
 
Example #30
Source File: ClientPrimitiveValueSerializer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ClientPrimitiveValue value, JsonGenerator generator, SerializerProvider provider) throws IOException {
    try {
        EdmPrimitiveTypeKind typeKind = value.getTypeKind();
        switch (typeKind) {
            case Boolean:
                generator.writeBoolean(value.toCastValue(Boolean.class));
                break;
            case Decimal:
                generator.writeNumber(value.toCastValue(BigDecimal.class));
                break;
            case Double:
                generator.writeNumber(value.toCastValue(Double.class));
                break;
            case Single:
            case Int16:
            case Int32:
            case Int64:
                generator.writeNumber(value.toCastValue(Integer.class));
                break;
            default:
                generator.writeString(value.toString());
                break;
        }
    } catch (EdmPrimitiveTypeException ignored) {
        generator.writeString(value.toString());
    }
}