From 405fb760886c5c21166981e0469082b191e98fec Mon Sep 17 00:00:00 2001 From: ramya vasanth Date: Thu, 27 Jun 2019 14:26:41 +0530 Subject: [PATCH] [OLINGO-1375]OData V4: EntitySet in function Import need not be prefixed with namespace --- .../core/edm/EdmEntityContainerImpl.java | 3 +- .../xml/MetadataDocumentXmlSerializer.java | 9 ++++- .../MetadataDocumentXmlSerializerTest.java | 40 ++++++++++++++----- .../xml/ServiceDocumentXmlSerializerTest.java | 3 ++ 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityContainerImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityContainerImpl.java index 86733ee7a..0bf3d91bc 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityContainerImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityContainerImpl.java @@ -267,7 +267,8 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit try { if (null != provider.getAliasInfos()) { for (CsdlAliasInfo aliasInfo : provider.getAliasInfos()) { - if (aliasInfo.getNamespace().equalsIgnoreCase(namespace)) { + if (null != aliasInfo.getNamespace() && + aliasInfo.getNamespace().equalsIgnoreCase(namespace)) { return aliasInfo.getAlias(); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java index e2930008e..cde9cf7c7 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java @@ -583,7 +583,14 @@ public class MetadataDocumentXmlSerializer { EdmEntitySet returnedEntitySet = functionImport.getReturnedEntitySet(); if (returnedEntitySet != null) { - writer.writeAttribute(XML_ENTITY_SET, containerNamespace + "." + returnedEntitySet.getName()); + String returnedEntitySetNamespace = returnedEntitySet.getEntityContainer().getNamespace(); + if ((null != returnedEntitySetNamespace && returnedEntitySetNamespace.equals(containerNamespace)) || ( + namespaceToAlias.get(returnedEntitySetNamespace) != null && + namespaceToAlias.get(returnedEntitySetNamespace).equals(containerNamespace))) { + writer.writeAttribute(XML_ENTITY_SET, returnedEntitySet.getName()); + } else { + writer.writeAttribute(XML_ENTITY_SET, containerNamespace + "." + returnedEntitySet.getName()); + } } // Default is false and we do not write the default if (functionImport.isIncludeInServiceDocument()) { diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java index 97106772f..e5a07d63f 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java @@ -316,6 +316,8 @@ public class MetadataDocumentXmlSerializerTest { assertTrue(metadata.contains("")); + assertTrue(metadata.contains("")); } @Test @@ -356,30 +358,30 @@ public class MetadataDocumentXmlSerializerTest { // All dynamic expressions // Logical expressions assertTrue(metadata.contains("truefalse" - + "")); + + "")); assertTrue(metadata.contains("truefalse" - + "")); + + "")); assertTrue(metadata.contains("true")); // Comparison expressions assertTrue(metadata.contains("truefalse" - + "")); + + "")); assertTrue(metadata.contains("truefalse" - + "")); + + "")); assertTrue(metadata.contains("truefalse" - + "")); + + "")); assertTrue(metadata.contains("truefalse" - + "")); + + "")); assertTrue(metadata.contains("truefalse" - + "")); + + "")); assertTrue(metadata.contains("truefalse" - + "")); + + "")); // Other assertTrue(metadata.contains("AnnoPathValue")); assertTrue(metadata .contains("true" - + "")); + + "")); assertTrue(metadata .contains("" + "value")); @@ -403,7 +405,7 @@ public class MetadataDocumentXmlSerializerTest { + "" + "")); assertTrue(metadata.contains("URLRefValue" - + "")); + + "")); } @@ -491,6 +493,7 @@ public class MetadataDocumentXmlSerializerTest { private final FullQualifiedName nameCTTwoPrim = new FullQualifiedName(nameSpace, "CTTwoPrim"); private final FullQualifiedName nameCTTwoPrimBase = new FullQualifiedName(nameSpace, "CTTwoPrimBase"); private final FullQualifiedName nameUFNRTInt16 = new FullQualifiedName(nameSpace, "UFNRTInt16"); + private final FullQualifiedName nameUFNRTETAllPrim = new FullQualifiedName(nameSpace, "UFNRTETAllPrim"); private final FullQualifiedName nameContainer = new FullQualifiedName(nameSpace, "container"); private final FullQualifiedName nameENString = new FullQualifiedName(nameSpace, "ENString"); @@ -567,6 +570,12 @@ public class MetadataDocumentXmlSerializerTest { .setName("UFNRTInt16") .setParameters(Collections. emptyList()) .setReturnType(new CsdlReturnType().setType(nameInt16))); + } else if (functionName.equals(nameUFNRTETAllPrim)) { + return Collections.singletonList( + new CsdlFunction() + .setName("UFNRTETAllPrim") + .setParameters(Collections. emptyList()) + .setReturnType(new CsdlReturnType().setType(nameETAbstractBase))); } return null; } @@ -616,6 +625,12 @@ public class MetadataDocumentXmlSerializerTest { .setName("FINRTInt16") .setFunction(nameUFNRTInt16) .setIncludeInServiceDocument(true); + } else if (functionImportName.equals("FINRTET")) { + return new CsdlFunctionImport() + .setName("FINRTET") + .setFunction(nameUFNRTETAllPrim) + .setEntitySet("ESAllPrim") + .setIncludeInServiceDocument(true); } } return null; @@ -649,6 +664,8 @@ public class MetadataDocumentXmlSerializerTest { // Functions schema.setFunctions(getFunctions(nameUFNRTInt16)); + + schema.setFunctions(getFunctions(nameUFNRTETAllPrim)); // EntityContainer schema.setEntityContainer(getEntityContainer()); @@ -692,7 +709,8 @@ public class MetadataDocumentXmlSerializerTest { container.setActionImports(Collections.singletonList(getActionImport(nameContainer, "AIRTPrimParam"))); // FunctionImports - container.setFunctionImports(Collections.singletonList(getFunctionImport(nameContainer, "FINRTInt16"))); + container.setFunctionImports(Arrays.asList(getFunctionImport(nameContainer, "FINRTInt16"), + getFunctionImport(nameContainer, "FINRTET"))); return container; } diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java index dae3011aa..4824732d5 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java @@ -93,6 +93,9 @@ public class ServiceDocumentXmlSerializerTest { + "" + "FINRTInt16" + "" + + "" + + "FINRTET" + + "" + "" + "SI" + ""