diff --git a/doi/apis.go b/doi/apis.go index 3cd4308..dd64bc4 100644 --- a/doi/apis.go +++ b/doi/apis.go @@ -2,5 +2,5 @@ package doi type Provider interface { Init() - Publish(did, description string) (string, string, error) + Publish(did, description string, record any) (string, string, error) } diff --git a/doi/datacite.go b/doi/datacite.go index cf0fe51..15391f8 100644 --- a/doi/datacite.go +++ b/doi/datacite.go @@ -19,7 +19,7 @@ func (d *DataciteProvider) Init() { } // Publish provides publication of dataset with did and description -func (d *DataciteProvider) Publish(did, description string) (string, string, error) { - doi, doiLink, err := datacite.Publish(did, description) +func (d *DataciteProvider) Publish(did, description string, record any) (string, string, error) { + doi, doiLink, err := datacite.Publish(did, description, record) return doi, doiLink, err } diff --git a/doi/material_commons.go b/doi/material_commons.go index d8e65b7..55ff702 100644 --- a/doi/material_commons.go +++ b/doi/material_commons.go @@ -19,7 +19,7 @@ func (m *MCProvider) Init() { } // Publish provides publication of dataset with did and description -func (m *MCProvider) Publish(did, description string) (string, string, error) { - doi, doiLink, err := materialCommons.Publish(did, description) +func (m *MCProvider) Publish(did, description string, record any) (string, string, error) { + doi, doiLink, err := materialCommons.Publish(did, description, record) return doi, doiLink, err } diff --git a/doi/zenodo.go b/doi/zenodo.go index f0b6c0d..fd9e5f5 100644 --- a/doi/zenodo.go +++ b/doi/zenodo.go @@ -1,20 +1,14 @@ package doi import ( - "bytes" - "encoding/json" "fmt" - "io" srvConfig "github.com/CHESSComputing/golib/config" - "github.com/CHESSComputing/golib/services" "github.com/CHESSComputing/golib/zenodo" ) // ZenodoProvider represents Zenodo provider type ZenodoProvider struct { - HttpRequest *services.HttpRequest - Token string } // Init function initializes Zenodo provider @@ -22,14 +16,10 @@ func (z *ZenodoProvider) Init() { if srvConfig.Config == nil { srvConfig.Init() } - if z.HttpRequest == nil { - z.HttpRequest = services.NewHttpRequest("read", 0) - z.HttpRequest.Token = z.Token - } } // Publish provides publication of dataset with did and description -func (z *ZenodoProvider) Publish(did, description string) (string, string, error) { +func (z *ZenodoProvider) Publish(did, description string, record any) (string, string, error) { var doi, doiLink string var err error docId, err := zenodo.CreateRecord() @@ -37,32 +27,8 @@ func (z *ZenodoProvider) Publish(did, description string) (string, string, error return doi, doiLink, err } - // extract meta-data record for our did - query := fmt.Sprintf("{\"did\": \"%s\"}", did) - rec := services.ServiceRequest{ - Client: "foxden-doi", - ServiceQuery: services.ServiceQuery{Query: query, Idx: 0, Limit: -1}, - } - - data, err := json.Marshal(rec) - rurl := fmt.Sprintf("%s/search", srvConfig.Config.Services.MetaDataURL) - resp, err := z.HttpRequest.Post(rurl, "application/json", bytes.NewBuffer(data)) - if err != nil { - return doi, doiLink, err - } - defer resp.Body.Close() - data, err = io.ReadAll(resp.Body) - if err != nil { - return doi, doiLink, err - } - var records []map[string]any - err = json.Unmarshal(data, &records) - if err != nil { - return doi, doiLink, err - } - // add foxden record - frec := zenodo.FoxdenRecord{Did: did, MetaData: records} + frec := zenodo.FoxdenRecord{Did: did, MetaData: record} err = zenodo.AddRecord(docId, "foxden-metadata.json", frec) if err != nil { return doi, doiLink, err