From 3bba1ba9eb95968a7e8c1730370b5ef676b312cb Mon Sep 17 00:00:00 2001 From: rot1024 Date: Wed, 7 Feb 2024 21:04:50 +0900 Subject: [PATCH] fix(worker): related data is not correctly handled in prepare-gspatialjp --- worker/preparegspatialjp/command.go | 52 ++++++++++++++++++----------- worker/preparegspatialjp/maxlod.go | 1 + worker/preparegspatialjp/model.go | 3 +- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/worker/preparegspatialjp/command.go b/worker/preparegspatialjp/command.go index f98077d25..1f01670f4 100644 --- a/worker/preparegspatialjp/command.go +++ b/worker/preparegspatialjp/command.go @@ -52,7 +52,7 @@ func Command(conf *Config) (err error) { } var comment string - var citygmlError, plateauError bool + var citygmlError, plateauError, maxlodError bool defer func() { if err != nil { comment = err.Error() @@ -61,7 +61,7 @@ func Command(conf *Config) (err error) { ctx, cms, cityItem.GeospatialjpData, err != nil, - citygmlError, plateauError, + citygmlError, plateauError, maxlodError, strings.TrimSpace(comment), ); err != nil { log.Errorfc(ctx, "failed to notify error: %w", err) @@ -74,6 +74,7 @@ func Command(conf *Config) (err error) { if err != nil { citygmlError = true plateauError = true + maxlodError = true return fmt.Errorf("failed to get all feature items: %w", err) } @@ -132,27 +133,27 @@ func Command(conf *Config) (err error) { plateauResult := <-plateauCh maxlodResult := <-maxlodCh - if citygmlResult.Err != nil { - citygmlError = true - } - - if plateauResult.Err != nil { - plateauError = true - } - - if citygmlResult.Err != nil || plateauResult.Err != nil { - err = errors.Join(citygmlResult.Err, plateauResult.Err) + if citygmlResult.Err != nil || plateauResult.Err != nil || maxlodResult.Err != nil { + var errs []error + if citygmlResult.Err != nil { + citygmlError = true + errs = append(errs, fmt.Errorf("CityGMLのマージに失敗しました: %w\n", citygmlResult.Err)) + } + if plateauResult.Err != nil { + plateauError = true + errs = append(errs, fmt.Errorf("3D Tiles,MVTのマージに失敗しました: %w\n", plateauResult.Err)) + } + if maxlodResult.Err != nil { + maxlodError = true + errs = append(errs, fmt.Errorf("最大LODのマージに失敗しました: %w", maxlodResult.Err)) + } + err = errors.Join(errs...) return err } - if maxlodResult.Err != nil { - log.Errorfc(ctx, "failed to merge maxlod: %w", maxlodResult.Err) - comment += fmt.Sprintf("\n最大LODのマージ処理に失敗しました。: %s", maxlodResult.Err) - } - var citygmlZipAssetID, plateauZipAssetID, maxlodAssetID, relatedZipAssetID string - if !conf.SkipCityGML { + if !conf.SkipRelated { var err2 error relatedZipAssetID, err2 = GetRelatedZipAssetID(ctx, cms, cityItem) if err2 != nil { @@ -267,6 +268,9 @@ func attachAssets(ctx context.Context, c *cms.CMS, cityItem *CityItem, citygmlZi if maxlodAssetID != "" { item.MaxLOD = maxlodAssetID + item.MergeMaxLODStatus = &cms.Tag{ + Name: "成功", + } } if relatedZipAssetID != "" { @@ -286,7 +290,7 @@ func attachAssets(ctx context.Context, c *cms.CMS, cityItem *CityItem, citygmlZi return nil } -func notifyError(ctx context.Context, c *cms.CMS, cityItemID string, isErr bool, citygmlError, plateauError bool, comment string) error { +func notifyError(ctx context.Context, c *cms.CMS, cityItemID string, isErr bool, citygmlError, plateauError, maxLODError bool, comment string) error { if comment != "" { msgPrefix := "" if isErr { @@ -327,6 +331,16 @@ func notifyError(ctx context.Context, c *cms.CMS, cityItemID string, isErr bool, } } + if maxLODError { + item.MergeMaxLODStatus = &cms.Tag{ + Name: "エラー", + } + } else { + item.MergeMaxLODStatus = &cms.Tag{ + Name: "未実行", + } + } + var rawItem cms.Item cms.Marshal(item, &rawItem) if rawItem.ID == "" { diff --git a/worker/preparegspatialjp/maxlod.go b/worker/preparegspatialjp/maxlod.go index 774b97c5f..a34ff94c5 100644 --- a/worker/preparegspatialjp/maxlod.go +++ b/worker/preparegspatialjp/maxlod.go @@ -43,6 +43,7 @@ func MergeMaxLOD(ctx context.Context, cms *cms.CMS, cityItem *CityItem, allFeatu if line, err := b.ReadString('\n'); err != nil { // skip the first line return "", "", fmt.Errorf("failed to read first line: %w", err) } else if line == "" || isNumeric(rune(line[0])) { + // the first line shold be header (code,type,maxlod,filename) return "", "", fmt.Errorf("invalid maxlod data for %s", ft) } } else { diff --git a/worker/preparegspatialjp/model.go b/worker/preparegspatialjp/model.go index c74218a61..4089d9766 100644 --- a/worker/preparegspatialjp/model.go +++ b/worker/preparegspatialjp/model.go @@ -48,8 +48,8 @@ type CityItem struct { Specification string `json:"specification,omitempty" cms:"specification,asset"` Misc string `json:"misc,omitempty" cms:"misc,asset"` Year string `json:"year,omitempty" cms:"year,select"` + RelatedDataset string `json:"related,omitempty" cms:"related,reference"` References map[string]string `json:"references,omitempty" cms:"-"` - RelatedDataset string `json:"related_dataset,omitempty" cms:"related_dataset,reference"` GeospatialjpIndex string `json:"geospatialjp-index,omitempty" cms:"geospatialjp-index,reference"` GeospatialjpData string `json:"geospatialjp-data,omitempty" cms:"geospatialjp-data,reference"` } @@ -87,6 +87,7 @@ type GspatialjpItem struct { MergeCityGMLStatus *cms.Tag `json:"merge_citygml_status" cms:"merge_citygml_status,tag,metadata"` MergePlateauStatus *cms.Tag `json:"merge_plateau_status" cms:"merge_plateau_status,tag,metadata"` MergeRelatedStatus *cms.Tag `json:"merge_related_status" cms:"merge_related_status,tag,metadata"` + MergeMaxLODStatus *cms.Tag `json:"merge_maxlod_status" cms:"merge_maxlod_status,tag,metadata"` } var reReiwa = regexp.MustCompile(`令和([0-9]+?)年度?`)