Java Code Examples for org.apache.olingo.commons.api.data.Property#asComplex()

The following examples show how to use org.apache.olingo.commons.api.data.Property#asComplex() . 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: ActionDataProviderTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void actionUARTCTTwoPrimParam() throws Exception {
  Parameter paramInt16 = new Parameter();
  paramInt16.setName("ParameterInt16");
  paramInt16.setValue(ValueType.PRIMITIVE, new Short((short) 3));
  final Map<String, Parameter> parameters = Collections.singletonMap("ParameterInt16", paramInt16);

  Property result = ActionData.complexAction("UARTCTTwoPrimParam", parameters);
  assertNotNull(result);
  ComplexValue value = result.asComplex();
  assertEquals((short) 3, value.getValue().get(0).asPrimitive());

  result = ActionData.complexAction("UARTCTTwoPrimParam", Collections.<String, Parameter> emptyMap());
  assertNotNull(result);
  value = result.asComplex();
  assertEquals((short) 32767, value.getValue().get(0).asPrimitive());
}
 
Example 2
Source File: ODataXmlDeserializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void complexProperty() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
  final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp");
  final String payload = "<data:PropertyComp xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" "
      + " xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\"\n"
      + " metadata:type=\"#olingo.odata.test1.CTTwoPrim\">\n"
      + "  <data:PropertyInt16>123</data:PropertyInt16>\n" 
      + "  <data:PropertyString metadata:null=\"true\"/>\n"
      + "</data:PropertyComp>";

  final Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty)
      .getProperty();

  Assert.assertEquals("PropertyComp", result.getName());
  Assert.assertTrue(result.isComplex());
  final ComplexValue cv = result.asComplex();
  Assert.assertEquals("olingo.odata.test1.CTTwoPrim", result.getType());
  Assert.assertEquals((short) 123, getCVProperty(cv, "PropertyInt16").asPrimitive());
  Assert.assertTrue(getCVProperty(cv, "PropertyString").isNull());    
}
 
Example 3
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void updateProperty(final EdmProperty edmProperty, Property property, final Property newProperty,
    final boolean patch) throws DataProviderException {
  if(property == null){
    throw new DataProviderException("Cannot update type of the entity",
        HttpStatusCode.BAD_REQUEST);
  }
  final EdmType type = edmProperty.getType();
  if (edmProperty.isCollection()) {
    // Updating collection properties means replacing all entries with the given ones.
    property.asCollection().clear();

    if (newProperty != null) {
      if (type.getKind() == EdmTypeKind.COMPLEX) {
        // Create each complex value.
        for (final ComplexValue complexValue : (List<ComplexValue>) newProperty.asCollection()) {
          ((List<ComplexValue>) property.asCollection()).add(createComplexValue(edmProperty, complexValue, patch));
        }
      } else {
        // Primitive type
        ((List<Object>) property.asCollection()).addAll(newProperty.asCollection());
      }
    }
  } else if (type.getKind() == EdmTypeKind.COMPLEX) {
    for (final String propertyName : ((EdmComplexType) type).getPropertyNames()) {
      final List<Property> newProperties = newProperty == null || newProperty.asComplex() == null ? null :
          newProperty.asComplex().getValue();
      updateProperty(((EdmComplexType) type).getStructuralProperty(propertyName),
          findProperty(propertyName, property.asComplex().getValue()),
          newProperties == null ? null : findProperty(propertyName, newProperties),
          patch);
    }
  } else {
    if (newProperty != null || !patch) {
      final Object value = newProperty == null ? null : newProperty.getValue();
      updatePropertyValue(property, value);
    }
  }
}
 
