Ver Fonte

Merge pull request #44 from achilleas-k/gin-doi-cherry-picks

Cherry picks from GIN DOI changes
Michael Sonntag há 6 anos atrás
pai
commit
7b5afa5ca5

+ 0 - 1
conf/app.ini

@@ -531,7 +531,6 @@ INDEX_URL = localhost/index
 SEACH_URL = localhost/search
 
 [doi]
-DO = false
 DOI_URL = https://doi.gin.g-node.org/
 ; AES key (eg. openssl enc -aes-128-cbc -k secret -P -md sha1)
 DOI_KEY = WONTWORK

+ 35 - 22
conf/datacite/datacite.yml

@@ -1,62 +1,75 @@
-# Required fields
-# The main researchers involved working on the resource,
-# or the authors of the publication in priority order.
-# May be a corporate/institutional or personal name.
-# Include digital identifier (e.g., ORCID) if possible
+# Metadata for DOI registration according to DataCite Metadata Schema 4.1.
+# For detailed schema description see https://doi.org/10.5438/0014
+
+## Required fields
+
+# The main researchers involved. Include digital identifier (e.g., ORCID)
+# if possible, including the prefix to indicate its type.
 authors:
   -
     firstname: "GivenName1"
     lastname: "FamilyName1"
     affiliation: "Affiliation1"
-    id: "AuthorID1 (e.g. ORCID)"
+    id: "ORCID:0000-0001-2345-6789"
   -
     firstname: "GivenName2"
     lastname: "FamilyName2"
     affiliation: "Affiliation2"
+    id: "ResearcherID:X-1234-5678"
   -
     firstname: "GivenName3"
     lastname: "FamilyName3"
 
-# A name or title to describe the published resource.
+# A title to describe the published resource.
 title: "Example Title"
 
-# Any additional information. It is best practice to supply a description for the resource.
+# Additional information about the resource, e.g., a brief abstract.
 description: |
   Example description
   that can contain linebreaks
   but has to maintain indentation.
 
-# List of keywords the resource should be associated with.
+# Lit of keywords the resource should be associated with.
+# Give as many keywords as possible, to make the resource findable.
 keywords:
   - Neuroscience
   - Electrophysiology
 
-# Any rights information for this resource. Please provide both a license name and a link to the license.
-# Please add also a LICENSE file to the repository
+# License information for this resource. Please provide the license name and/or a link to the license.
+# Please add also a corresponding LICENSE file to the repository.
 license:
   name: "Creative Commons CC0 1.0 Public Domain Dedication"
   url: "https://creativecommons.org/publicdomain/zero/1.0/"
 
+
+
 ## Optional Fields
 
-# Any funding reference for this resource. Separate funder name and grant number by comma
+# Funding information for this resource.
+# Separate funder name and grant number by comma.
 funding:
   - "DFG, DFG.12345"
   - "EU, EU.12345"
 
-# Related publications. reftype might be: IsCitedBy, IsSupplementTo, IsReferencedBy, IsPartOf
-# for further valid types see https://schema.datacite.org/meta/kernel-4
+
+# Related publications. reftype might be: IsSupplementTo, IsDescribedBy, IsReferencedBy.
 # Please provide digital identifier (e.g., DOI) if possible.
+# Add a prefix to the ID, separated by a colon, to indicate the source.
+# Supported sources are: DOI, arXiv, PMID
 references:
   -
-    doi: "10.xxx/zzzz"
+    id: "doi:10.xxx/zzzz"
+    reftype: "IsSupplementTo"
+    name: "PublicationName1"
+  -
+    id: "arxiv:mmmm.nnnn"
     reftype: "IsSupplementTo"
-    name: "PublicationName"
+    name: "PublicationName2"
   -
-    reftype: "IsPartOf"
-    name: "PublicationName"
+    id: "pmid:nnnnnnnn"
+    reftype: "IsReferencedBy"
+    name: "PublicationName3"
+
 
-# Type of the data in this repository (Dataset, Model, Software, Other see
-# https://schema.datacite.org/meta/kernel-4.1/doc/DataCite-MetadataKernel_v4.1.pdf
-# for examples
-dtype: Dataset
+# Resource type. Default is Dataset, other possible values are Software, DataPaper, Image, Text.
+resourcetype: Dataset

+ 3 - 4
pkg/setting/setting.go

