From 7d6dba1a7eb74a9c8d8002983f29fa82bc2b39dc Mon Sep 17 00:00:00 2001 From: Noah Overcash Date: Thu, 29 Aug 2024 15:29:22 -0400 Subject: [PATCH] [MODFQMMGR-429] Consolidate resource type column to directly expose instead (#402) --- .../MigrationStrategyRepository.java | 4 +- .../V1ModeOfIssuanceConsolidation.java | 2 +- .../V2ResourceTypeConsolidation.java | 61 +++++++++++++++++++ .../folio/fqm/service/MigrationService.java | 2 +- .../inventory/composite_instances.json5 | 10 --- .../inventory/simple_instance.json5 | 32 +++++++++- translations/mod-fqm-manager/en.json | 3 +- 7 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/folio/fqm/migration/strategies/V2ResourceTypeConsolidation.java diff --git a/src/main/java/org/folio/fqm/migration/MigrationStrategyRepository.java b/src/main/java/org/folio/fqm/migration/MigrationStrategyRepository.java index 7552d7ad..e822fdcf 100644 --- a/src/main/java/org/folio/fqm/migration/MigrationStrategyRepository.java +++ b/src/main/java/org/folio/fqm/migration/MigrationStrategyRepository.java @@ -3,6 +3,7 @@ import java.util.List; import org.folio.fqm.migration.strategies.V0POCMigration; import org.folio.fqm.migration.strategies.V1ModeOfIssuanceConsolidation; +import org.folio.fqm.migration.strategies.V2ResourceTypeConsolidation; import org.springframework.stereotype.Component; @Component @@ -11,7 +12,8 @@ public class MigrationStrategyRepository { // prevent re-initialization on each call private static final List MIGRATION_STRATEGIES = List.of( new V0POCMigration(), - new V1ModeOfIssuanceConsolidation() + new V1ModeOfIssuanceConsolidation(), + new V2ResourceTypeConsolidation() ); public List getMigrationStrategies() { diff --git a/src/main/java/org/folio/fqm/migration/strategies/V1ModeOfIssuanceConsolidation.java b/src/main/java/org/folio/fqm/migration/strategies/V1ModeOfIssuanceConsolidation.java index 1fb231e8..b76de62c 100644 --- a/src/main/java/org/folio/fqm/migration/strategies/V1ModeOfIssuanceConsolidation.java +++ b/src/main/java/org/folio/fqm/migration/strategies/V1ModeOfIssuanceConsolidation.java @@ -18,7 +18,7 @@ public class V1ModeOfIssuanceConsolidation extends AbstractSimpleMigrationStrate @Override public String getLabel() { - return "V1 -> V2 Removed simple_mode_of_issuance"; + return "V1 -> V2 Removed simple_mode_of_issuance (MODFQMMGR-427)"; } @Override diff --git a/src/main/java/org/folio/fqm/migration/strategies/V2ResourceTypeConsolidation.java b/src/main/java/org/folio/fqm/migration/strategies/V2ResourceTypeConsolidation.java new file mode 100644 index 00000000..3d7c1b46 --- /dev/null +++ b/src/main/java/org/folio/fqm/migration/strategies/V2ResourceTypeConsolidation.java @@ -0,0 +1,61 @@ +package org.folio.fqm.migration.strategies; + +import java.util.Map; +import java.util.UUID; +import java.util.function.BiFunction; +import java.util.function.Function; +import org.folio.fqm.migration.AbstractSimpleMigrationStrategy; +import org.folio.fqm.migration.warnings.EntityTypeWarning; +import org.folio.fqm.migration.warnings.FieldWarning; + +/** + * Version 2 -> 3, decouples simple_mode_of_issuance entity type from composite_instances + * @see https://folio-org.atlassian.net/browse/MODFQMMGR-429 + */ +public class V2ResourceTypeConsolidation extends AbstractSimpleMigrationStrategy { + + public static final UUID COMPOSITE_INSTANCES = UUID.fromString("6b08439b-4f8e-4468-8046-ea620f5cfb74"); + + @Override + public String getLabel() { + return "V2 -> V3 Exposing resource_type directly in composite_instances (MODFQMMGR-429)"; + } + + @Override + public String getSourceVersion() { + return "2"; + } + + @Override + public String getTargetVersion() { + return "3"; + } + + @Override + public Map getEntityTypeChanges() { + return Map.of(); + } + + @Override + public Map> getFieldChanges() { + return Map.ofEntries( + Map.entry( + COMPOSITE_INSTANCES, + Map.ofEntries( + Map.entry("instance_type.id", "instance.instance_type_id"), + Map.entry("instance_type.name", "instance.instance_type_name") + ) + ) + ); + } + + @Override + public Map> getEntityTypeWarnings() { + return Map.of(); + } + + @Override + public Map>> getFieldWarnings() { + return Map.of(); + } +} diff --git a/src/main/java/org/folio/fqm/service/MigrationService.java b/src/main/java/org/folio/fqm/service/MigrationService.java index d19d59af..45a9aaf3 100644 --- a/src/main/java/org/folio/fqm/service/MigrationService.java +++ b/src/main/java/org/folio/fqm/service/MigrationService.java @@ -25,7 +25,7 @@ public class MigrationService { public static final UUID REMOVED_ENTITY_TYPE_ID = UUID.fromString("deadbeef-dead-dead-dead-deaddeadbeef"); - protected static final String CURRENT_VERSION = "2"; + protected static final String CURRENT_VERSION = "3"; // TODO: replace this with current version in the future? protected static final String DEFAULT_VERSION = "0"; diff --git a/src/main/resources/entity-types/inventory/composite_instances.json5 b/src/main/resources/entity-types/inventory/composite_instances.json5 index 9bdcda01..6e1d8d05 100644 --- a/src/main/resources/entity-types/inventory/composite_instances.json5 +++ b/src/main/resources/entity-types/inventory/composite_instances.json5 @@ -22,16 +22,6 @@ condition: ":this.id = (:that.jsonb ->> 'statusId')::uuid", }, }, - { - alias: 'instance_type', - type: 'entity-type', - id: 'af44e2e0-12e0-4eec-b80d-49feb33a866c', // simple_instance_type - join: { - type: 'left join', - joinTo: 'instance.inst', - condition: ':this.id = :that.instanceTypeId', - }, - }, ], defaultSort: [ { diff --git a/src/main/resources/entity-types/inventory/simple_instance.json5 b/src/main/resources/entity-types/inventory/simple_instance.json5 index 64a985c3..97392a49 100644 --- a/src/main/resources/entity-types/inventory/simple_instance.json5 +++ b/src/main/resources/entity-types/inventory/simple_instance.json5 @@ -19,6 +19,16 @@ condition: ':this.id = :that.modeOfIssuanceId', }, }, + { + type: 'db', + alias: 'instance_type', + target: 'src_inventory_instance_type', + join: { + type: 'left join', + joinTo: 'inst', + condition: ':this.id = :that.instanceTypeId', + }, + }, ], requiredPermissions: [ 'inventory-storage.instances.item.get', @@ -110,10 +120,30 @@ }, isIdColumn: false, queryable: true, - essential: true, + essential: false, visibleByDefault: false, valueGetter: ':sourceAlias.instancetypeid', }, + { + name: 'instance_type_name', + sourceAlias: 'instance_type', + dataType: { + dataType: 'stringType', + }, + isIdColumn: false, + queryable: true, + visibleByDefault: true, + essential: true, + valueGetter: ":sourceAlias.jsonb->>'name'", + filterValueGetter: "lower(\ + ${tenant_id}_mod_inventory_storage.f_unaccent (:sourceAlias.jsonb->>'name'::text)\ + )", + valueFunction: 'lower(${tenant_id}_mod_inventory_storage.f_unaccent (:value))', + source: { + entityTypeId: 'af44e2e0-12e0-4eec-b80d-49feb33a866c', + columnName: 'name', + }, + }, { name: 'mode_of_issuance_id', sourceAlias: 'inst', diff --git a/translations/mod-fqm-manager/en.json b/translations/mod-fqm-manager/en.json index dd02b128..bc2dd2b8 100644 --- a/translations/mod-fqm-manager/en.json +++ b/translations/mod-fqm-manager/en.json @@ -681,7 +681,8 @@ "entityType.simple_instance.identifiers.value._qualified": "Identifiers value", "entityType.simple_instance.index_title": "Index title", "entityType.simple_instance.instance_format_ids": "Instance format UUIDs", - "entityType.simple_instance.instance_type_id": "Instance type UUID", + "entityType.simple_instance.instance_type_id": "Resource type UUID", + "entityType.simple_instance.instance_type_name": "Resource type", "entityType.simple_instance.jsonb": "JSONB", "entityType.simple_instance.languages": "Languages", "entityType.simple_instance.match_key": "Match key",