From 54e7bd3dd0d34472fa32c836c9b0df1db1751b60 Mon Sep 17 00:00:00 2001 From: jo-pol Date: Fri, 22 Dec 2023 14:29:46 +0100 Subject: [PATCH] NullPointerException for custom dataset terms --- .../harvard/iq/dataverse/dataset/DatasetUtil.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java index adbd132bce8..f194533d12e 100644 --- a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java @@ -5,6 +5,7 @@ import edu.harvard.iq.dataverse.DatasetField; import edu.harvard.iq.dataverse.DatasetVersion; import edu.harvard.iq.dataverse.FileMetadata; +import edu.harvard.iq.dataverse.GlobalId; import edu.harvard.iq.dataverse.TermsOfUseAndAccess; import edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress; import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; @@ -584,10 +585,18 @@ public static String getLicenseURI(DatasetVersion dsv) { : (dsv.getVersionState().name().equals("DRAFT") ? dsv.getDataverseSiteUrl() + "/api/datasets/:persistentId/versions/:draft/customlicense?persistentId=" - + dsv.getDataset().getGlobalId().asString() + + getPid(dsv) : dsv.getDataverseSiteUrl() + "/api/datasets/:persistentId/versions/" + dsv.getVersionNumber() + "." + dsv.getMinorVersionNumber() + "/customlicense?persistentId=" - + dsv.getDataset().getGlobalId().asString()); + + getPid(dsv)); + } + + private static String getPid(DatasetVersion dsv) { + GlobalId globalId = dsv.getDataset().getGlobalId(); + if (globalId == null) + return "no-doi-yet"; + else + return globalId.asString(); } public static String getLicenseIcon(DatasetVersion dsv) {