@@ -337,10 +337,9 @@ var (
 	}
 
 	DOI struct {
-		Do      bool
-		DOIURL  string
-		DOIKey  string
-		DOIBase string
+		URL  string `ini:"DOI_URL"`
+		Key  string `ini:"DOI_KEY"`
+		Base string `ini:"DOI_BASE"`
 	}
 
 	CLIConfig struct {

+ 16 - 6
routes/doi.go

@@ -5,9 +5,9 @@ import (
 	"crypto/cipher"
 	"crypto/rand"
 	"encoding/base64"
-	"fmt"
 	"io"
 	"net/http"
+	"net/url"
 
 	"github.com/G-Node/gogs/pkg/context"
 	"github.com/G-Node/gogs/pkg/setting"
@@ -20,15 +20,25 @@ func RequestDOI(c *context.Context) {
 		return
 	}
 	token := c.GetCookie(setting.SessionConfig.CookieName)
-	token, err := encrypt([]byte(setting.DOI.DOIKey), token)
+	token, err := encrypt([]byte(setting.DOI.Key), token)
 	if err != nil {
-		log.Error(0, "Could not encrypt Secret key:%s", err)
+		log.Error(2, "Could not encrypt secret key: %s", err)
 		c.Status(http.StatusInternalServerError)
 		return
 	}
-	url := fmt.Sprintf("%s/?repo=%s&user=%s&token=%s", setting.DOI.DOIURL, c.Repo.Repository.FullName(),
-		c.User.Name, token)
-	c.Redirect(url)
+	doiurl, err := url.Parse(setting.DOI.URL + "/register") // TODO: Handle error by notifying admin email
+	if err != nil {
+		log.Error(2, "Failed to parse DOI URL: %s", setting.DOI.URL)
+	}
+
+	params := url.Values{}
+	params.Add("repo", c.Repo.Repository.FullName())
+	params.Add("user", c.User.Name)
+	params.Add("token", token)
+	doiurl.RawQuery = params.Encode()
+	target, _ := url.PathUnescape(doiurl.String())
+	log.Trace(target)
+	c.RawRedirect(target)
 }
 
 // NOTE: TEMPORARY COPY FROM gin-doi

+ 2 - 1
routes/repo/repo_gin.go

@@ -50,6 +50,7 @@ func serveAnnexedData(ctx *context.Context, name string, cpt *captcha.Captcha, b
 }
 
 func readDataciteFile(entry *git.TreeEntry, c *context.Context) {
+	log.Trace("Found datacite.yml file")
 	c.Data["HasDatacite"] = true
 	doiData, err := entry.Blob().Data()
 	if err != nil {
@@ -69,7 +70,7 @@ func readDataciteFile(entry *git.TreeEntry, c *context.Context) {
 	}
 	c.Data["DOIInfo"] = &doiInfo
 
-	doi := calcRepoDOI(c, setting.DOI.DOIBase)
+	doi := calcRepoDOI(c, setting.DOI.Base)
 	//ddata, err := ginDoi.GDoiMData(doi, "https://api.datacite.org/works/") //todo configure URL?
 
 	c.Data["DOIReg"] = libgin.IsRegisteredDOI(doi)

+ 3 - 1
routes/repo/view.go

@@ -57,8 +57,10 @@ func renderDirectory(c *context.Context, treeLink string) {
 	for _, entry := range entries {
 		if !entry.IsDir() && entry.Name() == "datacite.yml" {
 			readDataciteFile(entry, c)
-			continue
+			break
 		}
+	}
+	for _, entry := range entries {
 		if entry.IsDir() || !markup.IsReadmeFile(entry.Name()) {
 			continue
 		}

+ 1 - 1
templates/repo/doifile.tmpl

@@ -42,7 +42,7 @@
 						<td>References</td>
 						<td>
 								{{range $index, $ref := .DOIInfo.References}}
-								{{ $ref.Name }} [{{ $ref.DOI }}] ({{ $ref.Reftype }})
+								{{ $ref.Name }} [{{ $ref.ID }}] ({{ $ref.Reftype }})
 								<br>
 								{{end}}
 						</td>

+ 15 - 15
vendor/github.com/G-Node/libgin/libgin/doi.go

@@ -36,23 +36,23 @@ func RepoPathToUUID(URI string) string {
 
 // DOIRegInfo holds all the metadata and information necessary for a DOI registration request.
 type DOIRegInfo struct {
-	Missing     []string
-	DOI         string
-	UUID        string
-	FileSize    int64
-	Title       string
-	Authors     []Author
-	Description string
-	Keywords    []string
-	References  []Reference
-	Funding     []string
-	License     *License
-	DType       string
+	Missing      []string
+	DOI          string
+	UUID         string
+	FileSize     int64
+	Title        string
+	Authors      []Author
+	Description  string
+	Keywords     []string
+	References   []Reference
+	Funding      []string
+	License      *License
+	ResourceType string
 }
 
 func (c *DOIRegInfo) GetType() string {
-	if c.DType != "" {
-		return c.DType
+	if c.ResourceType != "" {
+		return c.ResourceType
 	}
 	return "Dataset"
 }
@@ -112,7 +112,7 @@ type NamedIdentifier struct {
 type Reference struct {
 	Reftype string
 	Name    string
-	DOI     string
+	ID      string
 }
 
 type License struct {