Java Code Examples for org.apache.olingo.server.api.uri.UriParameter#getText()

The following examples show how to use org.apache.olingo.server.api.uri.UriParameter#getText() . 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: DataProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Map<String, Parameter> getFunctionParameters(final EdmFunction function,
    final List<UriParameter> parameters, final UriInfoResource uriInfo) throws DataProviderException {
  Map<String, Parameter> values = new HashMap<String, Parameter>();
  for (final UriParameter parameter : parameters) {
    if (parameter.getExpression() != null && !(parameter.getExpression() instanceof Literal)) {
      throw new DataProviderException("Expression in function-parameter value is not supported yet!",
          HttpStatusCode.NOT_IMPLEMENTED);
    }
    final EdmParameter edmParameter = function.getParameter(parameter.getName());
    final String text = parameter.getAlias() == null ?
        parameter.getText() :
        uriInfo.getValueForAlias(parameter.getAlias());
    if (text != null) {
      try {
        values.put(parameter.getName(),
            odata.createFixedFormatDeserializer().parameter(text, edmParameter));
      } catch (final DeserializerException e) {
        throw new DataProviderException("Invalid function parameter.", HttpStatusCode.BAD_REQUEST, e);
      }
    }
  }
  return values;
}
 
Example 2
Source File: ODataAdapter.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method updates entity in tables where the request doesn't specify the odata e-tag.
 *
 * @param edmEntityType Entity type
 * @param entity        Entity
 * @param keys          Keys
 * @param merge         Merge
 * @throws DataServiceFault
 * @throws ODataApplicationException
 */
private void updateEntity(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keys, boolean merge)
        throws DataServiceFault, ODataApplicationException {
    ODataEntry entry = new ODataEntry();
    for (UriParameter key : keys) {
        String value = key.getText();
        if (value.startsWith("'") && value.endsWith("'")) {
            value = value.substring(1, value.length() - 1);
        }
        entry.addValue(key.getName(), value);
    }
    for (String property : edmEntityType.getPropertyNames()) {
        Property updateProperty = entity.getProperty(property);
        if (isKey(edmEntityType, property)) {
            continue;
        }
        // the request payload might not consider ALL properties, so it can be null
        if (updateProperty == null) {
            // if a property has NOT been added to the request payload
            // depending on the HttpMethod, our behavior is different
            if (merge) {
                // as of the OData spec, in case of PATCH, the existing property is not touched
                continue;
            } else {
                // as of the OData spec, in case of PUT, the existing property is set to null (or to default value)
                entry.addValue(property, null);
                continue;
            }
        }
        EdmProperty propertyType = (EdmProperty) edmEntityType.getProperty(property);
        entry.addValue(property, readPrimitiveValueInString(propertyType, updateProperty.getValue()));
    }
    this.dataHandler.updateEntityInTable(edmEntityType.getName(), entry);
}
 
Example 3
Source File: ODataAdapter.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method wraps list of eir parameters into single Data Entry object.
 *
 * @param keys list of URI parameters
 * @return DataEntry
 * @see UriParameter
 * @see DataEntry
 */
private ODataEntry wrapKeyParamToDataEntry(List<UriParameter> keys) {
    ODataEntry entry = new ODataEntry();
    for (UriParameter key : keys) {
        String value = key.getText();
        if (value.startsWith("'") && value.endsWith("'")) {
            value = value.substring(1, value.length() - 1);
        }
        entry.addValue(key.getName(), value);
    }
    return entry;
}
 
