new_model_for_communities #15

Merged
michele.artini merged 81 commits from new_model_for_communities into master 2023-10-24 08:12:26 +02:00
10 changed files with 121 additions and 9 deletions
Showing only changes of commit a98c799c8b - Show all commits

View File

@ -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<String> communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020");
// public final static Set<String> communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020");
public final static Set<String> communityBlackList = Sets.newHashSet();
@Autowired
private CommunityImporterService importer;

View File

@ -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; }
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<String> splitValues(final Stream<String> stream, final String separator) {

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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<IISConfigurationEntry> 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<IISConfigurationEntry> 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)

View File

@ -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;
}

View File

@ -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

View File

@ -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 (

View File

@ -35,6 +35,9 @@ public class CommunityDetails extends CommunitySummary {
@Schema(description = "other zenodo communities")
private List<String> otherZenodoCommunities;
@Schema(description = "Suggested Acknowledgements")
private List<String> suggestedAcknowledgements;
public CommunityDetails() {}
public CommunityDetails(final CommunitySummary summary) {
@ -109,6 +112,14 @@ public class CommunityDetails extends CommunitySummary {
this.otherZenodoCommunities = otherZenodoCommunities;
}
public List<String> getSuggestedAcknowledgements() {
return suggestedAcknowledgements;
}
public void setSuggestedAcknowledgements(final List<String> 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();
}

View File

@ -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<String> 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<String> getParams() {
return params;
}
public void setParams(final List<String> params) {
this.params = params;
}
}