org.apache.olingo.odata2.api.edm.provider.Schema Java Examples

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.Schema. 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: EdmServiceMetadataImplProv.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<EdmEntitySetInfo> getEntitySetInfos() throws ODataException {
  if(edmProvider == null){
    throw new ODataException(EDM_PROVIDER_EXEPTION);
 }
  if (entitySetInfos == null) {
    entitySetInfos = new ArrayList<EdmEntitySetInfo>();

    if (schemas == null) {
      schemas = edmProvider.getSchemas();
    }

    for (Schema schema : schemas) {
      for (EntityContainer entityContainer : listOrEmptyList(schema.getEntityContainers())) {
        for (EntitySet entitySet : listOrEmptyList(entityContainer.getEntitySets())) {
          EdmEntitySetInfo entitySetInfo = new EdmEntitySetInfoImplProv(entitySet, entityContainer);
          entitySetInfos.add(entitySetInfo);
        }
      }
    }

  }

  return entitySetInfos;
}
 
Example #2
Source File: EdmServiceMetadataImplProvTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void twoEntitySetsOneContainerForInfo() throws Exception {
  List<EntitySet> entitySets = new ArrayList<EntitySet>();
  EntitySet entitySet = new EntitySet().setName("Employees");
  entitySets.add(entitySet);
  entitySets.add(entitySet);

  List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
  EntityContainer container =
      new EntityContainer().setDefaultEntityContainer(true).setName("Container").setEntitySets(entitySets);
  entityContainers.add(container);

  List<Schema> schemas = new ArrayList<Schema>();
  schemas.add(new Schema().setEntityContainers(entityContainers));

  EdmProvider edmProvider = mock(EdmProvider.class);
  when(edmProvider.getSchemas()).thenReturn(schemas);

  EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider);

  List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos();
  assertNotNull(infos);
  assertEquals(2, infos.size());
}
 
Example #3
Source File: BasicProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void writeMetadata() throws Exception {
  Map<String, String> predefinedNamespaces = new HashMap<String, String>();
  predefinedNamespaces.put("annoPrefix", "http://annoNamespace");
  predefinedNamespaces.put("foo", "http://foo");
  predefinedNamespaces.put("annoPrefix2", "http://annoNamespace");
  predefinedNamespaces.put("annoPrefix", "http://annoNamespace");

  List<Schema> schemas = null;
  ODataResponse response = provider.writeMetadata(schemas, predefinedNamespaces);
  assertNotNull(response);
  assertNotNull(response.getEntity());
  assertNull("BasicProvider should not set content header", response.getContentHeader());
  String metadata = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertTrue(metadata.contains("xmlns:foo=\"http://foo\""));
  assertTrue(metadata.contains("xmlns:annoPrefix=\"http://annoNamespace\""));
  assertTrue(metadata.contains("xmlns:annoPrefix2=\"http://annoNamespace\""));
}
 
Example #4
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void loadAnnotatedClassesFromPackage() throws Exception {
  AnnotationEdmProvider localAep = new AnnotationEdmProvider(TEST_MODEL_PACKAGE);

  // validate employee
  EntityType employee = localAep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
  assertEquals("Employee", employee.getName());
  final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
  assertEquals(1, employeeKeys.size());
  assertEquals("EmployeeId", employeeKeys.get(0).getName());
  assertEquals(6, employee.getProperties().size());
  assertEquals(3, employee.getNavigationProperties().size());

  List<Schema> schemas = localAep.getSchemas();
  assertEquals(1, schemas.size());
  EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
  assertTrue(info.isDefaultEntityContainer());
}
 
Example #5
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testAssociationSet() throws XMLStreamException, EntityProviderException {
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmlWithAssociation);
  DataServices result = parser.readMetadata(reader, true);
  for (Schema schema : result.getSchemas()) {
    for (EntityContainer container : schema.getEntityContainers()) {
      assertEquals(NAMESPACE2, schema.getNamespace());
      assertEquals("Container1", container.getName());
      assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());
      for (AssociationSet assocSet : container.getAssociationSets()) {
        assertEquals(ASSOCIATION, assocSet.getName());
        assertEquals(ASSOCIATION, assocSet.getAssociation().getName());
        assertEquals(NAMESPACE, assocSet.getAssociation().getNamespace());
        AssociationSetEnd end;
        if ("Employees".equals(assocSet.getEnd1().getEntitySet())) {
          end = assocSet.getEnd1();
        } else {
          end = assocSet.getEnd2();
        }
        assertEquals("r_Employees", end.getRole());
      }
    }
  }
}
 
