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

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.AnnotationElement. 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: EdmAnnotationsImplProvTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Before
public void getEdmEntityContainerImpl() throws Exception {

  List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>();
  AnnotationAttribute attribute =
      new AnnotationAttribute().setName("attributeName").setNamespace("namespace").setPrefix("prefix")
          .setText("Text");
  annotationAttributes.add(attribute);

  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  AnnotationElement element =
      new AnnotationElement().setName("elementName").setNamespace("namespace").setPrefix("prefix").setText("xmlData");
  annotationElements.add(element);

  annotationsProvider = new EdmAnnotationsImplProv(annotationAttributes, annotationElements);

  annotationsProviderWithNullEementAndAttributes = new EdmAnnotationsImplProv(null, null);
}
 
Example #2
Source File: BasicProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void metadataWithReferencesAndPredefinedNamespaces() throws Exception {
  DataServices serviceMetadata = new DataServices();
  serviceMetadata.setCustomEdmxVersion("4.0");
  List<AnnotationElement> annoElements = new ArrayList<AnnotationElement>();
  annoElements.add(createElementWithoutInclude());
  annoElements.add(createElementWithInclude());
  serviceMetadata.setAnnotationElements(annoElements);
  serviceMetadata.setDataServiceVersion("4.0");
  
  Map<String, String> predefinedNamespaces = new HashMap<String, String>();
  predefinedNamespaces.put("edmx", "http://docs.oasis-open.org/odata/ns/edmx");
  predefinedNamespaces.put(null, "http://docs.oasis-open.org/odata/ns/edmx");
  
  ODataResponse response = provider.writeMetadata(serviceMetadata, 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(
      "edmx:Reference xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\" Uri=\"http://someurl.com\""));
  assertTrue(metadata.contains("edmx:Include xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\""));
  assertTrue(metadata.contains("edmx:Edmx xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\" Version=\"4.0\""));
}
 
Example #3
Source File: BasicProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void metadataWithReferences() throws Exception {
  DataServices serviceMetadata = new DataServices();
  List<AnnotationElement> annoElements = new ArrayList<AnnotationElement>();
  annoElements.add(createElementWithoutInclude());
  annoElements.add(createElementWithInclude());
  serviceMetadata.setAnnotationElements(annoElements);
  serviceMetadata.setDataServiceVersion(ODataServiceVersion.V20);
  ODataResponse response = provider.writeMetadata(serviceMetadata, null);
  assertNotNull(response);
  assertNotNull(response.getEntity());
  assertNull("BasicProvider should not set content header", response.getContentHeader());
  String metadata = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertTrue(metadata.contains(
      "edmx:Reference xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\" Uri=\"http://someurl.com\""));
  assertTrue(metadata.contains("edmx:Include xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\""));
}
 
Example #4
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private PropertyRef readPropertyRef(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_PROPERTY_REF);
  PropertyRef propertyRef = new PropertyRef();
  propertyRef.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  propertyRef.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_PROPERTY_REF.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    propertyRef.setAnnotationElements(annotationElements);
  }
  return propertyRef;
}
 
