Skip to content

Commit

Permalink
avoid spurious log warning for others e.g. isbn
Browse files Browse the repository at this point in the history
these were going through the default check for URLs and failing (not a
url) leading to a warning. The new code should try URL parsing for URLs,
try PID and URL parsing for ones with no type specified, and send the
rest of the identifiers w/o any additional (optional) attributes.
  • Loading branch information
qqmyers committed Sep 17, 2024
1 parent b06e620 commit 41c9b29
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,22 @@ private void writeRelatedIdentifiers(XMLStreamWriter xmlw, DvObject dvObject) th
}
break;
case "URL":
// If a URL is given, split the string to get a schemeUri
try {
URL relatedUrl = new URI(relatedIdentifier).toURL();
String protocol = relatedUrl.getProtocol();
String authority = relatedUrl.getAuthority();
String site = String.format("%s://%s", protocol, authority);
relatedIdentifier = relatedIdentifier.substring(site.length());
attributes.put("schemeURI", site);
} catch (URISyntaxException | MalformedURLException | IllegalArgumentException e) {
// Just an identifier but without a pubIdType we won't include it
logger.warning("Invalid Identifier of type URL: " + relatedIdentifier);
relatedIdentifier = null;
}
break;
default:
case "none":
//Try to identify PIDs and URLs and send them as related identifiers
if (relatedIdentifier != null) {
// See if it is a GlobalID we know
try {
Expand All @@ -1048,8 +1062,14 @@ private void writeRelatedIdentifiers(XMLStreamWriter xmlw, DvObject dvObject) th
} catch (URISyntaxException | MalformedURLException | IllegalArgumentException e) {
// Just an identifier but without a pubIdType we won't include it
logger.warning("Related Identifier found without type: " + relatedIdentifier);
//Won't be sent since pubIdType is null - could also set relatedIdentifier to null
}
}
break;
default:
//Some other valid type - we just send the identifier w/o optional attributes
//To Do - validation for other types?
break;
}
}
if (StringUtils.isNotBlank(relatedIdentifier) && StringUtils.isNotBlank(pubIdType)) {
Expand Down

0 comments on commit 41c9b29

Please sign in to comment.