org.apache.olingo.odata2.api.uri.expression.MethodOperator Java Examples

The following examples show how to use org.apache.olingo.odata2.api.uri.expression.MethodOperator. 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: JsonVisitor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public Object visitMethod(final MethodExpression methodExpression, final MethodOperator method,
    final List<Object> parameters) {
  try {
    StringWriter writer = new StringWriter();
    JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
    jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", methodExpression.getKind().toString()).separator()
        .namedStringValueRaw("operator", method.toUriLiteral()).separator().namedStringValueRaw("type",
            getType(methodExpression)).separator().name("parameters").beginArray();
    boolean first = true;
    for (Object parameter : parameters) {
      if (first) {
        first = false;
      } else {
        jsonStreamWriter.separator();
      }
      jsonStreamWriter.unquotedValue(parameter.toString());
    }
    jsonStreamWriter.endArray().endObject();
    writer.flush();
    return writer.toString();
  } catch (final IOException e) {
    return null;
  }
}
 
Example #2
Source File: VisitorTool.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public Object visitMethod(final MethodExpression methodExpression, final MethodOperator method,
    final List<Object> retParameters) {
  StringBuilder sb = new StringBuilder();
  sb.append("{");
  sb.append(method.toUriLiteral());

  sb.append("(");
  for (int i = 0; i < retParameters.size(); i++) {
    if (i != 0) {
      sb.append(",");
    }
    sb.append(retParameters.get(i));
  }

  sb.append(")}");

  return sb.toString();
}
 
Example #3
Source File: InfoMethod.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public InfoMethod(final MethodOperator method, final ParameterSetCombination combination) {
  this.method = method;
  syntax = method.toUriLiteral();
  minParameter = 1;
  maxParameter = 1;
  this.combination = combination;
}
 
Example #4
Source File: InfoMethod.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public InfoMethod(final MethodOperator method, final int minParameters, final int maxParameters,
    final ParameterSetCombination combination) {
  this.method = method;
  syntax = method.toUriLiteral();
  minParameter = minParameters;
  maxParameter = maxParameters;
  this.combination = combination;
}
 
Example #5
Source File: InfoMethod.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public InfoMethod(final MethodOperator method, final String string, final int minParameters, final int maxParameters,
    final ParameterSetCombination combination) {
  this.method = method;
  syntax = string;
  minParameter = minParameters;
  maxParameter = maxParameters;
  this.combination = combination;
}
 
Example #6
Source File: FilterToJsonTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testToJsonMethod() throws Exception {
  FilterExpression expression = UriParser.parseFilter(null, null, "concat('aa','b')");
  String jsonString = toJson(expression);
  Gson gsonConverter = new Gson();

  LinkedTreeMap<String, Object> jsonMap = gsonConverter.fromJson(jsonString, LinkedTreeMap.class);
  checkMethod(jsonMap, MethodOperator.CONCAT, "Edm.String");

  List<Object> parameter = (List<Object>) jsonMap.get(PARAMETERS);
  checkLiteral((LinkedTreeMap<String, Object>) parameter.get(0), "Edm.String", "aa");
  checkLiteral((LinkedTreeMap<String, Object>) parameter.get(1), "Edm.String", "b");
}
 
Example #7
Source File: FilterToJsonTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void checkMethod(final LinkedTreeMap<String, Object> method, final MethodOperator expectedOperator,
    final String expectedType) {
  assertEquals(ExpressionKind.METHOD.toString(), method.get(NODETYPE));
  assertEquals(expectedOperator.toString(), method.get(OPERATOR));
  assertEquals(expectedType, method.get(TYPE));
  assertNotNull(method.get(PARAMETERS));
}
 