Example #5
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private Key readEntityTypeKey(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ENTITY_TYPE_KEY);
  List<PropertyRef> keys = new ArrayList<PropertyRef>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  List<AnnotationAttribute> annotationAttributes = readAnnotationAttribute(reader);
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ENTITY_TYPE_KEY.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_PROPERTY_REF.equals(currentHandledStartTagName)) {
        reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_PROPERTY_REF);
        keys.add(readPropertyRef(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  Key key = new Key().setKeys(keys).setAnnotationAttributes(annotationAttributes);
  if (!annotationElements.isEmpty()) {
    key.setAnnotationElements(annotationElements);
  }
  return key;
}
 
Example #6
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 #7
Source File: EdmAnnotationElementImplProv.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public List<EdmAnnotationElement> getChildElements() {
  if (childElements == null && element.getChildElements() != null) {
    childElements = new ArrayList<EdmAnnotationElement>();
    for (AnnotationElement childElement : element.getChildElements()) {
      childElements.add(new EdmAnnotationElementImplProv(childElement));
    }
  }
  return childElements;
}
 
Example #8
Source File: EdmAnnotationsImplProv.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public EdmAnnotationsImplProv(final List<AnnotationAttribute> annotationAttributes,
    final List<AnnotationElement> annotationElements) {
  if (annotationAttributes != null) {
    this.annotationAttributes = new ArrayList<EdmAnnotationAttribute>();
    this.annotationAttributes.addAll(annotationAttributes);
  }
  if (annotationElements != null) {
    this.annotationElements = new ArrayList<EdmAnnotationElement>();
    for (AnnotationElement element : annotationElements) {
      EdmAnnotationElement edmElement = new EdmAnnotationElementImplProv(element);
      this.annotationElements.add(edmElement);
    }
  }
}
 
Example #9
Source File: XmlMetadataProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static void writeAnnotationElements(final Collection<AnnotationElement> annotationElements,
    final Map<String, String> predefinedNamespaces, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
  if (annotationElements != null) {
    for (AnnotationElement annotationElement : annotationElements) {
      ArrayList<String> setNamespaces = new ArrayList<String>();
      if (annotationElement.getNamespace() != null) {
        if (annotationElement.getPrefix() != null) {
          xmlStreamWriter.writeStartElement(annotationElement.getPrefix(), annotationElement.getName(),
              annotationElement.getNamespace());
          if (!predefinedNamespaces.containsValue(annotationElement.getNamespace())) {
            xmlStreamWriter.writeNamespace(annotationElement.getPrefix(), annotationElement.getNamespace());
            setNamespaces.add(annotationElement.getNamespace());
          }
        } else {
          xmlStreamWriter.writeStartElement("", annotationElement.getName(), annotationElement.getNamespace());
          if (!predefinedNamespaces.containsValue(annotationElement.getNamespace())) {
            xmlStreamWriter.writeNamespace("", annotationElement.getNamespace());
            setNamespaces.add(annotationElement.getNamespace());
          }
        }
      } else {
        xmlStreamWriter.writeStartElement(annotationElement.getName());
      }

      writeAnnotationAttributes(annotationElement.getAttributes(), predefinedNamespaces, setNamespaces,
          xmlStreamWriter);

      if (annotationElement.getChildElements() != null) {
        writeAnnotationElements(annotationElement.getChildElements(), predefinedNamespaces, xmlStreamWriter);
      } else {
        if (annotationElement.getText() != null) {
          xmlStreamWriter.writeCharacters(annotationElement.getText());
        }
      }

      xmlStreamWriter.writeEndElement();
    }
  }
}
 
Example #10
Source File: XmlMetadataProducerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void writeValidMetadata() throws Exception {
  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  annotationElements.add(new AnnotationElement().setName("test").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);

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  String metadata = StringHelper.inputStreamToString(csb.getInputStream());
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:test", metadata);
}
 
Example #11
Source File: XmlMetadataProducerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void writeValidMetadata4() throws Exception {

  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
  attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self"));
  attributesElement1.add(new AnnotationAttribute().setName("href").setText("link"));

  List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
  schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
  schemaElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));

  Schema schema = new Schema().setAnnotationElements(schemaElements);
  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);
  String metadata = StringHelper.inputStreamToString(csb.getInputStream());

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
  prefixMap.put("atom", "http://www.w3.org/2005/Atom");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest2", metadata);
}
 
Example #12
Source File: XmlMetadataProducerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void writeValidMetadata5() throws Exception {

  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
  attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom"));
  attributesElement1.add(new AnnotationAttribute().setName("href").setText("link").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom"));

  List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
  schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
  schemaElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));

  Schema schema = new Schema().setAnnotationElements(schemaElements);
  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);
  String metadata = StringHelper.inputStreamToString(csb.getInputStream());

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
  prefixMap.put("atom", "http://www.w3.org/2005/Atom");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest2", metadata);
}
 
