From a98c799c8b7253612c1de7a5bdbead527970c68d Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Fri, 29 Sep 2023 12:43:03 +0200 Subject: [PATCH] added new field: suggestedAcknowledgements --- .../importer/CommunityImporterController.java | 3 +- .../importer/CommunityImporterService.java | 23 +++++++++-- .../openaire/community/model/DbCommunity.java | 12 ++++++ .../utils/CommunityMappingUtils.java | 6 ++- .../context/ContextApiController.java | 25 ++++++++++++ .../openaire/context/ContextMappingUtils.java | 4 +- .../src/main/resources/global.properties | 2 +- .../main/resources/sql/community-schema.sql | 3 +- .../model/community/CommunityDetails.java | 13 +++++++ .../model/context/IISConfigurationEntry.java | 39 +++++++++++++++++++ 10 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/context/IISConfigurationEntry.java diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterController.java index b5ae7f11..3f7cefb6 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterController.java @@ -32,7 +32,8 @@ import io.swagger.v3.oas.annotations.tags.Tag; @Tag(name = "OpenAIRE Communities: Migration API", description = "OpenAIRE Communities: Migration API") public class CommunityImporterController extends AbstractDnetController { - public final static Set communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020"); + // public final static Set communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020"); + public final static Set communityBlackList = Sets.newHashSet(); @Autowired private CommunityImporterService importer; diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java index ffa1a014..3a9bacd3 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java @@ -77,6 +77,7 @@ public class CommunityImporterService { private final static String CPROFILE_SDG = "sdg"; private final static String CPROFILE_ADVANCED_CONSTRAINT = "advancedConstraints"; private final static String CPROFILE_REMOVE_CONSTRAINT = "removeConstraints"; + private final static String CPROFILE_SUGGESTED_ACKNOWLEDGEMENT = "suggestedAcknowledgement"; // community project private final static String CPROJECT_FUNDER = "funder"; @@ -173,7 +174,7 @@ public class CommunityImporterService { if (ns != null) { p.setOpenaireId(ns + "::" + Hashing.md5(p.getGrantId())); } else { - log.error("EC project not in the db: " + p.getGrantId()); + log.warn("EC project not in the db: " + p.getGrantId()); } } else if (p.getFunder().equalsIgnoreCase("NSF")) { p.setOpenaireId("nsf_________::" + Hashing.md5(p.getGrantId())); @@ -249,7 +250,14 @@ public class CommunityImporterService { details.setClaim(CommunityClaimType.all); details.setDescription(asCsv(CSUMMARY_DESCRIPTION, c.getParams())); details.setLogoUrl(asCsv(CSUMMARY_LOGOURL, c.getParams())); - details.setStatus(CommunityStatus.valueOf(firstValue(CSUMMARY_STATUS, c.getParams()))); + + final String status = firstValue(CSUMMARY_STATUS, c.getParams()); + if (StringUtils.isNotBlank(status)) { + details.setStatus(CommunityStatus.valueOf(status)); + } else { + details.setStatus(CommunityStatus.hidden); + } + details.setName(asCsv(CSUMMARY_NAME, c.getParams())); details.setName(c.getLabel()); details.setZenodoCommunity(asCsv(CSUMMARY_ZENODOC, c.getParams())); @@ -260,6 +268,8 @@ public class CommunityImporterService { details.setAdvancedConstraints(SelectionCriteria.fromJson(asCsv(CPROFILE_ADVANCED_CONSTRAINT, c.getParams()))); // In the map the string is the serialization of the json representing the selection criteria so it is a valid json details.setRemoveConstraints(SelectionCriteria.fromJson(asCsv(CPROFILE_REMOVE_CONSTRAINT, c.getParams()))); + details.setSuggestedAcknowledgements(splitValues(asValues(CPROFILE_SUGGESTED_ACKNOWLEDGEMENT, c.getParams()), CSV_DELIMITER)); + try { details.setCreationDate(CommunityMappingUtils.asLocalDateTime(asCsv(CPROFILE_CREATIONDATE, c.getParams()))); } catch (final Exception e) { @@ -330,8 +340,13 @@ public class CommunityImporterService { } private static String getDecodedUrl(final String encoded_url) { - if (encoded_url == null) { return encoded_url; } - return new String(Base64.getDecoder().decode(encoded_url)); + if (encoded_url == null || encoded_url.startsWith("http")) { return encoded_url; } + try { + return new String(Base64.getDecoder().decode(encoded_url)); + } catch (final Exception e) { + log.warn("Invalid base64: " + encoded_url); + return encoded_url; + } } private static List splitValues(final Stream stream, final String separator) { diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DbCommunity.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DbCommunity.java index 68b7dafc..0fd68712 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DbCommunity.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DbCommunity.java @@ -110,6 +110,10 @@ public class DbCommunity implements Serializable { @Column(name = "logo_url") private String logoUrl; + @Type(type = "string-array") + @Column(name = "suggested_acknowledgements", columnDefinition = "text[]") + private String[] suggestedAcknowledgements; + public String getId() { return id; } @@ -254,4 +258,12 @@ public class DbCommunity implements Serializable { this.logoUrl = logoUrl; } + public String[] getSuggestedAcknowledgements() { + return suggestedAcknowledgements; + } + + public void setSuggestedAcknowledgements(final String[] suggestedAcknowledgements) { + this.suggestedAcknowledgements = suggestedAcknowledgements; + } + } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/utils/CommunityMappingUtils.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/utils/CommunityMappingUtils.java index d67aacea..78bec420 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/utils/CommunityMappingUtils.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/utils/CommunityMappingUtils.java @@ -60,6 +60,7 @@ public class CommunityMappingUtils { c.setRemoveConstraints(details.getRemoveConstraints()); c.setMainZenodoCommunity(details.getZenodoCommunity()); c.setOtherZenodoCommunities(toStringArray(details.getOtherZenodoCommunities())); + c.setSuggestedAcknowledgements(toStringArray(details.getSuggestedAcknowledgements())); c.setCreationDate(ObjectUtils.firstNonNull(details.getCreationDate(), LocalDateTime.now())); c.setLastUpdateDate(LocalDateTime.now()); return c; @@ -124,6 +125,7 @@ public class CommunityMappingUtils { details.setSdg(Arrays.asList(c.getSdg())); details.setSubjects(Arrays.asList(c.getSubjects())); details.setOtherZenodoCommunities(Arrays.asList(c.getOtherZenodoCommunities())); + details.setSuggestedAcknowledgements(Arrays.asList(c.getSuggestedAcknowledgements())); return details; } @@ -228,13 +230,15 @@ public class CommunityMappingUtils { } public static LocalDateTime asLocalDateTime(final String s) { + if (StringUtils.isBlank(s)) { return null; } + for (final String pattern : DATE_PATTERN) { try { final Date res = DateUtils.parseDate(s, pattern); if (res != null) { return asLocalDateTime(res); } } catch (final ParseException e) {} } - log.error("Invalid Date: " + s); + log.warn("Invalid Date: " + s); return null; } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextApiController.java index fdf6ace1..f3e2564d 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextApiController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextApiController.java @@ -1,5 +1,6 @@ package eu.dnetlib.openaire.context; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -25,6 +26,7 @@ import eu.dnetlib.openaire.exporter.model.community.SubCommunity; import eu.dnetlib.openaire.exporter.model.context.CategorySummary; import eu.dnetlib.openaire.exporter.model.context.ConceptSummary; import eu.dnetlib.openaire.exporter.model.context.ContextSummary; +import eu.dnetlib.openaire.exporter.model.context.IISConfigurationEntry; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; @@ -99,6 +101,29 @@ public class ContextApiController extends AbstractDnetController { } } + @RequestMapping(value = "/context/iis/conf/{contextId}", produces = { + "application/json" + }, method = RequestMethod.GET) + @Operation(summary = "return a list of entries for IIS", description = "return a list of entries for IIS") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public List getIISConfiguration( + @PathVariable final String contextId) throws CommunityException { + + try { + // TODO, see ticket https://support.openaire.eu/issues/9019 + // ritornare le informazioni solo dei context (root) e delle subCommunities + final List res = new ArrayList<>(); + + return res; + } catch (final Throwable e) { + log.error(e); + throw new CommunityException(e); + } + } + @RequestMapping(value = "/context/category/{categoryId}", produces = { "application/json" }, method = RequestMethod.GET) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextMappingUtils.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextMappingUtils.java index 8e001050..c7c0b0d1 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextMappingUtils.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextMappingUtils.java @@ -61,13 +61,15 @@ public class ContextMappingUtils { } private static Date asDate(final String s) { + if (StringUtils.isBlank(s)) { return null; } + for (final String pattern : DATE_PATTERN) { try { final Date res = DateUtils.parseDate(s, pattern); if (res != null) { return res; } } catch (final ParseException e) {} } - log.error("Invalid Date: " + s); + log.warn("Invalid Date: " + s); return null; } diff --git a/apps/dnet-exporter-api/src/main/resources/global.properties b/apps/dnet-exporter-api/src/main/resources/global.properties index 4f032602..8368c3e9 100644 --- a/apps/dnet-exporter-api/src/main/resources/global.properties +++ b/apps/dnet-exporter-api/src/main/resources/global.properties @@ -1,6 +1,6 @@ +services.is.protocol = http services.is.host = localhost services.is.port = 8280 -services.is.protocol = http services.is.context = app services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services diff --git a/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql b/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql index b72b2453..78547410 100644 --- a/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql +++ b/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql @@ -23,7 +23,8 @@ CREATE TABLE communities ( other_zenodo_communities text[], creation_date timestamp NOT NULL DEFAULT now(), last_update timestamp NOT NULL DEFAULT now(), - logo_url text + logo_url text, + suggested_acknowledgements text[] ); CREATE TABLE community_projects ( diff --git a/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/community/CommunityDetails.java b/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/community/CommunityDetails.java index 17ed7971..a55ef2f6 100644 --- a/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/community/CommunityDetails.java +++ b/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/community/CommunityDetails.java @@ -35,6 +35,9 @@ public class CommunityDetails extends CommunitySummary { @Schema(description = "other zenodo communities") private List otherZenodoCommunities; + @Schema(description = "Suggested Acknowledgements") + private List suggestedAcknowledgements; + public CommunityDetails() {} public CommunityDetails(final CommunitySummary summary) { @@ -109,6 +112,14 @@ public class CommunityDetails extends CommunitySummary { this.otherZenodoCommunities = otherZenodoCommunities; } + public List getSuggestedAcknowledgements() { + return suggestedAcknowledgements; + } + + public void setSuggestedAcknowledgements(final List suggestedAcknowledgements) { + this.suggestedAcknowledgements = suggestedAcknowledgements; + } + @Override public String toString() { final StringBuilder builder = new StringBuilder(); @@ -146,6 +157,8 @@ public class CommunityDetails extends CommunitySummary { .append(status) .append(",\n\tzenodoCommunity = ") .append(zenodoCommunity) + .append(",\n\tsuggestedAcknowledgements = ") + .append(suggestedAcknowledgements) .append("\n]"); return builder.toString(); } diff --git a/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/context/IISConfigurationEntry.java b/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/context/IISConfigurationEntry.java new file mode 100644 index 00000000..26c9f75c --- /dev/null +++ b/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/context/IISConfigurationEntry.java @@ -0,0 +1,39 @@ +package eu.dnetlib.openaire.exporter.model.context; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class IISConfigurationEntry implements Serializable { + + private static final long serialVersionUID = -1470248262314248937L; + + private String id; + private String label; + private List params = new ArrayList<>(); + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getLabel() { + return label; + } + + public void setLabel(final String label) { + this.label = label; + } + + public List getParams() { + return params; + } + + public void setParams(final List params) { + this.params = params; + } + +}