diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/broker/LiteratureBrokerServiceApplication.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/broker/LiteratureBrokerServiceApplication.java index 4c24d62c..4bf933a0 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/broker/LiteratureBrokerServiceApplication.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/broker/LiteratureBrokerServiceApplication.java @@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import eu.dnetlib.common.app.AbstractDnetApp; -import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; @@ -50,9 +49,6 @@ public class LiteratureBrokerServiceApplication extends AbstractDnetApp { .description("APIs documentation") .version("1.1") .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))) - .externalDocs(new ExternalDocumentation() - .description("SpringShop Wiki Documentation") - .url("https://springshop.wiki.github.org/docs")) .tags(tags); } } diff --git a/apps/dhp-broker-public-application/src/main/java/eu/dnetlib/broker/BrokerPublicApplication.java b/apps/dhp-broker-public-application/src/main/java/eu/dnetlib/broker/BrokerPublicApplication.java index 01cab66f..54774e41 100644 --- a/apps/dhp-broker-public-application/src/main/java/eu/dnetlib/broker/BrokerPublicApplication.java +++ b/apps/dhp-broker-public-application/src/main/java/eu/dnetlib/broker/BrokerPublicApplication.java @@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import eu.dnetlib.common.app.AbstractDnetApp; -import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; @@ -41,9 +40,6 @@ public class BrokerPublicApplication extends AbstractDnetApp { .description("APIs documentation") .version("1.1") .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))) - .externalDocs(new ExternalDocumentation() - .description("SpringShop Wiki Documentation") - .url("https://springshop.wiki.github.org/docs")) .tags(tags); } diff --git a/apps/dhp-mdstore-manager/src/main/java/eu/dnetlib/data/mdstore/manager/MainApplication.java b/apps/dhp-mdstore-manager/src/main/java/eu/dnetlib/data/mdstore/manager/MainApplication.java index 95abb9fd..4611b7dd 100644 --- a/apps/dhp-mdstore-manager/src/main/java/eu/dnetlib/data/mdstore/manager/MainApplication.java +++ b/apps/dhp-mdstore-manager/src/main/java/eu/dnetlib/data/mdstore/manager/MainApplication.java @@ -9,7 +9,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.scheduling.annotation.EnableScheduling; import eu.dnetlib.common.app.AbstractDnetApp; -import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; @@ -37,10 +36,7 @@ public class MainApplication extends AbstractDnetApp { openApi.info(new Info().title("MDStore Manager APIs") .description("APIs documentation") .version("1.1") - .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))) - .externalDocs(new ExternalDocumentation() - .description("SpringShop Wiki Documentation") - .url("https://springshop.wiki.github.org/docs")); + .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))); } } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/DNetOpenaireExporterApplication.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/DNetOpenaireExporterApplication.java index 486f44e4..9b642d0b 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/DNetOpenaireExporterApplication.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/DNetOpenaireExporterApplication.java @@ -16,7 +16,6 @@ import eu.dnetlib.openaire.dsm.DsmApiController; import eu.dnetlib.openaire.funders.FundersApiController; import eu.dnetlib.openaire.info.InfoController; import eu.dnetlib.openaire.project.ProjectsController; -import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; @@ -40,10 +39,7 @@ public class DNetOpenaireExporterApplication extends AbstractDnetApp { openApi.info(new Info().title("D-Net Exporter APIs") .description("APIs documentation") .version(V1) - .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))) - .externalDocs(new ExternalDocumentation() - .description("SpringShop Wiki Documentation") - .url("https://springshop.wiki.github.org/docs")); + .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))); } @Bean diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/MainApplication.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/MainApplication.java index ad4ce997..964b4d7b 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/MainApplication.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/MainApplication.java @@ -9,7 +9,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.scheduling.annotation.EnableScheduling; import eu.dnetlib.common.app.AbstractDnetApp; -import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; @@ -37,10 +36,7 @@ public class MainApplication extends AbstractDnetApp { openApi.info(new Info().title("D-Net Organizations Service APIs") .description("APIs documentation") .version("1.1") - .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))) - .externalDocs(new ExternalDocumentation() - .description("SpringShop Wiki Documentation") - .url("https://springshop.wiki.github.org/docs")); + .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))); } } diff --git a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/MainApplication.java b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/MainApplication.java index e8178368..cb936c26 100644 --- a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/MainApplication.java +++ b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/MainApplication.java @@ -1,10 +1,6 @@ package eu.dnetlib.scholix.api; -import eu.dnetlib.common.app.AbstractDnetApp; -import io.micrometer.core.aop.TimedAspect; -import io.micrometer.core.instrument.*; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; +import org.springdoc.core.GroupedOpenApi; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -13,28 +9,27 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.scheduling.annotation.EnableScheduling; - - - - - - -import java.time.Duration; -import java.util.Arrays; -import java.util.List; +import eu.dnetlib.common.app.AbstractDnetApp; +import io.micrometer.core.aop.TimedAspect; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.config.MeterFilter; +import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; @SpringBootApplication -@EnableSwagger2 @EnableCaching @EnableScheduling @ComponentScan(basePackages = "eu.dnetlib") public class MainApplication extends AbstractDnetApp { - private double scale = 1000000000; - - private double[] histogramValues =new double[]{.005 * scale, .01 * scale, .25 * scale, .5 * scale, .75 * scale, scale, 2.5 * scale, 5.0 * scale, 7.5 * scale, 10.0 * scale}; - + private final double scale = 1000000000; + private final double[] histogramValues = new double[] { + .005 * scale, .01 * scale, .25 * scale, .5 * scale, .75 * scale, scale, 2.5 * scale, 5.0 * scale, 7.5 * scale, 10.0 * scale + }; @Value("${dhp.swagger.api.host}") private String swaggetHost; @@ -42,31 +37,29 @@ public class MainApplication extends AbstractDnetApp { @Value("${dhp.swagger.api.basePath}") private String swaggerPath; - public static void main(final String[] args) { SpringApplication.run(MainApplication.class, args); } - - @Bean - public TaggedCounter myCounter(MeterRegistry meterRegistry) { + public TaggedCounter myCounter(final MeterRegistry meterRegistry) { - return new TaggedCounter(ScholixAPIConstants.SCHOLIX_MANAGER_COUNTER_NAME, ScholixAPIConstants.SCHOLIX_MANAGER_TAG_NAME,meterRegistry); + return new TaggedCounter(ScholixAPIConstants.SCHOLIX_MANAGER_COUNTER_NAME, ScholixAPIConstants.SCHOLIX_MANAGER_TAG_NAME, meterRegistry); } @Bean - public TimedAspect timedAspect(MeterRegistry meterRegistry) { - MeterFilter mf = new MeterFilter() { + public TimedAspect timedAspect(final MeterRegistry meterRegistry) { + final MeterFilter mf = new MeterFilter() { + @Override - public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) { + public DistributionStatisticConfig configure(final Meter.Id id, final DistributionStatisticConfig config) { if (id.getName().startsWith(ScholixAPIConstants.SCHOLIX_COUNTER_PREFIX)) { return DistributionStatisticConfig.builder() - .percentilesHistogram(false) - .serviceLevelObjectives( histogramValues) - .build() - .merge(config); + .percentilesHistogram(false) + .serviceLevelObjectives(histogramValues) + .build() + .merge(config); } return config; } @@ -75,50 +68,28 @@ public class MainApplication extends AbstractDnetApp { return new TimedAspect(meterRegistry); } - - @Override - protected void configSwagger(final Docket docket) { - docket - .host(swaggetHost) - .pathMapping(swaggerPath) - .groupName(ScholixAPIConstants.API_V1_NAME) - .select() - .apis(RequestHandlerSelectors.any()) - .paths(p -> p.startsWith("/v1")) - .build() - .apiInfo(new ApiInfoBuilder() - .title(ScholixAPIConstants.API_V1_NAME) - .description(ScholixAPIConstants.API_DESCRIPTION) - .version("1.0") - .contact(ApiInfo.DEFAULT_CONTACT) - .license("Apache 2.0") - .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0") - .build()); + @Bean + public GroupedOpenApi publicApiV1() { + return GroupedOpenApi.builder() + .group(ScholixAPIConstants.API_V1_NAME) + .pathsToMatch("/v1/**") + .build(); } + @Bean + public GroupedOpenApi publicApiV2() { + return GroupedOpenApi.builder() + .group(ScholixAPIConstants.API_V1_NAME) + .pathsToMatch("/v2/**") + .build(); + } - - @Bean (name = "SpringDocketv2") - public Docket v2Docket() { - final Docket docket = new Docket(DocumentationType.SWAGGER_2); - docket - .host(swaggetHost) - .pathMapping(swaggerPath) - .groupName(ScholixAPIConstants.API_V2_NAME) - .select() - .apis(RequestHandlerSelectors.any()) - .paths(p -> p.startsWith("/v2")) - .build() - .apiInfo(new ApiInfoBuilder() - .title(ScholixAPIConstants.API_V2_NAME) - .description(ScholixAPIConstants.API_DESCRIPTION) - .version("2.0") - .contact(ApiInfo.DEFAULT_CONTACT) - .license("Apache 2.0") - .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0") - .build()); - - return docket; + @Override + protected void configSwagger(final OpenAPI openApi) { + openApi.info(new Info().title("ScholeExplorer APIs") + .description("APIs documentation") + .version("1.1") + .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))); } } diff --git a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/DatasourceV1.java b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/DatasourceV1.java index e4491b41..26b9ab23 100644 --- a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/DatasourceV1.java +++ b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/DatasourceV1.java @@ -1,50 +1,41 @@ package eu.dnetlib.scholix.api.controller; -import eu.dnetlib.common.controller.AbstractDnetController; -import eu.dnetlib.dhp.schema.sx.api.model.v1.LinkPublisher; -import eu.dnetlib.scholix.api.ScholixException; -import eu.dnetlib.scholix.api.index.ScholixIndexManager; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; -import io.micrometer.core.annotation.Timed; -import io.swagger.annotations.Api; -import io.swagger.v3.oas.annotations.Operation; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - +import eu.dnetlib.common.controller.AbstractDnetController; +import eu.dnetlib.dhp.schema.sx.api.model.v1.LinkPublisher; +import eu.dnetlib.scholix.api.ScholixException; +import eu.dnetlib.scholix.api.index.ScholixIndexManager; +import io.micrometer.core.annotation.Timed; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; @RestController @RequestMapping("/v1") -@Tag(tags = { - "Datasources" -}) -public class DatasourceV1 extends AbstractDnetController { +@Tag(name = "Datasources") +public class DatasourceV1 extends AbstractDnetController { - @Autowired - private ScholixIndexManager manager; + @Autowired + private ScholixIndexManager manager; - @Timed(value = "scholix.v1.datasources", description = "Time taken to return all datasources on Version 1.0 of Scholix") - @Operation( - summary = "Get all Datasources", - description = "returns a list of all datasources") - @GetMapping("/listDatasources") - public List getDatasources() throws ScholixException { + @Timed(value = "scholix.v1.datasources", description = "Time taken to return all datasources on Version 1.0 of Scholix") + @Operation(summary = "Get all Datasources", description = "returns a list of all datasources") + @GetMapping("/listDatasources") + public List getDatasources() throws ScholixException { + final List> result = manager.totalLinksByProvider(null); - final List> result = manager.totalLinksByProvider(null); + if (result == null) { return new ArrayList<>(); } - if (result == null) - return new ArrayList<>(); + return result.stream().map(p -> new LinkPublisher().name(p.getKey()).totalRelationships(p.getValue().intValue())).collect(Collectors.toList()); - return result.stream().map(p -> new LinkPublisher().name(p.getKey()).totalRelationships(p.getValue().intValue())).collect(Collectors.toList()); - - - } + } } diff --git a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/LinkProviderV2.java b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/LinkProviderV2.java index 7b4ec1bc..942f222f 100644 --- a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/LinkProviderV2.java +++ b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/LinkProviderV2.java @@ -1,11 +1,9 @@ package eu.dnetlib.scholix.api.controller; -import eu.dnetlib.scholix.api.ScholixException; -import eu.dnetlib.scholix.api.index.ScholixIndexManager; -import eu.dnetlib.dhp.schema.sx.api.model.v2.LinkProviderType; -import io.swagger.annotations.Api; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -13,36 +11,33 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; +import eu.dnetlib.dhp.schema.sx.api.model.v2.LinkProviderType; +import eu.dnetlib.scholix.api.ScholixException; +import eu.dnetlib.scholix.api.index.ScholixIndexManager; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.tags.Tag; @RestController @RequestMapping("/v2") -@Tag(tags = { - "LinkProvider : Operation related to the Link Provider" -}) +@Tag(name = "LinkProvider : Operation related to the Link Provider") public class LinkProviderV2 { - @Autowired - ScholixIndexManager manager; + @Autowired + ScholixIndexManager manager; - @Operation( - summary = "Get all Link Providers", - description = "Return a list of link provider and relative number of relations") - @GetMapping("/LinkProvider") - public List getLinkProviders( - @Parameter(in = ParameterIn.QUERY, description = "Filter the link provider name") @RequestParam(required = false) String name - ) throws ScholixException { + @Operation(summary = "Get all Link Providers", description = "Return a list of link provider and relative number of relations") + @GetMapping("/LinkProvider") + public List getLinkProviders( + @Parameter(in = ParameterIn.QUERY, description = "Filter the link provider name") @RequestParam(required = false) final String name) + throws ScholixException { - List> result = manager.totalLinksByProvider(name); + final List> result = manager.totalLinksByProvider(name); - if (result==null) - return new ArrayList<>(); + if (result == null) { return new ArrayList<>(); } - return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList()); + return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList()); - - - } + } } diff --git a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/LinkPublisherV2.java b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/LinkPublisherV2.java index 6541d3b9..451d1b8e 100644 --- a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/LinkPublisherV2.java +++ b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/LinkPublisherV2.java @@ -1,11 +1,9 @@ package eu.dnetlib.scholix.api.controller; -import eu.dnetlib.scholix.api.ScholixException; -import eu.dnetlib.scholix.api.index.ScholixIndexManager; -import eu.dnetlib.dhp.schema.sx.api.model.v2.LinkProviderType; -import io.swagger.annotations.Api; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -13,49 +11,47 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; +import eu.dnetlib.dhp.schema.sx.api.model.v2.LinkProviderType; +import eu.dnetlib.scholix.api.ScholixException; +import eu.dnetlib.scholix.api.index.ScholixIndexManager; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.tags.Tag; @RestController @RequestMapping("/v2/LinkPublisher") -@Tag(tags = { - "LinkPublisher : Operation related to the Link Publisher" -}) +@Tag(name = "LinkPublisher : Operation related to the Link Publisher") public class LinkPublisherV2 { - @Autowired - ScholixIndexManager manager; + @Autowired + ScholixIndexManager manager; - @Operation( - summary = "Get All Publishers that provide source object", - description = "Return a List of all Publishers that provide source objects in Scholix " + - "links and the total number of links where the source object comes from this publisher") - @GetMapping("/inSource") - public List getInSource( - @Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name - ) throws ScholixException { - List> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.source,name); + @Operation(summary = "Get All Publishers that provide source object", description = "Return a List of all Publishers that provide source objects in Scholix " + + + "links and the total number of links where the source object comes from this publisher") + @GetMapping("/inSource") + public List getInSource( + @Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) final String name) + throws ScholixException { + final List> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.source, name); - if (result==null) - return new ArrayList<>(); + if (result == null) { return new ArrayList<>(); } - return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList()); - } + return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList()); + } - @Operation( - summary = "Get All Publishers that provide target object", - description = "Return a List of all Publishers that provide source objects in Scholix " + - "links and the total number of links where the target object comes from this publisher") - @GetMapping("/inTarget") - public List getInTarget( - @Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name - ) throws ScholixException { - List> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.target,name); + @Operation(summary = "Get All Publishers that provide target object", description = "Return a List of all Publishers that provide source objects in Scholix " + + + "links and the total number of links where the target object comes from this publisher") + @GetMapping("/inTarget") + public List getInTarget( + @Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) final String name) + throws ScholixException { + final List> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.target, name); - if (result==null) - return new ArrayList<>(); + if (result == null) { return new ArrayList<>(); } - return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList()); - } + return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList()); + } } diff --git a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/ScholixControllerV1.java b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/ScholixControllerV1.java index 04cc1aac..e5f57af9 100644 --- a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/ScholixControllerV1.java +++ b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/ScholixControllerV1.java @@ -1,114 +1,82 @@ package eu.dnetlib.scholix.api.controller; +import java.util.List; +import java.util.stream.Collectors; + +import javax.validation.constraints.NotNull; -import eu.dnetlib.common.controller.AbstractDnetController; -import eu.dnetlib.dhp.schema.sx.scholix.Scholix; -import eu.dnetlib.scholix.api.ScholixException; -import eu.dnetlib.scholix.api.index.ScholixIndexManager; -import eu.dnetlib.dhp.schema.sx.api.model.v1.ScholixV1; -import io.micrometer.core.annotation.Timed; -import io.swagger.annotations.Api; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.Schema; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; +import eu.dnetlib.common.controller.AbstractDnetController; +import eu.dnetlib.dhp.schema.sx.api.model.v1.ScholixV1; +import eu.dnetlib.dhp.schema.sx.scholix.Scholix; +import eu.dnetlib.scholix.api.ScholixException; +import eu.dnetlib.scholix.api.index.ScholixIndexManager; +import io.micrometer.core.annotation.Timed; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; @RestController @RequestMapping("/v1") -@Tag(tags = {"Scholix"}) +@Tag(name = "Scholix") public class ScholixControllerV1 extends AbstractDnetController { - @Autowired - ScholixIndexManager manager; + @Autowired + ScholixIndexManager manager; - @Operation( - summary = "Get all Scholix relation collected from a publisher", - description = "return a list of scholix object published from a specific publisher" - ) - @GetMapping("/linksFromPublisher") - @Timed(value = "scholix.v1.linksFromPublisher", description = "Time taken to return links on Version 1.0 of Scholix collected from a publisher") - public List linksFromPublisher( - @Parameter( - in = ParameterIn.QUERY, - description = "Filter Scholix relationships collected from a publisher", - schema = @Schema(), required = true) String publisher, - @Parameter(in = ParameterIn.QUERY, - description = "The page number") @RequestParam(required = false) Integer page - ) throws ScholixException { + @Operation(summary = "Get all Scholix relation collected from a publisher", description = "return a list of scholix object published from a specific publisher") + @GetMapping("/linksFromPublisher") + @Timed(value = "scholix.v1.linksFromPublisher", description = "Time taken to return links on Version 1.0 of Scholix collected from a publisher") + public List linksFromPublisher( + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships collected from a publisher", schema = @Schema(), required = true) final String publisher, + @Parameter(in = ParameterIn.QUERY, description = "The page number") @RequestParam(required = false) final Integer page) throws ScholixException { - final int currentPage = page != null ? page : 0; + final int currentPage = page != null ? page : 0; - Pair> scholixResult =manager.linksFromPid(null,null,null,publisher, - null,null,null,null,null, currentPage - ); - List scholixData = scholixResult.getValue(); - if (scholixData== null) - return null; - return scholixData.stream().map(ScholixV1::fromScholix).collect(Collectors.toList()); - } + final Pair> scholixResult = manager.linksFromPid(null, null, null, publisher, null, null, null, null, null, currentPage); + final List scholixData = scholixResult.getValue(); + if (scholixData == null) { return null; } + return scholixData.stream().map(ScholixV1::fromScholix).collect(Collectors.toList()); + } - @Operation( - summary = "Get all Scholix relation collected from a datasource", - description = "return a list of scholix object collected from a specific datasource" - ) - @GetMapping("/linksFromDatasource") - @Timed(value = "scholix.v1.linksFromDatasource", description = "Time taken to return links on Version 1.0 of Scholix collected from a LinkProvider") - public List linksFromDatasource( - @Parameter( - in = ParameterIn.QUERY, - description = "Filter Scholix relationships collected from a LinkProvider", - schema = @Schema()) @NotNull String datasource, - @Parameter(in = ParameterIn.QUERY, - description = "The page number") @RequestParam(required = false) Integer page - ) throws ScholixException { + @Operation(summary = "Get all Scholix relation collected from a datasource", description = "return a list of scholix object collected from a specific datasource") + @GetMapping("/linksFromDatasource") + @Timed(value = "scholix.v1.linksFromDatasource", description = "Time taken to return links on Version 1.0 of Scholix collected from a LinkProvider") + public List linksFromDatasource( + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships collected from a LinkProvider", schema = @Schema()) @NotNull final String datasource, + @Parameter(in = ParameterIn.QUERY, description = "The page number") @RequestParam(required = false) final Integer page) throws ScholixException { - final int currentPage = page != null ? page : 0; - Pair> scholixResult =manager.linksFromPid(datasource,null,null,null, - null,null,null,null,null, currentPage - ); - List scholixData = scholixResult.getValue(); - if (scholixData== null) - return null; - return scholixData.stream().map(ScholixV1::fromScholix).collect(Collectors.toList()); - } - - - @Operation( - summary = "Retrieve all scholix links from a persistent identifier", - description = "The linksFromPid endpoint returns a list of scholix object related from a specific persistent identifier" - ) - @GetMapping("/linksFromPid") - @Timed(value = "scholix.v1.linksFromPid", description = "Time taken to return links on Version 1.0 of Scholix related from a specific persistent identifier") - public List linksFromPid( - @Parameter(in = ParameterIn.QUERY, description = "persistent Identifier") @NotNull String pid, - @Parameter(in = ParameterIn.QUERY, description = "Persistent Identifier Type") @RequestParam(required = false) String pidType, - @Parameter(in = ParameterIn.QUERY, description = "typology target filter should be publication, dataset or unknown") @RequestParam(required = false) String typologyTarget, - @Parameter(in = ParameterIn.QUERY, description = "a datasource provenance filter of the target relation") @RequestParam(required = false) String datasourceTarget, - @Parameter(in = ParameterIn.QUERY, - description = "The page number") @RequestParam(required = false) Integer page - ) throws ScholixException { - - final int currentPage = page != null ? page : 0; - Pair> scholixResult =manager.linksFromPid(datasourceTarget,null,null,null, - typologyTarget,pid,pidType,null,null, currentPage - ); - List scholixData = scholixResult.getValue(); - if (scholixData== null) - return null; - return scholixData.stream().map(ScholixV1::fromScholix).collect(Collectors.toList()); - } + final int currentPage = page != null ? page : 0; + final Pair> scholixResult = manager.linksFromPid(datasource, null, null, null, null, null, null, null, null, currentPage); + final List scholixData = scholixResult.getValue(); + if (scholixData == null) { return null; } + return scholixData.stream().map(ScholixV1::fromScholix).collect(Collectors.toList()); + } + @Operation(summary = "Retrieve all scholix links from a persistent identifier", description = "The linksFromPid endpoint returns a list of scholix object related from a specific persistent identifier") + @GetMapping("/linksFromPid") + @Timed(value = "scholix.v1.linksFromPid", description = "Time taken to return links on Version 1.0 of Scholix related from a specific persistent identifier") + public List linksFromPid( + @Parameter(in = ParameterIn.QUERY, description = "persistent Identifier") @NotNull final String pid, + @Parameter(in = ParameterIn.QUERY, description = "Persistent Identifier Type") @RequestParam(required = false) final String pidType, + @Parameter(in = ParameterIn.QUERY, description = "typology target filter should be publication, dataset or unknown") @RequestParam(required = false) final String typologyTarget, + @Parameter(in = ParameterIn.QUERY, description = "a datasource provenance filter of the target relation") @RequestParam(required = false) final String datasourceTarget, + @Parameter(in = ParameterIn.QUERY, description = "The page number") @RequestParam(required = false) final Integer page) throws ScholixException { + final int currentPage = page != null ? page : 0; + final Pair> scholixResult = + manager.linksFromPid(datasourceTarget, null, null, null, typologyTarget, pid, pidType, null, null, currentPage); + final List scholixData = scholixResult.getValue(); + if (scholixData == null) { return null; } + return scholixData.stream().map(ScholixV1::fromScholix).collect(Collectors.toList()); + } } diff --git a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/ScholixControllerV2.java b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/ScholixControllerV2.java index d465a787..469af54d 100644 --- a/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/ScholixControllerV2.java +++ b/apps/scholexplorer-api/src/main/java/eu/dnetlib/scholix/api/controller/ScholixControllerV2.java @@ -1,5 +1,14 @@ package eu.dnetlib.scholix.api.controller; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import eu.dnetlib.common.controller.AbstractDnetController; import eu.dnetlib.dhp.schema.sx.api.model.v2.PageResultType; @@ -8,70 +17,53 @@ import eu.dnetlib.dhp.schema.sx.scholix.Scholix; import eu.dnetlib.scholix.api.ScholixException; import eu.dnetlib.scholix.api.index.ScholixIndexManager; import io.micrometer.core.annotation.Timed; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; -import java.util.stream.Collectors; +import io.swagger.v3.oas.annotations.tags.Tag; @RestController @RequestMapping("/v2") -@Tag(tags = { - "Links : Operation related to the Scholix Links" -}) +@Tag(name = "Links : Operation related to the Scholix Links") public class ScholixControllerV2 extends AbstractDnetController { - @Autowired - private ScholixIndexManager manager; + @Autowired + private ScholixIndexManager manager; - @Timed(value = "scholix.v2.links", description = "Time taken to return links on Version 2.0 of Scholix") - @Operation(summary = "Get Scholix Links") - @GetMapping("/Links") - public PageResultType links( - @Parameter(in = ParameterIn.QUERY, - description = "Filter Scholix relationships collected from a LinkProvider") String linkProvider, - @Parameter(in = ParameterIn.QUERY, - description = "Filter Scholix relationships having a target pid") String targetPid, - @Parameter(in = ParameterIn.QUERY, - description = "Filter Scholix relationships having a target pid type") String targetPidType, - @Parameter(in = ParameterIn.QUERY, - description = "Filter Scholix relationships having a target published in a Publisher named targetPublisher") String targetPublisher, - @Parameter(in = ParameterIn.QUERY, - description = "Filter Scholix relationships having a target type (literature, dataset, unknown)") String targetType, - @Parameter(in = ParameterIn.QUERY, - description = "Filter Scholix relationships having a source pid") String sourcePid, - @Parameter(in = ParameterIn.QUERY, - description = "Filter Scholix relationships having a source pid type") String sourcePidType, - @Parameter(in = ParameterIn.QUERY, - description = "Filter Scholix relationships having a source published in a Publisher named sourcePublisher") String sourcePublisher, - @Parameter(in = ParameterIn.QUERY, - description = "Filter Scholix relationships having a source type (literature, dataset, unknown)") String sourceType, -// @Parameter(in = ParameterIn.QUERY, -// description = "Filter scholix Links having collected after this date") String harvestedAfter, - @Parameter(in = ParameterIn.QUERY, - description = "select page of result") Integer page) throws Exception { + @Timed(value = "scholix.v2.links", description = "Time taken to return links on Version 2.0 of Scholix") + @Operation(summary = "Get Scholix Links") + @GetMapping("/Links") + public PageResultType links( + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships collected from a LinkProvider") final String linkProvider, + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships having a target pid") final String targetPid, + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships having a target pid type") final String targetPidType, + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships having a target published in a Publisher named targetPublisher") final String targetPublisher, + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships having a target type (literature, dataset, unknown)") final String targetType, + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships having a source pid") final String sourcePid, + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships having a source pid type") final String sourcePidType, + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships having a source published in a Publisher named sourcePublisher") final String sourcePublisher, + @Parameter(in = ParameterIn.QUERY, description = "Filter Scholix relationships having a source type (literature, dataset, unknown)") final String sourceType, + // @Parameter(in = ParameterIn.QUERY, + // description = "Filter scholix Links having collected after this date") String harvestedAfter, + @Parameter(in = ParameterIn.QUERY, description = "select page of result") final Integer page) throws Exception { - if (StringUtils.isEmpty(sourcePid) && StringUtils.isEmpty(targetPid) && StringUtils.isEmpty(sourcePublisher)&& StringUtils.isEmpty(targetPublisher)&& StringUtils.isEmpty(linkProvider)) - throw new ScholixException("The method requires one of the following parameters: sourcePid, targetPid, sourcePublisher, targetPublisher, linkProvider"); + if (StringUtils.isEmpty(sourcePid) && StringUtils.isEmpty(targetPid) && StringUtils.isEmpty(sourcePublisher) && StringUtils.isEmpty(targetPublisher) + && StringUtils.isEmpty(linkProvider)) { + throw new ScholixException( + "The method requires one of the following parameters: sourcePid, targetPid, sourcePublisher, targetPublisher, linkProvider"); + } - try { - final int currentPage = page != null ? page : 0; - Pair> scholixResult = manager.linksFromPid( linkProvider, targetPid, targetPidType, targetPublisher, targetType, sourcePid, sourcePidType, sourcePublisher, sourceType, currentPage); - final PageResultType pageResult = new PageResultType(); - pageResult.setTotalPages(scholixResult.getLeft().intValue() / 10); - pageResult.setTotalLinks(scholixResult.getLeft().intValue()); - pageResult.setResult(scholixResult.getRight().stream().map(ScholixType::fromScholix).collect(Collectors.toList())); - return pageResult; - } catch (Throwable e) { - throw new ScholixException("Error on requesting url ", e); - } - } + try { + final int currentPage = page != null ? page : 0; + final Pair> scholixResult = manager + .linksFromPid(linkProvider, targetPid, targetPidType, targetPublisher, targetType, sourcePid, sourcePidType, sourcePublisher, sourceType, currentPage); + final PageResultType pageResult = new PageResultType(); + pageResult.setTotalPages(scholixResult.getLeft().intValue() / 10); + pageResult.setTotalLinks(scholixResult.getLeft().intValue()); + pageResult.setResult(scholixResult.getRight().stream().map(ScholixType::fromScholix).collect(Collectors.toList())); + return pageResult; + } catch (final Throwable e) { + throw new ScholixException("Error on requesting url ", e); + } + } }