Example #13
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetadataDokumentWithWhitepaces() throws Exception {
  final String metadata = ""
      + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
      + "           <EntityType Name= \"Photo\">"
      + "               <Key> "
      + "                 <PropertyRef Name=\"Id\" />"
      + "               </Key>"
      + "               <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
      + "               <MyAnnotation xmlns=\"http://company.com/odata\">   "
      + "                 <child> value1</child>"
      + "                 <child>value2</child>"
      + "               </MyAnnotation>"
      + "           </EntityType>"
      + "       </Schema>"
      + "  </edmx:DataServices>"
      + "</edmx:Edmx>";

  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(metadata);
  DataServices result = parser.readMetadata(reader, true);

  assertEquals(1, result.getSchemas().size());
  List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes();
  assertEquals(1, entityTypes.size());
  EntityType entityType = entityTypes.get(0);
  List<AnnotationElement> annotationElements = entityType.getAnnotationElements();
  assertEquals(1, annotationElements.size());
  AnnotationElement annotationElement = annotationElements.get(0);
  List<AnnotationElement> childElements = annotationElement.getChildElements();
  assertEquals(2, childElements.size());

  assertEquals(" value1", childElements.get(0).getText());
  assertEquals("value2", childElements.get(1).getText());
}
 
Example #14
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetadataDokumentWithWhitepacesMultiline() throws Exception {
  final String metadata = ""
      + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
      + "           <EntityType Name= \"Photo\">"
      + "               <Key> "
      + "                 <PropertyRef Name=\"Id\" />"
      + "               </Key>"
      + "               <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
      + "               <MyAnnotation xmlns=\"http://company.com/odata\">   "
      + "                 <child> value1\n"
      + "                 long long long multiline attribute</child>"
      + "                 <child>value2</child>"
      + "               </MyAnnotation>"
      + "           </EntityType>"
      + "       </Schema>"
      + "  </edmx:DataServices>"
      + "</edmx:Edmx>";

  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(metadata);
  DataServices result = parser.readMetadata(reader, true);

  assertEquals(1, result.getSchemas().size());
  List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes();
  assertEquals(1, entityTypes.size());
  EntityType entityType = entityTypes.get(0);
  List<AnnotationElement> annotationElements = entityType.getAnnotationElements();
  assertEquals(1, annotationElements.size());
  AnnotationElement annotationElement = annotationElements.get(0);
  List<AnnotationElement> childElements = annotationElement.getChildElements();
  assertEquals(2, childElements.size());

  assertEquals(" value1\n" +
      "                 long long long multiline attribute", childElements.get(0).getText());
  assertEquals("value2", childElements.get(1).getText());
}
 
Example #15
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetadataDokumentWithWhitepaces2() throws Exception {
  final String metadata = ""
      + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
      + "           <EntityType Name= \"Photo\">"
      + "               <Key> "
      + "                 <PropertyRef Name=\"Id\" />"
      + "               </Key>"
      + "               <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
      + "               <MyAnnotation xmlns=\"http://company.com/odata\">   "
      + "                 <child> value1"
      + "</child></MyAnnotation>"
      + "           </EntityType>"
      + "       </Schema>"
      + "  </edmx:DataServices>"
      + "</edmx:Edmx>";

  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(metadata);
  DataServices result = parser.readMetadata(reader, true);

  assertEquals(1, result.getSchemas().size());
  List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes();
  assertEquals(1, entityTypes.size());
  EntityType entityType = entityTypes.get(0);
  List<AnnotationElement> annotationElements = entityType.getAnnotationElements();
  assertEquals(1, annotationElements.size());
  AnnotationElement annotationElement = annotationElements.get(0);
  List<AnnotationElement> childElements = annotationElement.getChildElements();
  assertEquals(1, childElements.size());

  assertEquals(" value1", childElements.get(0).getText());
}
 
