Skip to content

Commit

Permalink
Merge branch 'main' of github.com:caltechlibrary/irdmtools into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdoiel committed Apr 12, 2024
2 parents fa80ccd + 58a144d commit d803aec
Show file tree
Hide file tree
Showing 58 changed files with 901 additions and 616 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ t.json
t.keys
t.txt
man/*
sandbox/*
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ authors:


repository-code: "https://github.com/caltechlibrary/irdmtools"
version: 0.0.76
version: 0.0.78
license-url: "https://caltechlibrary.github.io/irdmtools/LICENSE"
keywords: [ "institutional repository", "data
management", "Invenio", "Invenio-RDM" ]
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ installer.sh: .FORCE
test: $(PACKAGE)
#go test -timeout 120h
go test -test.v -run Test01Config
go test -test.v -run Test01Query
go test -timeout 2h -ids testdata/test_record_ids.json -run Test02GetRecord
go test -timeout 2h -ids testdata/test_record_ids.json -run Test03Harvest
#go test -test.v -run Test01Query
#go test -timeout 2h -ids testdata/test_record_ids.json -run Test02GetRecord
#go test -timeout 2h -ids testdata/test_record_ids.json -run Test03Harvest
go test -timeout 2h -run Test01GetRecordIds
go test -timeout 2h -run Test01GetModifiedIds

Expand Down Expand Up @@ -117,6 +117,7 @@ install: build
@echo ""
@echo "Make sure $(PREFIX)/bin is in your PATH"
@echo "Installing man page in $(PREFIX)/man"
@mkdir -p $(PREFIX)/man/man1
@for FNAME in $(MAN_PAGES); do if [ -f "./man/man1/$${FNAME}" ]; then cp -v "./man/man1/$${FNAME}" "$(PREFIX)/man/man1/$${FNAME}"; fi; done
@echo ""
@echo "Make sure $(PREFIX)/man is in your MANPATH"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This tools take an EPrint record in a dataset collection and returns an abbrevia
- An Invenio RDM deployment
- To building the Go based software and documentation
- git
- Go >= 1.20.7
- Go >= 1.22.1
- Make (e.g. GNU Make)
- Pandoc >= 3
- For harvesting content
Expand Down
4 changes: 2 additions & 2 deletions about.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<section>
<h1 id="about-this-software">About this software</h1>
<h2 id="irdmtools-0.0.76">irdmtools 0.0.76</h2>
<h2 id="irdmtools-0.0.78">irdmtools 0.0.78</h2>
<h3 id="authors">Authors</h3>
<ul>
<li>R. S. Doiel</li>
Expand Down Expand Up @@ -60,7 +60,7 @@ <h3 id="operating-systems">Operating Systems</h3>
</ul>
<h3 id="software-requiremets">Software Requiremets</h3>
<ul>
<li>Go &gt;= 1.22</li>
<li>Go &gt;= 1.22.1</li>
<li>PostgreSQL &gt;= 16</li>
<li>PostgREST &gt;= 12</li>
<li>Pandoc &gt;= 3</li>
Expand Down
6 changes: 3 additions & 3 deletions about.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ authors:
orcid: "https://orcid.org/0000-0001-9266-5146"

repository-code: "https://github.com/caltechlibrary/irdmtools"
version: 0.0.76
version: 0.0.78
license-url: "https://caltechlibrary.github.io/irdmtools/LICENSE"
keywords: [ "institutional repository", "data
management", "Invenio", "Invenio-RDM" ]
Expand All @@ -24,7 +24,7 @@ management", "Invenio", "Invenio-RDM" ]
About this software
===================

## irdmtools 0.0.76
## irdmtools 0.0.78

### Authors

Expand Down Expand Up @@ -59,7 +59,7 @@ systems. Current implementation targets Invenio-RDM.

### Software Requiremets

- Go &gt;= 1.22
- Go &gt;= 1.22.1
- PostgreSQL &gt;= 16
- PostgREST &gt;= 12
- Pandoc &gt;= 3
Expand Down
34 changes: 15 additions & 19 deletions citation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strings"

// Caltech Library Packages
"github.com/caltechlibrary/simplified"
"github.com/caltechlibrary/eprinttools"
"github.com/caltechlibrary/simplified"
)

// irdmtools provides a means of turning an EPrint or RDM record into a datastructure suitable
Expand Down Expand Up @@ -139,7 +139,6 @@ type Citation struct {
// Chapters from book
Chapters string `json:"chapters,omitempty" xml:"chapters,omitempty" yaml:"chapters,omitempty"`


// Series/SeriesNumber values from CaltechAUTHORS (mapped from custom fields)
Series string `json:"series,omitempty" xml:"series,omitempty" yaml:"series,omitempty"`
SeriesNumber string `json:"series_number,omitempty" xml:"series_number,omitempty" yaml:"series_number,omitempty"`
Expand All @@ -151,7 +150,6 @@ type Citation struct {
// Pages
Pages string `json:"pages,omitempty" xml:"pages,omitempty" yaml:"pages,omitempty"`


// ThesisDegree for thesis types
ThesisDegree string `json:"thesis_degree,omitempty" xml:"thesis_degree,omitempty" yaml:"thesis_degree,omitempty"`

Expand Down Expand Up @@ -255,19 +253,19 @@ func (cite *Citation) CrosswalkRecord(cName string, cID string, citeUsingURL str
if rec.Files != nil {
// In RDM the "default preview" is the primary document (e.g. article, thesis, etc) of record.
defaultPreview := rec.Files.DefaultPreview
for _, entry := range rec.Files.Entries {
for _, entry := range rec.Files.Entries {
// Handle the case where default preview isn't set and treat the first file as the one
// serving as a default.
if defaultPreview == "" {
defaultPreview = entry.Key
}
if defaultPreview == entry.Key {
cite.PrimaryObject = map[string]interface{}{
"basename": defaultPreview,
"url": fmt.Sprintf("%s/records/%s/files/%s", repoURL, rec.ID, defaultPreview),
}
}
}
if defaultPreview == "" {
defaultPreview = entry.Key
}
if defaultPreview == entry.Key {
cite.PrimaryObject = map[string]interface{}{
"basename": defaultPreview,
"url": fmt.Sprintf("%s/records/%s/files/%s", repoURL, rec.ID, defaultPreview),
}
}
}
}

// Now crosswalk the rest of the citation from the simplified record.
Expand Down Expand Up @@ -481,7 +479,6 @@ func (ca *CitationAgent) ToString() string {
return fmt.Sprintf("%s, %s", ca.FamilyName, ca.LivedName)
}


// CrosswalkEPrint takes an eprinttools.EPrint record and return maps the values into the Citation.
func (cite *Citation) CrosswalkEPrint(cName string, cID string, citeUsingURL string, eprint *eprinttools.EPrint) error {
// map repository required fields, everything else is derived from crosswalk
Expand All @@ -504,7 +501,6 @@ func (cite *Citation) CrosswalkEPrint(cName string, cID string, citeUsingURL str
}
}


// from the eprint table
cite.Title = eprint.Title
cite.Type = eprint.Type
Expand All @@ -526,7 +522,7 @@ func (cite *Citation) CrosswalkEPrint(cName string, cID string, citeUsingURL str
cite.ISSN = eprint.ISSN
cite.DOI = eprint.DOI
cite.PMCID = eprint.PMCID

if eprint.ThesisType != "" {
cite.ThesisType = eprint.ThesisType
}
Expand Down Expand Up @@ -611,9 +607,9 @@ func (cite *Citation) CrosswalkEPrint(cName string, cID string, citeUsingURL str
cite.Contributor = append(cite.Contributor, agent)
}
}
}
}

// map in Thesis Adivors
// map in Thesis Adivors
if eprint.ThesisAdvisor.Length() > 0 {
for i := 0; i < eprint.ThesisAdvisor.Length(); i++ {
creator := eprint.ThesisAdvisor.IndexOf(i)
Expand Down
26 changes: 13 additions & 13 deletions citation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ func TestCitationCrosswalkRecord(t *testing.T) {
}

item := &Citation{}
if err := item.CrosswalkRecord("rdm_website", "10.5281-inveniordm.1234", "", rec); err != nil {
if err := item.CrosswalkRecord("rdm_website", "10.5281-inveniordm.1234", "", "", rec); err != nil {
t.Error(err)
}
expectedS := "rdm_website"
if item.Repository != expectedS {
t.Errorf("incorrect repository, expected %q, got %q", expectedS, item.Repository)
if item.Collection != expectedS {
t.Errorf("incorrect repository, expected %q, got %q", expectedS, item.Collection)
}
expectedS = "10.5281-inveniordm.1234"
if item.RepositoryRecordID != expectedS {
t.Errorf("incorrect repo. rec. id, expected %q, got %q", expectedS, item.RepositoryRecordID)
if item.CollectionID != expectedS {
t.Errorf("incorrect repo. rec. id, expected %q, got %q", expectedS, item.CollectionID)
}
expectedS = "InvenioRDM"
if item.Title != expectedS {
Expand Down Expand Up @@ -208,17 +208,17 @@ func TestCrosswalkCreatorToCitationAgent(t *testing.T) {
contributorList := []*simplified.Creator{
&simplified.Creator{
PersonOrOrg: &simplified.PersonOrOrg{
Name: "Nielsen, Lars Holm",
Name: "Nielsen, Lars Holm",
FamilyName: "Nielsen",
GivenName: "Lars Holm",
Type: "person",
GivenName: "Lars Holm",
Type: "person",
Identifiers: []*simplified.Identifier{
&simplified.Identifier{
Scheme: "orcid",
Scheme: "orcid",
Identifier: "0000-0001-8135-3489",
},
&simplified.Identifier{
Scheme: "clpid",
Scheme: "clpid",
Identifier: "Nielsen-Lars-Holm",
},
},
Expand All @@ -228,7 +228,7 @@ func TestCrosswalkCreatorToCitationAgent(t *testing.T) {
},
Affiliations: []*simplified.Affiliation{
&simplified.Affiliation{
ID: "01ggx415",
ID: "01ggx415",
Name: "CERN",
},
},
Expand All @@ -238,8 +238,8 @@ func TestCrosswalkCreatorToCitationAgent(t *testing.T) {
&CitationAgent{
FamilyName: "Nielsen",
LivedName: "Lars Holm",
ORCID: "0000-0001-8135-3489",
CLpid: "Nielsen-Lars-Holm",
ORCID: "0000-0001-8135-3489",
CLpid: "Nielsen-Lars-Holm",
},
}
expectedRole := "editor"
Expand Down
43 changes: 28 additions & 15 deletions cmd/doi2rdm/doi2rdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
# SYNOPSIS
{app_name} [OPTIONS] [OPTIONS_YAML] crossref|datacite DOI
{app_name} [OPTIONS] [OPTIONS_YAML] [crossref|datacite] DOI
# DESCRIPTION
Expand Down Expand Up @@ -92,26 +92,35 @@ migrating content from CrossRef to RDM.
# EXAMPLES
Save the default YAML options to a file. You can customize this to match your
vocabulary requirements in your RDM deployment.
~~~
{app_name} -show-yaml >options.yaml
~~~
Example generating a JSON document for a single DOI. The resulting
text file is called "article.json". In this example "options.yaml"
is the configuration file for setup for your RDM instance.
is the configuration file for setup for your RDM instance. It'll first
check CrossRef then DataCite.
~~~
{app_name} options.yaml crossref "10.1021/acsami.7b15651" >article.json
{app_name} options.yaml "10.1021/acsami.7b15651" >article.json
~~~
Check to see the difference from the saved "article.json" and
the current metadata retrieved from CrossRef.
the current metadata retrieved from CrossRef or DataCite.
~~~
{app_name} -diff article.json crossref doi2rdm.yaml "10.1021/acsami.7b15651
{app_name} -diff article.json options.yaml "10.1021/acsami.7b15651"
~~~
Save the default YAML options to a file.
Example getting metadata for an arXiv record from DataCite
~~~
{app_name} -show-yaml >options.yaml
{app_name} options.yaml "arXiv:2312.07215"
~~~
`
)

Expand Down Expand Up @@ -166,12 +175,15 @@ func main() {
app.Cfg.Debug = false
}

if len(args) < 2 {
fmt.Fprintln(eout, "expected a 'crossref' or 'datacite' and single DOI on the command line")
os.Exit(1)
}
optionsFName, dataSource, doi := "", "", ""
if len(args) > 2 {
if len(args) < 1 {
fmt.Fprintln(eout, "expected a least a single DOI on the command line")
os.Exit(1)
} else if len(args) == 1 {
optionsFName, dataSource, doi = "", "", args[0]
} else if len(args) == 2 {
optionsFName, dataSource, doi = args[0], "", args[1]
} else if len(args) > 2 {
optionsFName, dataSource, doi = args[0], args[1], args[2]
} else {
dataSource, doi = args[0], args[1]
Expand All @@ -182,14 +194,15 @@ func main() {
fmt.Fprintf(eout, "%s\n", err)
os.Exit(1)
}
/*
case "datacite":
if err := app.RunDataCiteToRdm(in, out, eout, optionsFName, doi, diffFName); err != nil {
fmt.Fprintf(eout, "%s\n", err)
os.Exit(1)
}
*/
default:
fmt.Fprintf(eout, "%q is not supported service to retrive DOI metadata\n", dataSource)
if err := app.RunDoiToRdmCombined(in, out, eout, optionsFName, doi, diffFName); err != nil {
fmt.Fprintf(eout, "%s\n", err)
os.Exit(1)
}
}
}
11 changes: 8 additions & 3 deletions cmd/rdm2eprint/rdm2eprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ specified by C_NAME.
-pipeline
: read from standard input and write crosswalk to standard out.
-latest
: only convert record(s) if latest version.
# EXAMPLE
Example generating a EPRINT JSON document from RDM would use the following
Expand Down Expand Up @@ -146,6 +149,7 @@ func main() {
releaseDate := irdmtools.ReleaseDate
releaseHash := irdmtools.ReleaseHash
fmtHelp := irdmtools.FmtHelp
latestVersions := false

showHelp, showVersion, showLicense := false, false, false
configFName, debug, asXML := "", false, false
Expand All @@ -159,6 +163,7 @@ func main() {
flag.StringVar(&idsFName, "ids", idsFName, "read ids from a file")
flag.StringVar(&cName, "harvest", cName, "harvest JSON eprint records into the dataset collection.")
flag.BoolVar(&pipeline, "pipeline", pipeline, "read from standard input, crosswalk and write to standard out")
flag.BoolVar(&latestVersions, "latest", latestVersions, "only convert record if the latest version")

flag.Parse()
rdmids := flag.Args()
Expand Down Expand Up @@ -196,20 +201,20 @@ func main() {
os.Exit(1)
}
if cName != "" {
if err := app.RunHarvest(os.Stdin, os.Stdout, os.Stderr, cName, rdmids); err != nil {
if err := app.RunHarvest(os.Stdin, os.Stdout, os.Stderr, cName, rdmids, latestVersions); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
os.Exit(0)
}
if pipeline {
if err := app.RunPipeline(os.Stdin, os.Stdout, os.Stderr, asXML); err != nil {
if err := app.RunPipeline(os.Stdin, os.Stdout, os.Stderr, asXML, latestVersions); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
os.Exit(0)
}
if err := app.Run(os.Stdin, os.Stdout, os.Stderr, rdmids, asXML); err != nil {
if err := app.Run(os.Stdin, os.Stdout, os.Stderr, rdmids, asXML, latestVersions); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
Expand Down
Loading

0 comments on commit d803aec

Please sign in to comment.