Skip to content

Commit

Permalink
Report grid update columns, permissions, picker/edit views combined
Browse files Browse the repository at this point in the history
#CTCTOWALTZ-2376
finos#5682
  • Loading branch information
jessica-woodland-scott-db authored and ljubon committed Dec 7, 2021
1 parent 764192a commit 3c5ef20
Show file tree
Hide file tree
Showing 26 changed files with 671 additions and 211 deletions.
11 changes: 11 additions & 0 deletions waltz-data/src/main/ddl/liquibase/db.changelog-1.39.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,15 @@
tableName="report_grid_member"/>
</changeSet>

<changeSet author="woodjes"
id="20211203-5682-3">
<addColumn tableName="report_grid">
<column name="kind"
type="${enum.type}"
defaultValue="PUBLIC">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ public Set<ReportGridDefinition> findForUser(String username){
return dsl
.select(rg.fields())
.from(rg)
.innerJoin(REPORT_GRID_MEMBER).on(rg.ID.eq(REPORT_GRID_MEMBER.GRID_ID))
.where(REPORT_GRID_MEMBER.USER_ID.eq(username))
.leftJoin(REPORT_GRID_MEMBER)
.on(rg.ID.eq(REPORT_GRID_MEMBER.GRID_ID))
.where(rg.KIND.eq(ReportGridKind.PUBLIC.name()).or(REPORT_GRID_MEMBER.USER_ID.eq(username)))
.fetchSet(r -> mkReportGridDefinition(rgcd.REPORT_GRID_ID.eq(r.get(rg.ID)), r.into(REPORT_GRID)));
}

Expand Down Expand Up @@ -165,12 +166,25 @@ public long create(ReportGridCreateCommand createCommand, String username) {
record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
record.setLastUpdatedBy(username);
record.setProvenance("waltz");
record.setKind(createCommand.kind().name());

int insert = record.insert();

return record.getId();
}

public long update(long id, ReportGridUpdateCommand updateCommand, String username) {
return dsl
.update(rg)
.set(rg.NAME, updateCommand.name())
.set(rg.DESCRIPTION, updateCommand.description())
.set(rg.KIND, updateCommand.kind().name())
.set(rg.LAST_UPDATED_AT, DateTimeUtilities.nowUtcTimestamp())
.set(rg.LAST_UPDATED_BY, username)
.where(rg.ID.eq(id))
.execute();
}

// --- Helpers ---

