deposition field management

This commit is contained in:
Michele Artini 2024-02-27 10:36:55 +01:00
parent a623c7be39
commit b79677475b
7 changed files with 259 additions and 326 deletions

View File

@ -18,10 +18,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -53,9 +54,7 @@ public class CommunityApiController extends AbstractExporterController {
@Autowired @Autowired
private CommunityService communityService; private CommunityService communityService;
@RequestMapping(value = "/community/communities", produces = { @GetMapping("/community/communities")
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "get all community profiles", description = "get all community profiles", tags = { @Operation(summary = "get all community profiles", description = "get all community profiles", tags = {
C, R C, R
}) })
@ -73,9 +72,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/", produces = { @PostMapping("/community/")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "add a new community profile", description = "add a new community profile", tags = { @Operation(summary = "add a new community profile", description = "add a new community profile", tags = {
C, W C, W
}) })
@ -94,9 +91,10 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}", produces = { @GetMapping("/community/{id}"
"application/json"
}, method = RequestMethod.GET) )
@Operation(summary = "get community profile", description = "get community profile", tags = { @Operation(summary = "get community profile", description = "get community profile", tags = {
C, R C, R
}) })
@ -115,9 +113,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}", produces = { @PostMapping("/community/{id}")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "update community details", description = "update community details", tags = { @Operation(summary = "update community details", description = "update community details", tags = {
C, W C, W
}) })
@ -138,9 +134,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}", produces = { @DeleteMapping("/community/{id}")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "delete a community", description = "delete a community", tags = { @Operation(summary = "delete a community", description = "delete a community", tags = {
C, W C, W
}) })
@ -160,9 +154,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/projects/{page}/{size}", produces = { @GetMapping("/community/{id}/projects/{page}/{size}")
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "get community projects", description = "get community projects", tags = { @Operation(summary = "get community projects", description = "get community projects", tags = {
C_PJ, R C_PJ, R
}) })
@ -187,9 +179,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/projects", produces = { @PostMapping("/community/{id}/projects")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a project to the community", description = "associate a project to the community", tags = { @Operation(summary = "associate a project to the community", description = "associate a project to the community", tags = {
C_PJ, W C_PJ, W
}) })
@ -211,9 +201,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/projects", produces = { @DeleteMapping("/community/{id}/projects")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove a project from the community", description = "remove a project from the community", tags = { @Operation(summary = "remove a project from the community", description = "remove a project from the community", tags = {
C_PJ, W C_PJ, W
}) })
@ -234,9 +222,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/projectList", produces = { @PostMapping("/community/{id}/projectList")
"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 = { @Operation(summary = "associate a list of project to the community", description = "associate a list of project to the community", tags = {
C_PJ, W C_PJ, W
}) })
@ -258,9 +244,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/projectList", produces = { @DeleteMapping("/community/{id}/projectList")
"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 = { @Operation(summary = "remove a list of projects from the community", description = "remove a list of projects from the community", tags = {
C_PJ, W C_PJ, W
}) })
@ -281,9 +265,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/funders", produces = { @GetMapping("/community/{id}/funders")
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "get the funders of the projects of a community", description = "get the funders of the projects of a community", tags = { @Operation(summary = "get the funders of the projects of a community", description = "get the funders of the projects of a community", tags = {
C_PJ, R C_PJ, R
}) })
@ -303,11 +285,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = { @GetMapping({ "/community/{id}/contentproviders", "/community/{id}/datasources" })
"/community/{id}/contentproviders", "/community/{id}/datasources"
}, produces = {
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "get the list of content providers associated to a given community", description = "get the list of content providers associated to a given community", tags = { @Operation(summary = "get the list of content providers associated to a given community", description = "get the list of content providers associated to a given community", tags = {
C_CP, R C_CP, R
}) })
@ -316,9 +294,10 @@ public class CommunityApiController extends AbstractExporterController {
@ApiResponse(responseCode = "404", description = "not found"), @ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error") @ApiResponse(responseCode = "500", description = "unexpected error")
}) })
public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id) throws CommunityException { public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id, @RequestParam(required = false) final Boolean deposit)
throws CommunityException {
try { try {
return communityService.getCommunityContentproviders(id); return deposit == null ? communityService.getCommunityDatasources(id) : communityService.getCommunityDatasourcesWithDeposit(id, deposit);
} catch (final ResourceNotFoundException e) { } catch (final ResourceNotFoundException e) {
throw e; throw e;
} catch (final Throwable e) { } catch (final Throwable e) {
@ -326,11 +305,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = { @PostMapping({ "/community/{id}/contentproviders", "/community/{id}/datasources" })
"/community/{id}/contentproviders", "/community/{id}/datasources"
}, produces = {
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a content provider to the community", description = "associate a content provider to the community", tags = { @Operation(summary = "associate a content provider to the community", description = "associate a content provider to the community", tags = {
C_CP, W C_CP, W
}) })
@ -344,7 +319,7 @@ public class CommunityApiController extends AbstractExporterController {
@RequestBody final CommunityContentprovider contentprovider) throws CommunityException { @RequestBody final CommunityContentprovider contentprovider) throws CommunityException {
try { try {
communityService.addCommunityContentProviders(id, contentprovider); communityService.addCommunityDatasources(id, contentprovider);
return contentprovider; return contentprovider;
} catch (final ResourceNotFoundException e) { } catch (final ResourceNotFoundException e) {
throw e; throw e;
@ -353,11 +328,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = { @DeleteMapping({ "/community/{id}/contentproviders", "/community/{id}/datasources" })
"/community/{id}/contentproviders", "/community/{id}/datasources"
}, produces = {
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove the association between a content provider and the community", description = "remove the association between a content provider and the community", tags = { @Operation(summary = "remove the association between a content provider and the community", description = "remove the association between a content provider and the community", tags = {
C_CP, W C_CP, W
}) })
@ -370,7 +341,7 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id, @PathVariable final String id,
@RequestParam final String contentproviderId) throws CommunityException { @RequestParam final String contentproviderId) throws CommunityException {
try { try {
communityService.removeCommunityContentProviders(id, contentproviderId); communityService.removeCommunityDatasources(id, contentproviderId);
} catch (final ResourceNotFoundException e) { } catch (final ResourceNotFoundException e) {
throw e; throw e;
} catch (final Throwable e) { } catch (final Throwable e) {
@ -378,11 +349,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = { @PostMapping({ "/community/{id}/contentprovidersList", "/community/{id}/datasourcesList" })
"/community/{id}/contentprovidersList", "/community/{id}/datasourcesList"
}, 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 = { @Operation(summary = "associate a list of content providers to the community", description = "associate a list of content providers to the community", tags = {
C_CP, W C_CP, W
}) })
@ -396,7 +363,7 @@ public class CommunityApiController extends AbstractExporterController {
@RequestBody final CommunityContentprovider[] contentprovidersList) throws CommunityException { @RequestBody final CommunityContentprovider[] contentprovidersList) throws CommunityException {
try { try {
communityService.addCommunityContentProviders(id, contentprovidersList); communityService.addCommunityDatasources(id, contentprovidersList);
return contentprovidersList; return contentprovidersList;
} catch (final ResourceNotFoundException e) { } catch (final ResourceNotFoundException e) {
throw e; throw e;
@ -405,11 +372,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = { @DeleteMapping({ "/community/{id}/contentprovidersList", "/community/{id}/datasourcesList" })
"/community/{id}/contentprovidersList", "/community/{id}/datasourcesList"
}, 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 = { @Operation(summary = "remove a list of content providers from the community", description = "remove a list of content providers from the community", tags = {
C_CP, W C_CP, W
}) })
@ -422,7 +385,7 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id, @PathVariable final String id,
@RequestBody final String[] contentProviderIdList) throws CommunityException { @RequestBody final String[] contentProviderIdList) throws CommunityException {
try { try {
communityService.removeCommunityContentProviders(id, contentProviderIdList); communityService.removeCommunityDatasources(id, contentProviderIdList);
} catch (final ResourceNotFoundException e) { } catch (final ResourceNotFoundException e) {
throw e; throw e;
} catch (final Throwable e) { } catch (final Throwable e) {
@ -432,9 +395,7 @@ public class CommunityApiController extends AbstractExporterController {
// ADDING CODE FOR COMMUNITY ORGANIZATIONS // ADDING CODE FOR COMMUNITY ORGANIZATIONS
@RequestMapping(value = "/community/{id}/organizations", produces = { @GetMapping("/community/{id}/organizations")
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "get the list of organizations for a given community", description = "get the list of organizations for a given community", tags = { @Operation(summary = "get the list of organizations for a given community", description = "get the list of organizations for a given community", tags = {
C_O, R C_O, R
}) })
@ -453,9 +414,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/organizations", produces = { @PostMapping("/community/{id}/organizations")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate an organization to the community", description = "associate an organization to the community", tags = { @Operation(summary = "associate an organization to the community", description = "associate an organization to the community", tags = {
C_O, W C_O, W
}) })
@ -477,9 +436,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/organizationList", produces = { @PostMapping("/community/{id}/organizationList")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a list of organizations to the community", description = "associate a list of organizations to the community", tags = { @Operation(summary = "associate a list of organizations to the community", description = "associate a list of organizations to the community", tags = {
C_O, W C_O, W
}) })
@ -502,9 +459,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/organizations", produces = { @DeleteMapping("/community/{id}/organizations")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove the association between an organization and the community", description = "remove the association between an organization and the community", tags = { @Operation(summary = "remove the association between an organization and the community", description = "remove the association between an organization and the community", tags = {
C_O, W C_O, W
}) })
@ -525,9 +480,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/organizationList", produces = { @DeleteMapping("/community/{id}/organizationList")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove a list of associations between some organizations and the community", description = "remove a list of associations between some organizations and the community", tags = { @Operation(summary = "remove a list of associations between some organizations and the community", description = "remove a list of associations between some organizations and the community", tags = {
C_O, W C_O, W
}) })
@ -550,9 +503,7 @@ public class CommunityApiController extends AbstractExporterController {
// ********************** // **********************
@RequestMapping(value = "/community/{id}/subjects", produces = { @PostMapping("/community/{id}/subjects")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a subject to the community", description = "associate a subject to the community", tags = { @Operation(summary = "associate a subject to the community", description = "associate a subject to the community", tags = {
C, W C, W
}) })
@ -574,9 +525,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/subjects", produces = { @DeleteMapping("/community/{id}/subjects")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove subjects from a community", description = "remove subjects from a community", tags = { @Operation(summary = "remove subjects from a community", description = "remove subjects from a community", tags = {
C, W C, W
}) })
@ -598,9 +547,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/fos", produces = { @PostMapping("/community/{id}/fos")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a fos to the community", description = "associate a fos to the community", tags = { @Operation(summary = "associate a fos to the community", description = "associate a fos to the community", tags = {
C, W C, W
}) })
@ -622,9 +569,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/fos", produces = { @DeleteMapping("/community/{id}/fos")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove fos from a community", description = "remove fos from a community", tags = { @Operation(summary = "remove fos from a community", description = "remove fos from a community", tags = {
C, W C, W
}) })
@ -646,9 +591,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/sdg", produces = { @PostMapping("/community/{id}/sdg")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a sdg to the community", description = "associate a sdg to the community", tags = { @Operation(summary = "associate a sdg to the community", description = "associate a sdg to the community", tags = {
C, W C, W
}) })
@ -670,9 +613,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/sdg", produces = { @DeleteMapping("/community/{id}/sdg")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove sdg from a community", description = "remove sdg from a community", tags = { @Operation(summary = "remove sdg from a community", description = "remove sdg from a community", tags = {
C, W C, W
}) })
@ -694,9 +635,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = { @PostMapping("/community/{id}/advancedConstraint")
"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 = { @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 C, W
}) })
@ -718,9 +657,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = { @DeleteMapping("/community/{id}/advancedConstraint")
"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 = { @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 C, W
}) })
@ -741,9 +678,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/removeConstraint", produces = { @PostMapping("/community/{id}/removeConstraint")
"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 = { @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 C, W
}) })
@ -765,9 +700,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/removeConstraint", produces = { @DeleteMapping("/community/{id}/removeConstraint")
"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 = { @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 C, W
}) })
@ -787,9 +720,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = { @PostMapping("/community/{id}/zenodocommunities")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a Zenodo community to the community", description = "associate a Zenodo community to the community", tags = { @Operation(summary = "associate a Zenodo community to the community", description = "associate a Zenodo community to the community", tags = {
C_ZC, W C_ZC, W
}) })
@ -813,9 +744,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = { @DeleteMapping("/community/{id}/zenodocommunities")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove a Zenodo community from a community", description = "remove a Zenodo community from a community", tags = { @Operation(summary = "remove a Zenodo community from a community", description = "remove a Zenodo community from a community", tags = {
C_ZC, W C_ZC, W
}) })
@ -837,9 +766,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{zenodoId}/openairecommunities", produces = { @GetMapping("/community/{zenodoId}/openairecommunities")
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "get the list of OpenAIRE communities associated to a given Zenodo community", description = "get the list of OpenAIRE communities associated to a given Zenodo community", tags = { @Operation(summary = "get the list of OpenAIRE communities associated to a given Zenodo community", description = "get the list of OpenAIRE communities associated to a given Zenodo community", tags = {
C_ZC, R C_ZC, R
}) })
@ -862,9 +789,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
// APIs to manage the propagationOrganizationCommunityMap // APIs to manage the propagationOrganizationCommunityMap
@RequestMapping(value = "/propagationOrganizationCommunityMap", produces = { @GetMapping("/propagationOrganizationCommunityMap")
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "Get the propagationOrganizationCommunityMap", description = "propagationOrganizationCommunityMap", tags = { @Operation(summary = "Get the propagationOrganizationCommunityMap", description = "propagationOrganizationCommunityMap", tags = {
C_O, R C_O, R
}) })
@ -883,9 +808,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = { @GetMapping("/community/{id}/propagationOrganizations")
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "try { return the propagation organizations of a community", description = "try { return the propagation organizations of a community", tags = { @Operation(summary = "try { return the propagation organizations of a community", description = "try { return the propagation organizations of a community", tags = {
C_O, R C_O, R
}) })
@ -904,9 +827,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = { @PostMapping("/community/{id}/propagationOrganizations")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "add an organization to the propagationOrganizationCommunityMap", description = "add an organization to the propagationOrganizationCommunityMap", tags = { @Operation(summary = "add an organization to the propagationOrganizationCommunityMap", description = "add an organization to the propagationOrganizationCommunityMap", tags = {
C_O, W C_O, W
}) })
@ -927,9 +848,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = { @DeleteMapping("/community/{id}/propagationOrganizations")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "delete an organization to the propagationOrganizationCommunityMap", description = "delete an organization to the propagationOrganizationCommunityMap", tags = { @Operation(summary = "delete an organization to the propagationOrganizationCommunityMap", description = "delete an organization to the propagationOrganizationCommunityMap", tags = {
C_O, W C_O, W
}) })
@ -952,9 +871,7 @@ public class CommunityApiController extends AbstractExporterController {
// APIs to manage the sub communities // APIs to manage the sub communities
@RequestMapping(value = "/community/{id}/subcommunities", produces = { @GetMapping("/community/{id}/subcommunities")
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "get the list of subcommunities for a given community", description = "get the list of subcommunities for a given community", tags = { @Operation(summary = "get the list of subcommunities for a given community", description = "get the list of subcommunities for a given community", tags = {
C_SUB, R C_SUB, R
}) })
@ -977,9 +894,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/subcommunities", produces = { @PostMapping("/community/{id}/subcommunities")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a subcommunity to the community", description = "associate a subcommunity to the community", tags = { @Operation(summary = "associate a subcommunity to the community", description = "associate a subcommunity to the community", tags = {
C_SUB, W C_SUB, W
}) })
@ -1001,9 +916,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/subcommunitiesList", produces = { @PostMapping("/community/{id}/subcommunitiesList")
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a list of subcommunities to the community", description = "associate a list of subcommunities to the community", tags = { @Operation(summary = "associate a list of subcommunities to the community", description = "associate a list of subcommunities to the community", tags = {
C_SUB, W C_SUB, W
}) })
@ -1026,9 +939,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/subcommunities", produces = { @DeleteMapping("/community/{id}/subcommunities")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove the association between a subcommunity and the community", description = "remove the association between a subcommunity and the community", tags = { @Operation(summary = "remove the association between a subcommunity and the community", description = "remove the association between a subcommunity and the community", tags = {
C_SUB, W C_SUB, W
}) })
@ -1049,9 +960,7 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
@RequestMapping(value = "/community/{id}/subcommunitiesList", produces = { @DeleteMapping("/community/{id}/subcommunitiesList")
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove a list of associations between some subcommunities and the community", description = "remove a list of associations between some subcommunities and the community", tags = { @Operation(summary = "remove a list of associations between some subcommunities and the community", description = "remove a list of associations between some subcommunities and the community", tags = {
C_SUB, W C_SUB, W
}) })

