Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IQSS/8503 make icon url optional #8504

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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