Example #16
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 #17
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void edmxReferences() throws Exception {
  DataServices serviceMetadata = new DataServices();
  List<AnnotationElement> annoElements = new ArrayList<AnnotationElement>();
  annoElements.add(createElementWithoutInclude());
  annoElements.add(createElementWithInclude());
  serviceMetadata.setAnnotationElements(annoElements);
  serviceMetadata.setDataServiceVersion(ODataServiceVersion.V20);
  ODataResponse response = EntityProvider.writeMetadata(serviceMetadata, null);

  EntityProvider.readMetadata(response.getEntityAsStream(), false);
}
 
Example #18
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private AnnotationElement createElementWithInclude() {
  List<AnnotationAttribute> childAttributes = new ArrayList<AnnotationAttribute>();
  childAttributes.add(new AnnotationAttribute().setName("Namespace").setText("Org.OData.Core.V1"));
  childAttributes.add(new AnnotationAttribute().setName("Alias").setText("UI"));
  List<AnnotationElement> childElements = new ArrayList<AnnotationElement>();
  childElements.add(new AnnotationElement().setName("Include").setNamespace(
      "http://docs.oasis-open.org/odata/ns/edmx").setPrefix("edmx").setAttributes(childAttributes));
  List<AnnotationAttribute> referenceAttributes = new ArrayList<AnnotationAttribute>();
  referenceAttributes.add(new AnnotationAttribute().setName("Uri").setText("http://someurl2.com"));
  return new AnnotationElement().setName("Reference").setPrefix("edmx").setNamespace(
      "http://docs.oasis-open.org/odata/ns/edmx").setAttributes(referenceAttributes).setChildElements(childElements);
}
 
Example #19
Source File: BasicProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private AnnotationElement createElementWithInclude() {
  List<AnnotationAttribute> childAttributes = new ArrayList<AnnotationAttribute>();
  childAttributes.add(new AnnotationAttribute().setName("Namespace").setText("Org.OData.Core.V1"));
  childAttributes.add(new AnnotationAttribute().setName("Alias").setText("UI"));
  List<AnnotationElement> childElements = new ArrayList<AnnotationElement>();
  childElements.add(new AnnotationElement().setName("Include").setNamespace(
      "http://docs.oasis-open.org/odata/ns/edmx").setPrefix("edmx").setAttributes(childAttributes));
  List<AnnotationAttribute> referenceAttributes = new ArrayList<AnnotationAttribute>();
  referenceAttributes.add(new AnnotationAttribute().setName("Uri").setText("http://someurl2.com"));
  return new AnnotationElement().setName("Reference").setPrefix("edmx").setNamespace(
      "http://docs.oasis-open.org/odata/ns/edmx").setAttributes(referenceAttributes).setChildElements(childElements);
}
 
Example #20
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Property readProperty(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_PROPERTY);
  Property property;
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  String type = reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE);
  if (type == null) {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_TYPE).addContent(XmlMetadataConstants.EDM_PROPERTY));
  }
  FullQualifiedName fqName = extractFQName(type);

  if (EdmSimpleType.EDM_NAMESPACE.equals(fqName.getNamespace())) {
    property = readSimpleProperty(reader, fqName);
  } else {
    property = readComplexProperty(reader, fqName);
  }
  property.setFacets(readFacets(reader));
  property.setCustomizableFeedMappings(readCustomizableFeedMappings(reader));
  property.setMimeType(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, XmlMetadataConstants.M_MIMETYPE));
  property.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_PROPERTY.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    property.setAnnotationElements(annotationElements);
  }
  return property;
}
 
Example #21
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Using readUsing(final XMLStreamReader reader, final String schemaNamespace)
    throws XMLStreamException, EntityProviderException {

  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_USING);

  Using using = new Using();
  using.setNamespace(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_NAMESPACE));
  inscopeMap.get(schemaNamespace).add(using.getNamespace());
  using.setAlias(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_ALIAS));
  using.setAnnotationAttributes(readAnnotationAttribute(reader));

  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_USING.equals(reader.getLocalName()))) {

    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    using.setAnnotationElements(annotationElements);
  }

  if (using.getAlias() != null) {
    aliasNamespaceMap.put(using.getAlias(), using.getNamespace());
  }

  return using;
}
 