Example 4
Source File: ODataJsonDeserializerEntityTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void extendedComplexProperty() throws Exception {
  
  final String payload = "{"
      + "\"@odata.context\":\"$metadata#ESCompComp/$entity\","
      + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
      + "\"@odata.etag\":\"W/\\\"32767\\\"\","
      + "\"PropertyInt16\":32767,"
      + "\"PropertyComp\":{"
          +  "\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
          +  "\"PropertyInt16\":11,"
          +  "\"PropertyString\":\"Num11\""
      +  "},"
      +  "\"PropertyCompComp\":{"
          +  "\"@odata.type\":\"#olingo.odata.test1.CTCompComp\","
          +  "\"PropertyComp\":{"
          +  "\"@odata.type\":\"#olingo.odata.test1.CTBase\","
          +  "\"PropertyInt16\":32767,"
          +  "\"PropertyString\":\"Num111\","
          +  "\"AdditionalPropString\":\"Test123\""
      +  "}}}";
  final Entity result = deserialize(payload, "ETFourKeyAlias");
  
  Assert.assertNotNull(result);
  Property propertyCompComp = result.getProperty("PropertyCompComp");
  Assert.assertEquals("PropertyCompComp", propertyCompComp.getName());   
  Assert.assertEquals("olingo.odata.test1.CTCompComp", propertyCompComp.getType());
  Assert.assertTrue(propertyCompComp.isComplex());
  
  ComplexValue complexValuePropComp = propertyCompComp.asComplex();    
  Property propertyComp = getCVProperty(complexValuePropComp, "PropertyComp");
  Assert.assertEquals("PropertyComp", propertyComp.getName()); 
  Assert.assertEquals("olingo.odata.test1.CTBase", propertyComp.getType());
  Assert.assertTrue(propertyComp.isComplex());  
  
  final ComplexValue cvAdditionalString = propertyComp.asComplex();
  Assert.assertEquals("Test123",getCVProperty(cvAdditionalString, "AdditionalPropString").asPrimitive());
}
 
Example 5
Source File: ODataJsonDeserializerEntityTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void deriveEntityETMixPrimCollComp() throws Exception {
  final String entityString = "{"
      + "\"PropertyInt16\":32767,"
      + "\"CollPropertyString\":"
      + "[\"[email protected]\",\"[email protected]\",\"[email protected]\"],"
      + "\"PropertyComp\":{\"@odata.type\": \"#olingo.odata.test1.CTBase\","
      + "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\",\"AdditionalPropString\":\"Additional\"},"
      + "\"CollPropertyComp\":["
      + "{\"@odata.type\": \"#olingo.odata.test1.CTBase\",\n"
      + "\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\",\"AdditionalPropString\":\"Additional\"},"
      + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
      + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
  final Entity entity = deserialize(entityString, "ETMixPrimCollComp");
  assertNotNull(entity);
  List<Property> properties = entity.getProperties();
  assertNotNull(properties);
  assertEquals(4, properties.size());
  Property prop = entity.getProperty("PropertyComp");
  ComplexValue asComp = prop.asComplex();
  assertEquals(3,asComp.getValue().size());
  assertEquals("olingo.odata.test1.CTBase",prop.getType());
  Property property = entity.getProperty("CollPropertyComp");
  assertEquals(ValueType.COLLECTION_COMPLEX, property.getValueType());

  assertTrue(property.getValue() instanceof List);
  List<? extends Object> asCollection = property.asCollection();
  assertEquals(3, asCollection.size());
  assertEquals(3,((ComplexValue)asCollection.get(0)).getValue().size());
  assertEquals(2,((ComplexValue)asCollection.get(1)).getValue().size());
  assertEquals(2,((ComplexValue)asCollection.get(2)).getValue().size());
}
 
Example 6
Source File: ODataXmlSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void writeComplex(final ServiceMetadata metadata,
    final EdmProperty edmProperty, final Property property,
    final Set<List<String>> selectedPaths,
    final String xml10InvalidCharReplacement, final XMLStreamWriter writer, 
    Set<List<String>> expandedPaths, Linked linked, ExpandOption expand) 
        throws XMLStreamException, SerializerException{
    
     writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
            "#" + complexType(metadata, (EdmComplexType) edmProperty.getType(), 
                    property.getType()));
      String derivedName = property.getType();
     final EdmComplexType resolvedType = resolveComplexType(metadata,
      (EdmComplexType) edmProperty.getType(), derivedName);
     
     if (null != linked) {
       if (linked instanceof Entity) {
         linked = ((Entity)linked).getProperty(property.getName()).asComplex();
       } else if (linked instanceof ComplexValue) {
         List<Property> complexProperties = ((ComplexValue)linked).getValue();
         for (Property prop : complexProperties) {
           if (prop.getName().equals(property.getName())) {
             linked = prop.asComplex();
             break;
           }
         }
       }
       expandedPaths = expandedPaths == null || expandedPaths.isEmpty() ? null :
         ExpandSelectHelper.getReducedExpandItemsPaths(expandedPaths, property.getName());
     }
     
      writeComplexValue(metadata, resolvedType, property.asComplex().getValue(),
         selectedPaths, xml10InvalidCharReplacement, writer, expandedPaths, linked, expand, property.getName());
}
 
