Java Code Examples for org.apache.olingo.odata2.api.edm.EdmProperty#getType()

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmProperty#getType() . 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: EdmUriBuilderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = RuntimeException.class)
public void negTestUriWithFormat() throws EdmException {
  EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Employees");
  EdmComplexType complexType = edm.getComplexType("RefScenario", "c_Location");
  EdmProperty property = (EdmProperty) complexType.getProperty("City");
  EdmComplexType complexType1 = (EdmComplexType) property.getType();
  EdmProperty property1 = (EdmProperty) complexType1.getProperty("CityName");
  new EdmURIBuilderImpl(SERVICE_ROOT_URI).
  appendEntitySetSegment(entitySet).
  appendKeySegment((EdmProperty)entitySet.getEntityType().getProperty("EmployeeId"), "1").
  appendPropertySegment((EdmProperty)entitySet.getEntityType().getProperty("Location"), "Location").
  appendPropertySegment(property, "City").
  appendPropertySegment(property1, "CityName").
  appendValueSegment().
  format("application/json").
  build();
}
 
Example 2
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static Map<String, Object> mapKey(final List<KeyPredicate> keys) throws EdmException {
  Map<String, Object> keyMap = new HashMap<String, Object>();
  for (final KeyPredicate key : keys) {
    final EdmProperty property = key.getProperty();
    final EdmSimpleType type = (EdmSimpleType) property.getType();
    keyMap.put(property.getName(), type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(),
        type.getDefaultType()));
  }
  return keyMap;
}
 
Example 3
Source File: EdmURIBuilderImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param property
 * @param value
 * @return
 * @throws EdmException
 * @throws EdmSimpleTypeException
 */
private String getKey(EdmProperty property, Object value, boolean isSegment) 
    throws EdmException {
  String key = "";
  EdmSimpleType edmType = (EdmSimpleType) property.getType();
  if (value instanceof String) {
    value = Encoder.encode(value.toString()); //NOSONAR
  }
  if (!isSegment) {
    key = "(" + edmType.valueToString(value, EdmLiteralKind.URI, property.getFacets()) + ")";
  } else {
    key = edmType.valueToString(value, EdmLiteralKind.URI, property.getFacets());
  }
  return key;
}
 
Example 4
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> String getSkipToken(final EdmEntitySet entitySet, final T data) throws ODataException {
  String skipToken = "";
  for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
    final EdmSimpleType type = (EdmSimpleType) property.getType();
    skipToken = skipToken.concat(type.valueToString(valueAccess.getPropertyValue(data, property),
        EdmLiteralKind.DEFAULT, property.getFacets()));
  }
  return skipToken;
}
 
Example 5
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
  final EdmEntityType entityType = entitySet.getEntityType();
  String eTag = null;
  for (final String propertyName : entityType.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
    if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
      final EdmSimpleType type = (EdmSimpleType) property.getType();
      final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
          EdmLiteralKind.DEFAULT, property.getFacets());
      eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
    }
  }
  return eTag == null ? null : "W/\"" + eTag + "\"";
}
 
Example 6
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static Map<String, Object> mapKey(final List<KeyPredicate> keys) throws EdmException {
  Map<String, Object> keyMap = new HashMap<String, Object>();
  for (final KeyPredicate key : keys) {
    final EdmProperty property = key.getProperty();
    final EdmSimpleType type = (EdmSimpleType) property.getType();
    keyMap.put(property.getName(), type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(),
        type.getDefaultType()));
  }
  return keyMap;
}
 
Example 7
Source File: TestSpec.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropertiesWithEdm() {
  try {
    EdmEntityType edmEtAllTypes = edmInfo.getTypeEtAllTypes();
    EdmProperty string = (EdmProperty) edmEtAllTypes.getProperty("String");
    EdmSimpleType stringType = (EdmSimpleType) string.getType();
    EdmComplexPropertyImplProv complex = (EdmComplexPropertyImplProv) edmEtAllTypes.getProperty("Complex");
    EdmComplexType complexType = (EdmComplexType) complex.getType();
    EdmProperty complexString = (EdmProperty) complexType.getProperty("String");
    EdmSimpleType complexStringType = (EdmSimpleType) complexString.getType();
    EdmComplexPropertyImplProv complexAddress = (EdmComplexPropertyImplProv) complexType.getProperty("Address");
    EdmComplexType complexAddressType = (EdmComplexType) complexAddress.getType();
    EdmProperty complexAddressCity = (EdmProperty) complexAddressType.getProperty("City");
    EdmSimpleType complexAddressCityType = (EdmSimpleType) complexAddressCity.getType();

    GetPTF(edmEtAllTypes, "String").aEdmProperty(string).aEdmType(stringType);

    GetPTF(edmEtAllTypes, "'text' eq String").root().aKind(ExpressionKind.BINARY);

    GetPTF(edmEtAllTypes, "Complex/String").root().left().aEdmProperty(complex).aEdmType(complexType).root().right()
        .aEdmProperty(complexString).aEdmType(complexStringType).root().aKind(ExpressionKind.MEMBER).aEdmType(
            complexStringType);

    GetPTF(edmEtAllTypes, "Complex/Address/City").root().aKind(ExpressionKind.MEMBER).root().left().aKind(
        ExpressionKind.MEMBER).root().left().left().aKind(ExpressionKind.PROPERTY).aEdmProperty(complex).aEdmType(
        complexType).root().left().right().aKind(ExpressionKind.PROPERTY).aEdmProperty(complexAddress).aEdmType(
        complexAddressType).root().left().aEdmType(complexAddressType).root().right().aKind(ExpressionKind.PROPERTY)
        .aEdmProperty(complexAddressCity).aEdmType(complexAddressCityType).root().aEdmType(complexAddressCityType);

    EdmProperty boolean_ = (EdmProperty) edmEtAllTypes.getProperty("Boolean");
    EdmSimpleType boolean_Type = (EdmSimpleType) boolean_.getType();

    GetPTF(edmEtAllTypes, "not Boolean").aKind(ExpressionKind.UNARY).aEdmType(boolean_Type).right().aEdmProperty(
        boolean_).aEdmType(boolean_Type);

  } catch (EdmException e) {
    fail("Error in testPropertiesWithEdm:" + e.getLocalizedMessage());
    e.printStackTrace();
  }
}
 