View File

@ -3,6 +3,7 @@ package eu.dnetlib.openaire.community;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -74,21 +75,17 @@ public class CommunityService {
public List<CommunitySummary> listCommunities() { public List<CommunitySummary> listCommunities() {
return dbCommunityRepository.findAll() return dbCommunityRepository.findAll()
.stream() .stream()
.map(CommunityMappingUtils::toCommunitySummary) .map(CommunityMappingUtils::toCommunitySummary)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Transactional @Transactional
public CommunityDetails newCommunity(final CommunityDetails details) throws CommunityException { public CommunityDetails newCommunity(final CommunityDetails details) throws CommunityException {
if (StringUtils.isBlank(details.getId())) { if (StringUtils.isBlank(details.getId())) { throw new CommunityException("Empty Id"); }
throw new CommunityException("Empty Id"); if (dbCommunityRepository.existsById(details.getId())) { throw new CommunityException("Community already exists: " + details.getId()); }
} else if (dbCommunityRepository.existsById(details.getId())) { details.setCreationDate(LocalDateTime.now());
throw new CommunityException("Community already exists: " + details.getId()); return saveCommunity(details);
} else {
details.setCreationDate(LocalDateTime.now());
return saveCommunity(details);
}
} }
@ -115,23 +112,23 @@ public class CommunityService {
@Transactional @Transactional
public Page<CommunityProject> getCommunityProjects(final String id, public Page<CommunityProject> getCommunityProjects(final String id,
final String funder, final String funder,
final String filter, final String filter,
final int page, final int page,
final int size, final int size,
final String orderBy) throws CommunityException { final String orderBy) throws CommunityException {
if (StringUtils.isBlank(id)) { throw new CommunityException("Empty ID"); } if (StringUtils.isBlank(id)) { throw new CommunityException("Empty ID"); }
try { try {
final Sort sort; final Sort sort;
if (StringUtils.isBlank(orderBy)) { if (StringUtils.isBlank(orderBy)) {
sort = Sort.by("projectName"); sort = Sort.by("projectName");
} else if (orderBy.equalsIgnoreCase("funder")) { } else if ("funder".equalsIgnoreCase(orderBy)) {
sort = Sort.by("projectFunder").and(Sort.by("projectName")); sort = Sort.by("projectFunder").and(Sort.by("projectName"));
} else if (orderBy.equalsIgnoreCase("grantId")) { } else if ("grantId".equalsIgnoreCase(orderBy)) {
sort = Sort.by("projectCode"); sort = Sort.by("projectCode");
} else if (orderBy.equalsIgnoreCase("acronym")) { } else if ("acronym".equalsIgnoreCase(orderBy)) {
sort = Sort.by("projectAcronym"); sort = Sort.by("projectAcronym");
} else if (orderBy.equalsIgnoreCase("openaireId")) { } else if ("openaireId".equalsIgnoreCase(orderBy)) {
sort = Sort.by("projectId"); sort = Sort.by("projectId");
} else { } else {
sort = Sort.by("projectName"); sort = Sort.by("projectName");
@ -140,10 +137,9 @@ public class CommunityService {
final PageRequest pageable = PageRequest.of(page, size, sort); final PageRequest pageable = PageRequest.of(page, size, sort);
if (StringUtils.isAllBlank(filter, funder)) { if (StringUtils.isAllBlank(filter, funder)) {
return dbProjectRepository.findByCommunity(id, pageable).map(CommunityMappingUtils::toCommunityProject); return dbProjectRepository.findByCommunity(id, pageable).map(CommunityMappingUtils::toCommunityProject);
} else {
final Specification<DbProject> projSpec = prepareProjectSpec(id, funder, filter);
return dbProjectRepository.findAll(projSpec, pageable).map(CommunityMappingUtils::toCommunityProject);
} }
final Specification<DbProject> projSpec = prepareProjectSpec(id, funder, filter);
return dbProjectRepository.findAll(projSpec, pageable).map(CommunityMappingUtils::toCommunityProject);
} catch (final Throwable e) { } catch (final Throwable e) {
log.error(e); log.error(e);
throw new CommunityException(e); throw new CommunityException(e);
@ -191,8 +187,8 @@ public class CommunityService {
public void addCommunityProjects(final String id, final CommunityProject... projects) throws CommunityException { public void addCommunityProjects(final String id, final CommunityProject... projects) throws CommunityException {
try { try {
final List<DbProject> list = Arrays.stream(projects) final List<DbProject> list = Arrays.stream(projects)
.map(p -> CommunityMappingUtils.toDbProject(id, p)) .map(p -> CommunityMappingUtils.toDbProject(id, p))
.collect(Collectors.toList()); .collect(Collectors.toList());
dbProjectRepository.saveAll(list); dbProjectRepository.saveAll(list);
} catch (final Throwable e) { } catch (final Throwable e) {
@ -204,56 +200,63 @@ public class CommunityService {
@Transactional @Transactional
public void removeCommunityProjects(final String id, final String... ids) { public void removeCommunityProjects(final String id, final String... ids) {
final List<DbProjectPK> list = Arrays.stream(ids) final List<DbProjectPK> list = Arrays.stream(ids)
.map(projectId -> new DbProjectPK(id, projectId)) .map(projectId -> new DbProjectPK(id, projectId))
.collect(Collectors.toList()); .collect(Collectors.toList());
dbProjectRepository.deleteAllById(list); dbProjectRepository.deleteAllById(list);
} }
public List<CommunityContentprovider> getCommunityContentproviders(final String id) { public List<CommunityContentprovider> getCommunityDatasources(final String id) {
return dbDatasourceRepository.findByCommunity(id) return dbDatasourceRepository.findByCommunity(id)
.stream() .stream()
.map(CommunityMappingUtils::toCommunityContentprovider) .map(CommunityMappingUtils::toCommunityContentprovider)
.collect(Collectors.toList()); .collect(Collectors.toList());
}
public List<CommunityContentprovider> getCommunityDatasourcesWithDeposit(final String id, final boolean deposit) {
return dbDatasourceRepository.findByCommunityAndDeposit(id, deposit)
.stream()
.map(CommunityMappingUtils::toCommunityContentprovider)
.collect(Collectors.toList());
} }
@Transactional @Transactional
public void addCommunityContentProviders(final String id, final CommunityContentprovider... contentproviders) { public void addCommunityDatasources(final String id, final CommunityContentprovider... contentproviders) {
final List<DbDatasource> list = Arrays.stream(contentproviders) final List<DbDatasource> list = Arrays.stream(contentproviders)
.map(cp -> CommunityMappingUtils.toDbDatasource(id, cp)) .map(cp -> CommunityMappingUtils.toDbDatasource(id, cp))
.collect(Collectors.toList()); .collect(Collectors.toList());
dbDatasourceRepository.saveAll(list); dbDatasourceRepository.saveAll(list);
} }
@Transactional @Transactional
public void removeCommunityContentProviders(final String id, final String... ids) { public void removeCommunityDatasources(final String id, final String... ids) {
final List<DbDatasourcePK> list = Arrays.stream(ids) final List<DbDatasourcePK> list = Arrays.stream(ids)
.map(dsId -> new DbDatasourcePK(id, dsId)) .map(dsId -> new DbDatasourcePK(id, dsId))
.collect(Collectors.toList()); .collect(Collectors.toList());
dbDatasourceRepository.deleteAllById(list); dbDatasourceRepository.deleteAllById(list);
} }
@Transactional @Transactional
public void removeCommunityOrganizations(final String id, final String... orgNames) { public void removeCommunityOrganizations(final String id, final String... orgNames) {
final List<DbSupportOrgPK> list = Arrays.stream(orgNames) final List<DbSupportOrgPK> list = Arrays.stream(orgNames)
.map(name -> new DbSupportOrgPK(id, name)) .map(name -> new DbSupportOrgPK(id, name))
.collect(Collectors.toList()); .collect(Collectors.toList());
dbSupportOrgRepository.deleteAllById(list); dbSupportOrgRepository.deleteAllById(list);
} }
@Transactional @Transactional
public List<CommunityOrganization> getCommunityOrganizations(final String id) { public List<CommunityOrganization> getCommunityOrganizations(final String id) {
return dbSupportOrgRepository.findByCommunity(id) return dbSupportOrgRepository.findByCommunity(id)
.stream() .stream()
.map(CommunityMappingUtils::toCommunityOrganization) .map(CommunityMappingUtils::toCommunityOrganization)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Transactional @Transactional
public void addCommunityOrganizations(final String id, final CommunityOrganization... orgs) { public void addCommunityOrganizations(final String id, final CommunityOrganization... orgs) {
final List<DbSupportOrg> list = Arrays.stream(orgs) final List<DbSupportOrg> list = Arrays.stream(orgs)
.map(o -> CommunityMappingUtils.toDbSupportOrg(id, o)) .map(o -> CommunityMappingUtils.toDbSupportOrg(id, o))
.collect(Collectors.toList()); .collect(Collectors.toList());
dbSupportOrgRepository.saveAll(list); dbSupportOrgRepository.saveAll(list);
} }
@ -266,43 +269,43 @@ public class CommunityService {
@Transactional @Transactional
public List<SubCommunity> getSubCommunities(final String id) { public List<SubCommunity> getSubCommunities(final String id) {
return dbSubCommunityRepository.findByCommunity(id) return dbSubCommunityRepository.findByCommunity(id)
.stream() .stream()
.map(CommunityMappingUtils::toSubCommunity) .map(CommunityMappingUtils::toSubCommunity)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Transactional @Transactional
public void addSubCommunities(final String id, final SubCommunity... subs) { public void addSubCommunities(final String id, final SubCommunity... subs) {
final List<DbSubCommunity> list = Arrays.stream(subs) final List<DbSubCommunity> list = Arrays.stream(subs)
.map(s -> CommunityMappingUtils.toDbSubCommunity(id, s)) .map(s -> CommunityMappingUtils.toDbSubCommunity(id, s))
.collect(Collectors.toList()); .collect(Collectors.toList());
dbSubCommunityRepository.saveAll(list); dbSubCommunityRepository.saveAll(list);
} }
@Transactional @Transactional
public CommunityDetails addCommunitySubjects(final String id, final String... subjects) { public CommunityDetails addCommunitySubjects(final String id, final String... subjects) {
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false, subjects); return modifyElementToArrayField(id, DbCommunity::getSubjects, DbCommunity::setSubjects, false, subjects);
} }
public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) { public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) {
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true, subjects); return modifyElementToArrayField(id, DbCommunity::getSubjects, DbCommunity::setSubjects, true, subjects);
} }
public CommunityDetails addCommunityFOS(final String id, final String... foss) { public CommunityDetails addCommunityFOS(final String id, final String... foss) {
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), false, foss); return modifyElementToArrayField(id, DbCommunity::getFos, DbCommunity::setFos, false, foss);
} }
public CommunityDetails removeCommunityFOS(final String id, final String... foss) { public CommunityDetails removeCommunityFOS(final String id, final String... foss) {
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), true, foss); return modifyElementToArrayField(id, DbCommunity::getFos, DbCommunity::setFos, true, foss);
} }
public CommunityDetails addCommunitySDG(final String id, final String... sdgs) { public CommunityDetails addCommunitySDG(final String id, final String... sdgs) {
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false, sdgs); return modifyElementToArrayField(id, DbCommunity::getSdg, DbCommunity::setSdg, false, sdgs);
} }
public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) { public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) {
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs); return modifyElementToArrayField(id, DbCommunity::getSdg, DbCommunity::setSdg, true, sdgs);
} }
@Transactional @Transactional
@ -342,25 +345,19 @@ public class CommunityService {
} }
public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) { public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) {
if (isMain) { if (isMain) { return updateElementToSimpleField(id, DbCommunity::setMainZenodoCommunity, null); }
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), null); return modifyElementToArrayField(id, DbCommunity::getOtherZenodoCommunities, DbCommunity::setOtherZenodoCommunities, true, zenodoCommunity);
} else {
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), true, zenodoCommunity);
}
} }
public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) { public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) {
if (isMain) { if (isMain) { return updateElementToSimpleField(id, DbCommunity::setMainZenodoCommunity, zenodoCommunity); }
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity); return modifyElementToArrayField(id, DbCommunity::getOtherZenodoCommunities, DbCommunity::setOtherZenodoCommunities, false, zenodoCommunity);
} else {
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity);
}
} }
@Transactional @Transactional
private CommunityDetails updateElementToSimpleField(final String id, private CommunityDetails updateElementToSimpleField(final String id,
final BiConsumer<DbCommunity, String> setter, final BiConsumer<DbCommunity, String> setter,
final String value) { final String value) {
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)); final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
setter.accept(dbEntry, value); setter.accept(dbEntry, value);
dbEntry.setLastUpdateDate(LocalDateTime.now()); dbEntry.setLastUpdateDate(LocalDateTime.now());
@ -370,19 +367,17 @@ public class CommunityService {
@Transactional @Transactional
private CommunityDetails modifyElementToArrayField(final String id, private CommunityDetails modifyElementToArrayField(final String id,
final Function<DbCommunity, String[]> getter, final Function<DbCommunity, String[]> getter,
final BiConsumer<DbCommunity, String[]> setter, final BiConsumer<DbCommunity, String[]> setter,
final boolean remove, final boolean remove,
final String... values) { final String... values) {
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)); final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
final Set<String> tmpList = new LinkedHashSet<>(); final Set<String> tmpList = new LinkedHashSet<>();
final String[] oldValues = getter.apply(dbEntry); final String[] oldValues = getter.apply(dbEntry);
if (oldValues != null) { if (oldValues != null) {
for (final String s : oldValues) { Collections.addAll(tmpList, oldValues);
tmpList.add(s);
}
} }
if (remove) { if (remove) {
tmpList.removeAll(Arrays.asList(values)); tmpList.removeAll(Arrays.asList(values));
@ -407,16 +402,16 @@ public class CommunityService {
@Transactional @Transactional
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() { public Map<String, Set<String>> getPropagationOrganizationCommunityMap() {
return dbOrganizationRepository.findAll() return dbOrganizationRepository.findAll()
.stream() .stream()
.collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet()))); .collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet())));
} }
@Transactional @Transactional
public Set<String> getPropagationOrganizationsForCommunity(final String communityId) { public Set<String> getPropagationOrganizationsForCommunity(final String communityId) {
return dbOrganizationRepository.findByCommunity(communityId) return dbOrganizationRepository.findByCommunity(communityId)
.stream() .stream()
.map(DbOrganization::getOrgId) .map(DbOrganization::getOrgId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
@Transactional @Transactional
@ -454,8 +449,8 @@ public class CommunityService {
final List<IISConfigurationEntry> res = new ArrayList<>(); final List<IISConfigurationEntry> res = new ArrayList<>();
res.add(dbCommunityRepository.findById(id) res.add(dbCommunityRepository.findById(id)
.map(CommunityMappingUtils::asIISConfigurationEntry) .map(CommunityMappingUtils::asIISConfigurationEntry)
.orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id))); .orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)));
for (final DbSubCommunity subc : dbSubCommunityRepository.findByCommunity(id)) { for (final DbSubCommunity subc : dbSubCommunityRepository.findByCommunity(id)) {
res.add(CommunityMappingUtils.asIISConfigurationEntry(subc)); res.add(CommunityMappingUtils.asIISConfigurationEntry(subc));

View File

@ -6,6 +6,7 @@ import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -115,23 +116,20 @@ public class CommunityImporterService {
public List<DbOrganization> importPropagationOrganizationsFromProfile(final String xml, final boolean simulation) throws Exception { public List<DbOrganization> importPropagationOrganizationsFromProfile(final String xml, final boolean simulation) throws Exception {
final String json = DocumentHelper.parseText(xml) final String json = DocumentHelper.parseText(xml)
.selectSingleNode("//NODE[@name='setPropagationOrganizationCommunityMap']//PARAM[@name='parameterValue']") .selectSingleNode("//NODE[@name='setPropagationOrganizationCommunityMap']//PARAM[@name='parameterValue']")
.getText(); .getText();
final List<DbOrganization> list = new ObjectMapper() final List<DbOrganization> list = new ObjectMapper()
.readValue(json, new TypeReference<Map<String, List<String>>>() {}) .readValue(json, new TypeReference<Map<String, List<String>>>() {})
.entrySet() .entrySet()
.stream()
.flatMap(e -> e.getValue()
.stream() .stream()
.map(community -> { .flatMap(e -> e.getValue()
if (e.getKey().contains("|")) { .stream()
return new DbOrganization(community, StringUtils.substringAfter(e.getKey(), "|")); .map(community -> {
} else { if (e.getKey().contains("|")) { return new DbOrganization(community, StringUtils.substringAfter(e.getKey(), "|")); }
return new DbOrganization(community, e.getKey()); return new DbOrganization(community, e.getKey());
} }))
})) .collect(Collectors.toList());
.collect(Collectors.toList());
if (!simulation) { if (!simulation) {
list.forEach(o -> { list.forEach(o -> {
@ -153,69 +151,69 @@ public class CommunityImporterService {
final CommunityDetails community = asCommunityDetails(context); final CommunityDetails community = asCommunityDetails(context);
final List<CommunityContentprovider> datasources = final List<CommunityContentprovider> datasources =
getCommunityInfo(context, CONTENTPROVIDERS_ID_SUFFIX, c -> asCommunityDataprovider(context.getId(), c)) getCommunityInfo(context, CONTENTPROVIDERS_ID_SUFFIX, c -> asCommunityDataprovider(context.getId(), c))
.stream() .stream()
.map(o -> { .map(o -> {
if (o.getOpenaireId() == null) { if (o.getOpenaireId() == null) {
log.warn("Openaire ID is missing, organization: " + o.getOfficialname()); log.warn("Openaire ID is missing, organization: " + o.getOfficialname());
} else if (o.getOpenaireId().contains("|")) { } else if (o.getOpenaireId().contains("|")) {
o.setOpenaireId(StringUtils.substringAfter(o.getOpenaireId(), "|")); o.setOpenaireId(StringUtils.substringAfter(o.getOpenaireId(), "|"));
} }
return o; return o;
}) })
.filter(o -> o.getOpenaireId() != null) .filter(o -> o.getOpenaireId() != null)
.collect(Collectors.toList()); .collect(Collectors.toList());
final List<CommunityProject> projects = final List<CommunityProject> projects =
getCommunityInfo(context, PROJECTS_ID_SUFFIX, c -> asCommunityProject(context.getId(), c)) getCommunityInfo(context, PROJECTS_ID_SUFFIX, c -> asCommunityProject(context.getId(), c))
.stream() .stream()
.map(p -> { .map(p -> {
if (p.getOpenaireId() == null) { if (p.getOpenaireId() == null) {
if (p.getFunder().equalsIgnoreCase("EC")) { if ("EC".equalsIgnoreCase(p.getFunder())) {
final String ns = findNamespaceForECProject(p.getGrantId()); final String ns = findNamespaceForECProject(p.getGrantId());
if (ns != null) { if (ns != null) {
p.setOpenaireId(ns + "::" + Hashing.md5(p.getGrantId())); p.setOpenaireId(ns + "::" + Hashing.md5(p.getGrantId()));
} else { } else {
log.warn("EC project not in the db: " + p.getGrantId()); log.warn("EC project not in the db: " + p.getGrantId());
}
} else if ("NSF".equalsIgnoreCase(p.getFunder())) {
p.setOpenaireId("nsf_________::" + Hashing.md5(p.getGrantId()));
} else if ("NIH".equalsIgnoreCase(p.getFunder())) {
p.setOpenaireId("nih_________::" + Hashing.md5(p.getGrantId()));
} else {
log.warn("Openaire ID is missing, funder: " + p.getFunder());
}
} else if (p.getOpenaireId().contains("|")) {
p.setOpenaireId(StringUtils.substringAfter(p.getOpenaireId(), "|"));
} }
} else if (p.getFunder().equalsIgnoreCase("NSF")) { return p;
p.setOpenaireId("nsf_________::" + Hashing.md5(p.getGrantId())); })
} else if (p.getFunder().equalsIgnoreCase("NIH")) { .filter(p -> p.getOpenaireId() != null)
p.setOpenaireId("nih_________::" + Hashing.md5(p.getGrantId())); .collect(Collectors.toList());
} else {
log.warn("Openaire ID is missing, funder: " + p.getFunder());
}
} else if (p.getOpenaireId().contains("|")) {
p.setOpenaireId(StringUtils.substringAfter(p.getOpenaireId(), "|"));
}
return p;
})
.filter(p -> p.getOpenaireId() != null)
.collect(Collectors.toList());
final List<CommunityOrganization> orgs = final List<CommunityOrganization> orgs =
getCommunityInfo(context, ORGANIZATION_ID_SUFFIX, c -> asCommunityOrganization(context.getId(), c)); getCommunityInfo(context, ORGANIZATION_ID_SUFFIX, c -> asCommunityOrganization(context.getId(), c));
final List<String> otherZenodoCommunities = final List<String> otherZenodoCommunities =
getCommunityInfo(context, ZENODOCOMMUNITY_ID_SUFFIX, c -> asZenodoCommunity(c)); getCommunityInfo(context, ZENODOCOMMUNITY_ID_SUFFIX, CommunityImporterService::asZenodoCommunity);
community.setOtherZenodoCommunities(otherZenodoCommunities); community.setOtherZenodoCommunities(otherZenodoCommunities);
final List<SubCommunity> subs = context.getCategories() final List<SubCommunity> subs = context.getCategories()
.entrySet() .entrySet()
.stream() .stream()
.filter(e -> !e.getKey().equals(context.getId() + CONTENTPROVIDERS_ID_SUFFIX)) .filter(e -> !(context.getId() + CONTENTPROVIDERS_ID_SUFFIX).equals(e.getKey()))
.filter(e -> !e.getKey().equals(context.getId() + PROJECTS_ID_SUFFIX)) .filter(e -> !(context.getId() + PROJECTS_ID_SUFFIX).equals(e.getKey()))
.filter(e -> !e.getKey().equals(context.getId() + ORGANIZATION_ID_SUFFIX)) .filter(e -> !(context.getId() + ORGANIZATION_ID_SUFFIX).equals(e.getKey()))
.filter(e -> !e.getKey().equals(context.getId() + ZENODOCOMMUNITY_ID_SUFFIX)) .filter(e -> !(context.getId() + ZENODOCOMMUNITY_ID_SUFFIX).equals(e.getKey()))
.map(e -> e.getValue()) .map(Entry::getValue)
.map(cat -> asSubCommunities(context.getId(), null, cat.getLabel(), cat.getConcepts())) .map(cat -> asSubCommunities(context.getId(), null, cat.getLabel(), cat.getConcepts()))
.flatMap(List::stream) .flatMap(List::stream)
.collect(Collectors.toList()); .collect(Collectors.toList());
service.saveCommunity(community); service.saveCommunity(community);
service.addCommunityProjects(context.getId(), projects.toArray(new CommunityProject[projects.size()])); service.addCommunityProjects(context.getId(), projects.toArray(new CommunityProject[projects.size()]));
service.addCommunityContentProviders(context.getId(), datasources.toArray(new CommunityContentprovider[datasources.size()])); service.addCommunityDatasources(context.getId(), datasources.toArray(new CommunityContentprovider[datasources.size()]));
service.addCommunityOrganizations(context.getId(), orgs.toArray(new CommunityOrganization[orgs.size()])); service.addCommunityOrganizations(context.getId(), orgs.toArray(new CommunityOrganization[orgs.size()]));
service.addSubCommunities(context.getId(), subs.toArray(new SubCommunity[subs.size()])); service.addSubCommunities(context.getId(), subs.toArray(new SubCommunity[subs.size()]));
} catch ( } catch (
@ -226,14 +224,14 @@ public class CommunityImporterService {
} }
private <R> List<R> getCommunityInfo(final Context context, final String idSuffix, final Function<Concept, R> mapping) private <R> List<R> getCommunityInfo(final Context context, final String idSuffix, final Function<Concept, R> mapping)
throws CommunityException { throws CommunityException {
if (context != null) { if (context != null) {
final Map<String, Category> categories = context.getCategories(); final Map<String, Category> categories = context.getCategories();
final Category category = categories.get(context.getId() + idSuffix); final Category category = categories.get(context.getId() + idSuffix);
if (category != null) { return category.getConcepts() if (category != null) { return category.getConcepts()
.stream() .stream()
.map(mapping) .map(mapping)
.collect(Collectors.toList()); } .collect(Collectors.toList()); }
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -302,6 +300,8 @@ public class CommunityImporterService {
d.setOfficialname(firstValue(CCONTENTPROVIDER_OFFICIALNAME, p)); d.setOfficialname(firstValue(CCONTENTPROVIDER_OFFICIALNAME, p));
d.setEnabled(BooleanUtils.toBoolean(firstValue(CCONTENTPROVIDER_ENABLED, p))); d.setEnabled(BooleanUtils.toBoolean(firstValue(CCONTENTPROVIDER_ENABLED, p)));
d.setSelectioncriteria(SelectionCriteria.fromJson(firstValue(CCONTENTPROVIDER_SELCRITERIA, p))); d.setSelectioncriteria(SelectionCriteria.fromJson(firstValue(CCONTENTPROVIDER_SELCRITERIA, p)));
d.setDeposit(false);
d.setMessage(null);
return d; return d;
} }
@ -339,7 +339,7 @@ public class CommunityImporterService {
private String findNamespaceForECProject(final String code) { private String findNamespaceForECProject(final String code) {
final List<String> list = final List<String> list =
jdbcTemplate.queryForList("SELECT substr(id, 1, 12) from projects where code = ? and id like 'corda%'", String.class, code); jdbcTemplate.queryForList("SELECT substr(id, 1, 12) from projects where code = ? and id like 'corda%'", String.class, code);
return list.isEmpty() ? null : list.get(0); return list.isEmpty() ? null : list.get(0);
} }
@ -355,11 +355,11 @@ public class CommunityImporterService {
private static List<String> splitValues(final Stream<String> stream, final String separator) { private static List<String> splitValues(final Stream<String> stream, final String separator) {
return stream.map(s -> s.split(separator)) return stream.map(s -> s.split(separator))
.map(Arrays::asList) .map(Arrays::asList)
.flatMap(List::stream) .flatMap(List::stream)
.filter(StringUtils::isNotBlank) .filter(StringUtils::isNotBlank)
.map(StringUtils::trim) .map(StringUtils::trim)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private static String firstValue(final String name, final List<Param> params) { private static String firstValue(final String name, final List<Param> params) {
@ -372,13 +372,13 @@ public class CommunityImporterService {
private static Stream<String> asValues(final String name, final List<Param> params) { private static Stream<String> asValues(final String name, final List<Param> params) {
return params == null ? Stream.empty() return params == null ? Stream.empty()
: params.stream() : params.stream()
.filter(p -> p != null) .filter(p -> p != null)
.filter(p -> StringUtils.isNotBlank(p.getName())) .filter(p -> StringUtils.isNotBlank(p.getName()))
.filter(p -> p.getName().trim().equals(name.trim())) .filter(p -> p.getName().trim().equals(name.trim()))
.map(Param::getValue) .map(Param::getValue)
.map(StringUtils::trim) .map(StringUtils::trim)
.distinct(); .distinct();
} }
protected DbOrganizationRepository getDbOrganizationRepository() { protected DbOrganizationRepository getDbOrganizationRepository() {

View File

@ -13,5 +13,8 @@ public interface DbDatasourceRepository extends JpaRepository<DbDatasource, DbDa
List<DbDatasource> findByCommunity(String community); List<DbDatasource> findByCommunity(String community);
List<DbDatasource> findByCommunityAndDeposit(String community, boolean deposit);
void deleteByCommunity(String id); void deleteByCommunity(String id);
} }

View File

@ -189,6 +189,8 @@ public class CommunityMappingUtils {
ccp.setOfficialname(dbEntry.getDsOfficialName()); ccp.setOfficialname(dbEntry.getDsOfficialName());
ccp.setSelectioncriteria(dbEntry.getConstraints()); ccp.setSelectioncriteria(dbEntry.getConstraints());
ccp.setEnabled(dbEntry.getEnabled() != null ? dbEntry.getEnabled() : true); ccp.setEnabled(dbEntry.getEnabled() != null ? dbEntry.getEnabled() : true);
ccp.setDeposit(dbEntry.getDeposit() != null ? dbEntry.getDeposit() : false);
ccp.setMessage(dbEntry.getMessage());
return ccp; return ccp;
} }
@ -200,6 +202,8 @@ public class CommunityMappingUtils {
ds.setDsOfficialName(provider.getOfficialname()); ds.setDsOfficialName(provider.getOfficialname());
ds.setConstraints(provider.getSelectioncriteria()); ds.setConstraints(provider.getSelectioncriteria());
ds.setEnabled(provider.isEnabled()); ds.setEnabled(provider.isEnabled());
ds.setDeposit(provider.getDeposit() != null ? provider.getDeposit() : false);
ds.setMessage(provider.getMessage());
return ds; return ds;
} }
@ -262,8 +266,8 @@ public class CommunityMappingUtils {
public static LocalDateTime asLocalDateTime(final Date date) { public static LocalDateTime asLocalDateTime(final Date date) {
return date.toInstant() return date.toInstant()
.atZone(ZoneId.systemDefault()) .atZone(ZoneId.systemDefault())
.toLocalDateTime(); .toLocalDateTime();
} }
private static String[] toStringArray(final List<String> list) { private static String[] toStringArray(final List<String> list) {

View File

@ -60,9 +60,9 @@ class CommunityImporterServiceTest {
// list.forEach(System.out::println); // list.forEach(System.out::println);
assertEquals(245, list.size()); assertEquals(245, list.size());
assertEquals(1, list.stream().filter(o -> o.getOrgId().equals("openorgs____::9dd5545aacd3d8019e00c3f837269746")).count()); assertEquals(1, list.stream().filter(o -> "openorgs____::9dd5545aacd3d8019e00c3f837269746".equals(o.getOrgId())).count());
assertEquals(2, list.stream().filter(o -> o.getOrgId().equals("openorgs____::d11f981828c485cd23d93f7f24f24db1")).count()); assertEquals(2, list.stream().filter(o -> "openorgs____::d11f981828c485cd23d93f7f24f24db1".equals(o.getOrgId())).count());
assertEquals(14, list.stream().filter(o -> o.getCommunity().equals("beopen")).count()); assertEquals(14, list.stream().filter(o -> "beopen".equals(o.getCommunity())).count());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -85,7 +85,7 @@ class CommunityImporterServiceTest {
Mockito.verify(service, Mockito.times(1)).saveCommunity(detailsCapture.capture()); Mockito.verify(service, Mockito.times(1)).saveCommunity(detailsCapture.capture());
Mockito.verify(service, Mockito.times(1)).addCommunityProjects(Mockito.anyString(), projectsCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityProjects(Mockito.anyString(), projectsCapture.capture());
Mockito.verify(service, Mockito.times(1)).addCommunityContentProviders(Mockito.anyString(), datasourcesCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityDatasources(Mockito.anyString(), datasourcesCapture.capture());
Mockito.verify(service, Mockito.times(1)).addCommunityOrganizations(Mockito.anyString(), orgsCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityOrganizations(Mockito.anyString(), orgsCapture.capture());
Mockito.verify(service, Mockito.times(1)).addSubCommunities(Mockito.anyString(), subCommunitiesCapture.capture()); Mockito.verify(service, Mockito.times(1)).addSubCommunities(Mockito.anyString(), subCommunitiesCapture.capture());
@ -132,7 +132,7 @@ class CommunityImporterServiceTest {
Mockito.verify(service, Mockito.times(1)).saveCommunity(detailsCapture.capture()); Mockito.verify(service, Mockito.times(1)).saveCommunity(detailsCapture.capture());
Mockito.verify(service, Mockito.times(1)).addCommunityProjects(Mockito.anyString(), projectsCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityProjects(Mockito.anyString(), projectsCapture.capture());
Mockito.verify(service, Mockito.times(1)).addCommunityContentProviders(Mockito.anyString(), datasourcesCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityDatasources(Mockito.anyString(), datasourcesCapture.capture());
Mockito.verify(service, Mockito.times(1)).addCommunityOrganizations(Mockito.anyString(), orgsCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityOrganizations(Mockito.anyString(), orgsCapture.capture());
Mockito.verify(service, Mockito.times(1)).addSubCommunities(Mockito.anyString(), subCommunitiesCapture.capture()); Mockito.verify(service, Mockito.times(1)).addSubCommunities(Mockito.anyString(), subCommunitiesCapture.capture());

View File

@ -34,6 +34,12 @@ public class CommunityContentprovider {
@Schema(description = "content provider selection criteria", required = false) @Schema(description = "content provider selection criteria", required = false)
private SelectionCriteria selectioncriteria; private SelectionCriteria selectioncriteria;
@Schema(description = "suggested for deposition", required = false)
private Boolean deposit;
@Schema(description = "message for the deposition page", required = false)
private String message;
public String getOpenaireId() { public String getOpenaireId() {
return openaireId; return openaireId;
} }
@ -75,7 +81,7 @@ public class CommunityContentprovider {
} }
public SelectionCriteria getSelectioncriteria() { public SelectionCriteria getSelectioncriteria() {
return this.selectioncriteria; return selectioncriteria;
} }
public void setSelectioncriteria(final SelectionCriteria selectioncriteria) { public void setSelectioncriteria(final SelectionCriteria selectioncriteria) {
@ -101,17 +107,33 @@ public class CommunityContentprovider {
public String toString() { public String toString() {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
builder.append("CommunityContentprovider [\n\topenaireId = ") builder.append("CommunityContentprovider [\n\topenaireId = ")
.append(openaireId) .append(openaireId)
.append(",\n\tcommunityId = ") .append(",\n\tcommunityId = ")
.append(communityId) .append(communityId)
.append(",\n\tname = ") .append(",\n\tname = ")
.append(name) .append(name)
.append(",\n\tofficialname = ") .append(",\n\tofficialname = ")
.append(officialname) .append(officialname)
.append(",\n\tselectioncriteria = ") .append(",\n\tselectioncriteria = ")
.append(selectioncriteria) .append(selectioncriteria)
.append("\n]"); .append("\n]");
return builder.toString(); return builder.toString();
} }
public Boolean getDeposit() {
return deposit;
}
public void setDeposit(final Boolean deposit) {
this.deposit = deposit;
}
public String getMessage() {
return message;
}
public void setMessage(final String message) {
this.message = message;
}
} }