You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Harold Roussel <ha...@gmail.com> on 2021/01/09 16:32:17 UTC

Expanding a complex property of an entity, is it possible?

Hello,

I have an entity object which contains a complex property (with many 
fields).  Getting the complex property is expensive, so normally when 
fetching it the complex property is not populated, and I'd like to 
populate it through a $expand directive.

I've played with the olingo tutorial samples.  More specifically the one 
on navigation (available here: 
https://olingo.apache.org/doc/odata4/tutorials/navigation/tutorial_navigation.html).

Although the online tutorial doesn't mention it, the downloadable source 
code for the navigation project contains an extra entity, "Suppliers".  
And that entity contains a complex property, "Address".  So I thought 
that would be the perfect place to practice this $expand I was planning.

But it doesn't seem to work.  I tried modifying the suppliers entity as 
follows, first in getEntityType,

} else if (entityTypeName.equals(ET_SUPPLIER_FQN)) {
       // create EntityType properties
       CsdlProperty supplierId = new 
CsdlProperty().setName("SupplierID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
       CsdlProperty companyName = new 
CsdlProperty().setName("CompanyName").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
       CsdlProperty fax = new 
CsdlProperty().setName("Fax").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
       CsdlProperty address = new 
CsdlProperty().setName(CT_ADDRESS_NAME).setType(CT_ADDRESS_FQN);

       // create PropertyRef for Key element
       CsdlPropertyRef propertyRef = new CsdlPropertyRef();
       propertyRef.setName("SupplierID");

    // navigation property: one-to-many
*      CsdlNavigationProperty navProp = new 
CsdlNavigationProperty().setName("Address").setType(CT_ADDRESS_FQN).setCollection(false).setPartner("Supplier");**
**      List<CsdlNavigationProperty> navPropList = new 
ArrayList<CsdlNavigationProperty>();**
**      navPropList.add(navProp);*

       // configure EntityType
       entityType = new CsdlEntityType();
       entityType.setName(ET_SUPPLIER_NAME);
       entityType.setProperties(Arrays.asList(supplierId, companyName, 
fax, address));
       entityType.setKey(Arrays.asList(propertyRef));
       entityType.setNavigationProperties(navPropList);
     }

In bold is my addition.  I also modified getEntitySet,

} else if (entitySetName.equals(ES_SUPPLIERS_NAME)) {

           entitySet = new CsdlEntitySet();
           entitySet.setName(ES_SUPPLIERS_NAME);
           entitySet.setType(ET_SUPPLIER_FQN);

*          // navigation**
**          CsdlNavigationPropertyBinding navPropBinding = new 
CsdlNavigationPropertyBinding();**
**          navPropBinding.setTarget("Address"); // the target entity 
set, where the navigation property points to**
**          navPropBinding.setPath("Address"); // the path from entity 
type to navigation property**
**          List<CsdlNavigationPropertyBinding> navPropBindingList = new 
ArrayList<CsdlNavigationPropertyBinding>();**
**          navPropBindingList.add(navPropBinding);**
**entitySet.setNavigationPropertyBindings(navPropBindingList);**
*}

Again in bold my additions.  But whenever I tried to expand on the 
Address with the following URL,

http://localhost:8080/DemoService/DemoService.svc/Suppliers(1)?$expand=Address

it fails with "The URI is malformed."

So, my question is whether what I want to achieve is possible in olingo, 
and if so what I'm not doing properly.

Thanks,
Harold


Re: Expanding a complex property of an entity, is it possible?

Posted by Harold Roussel <ha...@gmail.com>.
Thanks for the suggestions, I'll check if they can fit my requirements.  
I wonder also if it would be possible to declare the Address as a 
separate navigable entity, on top of being a complex property of 
Supplier.  Might give it a try.

Just a question though.  I have some old code based on olingo 4.0.0 
beta2 that appears to allow $expand on complex properties. Does this 
mean that this capability was removed at some point?

Thanks,
Harold

