[OLINGO-1062]Fallback to fetch full qualified name of Record when the vocab file is not loaded

This commit is contained in:
ramya vasanth 2020-03-19 10:02:52 +05:30
parent ac7d8dbd62
commit d4c057b80c
5 changed files with 56 additions and 8 deletions

View File

@ -22,6 +22,7 @@ import java.util.List;
import org.apache.olingo.commons.api.edm.EdmAnnotatable;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
/**
* The edm:Record expression enables a new entity type or complex type instance to be constructed.
@ -40,4 +41,10 @@ public interface EdmRecord extends EdmDynamicExpression, EdmAnnotatable {
* @return Entity type or complex type
*/
EdmStructuredType getType();
/**
*
* @return Fully Qualified Name of the Record
*/
FullQualifiedName getTypeFQN();
}

View File

@ -25,6 +25,7 @@ import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue;
import org.apache.olingo.commons.api.edm.annotation.EdmRecord;
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyValue;
@ -74,4 +75,9 @@ public class EdmRecordImpl extends AbstractEdmAnnotatableDynamicExpression imple
public EdmExpressionType getExpressionType() {
return EdmExpressionType.Record;
}
@Override
public FullQualifiedName getTypeFQN() {
return record.getType() != null ? new FullQualifiedName(record.getType()) : null;
}
}

View File

@ -36,6 +36,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmFunction;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef;
@ -130,6 +131,8 @@ public class MetadataDocumentJsonSerializer {
private static final String ANNOTATION = DOLLAR + "Annotations";
private static final String ANNOTATION_PATH = DOLLAR + "Path";
private static final String NAME = DOLLAR + "Name";
private static final String ON_DELETE = "OnDelete";
private static final String ON_DELETE_PROPERTY = "Action";
public MetadataDocumentJsonSerializer(final ServiceMetadata serviceMetadata) throws SerializerException {
if (serviceMetadata == null || serviceMetadata.getEdm() == null) {
@ -663,6 +666,13 @@ public class MetadataDocumentJsonSerializer {
json.writeEndObject();
}
}
if (navigationProperty.getOnDelete() != null) {
json.writeObjectFieldStart(ON_DELETE);
json.writeStringField(ON_DELETE_PROPERTY, navigationProperty.getOnDelete().getAction());
appendAnnotations(json, navigationProperty.getOnDelete(), null);
json.writeEndObject();
}
appendAnnotations(json, navigationProperty, null);
@ -993,9 +1003,16 @@ public class MetadataDocumentJsonSerializer {
case Record:
EdmRecord asRecord = dynExp.asRecord();
json.writeStartObject();
EdmStructuredType type = asRecord.getType();
if (type != null) {
json.writeStringField(TYPE, getAliasedFullQualifiedName(type));
try {
EdmStructuredType structuredType = asRecord.getType();
if (structuredType != null) {
json.writeStringField(TYPE, getAliasedFullQualifiedName(structuredType));
}
} catch (EdmException e) {
FullQualifiedName type = asRecord.getTypeFQN();
if (type != null) {
json.writeStringField(TYPE, getAliasedFullQualifiedName(type));
}
}
for (EdmPropertyValue propValue : asRecord.getPropertyValues()) {
appendExpression(json, propValue.getValue(), propValue.getProperty());

View File

@ -37,6 +37,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmFunction;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef;
@ -455,10 +456,18 @@ public class MetadataDocumentXmlSerializer {
break;
case Record:
EdmRecord asRecord = dynExp.asRecord();
EdmStructuredType type = asRecord.getType();
if (type != null) {
writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(type, false));
try {
EdmStructuredType structuredType = asRecord.getType();
if (structuredType != null) {
writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(structuredType, false));
}
} catch (EdmException e) {
FullQualifiedName type = asRecord.getTypeFQN();
if (type != null) {
writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(type, false));
}
}
for (EdmPropertyValue propValue : asRecord.getPropertyValues()) {
writer.writeStartElement(XML_PROPERTY_VALUE);
writer.writeAttribute(XML_PROPERTY, propValue.getProperty());

View File

@ -64,6 +64,8 @@ import org.apache.olingo.commons.api.edm.provider.CsdlFunction;
import org.apache.olingo.commons.api.edm.provider.CsdlFunctionImport;
import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
import org.apache.olingo.commons.api.edm.provider.CsdlNavigationPropertyBinding;
import org.apache.olingo.commons.api.edm.provider.CsdlOnDelete;
import org.apache.olingo.commons.api.edm.provider.CsdlOnDeleteAction;
import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef;
@ -379,7 +381,8 @@ public class MetadataDocumentJsonSerializerTest {
+ "},\"Info\":"
+ "{\"$Type\":\"Alias.CTEntityInfo\"},"
+ "\"NavPropertyETOne\":{\"$Kind\":\"NavigationProperty\","
+ "\"$Type\":\"Alias.ETOne\"}}"));
+ "\"$Type\":\"Alias.ETOne\"},\"NavProperty\":{\"$Kind\":\"NavigationProperty\","
+ "\"$Type\":\"Alias.ETAbstract\",\"$Nullable\":false,\"OnDelete\":{\"Action\":\"Cascade\"}}}"));
assertTrue(metadata.contains("\"BAETTwoKeyNavRTETTwoKeyNavParam\":"
+ "[{\"$Kind\":\"Action\",\"$EntitySetPath\":\"BindingParam/NavPropertyETTwoKeyNavOne\","
+ "\"$IsBound\":true,\"$Parameter\":[{\"$Name\":\"BindingParam\",\"$Type\":\"Alias.ETTwoKeyNav\"},"
@ -526,6 +529,12 @@ public class MetadataDocumentJsonSerializerTest {
.setScale(2)
.setDefaultValue("10-2-2017:20:30:40")
.setMaxLength(30);
private final CsdlNavigationProperty navProperty = new CsdlNavigationProperty()
.setName("NavProperty")
.setType(nameETAbstract)
.setNullable(false)
.setOnDelete(new CsdlOnDelete().setAction(CsdlOnDeleteAction.Cascade)
.setAnnotations(Arrays.asList(new CsdlAnnotation().setTerm("core.Term"))));
private final FullQualifiedName nameCTTwoPrim = new FullQualifiedName(nameSpace, "CTTwoPrim");
private final FullQualifiedName nameCTTwoPrimBase = new FullQualifiedName(nameSpace, "CTTwoPrimBase");
@ -596,7 +605,7 @@ public class MetadataDocumentJsonSerializerTest {
.setKey(Arrays.asList(new CsdlPropertyRef().setAlias("EntityInfoID").setName("Info/ID"),
new CsdlPropertyRef().setName("name")))
.setNavigationProperties(Arrays.asList(
new CsdlNavigationProperty().setName("NavPropertyETOne").setType(nameETOne)))
new CsdlNavigationProperty().setName("NavPropertyETOne").setType(nameETOne), navProperty))
.setProperties(Arrays.asList(nameProperty, infoProperty));
} else if (entityTypeName.equals(nameETTwoKeyNav)) {
return new CsdlEntityType()