split methods in multiple controllers

This commit is contained in:
Michele Artini 2024-10-17 10:20:55 +02:00
parent bcaa00c66f
commit e43bf53483
3 changed files with 1085 additions and 570 deletions

View File

@ -4,18 +4,13 @@ import static eu.dnetlib.openaire.common.ExporterConstants.C;
import static eu.dnetlib.openaire.common.ExporterConstants.C_CP;
import static eu.dnetlib.openaire.common.ExporterConstants.C_O;
import static eu.dnetlib.openaire.common.ExporterConstants.C_PJ;
import static eu.dnetlib.openaire.common.ExporterConstants.C_SUB;
import static eu.dnetlib.openaire.common.ExporterConstants.C_ZC;
import static eu.dnetlib.openaire.common.ExporterConstants.R;
import static eu.dnetlib.openaire.common.ExporterConstants.W;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.domain.Page;
@ -35,12 +30,10 @@ import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
import eu.dnetlib.openaire.exporter.model.community.CommunityOpenAIRECommunities;
import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
import eu.dnetlib.openaire.exporter.model.community.CommunityWritableProperties;
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@ -159,125 +152,6 @@ public class CommunityApiController extends AbstractExporterController {
// APIs to manage the sub communities
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<SubCommunity> getSubCommunities(@PathVariable final String id, @RequestParam(required = false, defaultValue = "false") final boolean all)
throws CommunityException {
try {
return communityService.getSubCommunitiesForCommunity(id)
.stream()
.filter(sc -> all || sc.isBrowsable())
.collect(Collectors.toList());
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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 = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity addSubCommunity(
@PathVariable final String id,
@RequestBody final SubCommunity subcommunity) throws CommunityException {
try {
return communityService.addSubCommunity(id, subcommunity);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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 = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<SubCommunity> addSubCommunityList(
@PathVariable final String id,
@RequestBody final SubCommunity[] subcommunities) throws CommunityException {
for (final SubCommunity sub : subcommunities) {
if (!id.equals(CommunityMappingUtils.calculateMainCommunityId(sub.getSubCommunityId()))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
}
try {
final List<SubCommunity> res = new ArrayList<SubCommunity>();
for (final SubCommunity subc : subcommunities) {
res.add(communityService.addSubCommunity(id, subc));
}
return res;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeSubCommunity(
@PathVariable final String id,
@RequestParam final String subCommunityId) throws CommunityException {
try {
communityService.removeSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeSubcommunities(
@PathVariable final String id,
@RequestBody final String[] subCommunityIdList) throws CommunityException {
try {
for (final String subId : subCommunityIdList) {
communityService.removeSubCommunity(id, subId);
}
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// API to manage specific community fields
@PostMapping("/community/{id}/subjects")
@ -293,7 +167,7 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunitySubjects(id, subjects);
@ -319,8 +193,6 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, null);
try {
communityService.removeCommunitySubjects(id, subjects);
@ -345,7 +217,7 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunityFOS(id, subjects);
@ -371,7 +243,7 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityFOS(id, subjects);
@ -397,8 +269,6 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, null);
try {
communityService.addCommunitySDG(id, subjects);
@ -423,7 +293,7 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunitySDG(id, subjects);
@ -449,7 +319,7 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id,
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunityAdvancedConstraint(id, advancedConstraint);
@ -473,7 +343,7 @@ public class CommunityApiController extends AbstractExporterController {
})
public CommunityDetails removeCommunityAdvancedConstraint(@PathVariable final String id) throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityAdvancedConstraint(id);
@ -499,7 +369,7 @@ public class CommunityApiController extends AbstractExporterController {
@PathVariable final String id,
@RequestBody final SelectionCriteria removeConstraint) throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunityRemoveConstraint(id, removeConstraint);
@ -524,7 +394,7 @@ public class CommunityApiController extends AbstractExporterController {
public CommunityDetails removeCommunityRemoveConstraint(@PathVariable final String id)
throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityRemoveConstraint(id);
@ -551,7 +421,7 @@ public class CommunityApiController extends AbstractExporterController {
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunityZenodoCommunity(id, zenodocommunity, main);
@ -579,7 +449,7 @@ public class CommunityApiController extends AbstractExporterController {
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
verifyIdParameters(id, null);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityZenodoCommunity(id, zenodocommunity, main);
@ -592,330 +462,6 @@ public class CommunityApiController extends AbstractExporterController {
}
}
// API to manage specific sub-community fields
@PostMapping("/community/{id}/subcommunities/subjects")
@Operation(summary = "associate a subject to a sub-community", description = "associate a subject to 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 SubCommunity addSubCommunitySubjects(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunitySubjects(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/subjects")
@Operation(summary = "remove subjects from a sub-community", description = "remove subjects from 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 SubCommunity removeSubCommunitySubjects(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunitySubjects(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/fos")
@Operation(summary = "associate a fos to a sub-community", description = "associate a fos to 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 SubCommunity addSubCommunityFOS(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityFOS(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/fos")
@Operation(summary = "remove fos from a sub-community", description = "remove fos from 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 SubCommunity removeSubCommunityFOS(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityFOS(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/sdg")
@Operation(summary = "associate a sdg to a sub-community", description = "associate a sdg to the 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 SubCommunity addSubCommunitySDG(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunitySDG(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/sdg")
@Operation(summary = "remove sdg from a sub-community", description = "remove sdg from 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 SubCommunity removeSubCommunitySDG(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunitySDG(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/advancedConstraint")
@Operation(summary = "the set of constraints to be used to extend the association between result and sub-community", description = "the set of constraints to be used to extend the association between result and 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 SubCommunity addASubCommunitydvancedConstraint(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityAdvancedConstraint(subCommunityId, advancedConstraint);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/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, C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity removeSubCommunityAdvancedConstraint(@PathVariable final String id, @RequestParam final String subCommunityId)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityAdvancedConstraint(subCommunityId);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/removeConstraint")
@Operation(summary = "the set of constraints to be used to remove the association between result and sub-community", description = "the set of constraints to be used to remove the association between result and 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 SubCommunity addSubCommunityRemoveConstraint(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final SelectionCriteria removeConstraint) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityRemoveConstraint(subCommunityId, removeConstraint);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/removeConstraint")
@Operation(summary = "remove the constraints to remove the association beetween result and sub-community", description = "remove the constraints to remove the association beetween result and 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 SubCommunity removeSubCommunityRemoveConstraint(@PathVariable final String id, @RequestParam(required = false) final String subCommunityId)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityRemoveConstraint(subCommunityId);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/zenodocommunities")
@Operation(summary = "associate a Zenodo community to a sub-community", description = "associate a Zenodo community to 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 SubCommunity addSubCommunityZenodoCommunity(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityZenodoCommunity(subCommunityId, zenodocommunity, main);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/zenodocommunities")
@Operation(summary = "remove a Zenodo community from a sub-community", description = "remove a Zenodo community from 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 SubCommunity removeSubCommunityZenodoCommunity(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityZenodoCommunity(subCommunityId, zenodocommunity, main);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// PROJECTS
@GetMapping("/community/{id}/projects/{page}/{size}")
@ -930,16 +476,16 @@ public class CommunityApiController extends AbstractExporterController {
public Page<CommunityProject> getCommunityProjects(@PathVariable final String id,
@PathVariable final Integer page,
@PathVariable final Integer size,
@RequestParam(required = false) final String subCommunityId,
@RequestParam(required = false) final String funder,
@RequestParam(required = false) final String searchFilter,
@RequestParam(required = false) final String orderBy)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
return communityService.getCommunityProjects(ObjectUtils.firstNonNull(subCommunityId, id), funder, searchFilter, page, size, orderBy);
return communityService.getCommunityProjects(id, funder, searchFilter, page, size, orderBy);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -958,13 +504,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public CommunityProject addCommunityProject(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final CommunityProject project) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
return communityService.addCommunityProject(ObjectUtils.firstNonNull(subCommunityId, id), project);
return communityService.addCommunityProject(id, project);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -983,13 +529,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public void deleteCommunityProject(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestParam final String projectId) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityProjects(ObjectUtils.firstNonNull(subCommunityId, id), projectId);
communityService.removeCommunityProjects(id, projectId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -1008,13 +554,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public CommunityProject[] addCommunityProjectList(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final CommunityProject[] projects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunityProjects(ObjectUtils.firstNonNull(subCommunityId, id), projects);
communityService.addCommunityProjects(id, projects);
return projects;
} catch (final ResourceNotFoundException e) {
throw e;
@ -1034,13 +580,12 @@ public class CommunityApiController extends AbstractExporterController {
})
public void deleteCommunityProjectList(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final String[] projectIdList) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityProjects(ObjectUtils.firstNonNull(subCommunityId, id), projectIdList);
communityService.removeCommunityProjects(id, projectIdList);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -1057,13 +602,13 @@ public class CommunityApiController extends AbstractExporterController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<String> getCommunityFunders(@PathVariable final String id, @RequestParam(required = false) final String subCommunityId)
public List<String> getCommunityFunders(@PathVariable final String id)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
return communityService.getCommunityFunders(ObjectUtils.firstNonNull(subCommunityId, id));
return communityService.getCommunityFunders(id);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -1083,14 +628,14 @@ public class CommunityApiController extends AbstractExporterController {
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityContentprovider> getCommunityDatasources(@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestParam(required = false) final Boolean deposit)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
return deposit == null ? communityService.getCommunityDatasources(ObjectUtils.firstNonNull(subCommunityId, id))
return deposit == null ? communityService.getCommunityDatasources(id)
: communityService.getCommunityDatasourcesWithDeposit(id, deposit);
} catch (final ResourceNotFoundException e) {
throw e;
@ -1110,13 +655,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public CommunityContentprovider addCommunityDatasource(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final CommunityContentprovider datasource) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunityDatasources(ObjectUtils.firstNonNull(subCommunityId, id), datasource);
communityService.addCommunityDatasources(id, datasource);
return datasource;
} catch (final ResourceNotFoundException e) {
throw e;
@ -1136,13 +681,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public CommunityContentprovider addCommunityDatasourceDeposit(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final DepositionInfo info) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
return communityService.updateCommunityDatasourcesDeposit(ObjectUtils.firstNonNull(subCommunityId, id), info.getOpenaireId(), info
return communityService.updateCommunityDatasourcesDeposit(id, info.getOpenaireId(), info
.getDeposit(), info.getMessage());
} catch (final ResourceNotFoundException e) {
throw e;
@ -1162,13 +707,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public void removeCommunityDatasource(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestParam final String dsId) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityDatasources(ObjectUtils.firstNonNull(subCommunityId, id), dsId);
communityService.removeCommunityDatasources(id, dsId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -1187,13 +732,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public CommunityContentprovider[] addCommunityDatasourcesList(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final CommunityContentprovider[] dsList) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunityDatasources(ObjectUtils.firstNonNull(subCommunityId, id), dsList);
communityService.addCommunityDatasources(id, dsList);
return dsList;
} catch (final ResourceNotFoundException e) {
throw e;
@ -1213,13 +758,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public void deleteCommunityDatasourcesList(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final String[] dsIdList) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityDatasources(ObjectUtils.firstNonNull(subCommunityId, id), dsIdList);
communityService.removeCommunityDatasources(id, dsIdList);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -1238,12 +783,12 @@ public class CommunityApiController extends AbstractExporterController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityOrganization> getCommunityOrganizations(@PathVariable final String id, @RequestParam(required = false) final String subCommunityId)
public List<CommunityOrganization> getCommunityOrganizations(@PathVariable final String id)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
return communityService.getCommunityOrganizations(ObjectUtils.firstNonNull(subCommunityId, id));
return communityService.getCommunityOrganizations(id);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -1262,13 +807,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public CommunityOrganization addCommunityOrganization(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final CommunityOrganization organization) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunityOrganizations(ObjectUtils.firstNonNull(subCommunityId, id), organization);
communityService.addCommunityOrganizations(id, organization);
return organization;
} catch (final ResourceNotFoundException e) {
throw e;
@ -1288,13 +833,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public CommunityOrganization[] addCommunityOrganizationList(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final CommunityOrganization[] orgs) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.addCommunityOrganizations(ObjectUtils.firstNonNull(subCommunityId, id), orgs);
communityService.addCommunityOrganizations(id, orgs);
return orgs;
} catch (final ResourceNotFoundException e) {
throw e;
@ -1314,13 +859,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public void removeCommunityOrganization(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestParam final String organizationName) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityOrganizations(ObjectUtils.firstNonNull(subCommunityId, id), organizationName);
communityService.removeCommunityOrganizations(id, organizationName);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -1339,13 +884,13 @@ public class CommunityApiController extends AbstractExporterController {
})
public void removeCommunityOrganizationList(
@PathVariable final String id,
@RequestParam(required = false) final String subCommunityId,
@RequestBody final String[] orgNames) throws CommunityException {
verifyIdParameters(id, subCommunityId);
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
try {
communityService.removeCommunityOrganizations(ObjectUtils.firstNonNull(subCommunityId, id), orgNames);
communityService.removeCommunityOrganizations(id, orgNames);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
@ -1353,49 +898,7 @@ public class CommunityApiController extends AbstractExporterController {
}
}
// **********************
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityOpenAIRECommunities getOpenAireCommunities(@PathVariable final String zenodoId) throws CommunityException {
try {
final CommunityOpenAIRECommunities res = new CommunityOpenAIRECommunities();
res.setZenodoid(zenodoId);
res.setOpenAirecommunitylist(communityService.getOpenAIRECommunitiesByZenodoId(zenodoId));
return res;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// APIs to manage the propagationOrganizationCommunityMap
@GetMapping("/propagationOrganizationCommunityMap")
@Operation(summary = "Get the propagationOrganizationCommunityMap", description = "propagationOrganizationCommunityMap", tags = {
C_O, R
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() throws CommunityException {
try {
return communityService.getPropagationOrganizationCommunityMap();
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// Propagation Organizations
@GetMapping("/community/{id}/propagationOrganizations")
@Operation(summary = "try { return the propagation organizations of a community", description = "try { return the propagation organizations of a community", tags = {
@ -1458,16 +961,4 @@ public class CommunityApiController extends AbstractExporterController {
}
}
private void verifyIdParameters(final String id, final String subCommunityId) throws CommunityException {
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
if (subCommunityId != null && CommunityMappingUtils.isValidSubCommunityId(subCommunityId)) {
throw new CommunityException("Invalid sub-collection id: " + subCommunityId);
}
if (subCommunityId != null && !id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
}
}

View File

@ -0,0 +1,81 @@
package eu.dnetlib.openaire.community;
import static eu.dnetlib.openaire.common.ExporterConstants.C_O;
import static eu.dnetlib.openaire.common.ExporterConstants.C_ZC;
import static eu.dnetlib.openaire.common.ExporterConstants.R;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.openaire.common.AbstractExporterController;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityOpenAIRECommunities;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
@RestController
@CrossOrigin(origins = {
"*"
})
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
@Tag(name = "OpenAIRE Communities API", description = "the OpenAIRE Community API")
public class OtherCommunityApiController extends AbstractExporterController {
@Autowired
private CommunityService communityService;
// APIs to manage the propagationOrganizationCommunityMap
@GetMapping("/propagationOrganizationCommunityMap")
@Operation(summary = "Get the propagationOrganizationCommunityMap", description = "propagationOrganizationCommunityMap", tags = {
C_O, R
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() throws CommunityException {
try {
return communityService.getPropagationOrganizationCommunityMap();
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// Specific API for ZENODO communities
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityOpenAIRECommunities getOpenAireCommunities(@PathVariable final String zenodoId) throws CommunityException {
try {
final CommunityOpenAIRECommunities res = new CommunityOpenAIRECommunities();
res.setZenodoid(zenodoId);
res.setOpenAirecommunitylist(communityService.getOpenAIRECommunitiesByZenodoId(zenodoId));
return res;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
}

View File

@ -0,0 +1,943 @@
package eu.dnetlib.openaire.community;
import static eu.dnetlib.openaire.common.ExporterConstants.C_CP;
import static eu.dnetlib.openaire.common.ExporterConstants.C_O;
import static eu.dnetlib.openaire.common.ExporterConstants.C_PJ;
import static eu.dnetlib.openaire.common.ExporterConstants.C_SUB;
import static eu.dnetlib.openaire.common.ExporterConstants.C_ZC;
import static eu.dnetlib.openaire.common.ExporterConstants.R;
import static eu.dnetlib.openaire.common.ExporterConstants.W;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
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.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.community.utils.CommunityMappingUtils;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
@RestController
@CrossOrigin(origins = {
"*"
})
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
@Tag(name = "OpenAIRE Communities API", description = "the OpenAIRE Community API")
public class SubCommunityApiController extends AbstractExporterController {
@Autowired
private CommunityService communityService;
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<SubCommunity> getSubCommunities(@PathVariable final String id, @RequestParam(required = false, defaultValue = "false") final boolean all)
throws CommunityException {
try {
return communityService.getSubCommunitiesForCommunity(id)
.stream()
.filter(sc -> all || sc.isBrowsable())
.collect(Collectors.toList());
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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 = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity addSubCommunity(
@PathVariable final String id,
@RequestBody final SubCommunity subcommunity) throws CommunityException {
try {
return communityService.addSubCommunity(id, subcommunity);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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 = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<SubCommunity> addSubCommunityList(
@PathVariable final String id,
@RequestBody final SubCommunity[] subcommunities) throws CommunityException {
for (final SubCommunity sub : subcommunities) {
if (!id.equals(CommunityMappingUtils.calculateMainCommunityId(sub.getSubCommunityId()))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
}
try {
final List<SubCommunity> res = new ArrayList<SubCommunity>();
for (final SubCommunity subc : subcommunities) {
res.add(communityService.addSubCommunity(id, subc));
}
return res;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeSubCommunity(
@PathVariable final String id,
@RequestParam final String subCommunityId) throws CommunityException {
try {
communityService.removeSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeSubcommunities(
@PathVariable final String id,
@RequestBody final String[] subCommunityIdList) throws CommunityException {
try {
for (final String subId : subCommunityIdList) {
communityService.removeSubCommunity(id, subId);
}
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// API to manage specific sub-community fields
@PostMapping("/community/{id}/subcommunities/subjects")
@Operation(summary = "associate a subject to a sub-community", description = "associate a subject to a sub-community", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity addSubCommunitySubjects(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunitySubjects(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/subjects")
@Operation(summary = "remove subjects from a sub-community", description = "remove subjects from a sub-community", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity removeSubCommunitySubjects(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunitySubjects(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/fos")
@Operation(summary = "associate a fos to a sub-community", description = "associate a fos to a sub-community", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity addSubCommunityFOS(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityFOS(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/fos")
@Operation(summary = "remove fos from a sub-community", description = "remove fos from a sub-community", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity removeSubCommunityFOS(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityFOS(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/sdg")
@Operation(summary = "associate a sdg to a sub-community", description = "associate a sdg to the community", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity addSubCommunitySDG(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunitySDG(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/sdg")
@Operation(summary = "remove sdg from a sub-community", description = "remove sdg from a sub-community", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity removeSubCommunitySDG(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] subjects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunitySDG(subCommunityId, subjects);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/advancedConstraint")
@Operation(summary = "the set of constraints to be used to extend the association between result and sub-community", description = "the set of constraints to be used to extend the association between result and sub-community", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity addASubCommunitydvancedConstraint(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityAdvancedConstraint(subCommunityId, advancedConstraint);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/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_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity removeSubCommunityAdvancedConstraint(@PathVariable final String id, @RequestParam final String subCommunityId)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityAdvancedConstraint(subCommunityId);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/removeConstraint")
@Operation(summary = "the set of constraints to be used to remove the association between result and sub-community", description = "the set of constraints to be used to remove the association between result and sub-community", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity addSubCommunityRemoveConstraint(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final SelectionCriteria removeConstraint) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityRemoveConstraint(subCommunityId, removeConstraint);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/removeConstraint")
@Operation(summary = "remove the constraints to remove the association beetween result and sub-community", description = "remove the constraints to remove the association beetween result and sub-community", tags = {
C_SUB, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public SubCommunity removeSubCommunityRemoveConstraint(@PathVariable final String id, @RequestParam final String subCommunityId)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityRemoveConstraint(subCommunityId);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/zenodocommunities")
@Operation(summary = "associate a Zenodo community to a sub-community", description = "associate a Zenodo community to 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 SubCommunity addSubCommunityZenodoCommunity(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityZenodoCommunity(subCommunityId, zenodocommunity, main);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/zenodocommunities")
@Operation(summary = "remove a Zenodo community from a sub-community", description = "remove a Zenodo community from 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 SubCommunity removeSubCommunityZenodoCommunity(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestParam(required = false, defaultValue = "false") final boolean main,
@RequestParam final String zenodocommunity) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityZenodoCommunity(subCommunityId, zenodocommunity, main);
return communityService.getSubCommunity(id, subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// PROJECTS
@GetMapping("/community/{id}/subcommunities/projects/{page}/{size}")
@Operation(summary = "get community projects", description = "get community projects", tags = {
C_PJ, R
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public Page<CommunityProject> getCommunityProjects(@PathVariable final String id,
@PathVariable final Integer page,
@PathVariable final Integer size,
@RequestParam final String subCommunityId,
@RequestParam(required = false) final String funder,
@RequestParam(required = false) final String searchFilter,
@RequestParam(required = false) final String orderBy)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
return communityService.getCommunityProjects(subCommunityId, funder, searchFilter, page, size, orderBy);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/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 = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityProject addCommunityProject(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final CommunityProject project) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
return communityService.addCommunityProject(subCommunityId, project);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/projects")
@Operation(summary = "remove a project from the community", description = "remove a project from the community", tags = {
C_PJ, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void deleteCommunityProject(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestParam final String projectId) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityProjects(subCommunityId, projectId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/projectList")
@Operation(summary = "associate a list of project to the community", description = "associate a list of project to the community", tags = {
C_PJ, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityProject[] addCommunityProjectList(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final CommunityProject[] projects) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityProjects(subCommunityId, projects);
return projects;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/projectList")
@Operation(summary = "remove a list of projects from the community", description = "remove a list of projects from the community", tags = {
C_PJ, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void deleteCommunityProjectList(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] projectIdList) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityProjects(subCommunityId, projectIdList);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@GetMapping("/community/{id}/subcommunities/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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<String> getCommunityFunders(@PathVariable final String id, @RequestParam final String subCommunityId)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
return communityService.getCommunityFunders(subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// Datasources
@GetMapping("/community/{id}/subcommunities/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 = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityContentprovider> getCommunityDatasources(@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestParam(required = false) final Boolean deposit)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
return deposit == null ? communityService.getCommunityDatasources(subCommunityId)
: communityService.getCommunityDatasourcesWithDeposit(id, deposit);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/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,
@RequestParam final String subCommunityId,
@RequestBody final CommunityContentprovider datasource) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityDatasources(subCommunityId, datasource);
return datasource;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/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,
@RequestParam final String subCommunityId,
@RequestBody final DepositionInfo info) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
return communityService.updateCommunityDatasourcesDeposit(subCommunityId, info.getOpenaireId(), info
.getDeposit(), info.getMessage());
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/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 subCommunityId,
@RequestParam final String dsId) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityDatasources(subCommunityId, dsId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/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,
@RequestParam final String subCommunityId,
@RequestBody final CommunityContentprovider[] dsList) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityDatasources(subCommunityId, dsList);
return dsList;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/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,
@RequestParam final String subCommunityId,
@RequestBody final String[] dsIdList) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityDatasources(subCommunityId, dsIdList);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
// ORGANIZATIONS
@GetMapping("/community/{id}/subcommunities/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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityOrganization> getCommunityOrganizations(@PathVariable final String id, @RequestParam final String subCommunityId)
throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
return communityService.getCommunityOrganizations(subCommunityId);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/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 = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityOrganization addCommunityOrganization(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final CommunityOrganization organization) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityOrganizations(subCommunityId, organization);
return organization;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@PostMapping("/community/{id}/subcommunities/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 = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityOrganization[] addCommunityOrganizationList(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final CommunityOrganization[] orgs) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.addCommunityOrganizations(subCommunityId, orgs);
return orgs;
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeCommunityOrganization(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestParam final String organizationName) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityOrganizations(subCommunityId, organizationName);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
@DeleteMapping("/community/{id}/subcommunities/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
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public void removeCommunityOrganizationList(
@PathVariable final String id,
@RequestParam final String subCommunityId,
@RequestBody final String[] orgNames) throws CommunityException {
verifyIdParameters(id, subCommunityId);
try {
communityService.removeCommunityOrganizations(subCommunityId, orgNames);
} catch (final ResourceNotFoundException e) {
throw e;
} catch (final Throwable e) {
throw new CommunityException(e);
}
}
private void verifyIdParameters(final String id, final String subCommunityId) throws CommunityException {
if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }
if (CommunityMappingUtils.isValidSubCommunityId(subCommunityId)) { throw new CommunityException("Invalid sub-collection id: " + subCommunityId); }
if (!id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
throw new CommunityException("The sub-collection id does not start with " + id);
}
}
}