On 2021-01-11 6:29 a.m., Grande, Oliver wrote:
>
> Hello Herold,
>
> $expand is there to retrieve navigation properties together with the 
> start of the navigation, like getting Categories together with the 
> Products. In case you want to retrieve only a subset of attributes of 
> an entity you have two options:
>
>  1. You want to get a property (this could be a complex property as
>     well) of one entity, you use:
>     http://localhost:8080/DemoService/DemoService.svc/Suppliers(1)/Address
>     <http://localhost:8080/DemoService/DemoService.svc/Suppliers(1)/Address>
>  2. You want to get a subset for an entity set, you can use $select:
>     http://localhost:8080/DemoService/DemoService.svc/Suppliers?$select=Address
>     <http://localhost:8080/DemoService/DemoService.svc/Suppliers?$select=Address>
>
>
> Regards,
>
> Oliver
>
> *From:*Harold Roussel <ha...@gmail.com>
> *Sent:* Samstag, 9. Januar 2021 17:32
> *To:* user@olingo.apache.org
> *Subject:* Expanding a complex property of an entity, is it possible?
>
> Hello,
>
> I have an entity object which contains a complex property (with many 
> fields).  Getting the complex property is expensive, so normally when 
> fetching it the complex property is not populated, and I'd like to 
> populate it through a $expand directive.
>
> I've played with the olingo tutorial samples.  More specifically the 
> one on navigation (available here: 
> https://olingo.apache.org/doc/odata4/tutorials/navigation/tutorial_navigation.html 
> <https://olingo.apache.org/doc/odata4/tutorials/navigation/tutorial_navigation.html>).
>
> Although the online tutorial doesn't mention it, the downloadable 
> source code for the navigation project contains an extra entity, 
> "Suppliers".  And that entity contains a complex property, "Address".  
> So I thought that would be the perfect place to practice this $expand 
> I was planning.
>
> But it doesn't seem to work.  I tried modifying the suppliers entity 
> as follows, first in getEntityType,
>
> } else if (entityTypeName.equals(ET_SUPPLIER_FQN)) {
>       // create EntityType properties
>       CsdlProperty supplierId = new 
> CsdlProperty().setName("SupplierID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
>       CsdlProperty companyName = new 
> CsdlProperty().setName("CompanyName").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
>       CsdlProperty fax = new 
> CsdlProperty().setName("Fax").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
>       CsdlProperty address = new 
> CsdlProperty().setName(CT_ADDRESS_NAME).setType(CT_ADDRESS_FQN);
>
>       // create PropertyRef for Key element
>       CsdlPropertyRef propertyRef = new CsdlPropertyRef();
>       propertyRef.setName("SupplierID");
>
>    // navigation property: one-to-many
> *      CsdlNavigationProperty navProp = new 
> CsdlNavigationProperty().setName("Address").setType(CT_ADDRESS_FQN).setCollection(false).setPartner("Supplier");
>       List<CsdlNavigationProperty> navPropList = new 
> ArrayList<CsdlNavigationProperty>();
>       navPropList.add(navProp);*
>
>       // configure EntityType
>       entityType = new CsdlEntityType();
>       entityType.setName(ET_SUPPLIER_NAME);
>       entityType.setProperties(Arrays.asList(supplierId, companyName, 
> fax, address));
>       entityType.setKey(Arrays.asList(propertyRef));
>       entityType.setNavigationProperties(navPropList);
>     }
>
> In bold is my addition.  I also modified getEntitySet,
>
> } else if (entitySetName.equals(ES_SUPPLIERS_NAME)) {
>
>           entitySet = new CsdlEntitySet();
>           entitySet.setName(ES_SUPPLIERS_NAME);
>           entitySet.setType(ET_SUPPLIER_FQN);
>
> *          // navigation
>           CsdlNavigationPropertyBinding navPropBinding = new 
> CsdlNavigationPropertyBinding();
>           navPropBinding.setTarget("Address"); // the target entity 
> set, where the navigation property points to
>           navPropBinding.setPath("Address"); // the path from entity 
> type to navigation property
>           List<CsdlNavigationPropertyBinding> navPropBindingList = new 
> ArrayList<CsdlNavigationPropertyBinding>();
>           navPropBindingList.add(navPropBinding);
> entitySet.setNavigationPropertyBindings(navPropBindingList);
> *}
>
> Again in bold my additions.  But whenever I tried to expand on the 
> Address with the following URL,
>
> http://localhost:8080/DemoService/DemoService.svc/Suppliers(1)?$expand=Address 
> <http://localhost:8080/DemoService/DemoService.svc/Suppliers(1)?$expand=Address>
>
> it fails with "The URI is malformed."
>
> So, my question is whether what I want to achieve is possible in 
> olingo, and if so what I'm not doing properly.
>
> Thanks,
> Harold
>

