Skip to content

Commit

Permalink
Add additional author metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Sep 6, 2024
1 parent 1fff72c commit e5ccb48
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 32 deletions.
1 change: 0 additions & 1 deletion cmd/sheetsStructs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func sheetsFields() []CsvColumn {
"Title": "title",
"Full Title": "field_full_title",
"Make Public (Y/N)": "published",
"Contributor": "field_linked_agent",
"Related Department": "field_department_name",
"Resource Type": "field_resource_type",
"Genre (Getty AAT)": "field_genre",
Expand Down
17 changes: 1 addition & 16 deletions cmd/transformCsvCrossref.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,10 @@ var transformCsvCrossrefCmd = &cobra.Command{
}
if components[1] == "cre" || components[1] == "aut" {
name := strings.Join(components[3:], ":")
nameComponents := strings.Split(name, ", ")
surname := nameComponents[0]
given := ""
if len(nameComponents) > 1 {
given = strings.Join(nameComponents[1:], ", ")
}
sequence := "additional"
article.Contributors = append(article.Contributors, crossref.GetContributor(name, first))
if first {
first = false
sequence = "first"
}
article.Contributors = append(article.Contributors, crossref.Contributor{
Name: crossref.PersonName{
Given: html.EscapeString(given),
Surname: html.EscapeString(surname),
},
Role: "author",
Sequence: sequence,
})
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions crossref/journal-volume.xml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,23 @@
<given_name>{{ .Name.Given }}</given_name>
{{- end }}
<surname>{{ .Name.Surname }}</surname>
{{- if .Name.Institution }}
<affiliation>{{ .Name.Institution }}</affiliation>
{{- end }}
{{- if .Name.ORCID }}
<ORCID>{{ .Name.ORCID }}</ORCID>
{{- end }}
</person_name>
{{- if .Organization }}
<organization sequence="additional" contributor_role="{{ .Role }}">{{ .Organization }}</organization>
{{- end }}
{{- end }}
</contributors>
{{- end }}
{{- if .LicenseRef }}
<license>
<license_ref>{{ .LicenseRef }}</license_ref>
</license>
{{- end }}
<publication_date media_type="online">
<year>{{ .Year }}</year>
Expand Down
114 changes: 114 additions & 0 deletions model/crossref/contributor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package crossref

import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"strings"

"github.com/lehigh-university-libraries/go-islandora/model"
"golang.org/x/net/html"
)

type Contributor struct {
Name PersonName
Suffix string
Organization string
Orcid string
Role string
Sequence string
}

type PersonName struct {
Surname string `xml:"surname"`
Given string `xml:"given_name,omitempty"`
Institution string
ORCID string
}

func GetContributor(name string, first bool) Contributor {
contributor := Contributor{
Role: "author",
}

url := fmt.Sprintf("https://preserve.lehigh.edu/term_from_term_name?name=%s&vocab=person", url.QueryEscape(name))
resp, err := http.Get(url)
if err != nil {
log.Fatalf("Error fetching URL: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
log.Fatalf("Error: received non-200 status code: %v", resp.StatusCode)
}

body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Error reading response body: %v", err)
}

var c []model.TermResponse
if err := json.Unmarshal(body, &c); err != nil {
log.Fatalf("Error unmarshaling JSON: %v", err)
}

if len(c) > 0 {
for _, r := range c[0].Relationships {
if r.Url == "" {
continue
}
if r.RelType != "schema:worksFor" {
continue
}

relationshipUrl := fmt.Sprintf("https://preserve.lehigh.edu%s?_format=json", r.Url)
respRel, err := http.Get(relationshipUrl)
if err != nil {
log.Fatalf("Error fetching relationship URL: %v", err)
}
defer respRel.Body.Close()

if respRel.StatusCode != http.StatusOK {
log.Fatalf("Error: received non-200 status code from relationships URL: %v", respRel.StatusCode)
}

bodyRel, err := io.ReadAll(respRel.Body)
if err != nil {
log.Fatalf("Error reading relationships response body: %v", err)
}

var cr model.TermResponse
if err := json.Unmarshal(bodyRel, &cr); err != nil {
log.Fatalf("Error unmarshaling relationships JSON: %v", err)
}

contributor.Name.Institution = cr.Name[0].Value
name = strings.Replace(name, fmt.Sprintf(" - %s", contributor.Name.Institution), "", 1)
}
for _, i := range c[0].Identifier {
if i.Attr0 != "orcid" {
continue
}

contributor.Name.ORCID = i.Value
}

}
nameComponents := strings.Split(name, ", ")
surname := nameComponents[0]
given := ""
if len(nameComponents) > 1 {
given = strings.Join(nameComponents[1:], ", ")
}
sequence := "additional"
if first {
sequence = "first"
}
contributor.Name.Given = html.EscapeString(given)
contributor.Name.Surname = html.EscapeString(surname)
contributor.Sequence = sequence
return contributor
}
14 changes: 0 additions & 14 deletions model/crossref/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,3 @@ type Article struct {
type Reference struct {
DoiData DoiData
}

type Contributor struct {
Name PersonName
Suffix string
Organization string
Orcid string
Role string
Sequence string
}

type PersonName struct {
Surname string `xml:"surname"`
Given string `xml:"given_name,omitempty"`
}
8 changes: 8 additions & 0 deletions model/term.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package model

type TermResponse struct {
ID IntField `json:"tid"`
Name GenericField `json:"name"`
Relationships TypedRelationField `json:"field_relationships"`
Identifier TypedTextField `json:"field_identifier"`
}
1 change: 1 addition & 0 deletions model/type_relation_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type TypedRelationField []TypedRelation
type TypedRelation struct {
TargetId int `json:"target_id"`
RelType string `json:"rel_type"`
Url string `json:"url"`
}

func (field *TypedRelation) String() string {
Expand Down
1 change: 0 additions & 1 deletion workbench/workbench.gen.go

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

0 comments on commit e5ccb48

Please sign in to comment.