From 3654bb7b30926085a380bc94763c081224a84ce4 Mon Sep 17 00:00:00 2001 From: rot1024 Date: Mon, 25 Mar 2024 18:49:59 +0900 Subject: [PATCH] fix(server): fix feature type detection in cmsintegrationv3 --- .../cmsintegration/cmsintegrationv3/service_fme.go | 2 +- server/cmsintegration/cmsintegrationv3/util.go | 13 +++++++++++-- server/cmsintegration/cmsintegrationv3/util_test.go | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/server/cmsintegration/cmsintegrationv3/service_fme.go b/server/cmsintegration/cmsintegrationv3/service_fme.go index ff8a71f53..bd6c6e5ca 100644 --- a/server/cmsintegration/cmsintegrationv3/service_fme.go +++ b/server/cmsintegration/cmsintegrationv3/service_fme.go @@ -44,7 +44,7 @@ func sendRequestToFME(ctx context.Context, s *Services, conf *Config, w *cmswebh featureType := strings.TrimPrefix(w.ItemData.Model.Key, modelPrefix) if featureType == sampleModel && item.FeatureType != "" { - if ft := getBracketContent(item.FeatureType); ft != "" { + if ft := getLastBracketContent(item.FeatureType); ft != "" { featureType = ft log.Debugfc(ctx, "cmsintegrationv3: sample item: feature type is %s", ft) } diff --git a/server/cmsintegration/cmsintegrationv3/util.go b/server/cmsintegration/cmsintegrationv3/util.go index 650a96937..2c2b194e3 100644 --- a/server/cmsintegration/cmsintegrationv3/util.go +++ b/server/cmsintegration/cmsintegrationv3/util.go @@ -25,10 +25,19 @@ func tagFrom(t fmt.Stringer) *cms.Tag { } } -func getBracketContent(s string) string { +func getLastBracketContent(s string) string { if strings.Contains(s, "(") && strings.Contains(s, ")") { - return strings.Split(strings.Split(s, "(")[1], ")")[0] + _, s := cutStringRight(s, "(") + s, _, _ = strings.Cut(s, ")") + return s } return "" } + +func cutStringRight(s string, sep string) (string, string) { + if i := strings.LastIndex(s, sep); i >= 0 { + return s[:i], s[i+len(sep):] + } + return s, "" +} diff --git a/server/cmsintegration/cmsintegrationv3/util_test.go b/server/cmsintegration/cmsintegrationv3/util_test.go index a25bf3b3d..6e6c7783b 100644 --- a/server/cmsintegration/cmsintegrationv3/util_test.go +++ b/server/cmsintegration/cmsintegrationv3/util_test.go @@ -7,6 +7,6 @@ import ( ) func TestGetBracketContent(t *testing.T) { - assert.Equal(t, "", getBracketContent("トンネルモデル")) - assert.Equal(t, "tun", getBracketContent("トンネルモデル(tun)")) + assert.Equal(t, "", getLastBracketContent("トンネルモデル")) + assert.Equal(t, "tran", getLastBracketContent("交通(道路)モデル(tran)")) }