[OLINGO-1472]Support Scale having values variable and floating

This commit is contained in:
ramya vasanth 2020-08-18 13:07:09 +05:30
parent 7e1aa94d4e
commit 2b96e6e2a1
8 changed files with 67 additions and 1 deletions

View File

@ -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())) {

View File

@ -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();

View File

@ -71,6 +71,8 @@
<Property Name="DraftIsCreatedByMe" Type="Edm.Boolean"/>
<Property Name="DraftIsLastChangedByMe" Type="Edm.Boolean"/>
<Property Name="DraftIsProcessedByMe" Type="Edm.Boolean"/>
<Property Name="VariableDecimalType" Type="Edm.Decimal" Scale="variable"/>
<Property Name="FloatingDecimalType" Type="Edm.Decimal" Precision="7" Scale="floating"/>
<Property Name="CreatedByUserDescription" Type="Edm.String" MaxLength="80"/>
<Property Name="LastChangedByUserDescription" Type="Edm.String" MaxLength="80"/>
<Property Name="InProcessByUserDescription" Type="Edm.String" MaxLength="80"/>

View File

@ -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 <tt>variable</tt>
*/

View File

@ -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.
*

View File

@ -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();

View File

@ -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());

View File

@ -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;
}
}