Example 7
Source File: ODataXmlDeserializerTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void entityCompAllPrim() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompAllPrim");

  String payload = "<?xml version='1.0' encoding='UTF-8'?>"
      + "<atom:entry xmlns:atom=\"http://www.w3.org/2005/Atom\" "
      + "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
      + "xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" "
      + "metadata:etag=\"W/&quot;32767&quot;\">"
        + "<atom:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" "
        + "term=\"#olingo.odata.test1.ETCompAllPrim\"/>"
        + "<atom:content type=\"application/xml\">"
          + "<metadata:properties>"
            + "<data:PropertyInt16>32767</data:PropertyInt16>"
            + "<data:PropertyComp metadata:type=\"#olingo.odata.test1.CTAllPrim\">"
              + "<data:PropertyString>First Resource - first</data:PropertyString>"
              + "<data:PropertyBinary>ASNFZ4mrze8=</data:PropertyBinary>"
              + "<data:PropertyBoolean>true</data:PropertyBoolean>"
              + "<data:PropertyByte>255</data:PropertyByte>"
              + "<data:PropertyDate>2012-10-03</data:PropertyDate>"
              + "<data:PropertyDateTimeOffset>2012-10-03T07:16:23.1234567Z</data:PropertyDateTimeOffset>"
              + "<data:PropertyDecimal>34.27</data:PropertyDecimal>"
              + "<data:PropertySingle>1.79E20</data:PropertySingle>"
              + "<data:PropertyDouble>-1.79E19</data:PropertyDouble>"
              + "<data:PropertyDuration>PT6S</data:PropertyDuration>"
              + "<data:PropertyGuid>01234567-89ab-cdef-0123-456789abcdef</data:PropertyGuid>"
              + "<data:PropertyInt16>32767</data:PropertyInt16>"
              + "<data:PropertyInt32>2147483647</data:PropertyInt32>"
              + "<data:PropertyInt64>9223372036854775807</data:PropertyInt64>"
              + "<data:PropertySByte>127</data:PropertySByte>"
              + "<data:PropertyTimeOfDay>01:00:01</data:PropertyTimeOfDay>"
            + "</data:PropertyComp>"
          + "</metadata:properties>"
        + "</atom:content>"
      + "</atom:entry>";
  
  Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()), 
      edmEntitySet.getEntityType()).getEntity();

  Assert.assertEquals("olingo.odata.test1.ETCompAllPrim",result.getType());
  
  Assert.assertEquals(2, result.getProperties().size());
  Assert.assertEquals(0, result.getNavigationLinks().size());

  Assert.assertEquals((short) 32767, result.getProperty("PropertyInt16").asPrimitive());

  Assert.assertNotNull(result.getProperty("PropertyComp"));
  Property comp = result.getProperty("PropertyComp");
  Assert.assertEquals("olingo.odata.test1.CTAllPrim", comp.getType());
  ComplexValue cv = comp.asComplex();
  
  Assert.assertEquals(16, cv.getValue().size());
  
  Assert.assertEquals((short) 32767, getCVProperty(cv, "PropertyInt16").asPrimitive());
  Assert.assertEquals("First Resource - first", getCVProperty(cv, "PropertyString").asPrimitive());
  Assert.assertEquals((short) 255, getCVProperty(cv, "PropertyByte").asPrimitive());
  Assert.assertEquals((byte) 127, getCVProperty(cv, "PropertySByte").asPrimitive());
  Assert.assertEquals(2147483647, getCVProperty(cv, "PropertyInt32").asPrimitive());
  Assert.assertEquals(9223372036854775807L, getCVProperty(cv, "PropertyInt64").asPrimitive());
}
 
