Java Code Examples for org.apache.olingo.commons.api.edm.EdmProperty#getScale()

The following examples show how to use org.apache.olingo.commons.api.edm.EdmProperty#getScale() . 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: PrimitiveSerializerOptions.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/** Sets all facets from an EDM property. */
public Builder facetsFrom(final EdmProperty property) {
  options.isNullable = property.isNullable();
  options.maxLength = property.getMaxLength();
  options.precision = property.getPrecision();
  options.scale = property.getScale();
  options.isUnicode = property.isUnicode();
  return this;
}
 
Example 2
Source File: PrimitiveValueSerializerOptions.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/** Sets all facets from an EDM property. */
public Builder facetsFrom(final EdmProperty property) {
  options.isNullable = property.isNullable();
  options.maxLength = property.getMaxLength();
  options.precision = property.getPrecision();
  options.scale = property.getScale();
  options.isUnicode = property.isUnicode();
  return this;
}
 
Example 3
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
        throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();
    
    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString //
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
          .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 4
Source File: Util.java    From syndesis with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
    throws ODataApplicationException {

    // loop over all keys
    for (final UriParameter key : keyParams) {
        // key
        String keyName = key.getName();
        String keyText = key.getText();

        // Edm: we need this info for the comparison below
        EdmProperty edmKeyProperty = (EdmProperty)edmEntityType.getProperty(keyName);
        Boolean isNullable = edmKeyProperty.isNullable();
        Integer maxLength = edmKeyProperty.getMaxLength();
        Integer precision = edmKeyProperty.getPrecision();
        Boolean isUnicode = edmKeyProperty.isUnicode();
        Integer scale = edmKeyProperty.getScale();
        // get the EdmType in order to compare
        EdmType edmType = edmKeyProperty.getType();
        EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType)edmType;

        // Runtime data: the value of the current entity
        // don't need to check for null, this is done in olingo library
        Object valueObject = entity.getProperty(keyName).getValue();

        // now need to compare the valueObject with the keyText String
        // this is done using the type.valueToString
        String valueAsString;
        try {
            valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
        } catch (EdmPrimitiveTypeException e) {
            throw new ODataApplicationException("Failed to retrieve String value",
                                                HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ENGLISH, e);
        }

        if (valueAsString == null) {
            return false;
        }

        boolean matches = valueAsString.equals(keyText);
        if (!matches) {
            // if any of the key properties is not found in the entity, we don't need to search further
            return false;
        }
    }

    return true;
}
 
Example 5
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
        throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();

    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString
    String valueAsString;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
              .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 6
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams) 
    throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();
    
    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString //
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
          .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 7
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity rt_entity,
    List<UriParameter> keyParams) {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();

    // note: below line doesn't consider: keyProp can be part of a complexType in V4
    // in such case, it would be required to access it via getKeyPropertyRef()
    // but since this isn't the case in our model, we ignore it in our implementation
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    // Edm: we need this info for the comparison below
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    // if(EdmType instanceof EdmPrimitiveType) // do we need this?
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in FWK
    Object valueObject = rt_entity.getProperty(keyName).getValue();
    // TODO if the property is a complex type

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable,
              maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      return false; // TODO proper Exception handling
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (matches) {
      // if the given key value is found in the current entity, continue with the next key
      continue;
    } else {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 8
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
        throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();
    
    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString //
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
          .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 9
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams) 
    throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();
    
    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString //
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
          .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 10
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
        throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();

    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString
    String valueAsString;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
              .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 11
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity rt_entity,
    List<UriParameter> keyParams) {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();

    // note: below line doesn't consider: keyProp can be part of a complexType in V4
    // in such case, it would be required to access it via getKeyPropertyRef()
    // but since this isn't the case in our model, we ignore it in our implementation
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    // Edm: we need this info for the comparison below
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    // if(EdmType instanceof EdmPrimitiveType) // do we need this?
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in FWK
    Object valueObject = rt_entity.getProperty(keyName).getValue();
    // TODO if the property is a complex type

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable,
          maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      return false; // TODO proper Exception handling
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    // if any of the key properties is not found in the entity, we don't need to search further
    if (!matches) {
      return false;
    }
    // if the given key value is found in the current entity, continue with the next key
  }

  return true;
}
 
Example 12
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams) 
    throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();
    
    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString //
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
          .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 13
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity rt_entity,
    List<UriParameter> keyParams) {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();

    // note: below line doesn't consider: keyProp can be part of a complexType in V4
    // in such case, it would be required to access it via getKeyPropertyRef()
    // but since this isn't the case in our model, we ignore it in our implementation
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    // Edm: we need this info for the comparison below
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    // if(EdmType instanceof EdmPrimitiveType) // do we need this?
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in FWK
    Object valueObject = rt_entity.getProperty(keyName).getValue();
    // TODO if the property is a complex type

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable,
          maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      return false; // TODO proper Exception handling
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    // if any of the key properties is not found in the entity, we don't need to search further
    if (!matches) {
      return false;
    }
    // if the given key value is found in the current entity, continue with the next key
  }

  return true;
}
 
Example 14
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams) 
    throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();
    
    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString //
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
          .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 15
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
        throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();

    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString
    String valueAsString;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
              .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 16
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams) 
    throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();
    
    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString //
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
          .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 17
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
        throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();

    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using the type.valueToString
    String valueAsString;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
              .getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 18
