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

Commit

Permalink
fix(server): add suffix to dataset title in datacatalogv3
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Feb 8, 2024
1 parent f423f46 commit fb12a8c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
11 changes: 9 additions & 2 deletions server/datacatalog/datacatalogv3/conv_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,19 @@ func standardItemID(name string, area plateauapi.Area, ex string) string {
return fmt.Sprintf("%s_%s%s", area.GetCode(), name, ex)
}

func standardItemName(dtname, subname string, area plateauapi.Area) string {
func standardItemName(name, subname string, area plateauapi.Area) string {
var suffix string
if area != nil {
suffix = fmt.Sprintf("(%s)", area.GetName())
name = strings.TrimSuffix(name, suffix)
}

space := ""
if subname != "" {
space = " "
}
return fmt.Sprintf("%s%s%s(%s)", dtname, space, subname, area.GetName())

return fmt.Sprintf("%s%s%s%s", name, space, subname, suffix)
}

func layerNamesFrom(layer string) []string {
Expand Down
2 changes: 1 addition & 1 deletion server/datacatalog/datacatalogv3/conv_dataset_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (i *GenericItem) toDatasets(area *areaContext, dts []plateauapi.DatasetType

res := plateauapi.GenericDataset{
ID: id,
Name: i.Name,
Name: standardItemName(i.Name, "", area.City),
Description: lo.EmptyableToPtr(i.Desc),
Year: area.CityItem.YearInt(),
PrefectureID: area.PrefID,
Expand Down
9 changes: 9 additions & 0 deletions server/datacatalog/datacatalogv3/conv_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ func TestAssetURLFromFormat(t *testing.T) {
func TestAssetRootPath(t *testing.T) {
assert.Equal(t, "/example.com/1111/a", assetRootPath("/example.com/1111/a.zip"))
}

func TestStandardItemName(t *testing.T) {
assert.Equal(t, "name(area)", standardItemName("name", "", &plateauapi.City{Name: "area"}))
assert.Equal(t, "name name2(area)", standardItemName("name", "name2", &plateauapi.City{Name: "area"}))
assert.Equal(t, "name", standardItemName("name", "", nil))
assert.Equal(t, "name name2", standardItemName("name", "name2", nil))
assert.Equal(t, "name(area)", standardItemName("name(area)", "", &plateauapi.City{Name: "area"}))
assert.Equal(t, "name name2(area)", standardItemName("name(area)", "name2", &plateauapi.City{Name: "area"}))
}

0 comments on commit fb12a8c

Please sign in to comment.