From 2b96e6e2a18f406479d993e476ba9443239e6c20 Mon Sep 17 00:00:00 2001 From: ramya vasanth Date: Tue, 18 Aug 2020 13:07:09 +0530 Subject: [PATCH] [OLINGO-1472]Support Scale having values variable and floating --- .../core/edm/xml/ClientCsdlProperty.java | 1 + .../olingo/client/core/MetadataTest.java | 19 +++++++++++++++- .../apache/olingo/client/core/$metadata.xml | 2 ++ .../olingo/commons/api/edm/EdmProperty.java | 5 +++++ .../api/edm/provider/CsdlProperty.java | 22 +++++++++++++++++++ .../commons/core/edm/EdmPropertyImpl.java | 5 +++++ .../edm/provider/EdmPropertyImplTest.java | 3 +++ .../queryoption/apply/DynamicProperty.java | 11 ++++++++++ 8 files changed, 67 insertions(+), 1 deletion(-) diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ClientCsdlProperty.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ClientCsdlProperty.java index 4ac0c9a1d..807395dec 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ClientCsdlProperty.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ClientCsdlProperty.java @@ -71,6 +71,7 @@ class ClientCsdlProperty extends CsdlProperty implements Serializable { final String scale = jp.nextTextValue(); property.setScale("variable".equalsIgnoreCase(scale) || "floating".equalsIgnoreCase(scale) ? 0 : Integer.valueOf(scale)); + property.setScaleAsString(scale); } else if ("Unicode".equals(jp.getCurrentName())) { property.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("SRID".equals(jp.getCurrentName())) { diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java index 76872c11a..72dcf4f40 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java @@ -585,7 +585,24 @@ public class MetadataTest extends AbstractTest { assertEquals("UI.HeaderInfo", property.getAnnotations().get(0).getTerm(). getFullQualifiedName().getFullQualifiedNameAsString()); } - + + @Test + public void readVariableFloatingDecimalProperty() { + final Edm edm = fetchEdm(); + assertNotNull(edm); + EdmEntityType entity = edm.getEntityTypeWithAnnotations( + new FullQualifiedName("SEPMRA_SO_MAN2", "I_DraftAdministrativeDataType")); + EdmProperty VariableDecimalType = (EdmProperty) entity.getProperty("VariableDecimalType"); + assertEquals("variable", VariableDecimalType.getScaleAsString()); + assertEquals(Integer.valueOf(0), VariableDecimalType.getScale()); + assertNull(VariableDecimalType.getPrecision()); + + EdmProperty FloatingDecimalType = (EdmProperty) entity.getProperty("FloatingDecimalType"); + assertEquals("floating", FloatingDecimalType.getScaleAsString()); + assertEquals(Integer.valueOf(0), FloatingDecimalType.getScale()); + assertEquals(Integer.valueOf(7), FloatingDecimalType.getPrecision()); + } + @Test public void readAnnotationOnActionImport() { final Edm edm = fetchEdm(); diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/$metadata.xml b/lib/client-core/src/test/resources/org/apache/olingo/client/core/$metadata.xml index 152366962..85a33826b 100644 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/$metadata.xml +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/$metadata.xml @@ -71,6 +71,8 @@ + + diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmProperty.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmProperty.java index 6d4baec1c..71cce4db1 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmProperty.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmProperty.java @@ -61,6 +61,11 @@ public interface EdmProperty extends EdmElement, EdmMappable, EdmAnnotatable { */ Integer getScale(); + /** + * @return the scale as an String or null if not specified + */ + String getScaleAsString(); + /** * @return a non-negative integer or the special value variable */ diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlProperty.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlProperty.java index 387841708..593d4eebb 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlProperty.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlProperty.java @@ -50,6 +50,8 @@ public class CsdlProperty extends CsdlAbstractEdmItem implements CsdlNamed, Csdl private Integer scale; + private String scaleAsString; + private boolean unicode = true; private SRID srid; @@ -232,6 +234,26 @@ public class CsdlProperty extends CsdlAbstractEdmItem implements CsdlNamed, Csdl return this; } + /** + * Gets scaleAsString. + * + * @return the scaleAsString + */ + public String getScaleAsString() { + return scaleAsString; + } + + /** + * Sets scaleAsString. + * + * @param scaleAsString the scaleAsString + * @return the scaleAsString + */ + public CsdlProperty setScaleAsString(final String scaleAsString) { + this.scaleAsString = scaleAsString; + return this; + } + /** * Is unicode. * diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmPropertyImpl.java index b74292a03..62fc64560 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmPropertyImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmPropertyImpl.java @@ -119,6 +119,11 @@ public class EdmPropertyImpl extends AbstractEdmNamed implements EdmProperty { return property.getScale(); } + @Override + public String getScaleAsString() { + return property.getScaleAsString(); + } + @Override public SRID getSrid() { return property.getSrid(); diff --git a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmPropertyImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmPropertyImplTest.java index ef45af5b1..3f09524d2 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmPropertyImplTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmPropertyImplTest.java @@ -57,6 +57,7 @@ public class EdmPropertyImplTest { assertNull(property.getMaxLength()); assertNull(property.getPrecision()); assertNull(property.getScale()); + assertNull(property.getScaleAsString()); assertNull(property.getSrid()); assertNotNull(property.getAnnotations()); assertTrue(property.getAnnotations().isEmpty()); @@ -172,6 +173,7 @@ public class EdmPropertyImplTest { propertyProvider.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); propertyProvider.setPrecision(42); propertyProvider.setScale(12); + propertyProvider.setScaleAsString("12"); propertyProvider.setMaxLength(128); propertyProvider.setUnicode(true); propertyProvider.setNullable(false); @@ -182,6 +184,7 @@ public class EdmPropertyImplTest { assertNull(property.getMimeType()); assertEquals(Integer.valueOf(42), property.getPrecision()); assertEquals(Integer.valueOf(12), property.getScale()); + assertEquals("12", property.getScaleAsString()); assertEquals(Integer.valueOf(128), property.getMaxLength()); assertTrue(property.isUnicode()); assertFalse(property.isNullable()); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/apply/DynamicProperty.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/apply/DynamicProperty.java index 7cfde33be..654bb04ab 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/apply/DynamicProperty.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/apply/DynamicProperty.java @@ -36,6 +36,7 @@ public class DynamicProperty implements EdmProperty { private final EdmType propertyType; private Integer precision; private Integer scale; + private String scaleAsString; /** Creates a dynamic property with a mandatory name and an optional type. */ public DynamicProperty(final String name, final EdmType type) { @@ -88,6 +89,11 @@ public class DynamicProperty implements EdmProperty { return scale; } + @Override + public String getScaleAsString() { + return scaleAsString; + } + @Override public SRID getSrid() { return null; @@ -132,4 +138,9 @@ public class DynamicProperty implements EdmProperty { this.scale = scale; return this; } + + public DynamicProperty setScaleAsString(String scaleAsString) { + this.scaleAsString = scaleAsString; + return this; + } }