Example #6
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test()
public void testAlias() throws XMLStreamException, EntityProviderException {
  final String xml =
      "<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 + "\" Alias=\"RS\"  xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
          + "<EntityType Name= \"Employee\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RS.Employee\" m:HasStream=\"true\">" + "</EntityType>"
          + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xml);
  DataServices result = parser.readMetadata(reader, true);
  for (Schema schema : result.getSchemas()) {
    assertEquals("RS", schema.getAlias());
    for (EntityType entityType : schema.getEntityTypes()) {
      if ("Manager".equals(entityType.getName())) {
        assertEquals("Employee", entityType.getBaseType().getName());
        assertEquals("RS", entityType.getBaseType().getNamespace());
      }
    }

  }
}
 
Example #7
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 #8
Source File: EdmServiceMetadataImplProvTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void oneEntitySetsOneContainerTwoSchemadForInfo() throws Exception {
  List<EntitySet> entitySets = new ArrayList<EntitySet>();
  EntitySet entitySet = new EntitySet().setName("Employees");
  entitySets.add(entitySet);

  List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
  EntityContainer container =
      new EntityContainer().setDefaultEntityContainer(true).setName("Container").setEntitySets(entitySets);
  entityContainers.add(container);

  List<Schema> schemas = new ArrayList<Schema>();
  schemas.add(new Schema().setEntityContainers(entityContainers));
  schemas.add(new Schema().setEntityContainers(entityContainers));

  EdmProvider edmProvider = mock(EdmProvider.class);
  when(edmProvider.getSchemas()).thenReturn(schemas);

  EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider);

  List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos();
  assertNotNull(infos);
  assertEquals(2, infos.size());
}
 
Example #9
Source File: ODataJPAEdmProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
  if (edmFQName != null) {
    if (associations.containsKey(edmFQName.toString())) {
      return associations.get(edmFQName.toString());
    } else if (schemas == null) {
      getSchemas();
    }

    for (Schema schema : schemas) {
      if (schema.getNamespace().equals(edmFQName.getNamespace())) {
        if (schema.getAssociations() == null) {
          return null;
        }
        for (Association association : schema.getAssociations()) {
          if (association.getName().equals(edmFQName.getName())) {
            associations.put(edmFQName.toString(), association);
            return association;
          }
        }
      }
    }

  }
  return null;
}
 
Example #10
Source File: AtomServiceDocumentProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void writeServiceDocumentWithOneEnitySetTwoContainersOneSchema() throws Exception {
  List<EntitySet> entitySets = new ArrayList<EntitySet>();
  entitySets.add(new EntitySet().setName("Employees"));

  List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
  entityContainers.add(new EntityContainer().setDefaultEntityContainer(true).setName("Container").setEntitySets(
      entitySets));
  entityContainers.add(new EntityContainer().setDefaultEntityContainer(false).setName("Container2").setEntitySets(
      entitySets));

  schemas.add(new Schema().setEntityContainers(entityContainers));

  ODataResponse response = new AtomEntityProvider().writeServiceDocument(edm, "http://localhost");
  String xmlString = verifyResponse(response);
  assertXpathExists("/a:service/a:workspace/a:collection[@href='Employees']", xmlString);
  assertXpathExists("/a:service/a:workspace/a:collection[@href='Employees']/atom:title", xmlString);
  assertXpathEvaluatesTo("Employees", "/a:service/a:workspace/a:collection[@href='Employees']/atom:title", xmlString);

  assertXpathExists("/a:service/a:workspace/a:collection[@href='Employees']", xmlString);
  assertXpathExists("/a:service/a:workspace/a:collection[@href='Employees']/atom:title", xmlString);
  assertXpathEvaluatesTo("Employees", "/a:service/a:workspace/a:collection[@href='Container2.Employees']/atom:title",
      xmlString);
}
 
