Skip to Content
3
3 days ago

Deep Expansion (with $expand or another alternative)

33 Views

Greetings, SAP community.

I am working on a project with SAP CAP and SAP HANA in the SAP BTP environment (temporarily, trial account).

I have some entities similar to the following:

entity Regions : SAP.CodeList {
    key code        : String(5); //> ISO 3166-1 alpha-2 codes (or alpha-3)
        country     : SAP_Country not null;
        superRegion : Association to Regions;
        subRegions  : Composition of many Regions on subRegions.superRegion = $self;
}
entity ORG : SAP.CodeList {
  key ID      : String(36);
      parent  : Association to ORG;
      country : SAP_Country;
      sons    : Composition of many ORG on sons.parent = $self;
}

As can be seen, entities have compositions with themselves of one-to-many cardinality. For example, a region can have multiple subregions. Each subregion (being a region) can also have several subregions, and so on.

The situation is the following:
For each of these entities, I need a service (a GET operation) that returns the "whole tree" (deep expansion). This is, for example in the case of regions, that the service returns the data for the region, all its subregions, the subregions of those subregions, and so on down to the "lowest" level (subregions that do not have other nested subregions ).

My specific questions are several:

How can I address this requirement?

What is the best way to solve it?

In principle, I need something like the $expand operator from OData services, but that works by "expanding" all the necessary levels (an unknown number of levels).

As far as I know, the $expand operator works with only one level of expansion (or a number of levels explicitly stated in the query), am I correct? Is there a way to do what I need just with the $expand operator?

I think that to solve this requirement I must implement a Custom Handler, however, I would like to know if it is possible, in such a custom handler, to use/invoke the generic handler. Is it possible?

The previous idea is inspired by Object-Oriented Programming, in which (in certain languages), in the "specialization" of a method in a subclass, the implementation of the same method belonging to the parent class can be invoked.

Thank you very much in advance for any help and/or suggestions regarding one or more of my questions.