Example #22
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private NavigationProperty readNavigationProperty(final XMLStreamReader reader) throws XMLStreamException,
    EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_NAVIGATION_PROPERTY);

  NavigationProperty navProperty = new NavigationProperty();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  navProperty.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  String relationship = reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAVIGATION_RELATIONSHIP);
  if (relationship != null) {
    FullQualifiedName fqName = extractFQName(relationship);
    navProperty.setRelationship(fqName);

  } else {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_NAVIGATION_RELATIONSHIP).addContent(
            XmlMetadataConstants.EDM_NAVIGATION_PROPERTY));
  }

  navProperty.setFromRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAVIGATION_FROM_ROLE));
  navProperty.setToRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAVIGATION_TO_ROLE));
  navProperty.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_NAVIGATION_PROPERTY.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    navProperty.setAnnotationElements(annotationElements);
  }
  navProperties.add(navProperty);
  return navProperty;
}
 
Example #23
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private FunctionImportParameter readFunctionImportParameter(final XMLStreamReader reader)
    throws EntityProviderException, XMLStreamException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_FUNCTION_PARAMETER);
  FunctionImportParameter functionParameter = new FunctionImportParameter();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();

  functionParameter.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  functionParameter.setMode(reader.getAttributeValue(null, XmlMetadataConstants.EDM_FUNCTION_PARAMETER_MODE));
  String type = reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE);
  if (type == null) {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_TYPE).addContent(XmlMetadataConstants.EDM_FUNCTION_PARAMETER));
  }
  functionParameter.setType(EdmSimpleTypeKind.valueOf(extractFQName(type).getName()));
  functionParameter.setFacets(readFacets(reader));
  functionParameter.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_FUNCTION_PARAMETER.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    functionParameter.setAnnotationElements(annotationElements);
  }
  return functionParameter;
}
 
Example #24
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ReferentialConstraintRole readReferentialConstraintRole(final XMLStreamReader reader)
    throws EntityProviderException, XMLStreamException {
  ReferentialConstraintRole rcRole = new ReferentialConstraintRole();
  rcRole.setRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ROLE));
  List<PropertyRef> propertyRefs = new ArrayList<PropertyRef>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  rcRole.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && (XmlMetadataConstants.EDM_ASSOCIATION_PRINCIPAL.equals(reader.getLocalName())
      || XmlMetadataConstants.EDM_ASSOCIATION_DEPENDENT.equals(reader.getLocalName())))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_PROPERTY_REF.equals(currentHandledStartTagName)) {
        propertyRefs.add(readPropertyRef(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (!annotationElements.isEmpty()) {
    rcRole.setAnnotationElements(annotationElements);
  }
  rcRole.setPropertyRefs(propertyRefs);
  return rcRole;
}
 
Example #25
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ReferentialConstraint readReferentialConstraint(final XMLStreamReader reader) throws XMLStreamException,
    EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_CONSTRAINT);
  ReferentialConstraint refConstraint = new ReferentialConstraint();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  refConstraint.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ASSOCIATION_CONSTRAINT.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_ASSOCIATION_PRINCIPAL.equals(currentHandledStartTagName)) {
        reader
            .require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_PRINCIPAL);
        refConstraint.setPrincipal(readReferentialConstraintRole(reader));
      } else if (XmlMetadataConstants.EDM_ASSOCIATION_DEPENDENT.equals(currentHandledStartTagName)) {
        reader
            .require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_DEPENDENT);
        refConstraint.setDependent(readReferentialConstraintRole(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (!annotationElements.isEmpty()) {
    refConstraint.setAnnotationElements(annotationElements);
  }
  return refConstraint;
}
 
Example #26
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Association readAssociation(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION);

  Association association = new Association();
  association.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  List<AssociationEnd> associationEnds = new ArrayList<AssociationEnd>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  association.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ASSOCIATION.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_ASSOCIATION_END.equals(currentHandledStartTagName)) {
        associationEnds.add(readAssociationEnd(reader));
      } else if (XmlMetadataConstants.EDM_ASSOCIATION_CONSTRAINT.equals(currentHandledStartTagName)) {
        association.setReferentialConstraint(readReferentialConstraint(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (associationEnds.size() < 2 && associationEnds.size() > 2) {
    throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
        .addContent("Count of association ends should be 2"));
  }
  if (!annotationElements.isEmpty()) {
    association.setAnnotationElements(annotationElements);
  }
  association.setEnd1(associationEnds.get(0)).setEnd2(associationEnds.get(1));
  associationsMap.put(new FullQualifiedName(currentNamespace, association.getName()), association);
  return association;
}
 
Example #27
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private EntitySet readEntitySet(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ENTITY_SET);
  EntitySet entitySet = new EntitySet();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  entitySet.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  String entityType = reader.getAttributeValue(null, XmlMetadataConstants.EDM_ENTITY_TYPE);
  if (entityType != null) {
    FullQualifiedName fqName = extractFQName(entityType);
    entitySet.setEntityType(fqName);
  } else {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_ENTITY_TYPE).addContent(XmlMetadataConstants.EDM_ENTITY_SET));
  }
  entitySet.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ENTITY_SET.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    entitySet.setAnnotationElements(annotationElements);
  }
  return entitySet;
}
 