Example 8
Source File: ODataXmlDeserializerTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void entityMixPrimCollComp() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
  final String payload = "<?xml version='1.0' encoding='UTF-8'?>\n" + 
      "<atom:entry xmlns:atom=\"http://www.w3.org/2005/Atom\"\n" + 
      "  xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" + 
      "  xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" \n" + 
      "  metadata:metadata-etag=\"WmetadataETag\">\n" + 
      "  <atom:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" + 
      "    term=\"#olingo.odata.test1.ETMixPrimCollComp\" />\n" + 
      "  <atom:content type=\"application/xml\">\n" + 
      "    <metadata:properties>\n" + 
      "      <data:PropertyInt16>32767</data:PropertyInt16>\n" + 
      "      <data:CollPropertyString type=\"#Collection(String)\">\n" + 
      "        <metadata:element>[email protected]</metadata:element>\n" + 
      "        <metadata:element>[email protected]</metadata:element>\n" + 
      "        <metadata:element>[email protected]</metadata:element>\n" + 
      "      </data:CollPropertyString>\n" + 
      "      <data:PropertyComp metadata:type=\"#olingo.odata.test1.CTTwoPrim\">\n" + 
      "        <data:PropertyInt16>111</data:PropertyInt16>\n" + 
      "        <data:PropertyString>TEST A</data:PropertyString>\n" + 
      "      </data:PropertyComp>\n" + 
      "       <data:CollPropertyComp metadata:type=\"#Collection(olingo.odata.test1.CTTwoPrim)\">\n" + 
      "          <metadata:element>\n" + 
      "            <data:PropertyInt16>123</data:PropertyInt16>\n" + 
      "            <data:PropertyString>TEST 1</data:PropertyString>\n" + 
      "          </metadata:element>\n" + 
      "          <metadata:element>\n" + 
      "            <data:PropertyInt16>456</data:PropertyInt16>\n" + 
      "            <data:PropertyString>TEST 2</data:PropertyString>\n" + 
      "          </metadata:element>\n" + 
      "          <metadata:element>\n" + 
      "            <data:PropertyInt16>789</data:PropertyInt16>\n" + 
      "            <data:PropertyString>TEST 3</data:PropertyString>\n" + 
      "          </metadata:element>\n" + 
      "        </data:CollPropertyComp>\n" + 
      "    </metadata:properties>\n" + 
      "  </atom:content>\n" + 
      "</atom:entry>\n"; 

  Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()), 
      edmEntitySet.getEntityType()).getEntity();

  Assert.assertEquals(4, result.getProperties().size());
  Assert.assertEquals(0, result.getNavigationLinks().size());

  Assert.assertEquals(Arrays.asList("[email protected]", "[email protected]",
      "[email protected]"), result.getProperty("CollPropertyString").getValue());

  Property comp = result.getProperty("PropertyComp");
  Assert.assertEquals("olingo.odata.test1.CTTwoPrim", comp.getType());
  ComplexValue cv = comp.asComplex();
  
  Assert.assertEquals(2, cv.getValue().size());
  Assert.assertEquals((short) 111, getCVProperty(cv, "PropertyInt16").asPrimitive());
  Assert.assertEquals("TEST A", getCVProperty(cv, "PropertyString").asPrimitive());
  
  comp = result.getProperty("CollPropertyComp");
  Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", comp.getType());

  List<?> properties = comp.asCollection();
  Assert.assertEquals(3, properties.size());
  
  Assert.assertEquals((short) 123, getCVProperty((ComplexValue) properties.get(0), "PropertyInt16").asPrimitive());
  Assert.assertEquals("TEST 1", getCVProperty((ComplexValue) properties.get(0), "PropertyString").asPrimitive());

  Assert.assertEquals((short) 789, getCVProperty((ComplexValue) properties.get(2), "PropertyInt16").asPrimitive());
  Assert.assertEquals("TEST 3", getCVProperty((ComplexValue) properties.get(2), "PropertyString").asPrimitive());
}
 
