From 5af3791854a0453d3f5cda4670658e211c5ca9ac Mon Sep 17 00:00:00 2001 From: "david.watkins@db.com" Date: Fri, 17 Nov 2023 17:30:13 +0000 Subject: [PATCH] BUG: Export Measurable ratings seems to overfetch data - added new extractor endpoint for allocations/measurables #CTCTOWALTZ-2964 #6870 --- .../measurable-rating-explorer-section.html | 4 +- .../extracts/AllocationsExtractor.java | 68 +++++++++++++++---- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/waltz-ng/client/measurable-rating/components/explorer-section/measurable-rating-explorer-section.html b/waltz-ng/client/measurable-rating/components/explorer-section/measurable-rating-explorer-section.html index d1d3ed1ee7..e3ffbedcd9 100644 --- a/waltz-ng/client/measurable-rating/components/explorer-section/measurable-rating-explorer-section.html +++ b/waltz-ng/client/measurable-rating/components/explorer-section/measurable-rating-explorer-section.html @@ -68,8 +68,8 @@ diff --git a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/extracts/AllocationsExtractor.java b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/extracts/AllocationsExtractor.java index e9eebb386c..fd1c5c2cd4 100644 --- a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/extracts/AllocationsExtractor.java +++ b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/extracts/AllocationsExtractor.java @@ -28,14 +28,25 @@ import org.jooq.Record; import org.jooq.Record1; import org.jooq.Record2; -import org.jooq.Select; import org.jooq.SelectConditionStep; import org.jooq.SelectSelectStep; import org.jooq.impl.DSL; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import static org.finos.waltz.schema.Tables.*; +import java.util.Optional; + +import static org.finos.waltz.schema.Tables.ALLOCATION; +import static org.finos.waltz.schema.Tables.ALLOCATION_SCHEME; +import static org.finos.waltz.schema.Tables.APPLICATION; +import static org.finos.waltz.schema.Tables.ENTITY_HIERARCHY; +import static org.finos.waltz.schema.Tables.MEASURABLE; +import static org.finos.waltz.schema.Tables.MEASURABLE_CATEGORY; +import static org.finos.waltz.schema.Tables.MEASURABLE_RATING; +import static org.finos.waltz.schema.Tables.ORGANISATIONAL_UNIT; +import static org.finos.waltz.schema.Tables.RATING_SCHEME_ITEM; +import static org.finos.waltz.web.WebUtilities.mkPath; +import static spark.Spark.get; import static spark.Spark.post; @@ -54,9 +65,10 @@ public AllocationsExtractor(DSLContext dsl) { @Override public void register() { - registerExtractForAll( WebUtilities.mkPath("data-extract", "allocations", "all")); - registerExtractForCategory( WebUtilities.mkPath("data-extract", "allocations", "measurable-category", ":measurableCategoryId")); - registerExtractForScheme( WebUtilities.mkPath("data-extract", "allocations", "allocation-scheme", ":schemeId")); + registerExtractForAll(mkPath("data-extract", "allocations", "all")); + registerExtractForCategory(mkPath("data-extract", "allocations", "measurable-category", ":measurableCategoryId")); + registerExtractForMeasurable(mkPath("data-extract", "allocations", "measurable", ":id")); + registerExtractForScheme(mkPath("data-extract", "allocations", "allocation-scheme", ":schemeId")); } @@ -65,7 +77,7 @@ private void registerExtractForAll(String path) { IdSelectionOptions idSelectionOptions = WebUtilities.readIdSelectionOptionsFromBody(request); SelectConditionStep qry = prepareQuery( DSL.trueCondition(), - idSelectionOptions); + Optional.of(idSelectionOptions)); return writeExtract( "all_allocations", @@ -76,6 +88,34 @@ private void registerExtractForAll(String path) { } + private void registerExtractForMeasurable(String path) { + get(path, (request, response) -> { + + long measurableId = WebUtilities.getId(request); + + Record1 fileName = dsl + .select(DSL.concat(MEASURABLE.NAME, "_all_allocations")) + .from(MEASURABLE) + .where(MEASURABLE.ID.eq(measurableId)) + .fetchOne(); + + SelectConditionStep qry = prepareQuery( + MEASURABLE.ID.in(DSL + .select(ENTITY_HIERARCHY.ID) + .from(ENTITY_HIERARCHY) + .where(ENTITY_HIERARCHY.KIND.eq(EntityKind.MEASURABLE.name()) + .and(ENTITY_HIERARCHY.ANCESTOR_ID.eq(measurableId)))), + Optional.empty()); + + return writeExtract( + fileName.value1(), + qry, + request, + response); + }); + } + + private void registerExtractForCategory(String path) { post(path, (request, response) -> { @@ -91,7 +131,7 @@ private void registerExtractForCategory(String path) { SelectConditionStep qry = prepareQuery( MEASURABLE.MEASURABLE_CATEGORY_ID.eq(measurableCategoryId), - applicationIdSelectionOptions); + Optional.of(applicationIdSelectionOptions)); return writeExtract( fileName.value1(), @@ -118,7 +158,7 @@ private void registerExtractForScheme(String path) { SelectConditionStep qry = prepareQuery( ALLOCATION_SCHEME.ID.eq(schemeId), - applicationIdSelectionOptions); + Optional.of(applicationIdSelectionOptions)); String filename = fileNameInfoRow.value1() + "_" + fileNameInfoRow.value2(); @@ -134,8 +174,7 @@ private void registerExtractForScheme(String path) { // -- HELPER ---- private SelectConditionStep prepareQuery(Condition additionalCondition, - IdSelectionOptions idSelectionOptions) { - Select> appSelector = applicationIdSelectorFactory.apply(idSelectionOptions); + Optional idSelectionOptions) { SelectSelectStep reportColumns = dsl .select(APPLICATION.NAME.as("Application Name"), APPLICATION.ID.as("Application Waltz Id"), @@ -162,8 +201,13 @@ private SelectConditionStep prepareQuery(Condition additionalCondition, DSL.coalesce(ALLOCATION.LAST_UPDATED_BY, "").as("Allocation Last Updated By"), DSL.coalesce(ALLOCATION.PROVENANCE, "").as("Allocation Provenance")); - Condition condition = MEASURABLE_RATING.ENTITY_ID.in(appSelector) - .and(MEASURABLE_RATING.ENTITY_KIND.eq(EntityKind.APPLICATION.name())) + Condition appCondition = idSelectionOptions + .map(applicationIdSelectorFactory) + .map(selector -> MEASURABLE_RATING.ENTITY_ID.in(selector) + .and(MEASURABLE_RATING.ENTITY_KIND.eq(EntityKind.APPLICATION.name()))) + .orElse(DSL.trueCondition()); + + Condition condition = appCondition .and(ENTITY_HIERARCHY.ID.eq(ENTITY_HIERARCHY.ANCESTOR_ID)) .and(ENTITY_HIERARCHY.KIND.eq(EntityKind.MEASURABLE.name())) .and(ENTITY_HIERARCHY.ID.eq(MEASURABLE_RATING.MEASURABLE_ID))