Search in sources :

Example 6 with ReportMetadata

use of org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportMetadata in project camel by apache.

the class SalesforceReportResultsToListConverter method convertMatrixResults.

private static List<List<String>> convertMatrixResults(final AbstractReportResultsBase reportResults, Exchange exchange) {
    final ArrayList<List<String>> result = new ArrayList<List<String>>();
    final ReportMetadata reportMetadata = reportResults.getReportMetadata();
    final ReportExtendedMetadata reportExtendedMetadata = reportResults.getReportExtendedMetadata();
    final String[] aggregates = reportMetadata.getAggregates();
    final boolean includeDetails = reportResults.getHasDetailRows() && getOption(exchange, INCLUDE_DETAILS, Boolean.TRUE);
    final boolean includeSummary = aggregates.length > 0 && getOption(exchange, INCLUDE_SUMMARY, Boolean.TRUE);
    // column list, including grouping columns and details if required
    final ArrayList<DetailColumnInfo> columnInfos = new ArrayList<DetailColumnInfo>();
    final String[] columnNames = getResultColumns(columnInfos, reportMetadata, reportExtendedMetadata, includeDetails, includeSummary);
    // include detail headers?
    if (getOption(exchange, INCLUDE_HEADERS, Boolean.TRUE)) {
        addColumnHeaders(result, columnInfos);
    }
    // process down groups
    final GroupingValue[] groupingsDown = reportResults.getGroupingsDown().getGroupings();
    for (GroupingValue groupingValue : groupingsDown) {
        addMatrixGroupValues(result, reportResults, columnNames, groupingValue, EMPTY_STRING_LIST, includeDetails, includeSummary, EMPTY_VALUE, true);
    }
    // add grand total
    if (includeSummary) {
        final Map<String, ReportFactWithDetails> factMap = reportResults.getFactMap();
        // first add summary for across groups
        final List<String> downGroupsPrefix = new ArrayList<String>(Collections.nCopies(groupingsDown.length, EMPTY_VALUE));
        for (GroupingValue acrossGrouping : reportResults.getGroupingsAcross().getGroupings()) {
            addAcrossGroupSummaryValues(result, reportMetadata, includeDetails, columnNames, factMap, downGroupsPrefix, acrossGrouping);
        }
        final ReportFactWithDetails grandTotal = factMap.get("T!T");
        addSummaryValues(result, includeDetails, columnNames, EMPTY_STRING_LIST, reportResults.getReportMetadata().getAggregates(), grandTotal.getAggregates());
    }
    return result;
}
Also used : ReportFactWithDetails(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportFactWithDetails) ArrayList(java.util.ArrayList) DetailColumnInfo(org.apache.camel.component.salesforce.api.dto.analytics.reports.DetailColumnInfo) ReportExtendedMetadata(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportExtendedMetadata) ArrayList(java.util.ArrayList) List(java.util.List) GroupingValue(org.apache.camel.component.salesforce.api.dto.analytics.reports.GroupingValue) ReportMetadata(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportMetadata)

Aggregations

ReportMetadata (org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportMetadata)6 List (java.util.List)4 ArrayList (java.util.ArrayList)3 ReportExtendedMetadata (org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportExtendedMetadata)3 ReportFactWithDetails (org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportFactWithDetails)3 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)2 DetailColumnInfo (org.apache.camel.component.salesforce.api.dto.analytics.reports.DetailColumnInfo)2 GroupingValue (org.apache.camel.component.salesforce.api.dto.analytics.reports.GroupingValue)2 ReportInstance (org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportInstance)2 AnalyticsApiClient (org.apache.camel.component.salesforce.internal.client.AnalyticsApiClient)2 DefaultAnalyticsApiClient (org.apache.camel.component.salesforce.internal.client.DefaultAnalyticsApiClient)2 HashMap (java.util.HashMap)1 AbstractReportResultsBase (org.apache.camel.component.salesforce.api.dto.analytics.reports.AbstractReportResultsBase)1 AsyncReportResults (org.apache.camel.component.salesforce.api.dto.analytics.reports.AsyncReportResults)1 QueryRecordsReport (org.apache.camel.component.salesforce.api.dto.analytics.reports.QueryRecordsReport)1 Report (org.apache.camel.component.salesforce.api.dto.analytics.reports.Report)1 ReportDescription (org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportDescription)1 ReportRow (org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportRow)1 SyncReportResults (org.apache.camel.component.salesforce.api.dto.analytics.reports.SyncReportResults)1 Theory (org.junit.experimental.theories.Theory)1