Example 9
Source File: ODataXmlDeserializerTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void derivedEntityMixPrimCollComp() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
  final String payload = "<?xml version='1.0' encoding='UTF-8'?>\n" + 
      "<atom:entry xmlns:atom=\"http://www.w3.org/2005/Atom\"\n" + 
      "  xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" + 
      "  xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" \n" + 
      "  metadata:metadata-etag=\"WmetadataETag\">\n" + 
      "  <atom:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" + 
      "    term=\"#olingo.odata.test1.ETMixPrimCollComp\" />\n" + 
      "  <atom:content type=\"application/xml\">\n" + 
      "    <metadata:properties>\n" + 
      "      <data:PropertyInt16>32767</data:PropertyInt16>\n" + 
      "      <data:CollPropertyString type=\"#Collection(String)\">\n" + 
      "        <metadata:element>[email protected]</metadata:element>\n" + 
      "        <metadata:element>[email protected]</metadata:element>\n" + 
      "        <metadata:element>[email protected]</metadata:element>\n" + 
      "      </data:CollPropertyString>\n" + 
      "      <data:PropertyComp metadata:type=\"#olingo.odata.test1.CTBase\">\n" + 
      "        <data:PropertyInt16>111</data:PropertyInt16>\n" + 
      "        <data:PropertyString>TEST A</data:PropertyString>\n" + 
      "        <data:AdditionalPropString>Additional</data:AdditionalPropString>\n" + 
      "      </data:PropertyComp>\n" + 
      "       <data:CollPropertyComp metadata:type=\"#Collection(olingo.odata.test1.CTTwoPrim)\">\n" + 
      "          <metadata:element  metadata:type=\"olingo.odata.test1.CTBase\">\n" + 
      "            <data:PropertyInt16>123</data:PropertyInt16>\n" + 
      "            <data:PropertyString>TEST 1</data:PropertyString>\n" + 
      "            <data:AdditionalPropString>Additional test</data:AdditionalPropString>\n" + 
      "          </metadata:element>\n" + 
      "          <metadata:element>\n" + 
      "            <data:PropertyInt16>456</data:PropertyInt16>\n" + 
      "            <data:PropertyString>TEST 2</data:PropertyString>\n" + 
      "          </metadata:element>\n" + 
      "          <metadata:element>\n" + 
      "            <data:PropertyInt16>789</data:PropertyInt16>\n" + 
      "            <data:PropertyString>TEST 3</data:PropertyString>\n" + 
      "          </metadata:element>\n" + 
      "        </data:CollPropertyComp>\n" + 
      "    </metadata:properties>\n" + 
      "  </atom:content>\n" + 
      "</atom:entry>\n"; 

  Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()), 
      edmEntitySet.getEntityType()).getEntity();

  Assert.assertEquals(4, result.getProperties().size());
  Assert.assertEquals(0, result.getNavigationLinks().size());

  Assert.assertEquals(Arrays.asList("[email protected]", "[email protected]",
      "[email protected]"), result.getProperty("CollPropertyString").getValue());

  Property comp = result.getProperty("PropertyComp");
  Assert.assertEquals("olingo.odata.test1.CTBase", comp.getType());
  ComplexValue cv = comp.asComplex();
  
  Assert.assertEquals(3, cv.getValue().size());
  Assert.assertEquals((short) 111, getCVProperty(cv, "PropertyInt16").asPrimitive());
  Assert.assertEquals("TEST A", getCVProperty(cv, "PropertyString").asPrimitive());
  Assert.assertEquals("Additional", getCVProperty(cv, "AdditionalPropString").asPrimitive());
  
  comp = result.getProperty("CollPropertyComp");
  Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", comp.getType());

  List<?> properties = comp.asCollection();
  Assert.assertEquals(3, properties.size());
  
  Assert.assertEquals((short) 123, getCVProperty((ComplexValue) properties.get(0), "PropertyInt16").asPrimitive());
  Assert.assertEquals("TEST 1", getCVProperty((ComplexValue) properties.get(0), "PropertyString").asPrimitive());
  Assert.assertEquals("Additional test", getCVProperty((ComplexValue) properties.get(0), "AdditionalPropString")
      .asPrimitive());

  Assert.assertEquals((short) 789, getCVProperty((ComplexValue) properties.get(2), "PropertyInt16").asPrimitive());
  Assert.assertEquals("TEST 3", getCVProperty((ComplexValue) properties.get(2), "PropertyString").asPrimitive());
}
 
