Skip to content

Commit

Permalink
fix(server): fix cmsintegration for sample data in cmsintegrationv3
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Mar 25, 2024
1 parent 2550ea1 commit 7e28765
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions server/cmsintegration/cmsintegrationv3/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ type FeatureItem struct {
SearchIndex string `json:"search_index,omitempty" cms:"search_index,asset"`
Dic string `json:"dic,omitempty" cms:"dic,textarea"`
MaxLOD string `json:"maxlod,omitempty" cms:"maxlod,asset"`
FeatureType string `json:"featureType,omitempty" cms:"feature_type,select"`
// metadata
SkipQCConv *cms.Tag `json:"skip_qc_conv,omitempty" cms:"skip_qc_conv,tag,metadata"`
Status *cms.Tag `json:"status,omitempty" cms:"status,select,metadata"`
Expand Down
27 changes: 10 additions & 17 deletions server/cmsintegration/cmsintegrationv3/service_fme.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (

var ppp *pp.PrettyPrinter

const ftfield = "feature_type"

func init() {
ppp = pp.New()
ppp.SetColoringEnabled(false)
Expand All @@ -37,16 +35,18 @@ func sendRequestToFME(ctx context.Context, s *Services, conf *Config, w *cmswebh
return nil
}

featureType := strings.TrimPrefix(w.ItemData.Model.Key, modelPrefix)
if featureType == sampleModel {
if ft := lo.FromPtr(w.ItemData.Item.FieldByKey(ftfield).GetValue().String()); ft != "" {
// extract content inside ()
if strings.Contains(ft, "(") && strings.Contains(ft, ")") {
ft = strings.Split(strings.Split(ft, "(")[1], ")")[0]
}
mainItem, err := s.GetMainItemWithMetadata(ctx, w.ItemData.Item)
if err != nil {
return err
}

item := FeatureItemFrom(mainItem)

featureType := strings.TrimPrefix(w.ItemData.Model.Key, modelPrefix)
if featureType == sampleModel && item.FeatureType != "" {
if ft := getBracketContent(item.FeatureType); ft != "" {
featureType = ft
log.Debugfc(ctx, "cmsintegrationv3: sample item: feature type is %s", featureType)
log.Debugfc(ctx, "cmsintegrationv3: sample item: feature type is %s", ft)
}
}

Expand All @@ -55,13 +55,6 @@ func sendRequestToFME(ctx context.Context, s *Services, conf *Config, w *cmswebh
return nil
}

mainItem, err := s.GetMainItemWithMetadata(ctx, w.ItemData.Item)
if err != nil {
return err
}

item := FeatureItemFrom(mainItem)

skipQC, skipConv := isQCAndConvSkipped(item, featureType)
if skipQC && skipConv {
log.Debugfc(ctx, "cmsintegrationv3: skip qc and convert")
Expand Down
9 changes: 9 additions & 0 deletions server/cmsintegration/cmsintegrationv3/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmsintegrationv3

import (
"fmt"
"strings"

cms "github.com/reearth/reearth-cms-api/go"
)
Expand All @@ -23,3 +24,11 @@ func tagFrom(t fmt.Stringer) *cms.Tag {
Name: s,
}
}

func getBracketContent(s string) string {
if strings.Contains(s, "(") && strings.Contains(s, ")") {
return strings.Split(strings.Split(s, "(")[1], ")")[0]
}

return ""
}
12 changes: 12 additions & 0 deletions server/cmsintegration/cmsintegrationv3/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cmsintegrationv3

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetBracketContent(t *testing.T) {
assert.Equal(t, "", getBracketContent("トンネルモデル"))
assert.Equal(t, "tun", getBracketContent("トンネルモデル(tun)"))
}

0 comments on commit 7e28765

Please sign in to comment.