Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
fix(server): fix dataset subcode in datacatalogv2adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Feb 27, 2024
1 parent 43b58a2 commit 0036294
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions server/datacatalog/datacatalogv2/datacatalogv2adapter/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 18 additions & 4 deletions server/datacatalog/datacatalogv2/datacatalogv2adapter/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "名前",
Expand All @@ -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",
}))
}

0 comments on commit 0036294

Please sign in to comment.