Example 8
Source File: TestParser.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void propertiesWithEdm() throws Exception {
  EdmEntityType edmEtAllTypes = edmInfo.getTypeEtAllTypes();
  EdmProperty string = (EdmProperty) edmEtAllTypes.getProperty("String");
  EdmSimpleType stringType = (EdmSimpleType) string.getType();
  EdmComplexPropertyImplProv complex = (EdmComplexPropertyImplProv) edmEtAllTypes.getProperty("Complex");
  EdmComplexType complexType = (EdmComplexType) complex.getType();
  EdmProperty complexString = (EdmProperty) complexType.getProperty("String");
  EdmSimpleType complexStringType = (EdmSimpleType) complexString.getType();
  EdmComplexPropertyImplProv complexAddress = (EdmComplexPropertyImplProv) complexType.getProperty("Address");
  EdmComplexType complexAddressType = (EdmComplexType) complexAddress.getType();
  EdmProperty complexAddressCity = (EdmProperty) complexAddressType.getProperty("City");
  EdmSimpleType complexAddressCityType = (EdmSimpleType) complexAddressCity.getType();

  GetPTF(edmEtAllTypes, "String").aEdmProperty(string).aEdmType(stringType);

  GetPTF(edmEtAllTypes, "'text' eq String").root().aKind(ExpressionKind.BINARY);

  GetPTF(edmEtAllTypes, "Complex/String").root().left().aEdmProperty(complex).aEdmType(complexType).root().right()
      .aEdmProperty(complexString).aEdmType(complexStringType).root().aKind(ExpressionKind.MEMBER).aEdmType(
          complexStringType);

  GetPTF(edmEtAllTypes, "Complex/Address/City").root().aKind(ExpressionKind.MEMBER).root().left().aKind(
      ExpressionKind.MEMBER).root().left().left().aKind(ExpressionKind.PROPERTY).aEdmProperty(complex).aEdmType(
          complexType)
      .root().left().right().aKind(ExpressionKind.PROPERTY).aEdmProperty(complexAddress).aEdmType(
          complexAddressType)
      .root().left().aEdmType(complexAddressType).root().right().aKind(ExpressionKind.PROPERTY)
      .aEdmProperty(complexAddressCity).aEdmType(complexAddressCityType).root().aEdmType(complexAddressCityType);

  EdmProperty boolean_ = (EdmProperty) edmEtAllTypes.getProperty("Boolean");
  EdmSimpleType boolean_Type = (EdmSimpleType) boolean_.getType();

  GetPTF(edmEtAllTypes, "not Boolean").aKind(ExpressionKind.UNARY).aEdmType(boolean_Type).right().aEdmProperty(
      boolean_).aEdmType(boolean_Type);
}
 
Example 9
Source File: ODataRequestHandler.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static List<ContentType> getSupportedContentTypes(final EdmProperty property) throws EdmException {
  if (property != null) {
    return property.getType() == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()
        ? Collections.singletonList(property.getMimeType() == null
          ? ContentType.WILDCARD : ContentType.create(property.getMimeType()))
          : Arrays.asList(ContentType.TEXT_PLAIN, ContentType.TEXT_PLAIN_CS_UTF_8);
  } else {
    return null;
  }
  
}
 
