[OLINGO-612] Changed 'is*' behavior for Valuable
This commit is contained in:
parent
15cfa375e8
commit
26be7d2e7c
|
@ -1914,15 +1914,7 @@ public abstract class AbstractServices {
|
|||
|
||||
alink.setRel(Constants.get(ConstantKey.ATOM_LINK_REL) + property.getName());
|
||||
|
||||
if (property.isComplex()) {
|
||||
Entity inline = new EntityImpl();
|
||||
inline.setType(navProperties.get(property.getName()).getType());
|
||||
for (Property prop : property.asComplex().getValue()) {
|
||||
inline.getProperties().add(prop);
|
||||
}
|
||||
alink.setInlineEntity(inline);
|
||||
|
||||
} else if (property.isCollection()) {
|
||||
if (property.isCollection()) {
|
||||
EntitySet inline = new EntitySetImpl();
|
||||
for (Object value : property.asCollection()) {
|
||||
Entity inlineEntity = new EntityImpl();
|
||||
|
@ -1933,6 +1925,14 @@ public abstract class AbstractServices {
|
|||
inline.getEntities().add(inlineEntity);
|
||||
}
|
||||
alink.setInlineEntitySet(inline);
|
||||
} else if (property.isComplex()) {
|
||||
Entity inline = new EntityImpl();
|
||||
inline.setType(navProperties.get(property.getName()).getType());
|
||||
for (Property prop : property.asComplex().getValue()) {
|
||||
inline.getProperties().add(prop);
|
||||
}
|
||||
alink.setInlineEntity(inline);
|
||||
|
||||
} else {
|
||||
throw new IllegalStateException("Invalid navigation property " + property);
|
||||
}
|
||||
|
|
|
@ -740,13 +740,22 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
// fixes enum values treated as primitive when no type information is available
|
||||
if (client instanceof EdmEnabledODataClient && type != null) {
|
||||
final EdmEnumType edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getEnumType(type);
|
||||
if (valuable.isPrimitive() && edmType != null) {
|
||||
if (!valuable.isCollection() && valuable.isPrimitive() && edmType != null) {
|
||||
valuable.setValue(ValueType.ENUM, valuable.asPrimitive());
|
||||
}
|
||||
}
|
||||
|
||||
ODataValue value = null;
|
||||
if (valuable.isEnum()) {
|
||||
|
||||
if (valuable.isCollection()) {
|
||||
value = client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
|
||||
|
||||
for (Object _value : valuable.asCollection()) {
|
||||
final Property fake = new PropertyImpl();
|
||||
fake.setValue(valuable.getValueType().getBaseType(), _value);
|
||||
value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
|
||||
}
|
||||
} else if (valuable.isEnum()) {
|
||||
value = client.getObjectFactory().newEnumValue(type == null ? null : type.toString(),
|
||||
valuable.asEnum().toString());
|
||||
} else if (valuable.isComplex()) {
|
||||
|
@ -833,15 +842,6 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
}
|
||||
|
||||
value = cValue;
|
||||
} else if (valuable.isCollection()) {
|
||||
value =
|
||||
client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
|
||||
|
||||
for (Object _value : valuable.asCollection()) {
|
||||
final Property fake = new PropertyImpl();
|
||||
fake.setValue(valuable.getValueType().getBaseType(), _value);
|
||||
value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,26 +30,81 @@ public interface Valuable {
|
|||
|
||||
boolean isNull();
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a PRIMITIVE or COLLECTION_PRIMITIVE ValueType
|
||||
*
|
||||
* @return true if ValueType is a PRIMITIVE or COLLECTION_PRIMITIVE, otherwise false
|
||||
*/
|
||||
boolean isPrimitive();
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a GEOSPATIAL or COLLECTION_GEOSPATIAL ValueType
|
||||
*
|
||||
* @return true if ValueType is a GEOSPATIAL or COLLECTION_GEOSPATIAL, otherwise false
|
||||
*/
|
||||
boolean isGeospatial();
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a ENUM or COLLECTION_ENUM ValueType
|
||||
*
|
||||
* @return true if ValueType is a ENUM or COLLECTION_ENUM, otherwise false
|
||||
*/
|
||||
boolean isEnum();
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a COMPLEX or COLLECTION_COMPLEX ValueType
|
||||
*
|
||||
* @return true if ValueType is a COMPLEX or COLLECTION_COMPLEX, otherwise false
|
||||
*/
|
||||
boolean isComplex();
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a COLLECTION_* ValueType
|
||||
*
|
||||
* @return true if ValueType is a COLLECTION_*, otherwise false
|
||||
*/
|
||||
boolean isCollection();
|
||||
|
||||
/**
|
||||
* Get the value
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
Object getValue();
|
||||
|
||||
/**
|
||||
* Get the value in its primitive representation or null if it is not based on a primitive ValueType
|
||||
*
|
||||
* @return primitive representation or null if it is not based on a primitive ValueType
|
||||
*/
|
||||
Object asPrimitive();
|
||||
|
||||
/**
|
||||
* Get the value in its enum representation or null if it is not based on a enum ValueType
|
||||
*
|
||||
* @return enum representation or null if it is not based on a enum ValueType
|
||||
*/
|
||||
Object asEnum();
|
||||
|
||||
/**
|
||||
* Get the value in its geospatial representation or null if it is not based on a geospatial ValueType
|
||||
*
|
||||
* @return geospatial representation or null if it is not based on a geospatial ValueType
|
||||
*/
|
||||
Geospatial asGeospatial();
|
||||
|
||||
/**
|
||||
* Get the value in its complex representation or null if it is not based on a complex ValueType
|
||||
*
|
||||
* @return primitive complex or null if it is not based on a complex ValueType
|
||||
*/
|
||||
ComplexValue asComplex();
|
||||
|
||||
/**
|
||||
* Get the value as collection or null if it is not a collection ValueType
|
||||
*
|
||||
* @return collection or null if it is not a collection ValueType
|
||||
*/
|
||||
List<?> asCollection();
|
||||
|
||||
void setValue(ValueType valuetype, Object value);
|
||||
|
|
|
@ -56,21 +56,33 @@ public abstract class AbstractValuable implements Valuable, Annotatable {
|
|||
|
||||
@Override
|
||||
public boolean isPrimitive() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.PRIMITIVE;
|
||||
}
|
||||
return valueType == ValueType.PRIMITIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeospatial() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.GEOSPATIAL;
|
||||
}
|
||||
return valueType == ValueType.GEOSPATIAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnum() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.ENUM;
|
||||
}
|
||||
return valueType == ValueType.ENUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplex() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.COMPLEX;
|
||||
}
|
||||
return valueType == ValueType.COMPLEX;
|
||||
}
|
||||
|
||||
|
@ -81,21 +93,33 @@ public abstract class AbstractValuable implements Valuable, Annotatable {
|
|||
|
||||
@Override
|
||||
public Object asPrimitive() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isPrimitive() ? value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Geospatial asGeospatial() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isGeospatial() ? (Geospatial) value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asEnum() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isEnum() ? value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComplexValue asComplex() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isComplex() ? (ComplexValue) value : null;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
|
||||
value(writer, property.getValueType(), typeInfo == null ? null : typeInfo.getPrimitiveTypeKind(),
|
||||
property.getValue());
|
||||
if (!property.isNull() && property.isComplex()) {
|
||||
if (!property.isNull() && property.isComplex() && !property.isCollection()) {
|
||||
links(writer, property.asComplex().getAssociationLinks());
|
||||
links(writer, property.asComplex().getNavigationLinks());
|
||||
}
|
||||
|
|
|
@ -67,6 +67,8 @@ public class JsonPropertySerializer extends JsonSerializer {
|
|||
|
||||
if (property.isNull()) {
|
||||
jgen.writeBooleanField(Constants.JSON_NULL, true);
|
||||
} else if (property.isGeospatial() || property.isCollection()) {
|
||||
valuable(jgen, property, Constants.VALUE);
|
||||
} else if (property.isPrimitive()) {
|
||||
final EdmTypeInfo typeInfo = property.getType() == null
|
||||
? null
|
||||
|
@ -76,8 +78,6 @@ public class JsonPropertySerializer extends JsonSerializer {
|
|||
primitiveValue(jgen, typeInfo, property.asPrimitive());
|
||||
} else if (property.isEnum()) {
|
||||
jgen.writeStringField(Constants.VALUE, property.asEnum().toString());
|
||||
} else if (property.isGeospatial() || property.isCollection()) {
|
||||
valuable(jgen, property, Constants.VALUE);
|
||||
} else if (property.isComplex()) {
|
||||
for (Property cproperty : property.asComplex().getValue()) {
|
||||
valuable(jgen, cproperty, cproperty.getName());
|
||||
|
|
|
@ -336,6 +336,8 @@ public class JsonSerializer implements ODataSerializer {
|
|||
|
||||
if (value.isNull()) {
|
||||
jgen.writeNull();
|
||||
} else if (value.isCollection()) {
|
||||
collection(jgen, typeInfo, value.getValueType(), value.asCollection());
|
||||
} else if (value.isPrimitive()) {
|
||||
primitiveValue(jgen, typeInfo, value.asPrimitive());
|
||||
} else if (value.isEnum()) {
|
||||
|
@ -344,8 +346,6 @@ public class JsonSerializer implements ODataSerializer {
|
|||
jgen.writeStartObject();
|
||||
geoSerializer.serialize(jgen, value.asGeospatial());
|
||||
jgen.writeEndObject();
|
||||
} else if (value.isCollection()) {
|
||||
collection(jgen, typeInfo, value.getValueType(), value.asCollection());
|
||||
} else if (value.isComplex()) {
|
||||
complexValue(jgen, typeInfo, value.asComplex().getValue(), value.asComplex());
|
||||
}
|
||||
|
@ -355,10 +355,12 @@ public class JsonSerializer implements ODataSerializer {
|
|||
throws IOException, EdmPrimitiveTypeException {
|
||||
|
||||
if (!Constants.VALUE.equals(name) && !(valuable instanceof Annotation)
|
||||
&& !valuable.isComplex() && !valuable.isComplex()) {
|
||||
&& !(valuable.isComplex() && !valuable.isCollection())) {
|
||||
|
||||
String type = valuable.getType();
|
||||
if (StringUtils.isBlank(type) && valuable.isPrimitive() || valuable.isNull()) {
|
||||
if ((!valuable.isCollection() &&
|
||||
StringUtils.isBlank(type) &&
|
||||
valuable.isPrimitive()) || valuable.isNull()) {
|
||||
type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString();
|
||||
}
|
||||
if (StringUtils.isNotBlank(type) && format != ODataFormat.JSON_NO_METADATA) {
|
||||
|
|
Loading…
Reference in New Issue