olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From archana...@apache.org
Subject olingo-odata2 git commit: [OLINGO-1283]Facet info for Function Import parameters not honored
Date Mon, 06 Aug 2018 11:21:25 GMT
Repository: olingo-odata2
Updated Branches:
  refs/heads/master 9aa18ee4f -> b96a9d152


[OLINGO-1283]Facet info for Function Import parameters not honored


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

Branch: refs/heads/master
Commit: b96a9d1525067d7241cbbc1af55ac91b6eeb18da
Parents: 9aa18ee
Author: Archana Rai <archana.rai@sap.com>
Authored: Mon Aug 6 16:51:16 2018 +0530
Committer: Archana Rai <archana.rai@sap.com>
Committed: Mon Aug 6 16:51:16 2018 +0530

----------------------------------------------------------------------
 .../odata2/api/edm/EdmSimpleTypeFacade.java      | 10 ++++++++++
 .../odata2/core/edm/EdmSimpleTypeFacadeImpl.java | 17 +++++++++++++----
 .../apache/olingo/odata2/core/edm/EdmString.java |  2 +-
 .../olingo/odata2/core/uri/UriParserImpl.java    | 19 ++++++++++++++++++-
 4 files changed, 42 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b96a9d15/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmSimpleTypeFacade.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmSimpleTypeFacade.java
