Skip to content

Commit

Permalink
Aggregated measurables agg
Browse files Browse the repository at this point in the history
#CTCTOWALTZ-1967
finos#5107
  • Loading branch information
JWoodland-Scott committed Oct 5, 2020
1 parent 3438a4a commit 9d0ca27
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static com.khartec.waltz.common.DateTimeUtilities.toLocalDateTime;
import static com.khartec.waltz.model.EntityReference.mkRef;
import static com.khartec.waltz.schema.Tables.*;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.select;

@Repository
public class ReportGridDao {
Expand Down Expand Up @@ -144,7 +146,7 @@ private Set<ReportGridRatingCell> findCellDataByGridCondition(Condition gridCond
Condition condition = app.ID.in(appSelector)
.and(gridCondition);

SelectConditionStep<Record4<Long, Long, String, Long>> measurableData = dsl
SelectConditionStep<Record4<Long, Long, String, Long>> exactMeasurableData = dsl
.select(app.ID,
rgcd.COLUMN_ENTITY_ID,
DSL.value(EntityKind.MEASURABLE.name()).as("kind"),
Expand All @@ -156,7 +158,8 @@ private Set<ReportGridRatingCell> findCellDataByGridCondition(Condition gridCond
.innerJoin(rgcd).on(rgcd.COLUMN_ENTITY_ID.eq(m.ID)).and(rgcd.COLUMN_ENTITY_KIND.eq(DSL.val(EntityKind.MEASURABLE.name())))
.innerJoin(rg).on(rg.ID.eq(rgcd.REPORT_GRID_ID))
.innerJoin(rsi).on(rsi.CODE.eq(mr.RATING)).and(rsi.SCHEME_ID.eq(mc.RATING_SCHEME_ID))
.where(dsl.renderInlined(condition)); // jOOQ seems very slow when using simple `condition` (esp. for complex conditions). Inlined seems a lot faster
.where(dsl.renderInlined(condition))
.and(rgcd.DISPLAY_NAME.ne("agg")); // jOOQ seems very slow when using simple `condition` (esp. for complex conditions). Inlined seems a lot faster

SelectConditionStep<Record4<Long, Long, String, Long>> assessmentData = dsl
.select(app.ID,
Expand All @@ -171,17 +174,55 @@ private Set<ReportGridRatingCell> findCellDataByGridCondition(Condition gridCond
.innerJoin(rsi).on(rsi.ID.eq(ar.RATING_ID))
.where(dsl.renderInlined(condition)); // jOOQ seems very slow when using simple `condition` (esp. for complex conditions). Inlined seems a lot faster

return measurableData
SelectConditionStep<Record4<Long, Long, Long, Integer>> selectRatings = select(
MEASURABLE.ID,
MEASURABLE_RATING.ENTITY_ID,
RATING_SCHEME_ITEM.ID,
RATING_SCHEME_ITEM.POSITION)
.from(MEASURABLE)
.innerJoin(ENTITY_HIERARCHY).on(ENTITY_HIERARCHY.ANCESTOR_ID.eq(MEASURABLE.ID)
.and(ENTITY_HIERARCHY.KIND.eq(EntityKind.MEASURABLE.name())))
.innerJoin(MEASURABLE_RATING).on(MEASURABLE_RATING.MEASURABLE_ID.eq(ENTITY_HIERARCHY.ID))
.innerJoin(MEASURABLE_CATEGORY).on(MEASURABLE.MEASURABLE_CATEGORY_ID.eq(MEASURABLE_CATEGORY.ID))
.innerJoin(RATING_SCHEME_ITEM).on(MEASURABLE_RATING.RATING.eq(RATING_SCHEME_ITEM.CODE)
.and(RATING_SCHEME_ITEM.SCHEME_ID.eq(MEASURABLE_CATEGORY.RATING_SCHEME_ID)))
.where(MEASURABLE_RATING.ENTITY_KIND.eq(EntityKind.APPLICATION.name()));

CommonTableExpression<Record4<Long, Long, Long, Integer>> ratings = name("rating")
.fields("smid", "eid", "rid", "rp")
.as(selectRatings);

Table<Record4<Long, Long, Long, Integer>> r1 = ratings.as("r1");
Table<Record4<Long, Long, Long, Integer>> r2 = ratings.as("r2");

SelectConditionStep<Record4<Long, Long, String, Long>> aggregatedMeasurableData = dsl
.with(ratings)
.selectDistinct(
r1.field("eid", Long.class),
r1.field("smid", Long.class),
DSL.val(EntityKind.MEASURABLE.name()),
r1.field("rid", Long.class))
.from(r1)
.leftJoin(r2).on(r1.field("eid", Long.class).eq(r2.field("eid", Long.class))
.and(r1.field("smid", Long.class).eq(r2.field("smid", Long.class))
.and(r1.field("rp", Integer.class).gt(r2.field("rp", Integer.class)))))
.innerJoin(rgcd).on(rgcd.COLUMN_ENTITY_ID.eq(r1.field("smid", Long.class))
.and(rgcd.COLUMN_ENTITY_KIND.eq(DSL.val(EntityKind.MEASURABLE.name()))
.and(rgcd.DISPLAY_NAME.eq("agg"))))
.innerJoin(rg).on(rg.ID.eq(rgcd.REPORT_GRID_ID))
.where(r2.field("rid", Long.class).isNull()
.and(r1.field("eid", Long.class).in(appSelector)));

return aggregatedMeasurableData
.unionAll(assessmentData)
.unionAll(exactMeasurableData)
.fetchSet(r -> ImmutableReportGridRatingCell
.builder()
.applicationId(r.get(app.ID))
.columnEntityId(r.get(rgcd.COLUMN_ENTITY_ID))
.columnEntityKind(EntityKind.valueOf(r.get("kind", String.class)))
.ratingId(r.get(rsi.ID))
.applicationId(r.get(0, Long.class))
.columnEntityId(r.get(1, Long.class))
.columnEntityKind(EntityKind.valueOf(r.get(2, String.class)))
.ratingId(r.get(3, Long.class))
.build());
}


}

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div>

<h4 ng-if="!$ctrl.showPicker">
<h4>
<span ng-bind="$ctrl.selectedGrid.name"></span>
<span class="small">
<a class="clickable"
ng-click="$ctrl.showPicker = true">
Change report
ng-click="$ctrl.showPicker = !$ctrl.showPicker"
ng-bind="$ctrl.showPicker ? 'View current report' : 'Change report'">
</a>
</span>
</h4>
Expand All @@ -21,7 +21,8 @@ <h4 ng-if="!$ctrl.showPicker">
<waltz-report-grid-picker on-grid-select="$ctrl.onGridSelect">
</waltz-report-grid-picker>
</div>
<div class="waltz-sub-section-controls">
<div class="waltz-sub-section-controls"
ng-if="$ctrl.selectedGrid">
<a ng-click="$ctrl.showPicker = false"
class="clickable">
Close
Expand All @@ -33,9 +34,10 @@ <h4 ng-if="!$ctrl.showPicker">
</div>

<!-- GRID & FILTERS -->
<waltz-report-grid-view-panel parent-entity-ref="$ctrl.parentEntityRef"
grid-id="$ctrl.selectedGrid.id">
</waltz-report-grid-view-panel>

<div ng-if="$ctrl.selectedGrid">
<waltz-report-grid-view-panel parent-entity-ref="$ctrl.parentEntityRef"
grid-id="$ctrl.selectedGrid.id">
</waltz-report-grid-view-panel>
</div>
</div>

Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
import template from "./report-grid-view-section.html";
import {initialiseData} from "../../../common";
import {CORE_API} from "../../../common/services/core-api-utils";
import * as _ from "lodash";

const bindings = {
parentEntityRef: "<"
};

const initData = {
gridId: 1,
showPicker: false
};

function controller(serviceBroker) {
const localStorageKey = "waltz-report-grid-view-section-last-id";

function controller(serviceBroker, localStorageService) {

const vm = initialiseData(this, initData);

vm.$onChanges = () => {
const lastUsedGridId = localStorageService.get(localStorageKey);

if (_.isNil(lastUsedGridId)){
vm.showPicker = true;
} else {
serviceBroker
.loadViewData(CORE_API.ReportGridStore.findAll)
.then(r => {
vm.selectedGrid = _.find(r.data, d => d.id === lastUsedGridId);
if (!vm.selectedGrid){
vm.showPicker = true;
}
})
}
};

vm.onGridSelect = (grid) => {
localStorageService.set(localStorageKey, grid.id);
vm.selectedGrid = grid;
vm.showPicker = false;
};
}

controller.$inject = ["ServiceBroker"];
controller.$inject = [
"ServiceBroker",
"localStorageService"
];

const component = {
controller,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="col-sm-6">
<waltz-no-data>
<message>
You have no report grids.
There are no report grids
</message>
</waltz-no-data>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function controller(serviceBroker) {

vm.$onChanges = () => {
serviceBroker
.loadAppData(CORE_API.ReportGridStore.findAll)
.loadViewData(CORE_API.ReportGridStore.findAll)
.then(r => vm.grids = r.data);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,88 @@
<div>

<!-- NO SUMMARIES -->
<waltz-no-data class="small"
ng-if="$ctrl.chunkedSummaryData.length == 0">
<message>
<strong>No summaries selected</strong>
<p>
There are no active summaries. To add one select the
'Add to summary' option in the column drop down menu.
Once added you can select summary rows to quickly filter
the report.
</p>
</message>
</waltz-no-data>

<waltz-loading-notification show="$ctrl.loading"
name="Loading grid data">
</waltz-loading-notification>

<!-- HELP -->
<p ng-if="$ctrl.chunkedSummaryData.length > 0"
class="help-block small">
Select a value in the summary tables to quickly filter the data.
Select the row again to clear the filter.
You can add more summaries using the column menu ('Add to summary').
</p>
<div ng-if="!$ctrl.loading">

<!-- NO SUMMARIES -->
<waltz-no-data class="small"
ng-if="$ctrl.chunkedSummaryData.length == 0">
<message>
<strong>No summaries selected</strong>
<p>
There are no active summaries. To add one select the
'Add to summary' option in the column drop down menu.
Once added you can select summary rows to quickly filter
the report.
</p>
</message>
</waltz-no-data>

<!-- SUMMARIES -->
<div class="row small"
ng-repeat="row in $ctrl.chunkedSummaryData">
<div ng-repeat="summary in row" class="col-sm-3">
<h5 class="waltz-visibility-parent">
<span ng-bind="summary.column.columnEntityReference.name"></span>
<a ng-click="$ctrl.onRemoveSummary(summary)"
class="waltz-visibility-child-30 clickable pull-right">
<waltz-icon name="close"></waltz-icon>
</a>
</h5>
<table class="table table-condensed small">
<tbody>
<tr ng-repeat="counter in summary.counters"
class="clickable"
ng-class="{ 'waltz-highlighted-row' : $ctrl.isSelectedCounter(counter.counterId) }"
ng-click="$ctrl.onToggleFilter(counter)">
<td>
<div style="display: inline-block; height: 10px; width: 10px;"
ng-style="{ 'background-color': counter.rating.color }">
</div>
<span ng-bind="counter.rating.name"
uib-popover="{{counter.rating.description}}"
popover-popup-delay="300"
popover-append-to-body="true"
popover-trigger="mouseenter">

<!-- HELP -->
<p ng-if="$ctrl.chunkedSummaryData.length > 0"
class="help-block small">
Select a value in the summary tables to quickly filter the data.
Select the row again to clear the filter.
You can add more summaries using the column menu ('Add to summary').
</p>


<!-- SUMMARIES -->
<div class="row small"
ng-repeat="row in $ctrl.chunkedSummaryData">
<div ng-repeat="summary in row" class="col-sm-3">
<h5 class="waltz-visibility-parent">
<span ng-bind="summary.column.columnEntityReference.name"></span>
<a ng-click="$ctrl.onRemoveSummary(summary)"
class="waltz-visibility-child-30 clickable pull-right">
<waltz-icon name="close"></waltz-icon>
</a>
</h5>
<table class="table table-condensed small">
<tbody>
<tr ng-repeat="counter in summary.counters"
class="clickable"
ng-class="{ 'waltz-highlighted-row' : $ctrl.isSelectedCounter(counter.counterId) }"
ng-click="$ctrl.onToggleFilter(counter)">
<td>
<div style="display: inline-block; height: 10px; width: 10px;"
ng-style="{ 'background-color': counter.rating.color }">
</div>
<span ng-bind="counter.rating.name"
uib-popover="{{counter.rating.description}}"
popover-popup-delay="300"
popover-append-to-body="true"
popover-trigger="mouseenter">
</span>
</td>
<td class="text-right"><span ng-bind="counter.count"></span></td>
</tr>
</tbody>
<tbody>
<tr>
<td>
<b>Total</b>
</td>
<td class="text-right">
<span ng-bind="summary.total"></span>
</td>
</tr>
</tbody>
</table>
</td>
<td class="text-right"><span ng-bind="counter.count"></span></td>
</tr>
</tbody>
<tbody>
<tr>
<td>
<b>Total</b>
</td>
<td class="text-right">
<span ng-bind="summary.total"></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>


<!-- GRID -->
<waltz-grid-with-search column-defs="$ctrl.columnDefs"
entries="$ctrl.tableData"
class="small">
</waltz-grid-with-search>
<!-- GRID -->
<waltz-grid-with-search column-defs="$ctrl.columnDefs"
entries="$ctrl.tableData"
class="small">
</waltz-grid-with-search>
</div>

</div>

Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,14 @@ function controller(serviceBroker) {

vm.$onChanges = () => {
if (! vm.parentEntityRef) return;

vm.loading = true;
serviceBroker
.loadViewData(
CORE_API.ReportGridStore.getViewById,
[vm.gridId, mkSelectionOptions(vm.parentEntityRef)])
.then(r => {
vm.loading = false;
vm.rawGridData = r.data;
vm.allTableData = prepareTableData(vm.rawGridData);
vm.allColumnDefs = prepareColumnDefs(vm.rawGridData);
Expand Down

0 comments on commit 9d0ca27

Please sign in to comment.