From 7e7ed449b6f06b5488235b5f67c78404e1a94a5c Mon Sep 17 00:00:00 2001 From: Don Mennerich Date: Wed, 9 Mar 2022 12:53:33 -0500 Subject: [PATCH] updating update cmd to change aeon links to hdl link --- cmd/report.go | 17 +++++++++++------ cmd/update-roles.go | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/report.go b/cmd/report.go index 8a9cbd9..e43d2bc 100644 --- a/cmd/report.go +++ b/cmd/report.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "log" "os" + "sort" "time" ) @@ -71,7 +72,7 @@ func GenerateRoleReport(roles map[string]int) { } func HasRole(roles map[string]int, role string) bool { - for k, _ := range roles { + for k := range roles { if k == role { return true } @@ -94,9 +95,8 @@ func GetRoles(chunk []ObjectID, resultsChannel chan map[string]int, worker int, if len(fileVersions) > 0 { for _, fileVersion := range fileVersions { role := fileVersion.UseStatement - if role == "service" { - writer.WriteString(fmt.Sprintf("%s\t%s\n", do.URI, fileVersion.FileURI)) - writer.Flush() + if role == "" { + role = "undefined" } if HasRole(results, role) == true { results[role] = results[role] + 1 @@ -110,7 +110,12 @@ func GetRoles(chunk []ObjectID, resultsChannel chan map[string]int, worker int, } func PrintRoleMap(roles map[string]int) { - for k, v := range roles { - fmt.Printf("%s\t%d\n", k, v) + roleKeys := []string{} + for k := range roles { + roleKeys = append(roleKeys, k) + } + sort.Strings(roleKeys) + for _, k := range roleKeys { + fmt.Printf("%s\t%d\n", k, roles[k]) } } diff --git a/cmd/update-roles.go b/cmd/update-roles.go index 7a36733..f7dda4e 100644 --- a/cmd/update-roles.go +++ b/cmd/update-roles.go @@ -26,14 +26,12 @@ var ( var updateCmd = &cobra.Command{ Use: "update-roles", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("UPDATE ROLES") setClient() updateRoles() }, } func updateRoles() { - fmt.Println("Updating Roles") GetDOIDs() doChunks := getChunks(dos) resultChannel := make(chan []Result) @@ -98,12 +96,14 @@ func updateFileVersionRoles(fvs []aspace.FileVersion) []aspace.FileVersion { for _, fv := range fvs { if fv.UseStatement == "electronic-records-service" { fv.UseStatement = "electronic-records-reading-room" + fv.FileURI = "https://hdl.handle.net/2333.1/material-request-placeholder" newFvs = append(newFvs, fv) continue } if fv.UseStatement == "" || fv.UseStatement == "service" { if aeonMatcher.MatchString(fv.FileURI) == true { fv.UseStatement = "electronic-records-reading-room" + fv.FileURI = "https://hdl.handle.net/2333.1/material-request-placeholder" newFvs = append(newFvs, fv) continue }