Commit 1837b2b9 authored by Andreas Wagner's avatar Andreas Wagner
Browse files

Enable updating existing DOIs.

parent 1560fc11
......@@ -33,7 +33,7 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
{
APIv1.POST("/file", func(c *gin.Context) {
var myResult tei2zenodo.Result
var myDeposit tei2zenodo.Deposit
var r io.ReadSeeker
var doPublish bool
......@@ -69,55 +69,58 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
return
}
r.Seek(0, 0)
md.DOI = ""
if doi != "" {
log.Printf("=== DOI %s present, retrieving zenodo deposit ===", doi)
depositURI, err := zenodo.ResolveDOI(doi, &md, &conf.Repo)
if err != nil || depositURI == "" {
log.Printf("Error retrieving zenodo deposit for doi %s: %v", doi, err)
AbortMsg(500, fmt.Errorf("problem reported by zenodo: %s", err), c)
return
}
myResult.DepositURI = depositURI
myResult.DepositDOI = doi
myResult.FileContent = file
md.DOI = doi
} else {
log.Printf("=== Fetching new DOI from zenodo ===")
doi, depositURI, err := zenodo.GetDOI(&conf.Repo)
if doi == "" {
log.Printf("=== Create new DOI at zenodo ===")
doi, err = zenodo.CreateNewDOI(&md, &conf.Repo)
if err != nil || doi == "" {
log.Printf("Error creating DOI reservation deposit: %v", err)
AbortMsg(500, fmt.Errorf("problem reported by zenodo: %s", err), c)
return
}
myResult.DepositURI = depositURI
myResult.DepositDOI = doi
myDeposit.DepositDOI = doi
myDeposit.Metadata.DOI = doi
md.DOI = doi
log.Printf("=== Adding new DOI to document ===")
newfile, err := t2zxml.MixinDOI(r, doi)
} else {
log.Printf("=== Retrieve deposit for %s and create a new version ===", doi)
myDeposit.OldDOI = doi
// TODO: Fix Metadata and re-enable RelatedIdentifiers and other fields!
// md.RelatedIdentifiers = append(md.RelatedIdentifiers, tei2zenodo.ZIdentifier{Relation: "isNewVersionOf", Identifier: doi})
newDOI, err := zenodo.UpdateDeposit(&myDeposit, &md, &conf.Repo)
if err != nil {
log.Printf("Error mixing new DOI into document: %v", err)
AbortMsg(500, fmt.Errorf("problem mixing new DOI into document: %s", err), c)
log.Printf("Error retrieving zenodo deposit for doi %s: %v", doi, err)
AbortMsg(500, fmt.Errorf("problem reported by zenodo: %s", err), c)
return
}
// log.Printf("Here is the new file:\n%s", newfile[:10000])
myResult.FileContent = newfile
r = strings.NewReader(newfile)
myDeposit.DepositDOI = newDOI
md.DOI = newDOI
}
log.Printf("=== Add new DOI to document ===")
newfile, err := t2zxml.MixinDOI(r, md.DOI)
if err != nil {
log.Printf("Error mixing new DOI into document: %v", err)
AbortMsg(500, fmt.Errorf("problem mixing new DOI into document: %s", err), c)
return
}
// log.Printf("Here is the new file:\n%s", newfile[:10000])
myDeposit.FileContent = newfile
r = strings.NewReader(newfile)
r.Seek(0, 0)
log.Printf("=== Uploading to zenodo ===")
log.Printf("=== Upload to zenodo ===")
url, err := zenodo.PostFile(r, filename, &md, &conf.Repo)
if err != nil {
log.Printf("Error sending POST request to zenodo: %v", err)
AbortMsg(500, err, c)
return
}
myResult.FileURI = url
myDeposit.FileURI = url
log.Printf("=== Adding metadata to zenodo ===")
err = zenodo.PutMetadata(&md, &conf.Repo)
log.Printf("=== Add metadata to zenodo ===")
err = zenodo.PutMetadata(&myDeposit, &md, &conf.Repo)
if err != nil {
log.Printf("Error putting metadata: %v", err)
AbortMsg(500, err, c)
......@@ -137,7 +140,7 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
}
log.Printf("=== All done ===")
c.JSON(200, myResult)
c.JSON(200, myDeposit)
})
APIv1.GET("/webhook", func(c *gin.Context) {
})
......
......@@ -281,11 +281,20 @@ func MixinDOI(r io.Reader, doi string) (string, error) {
} else {
subIdnos := topLevelIdno.FindElement(`./idno`)
if subIdnos != nil { // publicationStmt contains <idno> with sub-<idno>s -> add doi idno as last child of parentIdno
parentIdno := pStmt.FindElement(`./idno`)
targetIdno := parentIdno.CreateElement("idno")
oldIdno := topLevelIdno.FindElement(`./idno[@type='DOI']`)
if oldIdno != nil {
oldIdnoIdx := oldIdno.Index()
topLevelIdno.RemoveChildAt(oldIdnoIdx)
}
targetIdno := topLevelIdno.CreateElement("idno")
targetIdno.CreateAttr("type", "DOI")
targetIdno.CreateText(doi)
} else { // publicationStmt contains one (or several) <idno> elements ->
} else { // publicationStmt contains one (or several) <idno> elements -> add doi at the first idno element's position
oldIdno := pStmt.FindElement(`./idno[@type='DOI']`)
if oldIdno != nil {
oldIdnoIdx := oldIdno.Index()
pStmt.RemoveChildAt(oldIdnoIdx)
}
targetIdno := etree.NewElement("idno")
targetIdno.CreateAttr("type", "DOI")
targetIdno.CreateText(doi)
......@@ -302,6 +311,6 @@ func MixinDOI(r io.Reader, doi string) (string, error) {
return "", err
}
log.Printf("Succes.")
log.Printf("Success.")
return output, nil
}
......@@ -9,7 +9,6 @@ import (
"log"
"mime/multipart"
"net/http"
"regexp"
"strconv"
"strings"
......@@ -38,57 +37,11 @@ type DOIData struct {
Value string
}
// ZDepositResponse stores a zenodo deposit response
type ZDepositResponse struct {
Created string
Files []ZFileResponse
ID int64
Links ZLinks
Metadata ZPrereserveMetadata
Modified string
Owner int64
RecordID int64 `json:"record_id"`
State string
Submitted bool
Title string
}
// ZFileResponse stores a zenodo file response
type ZFileResponse struct {
Checksum string
Filename string `json:"name"`
ID string
Filesize int64
Links ZLinks
}
// ZLinks stores links to zenodo's REST endpoints
type ZLinks struct {
Discard string
Edit string
Files string
Publish string
NewVersion string
Self string
Download string
}
// ZPostData wraps the metadata in a "metadata" object
type ZPostData struct {
Metadata *tei2zenodo.ZMetadata `json:"metadata"`
}
// ZPrereserveMetadata stores DOI prereservation metadata
type ZPrereserveMetadata struct {
PrereserveDOI ZPrereserveDOI `json:"prereserve_doi"`
}
// ZPrereserveDOI stores prereservation information
type ZPrereserveDOI struct {
DOI string
RecID int64
}
/* What's happening here?
- The order as described at https://developers.zenodo.org/ is this:
......@@ -121,20 +74,30 @@ III. Upload metadata
params={'access_token': ACCESS_TOKEN} )
*/
// GetDOI creates an empty zenodo deposit and reserves a DOI
// it returns the DOI of the deposit, its URI and an error value
func GetDOI(conf *tei2zenodo.RepoConfig) (string, string, error) {
// CreateDeposit creates an empty zenodo deposit and reserves a DOI
// it returns the DOI of the new deposit and an error value
func CreateDeposit(targetURI string, md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfig) (string, error) {
// Compile POST request
targetURI := conf.Host + ":" + strconv.Itoa(int(conf.Port)) + "/api/deposit/depositions" // ?access_token=" + conf.Token
log.Printf("Post request to: %s", targetURI)
log.Printf(" Post request to: %s", targetURI)
body := ZPostData{Metadata: md}
mdJSON, err := json.Marshal(body)
if err != nil {
log.Printf("Problem converting metadata to JSON format: %v ...", err)
return "", fmt.Errorf("problem converting metadata to JSON format: %s", err)
}
v := []byte(`{}`)
buf := bytes.NewBuffer(v)
var buf *bytes.Buffer
if targetURI[len(targetURI)-19:] == "/actions/newversion" {
buf = bytes.NewBuffer(mdJSON)
} else {
buf = bytes.NewBuffer([]byte(`{}`))
}
req, err := http.NewRequest("POST", targetURI, buf)
if err != nil {
log.Printf("Problem creating POST request: %v ...", err)
return "", "", fmt.Errorf("problem creating POST request: %s", err)
return "", fmt.Errorf("problem creating POST request: %s", err)
}
req.Header.Add("Content-Type", `application/json`)
req.Header.Add("Authorization", "Bearer "+conf.Token)
......@@ -144,7 +107,7 @@ func GetDOI(conf *tei2zenodo.RepoConfig) (string, string, error) {
resp, err := client.Do(req)
if err != nil {
log.Printf("Problem sending POST request: %v ...", err)
return "", "", fmt.Errorf("problem sending POST request: %s", err)
return "", fmt.Errorf("problem sending POST request: %s", err)
}
defer resp.Body.Close()
......@@ -152,38 +115,64 @@ func GetDOI(conf *tei2zenodo.RepoConfig) (string, string, error) {
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Printf("Problem reading POST response: %v ...", err)
return "", "", fmt.Errorf("problem reading POST response: %s", err)
return "", fmt.Errorf("problem reading POST response: %s", err)
}
if strconv.Itoa(resp.StatusCode)[:1] != "2" {
log.Printf("Problem reported by zenodo: %d %v. %80s ...", resp.StatusCode, err, content)
return "", "", fmt.Errorf("problem reported by zenodo: %d %v. %80s", resp.StatusCode, err, content)
return "", fmt.Errorf("problem reported by zenodo: %d %v. %80s", resp.StatusCode, err, content)
}
// Parse response
var parsedContent ZDepositResponse
var parsedContent tei2zenodo.Deposit
err = json.Unmarshal(content, &parsedContent)
if err != nil {
log.Printf("Problem parsing zenodo's response: %v ...", err)
return "", "", fmt.Errorf("problem parsing zenodo's response: %s", err)
return "", fmt.Errorf("problem parsing zenodo's response: %s", err)
}
doi := parsedContent.Metadata.PrereserveDOI.DOI
depositURI := parsedContent.Links.Self
var doi string
if targetURI[len(targetURI)-19:] == "/actions/newversion" {
i := parsedContent.Links.LatestDraftURI
id := i[strings.LastIndex(i, "/")+1:]
doi = conf.Prefix + id
} else {
doi = conf.Prefix + strconv.Itoa(int(parsedContent.ID))
}
log.Printf("Success (code %d (expected 201)). DOI %s is created and %s.", resp.StatusCode, doi, parsedContent.State)
return doi, depositURI, nil
return doi, nil
}
// ResolveDOI retrieves a zenodo deposit based on a gived DOI
// it returns a zenodo ID for the deposit and an error value
func ResolveDOI(doi string, md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfig) (string, error) {
// Compile POST request
targetURI := "https://doi.org/api/handles/" + doi
log.Printf("Get request from: %s", targetURI)
// CreateNewDOI creates a Deposit from Scratch
// it returns a new zenodo DOI for the deposit and an error value
func CreateNewDOI(md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfig) (string, error) {
targetURI := conf.Host + ":" + strconv.Itoa(int(conf.Port)) + "/api/deposit/depositions"
doi, err := CreateDeposit(targetURI, md, conf)
if err != nil {
log.Printf("Problem creating new DOI/deposit: %v ...", err)
return "", fmt.Errorf("problem creating new DOI/deposit: %s", err)
}
return doi, nil
}
// UpdateDeposit retrieves a zenodo deposit based on a gived DOI and creates a new version
// it returns a new zenodo DOI for the deposit and an error value
func UpdateDeposit(d *tei2zenodo.Deposit, md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfig) (string, error) {
if d.OldDOI[:len(conf.Prefix)] != conf.Prefix {
log.Printf("Problem: DOI %s is not a zenodo DOI.", d.OldDOI)
return "", fmt.Errorf("invalid DOI value")
}
oldDOI := d.OldDOI[len(conf.Prefix):]
// Compile GET request
targetURI := conf.Host + ":" + strconv.Itoa(int(conf.Port)) + "/api/deposit/depositions/" + oldDOI
req, err := http.NewRequest("GET", targetURI, nil)
req.Header.Add("Authorization", "Bearer "+conf.Token)
// Send GET request
resp, err := http.Get(targetURI)
log.Printf(" Get deposit for %s from %s", oldDOI, targetURI)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Printf("Problem creating GET request: %v ...", err)
return "", fmt.Errorf("problem creating GET request: %s", err)
......@@ -196,43 +185,187 @@ func ResolveDOI(doi string, md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfi
log.Printf("Problem reading GET response: %v ...", err)
return "", fmt.Errorf("problem reading GET response: %s", err)
}
if strconv.Itoa(resp.StatusCode)[:1] != "2" {
log.Printf("Problem reported by resolver: %d %v. %80s ...", resp.StatusCode, err, content)
return "", fmt.Errorf("problem reported by resolver: %d %v. %80s", resp.StatusCode, err, content)
}
// Parse response
err = json.Unmarshal(content, d)
if err != nil {
log.Printf("Problem parsing resolver's response: %v ...", err)
return "", fmt.Errorf("problem parsing resolver's response: %s", err)
}
d.OldDOI = oldDOI
log.Printf("Success.")
newVersionLink := d.Links.NewVersionURI
log.Printf(" Now get new version at %s", newVersionLink)
newDOI, err := CreateDeposit(newVersionLink, md, conf)
if err != nil {
log.Printf("Problem creating new version/deposit: %v ...", err)
return "", fmt.Errorf("problem creating new version/deposit: %s", err)
}
md.DOI = newDOI
return newDOI, nil
}
// GetFiles gets all files associated to a deposit
// it returns a slice of tei2zenodo.ZFile objects
func GetFiles(doi string, conf *tei2zenodo.RepoConfig) ([]tei2zenodo.ZFile, error) {
if doi[:len(conf.Prefix)] != conf.Prefix {
log.Printf("Problem: DOI %s is not a zenodo DOI.", doi)
return nil, fmt.Errorf("invalid DOI value")
}
id := doi[len(conf.Prefix):]
// Compile GET request
targetURI := conf.Host + ":" + strconv.Itoa(int(conf.Port)) + "/api/deposit/depositions/" + id + "/files"
req, err := http.NewRequest("GET", targetURI, nil)
req.Header.Add("Authorization", "Bearer "+conf.Token)
// Send GET request
log.Printf(" Get files for %s from: %s", doi, targetURI)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Printf("Problem creating GET request: %v ...", err)
return nil, fmt.Errorf("problem creating GET request: %s", err)
}
defer resp.Body.Close()
// Handle problematic responses
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Printf("Problem reading GET response: %v ...", err)
return nil, fmt.Errorf("problem reading GET response: %s", err)
}
if strconv.Itoa(resp.StatusCode)[:1] != "2" {
log.Printf("Problem reported by doi.org: %d %v. %80s ...", resp.StatusCode, err, content)
return "", fmt.Errorf("problem reported by doi.org: %d %v. %80s", resp.StatusCode, err, content)
log.Printf("Problem reported by zenodo: %d %v. %80s ...", resp.StatusCode, err, content)
return nil, fmt.Errorf("problem reported by zenodo: %d %v. %80s", resp.StatusCode, err, content)
}
// Parse response
var parsedContent DOIResponse
err = json.Unmarshal(content, &parsedContent)
var files []tei2zenodo.ZFile
err = json.Unmarshal(content, &files)
if err != nil {
log.Printf("Problem parsing resolver's response: %v ...", err)
return nil, fmt.Errorf("problem parsing resolver's response: %s", err)
}
return files, nil
}
// DeleteFileByID deletes a file from a zenodo deposit by its ID
// it returns an error value
func DeleteFileByID(doi string, id string, conf *tei2zenodo.RepoConfig) error {
if doi[:len(conf.Prefix)] != conf.Prefix {
log.Printf("Problem: DOI %s is not a zenodo DOI.", doi)
return fmt.Errorf("invalid DOI value")
}
dID := doi[len(conf.Prefix):]
// Compile DELETE request
targetURI := conf.Host + ":" + strconv.Itoa(int(conf.Port)) + "/api/deposit/depositions/" + dID + "/files/" + id
req, err := http.NewRequest("DELETE", targetURI, nil)
req.Header.Add("Authorization", "Bearer "+conf.Token)
// Send DELETE request
log.Printf(" Delete file %s from deposit %s", id, doi)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Printf("Problem parsing doi.org's response: %v ...", err)
return "", fmt.Errorf("problem parsing doi.org's response: %s", err)
log.Printf("Problem sending DELETE request: %v ...", err)
return fmt.Errorf("problem sending DELETE request: %s", err)
}
defer resp.Body.Close()
for _, v := range parsedContent.Values {
if v.Type == "URL" {
depositURI := v.Data.Value
if depositURI != "" {
// "https://zenodo.org/record/1186520" -> "https://sandbox.zenodo.org/api/deposit/depositions/1186520"
re := regexp.MustCompile(`^https://zenodo\.org/record/`)
apiURI := re.ReplaceAllString(depositURI, conf.Host+":"+strconv.Itoa(int(conf.Port))+"/api/deposit/depositions/")
log.Printf("Retrieved zenodo deposit for %s: %s.", doi, apiURI)
return apiURI, nil
// Handle problematic responses
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Printf("Problem reading DELETE response: %v ...", err)
return fmt.Errorf("problem reading DELETE response: %s", err)
}
if strconv.Itoa(resp.StatusCode)[:1] != "2" {
log.Printf("Problem reported by zenodo: %d %v. %80s ...", resp.StatusCode, err, content)
return fmt.Errorf("problem reported by zenodo: %d %v. %80s", resp.StatusCode, err, content)
}
return nil
}
// DeleteFileByName deletes a file from a zenodo deposit by its name
// it returns an error value
func DeleteFileByName(doi string, filename string, conf *tei2zenodo.RepoConfig) error {
if doi[:len(conf.Prefix)] != conf.Prefix {
log.Printf("Problem: DOI %s is not a zenodo DOI.", doi)
return fmt.Errorf("invalid DOI value")
}
files, err := GetFiles(doi, conf)
if err != nil {
log.Printf("Problem: Could not get files for DOI %s.", doi)
return fmt.Errorf("could not get files for %s", doi)
}
for _, f := range files {
log.Printf("test %s...", f.Filename)
if f.Filename == filename {
err = DeleteFileByID(doi, f.ID, conf)
if err != nil {
log.Printf("Problem: Could not delete file %s.", f.ID)
return fmt.Errorf("could not delete file %s", f.ID)
}
log.Printf("Success. Deleted file %s.", filename)
return nil
}
}
return "", fmt.Errorf("no valid deposit URI found in doi.org response")
return fmt.Errorf("no file with name %s found in deposit %s", filename, doi)
}
// DeleteIfExistsFileByName deletes a file from a zenodo deposit by its name.
// it does not raise an error if the file does not exist in the first place.
// it returns an error value
func DeleteIfExistsFileByName(doi string, filename string, conf *tei2zenodo.RepoConfig) error {
if doi[:len(conf.Prefix)] != conf.Prefix {
log.Printf("Problem: DOI %s is not a zenodo DOI.", doi)
return fmt.Errorf("invalid DOI value")
}
files, err := GetFiles(doi, conf)
if err != nil {
log.Printf("Problem: Could not get files for DOI %s.", doi)
return fmt.Errorf("could not get files for %s", doi)
}
for _, f := range files {
if f.Filename == filename {
err = DeleteFileByID(doi, f.ID, conf)
if err != nil {
log.Printf("Problem: Could not delete file %s.", f.ID)
return fmt.Errorf("could not delete file %s", f.ID)
}
log.Printf("Success. Deleted file %s.", filename)
return nil
}
}
log.Printf("No file %s to delete.", filename)
return nil
}
// PostFile posts a file to zenodo, taking the id from the md.DOI field
// it returns an URI for the upload and an error value
func PostFile(r io.Reader, filename string, md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfig) (string, error) {
if md.DOI[:15] != "10.5072/zenodo." { // not a zenodo doi (the pattern is for sandbox, the final prefix is 10.5281)
if md.DOI[:len(conf.Prefix)] != conf.Prefix {
log.Printf("Problem: DOI %s is not a zenodo DOI.", md.DOI)
return "", fmt.Errorf("invalid DOI value")
}
id := md.DOI[15:]
id := md.DOI[len(conf.Prefix):]
log.Printf("Make sure no file named %s exists in doi %s.", filename, md.DOI)
err := DeleteIfExistsFileByName(md.DOI, filename, conf)
if err != nil {
log.Printf("Problem deleting file %s: %v", filename, err)
return "", fmt.Errorf("problem deleting file %s: %s", filename, err)
}
// Read file from Request body
buf := new(bytes.Buffer)
......@@ -244,7 +377,7 @@ func PostFile(r io.Reader, filename string, md *tei2zenodo.ZMetadata, conf *tei2
uri := conf.Host + ":" + strconv.Itoa(int(conf.Port)) + "/api/deposit/depositions/" + id + "/files" // ?access_token=" + conf.Token
log.Printf("Post request to: %s", uri)
log.Printf("Upload filename: %s", filename)
log.Printf("Upload file: %s", file[:80])
log.Printf("Upload file: %s ...", file[:80])
// Compile upload form and prepare POST request
body := new(bytes.Buffer)
......@@ -290,7 +423,6 @@ func PostFile(r io.Reader, filename string, md *tei2zenodo.ZMetadata, conf *tei2
log.Printf("Problem reading POST response: %v ...", err)
return "", fmt.Errorf("problem reading POST response: %s", err)
}
if strconv.Itoa(resp.StatusCode)[:1] != "2" {
log.Printf("Problem reported by zenodo: %d %v. %80s ...", resp.StatusCode, err, content)
return "", fmt.Errorf("problem reported by zenodo: %v. %s", err, content)
......@@ -298,7 +430,7 @@ func PostFile(r io.Reader, filename string, md *tei2zenodo.ZMetadata, conf *tei2
// Parse response to extract filesize and download URI
// log.Printf("Response code %d, content: %80s", resp.StatusCode, content)
var parsedContent ZFileResponse
var parsedContent tei2zenodo.ZFile
err = json.Unmarshal(content, &parsedContent)
if err != nil {
log.Printf("Problem parsing zenodo's response: %v ...", err)
......@@ -306,20 +438,21 @@ func PostFile(r io.Reader, filename string, md *tei2zenodo.ZMetadata, conf *tei2
}
// log.Printf("Response code %d, content: %80s", resp.StatusCode, content)
log.Printf("Success (code %d (expected 201), %s Bytes). Return URI: %s.", resp.StatusCode, strconv.Itoa(int(parsedContent.Filesize)), parsedContent.Links.Download)
return parsedContent.Links.Download, nil
log.Printf("Success (code %d (expected 201), %s Bytes). Return URI: %s", resp.StatusCode, strconv.Itoa(int(parsedContent.Filesize)), parsedContent.Links.DownloadURI)
return parsedContent.Links.DownloadURI, nil
}
// PutMetadata adds metadata to an existing deposit and returns an error value
func PutMetadata(md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfig) error {
if md.DOI[:15] != "10.5072/zenodo." { // not a zenodo doi (the pattern is for sandbox, the final prefix is 10.5281)
log.Printf("Problem: DOI is not a zenodo DOI.")
func PutMetadata(d *tei2zenodo.Deposit, md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfig) error {
if md.DOI[:len(conf.Prefix)] != conf.Prefix {
log.Printf("Problem: DOI %s is not a zenodo DOI.", md.DOI)
return fmt.Errorf("invalid DOI value")
}
id := md.DOI[15:]
id := md.DOI[len(conf.Prefix):]
// Read metadata
body := ZPostData{Metadata: md}
var body ZPostData
body.Metadata = md
mdJSON, err := json.Marshal(body)
if err != nil {
log.Printf("Problem converting metadata to JSON format: %v ...", err)
......@@ -354,7 +487,6 @@ func PutMetadata(md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfig) error {
log.Printf("Problem reading PUT response: %v ...", err)
return fmt.Errorf("problem reading PUT response: %s", err)
}
if strconv.Itoa(resp.StatusCode)[:1] != "2" {
log.Printf("Problem reported by zenodo: %d %v. %80s ...", resp.StatusCode, err, content)
return fmt.Errorf("problem reported by zenodo: %v. %s", err, content)
......@@ -362,24 +494,25 @@ func PutMetadata(md *tei2zenodo.ZMetadata, conf *tei2zenodo.RepoConfig) error {