This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
/
publicart.go
93 lines (67 loc) · 1.69 KB
/
publicart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package sfomuseum
import (
"context"
"errors"
"fmt"
"github.com/sfomuseum/go-lookup/catalog"
"github.com/tidwall/gjson"
"io"
"io/ioutil"
_ "log"
)
func DefaultPublicArtGitURI() string {
return NewPublicArtGitURI(SFOMUSEUM_DATA_PUBLICART)
}
func NewPublicArtGitURI(uri string) string {
return NewPublicArtURI("git", uri)
}
func NewPublicArtBlobURI(uri string) string {
return NewPublicArtURI("blob", uri)
}
func NewPublicArtURI(lu_scheme string, uri string) string {
return NewIteratorURI("publicart", lu_scheme, uri)
}
func DefaultPublicArtCatalogOptions() (*CatalogOptions, error) {
opts, err := DefaultCatalogOptions()
if err != nil {
return nil, err
}
opts.AppendFuncs = append(opts.AppendFuncs, AppendPublicArtFunc)
return opts, nil
}
func AppendPublicArtFunc(ctx context.Context, lu catalog.Catalog, fh io.ReadCloser) error {
body, err := ioutil.ReadAll(fh)
if err != nil {
return err
}
id_rsp := gjson.GetBytes(body, "properties.wof:id")
if !id_rsp.Exists() {
return nil
}
pt_rsp := gjson.GetBytes(body, "properties.sfomuseum:placetype")
if !pt_rsp.Exists() {
return nil
}
if pt_rsp.String() != "publicart" {
return nil
}
obj_rsp := gjson.GetBytes(body, "properties.sfomuseum:object_id")
if !obj_rsp.Exists() {
return nil
}
c_rsp := gjson.GetBytes(body, "properties.mz:is_current")
if !c_rsp.Exists() {
return nil
}
if c_rsp.Int() != 1 {
return nil
}
obj_id := obj_rsp.String()
wof_id := id_rsp.Int()
has_id, exists := lu.LoadOrStore(obj_id, wof_id)
if exists && wof_id != has_id.(int64) {
msg := fmt.Sprintf("Existing public art work for '%s' (%d). Has ID: %d", obj_id, wof_id, has_id.(int64))
return errors.New(msg)
}
return nil
}