From e751759de9a3a223cbf3ee35bac44686169259c0 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Mon, 26 Sep 2022 12:15:39 +0200 Subject: [PATCH 1/4] [CommunityAPIExtention] adding FOS , SDG and advancedCriteria to the summary. Adding the possibility to add and remove list of projects from the profiles --- .../community/CommunityApiController.java | 133 +++++++++++++ .../openaire/community/CommunityApiCore.java | 174 ++++++++++++++---- .../community/CommunityConstants.java | 3 + .../openaire/community/CommunityDetails.java | 34 ++++ .../community/CommunityMappingUtils.java | 9 + .../CommunityWritableProperties.java | 37 ++++ 6 files changed, 351 insertions(+), 39 deletions(-) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java index c8c6af9a..75ad8fd8 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java @@ -133,6 +133,44 @@ public class CommunityApiController { communityApiCore.removeCommunityProject(id, projectId); } + @RequestMapping(value = "/community/{id}/projectList", produces = { + "application/json" + }, method = RequestMethod.POST) + @Operation(summary = "associate a list of project to the community", + description = "associate a list of project to the community", tags = { + C_PJ, W + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public List addCommunityProjectList( + @PathVariable final String id, + @RequestBody final List projectList) throws CommunityException, CommunityNotFoundException { + + return communityApiCore.addCommunityProjectList(id, projectList); + } + + @RequestMapping(value = "/community/{id}/projectList", produces = { + "application/json" + }, method = RequestMethod.DELETE) + @Operation(summary = "remove a list of projects from the community", + description = "remove a list of projects from the community", tags = { + C_PJ, W + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public void deleteCommunityProjectList( + @PathVariable final String id, + @RequestBody final List projectIdList) throws CommunityException, CommunityNotFoundException { + + communityApiCore.removeCommunityProjectList(id, projectIdList); + } + @RequestMapping(value = "/community/{id}/contentproviders", produces = { "application/json" }, method = RequestMethod.GET) @@ -273,6 +311,101 @@ public class CommunityApiController { return communityApiCore.removeCommunitySubjects(id, subjects); } + @RequestMapping(value = "/community/{id}/fos", produces = { "application/json" }, method = RequestMethod.POST) + @Operation( + summary = "associate a fos to the community", + description = "associate a fos to the community", + tags = { C, W }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) + public CommunityDetails addCommunityFOS( + @PathVariable final String id, + @RequestBody final List subjects) throws CommunityException, CommunityNotFoundException { + + return communityApiCore.addCommunityFOS(id, subjects); + } + + @RequestMapping(value = "/community/{id}/fos", produces = { "application/json" }, method = RequestMethod.DELETE) + @Operation( + summary = "remove fos from a community", + description = "remove fos from a community", + tags = { C, W }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) + public CommunityDetails removeCommunityFOS( + @PathVariable final String id, + @RequestBody final List subjects) throws CommunityException, CommunityNotFoundException { + + return communityApiCore.removeCommunityFOS(id, subjects); + } + + + @RequestMapping(value = "/community/{id}/sdg", produces = { "application/json" }, method = RequestMethod.POST) + @Operation( + summary = "associate a sdg to the community", + description = "associate a sdg to the community", + tags = { C, W }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) + public CommunityDetails addCommunitySDG( + @PathVariable final String id, + @RequestBody final List subjects) throws CommunityException, CommunityNotFoundException { + + return communityApiCore.addCommunitySDG(id, subjects); + } + + @RequestMapping(value = "/community/{id}/sdg", produces = { "application/json" }, method = RequestMethod.DELETE) + @Operation( + summary = "remove sdg from a community", + description = "remove sdg from a community", + tags = { C, W }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) + public CommunityDetails removeCommunitySDG( + @PathVariable final String id, + @RequestBody final List subjects) throws CommunityException, CommunityNotFoundException { + + return communityApiCore.removeCommunitySDG(id, subjects); + } + + @RequestMapping(value = "/community/{id}/advancedConstraint", produces = { "application/json" }, method = RequestMethod.POST) + @Operation( + summary = "the set of constraints to be used to extend the association between result and community", + description = "the set of constraints to be used to extend the association between result and community", + tags = { C, W }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) + public CommunityDetails addAdvancedConstraint( + @PathVariable final String id, + @RequestBody final String advancedConstraint) throws CommunityException, CommunityNotFoundException { + + return communityApiCore.addCommunityAdvancedConstraint(id, advancedConstraint); + } + + @RequestMapping(value = "/community/{id}/advancedConstraint", produces = { "application/json" }, method = RequestMethod.DELETE) + @Operation( + summary = "remove the constraints to extend the association result community from a community", + description = "remove the constraints to extend the association result community from a community", + tags = { C, W }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) + public CommunityDetails removeAdvancedConstraint( + @PathVariable final String id) throws CommunityException, CommunityNotFoundException { + + return communityApiCore.removeCommunityAdvancedConstraint(id); + } @RequestMapping(value = "/community/{id}/zenodocommunities", produces = { "application/json" diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java index bc8c2c18..a07d8ea7 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java @@ -1,35 +1,6 @@ package eu.dnetlib.openaire.community; -import static eu.dnetlib.openaire.community.CommunityConstants.CCONTENTPROVIDER_NAME; -import static eu.dnetlib.openaire.community.CommunityConstants.CCONTENTPROVIDER_OFFICIALNAME; -import static eu.dnetlib.openaire.community.CommunityConstants.CCONTENTPROVIDER_SELCRITERIA; -import static eu.dnetlib.openaire.community.CommunityConstants.CLABEL; -import static eu.dnetlib.openaire.community.CommunityConstants.CONTENTPROVIDERS_ID_SUFFIX; -import static eu.dnetlib.openaire.community.CommunityConstants.CORGANIZATION_LOGOURL; -import static eu.dnetlib.openaire.community.CommunityConstants.CORGANIZATION_NAME; -import static eu.dnetlib.openaire.community.CommunityConstants.CORGANIZATION_WEBSITEURL; -import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_SUBJECT; -import static eu.dnetlib.openaire.community.CommunityConstants.CPROJECT_ACRONYM; -import static eu.dnetlib.openaire.community.CommunityConstants.CPROJECT_FULLNAME; -import static eu.dnetlib.openaire.community.CommunityConstants.CPROJECT_FUNDER; -import static eu.dnetlib.openaire.community.CommunityConstants.CPROJECT_NUMBER; -import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_DESCRIPTION; -import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_LOGOURL; -import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_NAME; -import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_STATUS; -import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_ZENODOC; -import static eu.dnetlib.openaire.community.CommunityConstants.CSV_DELIMITER; -import static eu.dnetlib.openaire.community.CommunityConstants.ID_SEPARATOR; -import static eu.dnetlib.openaire.community.CommunityConstants.OPENAIRE_ID; -import static eu.dnetlib.openaire.community.CommunityConstants.ORGANIZATION_ID_SUFFIX; -import static eu.dnetlib.openaire.community.CommunityConstants.PROJECTS_ID_SUFFIX; -import static eu.dnetlib.openaire.community.CommunityConstants.ZENODOCOMMUNITY_ID_SUFFIX; - -import java.util.Base64; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; +import java.util.*; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; @@ -47,6 +18,8 @@ import com.google.common.collect.Sets; import eu.dnetlib.openaire.common.ISClient; +import static eu.dnetlib.openaire.community.CommunityConstants.*; + @Component @ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true") public class CommunityApiCore {// implements CommunityClient{ @@ -99,6 +72,18 @@ public class CommunityApiCore {// implements CommunityClient{ if (details.getSubjects() != null) { isClient.updateContextParam(id, CPROFILE_SUBJECT, Joiner.on(CSV_DELIMITER).join(details.getSubjects())); + } + if (details.getFos() != null) { + isClient.updateContextParam(id, CPROFILE_FOS, Joiner.on(CSV_DELIMITER).join(details.getFos())); + + } + if (details.getSdg() != null) { + isClient.updateContextParam(id, CPROFILE_SDG, Joiner.on(CSV_DELIMITER).join(details.getSdg())); + + } + if (details.getAdvancedConstraint() != null) { + isClient.updateContextParam(id, CPROFILE_ADVANCED_CONSTRAINT, details.getAdvancedConstraint()); + } if (details.getMainZenodoCommunity() != null) { isClient.updateContextParam(id, CSUMMARY_ZENODOC, details.getMainZenodoCommunity()); @@ -117,40 +102,63 @@ public class CommunityApiCore {// implements CommunityClient{ throw new CommunityException("parameters 'id' and project.communityId must be coherent"); } - final TreeMap projects = getCommunityProjectMap(id); - final String project_id = project.getId(); + return updateProject(id, project); - if (project_id != null && projects.keySet().contains(Integer.valueOf(project_id))) { + } + + private CommunityProject updateProject(String id, CommunityProject project) throws CommunityException, CommunityNotFoundException { + final TreeMap projects = getCommunityProjectMap(id); + String project_id = project.getId(); + + if (project_id != null && projects.keySet().contains(Integer.valueOf(project_id))){ if (project.getName() != null) { isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, CPROJECT_FULLNAME, project.getName()); } - if (project.getAcronym() != null) { + if(project.getAcronym()!= null){ isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, CPROJECT_ACRONYM, project.getAcronym()); } - if (project.getOpenaireId() != null) { + if (project.getOpenaireId() != null){ isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, OPENAIRE_ID, project.getOpenaireId()); } - if (project.getFunder() != null) { + if (project.getFunder() != null){ isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, CPROJECT_FUNDER, project.getFunder()); } - if (project.getGrantId() != null) { + if(project.getGrantId() != null){ isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, CPROJECT_NUMBER, project.getGrantId()); } - } else { + }else { project.setId(nextId(projects != null && !projects.isEmpty() ? projects.lastKey() : 0)); isClient.addConcept(id, id + PROJECTS_ID_SUFFIX, CommunityMappingUtils.asProjectXML(id, project)); } - cc.updateProject(id, project); + cc.updateProject(id, project ); return project; } + public List addCommunityProjectList(final String id, final List projectList) throws CommunityException, CommunityNotFoundException { + if(projectList == null || projectList.size() == 0){ + throw new CommunityException("parameter 'projectList' must be present and should contain at least one project"); + } + if (!StringUtils.equalsIgnoreCase(id, projectList.get(0).getCommunityId())) { + throw new CommunityException("parameters 'id' and project.communityId must be coherent"); + } + + List projects = new ArrayList(); + + for(CommunityProject project : projectList){ + projects.add(updateProject(id, project)); + } + + + return projects; + } + private String nextId(final Integer id) { return String.valueOf(id + 1); } @@ -164,6 +172,12 @@ public class CommunityApiCore {// implements CommunityClient{ cc.removeFromCategory(id, PROJECTS_ID_SUFFIX, String.valueOf(projectId)); } + public void removeCommunityProjectList(final String id, final List projectIdList) throws CommunityException, CommunityNotFoundException { + for(Integer projectId: projectIdList){ + removeCommunityProject(id, projectId); + } + } + public List getCommunityContentproviders(final String id) throws CommunityException, CommunityNotFoundException { cc.getCommunity(id); // ensure the community exists. return cc.getCommunityInfo(id, CONTENTPROVIDERS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityDataprovider(id, c)); @@ -258,6 +272,88 @@ public class CommunityApiCore {// implements CommunityClient{ return cd; } + public CommunityDetails addCommunityFOS(final String id, final List foss) throws CommunityException, CommunityNotFoundException { + + final CommunityDetails cd = new CommunityDetails(); + + final Set current = Sets.newHashSet(cc.getCommunity(id).getFos()); + + current.addAll(foss); + + cd.setFos(Lists.newArrayList(current)); + + setCommunity(id, CommunityWritableProperties.fromDetails(cd)); + + return cd; + } + + public CommunityDetails removeCommunityFOS(final String id, final List foss) throws CommunityException, CommunityNotFoundException { + + final CommunityDetails cd = new CommunityDetails(); + + final Set current = Sets.newHashSet(cc.getCommunity(id).getFos()); + + current.removeAll(foss); + + cd.setFos(Lists.newArrayList(current)); + + setCommunity(id, CommunityWritableProperties.fromDetails(cd)); + + return cd; + } + + public CommunityDetails addCommunitySDG(final String id, final List sdgs) throws CommunityException, CommunityNotFoundException { + + final CommunityDetails cd = new CommunityDetails(); + + final Set current = Sets.newHashSet(cc.getCommunity(id).getSdg()); + + current.addAll(sdgs); + + cd.setFos(Lists.newArrayList(current)); + + setCommunity(id, CommunityWritableProperties.fromDetails(cd)); + + return cd; + } + + public CommunityDetails removeCommunitySDG(final String id, final List sdgs) throws CommunityException, CommunityNotFoundException { + + final CommunityDetails cd = new CommunityDetails(); + + final Set current = Sets.newHashSet(cc.getCommunity(id).getSdg()); + + current.removeAll(sdgs); + + cd.setFos(Lists.newArrayList(current)); + + setCommunity(id, CommunityWritableProperties.fromDetails(cd)); + + return cd; + } + + public CommunityDetails addCommunityAdvancedConstraint(final String id, final String advancedCosntraint) throws CommunityException, CommunityNotFoundException { + + final CommunityDetails cd = cc.getCommunity(id); + + cd.setAdvancedConstraint(advancedCosntraint); + + setCommunity(id, CommunityWritableProperties.fromDetails(cd)); + + return cd; + } + + public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws CommunityException, CommunityNotFoundException { + + final CommunityDetails cd = cc.getCommunity(id); + + cd.setAdvancedConstraint(null); + + setCommunity(id, CommunityWritableProperties.fromDetails(cd)); + + return cd; + } + @CacheEvict(value = "community-cache", allEntries = true) public void removeCommunityZenodoCommunity(final String id, final Integer zenodoCommId) throws CommunityException, CommunityNotFoundException { diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityConstants.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityConstants.java index 9ac100f9..8c11cebf 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityConstants.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityConstants.java @@ -32,6 +32,9 @@ public class CommunityConstants { // community profile public final static String CPROFILE_SUBJECT = "subject"; public final static String CPROFILE_CREATIONDATE = "creationdate"; + public final static String CPROFILE_FOS = "fos"; + public final static String CPROFILE_SDG = "sdg"; + public final static String CPROFILE_ADVANCED_CONSTRAINT = "advancedConstraint"; // community project public final static String CPROJECT_FUNDER = "funder"; diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityDetails.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityDetails.java index 2632267c..712c3702 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityDetails.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityDetails.java @@ -19,6 +19,16 @@ public class CommunityDetails extends CommunitySummary { @Schema(description = "list of subjects (keywords) that characterise this community") private List subjects; + @Schema(description = "list of fos that characterise this community") + private List fos; + + @Schema(description = "list of sdg that characterise this community") + private List sdg; + + @Schema(description = "list of advanced criteria to associate results to this community") + private String advancedConstraint; + + public CommunityDetails() {} public CommunityDetails(final CommunitySummary summary) { @@ -52,4 +62,28 @@ public class CommunityDetails extends CommunitySummary { public void setLastUpdateDate(final Date lastUpdateDate) { this.lastUpdateDate = lastUpdateDate; } + + public List getFos() { + return fos; + } + + public void setFos(List fos) { + this.fos = fos; + } + + public List getSdg() { + return sdg; + } + + public void setSdg(List sdg) { + this.sdg = sdg; + } + + public String getAdvancedConstraint() { + return advancedConstraint; + } + + public void setAdvancedConstraint(String advancedConstraint) { + this.advancedConstraint = advancedConstraint; + } } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java index 271c1cbe..a54bd368 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java @@ -62,6 +62,15 @@ public class CommunityMappingUtils { if (params.containsKey(CPROFILE_SUBJECT)) { p.setSubjects(splitValues(asValues(params.get(CPROFILE_SUBJECT)), CSV_DELIMITER)); } + if (params.containsKey(CPROFILE_FOS)) { + p.setFos(splitValues(asValues(params.get(CPROFILE_FOS)), CSV_DELIMITER)); + } + if (params.containsKey(CPROFILE_SDG)) { + p.setSdg(splitValues(asValues(params.get(CPROFILE_SDG)), CSV_DELIMITER)); + } + if (params.containsKey(CPROFILE_ADVANCED_CONSTRAINT)) { + p.setAdvancedConstraint(asCsv(params.get(CPROFILE_ADVANCED_CONSTRAINT))); + } if (params.containsKey(CPROFILE_CREATIONDATE)){ try { p.setCreationDate(org.apache.commons.lang3.time.DateUtils.parseDate(asCsv(params.get(CPROFILE_CREATIONDATE)), pattern)); diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityWritableProperties.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityWritableProperties.java index ac9723d6..1be9ed90 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityWritableProperties.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityWritableProperties.java @@ -24,6 +24,16 @@ public class CommunityWritableProperties { @Schema(description = "list of subjects (keywords) that characterise this community") private List subjects; + @Schema(description = "list of fos that characterise this community") + private List fos; + + @Schema(description = "list of sdg that characterise this community") + private List sdg; + + @Schema(description = "Advanced constraint for the association of results to the community") + private String advancedConstraint; + + @Schema(description = "status of the community, drives its visibility") private CommunityStatus status; @@ -39,9 +49,36 @@ public class CommunityWritableProperties { p.setSubjects(details.getSubjects()); p.setStatus(details.getStatus()); p.setMainZenodoCommunity(details.getZenodoCommunity()); + p.setFos(details.getFos()); + p.setSdg(details.getSdg()); + p.setAdvancedConstraint(details.getAdvancedConstraint()); return p; } + public List getFos() { + return fos; + } + + public void setFos(List fos) { + this.fos = fos; + } + + public List getSdg() { + return sdg; + } + + public void setSdg(List sdg) { + this.sdg = sdg; + } + + public String getAdvancedConstraint() { + return advancedConstraint; + } + + public void setAdvancedConstraint(String advancedConstraint) { + this.advancedConstraint = advancedConstraint; + } + public String getName() { return name; } -- 2.17.1 From 3549fdebf9eb4db580f91f0d40514075daf643b1 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Mon, 26 Sep 2022 19:06:51 +0200 Subject: [PATCH 2/4] [CommunityAPIExtention] fixed issues --- .../eu/dnetlib/openaire/common/ISClient.java | 2 ++ .../dnetlib/openaire/common/ISClientImpl.java | 22 +++++++++++++++++++ .../community/CommunityApiController.java | 3 ++- .../openaire/community/CommunityApiCore.java | 18 ++++++++------- .../openaire/community/CommunityCommon.java | 19 ++++++++++++++++ .../openaire/community/CommunityDetails.java | 7 +++--- .../community/CommunityMappingUtils.java | 2 +- .../CommunityWritableProperties.java | 9 +++++--- .../src/main/resources/application.properties | 2 +- .../src/main/resources/global.properties | 16 +++++++++----- 10 files changed, 78 insertions(+), 22 deletions(-) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java index 01752de5..6a048867 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java @@ -22,6 +22,8 @@ public interface ISClient { void updateContextParam(String id, String name, String value); + void updateContextParamNoEscape(String id, String name, String value); + void updateContextAttribute(String id, String name, String value); void addConcept(String id, String categoryId, String data); diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java index 3bb72c60..960d437d 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java @@ -117,6 +117,18 @@ public class ISClientImpl implements ISClient { } } + @Override + @CacheEvict(value = { + "context-cache", "context-cache-funder" + }, allEntries = true) + public void updateContextParamNoEscape(final String id, final String name, final String value) { + try { + _quickSeachProfile(getXQueryNoEscape(id, name, value)); + } catch (final ISLookUpException e) { + throw new DsmRuntimeException(String.format("unable update context param [id: %s, name: %s, value: %s]", id, name, value), e); + } + } + @Override @CacheEvict(value = { "context-cache", "context-cache-funder" @@ -211,6 +223,16 @@ public class ISClientImpl implements ISClient { } } + private String getXQueryNoEscape(final String id, final String name, final String value) { + if (StringUtils.isNotBlank(value)) { + return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + + "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with %s", id, name, name, value); + } else { + return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + + "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with ", id, name, name); + } + } + private String getConceptXQuery(final String id, final String name, final String value) { final Escaper esc = XmlEscapers.xmlContentEscaper(); if (StringUtils.isNotBlank(value)) { diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java index 75ad8fd8..bde3672d 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java @@ -10,6 +10,7 @@ import static eu.dnetlib.openaire.common.ExporterConstants.W; import java.util.List; +import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.web.bind.annotation.CrossOrigin; @@ -387,7 +388,7 @@ public class CommunityApiController { @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails addAdvancedConstraint( @PathVariable final String id, - @RequestBody final String advancedConstraint) throws CommunityException, CommunityNotFoundException { + @RequestBody final SelectionCriteria advancedConstraint) throws CommunityException, CommunityNotFoundException { return communityApiCore.addCommunityAdvancedConstraint(id, advancedConstraint); } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java index a07d8ea7..473b84a1 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java @@ -3,6 +3,8 @@ package eu.dnetlib.openaire.community; import java.util.*; import java.util.stream.Collectors; +import com.google.gson.Gson; +import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -82,7 +84,7 @@ public class CommunityApiCore {// implements CommunityClient{ } if (details.getAdvancedConstraint() != null) { - isClient.updateContextParam(id, CPROFILE_ADVANCED_CONSTRAINT, details.getAdvancedConstraint()); + isClient.updateContextParamNoEscape(id, CPROFILE_ADVANCED_CONSTRAINT, ""); } if (details.getMainZenodoCommunity() != null) { @@ -310,7 +312,7 @@ public class CommunityApiCore {// implements CommunityClient{ current.addAll(sdgs); - cd.setFos(Lists.newArrayList(current)); + cd.setSdg(Lists.newArrayList(current)); setCommunity(id, CommunityWritableProperties.fromDetails(cd)); @@ -325,16 +327,16 @@ public class CommunityApiCore {// implements CommunityClient{ current.removeAll(sdgs); - cd.setFos(Lists.newArrayList(current)); + cd.setSdg(Lists.newArrayList(current)); setCommunity(id, CommunityWritableProperties.fromDetails(cd)); return cd; } - public CommunityDetails addCommunityAdvancedConstraint(final String id, final String advancedCosntraint) throws CommunityException, CommunityNotFoundException { + public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint) throws CommunityException, CommunityNotFoundException { - final CommunityDetails cd = cc.getCommunity(id); + final CommunityDetails cd = new CommunityDetails(); cd.setAdvancedConstraint(advancedCosntraint); @@ -345,9 +347,9 @@ public class CommunityApiCore {// implements CommunityClient{ public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws CommunityException, CommunityNotFoundException { - final CommunityDetails cd = cc.getCommunity(id); - - cd.setAdvancedConstraint(null); + final CommunityDetails cd = new CommunityDetails(); + SelectionCriteria sl = new SelectionCriteria(); + cd.setAdvancedConstraint(sl); setCommunity(id, CommunityWritableProperties.fromDetails(cd)); diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java index fde84333..52d4dd40 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java @@ -2,7 +2,9 @@ package eu.dnetlib.openaire.community; import com.google.common.base.Joiner; import com.google.common.collect.Lists; +import com.google.gson.Gson; import eu.dnetlib.openaire.common.ISClient; +import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria; import eu.dnetlib.openaire.context.Category; import eu.dnetlib.openaire.context.Concept; import eu.dnetlib.openaire.context.Context; @@ -199,6 +201,23 @@ public class CommunityCommon { .setValue(Joiner.on(CSV_DELIMITER) .join(community.getSubjects())))); } + if(community.getFos() != null){ + context.getParams() + .replace(CPROFILE_FOS, Arrays.asList(new Param().setName(CPROFILE_FOS) + .setValue(Joiner.on(CSV_DELIMITER) + .join(community.getFos())))); + } + if(community.getSdg() != null){ + context.getParams() + .replace(CPROFILE_SDG, Arrays.asList(new Param().setName(CPROFILE_SDG) + .setValue(Joiner.on(CSV_DELIMITER) + .join(community.getSdg())))); + } + if (community.getAdvancedConstraint() != null) { + context.getParams() + .replace(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param() + .setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(new Gson().toJson(community.getAdvancedConstraint())))); + } if(community.getMainZenodoCommunity() != null){ context.getParams() .replace(CSUMMARY_ZENODOC, Arrays.asList(new Param() diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityDetails.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityDetails.java index 712c3702..7625582a 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityDetails.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityDetails.java @@ -5,6 +5,7 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonAutoDetect; +import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria; import io.swagger.v3.oas.annotations.media.Schema; @JsonAutoDetect @@ -26,7 +27,7 @@ public class CommunityDetails extends CommunitySummary { private List sdg; @Schema(description = "list of advanced criteria to associate results to this community") - private String advancedConstraint; + private SelectionCriteria advancedConstraint; public CommunityDetails() {} @@ -79,11 +80,11 @@ public class CommunityDetails extends CommunitySummary { this.sdg = sdg; } - public String getAdvancedConstraint() { + public SelectionCriteria getAdvancedConstraint() { return advancedConstraint; } - public void setAdvancedConstraint(String advancedConstraint) { + public void setAdvancedConstraint(SelectionCriteria advancedConstraint) { this.advancedConstraint = advancedConstraint; } } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java index a54bd368..24ce0262 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java @@ -69,7 +69,7 @@ public class CommunityMappingUtils { p.setSdg(splitValues(asValues(params.get(CPROFILE_SDG)), CSV_DELIMITER)); } if (params.containsKey(CPROFILE_ADVANCED_CONSTRAINT)) { - p.setAdvancedConstraint(asCsv(params.get(CPROFILE_ADVANCED_CONSTRAINT))); + p.setAdvancedConstraint(SelectionCriteria.fromJson(asCsv(params.get(CPROFILE_ADVANCED_CONSTRAINT)))); } if (params.containsKey(CPROFILE_CREATIONDATE)){ try { diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityWritableProperties.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityWritableProperties.java index 1be9ed90..db6d3e5e 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityWritableProperties.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityWritableProperties.java @@ -4,8 +4,11 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonAutoDetect; +import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria; import io.swagger.v3.oas.annotations.media.Schema; +import javax.persistence.criteria.Selection; + @JsonAutoDetect public class CommunityWritableProperties { @@ -31,7 +34,7 @@ public class CommunityWritableProperties { private List sdg; @Schema(description = "Advanced constraint for the association of results to the community") - private String advancedConstraint; + private SelectionCriteria advancedConstraint; @Schema(description = "status of the community, drives its visibility") @@ -71,11 +74,11 @@ public class CommunityWritableProperties { this.sdg = sdg; } - public String getAdvancedConstraint() { + public SelectionCriteria getAdvancedConstraint() { return advancedConstraint; } - public void setAdvancedConstraint(String advancedConstraint) { + public void setAdvancedConstraint(SelectionCriteria advancedConstraint) { this.advancedConstraint = advancedConstraint; } diff --git a/apps/dnet-exporter-api/src/main/resources/application.properties b/apps/dnet-exporter-api/src/main/resources/application.properties index bde38f76..340eb274 100644 --- a/apps/dnet-exporter-api/src/main/resources/application.properties +++ b/apps/dnet-exporter-api/src/main/resources/application.properties @@ -22,7 +22,7 @@ management.endpoints.web.base-path = / management.endpoints.web.path-mapping.prometheus = metrics management.endpoints.web.path-mapping.health = health - +apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java # ENABLE / DISABLE CONTROLLERS openaire.exporter.enable.dsm = true openaire.exporter.enable.community = true diff --git a/apps/dnet-exporter-api/src/main/resources/global.properties b/apps/dnet-exporter-api/src/main/resources/global.properties index 82988336..6b026841 100644 --- a/apps/dnet-exporter-api/src/main/resources/global.properties +++ b/apps/dnet-exporter-api/src/main/resources/global.properties @@ -1,7 +1,12 @@ -services.is.host = localhost -services.is.port = 8280 -services.is.protocol = http -services.is.context = app +#services.is.host = localhost +services.is.host = dev-openaire.d4science.org +#services.is.port = 8280 +services.is.port = 443 +#services.is.protocol = http +services.is.protocol = https +#services.is.context = app +services.is.context = is +#services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services openaire.exporter.isLookupUrl = ${services.is.baseurl}/isLookUp @@ -15,7 +20,8 @@ openaire.exporter.cxfClientConnectTimeout = 60000 openaire.exporter.cxfClientReceiveTimeout = 120000 # JDBC -openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaireplus +#openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaireplus +openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dev_openaire_8280 openaire.exporter.jdbc.user = dnetapi openaire.exporter.jdbc.pwd = dnetPwd openaire.exporter.jdbc.minIdle = 1 -- 2.17.1 From 2a937cc4aed8cefe09bc5207e9dd42fc337ca184 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Tue, 27 Sep 2022 16:06:31 +0200 Subject: [PATCH 3/4] [CommunityAPIExtention] added bulk deletion and addition for datasouces. Added the possibility to insert a pram in the cntext if it is not already present. Useful not to be forced to modify all the profiles by hand to insert new params for fos, sdg and advancedContraints --- .../eu/dnetlib/openaire/common/ISClient.java | 4 +- .../dnetlib/openaire/common/ISClientImpl.java | 79 +++++++++++++------ .../community/CommunityApiController.java | 38 +++++++++ .../openaire/community/CommunityApiCore.java | 77 +++++++++++++----- .../openaire/community/CommunityCommon.java | 21 +++++ 5 files changed, 172 insertions(+), 47 deletions(-) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java index 6a048867..d4ed2f32 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java @@ -20,9 +20,7 @@ public interface ISClient { Map getContextMap(final List type) throws IOException; - void updateContextParam(String id, String name, String value); - - void updateContextParamNoEscape(String id, String name, String value); + void updateContextParam(String id, String name, String value, boolean toEscape); void updateContextAttribute(String id, String name, String value); diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java index 960d437d..67397331 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java @@ -105,28 +105,38 @@ public class ISClientImpl implements ISClient { } } + @Override @CacheEvict(value = { "context-cache", "context-cache-funder" }, allEntries = true) - public void updateContextParam(final String id, final String name, final String value) { - try { - _quickSeachProfile(getXQuery(id, name, value)); - } catch (final ISLookUpException e) { - throw new DsmRuntimeException(String.format("unable update context param [id: %s, name: %s, value: %s]", id, name, value), e); + public void updateContextParam(final String id, final String name, final String value, boolean toEscape) { + if(getSize(id, name) > 0){ + try { + _quickSeachProfile(getXQuery(id, name, value, toEscape)); + } catch (final ISLookUpException e) { + throw new DsmRuntimeException(String.format("unable to update context param [id: %s, name: %s, value: %s]", id, name, value), e); + } } + else{ + try { + _quickSeachProfile(getInsertXQuery(id, name, value,toEscape)); + } catch (final ISLookUpException e) { + throw new DsmRuntimeException(String.format("unable to insert context param [id: %s, name: %s, value: %s]", id, name, value), e); + } + } + + } - @Override - @CacheEvict(value = { - "context-cache", "context-cache-funder" - }, allEntries = true) - public void updateContextParamNoEscape(final String id, final String name, final String value) { + private int getSize(String id, String name) { + int size = 0; try { - _quickSeachProfile(getXQueryNoEscape(id, name, value)); - } catch (final ISLookUpException e) { - throw new DsmRuntimeException(String.format("unable update context param [id: %s, name: %s, value: %s]", id, name, value), e); + size = _quickSeachProfile(String.format("for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') where $x//context[@id='%s']/param[@name='%s'] return $x", id, name)).size(); + } catch (ISLookUpException e) { + throw new DsmRuntimeException("unable to execute search query", e); } + return size; } @Override @@ -212,26 +222,45 @@ public class ISClientImpl implements ISClient { /// HELPERS - private String getXQuery(final String id, final String name, final String value) { - final Escaper esc = XmlEscapers.xmlContentEscaper(); + + private String getInsertXQuery(final String id, final String paramName, final String paramValue, final boolean toEscape) { + String value; + if(toEscape) + value = escape(XmlEscapers.xmlContentEscaper(), paramValue); + else + value = paramValue; + if (StringUtils.isNotBlank(value)) { + return String.format("update insert %s into collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + + "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']", paramName, value, id); + } else { + return String.format("update insert into collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + + "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']", paramName, id); + } + } + + private String getXQuery(final String id, final String name, final String paramValue, final boolean toEscape) { + String value = paramValue; + if (toEscape) + value = escape(XmlEscapers.xmlContentEscaper(), paramValue); + if (StringUtils.isNotBlank(value)) { return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + - "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with %s", id, name, name, escape(esc, value)); + "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with %s", id, name, name, value); } else { return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with ", id, name, name); } } - private String getXQueryNoEscape(final String id, final String name, final String value) { - if (StringUtils.isNotBlank(value)) { - return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + - "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with %s", id, name, name, value); - } else { - return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + - "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with ", id, name, name); - } - } +// private String getXQueryNoEscape(final String id, final String name, final String value) { +// if (StringUtils.isNotBlank(value)) { +// return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + +// "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with %s", id, name, name, value); +// } else { +// return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" + +// "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with ", id, name, name); +// } +// } private String getConceptXQuery(final String id, final String name, final String value) { final Escaper esc = XmlEscapers.xmlContentEscaper(); diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java index bde3672d..6bc357eb 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java @@ -223,6 +223,44 @@ public class CommunityApiController { communityApiCore.removeCommunityContentProvider(id, contentproviderId); } + @RequestMapping(value = "/community/{id}/contentprovidersList", produces = { + "application/json" + }, method = RequestMethod.POST) + @Operation(summary = "associate a list of content providers to the community", + description = "associate a list of content providers to the community", tags = { + C_PJ, W + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public List addCommunityContentProvidersList( + @PathVariable final String id, + @RequestBody final List contentprovidersList) throws CommunityException, CommunityNotFoundException { + + return communityApiCore.addCommunityContentProvidersList(id, contentprovidersList); + } + + @RequestMapping(value = "/community/{id}/projectList", produces = { + "application/json" + }, method = RequestMethod.DELETE) + @Operation(summary = "remove a list of content providers from the community", + description = "remove a list of content providers from the community", tags = { + C_PJ, W + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public void deleteCommunityContentProvidersList( + @PathVariable final String id, + @RequestBody final List contentProviderIdList) throws CommunityException, CommunityNotFoundException { + + communityApiCore.removeCommunityContentProviderList(id, contentProviderIdList); + } + // ADDING CODE FOR COMMUNITY ORGANIZATIONS @RequestMapping(value = "/community/{id}/organizations", produces = { diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java index 473b84a1..09cb2a28 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java @@ -47,6 +47,13 @@ public class CommunityApiCore {// implements CommunityClient{ } + private void removeAdvancedConstraint(String id) throws CommunityNotFoundException, CommunityException { + cc.getCommunity(id); + isClient.updateContextParam(id, CPROFILE_ADVANCED_CONSTRAINT, "", false); + cc.removeAdvancedConstraint(id); + + } + public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, CommunityNotFoundException { cc.getCommunity(id); // ensure the community exists. @@ -56,39 +63,39 @@ public class CommunityApiCore {// implements CommunityClient{ } if (details.getName() != null) { - isClient.updateContextParam(id, CSUMMARY_NAME, details.getName()); + isClient.updateContextParam(id, CSUMMARY_NAME, details.getName(), true); } if (details.getDescription() != null) { - isClient.updateContextParam(id, CSUMMARY_DESCRIPTION, details.getDescription()); + isClient.updateContextParam(id, CSUMMARY_DESCRIPTION, details.getDescription(), true); } if (details.getLogoUrl() != null) { - isClient.updateContextParam(id, CSUMMARY_LOGOURL, details.getLogoUrl()); + isClient.updateContextParam(id, CSUMMARY_LOGOURL, details.getLogoUrl(), true); } if (details.getStatus() != null) { - isClient.updateContextParam(id, CSUMMARY_STATUS, details.getStatus().name()); + isClient.updateContextParam(id, CSUMMARY_STATUS, details.getStatus().name(), true); } if (details.getSubjects() != null) { - isClient.updateContextParam(id, CPROFILE_SUBJECT, Joiner.on(CSV_DELIMITER).join(details.getSubjects())); + isClient.updateContextParam(id, CPROFILE_SUBJECT, Joiner.on(CSV_DELIMITER).join(details.getSubjects()), true); } if (details.getFos() != null) { - isClient.updateContextParam(id, CPROFILE_FOS, Joiner.on(CSV_DELIMITER).join(details.getFos())); + isClient.updateContextParam(id, CPROFILE_FOS, Joiner.on(CSV_DELIMITER).join(details.getFos()), true); } if (details.getSdg() != null) { - isClient.updateContextParam(id, CPROFILE_SDG, Joiner.on(CSV_DELIMITER).join(details.getSdg())); + isClient.updateContextParam(id, CPROFILE_SDG, Joiner.on(CSV_DELIMITER).join(details.getSdg()), true); } if (details.getAdvancedConstraint() != null) { - isClient.updateContextParamNoEscape(id, CPROFILE_ADVANCED_CONSTRAINT, ""); + isClient.updateContextParam(id, CPROFILE_ADVANCED_CONSTRAINT, "", false); } if (details.getMainZenodoCommunity() != null) { - isClient.updateContextParam(id, CSUMMARY_ZENODOC, details.getMainZenodoCommunity()); + isClient.updateContextParam(id, CSUMMARY_ZENODOC, details.getMainZenodoCommunity(), true); } cc.updateCommunity(id, details); @@ -190,6 +197,10 @@ public class CommunityApiCore {// implements CommunityClient{ log.info("content provider to add " + cp.toString()); if (!StringUtils.equalsIgnoreCase(id, cp.getCommunityId())) { throw new CommunityException("parameters 'id' and cp.communityId must be coherent"); } + return updateContentprovider(id, cp); + } + + private CommunityContentprovider updateContentprovider(String id, CommunityContentprovider cp) throws CommunityException, CommunityNotFoundException { final TreeMap cps = getCommunityContentproviderMap(id); final String concept_id = cp.getId(); if (concept_id != null && cps.keySet().contains(Integer.valueOf(concept_id))) { @@ -225,6 +236,30 @@ public class CommunityApiCore {// implements CommunityClient{ cc.removeFromCategory(id, CONTENTPROVIDERS_ID_SUFFIX, String.valueOf(contentproviderId)); } + public List addCommunityContentProvidersList(String id, List contentprovidersList) throws CommunityException, CommunityNotFoundException { + if(contentprovidersList == null || contentprovidersList.size() == 0){ + throw new CommunityException("parameter 'contentprovidersList' must be present and should contain at least one content provider"); + } + if (!StringUtils.equalsIgnoreCase(id, contentprovidersList.get(0).getCommunityId())) { + throw new CommunityException("parameters 'id' and contentprovider.communityId must be coherent"); + } + + List contentproviders = new ArrayList(); + + for(CommunityContentprovider contentProvider : contentprovidersList){ + contentproviders.add(updateContentprovider(id, contentProvider)); + } + + + return contentproviders; + } + + public void removeCommunityContentProviderList(final String id, final List contentProviderIdList) throws CommunityException, CommunityNotFoundException { + for(Integer contentProviderId: contentProviderIdList){ + removeCommunityContentProvider(id, contentProviderId); + } + } + public void removeCommunityOrganization(final String id, final Integer organizationId) throws CommunityException, CommunityNotFoundException { final Map organizations = getCommunityOrganizationMap(id); if (!organizations.containsKey(organizationId)) { @@ -278,7 +313,10 @@ public class CommunityApiCore {// implements CommunityClient{ final CommunityDetails cd = new CommunityDetails(); - final Set current = Sets.newHashSet(cc.getCommunity(id).getFos()); + final Set current = Sets.newHashSet(); + if(Optional.ofNullable(cc.getCommunity(id).getFos()).isPresent()){ + current.addAll(cc.getCommunity(id).getFos()); + } current.addAll(foss); @@ -307,8 +345,10 @@ public class CommunityApiCore {// implements CommunityClient{ public CommunityDetails addCommunitySDG(final String id, final List sdgs) throws CommunityException, CommunityNotFoundException { final CommunityDetails cd = new CommunityDetails(); - - final Set current = Sets.newHashSet(cc.getCommunity(id).getSdg()); + final Set current = Sets.newHashSet(); + if(Optional.ofNullable(cc.getCommunity(id).getSdg()).isPresent()){ + current.addAll(cc.getCommunity(id).getSdg()); + } current.addAll(sdgs); @@ -345,17 +385,15 @@ public class CommunityApiCore {// implements CommunityClient{ return cd; } - public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws CommunityException, CommunityNotFoundException { + public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws CommunityNotFoundException, CommunityException { - final CommunityDetails cd = new CommunityDetails(); - SelectionCriteria sl = new SelectionCriteria(); - cd.setAdvancedConstraint(sl); + removeAdvancedConstraint(id); - setCommunity(id, CommunityWritableProperties.fromDetails(cd)); - - return cd; + return new CommunityDetails(); } + + @CacheEvict(value = "community-cache", allEntries = true) public void removeCommunityZenodoCommunity(final String id, final Integer zenodoCommId) throws CommunityException, CommunityNotFoundException { @@ -463,4 +501,5 @@ public class CommunityApiCore {// implements CommunityClient{ return organization; } + } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java index 52d4dd40..d23bc881 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java @@ -168,6 +168,13 @@ public class CommunityCommon { } + public void removeAdvancedConstraint(String id) throws CommunityException { + final Context context = getContextMap().get(id); + context.getParams() + .replace(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param() + .setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(null))); + } + public void updateCommunity(String id, CommunityWritableProperties community) throws CommunityException { final Context context = getContextMap().get(id); @@ -202,21 +209,35 @@ public class CommunityCommon { .join(community.getSubjects())))); } if(community.getFos() != null){ + if (context.getParams().containsKey(CPROFILE_FOS)) context.getParams() .replace(CPROFILE_FOS, Arrays.asList(new Param().setName(CPROFILE_FOS) .setValue(Joiner.on(CSV_DELIMITER) .join(community.getFos())))); + else + context.getParams().put(CPROFILE_FOS, Arrays.asList(new Param().setName(CPROFILE_FOS) + .setValue(Joiner.on(CSV_DELIMITER) + .join(community.getFos())))); } if(community.getSdg() != null){ + if(context.getParams().containsKey(CPROFILE_SDG)) context.getParams() .replace(CPROFILE_SDG, Arrays.asList(new Param().setName(CPROFILE_SDG) .setValue(Joiner.on(CSV_DELIMITER) .join(community.getSdg())))); + else + context.getParams().put(CPROFILE_SDG, Arrays.asList(new Param().setName(CPROFILE_SDG) + .setValue(Joiner.on(CSV_DELIMITER) + .join(community.getSdg())))); } if (community.getAdvancedConstraint() != null) { + if(context.getParams().containsKey(CPROFILE_ADVANCED_CONSTRAINT)) context.getParams() .replace(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param() .setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(new Gson().toJson(community.getAdvancedConstraint())))); + else + context.getParams().put(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param() + .setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(new Gson().toJson(community.getAdvancedConstraint())))); } if(community.getMainZenodoCommunity() != null){ context.getParams() -- 2.17.1 From 50b2468a13690f10f979b43f3db0c268aae14490 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Mon, 19 Dec 2022 12:45:13 +0100 Subject: [PATCH 4/4] [CommunityAPIextention]- --- .../eu/dnetlib/openaire/community/CommunityApiController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java index 6bc357eb..c5207180 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java @@ -242,7 +242,7 @@ public class CommunityApiController { return communityApiCore.addCommunityContentProvidersList(id, contentprovidersList); } - @RequestMapping(value = "/community/{id}/projectList", produces = { + @RequestMapping(value = "/community/{id}/contentprovidersList", produces = { "application/json" }, method = RequestMethod.DELETE) @Operation(summary = "remove a list of content providers from the community", -- 2.17.1