Merge pull request 'task9462' (#18) from task9462 into master

Reviewed-on: #18
This commit is contained in:
Michele Artini 2024-03-13 09:22:51 +01:00
commit 5a8e8f2ade
10 changed files with 718 additions and 599 deletions

View File

@ -18,14 +18,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.domain.Page;
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.PostMapping;
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.RestController;
import eu.dnetlib.openaire.common.AbstractExporterController;
import eu.dnetlib.openaire.community.model.DepositionInfo;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
@ -53,9 +55,7 @@ public class CommunityApiController extends AbstractExporterController {
@Autowired
private CommunityService communityService;
@RequestMapping(value = "/community/communities", produces = {
"application/json"
}, method = RequestMethod.GET)
@GetMapping("/community/communities")
@Operation(summary = "get all community profiles", description = "get all community profiles", tags = {
C, R
})
@ -73,9 +73,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/")
@Operation(summary = "add a new community profile", description = "add a new community profile", tags = {
C, W
})
@ -94,9 +92,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}", produces = {
"application/json"
}, method = RequestMethod.GET)
@GetMapping("/community/{id}")
@Operation(summary = "get community profile", description = "get community profile", tags = {
C, R
})
@ -115,9 +111,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/{id}")
@Operation(summary = "update community details", description = "update community details", tags = {
C, W
})
@ -138,9 +132,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}")
@Operation(summary = "delete a community", description = "delete a community", tags = {
C, W
})
@ -160,9 +152,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/projects/{page}/{size}", produces = {
"application/json"
}, method = RequestMethod.GET)
@GetMapping("/community/{id}/projects/{page}/{size}")
@Operation(summary = "get community projects", description = "get community projects", tags = {
C_PJ, R
})
@ -187,10 +177,8 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/projects", produces = {
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a project to the community", description = "associate a project to the community", tags = {
@PostMapping("/community/{id}/projects")
@Operation(summary = "associate a project to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a project to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = {
C_PJ, W
})
@ApiResponses(value = {
@ -211,9 +199,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/projects", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/projects")
@Operation(summary = "remove a project from the community", description = "remove a project from the community", tags = {
C_PJ, W
})
@ -234,9 +220,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/projectList", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/{id}/projectList")
@Operation(summary = "associate a list of project to the community", description = "associate a list of project to the community", tags = {
C_PJ, W
})
@ -258,9 +242,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/projectList", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/projectList")
@Operation(summary = "remove a list of projects from the community", description = "remove a list of projects from the community", tags = {
C_PJ, W
})
@ -281,9 +263,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/funders", produces = {
"application/json"
}, method = RequestMethod.GET)
@GetMapping("/community/{id}/funders")
@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
})
@ -303,10 +283,10 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/contentproviders", 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 = {
// Datasources
@GetMapping("/community/{id}/datasources")
@Operation(summary = "get the list of datasources associated to a given community", description = "get the list of content providers associated to a given community", tags = {
C_CP, R
})
@ApiResponses(value = {
@ -314,9 +294,10 @@ public class CommunityApiController extends AbstractExporterController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id) throws CommunityException {
public List<CommunityContentprovider> getCommunityDatasources(@PathVariable final String id, @RequestParam(required = false) final Boolean deposit)
throws CommunityException {
try {
return communityService.getCommunityContentproviders(id);
return deposit == null ? communityService.getCommunityDatasources(id) : communityService.getCommunityDatasourcesWithDeposit(id, deposit);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -324,10 +305,135 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a content provider to the community", description = "associate a content provider to the community", tags = {
@PostMapping("/community/{id}/datasources")
@Operation(summary = "associate a datasource to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a datasource to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = {
C_CP, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityContentprovider addCommunityDatasource(
@PathVariable final String id,
@RequestBody final CommunityContentprovider datasource) throws CommunityException {
try {
communityService.addCommunityDatasources(id, datasource);
return datasource;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/datasources/deposit")
@Operation(summary = "update the deposit and message filelds of a datasource associated to the community", description = "update the deposit and message filelds of a datasource associated to the community", tags = {
C_CP, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityContentprovider addCommunityDatasourceDeposit(
@PathVariable final String id,
@RequestBody final DepositionInfo info) throws CommunityException {
try {
return communityService.updateCommunityDatasourcesDeposit(id, info.getOpenaireId(), info.getDeposit(), info.getMessage());
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/datasources")
@Operation(summary = "remove the association between a datasource and the community", description = "remove the association between a datasource and the community", tags = {
C_CP, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeCommunityDatasource(
@PathVariable final String id,
@RequestParam final String dsId) throws CommunityException {
try {
communityService.removeCommunityDatasources(id, dsId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/datasourcesList")
@Operation(summary = "associate a list of datasources to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a list of datasources to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = {
C_CP, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityContentprovider[] addCommunityDatasourcesList(
@PathVariable final String id,
@RequestBody final CommunityContentprovider[] dsList) throws CommunityException {
try {
communityService.addCommunityDatasources(id, dsList);
return dsList;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/datasourcesList")
@Operation(summary = "remove a list of datasources from the community", description = "remove a list of datasources from the community", tags = {
C_CP, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void deleteCommunityDatasourcesList(
@PathVariable final String id,
@RequestBody final String[] dsIdList) throws CommunityException {
try {
communityService.removeCommunityDatasources(id, dsIdList);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// Content Providers (DEPRECATED)
@Deprecated
@GetMapping("/community/{id}/contentproviders")
@Operation(summary = "get the list of datasources associated to a given community", description = "get the list of content providers associated to a given community", tags = {
C_CP, R
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id, @RequestParam(required = false) final Boolean deposit)
throws CommunityException {
return getCommunityDatasources(id, deposit);
}
@Deprecated
@PostMapping("/community/{id}/contentproviders")
@Operation(summary = "associate a datasource to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a datasource to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = {
C_CP, W
})
@ApiResponses(value = {
@ -339,20 +445,12 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id,
@RequestBody final CommunityContentprovider contentprovider) throws CommunityException {
try {
communityService.addCommunityContentProviders(id, contentprovider);
return contentprovider;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
return addCommunityDatasource(id, contentprovider);
}
@RequestMapping(value = "/community/{id}/contentproviders", 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 = {
@Deprecated
@DeleteMapping("/community/{id}/contentproviders")
@Operation(summary = "remove the association between a datasource and the community", description = "remove the association between a datasource and the community", tags = {
C_CP, W
})
@ApiResponses(value = {
@ -360,22 +458,13 @@ public class CommunityApiController extends AbstractExporterController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeCommunityContentprovider(
@PathVariable final String id,
@RequestParam final String contentproviderId) throws CommunityException {
try {
communityService.removeCommunityContentProviders(id, contentproviderId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
public void removeCommunityContentprovider(@PathVariable final String id, @RequestParam final String contentproviderId) throws CommunityException {
removeCommunityDatasource(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 = {
@Deprecated
@PostMapping("/community/{id}/contentprovidersList")
@Operation(summary = "associate a list of datasources to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a list of datasources to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = {
C_CP, W
})
@ApiResponses(value = {
@ -386,21 +475,12 @@ public class CommunityApiController extends AbstractExporterController {
public CommunityContentprovider[] addCommunityContentProvidersList(
@PathVariable final String id,
@RequestBody final CommunityContentprovider[] contentprovidersList) throws CommunityException {
try {
communityService.addCommunityContentProviders(id, contentprovidersList);
return contentprovidersList;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
return addCommunityDatasourcesList(id, contentprovidersList);
}
@RequestMapping(value = "/community/{id}/contentprovidersList", 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 = {
@Deprecated
@DeleteMapping("/community/{id}/contentprovidersList")
@Operation(summary = "remove a list of datasources from the community", description = "remove a list of datasources from the community", tags = {
C_CP, W
})
@ApiResponses(value = {
@ -411,20 +491,12 @@ public class CommunityApiController extends AbstractExporterController {
public void deleteCommunityContentProvidersList(
@PathVariable final String id,
@RequestBody final String[] contentProviderIdList) throws CommunityException {
try {
communityService.removeCommunityContentProviders(id, contentProviderIdList);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
deleteCommunityDatasourcesList(id, contentProviderIdList);
}
// ADDING CODE FOR COMMUNITY ORGANIZATIONS
// ORGANIZATIONS
@RequestMapping(value = "/community/{id}/organizations", produces = {
"application/json"
}, method = RequestMethod.GET)
@GetMapping("/community/{id}/organizations")
@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
})
@ -443,10 +515,8 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/organizations", produces = {
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate an organization to the community", description = "associate an organization to the community", tags = {
@PostMapping("/community/{id}/organizations")
@Operation(summary = "associate an organization to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate an organization to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = {
C_O, W
})
@ApiResponses(value = {
@ -467,10 +537,8 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/organizationList", produces = {
"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 = {
@PostMapping("/community/{id}/organizationList")
@Operation(summary = "associate a list of organizations to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a list of organizations to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = {
C_O, W
})
@ApiResponses(value = {
@ -492,9 +560,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/organizations", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/organizations")
@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
})
@ -515,9 +581,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/organizationList", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/organizationList")
@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
})
@ -540,9 +604,7 @@ public class CommunityApiController extends AbstractExporterController {
// **********************
@RequestMapping(value = "/community/{id}/subjects", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/{id}/subjects")
@Operation(summary = "associate a subject to the community", description = "associate a subject to the community", tags = {
C, W
})
@ -564,9 +626,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/subjects", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/subjects")
@Operation(summary = "remove subjects from a community", description = "remove subjects from a community", tags = {
C, W
})
@ -588,9 +648,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/fos", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/{id}/fos")
@Operation(summary = "associate a fos to the community", description = "associate a fos to the community", tags = {
C, W
})
@ -612,9 +670,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/fos", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/fos")
@Operation(summary = "remove fos from a community", description = "remove fos from a community", tags = {
C, W
})
@ -636,9 +692,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/sdg", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/{id}/sdg")
@Operation(summary = "associate a sdg to the community", description = "associate a sdg to the community", tags = {
C, W
})
@ -660,9 +714,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/sdg", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/sdg")
@Operation(summary = "remove sdg from a community", description = "remove sdg from a community", tags = {
C, W
})
@ -684,9 +736,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/{id}/advancedConstraint")
@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
})
@ -708,9 +758,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/advancedConstraint")
@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
})
@ -731,9 +779,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/removeConstraint", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/{id}/removeConstraint")
@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
})
@ -755,9 +801,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/removeConstraint", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/removeConstraint")
@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
})
@ -777,9 +821,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/{id}/zenodocommunities")
@Operation(summary = "associate a Zenodo community to the community", description = "associate a Zenodo community to the community", tags = {
C_ZC, W
})
@ -803,9 +845,7 @@ public class CommunityApiController extends AbstractExporterController {
}
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/zenodocommunities")
@Operation(summary = "remove a Zenodo community from a community", description = "remove a Zenodo community from a community", tags = {
C_ZC, W
})
@ -827,9 +867,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{zenodoId}/openairecommunities", produces = {
"application/json"
}, method = RequestMethod.GET)
@GetMapping("/community/{zenodoId}/openairecommunities")
@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
})
@ -852,9 +890,7 @@ public class CommunityApiController extends AbstractExporterController {
}
// APIs to manage the propagationOrganizationCommunityMap
@RequestMapping(value = "/propagationOrganizationCommunityMap", produces = {
"application/json"
}, method = RequestMethod.GET)
@GetMapping("/propagationOrganizationCommunityMap")
@Operation(summary = "Get the propagationOrganizationCommunityMap", description = "propagationOrganizationCommunityMap", tags = {
C_O, R
})
@ -873,9 +909,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
"application/json"
}, method = RequestMethod.GET)
@GetMapping("/community/{id}/propagationOrganizations")
@Operation(summary = "try { return the propagation organizations of a community", description = "try { return the propagation organizations of a community", tags = {
C_O, R
})
@ -894,9 +928,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
"application/json"
}, method = RequestMethod.POST)
@PostMapping("/community/{id}/propagationOrganizations")
@Operation(summary = "add an organization to the propagationOrganizationCommunityMap", description = "add an organization to the propagationOrganizationCommunityMap", tags = {
C_O, W
})
@ -917,9 +949,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/propagationOrganizations")
@Operation(summary = "delete an organization to the propagationOrganizationCommunityMap", description = "delete an organization to the propagationOrganizationCommunityMap", tags = {
C_O, W
})
@ -942,9 +972,7 @@ public class CommunityApiController extends AbstractExporterController {
// APIs to manage the sub communities
@RequestMapping(value = "/community/{id}/subcommunities", produces = {
"application/json"
}, method = RequestMethod.GET)
@GetMapping("/community/{id}/subcommunities")
@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
})
@ -967,10 +995,8 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/subcommunities", produces = {
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "associate a subcommunity to the community", description = "associate a subcommunity to the community", tags = {
@PostMapping("/community/{id}/subcommunities")
@Operation(summary = "associate a subcommunity to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a subcommunity to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ -991,10 +1017,8 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/subcommunitiesList", produces = {
"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 = {
@PostMapping("/community/{id}/subcommunitiesList")
@Operation(summary = "associate a list of subcommunities to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a list of subcommunities to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ -1016,9 +1040,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/subcommunities", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/subcommunities")
@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
})
@ -1039,9 +1061,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
@RequestMapping(value = "/community/{id}/subcommunitiesList", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@DeleteMapping("/community/{id}/subcommunitiesList")
@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
})

View File

@ -3,6 +3,7 @@ package eu.dnetlib.openaire.community;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -81,14 +82,10 @@ public class CommunityService {
@Transactional
public CommunityDetails newCommunity(final CommunityDetails details) throws CommunityException {
if (StringUtils.isBlank(details.getId())) {
throw new CommunityException("Empty Id");
} else if (dbCommunityRepository.existsById(details.getId())) {
throw new CommunityException("Community already exists: " + details.getId());
} else {
if (StringUtils.isBlank(details.getId())) { throw new CommunityException("Empty Id"); }
if (dbCommunityRepository.existsById(details.getId())) { throw new CommunityException("Community already exists: " + details.getId()); }
details.setCreationDate(LocalDateTime.now());
return saveCommunity(details);
}
}
@ -125,13 +122,13 @@ public class CommunityService {
final Sort sort;
if (StringUtils.isBlank(orderBy)) {
sort = Sort.by("projectName");
} else if (orderBy.equalsIgnoreCase("funder")) {
} else if ("funder".equalsIgnoreCase(orderBy)) {
sort = Sort.by("projectFunder").and(Sort.by("projectName"));
} else if (orderBy.equalsIgnoreCase("grantId")) {
} else if ("grantId".equalsIgnoreCase(orderBy)) {
sort = Sort.by("projectCode");
} else if (orderBy.equalsIgnoreCase("acronym")) {
} else if ("acronym".equalsIgnoreCase(orderBy)) {
sort = Sort.by("projectAcronym");
} else if (orderBy.equalsIgnoreCase("openaireId")) {
} else if ("openaireId".equalsIgnoreCase(orderBy)) {
sort = Sort.by("projectId");
} else {
sort = Sort.by("projectName");
@ -140,10 +137,9 @@ public class CommunityService {
final PageRequest pageable = PageRequest.of(page, size, sort);
if (StringUtils.isAllBlank(filter, funder)) {
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);
}
} catch (final Throwable e) {
log.error(e);
throw new CommunityException(e);
@ -209,15 +205,34 @@ public class CommunityService {
dbProjectRepository.deleteAllById(list);
}
public List<CommunityContentprovider> getCommunityContentproviders(final String id) {
public List<CommunityContentprovider> getCommunityDatasources(final String id) {
return dbDatasourceRepository.findByCommunity(id)
.stream()
.map(CommunityMappingUtils::toCommunityContentprovider)
.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
public void addCommunityContentProviders(final String id, final CommunityContentprovider... contentproviders) {
public CommunityContentprovider updateCommunityDatasourcesDeposit(final String id, final String dsId, final Boolean deposit, final String message) {
return dbDatasourceRepository.findById(new DbDatasourcePK(id, dsId))
.map(ds -> {
ds.setDeposit(deposit != null ? deposit : false);
ds.setMessage(message);
return ds;
})
.map(CommunityMappingUtils::toCommunityContentprovider)
.orElseThrow(() -> new ResourceNotFoundException("Community and/or Datasource not found"));
}
@Transactional
public void addCommunityDatasources(final String id, final CommunityContentprovider... contentproviders) {
final List<DbDatasource> list = Arrays.stream(contentproviders)
.map(cp -> CommunityMappingUtils.toDbDatasource(id, cp))
.collect(Collectors.toList());
@ -226,7 +241,7 @@ public class CommunityService {
}
@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)
.map(dsId -> new DbDatasourcePK(id, dsId))
.collect(Collectors.toList());
@ -282,27 +297,27 @@ public class CommunityService {
@Transactional
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) {
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) {
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) {
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) {
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) {
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs);
return modifyElementToArrayField(id, DbCommunity::getSdg, DbCommunity::setSdg, true, sdgs);
}
@Transactional
@ -342,19 +357,13 @@ public class CommunityService {
}
public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) {
if (isMain) {
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), null);
} else {
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), true, zenodoCommunity);
}
if (isMain) { return updateElementToSimpleField(id, DbCommunity::setMainZenodoCommunity, null); }
return modifyElementToArrayField(id, DbCommunity::getOtherZenodoCommunities, DbCommunity::setOtherZenodoCommunities, true, zenodoCommunity);
}
public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) {
if (isMain) {
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity);
} else {
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity);
}
if (isMain) { return updateElementToSimpleField(id, DbCommunity::setMainZenodoCommunity, zenodoCommunity); }
return modifyElementToArrayField(id, DbCommunity::getOtherZenodoCommunities, DbCommunity::setOtherZenodoCommunities, false, zenodoCommunity);
}
@Transactional
@ -380,9 +389,7 @@ public class CommunityService {
final Set<String> tmpList = new LinkedHashSet<>();
final String[] oldValues = getter.apply(dbEntry);
if (oldValues != null) {
for (final String s : oldValues) {
tmpList.add(s);
}
Collections.addAll(tmpList, oldValues);
}
if (remove) {
tmpList.removeAll(Arrays.asList(values));

View File

@ -6,6 +6,7 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -125,11 +126,8 @@ public class CommunityImporterService {
.flatMap(e -> e.getValue()
.stream()
.map(community -> {
if (e.getKey().contains("|")) {
return new DbOrganization(community, StringUtils.substringAfter(e.getKey(), "|"));
} else {
if (e.getKey().contains("|")) { return new DbOrganization(community, StringUtils.substringAfter(e.getKey(), "|")); }
return new DbOrganization(community, e.getKey());
}
}))
.collect(Collectors.toList());
@ -171,16 +169,16 @@ public class CommunityImporterService {
.stream()
.map(p -> {
if (p.getOpenaireId() == null) {
if (p.getFunder().equalsIgnoreCase("EC")) {
if ("EC".equalsIgnoreCase(p.getFunder())) {
final String ns = findNamespaceForECProject(p.getGrantId());
if (ns != null) {
p.setOpenaireId(ns + "::" + Hashing.md5(p.getGrantId()));
} else {
log.warn("EC project not in the db: " + p.getGrantId());
}
} else if (p.getFunder().equalsIgnoreCase("NSF")) {
} else if ("NSF".equalsIgnoreCase(p.getFunder())) {
p.setOpenaireId("nsf_________::" + Hashing.md5(p.getGrantId()));
} else if (p.getFunder().equalsIgnoreCase("NIH")) {
} else if ("NIH".equalsIgnoreCase(p.getFunder())) {
p.setOpenaireId("nih_________::" + Hashing.md5(p.getGrantId()));
} else {
log.warn("Openaire ID is missing, funder: " + p.getFunder());
@ -197,25 +195,25 @@ public class CommunityImporterService {
getCommunityInfo(context, ORGANIZATION_ID_SUFFIX, c -> asCommunityOrganization(context.getId(), c));
final List<String> otherZenodoCommunities =
getCommunityInfo(context, ZENODOCOMMUNITY_ID_SUFFIX, c -> asZenodoCommunity(c));
getCommunityInfo(context, ZENODOCOMMUNITY_ID_SUFFIX, CommunityImporterService::asZenodoCommunity);
community.setOtherZenodoCommunities(otherZenodoCommunities);
final List<SubCommunity> subs = context.getCategories()
.entrySet()
.stream()
.filter(e -> !e.getKey().equals(context.getId() + CONTENTPROVIDERS_ID_SUFFIX))
.filter(e -> !e.getKey().equals(context.getId() + PROJECTS_ID_SUFFIX))
.filter(e -> !e.getKey().equals(context.getId() + ORGANIZATION_ID_SUFFIX))
.filter(e -> !e.getKey().equals(context.getId() + ZENODOCOMMUNITY_ID_SUFFIX))
.map(e -> e.getValue())
.filter(e -> !(context.getId() + CONTENTPROVIDERS_ID_SUFFIX).equals(e.getKey()))
.filter(e -> !(context.getId() + PROJECTS_ID_SUFFIX).equals(e.getKey()))
.filter(e -> !(context.getId() + ORGANIZATION_ID_SUFFIX).equals(e.getKey()))
.filter(e -> !(context.getId() + ZENODOCOMMUNITY_ID_SUFFIX).equals(e.getKey()))
.map(Entry::getValue)
.map(cat -> asSubCommunities(context.getId(), null, cat.getLabel(), cat.getConcepts()))
.flatMap(List::stream)
.collect(Collectors.toList());
service.saveCommunity(community);
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.addSubCommunities(context.getId(), subs.toArray(new SubCommunity[subs.size()]));
} catch (
@ -302,6 +300,8 @@ public class CommunityImporterService {
d.setOfficialname(firstValue(CCONTENTPROVIDER_OFFICIALNAME, p));
d.setEnabled(BooleanUtils.toBoolean(firstValue(CCONTENTPROVIDER_ENABLED, p)));
d.setSelectioncriteria(SelectionCriteria.fromJson(firstValue(CCONTENTPROVIDER_SELCRITERIA, p)));
d.setDeposit(false);
d.setMessage(null);
return d;
}

View File

@ -40,6 +40,12 @@ public class DbDatasource implements Serializable {
@Column(name = "constraints")
private SelectionCriteria constraints;
@Column(name = "deposit")
private Boolean deposit;
@Column(name = "message")
private String message;
public DbDatasource() {}
public DbDatasource(final String community, final String dsId, final String dsName, final String dsOfficialName, final SelectionCriteria constraints) {
@ -98,4 +104,20 @@ public class DbDatasource implements Serializable {
this.constraints = constraints;
}
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;
}
}

View File

@ -0,0 +1,39 @@
package eu.dnetlib.openaire.community.model;
import java.io.Serializable;
public class DepositionInfo implements Serializable {
private static final long serialVersionUID = 7538663287451167904L;
private String openaireId;
private Boolean deposit;
private String message;
public String getOpenaireId() {
return openaireId;
}
public void setOpenaireId(final String openaireId) {
this.openaireId = openaireId;
}
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;
}
}

View File

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

View File

@ -189,6 +189,8 @@ public class CommunityMappingUtils {
ccp.setOfficialname(dbEntry.getDsOfficialName());
ccp.setSelectioncriteria(dbEntry.getConstraints());
ccp.setEnabled(dbEntry.getEnabled() != null ? dbEntry.getEnabled() : true);
ccp.setDeposit(dbEntry.getDeposit() != null ? dbEntry.getDeposit() : false);
ccp.setMessage(dbEntry.getMessage());
return ccp;
}
@ -200,6 +202,8 @@ public class CommunityMappingUtils {
ds.setDsOfficialName(provider.getOfficialname());
ds.setConstraints(provider.getSelectioncriteria());
ds.setEnabled(provider.isEnabled());
ds.setDeposit(provider.getDeposit() != null ? provider.getDeposit() : false);
ds.setMessage(provider.getMessage());
return ds;
}

View File

@ -44,8 +44,10 @@ CREATE TABLE community_datasources (
ds_id text NOT NULL,
ds_name text NOT NULL,
ds_officialname text NOT NULL,
enabled boolean NOT NULL DEFAULT true;
enabled boolean NOT NULL DEFAULT true
constraints jsonb,
deposit boolean NOT NULL DEFAULT false,
message text,
PRIMARY KEY (community, ds_id)
);

View File

@ -60,9 +60,9 @@ class CommunityImporterServiceTest {
// list.forEach(System.out::println);
assertEquals(245, list.size());
assertEquals(1, list.stream().filter(o -> o.getOrgId().equals("openorgs____::9dd5545aacd3d8019e00c3f837269746")).count());
assertEquals(2, list.stream().filter(o -> o.getOrgId().equals("openorgs____::d11f981828c485cd23d93f7f24f24db1")).count());
assertEquals(14, list.stream().filter(o -> o.getCommunity().equals("beopen")).count());
assertEquals(1, list.stream().filter(o -> "openorgs____::9dd5545aacd3d8019e00c3f837269746".equals(o.getOrgId())).count());
assertEquals(2, list.stream().filter(o -> "openorgs____::d11f981828c485cd23d93f7f24f24db1".equals(o.getOrgId())).count());
assertEquals(14, list.stream().filter(o -> "beopen".equals(o.getCommunity())).count());
}
@SuppressWarnings("unchecked")
@ -85,7 +85,7 @@ class CommunityImporterServiceTest {
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)).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)).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)).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)).addSubCommunities(Mockito.anyString(), subCommunitiesCapture.capture());

View File

@ -34,6 +34,12 @@ public class CommunityContentprovider {
@Schema(description = "content provider selection criteria", required = false)
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() {
return openaireId;
}
@ -75,7 +81,7 @@ public class CommunityContentprovider {
}
public SelectionCriteria getSelectioncriteria() {
return this.selectioncriteria;
return selectioncriteria;
}
public void setSelectioncriteria(final SelectionCriteria selectioncriteria) {
@ -114,4 +120,20 @@ public class CommunityContentprovider {
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;
}
}