Example 10
Source File: ODataXmlDeserializerTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void extendedComplexProperty() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESFourKeyAlias");
  
  String payload = "<?xml version='1.0' encoding='UTF-8'?>"
      + "<atom:entry xmlns:atom=\"http://www.w3.org/2005/Atom\" "
      + "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
      + "xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\">"
        + "<atom:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" "
        + "term=\"#olingo.odata.test1.ETFourKeyAlias\"/>"
        +  "<atom:content type=\"application/xml\">"
              +  "<metadata:properties>"
                  +  "<data:PropertyInt16 metadata:type=\"Int16\">1</data:PropertyInt16>"
                  +  "<data:PropertyComp metadata:type=\"#olingo.odata.test1.CTTwoPrim\">"
                      +  "<data:PropertyInt16 metadata:type=\"Int16\">11</data:PropertyInt16>"
                      +  "<data:PropertyString>Num11</data:PropertyString>"
                  +  "</data:PropertyComp>"
                  +  "<data:PropertyCompComp metadata:type=\"#olingo.odata.test1.CTCompComp\">"
                      +  "<data:PropertyComp metadata:type=\"#olingo.odata.test1.CTBase\">"
                          +  "<data:PropertyInt16 metadata:type=\"Int16\">111</data:PropertyInt16>"
                          +  "<data:PropertyString>Num111</data:PropertyString>"
                          +  "<data:AdditionalPropString>Test123</data:AdditionalPropString>"
                      +  "</data:PropertyComp>"
                  +  "</data:PropertyCompComp>"
              +  "</metadata:properties>"
            +  "</atom:content>"
        +  "</atom:entry>";
  
  EdmEntityType entityType = edmEntitySet.getEntityType();
  Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()), entityType)
          .getEntity();

  Assert.assertNotNull(result);
  Property propertyCompComp = result.getProperty("PropertyCompComp");
  Assert.assertEquals("PropertyCompComp", propertyCompComp.getName());   
  Assert.assertEquals("olingo.odata.test1.CTCompComp", propertyCompComp.getType());
  Assert.assertTrue(propertyCompComp.isComplex());
  
  ComplexValue complexValuePropComp = propertyCompComp.asComplex();    
  Property propertyComp = getCVProperty(complexValuePropComp, "PropertyComp");
  Assert.assertEquals("PropertyComp", propertyComp.getName()); 
  Assert.assertEquals("olingo.odata.test1.CTBase", propertyComp.getType());
  Assert.assertTrue(propertyComp.isComplex());  
  
  final ComplexValue cvAdditionalString = propertyComp.asComplex();
  Assert.assertEquals("Test123",getCVProperty(cvAdditionalString, "AdditionalPropString").asPrimitive());
}
 
Example 11
Source File: ODataJsonSerializer.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void writeComplex(final ServiceMetadata metadata, final EdmComplexType type,
    final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json, 
    Set<List<String>> expandedPaths, Linked linked, ExpandOption expand) 
        throws IOException, SerializerException{
      json.writeStartObject();        
      String derivedName = property.getType();
      EdmComplexType resolvedType = null;
      if (!type.getFullQualifiedName().getFullQualifiedNameAsString().
          equals(derivedName)) {
        if (type.getBaseType() != null && 
            type.getBaseType().getFullQualifiedName().getFullQualifiedNameAsString().
            equals(derivedName)) {
          resolvedType = resolveComplexType(metadata, type.getBaseType(), 
              type.getFullQualifiedName().getFullQualifiedNameAsString());
        } else {
          resolvedType = resolveComplexType(metadata, type, derivedName);
        }
      } else {
        resolvedType = resolveComplexType(metadata, type, derivedName);
      }
      if (!isODataMetadataNone && !resolvedType.equals(type) || isODataMetadataFull) {
         json.writeStringField(constants.getType(), "#" + 
      resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
      }
      
      if (null != linked) {
        if (linked instanceof Entity) {
          linked = ((Entity)linked).getProperty(property.getName()).asComplex();
        } else if (linked instanceof ComplexValue) {
          List<Property> complexProperties = ((ComplexValue)linked).getValue();
          for (Property prop : complexProperties) {
            if (prop.getName().equals(property.getName())) {
              linked = prop.asComplex();
              break;
            }
          }
        }
        expandedPaths = expandedPaths == null || expandedPaths.isEmpty() ? null :
          ExpandSelectHelper.getReducedExpandItemsPaths(expandedPaths, property.getName());
      }
      
      writeComplexValue(metadata, resolvedType, property.asComplex().getValue(), selectedPaths,
           json, expandedPaths, linked, expand, property.getName());
      json.writeEndObject();
}