Example #8
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private UriInfo mockURIInfoForEntitySet(EdmMapping mapping, String methodName) throws EdmException {
  
  UriInfo uriInfo = EasyMock.createMock(UriInfo.class);
  List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
  EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(mapping);
  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
  EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
  EasyMock.expect(edmProperty.getMapping()).andStubReturn((EdmMapping)mockEdmMappingForProperty());
  
  EdmProperty edmProperty1 = EasyMock.createMock(EdmProperty.class);
  EasyMock.expect(edmProperty1.getMapping()).andStubReturn((EdmMapping)mockEdmMappingForProperty1());
  
  EdmNavigationProperty navEdmProperty = EasyMock.createMock(EdmNavigationProperty.class);
  EasyMock.expect(navEdmProperty.getMapping()).andStubReturn((EdmMapping)mockNavEdmMappingForProperty());
  
  OrderByExpression orderbyExpression = EasyMock.createMock(OrderByExpression.class);
  List<OrderExpression> orders = new ArrayList<OrderExpression>();
  EasyMock.expect(orderbyExpression.getOrders()).andStubReturn(orders);
  EasyMock.expect(uriInfo.getOrderBy()).andStubReturn(orderbyExpression);
  FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
  MethodExpression commonExpression = EasyMock.createMock(MethodExpression.class);
  EasyMock.expect(commonExpression.getKind()).andStubReturn(ExpressionKind.METHOD);
  PropertyExpression propExp = EasyMock.createMock(PropertyExpression.class);
  LiteralExpression literalExp = EasyMock.createMock(LiteralExpression.class);
  MemberExpression memberExp = EasyMock.createMock(MemberExpression.class);
  List<CommonExpression> parameterList = new ArrayList<CommonExpression>();
  
  PropertyExpression navPropExp = EasyMock.createMock(PropertyExpression.class);
  if ("substringof".equals(methodName)) {
    EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.SUBSTRINGOF);
    EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2);
    EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'");
    EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
    parameterList.add(literalExp);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
  } else if ("startsWith".equals(methodName)) {
    EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.STARTSWITH);
    EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'");
    EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
    parameterList.add(literalExp);
  } else if ("endsWith".equals(methodName)) {
    EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.ENDSWITH);
    EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'");
    EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
    parameterList.add(literalExp);
  } else if ("substringof_1".equals(methodName)) {
    EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.SUBSTRINGOF);
    EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2);
    EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'");
    EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
    parameterList.add(literalExp);
    EasyMock.expect(memberExp.getKind()).andStubReturn(ExpressionKind.MEMBER);
    EasyMock.expect(memberExp.getProperty()).andStubReturn(propExp);
    
    EasyMock.expect(memberExp.getPath()).andStubReturn(navPropExp);
    EasyMock.expect(navPropExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    EasyMock.expect(navPropExp.getEdmProperty()).andStubReturn(navEdmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty1);
    
    parameterList.add(propExp);
  }
  
  EasyMock.expect(commonExpression.getParameters()).andStubReturn(parameterList);
  
  EasyMock.expect(filterExpression.getExpression()).andStubReturn(commonExpression);
  EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
  EasyMock.expect(filterExpression.getExpressionString()).andStubReturn("substringof('a.b.c',Id)");
  EasyMock.expect(uriInfo.getFilter()).andStubReturn(filterExpression);
  EasyMock.replay(edmEntityType, edmEntitySet, orderbyExpression, filterExpression, 
      commonExpression, literalExp, propExp, uriInfo, edmProperty, memberExp,
      edmProperty1, navEdmProperty);
  return uriInfo;

}
 
