Skip to content

Commit

Permalink
Do ToDo per review
Browse files Browse the repository at this point in the history
  • Loading branch information
qqmyers committed Jul 15, 2022
1 parent 3d8e76f commit b3292fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/GlobalId.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,27 @@ public static boolean verifyImportCharacters(String pidParam) {

return m.matches();
}

/**
* Convenience method to get the internal form of a PID string when it may be in
* the https:// or http:// form ToDo -refactor class to allow creating a
* GlobalID from any form (which assures it has valid syntax) and then have methods to get
* the form you want.
*
* @param pidUrlString - a string assumed to be a valid PID in some form
* @return the internal form as a String
*/
public static String getInternalFormOfPID(String pidUrlString) {
String pidString = pidUrlString;
if(pidUrlString.startsWith(GlobalId.DOI_RESOLVER_URL)) {
pidString = pidUrlString.replace(GlobalId.DOI_RESOLVER_URL, (GlobalId.DOI_PROTOCOL + ":"));
} else if(pidUrlString.startsWith(GlobalId.HDL_RESOLVER_URL)) {
pidString = pidUrlString.replace(GlobalId.HDL_RESOLVER_URL, (GlobalId.HDL_PROTOCOL + ":"));
} else if(pidUrlString.startsWith(GlobalId.HTTP_DOI_RESOLVER_URL)) {
pidString = pidUrlString.replace(GlobalId.HTTP_DOI_RESOLVER_URL, (GlobalId.DOI_PROTOCOL + ":"));
} else if(pidUrlString.startsWith(GlobalId.HTTP_HDL_RESOLVER_URL)) {
pidString = pidUrlString.replace(GlobalId.HTTP_HDL_RESOLVER_URL, (GlobalId.HDL_PROTOCOL + ":"));
}
return pidString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,7 @@ public boolean generateBag(OutputStream outputStream) throws Exception {
aggregation = (JsonObject) new JsonParser().parse(oremapObject.getJsonObject(JsonLDTerm.ore("describes").getLabel()).toString());

String pidUrlString = aggregation.get("@id").getAsString();
String pidString=pidUrlString;
//ToDo - put this conversion in GlobalId
if(pidUrlString.startsWith(GlobalId.DOI_RESOLVER_URL)) {
pidString = pidUrlString.replace(GlobalId.DOI_RESOLVER_URL, (GlobalId.DOI_PROTOCOL + ":"));
} else if(pidUrlString.startsWith(GlobalId.HDL_RESOLVER_URL)) {
pidString = pidUrlString.replace(GlobalId.HDL_RESOLVER_URL, (GlobalId.HDL_PROTOCOL + ":"));
}
String pidString=GlobalId.getInternalFormOfPID(pidUrlString);
bagID = pidString + "v."
+ aggregation.get(JsonLDTerm.schemaOrg("version").getLabel()).getAsString();

Expand Down

0 comments on commit b3292fa

Please sign in to comment.