b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmSimpleTypeFacade.java
index 82a82b8..c8988a5 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmSimpleTypeFacade.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmSimpleTypeFacade.java
@@ -35,6 +35,16 @@ public interface EdmSimpleTypeFacade {
   public EdmLiteral parseUriLiteral(final String uriLiteral) throws EdmLiteralException;
 
   /**
+   * IMPORTANT: Use {@link EdmSimpleTypeKind} parseUriLiteral for the implementation.
+   * <p>This method definition is used only inside the core of this library.
+   * @param uriLiteral
+   * @param facets
+   * @return the parsed literal
+   * @throws EdmLiteralException
+   */
+  public EdmLiteral parseUriLiteral(final String uriLiteral, final EdmFacets facets) throws
EdmLiteralException;
+  
+  /**
    * IMPORTANT: Use {@link EdmSimpleTypeKind#getEdmSimpleTypeInstance()} for the application
development.
    * 
    * <p>This method definition is used only inside the core of this library.</p>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b96a9d15/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeFacadeImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeFacadeImpl.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeFacadeImpl.java
index 25a5dc8..58d0e93 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeFacadeImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeFacadeImpl.java
@@ -18,6 +18,7 @@
  ******************************************************************************/
 package org.apache.olingo.odata2.core.edm;
 
+import org.apache.olingo.odata2.api.edm.EdmFacets;
 import org.apache.olingo.odata2.api.edm.EdmLiteral;
 import org.apache.olingo.odata2.api.edm.EdmLiteralException;
 import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
@@ -31,6 +32,8 @@ import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
  *  
  */
 public class EdmSimpleTypeFacadeImpl implements EdmSimpleTypeFacade {
+  
+  private EdmFacets facets = null;
 
   @Override
   public EdmLiteral parseUriLiteral(final String uriLiteral) throws EdmLiteralException {
@@ -46,7 +49,7 @@ public class EdmSimpleTypeFacadeImpl implements EdmSimpleTypeFacade {
         && uriLiteral.startsWith("'") && uriLiteral.endsWith("'")) {
       try {
         final EdmSimpleType type = getEdmSimpleType(EdmSimpleTypeKind.String);
-        return new EdmLiteral(type, type.valueOfString(uriLiteral, EdmLiteralKind.URI, null,
String.class));
+        return new EdmLiteral(type, type.valueOfString(uriLiteral, EdmLiteralKind.URI, facets,
String.class));
       } catch (EdmSimpleTypeException e) {
         throw new EdmLiteralException(EdmLiteralException.LITERALFORMAT.addContent(uriLiteral),
e);
       }
@@ -56,7 +59,7 @@ public class EdmSimpleTypeFacadeImpl implements EdmSimpleTypeFacade {
       try {
         final int i =
             getEdmSimpleType(EdmSimpleTypeKind.Int32)
-                .valueOfString(uriLiteral, EdmLiteralKind.URI, null, Integer.class);
+                .valueOfString(uriLiteral, EdmLiteralKind.URI, facets, Integer.class);
         if (i == 0 || i == 1) {
           return new EdmLiteral(getInternalEdmSimpleTypeByString("Bit"), uriLiteral);
         }
@@ -109,8 +112,8 @@ public class EdmSimpleTypeFacadeImpl implements EdmSimpleTypeFacade {
     if (uriLiteral.startsWith("X'") || uriLiteral.startsWith("binary'")) {
       try {
         final EdmSimpleType type = getEdmSimpleType(EdmSimpleTypeKind.Binary);
-        final byte[] value = type.valueOfString(uriLiteral, EdmLiteralKind.URI, null, byte[].class);
-        return new EdmLiteral(type, type.valueToString(value, EdmLiteralKind.DEFAULT, null));
+        final byte[] value = type.valueOfString(uriLiteral, EdmLiteralKind.URI, facets, byte[].class);
+        return new EdmLiteral(type, type.valueToString(value, EdmLiteralKind.DEFAULT, facets));
       } catch (EdmSimpleTypeException e) {
         throw new EdmLiteralException(EdmLiteralException.LITERALFORMAT.addContent(uriLiteral),
e);
       }
@@ -118,6 +121,12 @@ public class EdmSimpleTypeFacadeImpl implements EdmSimpleTypeFacade {
 
     throw new EdmLiteralException(EdmLiteralException.UNKNOWNLITERAL.addContent(uriLiteral));
   }
+  
+  @Override
+  public EdmLiteral parseUriLiteral(String uriLiteral, EdmFacets facets) throws EdmLiteralException
{
+    this.facets = facets;
+    return parseUriLiteral(uriLiteral);
+  }
 
   private static EdmLiteral createEdmLiteral(final EdmSimpleTypeKind typeKind, final String
literal,
       final int prefixLength, final int suffixLength) throws EdmLiteralException {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b96a9d15/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmString.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmString.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmString.java
index 0be9b64..e52d46e 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmString.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmString.java
@@ -58,7 +58,7 @@ public class EdmString extends AbstractSimpleType {
 
     if (facets != null
         && (facets.isUnicode() != null && !facets.isUnicode() &&
!PATTERN_ASCII.matcher(result).matches()
-        || facets.getMaxLength() != null && facets.getMaxLength() < result.length()))
{
+        || facets.getMaxLength() != null && facets.getMaxLength()!=0 && facets.getMaxLength()
< result.length())) {
       throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value,
facets));
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b96a9d15/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
index ac1927e..8373df7 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
@@ -35,6 +35,7 @@ import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
 import org.apache.olingo.odata2.api.edm.EdmEntitySet;
 import org.apache.olingo.odata2.api.edm.EdmEntityType;
 import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
 import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
 import org.apache.olingo.odata2.api.edm.EdmLiteral;
 import org.apache.olingo.odata2.api.edm.EdmLiteralException;
@@ -893,7 +894,7 @@ public class UriParserImpl extends UriParser {
           }
         }
 
-        EdmLiteral uriLiteral = parseLiteral(value, (EdmSimpleType) parameter.getType());
+        EdmLiteral uriLiteral = parseLiteral(value, (EdmSimpleType) parameter.getType(),
parameter.getFacets());
         uriResult.addFunctionImportParameter(parameterName, uriLiteral);
       }
     }
@@ -901,6 +902,22 @@ public class UriParserImpl extends UriParser {
     uriResult.setCustomQueryOptions(otherQueryParameters);
   }
 
+  private EdmLiteral parseLiteral(String value, EdmSimpleType expectedType, EdmFacets facets)

+      throws UriSyntaxException {
+    EdmLiteral literal;
+    try {
+      literal = simpleTypeFacade.parseUriLiteral(value, facets);
+    } catch (EdmLiteralException e) {
+      throw convertEdmLiteralException(e);
+    }
+
+    if (expectedType.isCompatible(literal.getType())) {
+      return literal;
+    } else {
+      throw new UriSyntaxException(UriSyntaxException.INCOMPATIBLELITERAL.addContent(value,
expectedType));
+    }
+  }
+
   private EdmLiteral parseLiteral(final String value, final EdmSimpleType expectedType) throws
UriSyntaxException {
     EdmLiteral literal;
     try {


Mime
View raw message