From 00362947038f1d3546e60197e2cfe0528c476f9b Mon Sep 17 00:00:00 2001 From: rot1024 Date: Tue, 27 Feb 2024 13:51:27 +0900 Subject: [PATCH] fix(server): fix dataset subcode in datacatalogv2adapter --- .../datacatalogv2adapter/type.go | 4 ++++ .../datacatalogv2adapter/type_test.go | 22 +++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/server/datacatalog/datacatalogv2/datacatalogv2adapter/type.go b/server/datacatalog/datacatalogv2/datacatalogv2adapter/type.go index 851ec4bd1..819484025 100644 --- a/server/datacatalog/datacatalogv2/datacatalogv2adapter/type.go +++ b/server/datacatalog/datacatalogv2/datacatalogv2adapter/type.go @@ -167,6 +167,10 @@ func getSubCode(d datacatalogv2.DataCatalogItem) string { ids := strings.SplitN(d.ID, "_", 4) if len(ids) > 3 { + if ids[2] != d.TypeEn { + return "" // e.g. 01100_sapporo-shi_01103_higashi-ku_bldg + } + return trimSuffixes( strings.TrimSuffix(ids[3], "_no_texture"), "_l1", diff --git a/server/datacatalog/datacatalogv2/datacatalogv2adapter/type_test.go b/server/datacatalog/datacatalogv2/datacatalogv2adapter/type_test.go index ad6a05f2d..0f1f95704 100644 --- a/server/datacatalog/datacatalogv2/datacatalogv2adapter/type_test.go +++ b/server/datacatalog/datacatalogv2/datacatalogv2adapter/type_test.go @@ -4,9 +4,19 @@ import ( "testing" "github.com/eukarya-inc/reearth-plateauview/server/datacatalog/datacatalogv2" + "github.com/eukarya-inc/reearth-plateauview/server/datacatalog/plateauapi" "github.com/stretchr/testify/assert" ) +func TestDatasetIDFrom(t *testing.T) { + assert.Equal(t, plateauapi.ID("d_01103_bldg"), datasetIDFrom(datacatalogv2.DataCatalogItem{ + ID: "01100_sapporo-shi_01103_higashi-ku_bldg", + WardCode: "01103", + TypeEn: "bldg", + Family: "plateau", + })) +} + func TestGetSubName(t *testing.T) { assert.Equal(t, "名前", getSubName(datacatalogv2.DataCatalogItem{ Type2: "名前", @@ -29,15 +39,19 @@ func TestGetSubCode(t *testing.T) { Type2En: "name", })) assert.Empty(t, getSubCode(datacatalogv2.DataCatalogItem{ - ID: "11111_hoge-shi_bldg", + ID: "11111_hoge-shi_bldg", + TypeEn: "bldg", })) assert.Equal(t, "aaaa_bbbb", getSubCode(datacatalogv2.DataCatalogItem{ - ID: "11111_hoge-shi_urf_aaaa_bbbb", + ID: "11111_hoge-shi_urf_aaaa_bbbb", + TypeEn: "urf", })) assert.Equal(t, "aaaa_bbbb", getSubCode(datacatalogv2.DataCatalogItem{ - ID: "11111_hoge-shi_fld_aaaa_bbbb_l1", + ID: "11111_hoge-shi_fld_aaaa_bbbb_l1", + TypeEn: "fld", })) assert.Equal(t, "aaaa_bbbb", getSubCode(datacatalogv2.DataCatalogItem{ - ID: "11111_hoge-shi_fld_aaaa_bbbb_l2", + ID: "11111_hoge-shi_fld_aaaa_bbbb_l2", + TypeEn: "fld", })) }