Example #11
Source File: JPAEdmExtension.java    From odata-boilerplate with MIT License 6 votes vote down vote up
@Override
public void extendJPAEdmSchema(JPAEdmSchemaView view) {
	ResourceBundle i18n = ODataContextUtil.getResourceBundle("i18n");
	final Schema edmSchema = view.getEdmSchema();
	
	for (EntityType entityType : edmSchema.getEntityTypes()) {
		for (Property property : entityType.getProperties()) {
			String label = null;
			if (i18n != null) { try { label = i18n.getString(entityType.getName() + "." + property.getName()); } catch (Exception e) {} }
			List<AnnotationAttribute> annotationAttributeList = new ArrayList<AnnotationAttribute>();
			if (label != null) {
				annotationAttributeList.add(new AnnotationAttribute()
						.setNamespace(SAP_NAMESPACE)
						.setPrefix(SAP_PREFIX)
						.setName(LABEL).setText(label));
			}
			annotationAttributeList.addAll(getSapPropertyAnnotations(entityType, property));
			property.setAnnotationAttributes(annotationAttributeList); 
		}
	}
	
	addSmartAnnotations(edmSchema);
}
 
Example #12
Source File: EdmxProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association,
    final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
  for (Schema schema : dataServices.getSchemas()) {
    for (EntityContainer container : schema.getEntityContainers()) {
      if (container.getName().equals(entityContainer)) {
        for (AssociationSet associationSet : container.getAssociationSets()) {
          if (associationSet.getAssociation().equals(association)
              && ((associationSet.getEnd1().getEntitySet().equals(sourceEntitySetName) && associationSet.getEnd1()
                  .getRole().equals(sourceEntitySetRole))
              || (associationSet.getEnd2().getEntitySet().equals(sourceEntitySetName) && associationSet.getEnd2()
                  .getRole().equals(sourceEntitySetRole)))) {
            return associationSet;
          }
        }
      }
    }
  }
  return null;
}
 
Example #13
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 #14
Source File: EdmImplProv.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
protected List<EdmFunctionImport> createFunctionImports() throws ODataException {
  List<EdmFunctionImport> edmFunctionImports = new ArrayList<EdmFunctionImport>();
  if (schemas == null) {
    schemas = edmProvider.getSchemas();
  }
  for (Schema schema : schemas) {
    for (EntityContainer entityContainer : schema.getEntityContainers()) {
      for (FunctionImport functionImport : entityContainer.getFunctionImports()) {
        EdmEntityContainer edmEntityContainer = createEntityContainer(entityContainer.getName());
        edmFunctionImports.add(new EdmFunctionImportImplProv(this, functionImport, edmEntityContainer));
      }
    }
  }
  return edmFunctionImports;
}
 
Example #15
Source File: XmlMetadataProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = Exception.class)
public void writeInvalidMetadata() throws Exception {
  disableLogging(this.getClass());
  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  annotationElements.add(new AnnotationElement().setText("hallo"));
  Schema schema = new Schema().setAnnotationElements(annotationElements);
  schema.setNamespace("http://namespace.com");
  schemas.add(schema);

  DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
  OutputStreamWriter writer = null;
  CircleStreamBuffer csb = new CircleStreamBuffer();
  writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
  XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
  XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
}
 
Example #16
Source File: AtomServiceDocumentProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws ODataException {
  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("atom", Edm.NAMESPACE_ATOM_2005);
  prefixMap.put("a", Edm.NAMESPACE_APP_2007);
  prefixMap.put("xml", Edm.NAMESPACE_XML_1998);
  prefixMap.put("custom", "http://localhost");
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));

  schemas = new ArrayList<Schema>();

  EdmProvider edmProvider = mock(EdmProvider.class);
  when(edmProvider.getSchemas()).thenReturn(schemas);

  EdmServiceMetadata edmServiceMetadata = new EdmServiceMetadataImplProv(edmProvider);

  edm = mock(Edm.class);
  when(edm.getServiceMetadata()).thenReturn(edmServiceMetadata);
}
 
Example #17
Source File: AtomServiceDocumentProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void writeServiceDocumentWithOneEnitySetOneContainerOneSchema() throws Exception {
  List<EntitySet> entitySets = new ArrayList<EntitySet>();
  entitySets.add(new EntitySet().setName("Employees"));

  List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
  entityContainers.add(new EntityContainer().setDefaultEntityContainer(true).setName("Container").setEntitySets(
      entitySets));

  schemas.add(new Schema().setEntityContainers(entityContainers));

  ODataResponse response = new AtomEntityProvider().writeServiceDocument(edm, "http://localhost");
  String xmlString = verifyResponse(response);
  assertXpathExists("/a:service/a:workspace/a:collection[@href='Employees']", xmlString);
  assertXpathExists("/a:service/a:workspace/a:collection[@href='Employees']/atom:title", xmlString);
  assertXpathEvaluatesTo("Employees", "/a:service/a:workspace/a:collection[@href='Employees']/atom:title", xmlString);
}
 
Example #18
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBaseType() throws XMLStreamException, EntityProviderException {
  int i = 0;
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmlWithBaseType);
  DataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (Schema schema : result.getSchemas()) {
    assertEquals(NAMESPACE, schema.getNamespace());
    assertEquals(2, schema.getEntityTypes().size());
    assertEquals("Employee", schema.getEntityTypes().get(0).getName());
    for (PropertyRef propertyRef : schema.getEntityTypes().get(0).getKey().getKeys()) {
      assertEquals("EmployeeId", propertyRef.getName());
    }
    for (Property property : schema.getEntityTypes().get(0).getProperties()) {
      assertEquals(propertyNames[i], property.getName());
      i++;
    }

  }
}
 
Example #19
Source File: EdmxProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
  for (Schema schema : dataServices.getSchemas()) {
    if (schema.getNamespace().equals(edmFQName.getNamespace())) {
      for (EntityType entityType : schema.getEntityTypes()) {
        if (entityType.getName().equals(edmFQName.getName())) {
          return entityType;
        }
      }
    }
  }
  return null;
}
 
Example #20
Source File: EdmxProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
  for (Schema schema : dataServices.getSchemas()) {
    if (schema.getNamespace().equals(edmFQName.getNamespace())) {
      for (ComplexType complexType : schema.getComplexTypes()) {
        if (complexType.getName().equals(edmFQName.getName())) {
          return complexType;
        }
      }
    }
  }
  return null;
}
 
Example #21
Source File: EdmServiceMetadataImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void twoContainersWithOneEntitySetEachForInfo() throws Exception {
  String entitySetUriString = new URI("Employees").toASCIIString();
  String entitySetUriString2 = new URI("Container2.Employees").toASCIIString();

  List<EntitySet> entitySets = new ArrayList<EntitySet>();
  EntitySet entitySet = new EntitySet().setName("Employees");
  entitySets.add(entitySet);

  List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
  EntityContainer container =
      new EntityContainer().setDefaultEntityContainer(true).setName("Container").setEntitySets(entitySets);
  entityContainers.add(container);

  EntityContainer container2 =
      new EntityContainer().setDefaultEntityContainer(false).setName("Container2").setEntitySets(entitySets);
  entityContainers.add(container2);

  List<Schema> schemas = new ArrayList<Schema>();
  schemas.add(new Schema().setEntityContainers(entityContainers));

  EdmProvider edmProvider = mock(EdmProvider.class);
  when(edmProvider.getSchemas()).thenReturn(schemas);

  EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider);

  List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos();
  assertNotNull(infos);
  assertEquals(2, infos.size());

  assertEquals(infos.get(0).getEntitySetName(), "Employees");
  assertEquals(infos.get(0).getEntityContainerName(), "Container");
  assertEquals(infos.get(0).getEntitySetUri().toASCIIString(), entitySetUriString);
  assertTrue(infos.get(0).isDefaultEntityContainer());

  assertEquals(infos.get(1).getEntitySetName(), "Employees");
  assertEquals(infos.get(1).getEntityContainerName(), "Container2");
  assertEquals(infos.get(1).getEntitySetUri().toASCIIString(), entitySetUriString2);
  assertFalse(infos.get(1).isDefaultEntityContainer());
}
 
Example #22
Source File: EdmxProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
  for (Schema schema : dataServices.getSchemas()) {
    if (schema.getNamespace().equals(edmFQName.getNamespace())) {
      for (Association association : schema.getAssociations()) {
        if (association.getName().equals(edmFQName.getName())) {
          return association;
        }
      }
    }
  }
  return null;
}
 
Example #23
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 #24
Source File: JPAEdmExtension.java    From lemonaid with MIT License 5 votes vote down vote up
private EntityType getEntityType(Schema edmSchema, FullQualifiedName entityType) {
	for (EntityType e : edmSchema.getEntityTypes()) {
		if (entityType.equals(new FullQualifiedName(edmSchema.getNamespace(), e.getName()))) {
			return e;
		}
	}
	return null;
}
 
Example #25
Source File: EdmxProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
  for (Schema schema : dataServices.getSchemas()) {
    for (EntityContainer container : schema.getEntityContainers()) {
      if (container.getName().equals(entityContainer)) {
        for (FunctionImport function : container.getFunctionImports()) {
          if (function.getName().equals(name)) {
            return function;
          }
        }
      }
    }
  }
  return null;
}
 
