Java Code Examples for org.apache.olingo.odata2.api.edm.provider.EntityContainer#getEntitySets()

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.EntityContainer#getEntitySets() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void schemaBasic() throws Exception {
  assertNotNull(aep);

  List<Schema> schemas = aep.getSchemas();
  assertEquals(1, schemas.size());

  Schema schema = schemas.get(0);
  List<EntityContainer> containers = schema.getEntityContainers();
  assertEquals(1, containers.size());
  EntityContainer container = containers.get(0);
  assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
  final List<EntitySet> entitySets = container.getEntitySets();
  assertEquals(6, entitySets.size());

  List<Association> associations = schema.getAssociations();
  assertEquals(5, associations.size());
  for (Association association : associations) {
    assertNotNull(association.getName());
    validateAssociation(association);
  }
}
 
Example 2
Source File: EdmEntityContainerImplProv.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<EdmEntitySet> getEntitySets() throws EdmException {
  try {
    List<EdmEntitySet> edmEntitySetsList = new ArrayList<EdmEntitySet>();
    List<EntityContainer> entityContainerHierachyList = getEntityContainerHierachy();
    for (EntityContainer entityContainer : entityContainerHierachyList) {
      List<EntitySet> entitySets = entityContainer.getEntitySets();
      for (EntitySet entitySet : entitySets) {
        EdmEntitySet ees = createEntitySet(entitySet);
        edmEntitySetsList.add(ees);
      }
    }
    return edmEntitySetsList;
  } catch (ODataException e) {
    throw new EdmException(EdmException.PROVIDERPROBLEM, e);
  }
}
 
Example 3
Source File: EdmImplProv.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
protected List<EdmEntitySet> createEntitySets() throws ODataException {
  List<EdmEntitySet> edmEntitySets = new ArrayList<EdmEntitySet>();
  if (schemas == null) {
    schemas = edmProvider.getSchemas();
  }
  for (Schema schema : schemas) {
    for (EntityContainer entityContainer : schema.getEntityContainers()) {
      for (EntitySet entitySet : entityContainer.getEntitySets()) {
        EdmEntityContainer edmEntityContainer = createEntityContainer(entityContainer.getName());
        edmEntitySets.add(new EdmEntitySetImplProv(this, entitySet, edmEntityContainer));
      }
    }
  }
  return edmEntitySets;
}
 
Example 4
Source File: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
  EntityContainer container = name2Container.get(entityContainer);
  if (container != null) {
    List<EntitySet> entitySets = container.getEntitySets();
    for (EntitySet entitySet : entitySets) {
      if (entitySet.getName().equals(name)) {
        return entitySet;
      }
    }
  }

  return null;
}
 
Example 5
Source File: EdmxProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
  for (Schema schema : dataServices.getSchemas()) {
    for (EntityContainer container : schema.getEntityContainers()) {
      if (container.getName().equals(entityContainer)) {
        for (EntitySet entitySet : container.getEntitySets()) {
          if (entitySet.getName().equals(name)) {
            return entitySet;
          }
        }
      }
    }
  }
  return null;
}
 
Example 6
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntitySet() throws XMLStreamException, EntityProviderException {
  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>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmWithEntityContainer);
  DataServices result = parser.readMetadata(reader, true);
  for (Schema schema : result.getSchemas()) {
    for (EntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());
      for (EntitySet entitySet : container.getEntitySets()) {
        assertEquals("Employees", entitySet.getName());
        assertEquals("Employee", entitySet.getEntityType().getName());
        assertEquals(NAMESPACE, entitySet.getEntityType().getNamespace());
      }
    }
  }
}
 
Example 7
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntityTypeInOtherSchema() throws XMLStreamException, EntityProviderException {
  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\"/>" + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Photos\" EntityType=\"" + NAMESPACE2 + ".Photo\"/>" + "</EntityContainer>"
          + "</Schema>" + "<Schema Namespace=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
          + "<EntityType Name= \"Photo\">" + "<Key><PropertyRef Name=\"Id\"/></Key>"
          + "<Property Name=\"Id\" Type=\"Edm.Int32\" Nullable=\"false\"/>" + "</EntityType>" + "</Schema>"
          + "</edmx:DataServices>"
          + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmWithEntityContainer);
  DataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (Schema schema : result.getSchemas()) {
    for (EntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      for (EntitySet entitySet : container.getEntitySets()) {
        assertEquals(NAMESPACE2, entitySet.getEntityType().getNamespace());
        assertEquals("Photo", entitySet.getEntityType().getName());
      }
    }
  }
}