Skip to content

Commit

Permalink
handle missing affiliations in crossrefxml writer
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed May 13, 2024
1 parent 2e59234 commit 42db45d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var versionCmd = &cobra.Command{
Short: "Print the version number of commonmeta",
Long: `All software has versions. This is commonmeta's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Commonmeta v0.3.5 -- HEAD")
fmt.Println("Commonmeta v0.3.6 -- HEAD")
},
}

Expand Down
4 changes: 2 additions & 2 deletions crossrefxml/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type Affiliation struct {

type Affiliations struct {
XMLName xml.Name `xml:"affiliations"`
Institution []Institution `xml:"institution"`
Institution []Institution `xml:"institution,omitempty"`
}

type ApprovalDate struct {
Expand Down Expand Up @@ -334,7 +334,7 @@ type Format struct {

type Institution struct {
XMLName xml.Name `xml:"institution"`
InstitutionName string `xml:"institution_name"`
InstitutionName string `xml:"institution_name,omitempty"`
InstitutionPlace string `xml:"institution_place,omitempty"`
InstitutionID *InstitutionID `xml:"institution_id,omitempty"`
}
Expand Down
62 changes: 36 additions & 26 deletions crossrefxml/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,36 +102,46 @@ func Convert(data commonmeta.Data) (Crossref, error) {
if i > 0 {
sequence = "additional"
}
institution := []Institution{}
for _, a := range contributor.Affiliations {
if a.Name != "" {
if a.ID != "" {
institutionID := &InstitutionID{
IDType: "ror",
Text: a.ID,
if len(contributor.Affiliations) > 0 {
institution := []Institution{}
for _, a := range contributor.Affiliations {
if a.Name != "" {
if a.ID != "" {
institutionID := &InstitutionID{
IDType: "ror",
Text: a.ID,
}
institution = append(institution, Institution{
InstitutionID: institutionID,
InstitutionName: a.Name,
})
} else {
institution = append(institution, Institution{
InstitutionName: a.Name,
})
}
institution = append(institution, Institution{
InstitutionID: institutionID,
InstitutionName: a.Name,
})
} else {
institution = append(institution, Institution{
InstitutionName: a.Name,
})
}
}
affiliations := &Affiliations{
Institution: institution,
}
personName = append(personName, PersonName{
ContributorRole: contributorRole,
Sequence: sequence,
ORCID: contributor.ID,
GivenName: contributor.GivenName,
Surname: contributor.FamilyName,
Affiliations: affiliations,
})
} else {
personName = append(personName, PersonName{
ContributorRole: contributorRole,
Sequence: sequence,
ORCID: contributor.ID,
GivenName: contributor.GivenName,
Surname: contributor.FamilyName,
})
}
affiliations := &Affiliations{
Institution: institution,
}
personName = append(personName, PersonName{
ContributorRole: contributorRole,
Sequence: sequence,
ORCID: contributor.ID,
GivenName: contributor.GivenName,
Surname: contributor.FamilyName,
Affiliations: affiliations,
})
}
}

Expand Down

0 comments on commit 42db45d

Please sign in to comment.