new_model_for_communities #15
|
@ -16,7 +16,9 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
||||||
import eu.dnetlib.openaire.exporter.exceptions.DsmApiException;
|
import eu.dnetlib.openaire.exporter.exceptions.DsmApiException;
|
||||||
|
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
|
||||||
import eu.dnetlib.openaire.exporter.model.dsm.Response;
|
import eu.dnetlib.openaire.exporter.model.dsm.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,17 +30,26 @@ public abstract class AbstractExporterController {
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler({
|
@ExceptionHandler({
|
||||||
DsmApiException.class
|
DsmApiException.class, CommunityException.class, Exception.class
|
||||||
})
|
})
|
||||||
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
public ErrorMessage handleDSMException(final Exception e) {
|
public ErrorMessage handle500(final Exception e) {
|
||||||
|
return _handleError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@ExceptionHandler({
|
||||||
|
ResourceNotFoundException.class
|
||||||
|
})
|
||||||
|
@ResponseStatus(value = HttpStatus.NOT_FOUND)
|
||||||
|
public ErrorMessage handle404(final Exception e) {
|
||||||
return _handleError(e);
|
return _handleError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
public List<ErrorMessage> processValidationError(final MethodArgumentNotValidException e) {
|
public List<ErrorMessage> handle400(final MethodArgumentNotValidException e) {
|
||||||
return e.getBindingResult()
|
return e.getBindingResult()
|
||||||
.getFieldErrors()
|
.getFieldErrors()
|
||||||
.stream()
|
.stream()
|
||||||
|
|
|
@ -23,8 +23,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import eu.dnetlib.common.controller.AbstractDnetController;
|
import eu.dnetlib.openaire.common.AbstractExporterController;
|
||||||
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
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.CommunityContentprovider;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
|
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.CommunityOpenAIRECommunities;
|
import eu.dnetlib.openaire.exporter.model.community.CommunityOpenAIRECommunities;
|
||||||
|
@ -44,7 +45,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
})
|
})
|
||||||
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
@Tag(name = "OpenAIRE Communities API", description = "the OpenAIRE Community API")
|
@Tag(name = "OpenAIRE Communities API", description = "the OpenAIRE Community API")
|
||||||
public class CommunityApiController extends AbstractDnetController {
|
public class CommunityApiController extends AbstractExporterController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CommunityService communityService;
|
private CommunityService communityService;
|
||||||
|
@ -60,7 +61,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<CommunitySummary> listCommunities() throws CommunityException {
|
public List<CommunitySummary> listCommunities() throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.listCommunities();
|
return communityService.listCommunities();
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/", produces = {
|
@RequestMapping(value = "/community/", produces = {
|
||||||
|
@ -75,7 +82,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public CommunityDetails getCommunity(@RequestBody final CommunityDetails details) throws CommunityException {
|
public CommunityDetails getCommunity(@RequestBody final CommunityDetails details) throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.newCommunity(details);
|
return communityService.newCommunity(details);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}", produces = {
|
@RequestMapping(value = "/community/{id}", produces = {
|
||||||
|
@ -90,7 +103,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public CommunityDetails getCommunity(@PathVariable final String id) throws CommunityException {
|
public CommunityDetails getCommunity(@PathVariable final String id) throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.getCommunity(id);
|
return communityService.getCommunity(id);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}", produces = {
|
@RequestMapping(value = "/community/{id}", produces = {
|
||||||
|
@ -107,8 +126,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public void setCommunity(
|
public void setCommunity(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final CommunityWritableProperties properties) throws CommunityException {
|
@RequestBody final CommunityWritableProperties properties) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.setCommunity(id, properties);
|
communityService.setCommunity(id, properties);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}", produces = {
|
@RequestMapping(value = "/community/{id}", produces = {
|
||||||
|
@ -124,7 +148,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
})
|
})
|
||||||
public void deleteCommunity(@PathVariable final String id, @RequestParam(required = false, defaultValue = "false") final boolean recursive)
|
public void deleteCommunity(@PathVariable final String id, @RequestParam(required = false, defaultValue = "false") final boolean recursive)
|
||||||
throws CommunityException {
|
throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.deleteCommunity(id, recursive);
|
communityService.deleteCommunity(id, recursive);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/projects/{page}/{size}", produces = {
|
@RequestMapping(value = "/community/{id}/projects/{page}/{size}", produces = {
|
||||||
|
@ -145,7 +175,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@RequestParam(required = false) final String searchFilter,
|
@RequestParam(required = false) final String searchFilter,
|
||||||
@RequestParam(required = false) final String orderBy)
|
@RequestParam(required = false) final String orderBy)
|
||||||
throws CommunityException {
|
throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.getCommunityProjects(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) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/projects", produces = {
|
@RequestMapping(value = "/community/{id}/projects", produces = {
|
||||||
|
@ -163,7 +199,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final CommunityProject project) throws CommunityException {
|
@RequestBody final CommunityProject project) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.addCommunityProject(id, project);
|
return communityService.addCommunityProject(id, project);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/projects", produces = {
|
@RequestMapping(value = "/community/{id}/projects", produces = {
|
||||||
|
@ -180,8 +222,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public void deleteCommunityProject(
|
public void deleteCommunityProject(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestParam final String projectId) throws CommunityException {
|
@RequestParam final String projectId) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.removeCommunityProjects(id, projectId);
|
communityService.removeCommunityProjects(id, projectId);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/projectList", produces = {
|
@RequestMapping(value = "/community/{id}/projectList", produces = {
|
||||||
|
@ -198,10 +245,14 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public CommunityProject[] addCommunityProjectList(
|
public CommunityProject[] addCommunityProjectList(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final CommunityProject[] projects) throws CommunityException {
|
@RequestBody final CommunityProject[] projects) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.addCommunityProjects(id, projects);
|
communityService.addCommunityProjects(id, projects);
|
||||||
|
|
||||||
return projects;
|
return projects;
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/projectList", produces = {
|
@RequestMapping(value = "/community/{id}/projectList", produces = {
|
||||||
|
@ -218,8 +269,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public void deleteCommunityProjectList(
|
public void deleteCommunityProjectList(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final String[] projectIdList) throws CommunityException {
|
@RequestBody final String[] projectIdList) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.removeCommunityProjects(id, projectIdList);
|
communityService.removeCommunityProjects(id, projectIdList);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/funders", produces = {
|
@RequestMapping(value = "/community/{id}/funders", produces = {
|
||||||
|
@ -235,7 +291,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
})
|
})
|
||||||
public List<String> getCommunityFunders(@PathVariable final String id)
|
public List<String> getCommunityFunders(@PathVariable final String id)
|
||||||
throws CommunityException {
|
throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.getCommunityFunders(id);
|
return communityService.getCommunityFunders(id);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
|
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
|
||||||
|
@ -250,7 +312,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id) throws CommunityException {
|
public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id) throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.getCommunityContentproviders(id);
|
return communityService.getCommunityContentproviders(id);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
|
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
|
||||||
|
@ -268,9 +336,14 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final CommunityContentprovider contentprovider) throws CommunityException {
|
@RequestBody final CommunityContentprovider contentprovider) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
communityService.addCommunityContentProviders(id, contentprovider);
|
communityService.addCommunityContentProviders(id, contentprovider);
|
||||||
|
|
||||||
return contentprovider;
|
return contentprovider;
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
|
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
|
||||||
|
@ -287,8 +360,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public void removeCommunityContentprovider(
|
public void removeCommunityContentprovider(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestParam final String contentproviderId) throws CommunityException {
|
@RequestParam final String contentproviderId) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.removeCommunityContentProviders(id, contentproviderId);
|
communityService.removeCommunityContentProviders(id, contentproviderId);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/contentprovidersList", produces = {
|
@RequestMapping(value = "/community/{id}/contentprovidersList", produces = {
|
||||||
|
@ -306,9 +384,14 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final CommunityContentprovider[] contentprovidersList) throws CommunityException {
|
@RequestBody final CommunityContentprovider[] contentprovidersList) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
communityService.addCommunityContentProviders(id, contentprovidersList);
|
communityService.addCommunityContentProviders(id, contentprovidersList);
|
||||||
|
|
||||||
return contentprovidersList;
|
return contentprovidersList;
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/contentprovidersList", produces = {
|
@RequestMapping(value = "/community/{id}/contentprovidersList", produces = {
|
||||||
|
@ -325,8 +408,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public void deleteCommunityContentProvidersList(
|
public void deleteCommunityContentProvidersList(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final String[] contentProviderIdList) throws CommunityException {
|
@RequestBody final String[] contentProviderIdList) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.removeCommunityContentProviders(id, contentProviderIdList);
|
communityService.removeCommunityContentProviders(id, contentProviderIdList);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ADDING CODE FOR COMMUNITY ORGANIZATIONS
|
// ADDING CODE FOR COMMUNITY ORGANIZATIONS
|
||||||
|
@ -343,7 +431,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<CommunityOrganization> getCommunityOrganizations(@PathVariable final String id) throws CommunityException {
|
public List<CommunityOrganization> getCommunityOrganizations(@PathVariable final String id) throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.getCommunityOrganizations(id);
|
return communityService.getCommunityOrganizations(id);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/organizations", produces = {
|
@RequestMapping(value = "/community/{id}/organizations", produces = {
|
||||||
|
@ -360,10 +454,14 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public CommunityOrganization addCommunityOrganization(
|
public CommunityOrganization addCommunityOrganization(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final CommunityOrganization organization) throws CommunityException {
|
@RequestBody final CommunityOrganization organization) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.addCommunityOrganizations(id, organization);
|
communityService.addCommunityOrganizations(id, organization);
|
||||||
|
|
||||||
return organization;
|
return organization;
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/organizationList", produces = {
|
@RequestMapping(value = "/community/{id}/organizationList", produces = {
|
||||||
|
@ -381,9 +479,14 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final CommunityOrganization[] orgs) throws CommunityException {
|
@RequestBody final CommunityOrganization[] orgs) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
communityService.addCommunityOrganizations(id, orgs);
|
communityService.addCommunityOrganizations(id, orgs);
|
||||||
|
|
||||||
return orgs;
|
return orgs;
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/organizations", produces = {
|
@RequestMapping(value = "/community/{id}/organizations", produces = {
|
||||||
|
@ -400,8 +503,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public void removeCommunityOrganization(
|
public void removeCommunityOrganization(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestParam final String organizationName) throws CommunityException {
|
@RequestParam final String organizationName) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.removeCommunityOrganizations(id, organizationName);
|
communityService.removeCommunityOrganizations(id, organizationName);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/organizationList", produces = {
|
@RequestMapping(value = "/community/{id}/organizationList", produces = {
|
||||||
|
@ -418,8 +526,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public void removeCommunityOrganizationList(
|
public void removeCommunityOrganizationList(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final String[] orgNames) throws CommunityException {
|
@RequestBody final String[] orgNames) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.removeCommunityOrganizations(id, orgNames);
|
communityService.removeCommunityOrganizations(id, orgNames);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// **********************
|
// **********************
|
||||||
|
@ -439,7 +552,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final String[] subjects) throws CommunityException {
|
@RequestBody final String[] subjects) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.addCommunitySubjects(id, subjects);
|
return communityService.addCommunitySubjects(id, subjects);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/subjects", produces = {
|
@RequestMapping(value = "/community/{id}/subjects", produces = {
|
||||||
|
@ -457,7 +576,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final String[] subjects) throws CommunityException {
|
@RequestBody final String[] subjects) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.removeCommunitySubjects(id, subjects);
|
return communityService.removeCommunitySubjects(id, subjects);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/fos", produces = {
|
@RequestMapping(value = "/community/{id}/fos", produces = {
|
||||||
|
@ -475,7 +600,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final String[] subjects) throws CommunityException {
|
@RequestBody final String[] subjects) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.addCommunityFOS(id, subjects);
|
return communityService.addCommunityFOS(id, subjects);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/fos", produces = {
|
@RequestMapping(value = "/community/{id}/fos", produces = {
|
||||||
|
@ -493,7 +624,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final String[] subjects) throws CommunityException {
|
@RequestBody final String[] subjects) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.removeCommunityFOS(id, subjects);
|
return communityService.removeCommunityFOS(id, subjects);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/sdg", produces = {
|
@RequestMapping(value = "/community/{id}/sdg", produces = {
|
||||||
|
@ -511,7 +648,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final String[] subjects) throws CommunityException {
|
@RequestBody final String[] subjects) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.addCommunitySDG(id, subjects);
|
return communityService.addCommunitySDG(id, subjects);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/sdg", produces = {
|
@RequestMapping(value = "/community/{id}/sdg", produces = {
|
||||||
|
@ -529,7 +672,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final String[] subjects) throws CommunityException {
|
@RequestBody final String[] subjects) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.removeCommunitySDG(id, subjects);
|
return communityService.removeCommunitySDG(id, subjects);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = {
|
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = {
|
||||||
|
@ -547,7 +696,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException {
|
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.addCommunityAdvancedConstraint(id, advancedConstraint);
|
return communityService.addCommunityAdvancedConstraint(id, advancedConstraint);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = {
|
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = {
|
||||||
|
@ -564,7 +719,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public CommunityDetails removeAdvancedConstraint(
|
public CommunityDetails removeAdvancedConstraint(
|
||||||
@PathVariable final String id) throws CommunityException {
|
@PathVariable final String id) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.removeCommunityAdvancedConstraint(id);
|
return communityService.removeCommunityAdvancedConstraint(id);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/removeConstraint", produces = {
|
@RequestMapping(value = "/community/{id}/removeConstraint", produces = {
|
||||||
|
@ -582,7 +743,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final SelectionCriteria removeConstraint) throws CommunityException {
|
@RequestBody final SelectionCriteria removeConstraint) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.addCommunityRemoveConstraint(id, removeConstraint);
|
return communityService.addCommunityRemoveConstraint(id, removeConstraint);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/removeConstraint", produces = {
|
@RequestMapping(value = "/community/{id}/removeConstraint", produces = {
|
||||||
|
@ -598,7 +765,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
})
|
})
|
||||||
public CommunityDetails removeRemoveConstraint(@PathVariable final String id) throws CommunityException {
|
public CommunityDetails removeRemoveConstraint(@PathVariable final String id) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.removeCommunityRemoveConstraint(id);
|
return communityService.removeCommunityRemoveConstraint(id);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
|
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
|
||||||
|
@ -617,7 +790,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@RequestParam(required = false, defaultValue = "false") final boolean main,
|
@RequestParam(required = false, defaultValue = "false") final boolean main,
|
||||||
@RequestParam final String zenodocommunity) throws CommunityException {
|
@RequestParam final String zenodocommunity) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.addCommunityZenodoCommunity(id, zenodocommunity, main);
|
return communityService.addCommunityZenodoCommunity(id, zenodocommunity, main);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,8 +815,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestParam(required = false, defaultValue = "false") final boolean main,
|
@RequestParam(required = false, defaultValue = "false") final boolean main,
|
||||||
@RequestParam final String zenodocommunity) throws CommunityException {
|
@RequestParam final String zenodocommunity) throws CommunityException {
|
||||||
|
try {
|
||||||
communityService.removeCommunityZenodoCommunity(id, zenodocommunity, main);
|
communityService.removeCommunityZenodoCommunity(id, zenodocommunity, main);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{zenodoId}/openairecommunities", produces = {
|
@RequestMapping(value = "/community/{zenodoId}/openairecommunities", produces = {
|
||||||
|
@ -652,10 +836,16 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public CommunityOpenAIRECommunities getOpenAireCommunities(@PathVariable final String zenodoId) throws CommunityException {
|
public CommunityOpenAIRECommunities getOpenAireCommunities(@PathVariable final String zenodoId) throws CommunityException {
|
||||||
|
try {
|
||||||
final CommunityOpenAIRECommunities res = new CommunityOpenAIRECommunities();
|
final CommunityOpenAIRECommunities res = new CommunityOpenAIRECommunities();
|
||||||
res.setZenodoid(zenodoId);
|
res.setZenodoid(zenodoId);
|
||||||
res.setOpenAirecommunitylist(communityService.getOpenAIRECommunitiesByZenodoId(zenodoId));
|
res.setOpenAirecommunitylist(communityService.getOpenAIRECommunitiesByZenodoId(zenodoId));
|
||||||
return res;
|
return res;
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// APIs to manage the propagationOrganizationCommunityMap
|
// APIs to manage the propagationOrganizationCommunityMap
|
||||||
|
@ -671,13 +861,19 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() throws CommunityException {
|
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.getPropagationOrganizationCommunityMap();
|
return communityService.getPropagationOrganizationCommunityMap();
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
|
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
|
||||||
"application/json"
|
"application/json"
|
||||||
}, method = RequestMethod.GET)
|
}, method = RequestMethod.GET)
|
||||||
@Operation(summary = "return the propagation organizations of a community", description = "return the propagation organizations of a community", tags = {
|
@Operation(summary = "try { return the propagation organizations of a community", description = "try { return the propagation organizations of a community", tags = {
|
||||||
C_O, R
|
C_O, R
|
||||||
})
|
})
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
|
@ -686,7 +882,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public Set<String> getPropagationOrganizationsForCommunity(@PathVariable final String id) throws CommunityException {
|
public Set<String> getPropagationOrganizationsForCommunity(@PathVariable final String id) throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.getPropagationOrganizationsForCommunity(id);
|
return communityService.getPropagationOrganizationsForCommunity(id);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
|
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
|
||||||
|
@ -703,7 +905,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public Set<String> addPropagationOrganizationForCommunity(@PathVariable final String id,
|
public Set<String> addPropagationOrganizationForCommunity(@PathVariable final String id,
|
||||||
@RequestParam final String organizationId) throws CommunityException {
|
@RequestParam final String organizationId) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.addPropagationOrganizationForCommunity(id, organizationId.split(","));
|
return communityService.addPropagationOrganizationForCommunity(id, organizationId.split(","));
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
|
@RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
|
||||||
|
@ -720,7 +928,13 @@ public class CommunityApiController extends AbstractDnetController {
|
||||||
public Set<String> removePropagationOrganizationForCommunity(@PathVariable final String id,
|
public Set<String> removePropagationOrganizationForCommunity(@PathVariable final String id,
|
||||||
@RequestParam final String organizationId) throws CommunityException {
|
@RequestParam final String organizationId) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.removePropagationOrganizationForCommunity(id, organizationId.split(","));
|
return communityService.removePropagationOrganizationForCommunity(id, organizationId.split(","));
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,16 +72,11 @@ public class CommunityService {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(CommunityService.class);
|
private static final Log log = LogFactory.getLog(CommunityService.class);
|
||||||
|
|
||||||
public List<CommunitySummary> listCommunities() throws CommunityException {
|
public List<CommunitySummary> listCommunities() {
|
||||||
try {
|
|
||||||
return dbCommunityRepository.findAll()
|
return dbCommunityRepository.findAll()
|
||||||
.stream()
|
.stream()
|
||||||
.map(CommunityMappingUtils::toCommunitySummary)
|
.map(CommunityMappingUtils::toCommunitySummary)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -98,39 +93,24 @@ public class CommunityService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommunityDetails saveCommunity(final CommunityDetails details) throws CommunityException {
|
public CommunityDetails saveCommunity(final CommunityDetails details) {
|
||||||
try {
|
|
||||||
details.setLastUpdateDate(LocalDateTime.now());
|
details.setLastUpdateDate(LocalDateTime.now());
|
||||||
dbCommunityRepository.save(CommunityMappingUtils.toCommunity(details));
|
dbCommunityRepository.save(CommunityMappingUtils.toCommunity(details));
|
||||||
return getCommunity(details.getId());
|
return getCommunity(details.getId());
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommunityDetails getCommunity(final String id) throws CommunityException {
|
public CommunityDetails getCommunity(final String id) {
|
||||||
try {
|
|
||||||
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
return CommunityMappingUtils.toCommunityDetails(c);
|
return CommunityMappingUtils.toCommunityDetails(c);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException {
|
public void setCommunity(final String id, final CommunityWritableProperties details) {
|
||||||
try {
|
|
||||||
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
CommunityMappingUtils.populateCommunity(c, details);
|
CommunityMappingUtils.populateCommunity(c, details);
|
||||||
c.setLastUpdateDate(LocalDateTime.now());
|
c.setLastUpdateDate(LocalDateTime.now());
|
||||||
dbCommunityRepository.save(c);
|
dbCommunityRepository.save(c);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -139,9 +119,7 @@ public class CommunityService {
|
||||||
final String filter,
|
final String filter,
|
||||||
final int page,
|
final int page,
|
||||||
final int size,
|
final int size,
|
||||||
final String orderBy)
|
final String orderBy) throws CommunityException {
|
||||||
|
|
||||||
throws CommunityException {
|
|
||||||
if (StringUtils.isBlank(id)) { throw new CommunityException("Empty ID"); }
|
if (StringUtils.isBlank(id)) { throw new CommunityException("Empty ID"); }
|
||||||
try {
|
try {
|
||||||
final Sort sort;
|
final Sort sort;
|
||||||
|
@ -203,15 +181,10 @@ public class CommunityService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommunityProject addCommunityProject(final String id, final CommunityProject project) throws CommunityException {
|
public CommunityProject addCommunityProject(final String id, final CommunityProject project) {
|
||||||
try {
|
|
||||||
final DbProject p = CommunityMappingUtils.toDbProject(id, project);
|
final DbProject p = CommunityMappingUtils.toDbProject(id, project);
|
||||||
dbProjectRepository.save(p);
|
dbProjectRepository.save(p);
|
||||||
return project;
|
return project;
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -229,249 +202,146 @@ public class CommunityService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeCommunityProjects(final String id, final String... ids) throws CommunityException {
|
public void removeCommunityProjects(final String id, final String... ids) {
|
||||||
try {
|
|
||||||
final List<DbProjectPK> list = Arrays.stream(ids)
|
final List<DbProjectPK> list = Arrays.stream(ids)
|
||||||
.map(projectId -> new DbProjectPK(id, projectId))
|
.map(projectId -> new DbProjectPK(id, projectId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
dbProjectRepository.deleteAllById(list);
|
dbProjectRepository.deleteAllById(list);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException {
|
public List<CommunityContentprovider> getCommunityContentproviders(final String id) {
|
||||||
try {
|
|
||||||
return dbDatasourceRepository.findByCommunity(id)
|
return dbDatasourceRepository.findByCommunity(id)
|
||||||
.stream()
|
.stream()
|
||||||
.map(CommunityMappingUtils::toCommunityContentprovider)
|
.map(CommunityMappingUtils::toCommunityContentprovider)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addCommunityContentProviders(final String id, final CommunityContentprovider... contentproviders)
|
public void addCommunityContentProviders(final String id, final CommunityContentprovider... contentproviders) {
|
||||||
throws CommunityException {
|
|
||||||
try {
|
|
||||||
final List<DbDatasource> list = Arrays.stream(contentproviders)
|
final List<DbDatasource> list = Arrays.stream(contentproviders)
|
||||||
.map(cp -> CommunityMappingUtils.toDbDatasource(id, cp))
|
.map(cp -> CommunityMappingUtils.toDbDatasource(id, cp))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
dbDatasourceRepository.saveAll(list);
|
dbDatasourceRepository.saveAll(list);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeCommunityContentProviders(final String id, final String... ids) throws CommunityException {
|
public void removeCommunityContentProviders(final String id, final String... ids) {
|
||||||
try {
|
|
||||||
final List<DbDatasourcePK> list = Arrays.stream(ids)
|
final List<DbDatasourcePK> list = Arrays.stream(ids)
|
||||||
.map(dsId -> new DbDatasourcePK(id, dsId))
|
.map(dsId -> new DbDatasourcePK(id, dsId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
dbDatasourceRepository.deleteAllById(list);
|
dbDatasourceRepository.deleteAllById(list);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeCommunityOrganizations(final String id, final String... orgNames) throws CommunityException {
|
public void removeCommunityOrganizations(final String id, final String... orgNames) {
|
||||||
try {
|
|
||||||
final List<DbSupportOrgPK> list = Arrays.stream(orgNames)
|
final List<DbSupportOrgPK> list = Arrays.stream(orgNames)
|
||||||
.map(name -> new DbSupportOrgPK(id, name))
|
.map(name -> new DbSupportOrgPK(id, name))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
dbSupportOrgRepository.deleteAllById(list);
|
dbSupportOrgRepository.deleteAllById(list);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException {
|
public List<CommunityOrganization> getCommunityOrganizations(final String id) {
|
||||||
try {
|
|
||||||
return dbSupportOrgRepository.findByCommunity(id)
|
return dbSupportOrgRepository.findByCommunity(id)
|
||||||
.stream()
|
.stream()
|
||||||
.map(CommunityMappingUtils::toCommunityOrganization)
|
.map(CommunityMappingUtils::toCommunityOrganization)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addCommunityOrganizations(final String id, final CommunityOrganization... orgs) throws CommunityException {
|
public void addCommunityOrganizations(final String id, final CommunityOrganization... orgs) {
|
||||||
try {
|
|
||||||
final List<DbSupportOrg> list = Arrays.stream(orgs)
|
final List<DbSupportOrg> list = Arrays.stream(orgs)
|
||||||
.map(o -> CommunityMappingUtils.toDbSupportOrg(id, o))
|
.map(o -> CommunityMappingUtils.toDbSupportOrg(id, o))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
dbSupportOrgRepository.saveAll(list);
|
dbSupportOrgRepository.saveAll(list);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeSubCommunity(final String id, final String subCommunityId) throws CommunityException {
|
public void removeSubCommunity(final String id, final String subCommunityId) {
|
||||||
try {
|
|
||||||
dbSubCommunityRepository.deleteById(subCommunityId);
|
dbSubCommunityRepository.deleteById(subCommunityId);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<SubCommunity> getSubCommunities(final String id) throws CommunityException {
|
public List<SubCommunity> getSubCommunities(final String id) {
|
||||||
try {
|
|
||||||
return dbSubCommunityRepository.findByCommunity(id)
|
return dbSubCommunityRepository.findByCommunity(id)
|
||||||
.stream()
|
.stream()
|
||||||
.map(CommunityMappingUtils::toSubCommunity)
|
.map(CommunityMappingUtils::toSubCommunity)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addSubCommunities(final SubCommunity... subs) throws CommunityException {
|
public void addSubCommunities(final SubCommunity... subs) {
|
||||||
try {
|
|
||||||
final List<DbSubCommunity> list = Arrays.stream(subs)
|
final List<DbSubCommunity> list = Arrays.stream(subs)
|
||||||
.map(CommunityMappingUtils::toDbSubCommunity)
|
.map(CommunityMappingUtils::toDbSubCommunity)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
dbSubCommunityRepository.saveAll(list);
|
dbSubCommunityRepository.saveAll(list);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommunityDetails addCommunitySubjects(final String id, final String... subjects) throws CommunityException {
|
public CommunityDetails addCommunitySubjects(final String id, final String... subjects) {
|
||||||
try {
|
|
||||||
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false, subjects);
|
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false, subjects);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) throws CommunityException {
|
public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) {
|
||||||
try {
|
|
||||||
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true, subjects);
|
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true, subjects);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails addCommunityFOS(final String id, final String... foss) throws CommunityException {
|
public CommunityDetails addCommunityFOS(final String id, final String... foss) {
|
||||||
try {
|
|
||||||
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), false, foss);
|
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), false, foss);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunityFOS(final String id, final String... foss) throws CommunityException {
|
public CommunityDetails removeCommunityFOS(final String id, final String... foss) {
|
||||||
try {
|
|
||||||
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), true, foss);
|
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), true, foss);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails addCommunitySDG(final String id, final String... sdgs) throws CommunityException {
|
public CommunityDetails addCommunitySDG(final String id, final String... sdgs) {
|
||||||
try {
|
|
||||||
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false, sdgs);
|
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false, sdgs);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) throws CommunityException {
|
public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) {
|
||||||
try {
|
|
||||||
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs);
|
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint)
|
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint) {
|
||||||
throws CommunityException {
|
|
||||||
try {
|
|
||||||
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
dbEntry.setAdvancedConstraints(advancedCosntraint);
|
dbEntry.setAdvancedConstraints(advancedCosntraint);
|
||||||
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
||||||
dbCommunityRepository.save(dbEntry);
|
dbCommunityRepository.save(dbEntry);
|
||||||
return getCommunity(id);
|
return getCommunity(id);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws CommunityException {
|
public CommunityDetails removeCommunityAdvancedConstraint(final String id) {
|
||||||
try {
|
|
||||||
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
dbEntry.setAdvancedConstraints(null);
|
dbEntry.setAdvancedConstraints(null);
|
||||||
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
||||||
dbCommunityRepository.save(dbEntry);
|
dbCommunityRepository.save(dbEntry);
|
||||||
return getCommunity(id);
|
return getCommunity(id);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommunityDetails addCommunityRemoveConstraint(final String id, final SelectionCriteria removeConstraint) throws CommunityException {
|
public CommunityDetails addCommunityRemoveConstraint(final String id, final SelectionCriteria removeConstraint) {
|
||||||
try {
|
|
||||||
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
dbEntry.setRemoveConstraints(removeConstraint);
|
dbEntry.setRemoveConstraints(removeConstraint);
|
||||||
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
||||||
dbCommunityRepository.save(dbEntry);
|
dbCommunityRepository.save(dbEntry);
|
||||||
return getCommunity(id);
|
return getCommunity(id);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommunityDetails removeCommunityRemoveConstraint(final String id) throws CommunityException {
|
public CommunityDetails removeCommunityRemoveConstraint(final String id) {
|
||||||
try {
|
|
||||||
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
dbEntry.setRemoveConstraints(null);
|
dbEntry.setRemoveConstraints(null);
|
||||||
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
||||||
dbCommunityRepository.save(dbEntry);
|
dbCommunityRepository.save(dbEntry);
|
||||||
return getCommunity(id);
|
return getCommunity(id);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain)
|
public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) {
|
||||||
throws CommunityException {
|
|
||||||
if (isMain) {
|
if (isMain) {
|
||||||
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), null);
|
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), null);
|
||||||
} else {
|
} else {
|
||||||
|
@ -479,34 +349,23 @@ public class CommunityService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain)
|
public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) {
|
||||||
throws CommunityException {
|
|
||||||
try {
|
|
||||||
if (isMain) {
|
if (isMain) {
|
||||||
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity);
|
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity);
|
||||||
} else {
|
} else {
|
||||||
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity);
|
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity);
|
||||||
}
|
}
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private CommunityDetails updateElementToSimpleField(final String id,
|
private CommunityDetails updateElementToSimpleField(final String id,
|
||||||
final BiConsumer<DbCommunity, String> setter,
|
final BiConsumer<DbCommunity, String> setter,
|
||||||
final String value) throws CommunityException {
|
final String value) {
|
||||||
try {
|
|
||||||
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
setter.accept(dbEntry, value);
|
setter.accept(dbEntry, value);
|
||||||
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
dbEntry.setLastUpdateDate(LocalDateTime.now());
|
||||||
dbCommunityRepository.save(dbEntry);
|
dbCommunityRepository.save(dbEntry);
|
||||||
return getCommunity(id);
|
return getCommunity(id);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -514,7 +373,7 @@ public class CommunityService {
|
||||||
final Function<DbCommunity, String[]> getter,
|
final Function<DbCommunity, String[]> getter,
|
||||||
final BiConsumer<DbCommunity, String[]> setter,
|
final BiConsumer<DbCommunity, String[]> setter,
|
||||||
final boolean remove,
|
final boolean remove,
|
||||||
final String... values) throws CommunityException {
|
final String... values) {
|
||||||
|
|
||||||
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
|
|
||||||
|
@ -541,66 +400,41 @@ public class CommunityService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<String> getOpenAIRECommunitiesByZenodoId(final String zenodoId) throws CommunityException {
|
public List<String> getOpenAIRECommunitiesByZenodoId(final String zenodoId) {
|
||||||
try {
|
|
||||||
return dbCommunityRepository.findByZenodoId(zenodoId);
|
return dbCommunityRepository.findByZenodoId(zenodoId);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() throws CommunityException {
|
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() {
|
||||||
try {
|
|
||||||
return dbOrganizationRepository.findAll()
|
return dbOrganizationRepository.findAll()
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet())));
|
.collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet())));
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Set<String> getPropagationOrganizationsForCommunity(final String communityId) throws CommunityException {
|
public Set<String> getPropagationOrganizationsForCommunity(final String communityId) {
|
||||||
try {
|
|
||||||
return dbOrganizationRepository.findByCommunity(communityId)
|
return dbOrganizationRepository.findByCommunity(communityId)
|
||||||
.stream()
|
.stream()
|
||||||
.map(DbOrganization::getOrgId)
|
.map(DbOrganization::getOrgId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Set<String> addPropagationOrganizationForCommunity(final String communityId, final String... organizationIds) throws CommunityException {
|
public Set<String> addPropagationOrganizationForCommunity(final String communityId, final String... organizationIds) {
|
||||||
try {
|
|
||||||
for (final String orgId : organizationIds) {
|
for (final String orgId : organizationIds) {
|
||||||
final DbOrganization o = new DbOrganization(communityId.trim(), orgId.trim());
|
final DbOrganization o = new DbOrganization(communityId.trim(), orgId.trim());
|
||||||
dbOrganizationRepository.save(o);
|
dbOrganizationRepository.save(o);
|
||||||
}
|
}
|
||||||
return getPropagationOrganizationsForCommunity(communityId);
|
return getPropagationOrganizationsForCommunity(communityId);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Set<String> removePropagationOrganizationForCommunity(final String communityId, final String... organizationIds) throws CommunityException {
|
public Set<String> removePropagationOrganizationForCommunity(final String communityId, final String... organizationIds) {
|
||||||
try {
|
|
||||||
for (final String orgId : organizationIds) {
|
for (final String orgId : organizationIds) {
|
||||||
final DbOrganization o = new DbOrganization(communityId.trim(), orgId.trim());
|
final DbOrganization o = new DbOrganization(communityId.trim(), orgId.trim());
|
||||||
dbOrganizationRepository.delete(o);
|
dbOrganizationRepository.delete(o);
|
||||||
}
|
}
|
||||||
return getPropagationOrganizationsForCommunity(communityId);
|
return getPropagationOrganizationsForCommunity(communityId);
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -616,8 +450,7 @@ public class CommunityService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<IISConfigurationEntry> getIISConfiguration(final String id) throws CommunityException {
|
public List<IISConfigurationEntry> getIISConfiguration(final String id) {
|
||||||
try {
|
|
||||||
final List<IISConfigurationEntry> res = new ArrayList<>();
|
final List<IISConfigurationEntry> res = new ArrayList<>();
|
||||||
|
|
||||||
res.add(dbCommunityRepository.findById(id)
|
res.add(dbCommunityRepository.findById(id)
|
||||||
|
@ -629,10 +462,6 @@ public class CommunityService {
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
} catch (final Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|
|
@ -17,9 +17,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import eu.dnetlib.common.controller.AbstractDnetController;
|
import eu.dnetlib.openaire.common.AbstractExporterController;
|
||||||
import eu.dnetlib.openaire.community.CommunityService;
|
import eu.dnetlib.openaire.community.CommunityService;
|
||||||
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
||||||
|
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.CommunityType;
|
import eu.dnetlib.openaire.exporter.model.community.CommunityType;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
|
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
||||||
|
@ -37,7 +38,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
})
|
})
|
||||||
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
@Tag(name = "OpenAIRE Context API", description = "the OpenAIRE Context API")
|
@Tag(name = "OpenAIRE Context API", description = "the OpenAIRE Context API")
|
||||||
public class ContextApiController extends AbstractDnetController {
|
public class ContextApiController extends AbstractExporterController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CommunityService communityService;
|
private CommunityService communityService;
|
||||||
|
@ -50,9 +51,11 @@ public class ContextApiController extends AbstractDnetController {
|
||||||
@Operation(summary = "list brief information about all the context profiles", description = "list brief information about all the context profiles")
|
@Operation(summary = "list brief information about all the context profiles", description = "list brief information about all the context profiles")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<ContextSummary> listContexts(@RequestParam(required = false) final Set<CommunityType> type) throws CommunityException {
|
public List<ContextSummary> listContexts(@RequestParam(required = false) final Set<CommunityType> type) throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.listCommunities()
|
return communityService.listCommunities()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(c -> type == null || type.contains(c.getType()))
|
.filter(c -> type == null || type.contains(c.getType()))
|
||||||
|
@ -65,6 +68,11 @@ public class ContextApiController extends AbstractDnetController {
|
||||||
return ctx;
|
return ctx;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/context/{contextId}", produces = {
|
@RequestMapping(value = "/context/{contextId}", produces = {
|
||||||
|
@ -73,6 +81,7 @@ public class ContextApiController extends AbstractDnetController {
|
||||||
@Operation(summary = "list the categories defined within a context", description = "list the categories defined within a context")
|
@Operation(summary = "list the categories defined within a context", description = "list the categories defined within a context")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<CategorySummary> listCategories(
|
public List<CategorySummary> listCategories(
|
||||||
|
@ -94,8 +103,9 @@ public class ContextApiController extends AbstractDnetController {
|
||||||
})
|
})
|
||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
log.error(e);
|
|
||||||
throw new CommunityException(e);
|
throw new CommunityException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,10 +116,17 @@ public class ContextApiController extends AbstractDnetController {
|
||||||
@Operation(summary = "return a list of entries for IIS", description = "return a list of entries for IIS")
|
@Operation(summary = "return a list of entries for IIS", description = "return a list of entries for IIS")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<IISConfigurationEntry> getIISConfiguration(@PathVariable final String contextId) throws CommunityException {
|
public List<IISConfigurationEntry> getIISConfiguration(@PathVariable final String contextId) throws CommunityException {
|
||||||
|
try {
|
||||||
return communityService.getIISConfiguration(contextId);
|
return communityService.getIISConfiguration(contextId);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/context/category/{categoryId}", produces = {
|
@RequestMapping(value = "/context/category/{categoryId}", produces = {
|
||||||
|
@ -118,12 +135,13 @@ public class ContextApiController extends AbstractDnetController {
|
||||||
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<ConceptSummary> listConcepts(
|
public List<ConceptSummary> listConcepts(
|
||||||
@PathVariable final String categoryId,
|
@PathVariable final String categoryId,
|
||||||
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
||||||
|
try {
|
||||||
final String[] parts = StringUtils.split(categoryId, "::");
|
final String[] parts = StringUtils.split(categoryId, "::");
|
||||||
if (parts.length != 2) {
|
if (parts.length != 2) {
|
||||||
log.error("Invalid category id (it should have 2 parts): " + categoryId);
|
log.error("Invalid category id (it should have 2 parts): " + categoryId);
|
||||||
|
@ -135,6 +153,11 @@ public class ContextApiController extends AbstractDnetController {
|
||||||
final List<SubCommunity> list = findSubCommunities(categoryId + "::", all, contextId);
|
final List<SubCommunity> list = findSubCommunities(categoryId + "::", all, contextId);
|
||||||
|
|
||||||
return processSubCommunities(null, list);
|
return processSubCommunities(null, list);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +167,13 @@ public class ContextApiController extends AbstractDnetController {
|
||||||
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<ConceptSummary> listSubConcepts(
|
public List<ConceptSummary> listSubConcepts(
|
||||||
@PathVariable final String conceptId,
|
@PathVariable final String conceptId,
|
||||||
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
||||||
|
try {
|
||||||
final String[] parts = StringUtils.split(conceptId, "::");
|
final String[] parts = StringUtils.split(conceptId, "::");
|
||||||
if (parts.length < 3) {
|
if (parts.length < 3) {
|
||||||
log.error("Invalid concept id (it should have 3 (or more) parts): " + conceptId);
|
log.error("Invalid concept id (it should have 3 (or more) parts): " + conceptId);
|
||||||
|
@ -161,6 +185,12 @@ public class ContextApiController extends AbstractDnetController {
|
||||||
final List<SubCommunity> list = findSubCommunities(conceptId + "::", all, contextId);
|
final List<SubCommunity> list = findSubCommunities(conceptId + "::", all, contextId);
|
||||||
|
|
||||||
return processSubCommunities(conceptId, list);
|
return processSubCommunities(conceptId, list);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SubCommunity> findSubCommunities(final String prefix, final boolean all, final String contextId) throws CommunityException {
|
private List<SubCommunity> findSubCommunities(final String prefix, final boolean all, final String contextId) throws CommunityException {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import eu.dnetlib.openaire.common.ISClient;
|
import eu.dnetlib.openaire.common.ISClient;
|
||||||
import eu.dnetlib.openaire.exporter.exceptions.ContextException;
|
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.Category;
|
import eu.dnetlib.openaire.exporter.model.context.Category;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.Concept;
|
import eu.dnetlib.openaire.exporter.model.context.Concept;
|
||||||
|
@ -31,7 +31,7 @@ public class ContextApiCore {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISClient isClient;
|
private ISClient isClient;
|
||||||
|
|
||||||
public List<ContextSummary> listContexts(final List<String> type) throws ContextException {
|
public List<ContextSummary> listContexts(final List<String> type) throws CommunityException {
|
||||||
|
|
||||||
return getContextMap(type).values()
|
return getContextMap(type).values()
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -48,7 +48,7 @@ public class ContextApiCore {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CategorySummary> listCategories(final String contextId, final Boolean all) throws ContextException {
|
public List<CategorySummary> listCategories(final String contextId, final Boolean all) throws CommunityException {
|
||||||
final Stream<Category> categories = getContextMap().get(contextId).getCategories().values().stream();
|
final Stream<Category> categories = getContextMap().get(contextId).getCategories().values().stream();
|
||||||
return all ? asCategorySummaries(categories) : asCategorySummaries(categories.filter(Category::isClaim));
|
return all ? asCategorySummaries(categories) : asCategorySummaries(categories.filter(Category::isClaim));
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public class ContextApiCore {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConceptSummary> listConcepts(final String categoryId, final Boolean all) throws ContextException {
|
public List<ConceptSummary> listConcepts(final String categoryId, final Boolean all) throws CommunityException {
|
||||||
final String contextId = StringUtils.substringBefore(categoryId, SEPARATOR);
|
final String contextId = StringUtils.substringBefore(categoryId, SEPARATOR);
|
||||||
final Stream<Concept> concepts = getContextMap().get(contextId)
|
final Stream<Concept> concepts = getContextMap().get(contextId)
|
||||||
.getCategories()
|
.getCategories()
|
||||||
|
@ -82,9 +82,9 @@ public class ContextApiCore {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConceptSummary> listSubConcepts(final String conceptId, final Boolean all) throws ContextException {
|
public List<ConceptSummary> listSubConcepts(final String conceptId, final Boolean all) throws CommunityException {
|
||||||
final List<String> ids = Splitter.on(SEPARATOR).splitToList(conceptId);
|
final List<String> ids = Splitter.on(SEPARATOR).splitToList(conceptId);
|
||||||
if (ids.size() < 3) { throw new ContextException(""); }
|
if (ids.size() < 3) { throw new CommunityException(""); }
|
||||||
|
|
||||||
final String contextId = ids.get(0);
|
final String contextId = ids.get(0);
|
||||||
final String categoryId = contextId + SEPARATOR + ids.get(1);
|
final String categoryId = contextId + SEPARATOR + ids.get(1);
|
||||||
|
@ -110,15 +110,15 @@ public class ContextApiCore {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Context> getContextMap() throws ContextException {
|
private Map<String, Context> getContextMap() throws CommunityException {
|
||||||
return getContextMap(Lists.newArrayList());
|
return getContextMap(Lists.newArrayList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Context> getContextMap(final List<String> type) throws ContextException {
|
private Map<String, Context> getContextMap(final List<String> type) throws CommunityException {
|
||||||
try {
|
try {
|
||||||
return isClient.getContextMap(type);
|
return isClient.getContextMap(type);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new ContextException(e);
|
throw new CommunityException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
package eu.dnetlib.openaire.exporter.exceptions;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class ContextException extends Exception {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = -5489369676370127052L;
|
|
||||||
|
|
||||||
public ContextException(final String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContextException(final IOException e) {
|
|
||||||
super(e);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package eu.dnetlib.openaire.exporter.exceptions;
|
|
||||||
|
|
||||||
public class ContextNotFoundException extends Exception {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = -2026506752817353752L;
|
|
||||||
|
|
||||||
public ContextNotFoundException(final String msg) {
|
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContextNotFoundException(final Exception e) {
|
|
||||||
super(e);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue