Skip to content

Commit

Permalink
Merge pull request #8504 from GlobalDataverseCommunityConsortium/IQSS…
Browse files Browse the repository at this point in the history
…/8503-make_iconURL_optional

IQSS/8503 make icon url optional
  • Loading branch information
kcondon authored Mar 17, 2022
2 parents 9bf414e + 993f85e commit af53452
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public static String getLicenseURI(DatasetVersion dsv) {

public static String getLicenseIcon(DatasetVersion dsv) {
License license = dsv.getTermsOfUseAndAccess().getLicense();
return license != null ? license.getIconUrl().toString() : null;
return license != null && license.getIconUrl() != null ? license.getIconUrl().toString() : null;
}

public static String getLicenseDescription(DatasetVersion dsv) {
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/license/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ public License(String name, String shortDescription, URI uri, URI iconUrl, boole
this.name = name;
this.shortDescription = shortDescription;
this.uri = uri.toASCIIString();
this.iconUrl = iconUrl.toASCIIString();
if (iconUrl != null) {
this.iconUrl = iconUrl.toASCIIString();
} else {
this.iconUrl = null;
}
this.active = active;
isDefault = false;
}
Expand Down Expand Up @@ -118,6 +122,9 @@ public void setUri(URI uri) {
}

public URI getIconUrl() {
if (iconUrl == null) {
return null;
}
try {
return new URI(iconUrl);
} catch (URISyntaxException e) {
Expand All @@ -134,7 +141,11 @@ public void setShortDescription(String shortDescription) {
}

public void setIconUrl(URI iconUrl) {
this.iconUrl = iconUrl.toASCIIString();
if (iconUrl != null) {
this.iconUrl = iconUrl.toASCIIString();
} else {
this.iconUrl = null;
}
}

public boolean isActive() {
Expand Down Expand Up @@ -166,7 +177,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
License license = (License) o;
return active == license.active && id.equals(license.id) && name.equals(license.name) && shortDescription.equals(license.shortDescription) && uri.equals(license.uri) && iconUrl.equals(license.iconUrl);
return active == license.active && id.equals(license.id) && name.equals(license.name) && shortDescription.equals(license.shortDescription) && uri.equals(license.uri) && Objects.equals(iconUrl, license.iconUrl);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public static JsonObjectBuilder json(License license) {
.add("name", license.getName())
.add("shortDescription", license.getShortDescription())
.add("uri", license.getUri().toString())
.add("iconUrl", license.getIconUrl().toString())
.add("iconUrl", license.getIconUrl() == null ? null : license.getIconUrl().toString())
.add("active", license.isActive())
.add("isDefault", license.isDefault());
}
Expand Down

0 comments on commit af53452

Please sign in to comment.