extend methods for subcommunities

This commit is contained in:
Michele Artini 2024-10-03 14:22:37 +02:00
parent 24c4ed3b8d
commit d3acb21e8c
1 changed files with 328 additions and 265 deletions

View File

@ -15,6 +15,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired; 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;
@ -275,6 +276,333 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
// COMMON PROPERTIES
@PostMapping("/community/{id}/subjects")
@Operation(summary = "associate a subject to a community or a sub-community", description = "associate a subject to a community or a sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addCommunitySubjects(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.addCommunitySubjects(ObjectUtils.firstNonNull(subCommunityId, id), subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subjects")
@Operation(summary = "remove subjects from a community or a sub-community", description = "remove subjects from a community or a sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeCommunitySubjects(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.removeCommunitySubjects(ObjectUtils.firstNonNull(subCommunityId, id), subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/fos")
@Operation(summary = "associate a fos to a community or a sub-community", description = "associate a fos to a community or a sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addCommunityFOS(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.addCommunityFOS(ObjectUtils.firstNonNull(subCommunityId, id), subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/fos")
@Operation(summary = "remove fos from a community or a sub-community", description = "remove fos from a community or a sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeCommunityFOS(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.removeCommunityFOS(ObjectUtils.firstNonNull(subCommunityId, id), subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/sdg")
@Operation(summary = "associate a sdg to a community or a sub-community", description = "associate a sdg to the community or a sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addCommunitySDG(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.addCommunitySDG(ObjectUtils.firstNonNull(subCommunityId, id), subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/sdg")
@Operation(summary = "remove sdg from a community or a sub-community", description = "remove sdg from a community or a sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeCommunitySDG(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.removeCommunitySDG(ObjectUtils.firstNonNull(subCommunityId, id), subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/advancedConstraint")
@Operation(summary = "the set of constraints to be used to extend the association between result and community or sub-community", description = "the set of constraints to be used to extend the association between result and community or sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addAdvancedConstraint(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.addCommunityAdvancedConstraint(ObjectUtils.firstNonNull(subCommunityId, id), advancedConstraint);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/advancedConstraint")
@Operation(summary = "remove the constraints to extend the association result community from a community or a sub-community", description = "remove the constraints to extend the association result community from a community or a sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeAdvancedConstraint(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.removeCommunityAdvancedConstraint(ObjectUtils.firstNonNull(subCommunityId, id));
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/removeConstraint")
@Operation(summary = "the set of constraints to be used to remove the association between result and community or sub-community", description = "the set of constraints to be used to remove the association between result and community or sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addRemoveConstraint(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final SelectionCriteria removeConstraint) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.addCommunityRemoveConstraint(ObjectUtils.firstNonNull(subCommunityId, id), removeConstraint);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/removeConstraint")
@Operation(summary = "remove the constraints to remove the association beetween result and community or sub-community", description = "remove the constraints to remove the association beetween result and community or sub-community", tags = {
C, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeRemoveConstraint(@PathVariable final String id, @RequestParam(required = false) final String subCommunityId)
throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.removeCommunityRemoveConstraint(ObjectUtils.firstNonNull(subCommunityId, id));
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/zenodocommunities")
@Operation(summary = "associate a Zenodo community to a community or a sub-community", description = "associate a Zenodo community to the community or a sub-community", tags = {
C_ZC, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addCommunityZenodoCommunity(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
return communityService.addCommunityZenodoCommunity(ObjectUtils.firstNonNull(subCommunityId, id), zenodocommunity, main);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/zenodocommunities")
@Operation(summary = "remove a Zenodo community from a community or a sub-community", description = "remove a Zenodo community from a community or a sub-community", tags = {
C_ZC, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeCommunityZenodoCommunity(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
try {
communityService.removeCommunityZenodoCommunity(ObjectUtils.firstNonNull(subCommunityId, id), zenodocommunity, main);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// PROJECTS
@GetMapping("/community/{id}/projects/{page}/{size}") @GetMapping("/community/{id}/projects/{page}/{size}")
@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
@ -300,8 +628,6 @@ public class CommunityApiController extends AbstractExporterController {
} }
} }
// PROJECTS
@PostMapping("/community/{id}/projects") @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 = { @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 C_PJ, W
@ -729,269 +1055,6 @@ public class CommunityApiController extends AbstractExporterController {
// ********************** // **********************
@PostMapping("/community/{id}/subjects")
@Operation(summary = "associate a subject to the community", description = "associate a subject to the community", tags = {
C, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addCommunitySubjects(
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
try {
return communityService.addCommunitySubjects(id, subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subjects")
@Operation(summary = "remove subjects from a community", description = "remove subjects from a community", tags = {
C, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeCommunitySubjects(
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
try {
return communityService.removeCommunitySubjects(id, subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/fos")
@Operation(summary = "associate a fos to the community", description = "associate a fos to the community", tags = {
C, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addCommunityFOS(
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
try {
return communityService.addCommunityFOS(id, subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/fos")
@Operation(summary = "remove fos from a community", description = "remove fos from a community", tags = {
C, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeCommunityFOS(
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
try {
return communityService.removeCommunityFOS(id, subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/sdg")
@Operation(summary = "associate a sdg to the community", description = "associate a sdg to the community", tags = {
C, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addCommunitySDG(
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
try {
return communityService.addCommunitySDG(id, subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/sdg")
@Operation(summary = "remove sdg from a community", description = "remove sdg from a community", tags = {
C, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeCommunitySDG(
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
try {
return communityService.removeCommunitySDG(id, subjects);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addAdvancedConstraint(
@PathVariable final String id,
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException {
try {
return communityService.addCommunityAdvancedConstraint(id, advancedConstraint);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeAdvancedConstraint(
@PathVariable final String id) throws CommunityException {
try {
return communityService.removeCommunityAdvancedConstraint(id);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addRemoveConstraint(
@PathVariable final String id,
@RequestBody final SelectionCriteria removeConstraint) throws CommunityException {
try {
return communityService.addCommunityRemoveConstraint(id, removeConstraint);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeRemoveConstraint(@PathVariable final String id) throws CommunityException {
try {
return communityService.removeCommunityRemoveConstraint(id);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addCommunityZenodoCommunity(
@PathVariable final String id,
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
try {
return communityService.addCommunityZenodoCommunity(id, zenodocommunity, main);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeCommunityZenodoCommunity(
@PathVariable final String id,
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
try {
communityService.removeCommunityZenodoCommunity(id, zenodocommunity, main);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@GetMapping("/community/{zenodoId}/openairecommunities") @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 = { @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