Example #26
Source File: EdmxProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public List<AliasInfo> getAliasInfos() {
  List<AliasInfo> aliasInfos = new ArrayList<AliasInfo>();
  for (Schema schema : dataServices.getSchemas()) {
    if (schema.getAlias() != null) {
      aliasInfos.add(new AliasInfo().setAlias(schema.getAlias()).setNamespace(schema.getNamespace()));
    }
  }

  return aliasInfos;
}
 
Example #27
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testOtherEdmNamespace() throws XMLStreamException, EntityProviderException {
  int i = 0;
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xml2);
  DataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (Schema schema : result.getSchemas()) {
    assertEquals(NAMESPACE, schema.getNamespace());
    assertEquals(1, schema.getEntityTypes().size());
    assertEquals("Employee", schema.getEntityTypes().get(0).getName());
    for (PropertyRef propertyRef : schema.getEntityTypes().get(0).getKey().getKeys()) {
      assertEquals("EmployeeId", propertyRef.getName());
    }
    for (Property property : schema.getEntityTypes().get(0).getProperties()) {
      assertEquals(propertyNames[i], property.getName());
      if ("Location".equals(property.getName())) {
        ComplexProperty cProperty = (ComplexProperty) property;
        assertEquals("c_Location", cProperty.getType().getName());
      } else if ("EmployeeName".equals(property.getName())) {
        assertNotNull(property.getCustomizableFeedMappings());
      }
      i++;
    }
    for (AnnotationElement annoElement : schema.getAnnotationElements()) {
      assertEquals("prefix", annoElement.getPrefix());
      assertEquals("namespace", annoElement.getNamespace());
      assertEquals("schemaElement", annoElement.getName());
      assertEquals("text3", annoElement.getText());
    }
  }
}
 
Example #28
Source File: EdmServiceMetadataImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void getEntitySetInfosForEmptyEdmProviderSchemas() throws Exception {
  List<Schema> schemas = new ArrayList<Schema>();

  EdmProvider edmProvider = mock(EdmProvider.class);
  when(edmProvider.getSchemas()).thenReturn(schemas);

  EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider);

  List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos();
  assertNotNull(infos);
  assertTrue(infos.isEmpty());
}
 
Example #29
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws XMLStreamException, EntityProviderException {
  int i = 0;
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xml);
  DataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (Schema schema : result.getSchemas()) {
    assertEquals(NAMESPACE, schema.getNamespace());
    assertEquals(1, schema.getEntityTypes().size());
    assertEquals("Employee", schema.getEntityTypes().get(0).getName());
    assertEquals(Boolean.TRUE, schema.getEntityTypes().get(0).isHasStream());
    for (PropertyRef propertyRef : schema.getEntityTypes().get(0).getKey().getKeys()) {
      assertEquals("EmployeeId", propertyRef.getName());
    }
    for (Property property : schema.getEntityTypes().get(0).getProperties()) {
      assertEquals(propertyNames[i], property.getName());
      if ("Location".equals(property.getName())) {
        ComplexProperty cProperty = (ComplexProperty) property;
        assertEquals(NAMESPACE, cProperty.getType().getNamespace());
        assertEquals("c_Location", cProperty.getType().getName());
      } else if ("EmployeeName".equals(property.getName())) {
        assertNotNull(property.getCustomizableFeedMappings());
        assertEquals("SyndicationTitle", property.getCustomizableFeedMappings().getFcTargetPath());
        assertNull(property.getCustomizableFeedMappings().getFcContentKind());
      }
      i++;
    }
    assertEquals(1, schema.getComplexTypes().size());
    assertEquals("c_Location", schema.getComplexTypes().get(0).getName());
  }
}
 
Example #30
Source File: EdmServiceMetadataImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Check that no NPE can occur with a new created Schema
 *
 * @throws Exception
 */
@Test
public void getEntitySetInfosForNewEdmProviderSchemas() throws Exception {
  List<Schema> schemas = new ArrayList<Schema>();
  schemas.add(new Schema());

  EdmProvider edmProvider = mock(EdmProvider.class);
  when(edmProvider.getSchemas()).thenReturn(schemas);

  EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider);

  List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos();
  assertNotNull(infos);
  assertTrue(infos.isEmpty());
}