From 891b49a9d6f67555f6c5e764ec95967338d68aa8 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Wed, 5 Jul 2023 11:20:53 +0200 Subject: [PATCH] api for removeConstaint --- .../community/CommunityApiController.java | 36 ++++++++++++++++++- .../openaire/community/CommunityService.java | 26 ++++++++++++++ 2 files changed, 61 insertions(+), 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 b1570916..8a227ebf 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 @@ -346,7 +346,7 @@ public class CommunityApiController { }) public void removeCommunityOrganization( @PathVariable final String id, - @RequestBody final String organizationId) throws CommunityException { + @RequestParam final String organizationId) throws CommunityException { communityService.removeCommunityOrganizations(id, organizationId); } @@ -514,6 +514,40 @@ public class CommunityApiController { return communityService.removeCommunityAdvancedConstraint(id); } + @RequestMapping(value = "/community/{id}/removeConstraint", produces = { + "application/json" + }, method = RequestMethod.POST) + @Operation(summary = "the set of constraints to be used to remove the association between result and community", description = "the set of constraints to be used to remove 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 addRemoveConstraint( + @PathVariable final String id, + @RequestBody final SelectionCriteria removeConstraint) throws CommunityException { + + return communityService.addCommunityRemoveConstraint(id, removeConstraint); + } + + @RequestMapping(value = "/community/{id}/removeConstraint", produces = { + "application/json" + }, method = RequestMethod.DELETE) + @Operation(summary = "remove the constraints to remove the association beetween result and community", description = "remove the constraints to remove the association beetween 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 removeRemoveConstraint(@PathVariable final String id) throws CommunityException { + + return communityService.removeCommunityRemoveConstraint(id); + } + @RequestMapping(value = "/community/{id}/zenodocommunities", produces = { "application/json" }, method = RequestMethod.POST) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java index 2647de48..d7bd5889 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java @@ -365,6 +365,32 @@ public class CommunityService { } } + @Transactional + public CommunityDetails addCommunityRemoveConstraint(final String id, final SelectionCriteria removeConstraint) throws CommunityException { + try { + final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)); + dbEntry.setRemoveConstraints(removeConstraint); + dbCommunityRepository.save(dbEntry); + return getCommunity(id); + } catch (final Throwable e) { + log.error(e); + throw new CommunityException(e); + } + } + + @Transactional + public CommunityDetails removeCommunityRemoveConstraint(final String id) throws CommunityException { + try { + final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)); + dbEntry.setRemoveConstraints(null); + dbCommunityRepository.save(dbEntry); + return getCommunity(id); + } catch (final Throwable e) { + log.error(e); + throw new CommunityException(e); + } + } + public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) throws CommunityException { if (isMain) {