cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CAP Java: OData V2 Aggregation for SAPUI5 SmartTable (AnalyticalTable)

hasanciftci
Explorer
454

Hello,

I have a freestyle SAPUI5 application which consumes an OData V2 service which I develop using CAP Java with 

cds-adapter-odata-v2 adapter and my SAPUI5 app has a SmartTable with AnalyticalTable type to use the grouping and aggregation features. The AnalyticalBinding sends a request to the OData service to fetch grand total (aggregated results) of the properties annotated as "measure".

I have a similar application which works fine with CAP Node.js because the Node.js stack can return the aggregated result requested by the AnalyticalBinding.

The request sent by the AnalyticalBinding looks like the following:

/odata/v2/my-service/MyEntitySet?$select=myMeasureProp1&$inlinecount=allpages

I believe CAP Node.js framework interprets this request by checking the "@sap.aggregation.role" annotation and returns the aggregated result (sum in my case). However, CAP Java does not return the aggregated result, instead it returns all the entities individually containing the myMeasureProp1.

Here is an example response of CAP Node.js. It has only a single entity with the aggregated numbers. 

{
   "d":{
      "results":[
         {
            "__metadata":{
               "type":"Reporting.VAnalytics",
               "uri":"https://myhost.com/odata/v2/reporting/VAnalytics(aggregation'{\"key\":{},\"value\":[\"bookingHour\",\"nonApprovedHour\"]}')"
            },
            "bookingHour":"516899.1",
            "nonApprovedHour":"5303",
            "ID__":"aggregation'{\"key\":{},\"value\":[\"bookingHour\",\"nonApprovedHour\"]}'"
         }
      ],
      "__count":"1"
   }
}


I believe Java stack does not interpret the "@sap.aggregation.role" annotation. I checked the documentations and could not find anything useful. 

I'd appreciate any help on how to achieve using SmartTable with AnalyticalTable type consuming an OData V2 service provided by CAP Java.

Annotations:

annotate ReportingCenter.Analytics with @(sap.semantics: 'aggregate');

annotate ReportingCenter.Analytics with {
    employeeTeamID .aggregation.role: 'dimension';
    employeeID     .aggregation.role: 'dimension';
    projectID      .aggregation.role: 'dimension';
    projectTeamID  .aggregation.role: 'dimension';
    hours          .aggregation.role: 'measure';
};

annotate ReportingCenter.Analytics with @(UI: {PresentationVariant: {
    $Type         : 'UI.PresentationVariantType',
    Total         : [hours],
    GroupBy       : [
        employeeTeamID,
        employeeID,
        projectID
    ],
    Visualizations: ['@UI.LineItem']
}});


EDIT: I have also tried with the following annotations. They work fine with OData V4 using $apply query but my service is V2 since SAPUI5 smart controls are only supported for OData V2.

using ReportingCenter from '../../../../srv/cds-models/analytics';
using from './line-item';

annotate ReportingCenter.Analytics with @(sap.semantics: 'aggregate');

annotate ReportingCenter.Analytics with {
    employeeTeamID  @Pa_Vi.aggregation.role: 'dimension'  @analytics.Dimension;
    employeeID      @Pa_Vi.aggregation.role: 'dimension'  @analytics.Dimension;
    projectID       @Pa_Vi.aggregation.role: 'dimension'  @analytics.Dimension;
    projectTeamID   @Pa_Vi.aggregation.role: 'dimension'  @analytics.Dimension;
    hours           @Pa_Vi.aggregation.role: 'measure'    @analytics.Measure;
};

annotate ReportingCenter.Analytics with @(UI: {PresentationVariant: {
    $Type         : 'UI.PresentationVariantType',
    Total         : [hours],
    GroupBy       : [
        employeeTeamID,
        employeeID
    ],
    Visualizations: ['@UI.LineItem']
}});

annotate ReportingCenter.Analytics with @(Aggregation: {ApplySupported: {
    $Type                 : 'Aggregation.ApplySupportedType',
    Transformations       : [
        'aggregate',
        'identity',
        'groupby',
        'filter',
        'search'
    ],
    GroupableProperties   : [
        employeeTeamID,
        employeeID,
        projectID,
        projectTeamID
    ],
    AggregatableProperties: [{
        $Type   : 'Aggregation.AggregatablePropertyType',
        Property: hours
    }]
}});

annotate ReportingCenter.Analytics with @(Analytics.AggregatedProperty #sumHours: {
    $Type               : 'Analytics.AggregatedPropertyType',
    Name                : 'sumHours',
    AggregationMethod   : 'sum',
    AggregatableProperty: hours
});



Accepted Solutions (0)

Answers (0)