olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject olingo-odata2 git commit: [OLINGO-660] Enhancement for client use cases
Date Wed, 13 May 2015 12:45:44 GMT
Repository: olingo-odata2
Updated Branches:
  refs/heads/master 936c95e96 -> a189877b6


[OLINGO-660] Enhancement for client use cases


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/a189877b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/a189877b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/a189877b

Branch: refs/heads/master
Commit: a189877b6c42e507f105aa4f76e6cb4fd9617d8f
Parents: 936c95e
Author: Michael Bolz <michael.bolz@sap.com>
Authored: Wed May 13 09:15:38 2015 +0200
Committer: Michael Bolz <michael.bolz@sap.com>
Committed: Wed May 13 14:42:42 2015 +0200

----------------------------------------------------------------------
 .../olingo/odata2/core/edm/EdmDecimal.java      | 21 ++++++----------
 .../odata2/core/edm/EdmSimpleTypeTest.java      | 26 ++++++++++++--------
 2 files changed, 23 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a189877b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDecimal.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDecimal.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDecimal.java
index 91178a0..b5d5adf 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDecimal.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDecimal.java
@@ -34,11 +34,12 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
  */
 public class EdmDecimal extends AbstractSimpleType {
 
-  // value-range limitation according to the CSDL document
-  private static final int MAX_DIGITS = 29;
-
-  private static final Pattern PATTERN = Pattern
-      .compile("(?:\\+|-)?(?:0*(\\p{Digit}{1,29}?))(?:\\.(\\p{Digit}{1,29}?)0*)?(M|m)?");
+  // value-range limitation which is increased compared to general OData V2 specification
+  // (according to the CSDL document the limit is 29 digits)
+  // This is to support services which allows a higher precision for EdmDecimal without
+  // breaking the backward capability of Olingo V2
+  private static final Pattern PATTERN =
+      Pattern.compile("(?:\\+|-)?(?:0*(\\p{Digit}+?))(?:\\.(\\p{Digit}+?)0*)?(M|m)?");
   private static final EdmDecimal instance = new EdmDecimal();
 
   public static EdmDecimal getInstance() {
@@ -83,7 +84,7 @@ public class EdmDecimal extends AbstractSimpleType {
         && (literalKind == EdmLiteralKind.URI) != (matcher.group(3) == null);
   }
 
-  private static final boolean validatePrecisionAndScale(final String value, final EdmFacets
facets) {
+  private static boolean validatePrecisionAndScale(final String value, final EdmFacets facets)
{
     if (facets == null || facets.getPrecision() == null && facets.getScale() == null)
{
       return true;
     }
@@ -155,9 +156,6 @@ public class EdmDecimal extends AbstractSimpleType {
         || value instanceof BigInteger) {
       result = value.toString();
       final int digits = result.startsWith("-") ? result.length() - 1 : result.length();
-      if (digits > MAX_DIGITS) {
-        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
-      }
       if (facets != null && facets.getPrecision() != null && facets.getPrecision()
< digits) {
         throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value,
facets));
       }
@@ -176,11 +174,6 @@ public class EdmDecimal extends AbstractSimpleType {
         throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value),
e);
       }
 
-      if (bigDecimalValue.precision() - bigDecimalValue.scale() > MAX_DIGITS
-          || bigDecimalValue.scale() > MAX_DIGITS) {
-        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
-      }
-
       final int digits = bigDecimalValue.scale() >= 0 ?
           Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) :
           bigDecimalValue.precision() - bigDecimalValue.scale();

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a189877b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java
index 7ddb197..47a9417 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java
@@ -686,6 +686,8 @@ public class EdmSimpleTypeTest extends BaseTest {
     assertEquals("255", instance.valueToString(255L, EdmLiteralKind.DEFAULT, null));
     assertEquals("12345678901234567890123456789", instance.valueToString(
         new BigInteger("12345678901234567890123456789"), EdmLiteralKind.DEFAULT, null));
+    assertEquals("1234567890123456789012345678901234567890", instance.valueToString(
+        new BigInteger("1234567890123456789012345678901234567890"), EdmLiteralKind.DEFAULT,
null));
     assertEquals("0.00390625", instance.valueToString(1.0 / 256, EdmLiteralKind.DEFAULT,
null));
     assertEquals("-0.125", instance.valueToString(-0.125f, EdmLiteralKind.DEFAULT, null));
     assertEquals("-1234567890.1234567890", instance.valueToString(new BigDecimal("-1234567890.1234567890"),
@@ -699,15 +701,14 @@ public class EdmSimpleTypeTest extends BaseTest {
     assertEquals("32768", instance.valueToString(32768, EdmLiteralKind.DEFAULT, getPrecisionScaleFacets(5,
null)));
     assertEquals("0.5", instance.valueToString(0.5, EdmLiteralKind.DEFAULT, getPrecisionScaleFacets(1,
null)));
     assertEquals("0.5", instance.valueToString(0.5, EdmLiteralKind.DEFAULT, getPrecisionScaleFacets(null,
1)));
-    assertEquals("100", instance.valueToString(new BigDecimal(BigInteger.ONE, -2), EdmLiteralKind.DEFAULT,
-        getPrecisionScaleFacets(3, null)));
+    assertEquals("100", instance
+        .valueToString(new BigDecimal(BigInteger.ONE, -2), EdmLiteralKind.DEFAULT, getPrecisionScaleFacets(3,
null)));
+
+    assertEquals("1000000000000000000000000000000000000000",
+        instance.valueToString(new BigDecimal(BigInteger.TEN, -38), EdmLiteralKind.DEFAULT,
null));
+    assertEquals("0.0000000000000000000000000000000000000001",
+        instance.valueToString(new BigDecimal(BigInteger.ONE, 40), EdmLiteralKind.DEFAULT,
null));
 
-    expectErrorInValueToString(instance, new BigInteger("123456789012345678901234567890"),
EdmLiteralKind.DEFAULT,
-        null, EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT);
-    expectErrorInValueToString(instance, new BigDecimal(BigInteger.TEN, -28), EdmLiteralKind.DEFAULT,
null,
-        EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT);
-    expectErrorInValueToString(instance, new BigDecimal(BigInteger.ONE, 30), EdmLiteralKind.DEFAULT,
null,
-        EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT);
     expectErrorInValueToString(instance, -1234, EdmLiteralKind.DEFAULT, getPrecisionScaleFacets(2,
null),
         EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED);
     expectErrorInValueToString(instance, 1234, EdmLiteralKind.DEFAULT, getPrecisionScaleFacets(3,
null),
@@ -1294,6 +1295,13 @@ public class EdmSimpleTypeTest extends BaseTest {
     assertEquals(new BigDecimal("-12345678901234567890"), instance.valueOfString("-12345678901234567890M",
         EdmLiteralKind.URI, null, BigDecimal.class));
     assertEquals(Short.valueOf((short) 0), instance.valueOfString("0M", EdmLiteralKind.URI,
null, Short.class));
+    // 0.9646153846153846153846153846153800
+    assertEquals(new BigDecimal("0.9646153846153846153846153846153800"),
+        instance.valueOfString("0.9646153846153846153846153846153800M",
+        EdmLiteralKind.URI, null, BigDecimal.class));
+    assertEquals(new BigDecimal("1234567890123456789012345678901234567890"),
+        instance.valueOfString("1234567890123456789012345678901234567890M",
+            EdmLiteralKind.URI, null, BigDecimal.class));
 
     assertEquals(Integer.valueOf(-32768), instance.valueOfString("-32768", EdmLiteralKind.DEFAULT,
         getPrecisionScaleFacets(42, null), Integer.class));
@@ -1340,8 +1348,6 @@ public class EdmSimpleTypeTest extends BaseTest {
         EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT);
     expectErrorInValueOfString(instance, "0x42", EdmLiteralKind.DEFAULT, null,
         EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT);
-    expectErrorInValueOfString(instance, "123456789012345678901234567890", EdmLiteralKind.DEFAULT,
null,
-        EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT);
 
     expectTypeErrorInValueOfString(instance, "1", EdmLiteralKind.DEFAULT);
     expectUnconvertibleErrorInValueOfString(instance, "-129", Byte.class);


Mime
View raw message