From 1a7057ba05e88678ba1189075618ce90b9714cd8 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Wed, 16 Oct 2024 14:40:32 +0200 Subject: [PATCH] fixed a method name --- .../context/ContextApiController.java | 136 +++++++++--------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextApiController.java index f2f37f24..37d9e18f 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextApiController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/context/ContextApiController.java @@ -34,7 +34,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; @RestController @CrossOrigin(origins = { - "*" + "*" }) @ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true") @Tag(name = "OpenAIRE Context API", description = "the OpenAIRE Context API") @@ -46,28 +46,28 @@ public class ContextApiController extends AbstractExporterController { private static final Log log = LogFactory.getLog(ContextApiController.class); @RequestMapping(value = "/contexts", produces = { - "application/json" + "application/json" }, method = RequestMethod.GET) @Operation(summary = "list brief information about all the context profiles", description = "list brief information about all the context profiles") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public List listContexts(@RequestParam(required = false) final Set type) throws CommunityException { try { return communityService.listCommunities() - .stream() - .filter(c -> type == null || type.contains(c.getType())) - .map(c -> { - final ContextSummary ctx = new ContextSummary(); - ctx.setId(c.getId()); - ctx.setLabel(c.getName()); - ctx.setStatus(c.getStatus().toString()); - ctx.setType(c.getType().toString()); - return ctx; - }) - .collect(Collectors.toList()); + .stream() + .filter(c -> type == null || type.contains(c.getType())) + .map(c -> { + final ContextSummary ctx = new ContextSummary(); + ctx.setId(c.getId()); + ctx.setLabel(c.getName()); + ctx.setStatus(c.getStatus().toString()); + ctx.setType(c.getType().toString()); + return ctx; + }) + .collect(Collectors.toList()); } catch (final ResourceNotFoundException e) { throw e; } catch (final Throwable e) { @@ -76,33 +76,33 @@ public class ContextApiController extends AbstractExporterController { } @RequestMapping(value = "/context/{contextId}", produces = { - "application/json" + "application/json" }, method = RequestMethod.GET) @Operation(summary = "list the categories defined within a context", description = "list the categories defined within a context") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public List listCategories( - @PathVariable final String contextId, - @RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException { + @PathVariable final String contextId, + @RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException { try { - return communityService.getSubCommunities(contextId) - .stream() - .filter(sc -> all || sc.isClaim()) - .map(sc -> { - final String[] parts = StringUtils.split(sc.getSubCommunityId(), "::"); - if (parts.length < 3) { throw new RuntimeException("Invalid conceptId (It should have 3 (or more) parts): " + sc.getSubCommunityId()); } - final CategorySummary cat = new CategorySummary(); - cat.setId(parts[0] + "::" + parts[1]); - cat.setLabel(sc.getCategory()); - cat.setHasConcept(true); - return cat; - }) - .distinct() - .collect(Collectors.toList()); + return communityService.getSubCommunitiesForCommunity(contextId) + .stream() + .filter(sc -> all || sc.isClaim()) + .map(sc -> { + final String[] parts = StringUtils.split(sc.getSubCommunityId(), "::"); + if (parts.length < 3) { throw new RuntimeException("Invalid conceptId (It should have 3 (or more) parts): " + sc.getSubCommunityId()); } + final CategorySummary cat = new CategorySummary(); + cat.setId(parts[0] + "::" + parts[1]); + cat.setLabel(sc.getCategory()); + cat.setHasConcept(true); + return cat; + }) + .distinct() + .collect(Collectors.toList()); } catch (final ResourceNotFoundException e) { throw e; } catch (final Throwable e) { @@ -111,13 +111,13 @@ public class ContextApiController extends AbstractExporterController { } @RequestMapping(value = "/context/iis/conf/{contextId}", produces = { - "application/json" + "application/json" }, method = RequestMethod.GET) @Operation(summary = "return a list of entries for IIS", description = "return a list of entries for IIS") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public List getIISConfiguration(@PathVariable final String contextId) throws CommunityException { try { @@ -130,17 +130,17 @@ public class ContextApiController extends AbstractExporterController { } @RequestMapping(value = "/context/category/{categoryId}", produces = { - "application/json" + "application/json" }, method = RequestMethod.GET) @Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public List listConcepts( - @PathVariable final String categoryId, - @RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException { + @PathVariable final String categoryId, + @RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException { try { final String[] parts = StringUtils.split(categoryId, "::"); if (parts.length != 2) { @@ -162,17 +162,17 @@ public class ContextApiController extends AbstractExporterController { } @RequestMapping(value = "/context/category/concept/{conceptId}", produces = { - "application/json" + "application/json" }, method = RequestMethod.GET) @Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public List listSubConcepts( - @PathVariable final String conceptId, - @RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException { + @PathVariable final String conceptId, + @RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException { try { final String[] parts = StringUtils.split(conceptId, "::"); if (parts.length < 3) { @@ -194,26 +194,26 @@ public class ContextApiController extends AbstractExporterController { } private List findSubCommunities(final String prefix, final boolean all, final String contextId) throws CommunityException { - return communityService.getSubCommunities(contextId) - .stream() - .filter(sc -> all || sc.isClaim()) - .filter(sc -> sc.getSubCommunityId().startsWith(prefix)) - .collect(Collectors.toList()); + return communityService.getSubCommunitiesForCommunity(contextId) + .stream() + .filter(sc -> all || sc.isClaim()) + .filter(sc -> sc.getSubCommunityId().startsWith(prefix)) + .collect(Collectors.toList()); } private List processSubCommunities(final String parent, final List list) { return list.stream() - .filter(sc -> Objects.equals(sc.getParent(), parent)) - .map(sc -> { - final List childs = processSubCommunities(sc.getSubCommunityId(), list); - final ConceptSummary concept = new ConceptSummary(); - concept.setId(sc.getSubCommunityId()); - concept.setLabel(sc.getLabel()); - concept.setHasSubConcept(!childs.isEmpty()); - concept.setConcept(childs); - return concept; - }) - .collect(Collectors.toList()); + .filter(sc -> Objects.equals(sc.getParent(), parent)) + .map(sc -> { + final List childs = processSubCommunities(sc.getSubCommunityId(), list); + final ConceptSummary concept = new ConceptSummary(); + concept.setId(sc.getSubCommunityId()); + concept.setLabel(sc.getLabel()); + concept.setHasSubConcept(!childs.isEmpty()); + concept.setConcept(childs); + return concept; + }) + .collect(Collectors.toList()); } }