Skip to content

Commit

Permalink
Merge pull request #9941 from Recherche-Data-Gouv/9940_fix_signpostin…
Browse files Browse the repository at this point in the history
…g_authors_links

#9940 - fixed various issues with generated urls of authors for signposting
  • Loading branch information
stevenwinship authored Jan 22, 2024
2 parents e8af210 + c0dacb5 commit 8dee2ea
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Two configurable options allow changing the limit for the number of authors or d
import jakarta.json.Json;
import jakarta.json.JsonArrayBuilder;
import jakarta.json.JsonObjectBuilder;
import org.apache.commons.validator.routines.UrlValidator;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -164,12 +166,11 @@ private List<String> getAuthorURLs(boolean limit) {
for (DatasetAuthor da : workingDatasetVersion.getDatasetAuthors()) {
logger.fine(String.format("idtype: %s; idvalue: %s, affiliation: %s; identifierUrl: %s", da.getIdType(),
da.getIdValue(), da.getAffiliation(), da.getIdentifierAsUrl()));
String authorURL = "";
authorURL = getAuthorUrl(da);
String authorURL = getAuthorUrl(da);
if (authorURL != null && !authorURL.isBlank()) {
// return empty if number of visible author more than max allowed
// >= since we're comparing before incrementing visibleAuthorCounter
if (visibleAuthorCounter >= maxAuthors) {
if (limit && visibleAuthorCounter >= maxAuthors) {
authorURLs.clear();
break;
}
Expand Down Expand Up @@ -211,15 +212,22 @@ private String getAuthorsAsString(List<String> datasetAuthorURLs) {
*
*/
private String getAuthorUrl(DatasetAuthor da) {
String authorURL = "";
//If no type and there's a value, assume it is a URL (is this reasonable?)
//Otherise, get the URL using the type and value
if (da.getIdType() != null && !da.getIdType().isBlank() && da.getIdValue()!=null) {
authorURL = da.getIdValue();
} else {
authorURL = da.getIdentifierAsUrl();

final String identifierAsUrl = da.getIdentifierAsUrl();
// First, try to get URL using the type and value
if(identifierAsUrl != null) {
return identifierAsUrl;
}
return authorURL;

final String idValue = da.getIdValue();
UrlValidator urlValidator = new UrlValidator(new String[]{"http", "https"});
// Otherwise, try to use idValue as url if it's valid
if(urlValidator.isValid(idValue)) {
return idValue;
}

// No url found
return null;
}

private JsonArrayBuilder getJsonAuthors(List<String> datasetAuthorURLs) {
Expand Down

0 comments on commit 8dee2ea

Please sign in to comment.