Example 10
Source File: EntityInfoAggregator.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private EntityPropertyInfo createEntityPropertyInfo(final EdmProperty property) throws EdmException,
    EntityProviderException {
  EdmType type = property.getType();
  if (type instanceof EdmSimpleType) {
    return EntityPropertyInfo.create(property);
  } else if (type instanceof EdmComplexType) {
    EdmComplexType complex = (EdmComplexType) type;
    Map<String, EntityPropertyInfo> recursiveInfos = createPropertyInfoObjects(complex, complex.getPropertyNames());
    return EntityComplexPropertyInfo.create(property, complex.getPropertyNames(), recursiveInfos);
  } else {
    throw new EntityProviderException(EntityProviderException.UNSUPPORTED_PROPERTY_TYPE);
  }
}
 
Example 11
Source File: EntityComplexPropertyInfo.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
static EntityComplexPropertyInfo create(final EdmProperty property, final List<String> propertyNames,
    final Map<String, EntityPropertyInfo> childEntityInfos) throws EdmException {
  List<EntityPropertyInfo> childEntityInfoList = new ArrayList<EntityPropertyInfo>(childEntityInfos.size());
  for (String name : propertyNames) {
    childEntityInfoList.add(childEntityInfos.get(name));
  }

  EntityComplexPropertyInfo info = new EntityComplexPropertyInfo(
      property.getName(),
      property.getType(),
      property.getFacets(),
      property.getCustomizableFeedMappings(),
      childEntityInfoList);
  return info;
}
 
Example 12
Source File: EntityPropertyInfo.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
static EntityPropertyInfo create(final EdmProperty property) throws EdmException {
  return new EntityPropertyInfo(
      property.getName(),
      property.getType(),
      property.getFacets(),
      property.getCustomizableFeedMappings(),
      property.getMimeType(),
      property.getMapping());
}
 
Example 13
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> String getSkipToken(final EdmEntitySet entitySet, final T data) throws ODataException {
  String skipToken = "";
  for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
    final EdmSimpleType type = (EdmSimpleType) property.getType();
    skipToken = skipToken.concat(type.valueToString(valueAccess.getPropertyValue(data, property),
        EdmLiteralKind.DEFAULT, property.getFacets()));
  }
  return skipToken;
}
 
Example 14
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
  final EdmEntityType entityType = entitySet.getEntityType();
  String eTag = null;
  for (final String propertyName : entityType.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
    if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
      final EdmSimpleType type = (EdmSimpleType) property.getType();
      final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
          EdmLiteralKind.DEFAULT, property.getFacets());
      eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
    }
  }
  return eTag == null ? null : "W/\"" + eTag + "\"";
}
 
Example 15
Source File: UriParserImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private void handlePropertyPath(final EdmProperty property) throws UriSyntaxException, UriNotMatchingException,
    EdmException {
  uriResult.addProperty(property);
  final EdmType type = property.getType();

  if (pathSegments.isEmpty()) {
    if (type.getKind() == EdmTypeKind.SIMPLE) {
      if (uriResult.getPropertyPath().size() == 1) {
        uriResult.setUriType(UriType.URI5);
      } else {
        uriResult.setUriType(UriType.URI4);
      }
    } else if (type.getKind() == EdmTypeKind.COMPLEX) {
      uriResult.setUriType(UriType.URI3);
    } else {
      throw new UriSyntaxException(UriSyntaxException.INVALIDPROPERTYTYPE.addContent(type.getKind()));
    }
    uriResult.setTargetType(type);
  } else {

    currentPathSegment = percentDecode(pathSegments.remove(0));
    switch (type.getKind()) {
    case SIMPLE:
      if ("$value".equals(percentDecode(currentPathSegment))) {
        ensureLastSegment();
        uriResult.setValue(true);
        if (uriResult.getPropertyPath().size() == 1) {
          uriResult.setUriType(UriType.URI5);
        } else {
          uriResult.setUriType(UriType.URI4);
        }
      } else {
        throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(currentPathSegment));
      }
      uriResult.setTargetType(type);
      break;

    case COMPLEX:
      final EdmProperty nextProperty = (EdmProperty) ((EdmComplexType) type).getProperty(currentPathSegment);
      if (nextProperty == null) {
        throw new UriNotMatchingException(UriNotMatchingException.PROPERTYNOTFOUND.addContent(currentPathSegment));
      }

      handlePropertyPath(nextProperty);
      break;

    default:
      throw new UriSyntaxException(UriSyntaxException.INVALIDPROPERTYTYPE.addContent(type.getKind()));
    }
  }
}
 
Example 16
Source File: BeanPropertyAccess.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
  return property.isSimple()
      && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
}
 
Example 17
Source File: BeanPropertyAccess.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
  return property.isSimple()
      && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
}
 
Example 18
Source File: CarODataSingleProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private int getKeyValue(final KeyPredicate key) throws ODataException {
  EdmProperty property = key.getProperty();
  EdmSimpleType type = (EdmSimpleType) property.getType();
  return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
}
 
Example 19
Source File: MyODataSingleProcessor.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
private int getKeyValue(KeyPredicate key) throws ODataException {
    EdmProperty property = key.getProperty();
    EdmSimpleType type = (EdmSimpleType) property.getType();
    return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
}