Source File: Util.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static boolean
    entityMatchesAllKeys(EdmEntityType edmEntityType, Entity rt_entity, List<UriParameter> keyParams)
        throws ODataApplicationException {

  // loop over all keys
  for (final UriParameter key : keyParams) {
    // key
    String keyName = key.getName();
    String keyText = key.getText();

    // Edm: we need this info for the comparison below
    EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
    Boolean isNullable = edmKeyProperty.isNullable();
    Integer maxLength = edmKeyProperty.getMaxLength();
    Integer precision = edmKeyProperty.getPrecision();
    Boolean isUnicode = edmKeyProperty.isUnicode();
    Integer scale = edmKeyProperty.getScale();
    // get the EdmType in order to compare
    EdmType edmType = edmKeyProperty.getType();
    // if(EdmType instanceof EdmPrimitiveType) // do we need this?
    EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;

    // Runtime data: the value of the current entity
    // don't need to check for null, this is done in olingo library
    Object valueObject = rt_entity.getProperty(keyName).getValue();

    // now need to compare the valueObject with the keyText String
    // this is done using type.valueToString
    String valueAsString = null;
    try {
      valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
    } catch (EdmPrimitiveTypeException e) {
      throw new ODataApplicationException("Failed to retrieve String value",
				HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ENGLISH, e);
    }

    if (valueAsString == null) {
      return false;
    }

    boolean matches = valueAsString.equals(keyText);
    if (!matches) {
      // if any of the key properties is not found in the entity, we don't need to search further
      return false;
    }
  }

  return true;
}
 
Example 19
Source File: MetadataDocumentXmlSerializer.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void appendProperties(final XMLStreamWriter writer, final EdmStructuredType type) throws XMLStreamException {
  List<String> propertyNames = new ArrayList<>(type.getPropertyNames());
  if (type.getBaseType() != null) {
    propertyNames.removeAll(type.getBaseType().getPropertyNames());
  }
  for (String propertyName : propertyNames) {
    EdmProperty property = type.getStructuralProperty(propertyName);
    writer.writeStartElement(XML_PROPERTY);
    writer.writeAttribute(XML_NAME, propertyName);
    String fqnString;
    if (property.isPrimitive()) {
      fqnString = getFullQualifiedName(property.getType(), property.isCollection());
    } else {
      fqnString = getAliasedFullQualifiedName(property.getType(), property.isCollection());
    }
    writer.writeAttribute(XML_TYPE, fqnString);

    // Facets
    if (!property.isNullable()) {
      writer.writeAttribute(XML_NULLABLE, "" + property.isNullable());
    }

    if (!property.isUnicode()) {
      writer.writeAttribute(XML_UNICODE, "" + property.isUnicode());
    }

    if (property.getDefaultValue() != null) {
      writer.writeAttribute(XML_DEFAULT_VALUE, property.getDefaultValue());
    }

    if (property.getMaxLength() != null) {
      writer.writeAttribute(XML_MAX_LENGTH, "" + property.getMaxLength());
    }

    if (property.getPrecision() != null) {
      writer.writeAttribute(XML_PRECISION, "" + property.getPrecision());
    }

    if (property.getScale() != null) {
      writer.writeAttribute(XML_SCALE, "" + property.getScale());
    }
    
    if (property.getSrid() != null) {
        writer.writeAttribute(XML_SRID, "" + property.getSrid());
    }

    appendAnnotations(writer, property);
    writer.writeEndElement();
  }
}
 
Example 20
Source File: MetadataDocumentJsonSerializer.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void appendProperties(final JsonGenerator json, 
    final EdmStructuredType type) throws SerializerException, IOException {
  List<String> propertyNames = new ArrayList<>(type.getPropertyNames());
  if (type.getBaseType() != null) {
    propertyNames.removeAll(type.getBaseType().getPropertyNames());
  }
  for (String propertyName : propertyNames) {
    EdmProperty property = type.getStructuralProperty(propertyName);
    json.writeObjectFieldStart(propertyName);
    String fqnString;
    if (property.isPrimitive()) {
      fqnString = getFullQualifiedName(property.getType());
    } else {
      fqnString = getAliasedFullQualifiedName(property.getType());
    }
    json.writeStringField(TYPE, fqnString);
    if (property.isCollection()) {
      json.writeBooleanField(COLLECTION, property.isCollection());
    }

    // Facets
    if (!property.isNullable()) {
      json.writeBooleanField(NULLABLE, property.isNullable());
    }

    if (!property.isUnicode()) {
      json.writeBooleanField(UNICODE, property.isUnicode());
    }

    if (property.getDefaultValue() != null) {
      json.writeStringField(DEFAULT_VALUE, property.getDefaultValue());
    }

    if (property.getMaxLength() != null) {
      json.writeNumberField(MAX_LENGTH, property.getMaxLength());
    }

    if (property.getPrecision() != null) {
      json.writeNumberField(PRECISION, property.getPrecision());
    }

    if (property.getScale() != null) {
      json.writeNumberField(SCALE, property.getScale());
    }
    
    if (property.getSrid() != null) {
        json.writeStringField(SRID, "" + property.getSrid());
    }

    appendAnnotations(json, property, null);
    json.writeEndObject();
  }
}