Search in sources :

Example 1 with GroupingValue

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

the class SalesforceReportResultsToListConverter method convertSummaryResults.

private static List<List<String>> convertSummaryResults(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
    for (GroupingValue groupingValue : reportResults.getGroupingsDown().getGroupings()) {
        addSummaryGroupValues(result, reportResults, columnNames, groupingValue, EMPTY_STRING_LIST, includeDetails, includeSummary);
    }
    // add grand total
    if (includeSummary) {
        final ReportFactWithDetails grandTotal = reportResults.getFactMap().get("T!T");
        addSummaryValues(result, includeDetails, columnNames, EMPTY_STRING_LIST, aggregates, grandTotal.getAggregates());
    }
    return result;
}
Also used : ReportExtendedMetadata(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportExtendedMetadata) ReportFactWithDetails(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportFactWithDetails) ArrayList(java.util.ArrayList) 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) DetailColumnInfo(org.apache.camel.component.salesforce.api.dto.analytics.reports.DetailColumnInfo)

Example 2 with GroupingValue

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

the class SalesforceReportResultsToListConverter method addAcrossGroupSummaryValues.

private static void addAcrossGroupSummaryValues(ArrayList<List<String>> result, ReportMetadata reportMetadata, boolean includeDetails, String[] columnNames, Map<String, ReportFactWithDetails> factMap, List<String> downGroupsPrefix, GroupingValue acrossGrouping) {
    final List<String> newDownGroupsPrefix = new ArrayList<String>(downGroupsPrefix);
    newDownGroupsPrefix.add(acrossGrouping.getLabel());
    addSummaryValues(result, includeDetails, columnNames, newDownGroupsPrefix, reportMetadata.getAggregates(), factMap.get("T!" + acrossGrouping.getKey()).getAggregates());
    // process across subgroups
    for (GroupingValue subGroup : acrossGrouping.getGroupings()) {
        addAcrossGroupSummaryValues(result, reportMetadata, includeDetails, columnNames, factMap, newDownGroupsPrefix, subGroup);
    }
}
Also used : ArrayList(java.util.ArrayList) GroupingValue(org.apache.camel.component.salesforce.api.dto.analytics.reports.GroupingValue)

Example 3 with GroupingValue

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

the class SalesforceReportResultsToListConverter method addMatrixGroupValues.

private static void addMatrixGroupValues(ArrayList<List<String>> result, AbstractReportResultsBase reportResults, String[] columnNames, GroupingValue groupingValue, List<String> rowPrefix, boolean includeDetails, boolean includeSummary, String keyPrefix, boolean downGroup) {
    final String groupKey = groupingValue.getKey();
    final String newKeyPrefix = keyPrefix + groupKey;
    // group values prefix
    final List<String> newPrefix = new ArrayList<String>(rowPrefix);
    newPrefix.add(groupingValue.getLabel());
    final GroupingValue[] groupings = groupingValue.getGroupings();
    // has subgroups?
    if (groupings.length > 0) {
        for (GroupingValue subGroup : groupings) {
            addMatrixGroupValues(result, reportResults, columnNames, subGroup, newPrefix, includeDetails, includeSummary, newKeyPrefix + "_", downGroup);
        }
    // process across groupings?
    } else if (downGroup) {
        for (GroupingValue acrossGroup : reportResults.getGroupingsAcross().getGroupings()) {
            addMatrixGroupValues(result, reportResults, columnNames, acrossGroup, newPrefix, includeDetails, includeSummary, newKeyPrefix + "!", false);
        }
    // add lowest level across group detail rows?
    } else if (includeDetails) {
        addDetailRows(result, newPrefix, reportResults.getFactMap().get(newKeyPrefix));
    // add group columns only at lowest across level?
    } else if (!includeSummary) {
        result.add(newPrefix);
    }
    // add summary values for down group or lowest level across group
    if (includeSummary) {
        final String summaryKey = getGroupTotalKey(keyPrefix, downGroup, groupKey);
        addSummaryValues(result, includeDetails, columnNames, newPrefix, reportResults.getReportMetadata().getAggregates(), reportResults.getFactMap().get(summaryKey).getAggregates());
    }
}
Also used : ArrayList(java.util.ArrayList) GroupingValue(org.apache.camel.component.salesforce.api.dto.analytics.reports.GroupingValue)

Example 4 with GroupingValue

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

the class SalesforceReportResultsToListConverter method addSummaryGroupValues.

private static void addSummaryGroupValues(ArrayList<List<String>> result, AbstractReportResultsBase reportResults, String[] columnNames, GroupingValue groupingValue, List<String> rowPrefix, boolean includeDetails, boolean includeSummary) {
    // get fact map at this level
    final ReportFactWithDetails factWithDetails = reportResults.getFactMap().get(groupingValue.getKey() + "!T");
    final List<String> newPrefix = new ArrayList<String>(rowPrefix);
    newPrefix.add(groupingValue.getLabel());
    // more groups?
    final GroupingValue[] groupings = groupingValue.getGroupings();
    if (groupings.length > 0) {
        for (GroupingValue subGroup : groupings) {
            addSummaryGroupValues(result, reportResults, columnNames, subGroup, newPrefix, includeDetails, includeSummary);
        }
    // add lowest level group detail rows?
    } else if (includeDetails) {
        addDetailRows(result, newPrefix, factWithDetails);
    // add group columns only at lowest level?
    } else if (!includeSummary) {
        result.add(newPrefix);
    }
    if (includeSummary) {
        final SummaryValue[] summaryValues = factWithDetails.getAggregates();
        final String[] aggregates = reportResults.getReportMetadata().getAggregates();
        addSummaryValues(result, includeDetails, columnNames, newPrefix, aggregates, summaryValues);
    }
}
Also used : ReportFactWithDetails(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportFactWithDetails) ArrayList(java.util.ArrayList) SummaryValue(org.apache.camel.component.salesforce.api.dto.analytics.reports.SummaryValue) GroupingValue(org.apache.camel.component.salesforce.api.dto.analytics.reports.GroupingValue)

Example 5 with GroupingValue

use of org.apache.camel.component.salesforce.api.dto.analytics.reports.GroupingValue 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

ArrayList (java.util.ArrayList)5 GroupingValue (org.apache.camel.component.salesforce.api.dto.analytics.reports.GroupingValue)5 ReportFactWithDetails (org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportFactWithDetails)3 List (java.util.List)2 DetailColumnInfo (org.apache.camel.component.salesforce.api.dto.analytics.reports.DetailColumnInfo)2 ReportExtendedMetadata (org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportExtendedMetadata)2 ReportMetadata (org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportMetadata)2 SummaryValue (org.apache.camel.component.salesforce.api.dto.analytics.reports.SummaryValue)1