RE: Expanding a complex property of an entity, is it possible?

Posted by "Grande, Oliver" <ol...@sap.com>.
Hello Herold,

$expand is there to retrieve navigation properties together with the start of the navigation, like getting Categories together with the Products. In case you want to retrieve only a subset of attributes of an entity you have two options:

  1.  You want to get a property (this could be a complex property as well) of one entity, you use:
http://localhost:8080/DemoService/DemoService.svc/Suppliers(1)/Address
  2.  You want to get a subset for an entity set, you can use $select:
http://localhost:8080/DemoService/DemoService.svc/Suppliers?$select=Address


Regards,
Oliver

From: Harold Roussel <ha...@gmail.com>
Sent: Samstag, 9. Januar 2021 17:32
To: user@olingo.apache.org
Subject: Expanding a complex property of an entity, is it possible?


Hello,

I have an entity object which contains a complex property (with many fields).  Getting the complex property is expensive, so normally when fetching it the complex property is not populated, and I'd like to populate it through a $expand directive.

I've played with the olingo tutorial samples.  More specifically the one on navigation (available here: https://olingo.apache.org/doc/odata4/tutorials/navigation/tutorial_navigation.html).

Although the online tutorial doesn't mention it, the downloadable source code for the navigation project contains an extra entity, "Suppliers".  And that entity contains a complex property, "Address".  So I thought that would be the perfect place to practice this $expand I was planning.

But it doesn't seem to work.  I tried modifying the suppliers entity as follows, first in getEntityType,

} else if (entityTypeName.equals(ET_SUPPLIER_FQN)) {
      // create EntityType properties
      CsdlProperty supplierId = new CsdlProperty().setName("SupplierID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
      CsdlProperty companyName = new CsdlProperty().setName("CompanyName").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
      CsdlProperty fax = new CsdlProperty().setName("Fax").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
      CsdlProperty address = new CsdlProperty().setName(CT_ADDRESS_NAME).setType(CT_ADDRESS_FQN);

      // create PropertyRef for Key element
      CsdlPropertyRef propertyRef = new CsdlPropertyRef();
      propertyRef.setName("SupplierID");

   // navigation property: one-to-many
      CsdlNavigationProperty navProp = new CsdlNavigationProperty().setName("Address").setType(CT_ADDRESS_FQN).setCollection(false).setPartner("Supplier");
      List<CsdlNavigationProperty> navPropList = new ArrayList<CsdlNavigationProperty>();
      navPropList.add(navProp);

      // configure EntityType
      entityType = new CsdlEntityType();
      entityType.setName(ET_SUPPLIER_NAME);
      entityType.setProperties(Arrays.asList(supplierId, companyName, fax, address));
      entityType.setKey(Arrays.asList(propertyRef));
      entityType.setNavigationProperties(navPropList);
    }

In bold is my addition.  I also modified getEntitySet,

} else if (entitySetName.equals(ES_SUPPLIERS_NAME)) {

          entitySet = new CsdlEntitySet();
          entitySet.setName(ES_SUPPLIERS_NAME);
          entitySet.setType(ET_SUPPLIER_FQN);

          // navigation
          CsdlNavigationPropertyBinding navPropBinding = new CsdlNavigationPropertyBinding();
          navPropBinding.setTarget("Address"); // the target entity set, where the navigation property points to
          navPropBinding.setPath("Address"); // the path from entity type to navigation property
          List<CsdlNavigationPropertyBinding> navPropBindingList = new ArrayList<CsdlNavigationPropertyBinding>();
          navPropBindingList.add(navPropBinding);
          entitySet.setNavigationPropertyBindings(navPropBindingList);
}

Again in bold my additions.  But whenever I tried to expand on the Address with the following URL,

http://localhost:8080/DemoService/DemoService.svc/Suppliers(1)?$expand=Address

it fails with "The URI is malformed."

So, my question is whether what I want to achieve is possible in olingo, and if so what I'm not doing properly.

Thanks,
Harold