private ReportGridDefinition getGridDefinitionByCondition(Condition condition) {
Expand Down Expand Up @@ -271,50 +285,56 @@ private Set<ReportGridCell> findCellDataByGridCondition(Condition gridCondition,

ReportGridDefinition gridDefn = getGridDefinitionByCondition(gridCondition);

Map<EntityKind, Collection<ReportGridColumnDefinition>> colsByKind = groupBy(
gridDefn.columnDefinitions(),
cd -> cd.columnEntityReference().kind());
if(gridDefn == null ){
return emptySet();

Set<Long> requiredAssessmentDefinitions = map(
colsByKind.getOrDefault(EntityKind.ASSESSMENT_DEFINITION, emptySet()),
cd -> cd.columnEntityReference().id());
} else {

Map<EntityKind, Collection<ReportGridColumnDefinition>> colsByKind = groupBy(
gridDefn.columnDefinitions(),
cd -> cd.columnEntityReference().kind());

Map<RatingRollupRule, Collection<ReportGridColumnDefinition>> measurableColumnsByRollupKind = groupBy(
colsByKind.getOrDefault(EntityKind.MEASURABLE, emptySet()),
ReportGridColumnDefinition::ratingRollupRule);
Set<Long> requiredAssessmentDefinitions = map(
colsByKind.getOrDefault(EntityKind.ASSESSMENT_DEFINITION, emptySet()),
cd -> cd.columnEntityReference().id());

Set<Long> exactMeasurableIds = map(
measurableColumnsByRollupKind.get(RatingRollupRule.NONE),
cd -> cd.columnEntityReference().id());
Map<RatingRollupRule, Collection<ReportGridColumnDefinition>> measurableColumnsByRollupKind = groupBy(
colsByKind.getOrDefault(EntityKind.MEASURABLE, emptySet()),
ReportGridColumnDefinition::ratingRollupRule);

Set<Long> summaryMeasurableIdsUsingHighest = map(
measurableColumnsByRollupKind.get(RatingRollupRule.PICK_HIGHEST),
cd -> cd.columnEntityReference().id());
Set<Long> exactMeasurableIds = map(
measurableColumnsByRollupKind.get(RatingRollupRule.NONE),
cd -> cd.columnEntityReference().id());

Set<Long> summaryMeasurableIdsUsingLowest = map(
measurableColumnsByRollupKind.get(RatingRollupRule.PICK_LOWEST),
cd -> cd.columnEntityReference().id());
Set<Long> summaryMeasurableIdsUsingHighest = map(
measurableColumnsByRollupKind.get(RatingRollupRule.PICK_HIGHEST),
cd -> cd.columnEntityReference().id());

Set<Long> requiredCostKinds = map(
colsByKind.getOrDefault(EntityKind.COST_KIND, emptySet()),
cd -> cd.columnEntityReference().id());
Set<Long> summaryMeasurableIdsUsingLowest = map(
measurableColumnsByRollupKind.get(RatingRollupRule.PICK_LOWEST),
cd -> cd.columnEntityReference().id());

Set<Long> requiredInvolvementKinds = map(
colsByKind.getOrDefault(EntityKind.INVOLVEMENT_KIND, emptySet()),
cd -> cd.columnEntityReference().id());
Set<Long> requiredCostKinds = map(
colsByKind.getOrDefault(EntityKind.COST_KIND, emptySet()),
cd -> cd.columnEntityReference().id());

Set<Long> requiredSurveyQuestionIds = map(
colsByKind.getOrDefault(EntityKind.SURVEY_QUESTION, emptySet()),
cd -> cd.columnEntityReference().id());
Set<Long> requiredInvolvementKinds = map(
colsByKind.getOrDefault(EntityKind.INVOLVEMENT_KIND, emptySet()),
cd -> cd.columnEntityReference().id());

Set<Long> requiredSurveyQuestionIds = map(
colsByKind.getOrDefault(EntityKind.SURVEY_QUESTION, emptySet()),
cd -> cd.columnEntityReference().id());

return union(
fetchSummaryMeasurableData(appSelector, summaryMeasurableIdsUsingHighest, summaryMeasurableIdsUsingLowest),
fetchAssessmentData(appSelector, requiredAssessmentDefinitions),
fetchExactMeasurableData(appSelector, exactMeasurableIds),
fetchCostData(appSelector, requiredCostKinds),
fetchInvolvementData(appSelector, requiredInvolvementKinds),
fetchSurveyQuestionResponseData(appSelector, requiredSurveyQuestionIds));

return union(
fetchSummaryMeasurableData(appSelector, summaryMeasurableIdsUsingHighest, summaryMeasurableIdsUsingLowest),
fetchAssessmentData(appSelector, requiredAssessmentDefinitions),
fetchExactMeasurableData(appSelector, exactMeasurableIds),
fetchCostData(appSelector, requiredCostKinds),
fetchInvolvementData(appSelector, requiredInvolvementKinds),
fetchSurveyQuestionResponseData(appSelector, requiredSurveyQuestionIds));
}
}


Expand Down Expand Up @@ -642,7 +662,22 @@ private ImmutableReportGridDefinition mkReportGridDefinition(Condition condition
.lastUpdatedAt(toLocalDateTime(r.get(rg.LAST_UPDATED_AT)))
.lastUpdatedBy(r.get(rg.LAST_UPDATED_BY))
.columnDefinitions(getColumnDefinitions(condition))
.kind(ReportGridKind.valueOf(r.get(rg.KIND)))
.build();
}


public Set<ReportGridDefinition> findForOwner(String username) {
Condition isOwner = REPORT_GRID_MEMBER.USER_ID.eq(username)
.and(REPORT_GRID_MEMBER.ROLE.eq(ReportGridMemberRole.OWNER.name()));

return dsl
.select(rg.fields())
.from(rg)
.innerJoin(REPORT_GRID_MEMBER)
.on(rg.ID.eq(REPORT_GRID_MEMBER.GRID_ID))
.where(isOwner)
.fetchSet(r -> mkReportGridDefinition(rgcd.REPORT_GRID_ID.eq(r.get(rg.ID)), r.into(REPORT_GRID)));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.RecordMapper;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -61,5 +62,23 @@ public Set<ReportGridMember> findByGridId(Long gridId){
.fetchSet(TO_DOMAIN_MAPPER);
}

public int register(long gridId, String username, ReportGridMemberRole role) {
return dsl
.insertInto(REPORT_GRID_MEMBER)
.set(REPORT_GRID_MEMBER.GRID_ID, gridId)
.set(REPORT_GRID_MEMBER.USER_ID, username)
.set(REPORT_GRID_MEMBER.ROLE, role.name())
.execute();
}

public boolean canUpdate(long gridId, String userId) {
return dsl
.fetchExists(DSL
.select(REPORT_GRID_MEMBER.GRID_ID)
.from(REPORT_GRID_MEMBER)
.where(REPORT_GRID_MEMBER.GRID_ID.eq(gridId)
.and(REPORT_GRID_MEMBER.USER_ID.eq(userId)
.and(REPORT_GRID_MEMBER.ROLE.eq(ReportGridMemberRole.OWNER.name())))));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public abstract class ReportGridCreateCommand implements Command {

@Nullable
public abstract String description();

@Value.Default
public ReportGridKind kind(){
return ReportGridKind.PUBLIC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ public abstract class ReportGridDefinition implements

public abstract List<ReportGridColumnDefinition> columnDefinitions(); // columns


@Value.Default
public ReportGridKind kind(){
return ReportGridKind.PUBLIC;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.finos.waltz.model.report_grid;

public enum ReportGridKind {
PUBLIC,
PRIVATE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.finos.waltz.model.report_grid;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.waltz.model.IdProvider;
import org.finos.waltz.model.Nullable;
import org.finos.waltz.model.command.Command;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableReportGridUpdateCommand.class)
@JsonDeserialize(as = ImmutableReportGridUpdateCommand.class)
public abstract class ReportGridUpdateCommand implements Command {

public abstract String name();

@Nullable
public abstract String description();

@Value.Default
public ReportGridKind kind(){
return ReportGridKind.PUBLIC;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<div>
<!-- GRID & FILTERS -->
<div ng-if="$ctrl.selectedGrid"
style="padding-top: 0.5em;">
<waltz-report-grid-view-panel parent-entity-ref="$ctrl.parentEntityRef">
</waltz-report-grid-view-panel>
</div>
<waltz-report-grid-view-panel parent-entity-ref="$ctrl.parentEntityRef">
</waltz-report-grid-view-panel>
</div>

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import _ from "lodash";
import ReportGridControlPanel from "../svelte/ReportGridControlPanel.svelte";
import {activeSummaryColRefs, filters, selectedGrid, columnDefs} from "../svelte/report-grid-store";
import {mkPropNameForRef, mkRowFilter, prepareColumnDefs, prepareTableData} from "../svelte/report-grid-utils";
import {displayError} from "../../../common/error-utils";

const bindings = {
parentEntityRef: "<",
Expand Down Expand Up @@ -72,7 +73,6 @@ function controller($scope, serviceBroker, localStorageService) {
CORE_API.ReportGridStore.getViewById,
[vm.gridId, mkSelectionOptions(vm.parentEntityRef)], {force: true})
.then(r => {
// vm.filters = [];
vm.loading = false;
vm.rawGridData = r.data;

Expand All @@ -82,6 +82,9 @@ function controller($scope, serviceBroker, localStorageService) {
vm.allTableData = prepareTableData(vm.rawGridData);
vm.allColumnDefs = prepareColumnDefs(vm.rawGridData);
refresh();
})
.catch(e => {
displayError("Could not load grid data for id: " + vm.gridId, e)
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,35 @@
import ReportGridOverview from "./ReportGridOverview.svelte";
import ReportGridFilters from "./ReportGridFilters.svelte";
import ColumnDefinitionEditPanel from "./column-definition-edit-panel/ColumnDefinitionEditPanel.svelte";
import {selectedGrid} from "./report-grid-store";
import {selectedGrid, ownedReportIds} from "./report-grid-store";
import {reportGridStore} from "../../../svelte-stores/report-grid-store";
import _ from "lodash";
import Icon from "../../../common/svelte/Icon.svelte";
export let onGridSelect = () => console.log("selecting grid");
export let onSave = () => console.log("Saved report grid");
let selectedTab = "context"
let selectedTab = "overview"
$: isOwned = $selectedGrid && _.includes($ownedReportIds, $selectedGrid.definition?.id);
$: ownedGridsCall = $selectedGrid.definition.id && reportGridStore.findForOwner(true);
$: $ownedReportIds = _.map($ownedGridsCall?.data, d => d.id);
</script>
<div class="waltz-tabs" style="padding-top: 1em">
<!-- TAB HEADERS -->
<input type="radio"
bind:group={selectedTab}
value="context"
id="context">
value="overview"
id="overview">
<label class="wt-label"
for="context">
<span>Context</span>
for="overview">
<span>
Overview
</span>
</label>
<input type="radio"
Expand All @@ -29,22 +41,27 @@
id="filters">
<label class="wt-label"
for="filters">
<span>Filters</span>
<span>
Filters
</span>
</label>
<input type="radio"
bind:group={selectedTab}
disabled={!$selectedGrid}
disabled={!isOwned}
value="columns"
id="columns">
<label class="wt-label"
for="columns">
<span>Columns</span>
<span title={isOwned ? "" : "You are not an owner for this report grid"}>
Column Editor
<Icon name={isOwned ? "unlock" : "lock"}/>
</span>
</label>
<div class="wt-tab wt-active">
<!-- SERVERS -->
{#if selectedTab === 'context'}
{#if selectedTab === 'overview'}
<ReportGridOverview {onGridSelect}/>
{:else if selectedTab === 'filters'}
<ReportGridFilters/>
Expand Down
Loading

0 comments on commit 3c5ef20

Please sign in to comment.