Skip to content

Commit

Permalink
Merge branch 'main' of github.com:whosonfirst/go-whosonfirst-findinga…
Browse files Browse the repository at this point in the history
…id into main
  • Loading branch information
thisisaaronland committed Oct 26, 2021
2 parents b549ce9 + 589f7cc commit b907ef0
Show file tree
Hide file tree
Showing 569 changed files with 56,657 additions and 17,708 deletions.
14 changes: 7 additions & 7 deletions application/catalog/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var cache_uri string
var indexer_uri string
var iterator_uri string
var findingaid_uri string

type CatalogApplication struct {
Expand All @@ -29,9 +29,9 @@ func (app *CatalogApplication) DefaultFlagSet(ctx context.Context) (*flag.FlagSe
fs := flagset.NewFlagSet("catalog")

fs.StringVar(&cache_uri, "cache-uri", "file:///tmp/", "A valid whosonfirst/go-cache URI string.")
fs.StringVar(&indexer_uri, "indexer-uri", "repo://", "A valid whosonfirst/go-whosonfirst-iterate/v2 URI string.")
fs.StringVar(&iterator_uri, "iterator-uri", "repo://", "A valid whosonfirst/go-whosonfirst-iterate/v2 URI string.")

fs.StringVar(&findingaid_uri, "findingaid-uri", "repo://?cache={cache_uri}&indexer={indexer_uri}", "A valid whosonfirst/go-whosonfirst-findingaid URI string.")
fs.StringVar(&findingaid_uri, "findingaid-uri", "repo://?cache={cache_uri}&iterator={iterator_uri}", "A valid whosonfirst/go-whosonfirst-findingaid URI string.")

return fs, nil
}
Expand Down Expand Up @@ -69,12 +69,12 @@ func (app *CatalogApplication) RunWithFlagSet(ctx context.Context, fs *flag.Flag
fa_q["cache"] = []string{cache_uri}
}

if fa_q.Get("indexer") == "{indexer_uri}" {
fa_q["indexer"] = []string{indexer_uri}
if fa_q.Get("iterator") == "{iterator_uri}" {
fa_q["iterator"] = []string{iterator_uri}
}

if fa_q.Get("indexer") == "" {
return fmt.Errorf("Missing '-indexer-uri' flag.")
if fa_q.Get("iterator") == "" {
return fmt.Errorf("Missing '-iterator-uri' flag.")
}

fa_uri.RawQuery = fa_q.Encode()
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ go 1.16
require (
github.com/aaronland/go-http-server v0.0.7
github.com/aaronland/go-roster v0.0.2
github.com/aaronland/gocloud-blob-s3 v0.1.0
github.com/aaronland/gocloud-blob-s3 v0.1.3
github.com/jtacoma/uritemplates v1.0.0
github.com/rs/cors v1.7.0
github.com/sfomuseum/go-flags v0.8.2
github.com/tidwall/gjson v1.9.3
github.com/tidwall/gjson v1.10.2
github.com/tidwall/sjson v1.2.3
github.com/whosonfirst/go-cache v0.5.0
github.com/whosonfirst/go-cache-blob v0.2.0
github.com/whosonfirst/go-ioutil v1.0.0
github.com/whosonfirst/go-whosonfirst-iterate v1.2.0 // indirect
github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.0.1
github.com/whosonfirst/go-whosonfirst-uri v1.0.1
gocloud.dev v0.23.0
gocloud.dev v0.24.0
)
285 changes: 186 additions & 99 deletions go.sum

Large diffs are not rendered by default.

56 changes: 51 additions & 5 deletions repo/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
"github.com/whosonfirst/go-cache"
"github.com/whosonfirst/go-ioutil"
"github.com/whosonfirst/go-whosonfirst-findingaid"
Expand All @@ -18,8 +20,9 @@ import (
// Indexer is a struct that implements the findingaid.Indexer interface for information about Who's On First repositories.
type Indexer struct {
findingaid.Indexer
cache cache.Cache
iterator_uri string
cache cache.Cache
iterator_uri string
repo_property string
}

func init() {
Expand Down Expand Up @@ -71,9 +74,22 @@ func NewIndexer(ctx context.Context, uri string) (findingaid.Indexer, error) {
return nil, fmt.Errorf("Invalid ?iterator= parameter, %w", err)
}

// This is necessary for some repos like sfomuseum-data/sfomuseum-data-whosonfirst
// where the relevant repo name is stored in a properties.sfomuseum:repo key. This
// logic is handled below in IndexReader

repo_property := WOF_REPO_PROPERTY

custom_repo := q.Get("repo-property")

if custom_repo != "" {
repo_property = custom_repo
}

fa := &Indexer{
cache: c,
iterator_uri: iterator_uri,
cache: c,
iterator_uri: iterator_uri,
repo_property: repo_property,
}

return fa, nil
Expand Down Expand Up @@ -112,7 +128,37 @@ func (fa *Indexer) IndexURIs(ctx context.Context, sources ...string) error {
// IndexReader will index an individual Who's On First record in the finding aid.
func (fa *Indexer) IndexReader(ctx context.Context, fh io.Reader) error {

rsp, err := FindingAidResponseFromReader(ctx, fh)
body, err := io.ReadAll(fh)

if err != nil {
return fmt.Errorf("Failed to read feature, %v", err)
}

// This is necessary for some repos like sfomuseum-data/sfomuseum-data-whosonfirst
// where the relevant repo name is stored in a properties.sfomuseum:repo key

if fa.repo_property != WOF_REPO_PROPERTY {

path_wof_repo := fmt.Sprintf("properties.%s", WOF_REPO_PROPERTY)
path_custom_repo := fmt.Sprintf("properties.%s", fa.repo_property)

custom_rsp := gjson.GetBytes(body, path_custom_repo)

// If custom repo property is present then use its value to update wof:repo

if custom_rsp.Exists() {

custom_repo := custom_rsp.String()

body, err = sjson.SetBytes(body, path_wof_repo, custom_repo)

if err != nil {
return fmt.Errorf("Failed to assign custom repo (%s) to %s, %v", custom_repo, WOF_REPO_PROPERTY, err)
}
}
}

rsp, err := FindingAidResponseFromBytes(ctx, body)

if err != nil {
return err
Expand Down
22 changes: 17 additions & 5 deletions repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package repo

import (
"context"
"errors"
"fmt"
"github.com/tidwall/gjson"
"github.com/whosonfirst/go-whosonfirst-uri"
"io"
_ "log"
)

const WOF_ID_PROPERTY string = "wof:id"
const WOF_REPO_PROPERTY string = "wof:repo"

// FindingAidResonse is a struct that contains Who's On First repository information for Who's On First records.
type FindingAidResponse struct {
// The unique Who's On First ID.
Expand All @@ -26,18 +30,26 @@ func FindingAidResponseFromReader(ctx context.Context, fh io.Reader) (*FindingAi
return nil, err
}

return FindingAidResponseFromBytes(ctx, body)
}

func FindingAidResponseFromBytes(ctx context.Context, body []byte) (*FindingAidResponse, error) {

// TO DO: SUPPORT ALT FILES

id_rsp := gjson.GetBytes(body, "properties.wof:id")
path_id := fmt.Sprintf("properties.%s", WOF_ID_PROPERTY)
path_repo := fmt.Sprintf("properties.%s", WOF_REPO_PROPERTY)

id_rsp := gjson.GetBytes(body, path_id)

if !id_rsp.Exists() {
return nil, errors.New("Missing wof:id")
return nil, fmt.Errorf("Missing '%s' property", path_id)
}

repo_rsp := gjson.GetBytes(body, "properties.wof:repo")
repo_rsp := gjson.GetBytes(body, path_repo)

if !repo_rsp.Exists() {
return nil, errors.New("Missing wof:repo")
return nil, fmt.Errorf("Missing '%s' property", path_repo)
}

wof_id := id_rsp.Int()
Expand Down
26 changes: 3 additions & 23 deletions vendor/github.com/aaronland/gocloud-blob-s3/acl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

150 changes: 150 additions & 0 deletions vendor/github.com/aaronland/gocloud-blob-s3/options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/aws/aws-sdk-go-v2/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b907ef0

Please sign in to comment.