Example #9
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private UriInfo mockURIInfoForEntitySetWithBinaryFilterExpression
(EdmMapping mapping, String methodName) throws EdmException {
  
  UriInfo uriInfo = EasyMock.createMock(UriInfo.class);
  List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
  EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(mapping);
  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
  EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
  EasyMock.expect(edmProperty.getMapping()).andStubReturn((EdmMapping)mockEdmMappingForProperty());
  OrderByExpression orderbyExpression = EasyMock.createMock(OrderByExpression.class);
  List<OrderExpression> orders = new ArrayList<OrderExpression>();
  EasyMock.expect(orderbyExpression.getOrders()).andStubReturn(orders);
  EasyMock.expect(uriInfo.getOrderBy()).andStubReturn(orderbyExpression);
  FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
  BinaryExpression commonExpression = EasyMock.createMock(BinaryExpression.class);
  EasyMock.expect(commonExpression.getOperator()).andStubReturn(BinaryOperator.EQ);
  EasyMock.expect(commonExpression.getKind()).andStubReturn(ExpressionKind.BINARY);
  MethodExpression methodExp = EasyMock.createMock(MethodExpression.class);
  EasyMock.expect(commonExpression.getLeftOperand()).andStubReturn(methodExp);
  EdmSimpleType type = EasyMock.createMock(EdmSimpleType.class);;
  EasyMock.expect(methodExp.getEdmType()).andStubReturn(type );
  
  LiteralExpression literalValueExp = EasyMock.createMock(LiteralExpression.class);
  EasyMock.expect(commonExpression.getRightOperand()).andStubReturn(literalValueExp);
  EasyMock.expect(literalValueExp.getUriLiteral()).andStubReturn("'a%.b*.c'");
  EasyMock.expect(literalValueExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
  EasyMock.expect(literalValueExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
  
  PropertyExpression propExp = EasyMock.createMock(PropertyExpression.class);
  LiteralExpression literalExp1 = EasyMock.createMock(LiteralExpression.class);
  LiteralExpression literalExp2 = EasyMock.createMock(LiteralExpression.class);
  List<CommonExpression> parameterList = new ArrayList<CommonExpression>();
  if ("substring".equals(methodName)) {
    EasyMock.expect(methodExp.getMethod()).andStubReturn(MethodOperator.SUBSTRING);
    EasyMock.expect(methodExp.getKind()).andStubReturn(ExpressionKind.METHOD);
    EasyMock.expect(methodExp.getParameterCount()).andStubReturn(3);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(literalExp1.getUriLiteral()).andStubReturn("1");
    EasyMock.expect(literalExp1.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp1.getEdmType()).andStubReturn(EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance());
    parameterList.add(literalExp1);
    EasyMock.expect(literalExp2.getUriLiteral()).andStubReturn("2");
    EasyMock.expect(literalExp2.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp2.getEdmType()).andStubReturn(EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance());
    parameterList.add(literalExp2);
    EasyMock.expect(methodExp.getParameters()).andStubReturn(parameterList);
  } else if ("toLower".equals(methodName)) {
    EasyMock.expect(methodExp.getMethod()).andStubReturn(MethodOperator.TOLOWER);
    EasyMock.expect(methodExp.getKind()).andStubReturn(ExpressionKind.METHOD);
    EasyMock.expect(methodExp.getParameterCount()).andStubReturn(1);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(methodExp.getParameters()).andStubReturn(parameterList);
  } else if ("toUpper".equals(methodName)) {
    EasyMock.expect(methodExp.getMethod()).andStubReturn(MethodOperator.TOUPPER);
    EasyMock.expect(methodExp.getKind()).andStubReturn(ExpressionKind.METHOD);
    EasyMock.expect(methodExp.getParameterCount()).andStubReturn(1);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(methodExp.getParameters()).andStubReturn(parameterList);
  }
  EasyMock.expect(filterExpression.getExpression()).andStubReturn(commonExpression);
  EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
  EasyMock.expect(filterExpression.getExpressionString()).andStubReturn("substring(CompanyName,1,2) eq 'a.b.c'");
  EasyMock.expect(uriInfo.getFilter()).andStubReturn(filterExpression);
  EasyMock.replay(edmEntityType, edmEntitySet, orderbyExpression, filterExpression, 
      commonExpression, literalExp1, literalExp2, propExp, uriInfo, edmProperty, 
      methodExp, literalValueExp);
  return uriInfo;

}
 
Example #10
Source File: MethodExpressionImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public MethodOperator getMethod() {
  return infoMethod.getMethod();
}
 
Example #11
Source File: InfoMethod.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public MethodOperator getMethod() {
  return method;
}
 
Example #12
Source File: FilterParserImplTool.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public void addTestfunctions() {
  Map<String, InfoMethod> lAvailableMethods = new HashMap<String, InfoMethod>(availableMethods);
  ParameterSetCombination combination = null;
  // create type helpers

  // TESTING
  combination = new ParameterSetCombination.PSCflex();
  lAvailableMethods.put("testingMINMAX1",
      new InfoMethod(MethodOperator.CONCAT, "testingMINMAX1", -1, -1, combination));

  // TESTING
  combination = new ParameterSetCombination.PSCflex();
  lAvailableMethods
      .put("testingMINMAX2", new InfoMethod(MethodOperator.CONCAT, "testingMINMAX2", 0, -1, combination));

  // TESTING
  combination = new ParameterSetCombination.PSCflex();
  lAvailableMethods
      .put("testingMINMAX3", new InfoMethod(MethodOperator.CONCAT, "testingMINMAX3", 2, -1, combination));

  // TESTING
  combination = new ParameterSetCombination.PSCflex();
  lAvailableMethods
      .put("testingMINMAX4", new InfoMethod(MethodOperator.CONCAT, "testingMINMAX4", -1, 0, combination));

  // TESTING
  combination = new ParameterSetCombination.PSCflex();
  lAvailableMethods
      .put("testingMINMAX5", new InfoMethod(MethodOperator.CONCAT, "testingMINMAX5", -1, 2, combination));

  // TESTING
  combination = new ParameterSetCombination.PSCflex();
  lAvailableMethods.put("testingMINMAX6", new InfoMethod(MethodOperator.CONCAT, "testingMINMAX6", 1, 2, combination));

  // TESTING
  combination = new ParameterSetCombination.PSCflex();
  lAvailableMethods.put("testingMINMAX7", new InfoMethod(MethodOperator.CONCAT, "testingMINMAX7", 1, 1, combination));

  availableMethods = Collections.unmodifiableMap(lAvailableMethods);

}
 
Example #13
Source File: ODataParser.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitMethod(MethodExpression methodExpression, MethodOperator method, List<Object> parameters) {
    throw new SearchParseException("Unsupported operation visitMethod: " + methodExpression
        + "," + method + "," + parameters);
}