Example 4
Source File: ParserHelper.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static void validateFunctionParameterFacets(final EdmFunction function, 
    final List<UriParameter> parameters, Edm edm, Map<String, AliasQueryOption> aliases) 
        throws UriParserException, UriValidationException {
  for (UriParameter parameter : parameters) {
    EdmParameter edmParameter = function.getParameter(parameter.getName());
    final EdmType type = edmParameter.getType();
    final EdmTypeKind kind = type.getKind();
    if ((kind == EdmTypeKind.PRIMITIVE || kind == EdmTypeKind.DEFINITION || kind == EdmTypeKind.ENUM)
        && !edmParameter.isCollection()) {
      final EdmPrimitiveType primitiveType = (EdmPrimitiveType) type;
      String text = null;
      try {
        text = parameter.getAlias() == null ?
            parameter.getText() :
              aliases.containsKey(parameter.getAlias()) ?
                  parseAliasValue(parameter.getAlias(),
                      edmParameter.getType(), edmParameter.isNullable(), edmParameter.isCollection(),
                      edm, type, aliases).getText() : null;
                      if (edmParameter.getMapping() == null) {
                        primitiveType.valueOfString(primitiveType.fromUriLiteral(text),
                            edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), 
                            edmParameter.getScale(), true, primitiveType.getDefaultType());
                      } else {
                        primitiveType.valueOfString(primitiveType.fromUriLiteral(text),
                            edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), 
                            edmParameter.getScale(), true, edmParameter.getMapping().getMappedJavaClass());
                      }
      } catch (final EdmPrimitiveTypeException e) {
        throw new UriValidationException(
            "Invalid value '" + text + "' for parameter " + parameter.getName(), e,
            UriValidationException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, parameter.getName());
      }
    }
  }
}
 
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 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 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 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 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;
    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 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 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 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 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 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 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 = 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 18
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public Entity readDataFromEntity(final EdmEntityType edmEntityType,
    final List<UriParameter> keys) throws DataProviderException {
  EntityCollection coll = data.get(edmEntityType.getName());
  List<Entity> entities = coll.getEntities();
  try {
    for (final Entity entity : entities) {
      boolean found = true;
      for (final UriParameter key : keys) {
        EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(key.getName());
        Object value =  findPropertyRefValue(entity, refType);
        
        final EdmProperty property = refType.getProperty();
        final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
        
        if (key.getExpression() != null && !(key.getExpression() instanceof Literal)) {
          throw new DataProviderException("Expression in key value is not supported yet!",
              HttpStatusCode.NOT_IMPLEMENTED);
        }
        final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
        Object keyValue = null;
        if (Calendar.class.isAssignableFrom(value.getClass())) {
          keyValue = type.valueOfString(type.fromUriLiteral(text),
              property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
              property.isUnicode(), Calendar.class);
        } else {
          keyValue = type.valueOfString(type.fromUriLiteral(text),
              property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
              property.isUnicode(), value.getClass());
        }
        if (!value.equals(keyValue)) {
          found = false;
          break;
        }
      }
      if (found) {
        return entity;
      }
    }
    return null;
  } catch (final EdmPrimitiveTypeException e) {
    throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
  }
}
 
Example 19
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public Entity read(final EdmEntityType edmEntityType, final EntityCollection entitySet,
    final List<UriParameter> keys) throws DataProviderException {
  try {
    for (final Entity entity : entitySet.getEntities()) {
      boolean found = true;
      for (final UriParameter key : keys) {
        EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(key.getName());
        Object value =  findPropertyRefValue(entity, refType);
        
        final EdmProperty property = refType.getProperty();
        final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
        
        if (key.getExpression() != null && !(key.getExpression() instanceof Literal)) {
          throw new DataProviderException("Expression in key value is not supported yet!",
              HttpStatusCode.NOT_IMPLEMENTED);
        }
        Object keyValue = null;
        final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
        if (Calendar.class.isAssignableFrom(value.getClass())) {
          keyValue = type.valueOfString(type.fromUriLiteral(text),
              property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
              property.isUnicode(), Calendar.class);
        } else {
          keyValue = type.valueOfString(type.fromUriLiteral(text),
              property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
              property.isUnicode(), value.getClass());
        }
        if (!value.equals(keyValue)) {
          found = false;
          break;
        }
      }
      if (found) {
        return entity;
      }
    }
    return null;
  } catch (final EdmPrimitiveTypeException e) {
    throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
  }
}
 
Example 20
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;
}