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

Commit

Permalink
refactor(server): transfer repos to plateauapi
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Mar 14, 2024
1 parent a7884f5 commit 6086440
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func cityFrom(d datacatalogv2.DataCatalogItem) *plateauapi.City {

func citygmlFrom(d datacatalogv2.DataCatalogItem) *plateauapi.CityGMLDataset {
id, code := cityIDFrom(d), cityCodeFrom(d)
if id == nil || code == nil || d.CityGMLURL == "" || d.Spec == "" || len(d.CityGMLFeatureTypes) == 0 {
if id == nil || code == nil || d.CityGMLURL == "" || d.MaxLODURL == "" || d.Spec == "" || len(d.CityGMLFeatureTypes) == 0 {
return nil
}

Expand All @@ -514,7 +514,6 @@ func citygmlFrom(d datacatalogv2.DataCatalogItem) *plateauapi.CityGMLDataset {
Admin: map[string]any{
"maxlod": d.MaxLODURL,
},
// Items: items,
}
}

Expand Down
162 changes: 0 additions & 162 deletions server/datacatalog/datacatalogv3/repo.go

This file was deleted.

77 changes: 77 additions & 0 deletions server/datacatalog/datacatalogv3/repos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package datacatalogv3

import (
"context"
"fmt"
"sort"
"time"

"github.com/eukarya-inc/reearth-plateauview/server/datacatalog/plateauapi"
cms "github.com/reearth/reearth-cms-api/go"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/util"
)

var stagesForAdmin = []string{string(stageBeta)}

type Repos struct {
cms *util.SyncMap[string, *CMS]
*plateauapi.Repos
}

func NewRepos() *Repos {
r := &Repos{
cms: util.NewSyncMap[string, *CMS](),
}
r.Repos = plateauapi.NewRepos(r.update)
return r
}

func (r *Repos) Prepare(ctx context.Context, project string, year int, cms cms.Interface) error {
if _, ok := r.cms.Load(project); ok {
return nil
}

r.setCMS(project, year, cms)
_, err := r.Update(ctx, project)
return err
}

func (r *Repos) update(ctx context.Context, project string) (*plateauapi.ReposUpdateResult, error) {
cms, ok := r.cms.Load(project)
if !ok {
return nil, fmt.Errorf("cms is not initialized for %s", project)
}

updated := r.UpdatedAt(project)
var updatedStr string
if !updated.IsZero() {
updatedStr = updated.Format(time.RFC3339)
}
log.Infofc(ctx, "datacatalogv3: updating repo %s: last_update=%s", project, updatedStr)

data, err := cms.GetAll(ctx, project)
if err != nil {
return nil, err
}

c, warning := data.Into()
sort.Strings(warning)

repo := plateauapi.NewInMemoryRepo(c)

adminRepo := plateauapi.NewInMemoryRepo(c)
adminRepo.SetAdmin(true)
adminRepo.SetIncludedStages(stagesForAdmin...)

return &plateauapi.ReposUpdateResult{
Repo: repo,
AdminRepo: adminRepo,
Warnings: warning,
}, nil
}

func (r *Repos) setCMS(project string, year int, cms cms.Interface) {
c := NewCMS(cms, year)
r.cms.Store(project, c)
}
Loading

0 comments on commit 6086440

Please sign in to comment.