[OLINGO-1359] Support replace as a operator
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/expression/MethodOperator.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/expression/MethodOperator.java
index f0f9638..b16fe31 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/expression/MethodOperator.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/expression/MethodOperator.java
@@ -27,7 +27,7 @@
ENDSWITH("endswith"), INDEXOF("indexof"), STARTSWITH("startswith"), TOLOWER("tolower"), TOUPPER("toupper"), TRIM(
"trim"), SUBSTRING("substring"), SUBSTRINGOF("substringof"), CONCAT("concat"), LENGTH("length"), YEAR("year"),
MONTH("month"), DAY("day"), HOUR("hour"), MINUTE("minute"), SECOND("second"), ROUND("round"), FLOOR("floor"),
- CEILING("ceiling");
+ CEILING("ceiling"), REPLACE("replace");
private String syntax;
private String stringRespresentation;
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserImpl.java
index 2741d50..6623a75 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserImpl.java
@@ -862,6 +862,12 @@
combination.add(new ParameterSet(boolean_, string, string));
lAvailableMethods.put(MethodOperator.SUBSTRINGOF.toUriLiteral(), new InfoMethod(MethodOperator.SUBSTRINGOF, 1, -1,
combination));
+
+ // replace
+ combination = new ParameterSetCombination.PSCflex();
+ combination.add(new ParameterSet(string, string, string, string));
+ lAvailableMethods.put(MethodOperator.REPLACE.toUriLiteral(), new InfoMethod(MethodOperator.REPLACE, 3, 3,
+ combination));
// concat
combination = new ParameterSetCombination.PSCflex();
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestAbapCompatibility.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestAbapCompatibility.java
index 0b9c17c..7e13ff2 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestAbapCompatibility.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestAbapCompatibility.java
@@ -385,6 +385,8 @@
// lcl_helper=>veri_type( iv_expression = `second(datetimeoffset'2002-10-10T12:00:00-05:00')` io_expected_type =
// lo_simple_type ).
GetPTF("second(datetimeoffset'2002-10-10T12:00:00-05:00')").aEdmType(EdmInt32.getInstance());
+
+ GetPTF("replace('aBa','B','CCC')").aEdmType(EdmString.getInstance());
}
@Test
@@ -595,22 +597,16 @@
// iv_expected_textid = /iwcor/cx_ds_expr_syntax_error=>function_invalid
// iv_expected_msg = `Invalid function 'replace' detected` ).
// -->see test method abapMethodRleplaceNotAllowed()
- }
-
- @Test
- public void abapMethodRleplaceNotAllowed() // copy of ABAP method test_filter_parser
- {
- // Filter method is NOT allowed
- // lcl_helper=>veri_expression_ex(
- // iv_expression = `replace('aBa','B','CCC')`
- // iv_expected_textid = /iwcor/cx_ds_expr_syntax_error=>function_invalid
- // iv_expected_msg = `Invalid function 'replace' detected` ).
-
- // http://services.odata.org/Northwind/Northwind.svc/Products/?$filter=replace('aBa','B','CCC')
- // -->Unknown function 'replace' at position 0.
- GetPTF("replace('aBa','B','CCC')").aExMsgText(
- "Unknown function \"replace\" at position 1 in \"replace('aBa','B','CCC')\".");
-
+
+ GetPTF("replace('a','b')")
+ .aExMsgText(
+ "No applicable method found for \"replace\" at position 1 in \"replace('a','b')\" "
+ + "with the specified arguments. Method \"replace\" requires exact 3 argument(s).");
+
+ GetPTF("replace('a',1,2)")
+ .aExMsgText(
+ "No applicable method found for \"replace\" at position 1 in "
+ + "\"replace('a',1,2)\" for the specified argument types.");
}
}
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestParser.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestParser.java
index 637287c..7d1bb5a 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestParser.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestParser.java
@@ -179,6 +179,7 @@
GetPTF("startswith('Test','Te')").aSerialized("{startswith('Test','Te')}");
GetPTF("startswith('Test', concat('A','B'))").aSerialized("{startswith('Test',{concat('A','B')})}");
GetPTF("substring('Test', 1 add 2)").aSerialized("{substring('Test',{1 add 2})}");
+ GetPTF("replace('Test', ' ', '')").aSerialized("{replace('Test',' ','')}");
}
@Test
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
index a64ab9a..913f1b4 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
@@ -1471,6 +1471,8 @@
final int offset = second.length() == 0 ? 0 : Integer.parseInt(second);
final int length = third.length() == 0 ? 0 : Integer.parseInt(second);
return first.substring(offset, offset + length);
+ case REPLACE:
+ return first.replace(second, third);
case SUBSTRINGOF:
return Boolean.toString(second.contains(first));
case CONCAT: