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

The following examples show how to use org.apache.olingo.server.api.uri.UriParameter#getExpression() . 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: ParserHelper.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static void validateFunctionParameters(final EdmFunction function, final List<UriParameter> parameters,
    final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases)
    throws UriParserException, UriValidationException {
  for (final UriParameter parameter : parameters) {
    final String parameterName = parameter.getName();
    final EdmParameter edmParameter = function.getParameter(parameterName);
    final boolean isNullable = edmParameter.isNullable();
    if (parameter.getText() == null && parameter.getExpression() == null && !isNullable) {
      if (parameter.getAlias() == null) {
        // No alias, value is explicitly null.
        throw new UriValidationException("Missing non-nullable parameter " + parameterName,
            UriValidationException.MessageKeys.MISSING_PARAMETER, parameterName);
      } else {
        final String valueForAlias = aliases.containsKey(parameter.getAlias()) ?
            parseAliasValue(parameter.getAlias(),
                edmParameter.getType(), edmParameter.isNullable(), edmParameter.isCollection(),
                edm, referringType, aliases).getText() :
            null;
        // Alias value is missing or explicitly null.
        if (valueForAlias == null) {
          throw new UriValidationException("Missing alias for " + parameterName,
              UriValidationException.MessageKeys.MISSING_ALIAS, parameter.getAlias());
        }
      }
    }
  }
}
 
Example 3
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 4
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);
  }
}