Example #28
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private Schema readSchema(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_SCHEMA);

  Schema schema = new Schema();
  List<Using> usings = new ArrayList<Using>();
  List<ComplexType> complexTypes = new ArrayList<ComplexType>();
  List<EntityType> entityTypes = new ArrayList<EntityType>();
  List<Association> associations = new ArrayList<Association>();
  List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();

  schema.setNamespace(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_NAMESPACE));
  inscopeMap.put(schema.getNamespace(), new HashSet<String>());
  schema.setAlias(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_ALIAS));
  schema.setAnnotationAttributes(readAnnotationAttribute(reader));
  currentNamespace = schema.getNamespace();
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_USING.equals(currentHandledStartTagName)) {
        usings.add(readUsing(reader, schema.getNamespace()));
      } else if (XmlMetadataConstants.EDM_ENTITY_TYPE.equals(currentHandledStartTagName)) {
        entityTypes.add(readEntityType(reader));
      } else if (XmlMetadataConstants.EDM_COMPLEX_TYPE.equals(currentHandledStartTagName)) {
        complexTypes.add(readComplexType(reader));
      } else if (XmlMetadataConstants.EDM_ASSOCIATION.equals(currentHandledStartTagName)) {
        associations.add(readAssociation(reader));
      } else if (XmlMetadataConstants.EDM_ENTITY_CONTAINER.equals(currentHandledStartTagName)) {
        entityContainers.add(readEntityContainer(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (schema.getAlias() != null) {
    aliasNamespaceMap.put(schema.getAlias(), schema.getNamespace());
  }
  if (!annotationElements.isEmpty()) {
    schema.setAnnotationElements(annotationElements);
  }
  schema.setUsings(usings).setEntityTypes(entityTypes).setComplexTypes(complexTypes).setAssociations(associations)
      .setEntityContainers(entityContainers);
  return schema;
}
 
Example #29
Source File: EdmAnnotationElementImplProv.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public EdmAnnotationElementImplProv(final AnnotationElement element) {
  this.element = element;
}
 
Example #30
Source File: BasicProviderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private AnnotationElement createElementWithoutInclude() {
  List<AnnotationAttribute> referenceAttributes = new ArrayList<AnnotationAttribute>();
  referenceAttributes.add(new AnnotationAttribute().setName("Uri").setText("http://someurl.com"));
  return new AnnotationElement().setName("Reference").setPrefix("edmx").setNamespace(
      "http://docs.oasis-open.org/odata/ns/edmx").setAttributes(referenceAttributes);
}