[Olingo-1259]Function Import enhancements
authorArchana Rai <archana.rai@sap.com>
Mon, 16 Jul 2018 05:31:09 +0000 (11:01 +0530)
committerArchana Rai <archana.rai@sap.com>
Mon, 16 Jul 2018 05:31:09 +0000 (11:01 +0530)
odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmEntityContainer.java
odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/edm/Impl/EdmEntityContainerImpl.java
odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializer.java
odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializerTest.java
odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmEntityContainerImplProv.java
odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/provider/EdmEntityContainerImplProvTest.java

index 39e70e4..945a4bc 100644 (file)
@@ -33,6 +33,12 @@ public interface EdmEntityContainer extends EdmNamed, EdmAnnotatable {
    * @return <b>boolean</b> true if this is the default container
    */
   boolean isDefaultEntityContainer();
+  
+  /**
+   * @return <b>String</b> namepspace of the container
+   * @throws EdmException
+   */
+  String getNamespace() throws EdmException;
 
   /**
    * Get contained EntitySet by name
index 1511a21..51ee01b 100644 (file)
@@ -52,6 +52,7 @@ public class EdmEntityContainerImpl implements EdmEntityContainer, EdmAnnotatabl
   private EdmDocumentation documentation;
   private String name;
   private String extendz;
+  private String namespace;
 
   public Map<String, EdmAssociationSet> getEdmAssociationSetMap() {
     return edmAssociationSetMap;
@@ -73,6 +74,10 @@ public class EdmEntityContainerImpl implements EdmEntityContainer, EdmAnnotatabl
     this.edm = edm;
   }
 
+  public void setNamespace(String namespace) throws EdmException {
+    this.namespace = namespace;
+  }
+  
   public ClientEdm getEdm() {
     return edm;
   }
@@ -218,4 +223,9 @@ public class EdmEntityContainerImpl implements EdmEntityContainer, EdmAnnotatabl
   public String toString() {
       return String.format(name);
   }
+  
+  @Override
+  public String getNamespace() throws EdmException {
+    return namespace;
+  }
 }
index f2d85b2..956fa83 100644 (file)
@@ -503,6 +503,7 @@ public class XmlMetadataDeserializer {
     if (edmAssociationSets != null && !edmAssociationSets.isEmpty()) {
       setConatinerInAssociationSet(edmAssociationSets, container);
     }
+    container.setNamespace(currentNamespace);
     container.setEdmEntitySets(edmEntitySets).setEdmAssociationSets(edmAssociationSets).setEdmFunctionImports(
         edmFunctionImports);
 
index daf7a5c..c900c23 100644 (file)
@@ -963,7 +963,33 @@ public class XmlMetadataDeserializerTest extends AbstractXmlDeserializerTest {
       }
     }
   }
-
+  
+  @Test
+  public void testEntityContainer() throws XMLStreamException, 
+  EntityProviderException, EdmException, UnsupportedEncodingException {
+    final String xmWithEntityContainer =
+        "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">"
+            + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">"
+            + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
+            + "<EntityType Name= \"Employee\" m:HasStream=\"true\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
+            + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
+            + "<Property Name=\"" + propertyNames[1] + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
+            + "</EntityType>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
+            + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>" + "</EntityContainer>"
+            + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
+    XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
+    InputStream reader = createStreamReader(xmWithEntityContainer);
+    EdmDataServices result = parser.readMetadata(reader, true);
+    assertEquals("Container1", result.getEdm().getEntityContainer("Container1").getName());
+    for (EdmSchema schema : result.getEdm().getSchemas()) {
+      for (EdmEntityContainer container : schema.getEntityContainers()) {
+        assertEquals("Container1", container.getName());
+        assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());
+        assertEquals(NAMESPACE, container.getNamespace());
+      }
+    }
+  }
+  
   @Test
   public void testAssociationSet() throws XMLStreamException, 
   EntityProviderException, EdmException, UnsupportedEncodingException {
index 5096fce..fad7994 100644 (file)
@@ -55,7 +55,8 @@ public class EdmEntityContainerImplProv implements EdmEntityContainer, EdmAnnota
   private EdmEntityContainer edmExtendedEntityContainer;
   private boolean isDefaultContainer;
   private EdmAnnotations annotations;
-
+  private String namespace;
+  
   public EdmEntityContainerImplProv(final EdmImplProv edm, final EntityContainerInfo entityContainerInfo)
       throws EdmException {
     this.edm = edm;
@@ -274,4 +275,30 @@ public class EdmEntityContainerImplProv implements EdmEntityContainer, EdmAnnota
     }
     return entityContainerHierachy;
   }
+  
+
+  @Override
+  public String getNamespace()  throws EdmException{
+    try {
+      if (namespace == null) {
+        List<Schema> schemas;
+        schemas = edm.edmProvider.getSchemas();
+        for (Schema schema : schemas) {
+          List<EntityContainer> containers = schema.getEntityContainers();
+          for (EntityContainer container : containers) {
+            if (container.getName().equals(entityContainerInfo.getName())) {
+              this.namespace = schema.getNamespace();
+              break;
+            }
+          }
+          if (namespace != null) {
+            break;
+          }
+        }
+      }
+    } catch (ODataException e) {
+      throw new EdmException(EdmException.PROVIDERPROBLEM, e);
+    }
+    return namespace;
+  }
 }
index ca58152..b799465 100644 (file)
@@ -77,6 +77,7 @@ public class EdmEntityContainerImplProvTest extends BaseTest {
     entityContainers.add(entityContainer);
     entityContainers.add(parentEntityContainer);
     when(mockedSchema.getEntityContainers()).thenReturn(entityContainers);
+    when(mockedSchema.getNamespace()).thenReturn("Namespace");
     schemas.add(mockedSchema);
     when(edmProvider.getSchemas()).thenReturn(schemas);
 
@@ -128,6 +129,11 @@ public class EdmEntityContainerImplProvTest extends BaseTest {
   }
 
   @Test
+  public void testEntityContainerNamespace() throws EdmException {
+    assertEquals("Namespace", edmEntityContainer.getNamespace());
+  }
+
+  @Test
   public void testEntityContainerInheritance() throws EdmException {
     assertEquals("fooFromParent", edmEntityContainer.getEntitySet("fooFromParent").getName());