Skip to content

Commit

Permalink
fix(server): fix feature type detection in cmsintegrationv3
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Mar 25, 2024
1 parent 7e28765 commit 3654bb7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/cmsintegration/cmsintegrationv3/service_fme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 11 additions & 2 deletions server/cmsintegration/cmsintegrationv3/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""
}
4 changes: 2 additions & 2 deletions server/cmsintegration/cmsintegrationv3/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"))
}

0 comments on commit 3654bb7

Please sign in to comment.