Compare commits

..

2 Commits

Author SHA1 Message Date
Alexios Symeonidis 79754cb7d3 implement checkstyle 2024-12-19 17:36:07 +02:00
Alexios Symeonidis b37437bce5 9720: impl call to scholix v2/Links 2024-12-19 15:53:47 +02:00
24 changed files with 421 additions and 99 deletions

3
.env
View File

@ -1,4 +1,5 @@
ZK_HOSTS=zookeeper-solr-openaire-dev-1:2181,zookeeper-solr-openaire-dev-2:2181,zookeeper-solr-openaire-dev-3:2181
SOLR_COLLECTION=public
OPENAPI_SERVER_BASE_URL=http://localhost:8080/graph
CONTEXT_PATH=/graph
CONTEXT_PATH=/graph
SCHOLIX_SERVER_BASE_URL=https://test.api.scholexplorer.openaire.eu

18
pom.xml
View File

@ -106,7 +106,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
@ -240,6 +239,23 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/src/main/resources/checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -0,0 +1,19 @@
package eu.openaire.api.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
@Configuration
public class ScholixClientConfig {
@Value("${scholix.server-base-url}")
private String baseUrl;
@Bean
public RestClient restClient() {
return RestClient.builder()
.baseUrl(baseUrl)
.build();
}
}

View File

@ -22,14 +22,17 @@ import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/dataSources")
@RequiredArgsConstructor
@Tag(name = "Data sources", description = "API endpoints to explore data sources")
public class DataSourceController
{
public class DataSourceController {
private final DataSourceService dataSourceService;

View File

@ -22,14 +22,17 @@ import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/organizations")
@RequiredArgsConstructor
@Tag(name = "Organizations", description = "API endpoints to explore organizations")
public class OrganizationController
{
public class OrganizationController {
private final OrganizationService organizationService;

View File

@ -22,14 +22,17 @@ import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/projects")
@RequiredArgsConstructor
@Tag(name = "Projects", description = "API endpoints to explore projects")
public class ProjectController
{
public class ProjectController {
private final ProjectService projectService;

View File

@ -23,14 +23,17 @@ import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/researchProducts")
@RequiredArgsConstructor
@Tag(name = "Research products", description = "API endpoints to explore research products")
public class ResearchProductsController
{
public class ResearchProductsController {
private final ResearchProductService researchProductService;

View File

@ -0,0 +1,54 @@
package eu.openaire.api.controllers;
import eu.dnetlib.dhp.schema.sx.api.model.v2.PageResultType;
import eu.openaire.api.dto.request.validators.PaginationValidator;
import eu.openaire.api.errors.ErrorResponse;
import eu.openaire.api.services.ScholixService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@Tag(name = "Scholix Relations", description = "API endpoints to explore scholix")
public class ScholixController {
private final ScholixService scholixService;
// common validator to check pagination parameters
private final PaginationValidator paginationValidator;
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.addValidators(paginationValidator);
}
@Operation(
summary = "Retrieve scholix links by sourcePid and sourceType",
description = "Retrieve scholix links by sourcePid and sourceType"
)
@ApiResponses({
@ApiResponse(responseCode = "200", content = { @Content(schema = @Schema(implementation = PageResultType.class), mediaType = "application/json") }),
@ApiResponse(responseCode = "404", content = { @Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json") }),
@ApiResponse(responseCode = "500", content = { @Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json") })
})
@GetMapping("/links")
public PageResultType getLinks(@RequestParam
@Parameter(description = "The OpenAIRE Id") String sourcePid,
@RequestParam(required = false)
@Parameter(description = "The OpenAIRE Source Type") String sourceType,
@RequestParam(defaultValue = "0")
@Parameter(description = "Page number of the results") int page) {
return scholixService.getLinks(sourcePid, sourceType, page);
}
}

View File

@ -1,6 +1,10 @@
package eu.openaire.api.dto.request.validators;
import eu.openaire.api.dto.request.*;
import eu.openaire.api.dto.request.DataSourceRequest;
import eu.openaire.api.dto.request.OrganizationRequest;
import eu.openaire.api.dto.request.PaginatedRequest;
import eu.openaire.api.dto.request.ProjectRequest;
import eu.openaire.api.dto.request.ResearchProductsRequest;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;

View File

@ -5,10 +5,12 @@ import eu.openaire.api.errors.exceptions.NotFoundException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.client.RestClientResponseException;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.resource.NoResourceFoundException;
@ -60,6 +62,22 @@ public class ServiceExceptionHandler {
return this.handleException(e.getMessage(), request, HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(RestClientResponseException.class)
public ResponseEntity<ErrorResponse> handleRestClientResponseException(RestClientResponseException e, WebRequest request) {
HttpStatusCode status = e.getStatusCode();
String path = ((ServletWebRequest) request).getRequest().getRequestURI();
ErrorResponse response = ErrorResponse.builder()
.message(e.getMessage())
.error(status.toString())
.code(status.value())
.timestamp(new Date())
.path(path)
.build();
return ResponseEntity.status(status.value()).body(response);
}
private ResponseEntity<ErrorResponse> handleException(String message, WebRequest request, HttpStatus httpStatus) {
var req = ((ServletWebRequest)request).getRequest();
String path = String.format("%s?%s", req.getRequestURI(), req.getQueryString());

View File

@ -10,11 +10,15 @@ import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class Utils {
private Utils() {}
private Utils() { }
public static final String API_PAGE_DESC = """
Page number of the results,\s

View File

@ -3,7 +3,11 @@ package eu.openaire.api.mappers.query;
import eu.openaire.api.dto.request.DataSourceRequest;
import eu.openaire.api.mappers.Utils;
import eu.openaire.api.solr.SolrQueryParams;
import org.mapstruct.*;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Named;
import java.util.ArrayList;
import java.util.Map;
@ -15,7 +19,7 @@ public interface DataSourceRequestMapper {
@Mapping(target = "rows", source = "pageSize")
@Mapping(target = "debugQuery", source = "debugQuery")
@Mapping(target = "cursor", source = "cursor")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.dataSourceSortMapping) )")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.DATASOURCE_SORT_MAPPING) )")
SolrQueryParams toSolrQuery(DataSourceRequest src);
@Named("calculateStart")
@ -26,7 +30,7 @@ public interface DataSourceRequestMapper {
@AfterMapping
default void paramsCustomMapping(DataSourceRequest src, @MappingTarget SolrQueryParams solrQueryParams) {
final Map<String, String> solrFieldMapping = SolrFieldsMapper.dataSourceFieldMapping;
final Map<String, String> solrFieldMapping = SolrFieldsMapper.DATASOURCE_FIELD_MAPPING;
var qList = new ArrayList<String>();

View File

@ -3,7 +3,11 @@ package eu.openaire.api.mappers.query;
import eu.openaire.api.dto.request.OrganizationRequest;
import eu.openaire.api.mappers.Utils;
import eu.openaire.api.solr.SolrQueryParams;
import org.mapstruct.*;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Named;
import java.util.ArrayList;
import java.util.Map;
@ -11,12 +15,10 @@ import java.util.Map;
@Mapper(componentModel = "spring")
public interface OrganizationRequestMapper {
@Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )")
@Mapping(target = "rows", source = "pageSize")
@Mapping(target = "debugQuery", source = "debugQuery")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.organizationSortMapping) )")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.ORGANIZATION_SORT_MAPPING) )")
SolrQueryParams toSolrQuery(OrganizationRequest src);
@Named("calculateStart")
@ -27,7 +29,7 @@ public interface OrganizationRequestMapper {
@AfterMapping
default void paramsCustomMapping(OrganizationRequest src, @MappingTarget SolrQueryParams solrQueryParams) {
final Map<String, String> solrFieldMapping = SolrFieldsMapper.organizationFieldsMapping;
final Map<String, String> solrFieldMapping = SolrFieldsMapper.ORGANIZATION_FIELDS_MAPPING;
var qList = new ArrayList<String>();

View File

@ -3,7 +3,11 @@ package eu.openaire.api.mappers.query;
import eu.openaire.api.dto.request.ProjectRequest;
import eu.openaire.api.mappers.Utils;
import eu.openaire.api.solr.SolrQueryParams;
import org.mapstruct.*;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Named;
import java.util.ArrayList;
import java.util.Map;
@ -15,7 +19,7 @@ public interface ProjectRequestMapper {
@Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )")
@Mapping(target = "rows", source = "pageSize")
@Mapping(target = "debugQuery", source = "debugQuery")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.projectSortMapping) )")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.PROJECT_SORT_MAPPING) )")
SolrQueryParams toSolrQuery(ProjectRequest src);
@Named("calculateStart")
@ -26,7 +30,7 @@ public interface ProjectRequestMapper {
@AfterMapping
default void paramsCustomMapping(ProjectRequest src, @MappingTarget SolrQueryParams solrQueryParams) {
final Map<String, String> solrFieldMapping = SolrFieldsMapper.projectFieldMapping;
final Map<String, String> solrFieldMapping = SolrFieldsMapper.PROJECT_FIELD_MAPPING;
var qList = new ArrayList<String>();

View File

@ -3,7 +3,11 @@ package eu.openaire.api.mappers.query;
import eu.openaire.api.dto.request.ResearchProductsRequest;
import eu.openaire.api.mappers.Utils;
import eu.openaire.api.solr.SolrQueryParams;
import org.mapstruct.*;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Named;
import java.util.ArrayList;
import java.util.Arrays;
@ -16,7 +20,7 @@ public interface ResearchProductsRequestMapper {
@Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )")
@Mapping(target = "rows", source = "pageSize")
@Mapping(target = "debugQuery", source = "debugQuery")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.researchProductSortMapping) )")
@Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.RESEARCH_PRODUCT_SORT_MAPPING) )")
SolrQueryParams toSolrQuery(ResearchProductsRequest src);
@Named("calculateStart")
@ -27,7 +31,7 @@ public interface ResearchProductsRequestMapper {
@AfterMapping
default void paramsCustomMapping(ResearchProductsRequest src, @MappingTarget SolrQueryParams solrQueryParams) {
final Map<String, String> solrFieldMapping = SolrFieldsMapper.researchProductFieldMapping;
final Map<String, String> solrFieldMapping = SolrFieldsMapper.RESEARCH_PRODUCT_FIELD_MAPPING;
var qList = new ArrayList<String>();

View File

@ -5,7 +5,7 @@ import java.util.Map;
public class SolrFieldsMapper {
// mappings for the organization entity
public static final Map<String, String> organizationFieldsMapping = java.util.Map.ofEntries(
public static final Map<String, String> ORGANIZATION_FIELDS_MAPPING = java.util.Map.ofEntries(
// search field mapping
Map.entry("search", "__all:(%s)"),
@ -23,12 +23,12 @@ public class SolrFieldsMapper {
);
public static final Map<String, String> organizationSortMapping = Map.ofEntries(
public static final Map<String, String> ORGANIZATION_SORT_MAPPING = Map.ofEntries(
Map.entry("relevance", "score")
);
// mappings for the datasource entity
public static final Map<String, String> dataSourceFieldMapping = Map.ofEntries(
public static final Map<String, String> DATASOURCE_FIELD_MAPPING = Map.ofEntries(
// search field mapping
Map.entry("search", "__all:(%s)"),
@ -48,13 +48,13 @@ public class SolrFieldsMapper {
Map.entry("relCollectedFromDatasourceId", "collectedfromdatasourceid:(%s)")
);
public static final Map<String, String> dataSourceSortMapping = Map.ofEntries(
public static final Map<String, String> DATASOURCE_SORT_MAPPING = Map.ofEntries(
Map.entry("relevance", "score")
);
// mappings for the project entity
public static final Map<String, String> projectFieldMapping = Map.ofEntries(
public static final Map<String, String> PROJECT_FIELD_MAPPING = Map.ofEntries(
// search field mapping
Map.entry("search", "__all:(%s)"),
@ -81,13 +81,13 @@ public class SolrFieldsMapper {
);
public static final Map<String, String> projectSortMapping = Map.ofEntries(
public static final Map<String, String> PROJECT_SORT_MAPPING = Map.ofEntries(
Map.entry("relevance", "score"),
Map.entry("startDate", "projectstartyear"),
Map.entry("endDate", "projectendyear")
);
public static final Map<String, String> researchProductFieldMapping = Map.ofEntries(
public static final Map<String, String> RESEARCH_PRODUCT_FIELD_MAPPING = Map.ofEntries(
// search field mapping
Map.entry("search", "__all:(%s)"),
@ -134,7 +134,7 @@ public class SolrFieldsMapper {
);
public static final Map<String, String> researchProductSortMapping = Map.ofEntries(
public static final Map<String, String> RESEARCH_PRODUCT_SORT_MAPPING = Map.ofEntries(
Map.entry("relevance", "score"),
Map.entry("publicationDate", "resultdateofacceptance"),

View File

@ -5,7 +5,12 @@ import eu.dnetlib.dhp.oa.model.Indicator;
import eu.dnetlib.dhp.oa.model.graph.Datasource;
import eu.dnetlib.dhp.oa.model.graph.DatasourcePid;
import eu.dnetlib.dhp.oa.model.graph.DatasourceSchemeValue;
import eu.dnetlib.dhp.schema.solr.*;
import eu.dnetlib.dhp.schema.solr.CodeLabel;
import eu.dnetlib.dhp.schema.solr.Journal;
import eu.dnetlib.dhp.schema.solr.Measure;
import eu.dnetlib.dhp.schema.solr.Pid;
import eu.dnetlib.dhp.schema.solr.SolrRecord;
import eu.dnetlib.dhp.schema.solr.Subject;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
@ -54,23 +59,26 @@ public interface DatasourceMapper {
DatasourcePid mapPid(Pid pid);
@Named("mapPids")
default List<DatasourcePid> mapPids(List<Pid> pids ){
if(pids == null)
default List<DatasourcePid> mapPids(List<Pid> pids ) {
if (pids == null) {
return null;
}
return pids.stream().map(this::mapPid).collect(Collectors.toList());
}
@Named("mapSubjects")
default List<String> mapSubjects(List<Subject> sbjs ){
if(sbjs == null)
default List<String> mapSubjects(List<Subject> sbjs ) {
if (sbjs == null) {
return null;
}
return sbjs.stream().map(Subject::getValue).collect(Collectors.toList());
}
@Named("mapPolicies")
default List<String> mapPolicies(List<CodeLabel> policies ){
if(policies == null)
default List<String> mapPolicies(List<CodeLabel> policies ) {
if (policies == null) {
return null;
}
return policies.stream().map(CodeLabel::getLabel).collect(Collectors.toList());
}
@ -82,7 +90,7 @@ public interface DatasourceMapper {
@Named("mapIndicators")
default Indicator mapIndicators(List<Measure> measureList){
default Indicator mapIndicators(List<Measure> measureList) {
return Utils.mapIndicators(measureList);
}

View File

@ -35,14 +35,15 @@ public interface OrganizationMapper {
OrganizationPid mapPid(Pid pid);
@Named("mapPids")
default List<OrganizationPid> mapPids(List<Pid> pids ){
if(pids == null)
default List<OrganizationPid> mapPids(List<Pid> pids ) {
if (pids == null) {
return null;
}
return pids.stream().map(this::mapPid).collect(Collectors.toList());
}
@Named("mapIndicators")
default Indicator mapIndicators(List<Measure> measureList){
default Indicator mapIndicators(List<Measure> measureList) {
return Utils.mapIndicators(measureList);
}

View File

@ -5,7 +5,11 @@ import eu.dnetlib.dhp.oa.model.graph.Funder;
import eu.dnetlib.dhp.oa.model.graph.Fundings;
import eu.dnetlib.dhp.oa.model.graph.Granted;
import eu.dnetlib.dhp.oa.model.graph.Project;
import eu.dnetlib.dhp.schema.solr.*;
import eu.dnetlib.dhp.schema.solr.Funding;
import eu.dnetlib.dhp.schema.solr.FundingLevel;
import eu.dnetlib.dhp.schema.solr.Measure;
import eu.dnetlib.dhp.schema.solr.SolrRecord;
import eu.dnetlib.dhp.schema.solr.Subject;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
@ -39,24 +43,27 @@ public interface ProjectMapper {
Granted mapFundedAmount(eu.dnetlib.dhp.schema.solr.Project project);
@Named("mapSubjects")
default List<String> mapSubjects(List<Subject>subjectList){
if(subjectList == null)
default List<String> mapSubjects(List<Subject>subjectList) {
if (subjectList == null) {
return null;
}
return subjectList.stream().map(Subject::getValue).collect(Collectors.toList());
}
@Named("mapOpenAccessMandate")
default Boolean mapOpenAccessMandate(String mandate){
if(mandate == null)
default Boolean mapOpenAccessMandate(String mandate) {
if (mandate == null) {
return Boolean.FALSE;
}
return Boolean.parseBoolean(mandate);
}
@Named("mapFunding")
default List<Funder> mapFundings(Funding funding){
if(funding == null)
default List<Funder> mapFundings(Funding funding) {
if (funding == null) {
return null;
}
return Collections.singletonList(mapFunding(funding));
}
@ -68,19 +75,19 @@ public interface ProjectMapper {
Funder mapFunding(Funding funding);
@Named("mapFundingStream")
default Fundings mapFundingStream(Funding funding){
default Fundings mapFundingStream(Funding funding) {
Fundings fundings = new Fundings();
StringBuffer description = new StringBuffer();
FundingLevel fl = funding.getLevel0();
String id ;
description.append(fl.getDescription());
id = fl.getId();
if(Optional.ofNullable(funding.getLevel1()).isPresent()) {
if (Optional.ofNullable(funding.getLevel1()).isPresent()) {
fl = funding.getLevel1();
id = fl.getId();
description.append(" - ").append(fl.getDescription());
}
if(Optional.ofNullable(funding.getLevel2()).isPresent()) {
if (Optional.ofNullable(funding.getLevel2()).isPresent()) {
fl = funding.getLevel2();
id = fl.getId();
description.append(" - ").append(fl.getDescription());
@ -91,7 +98,7 @@ public interface ProjectMapper {
}
@Named("mapIndicators")
default Indicator mapIndicators(List<Measure> measureList){
default Indicator mapIndicators(List<Measure> measureList) {
return Utils.mapIndicators(measureList);
}

View File

@ -2,19 +2,29 @@ package eu.openaire.api.mappers.response.entities;
import eu.dnetlib.dhp.oa.model.APC;
import eu.dnetlib.dhp.oa.model.AccessRight;
import eu.dnetlib.dhp.oa.model.AlternateIdentifier;
import eu.dnetlib.dhp.oa.model.AuthorPid;
import eu.dnetlib.dhp.oa.model.AuthorPidSchemeValue;
import eu.dnetlib.dhp.oa.model.Container;
import eu.dnetlib.dhp.oa.model.OpenAccessRoute;
import eu.dnetlib.dhp.oa.model.*;
import eu.dnetlib.dhp.oa.model.Indicator;
import eu.dnetlib.dhp.oa.model.ResultCountry;
import eu.dnetlib.dhp.oa.model.ResultPid;
import eu.dnetlib.dhp.oa.model.SubjectSchemeValue;
import eu.dnetlib.dhp.oa.model.graph.GraphResult;
import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.solr.Author;
import eu.dnetlib.dhp.schema.solr.BestAccessRight;
import eu.dnetlib.dhp.schema.solr.Country;
import eu.dnetlib.dhp.schema.solr.Instance;
import eu.dnetlib.dhp.schema.solr.Journal;
import eu.dnetlib.dhp.schema.solr.Language;
import eu.dnetlib.dhp.schema.solr.Measure;
import eu.dnetlib.dhp.schema.solr.OpenAccessColor;
import eu.dnetlib.dhp.schema.solr.Pid;
import eu.dnetlib.dhp.schema.solr.SolrRecord;
import eu.dnetlib.dhp.schema.solr.Subject;
import eu.dnetlib.dhp.schema.solr.*;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
@ -67,21 +77,23 @@ public interface ResearchProductMapper {
ResultPid mapPid(Pid pid);
@Named("mapIndicators")
default Indicator mapIndicators(List<Measure> measureList){
default Indicator mapIndicators(List<Measure> measureList) {
return Utils.mapIndicators(measureList);
}
@Named("mapPids")
default List<ResultPid> mapPids(List<Pid> pids ){
if(pids == null)
default List<ResultPid> mapPids(List<Pid> pids ) {
if (pids == null) {
return null;
}
return pids.stream().map(this::mapPid).collect(Collectors.toList());
}
@Named("mapAltIds")
default List<AlternateIdentifier> mapAltIds(List<Pid> altIdentifiers){
if(altIdentifiers == null)
default List<AlternateIdentifier> mapAltIds(List<Pid> altIdentifiers) {
if (altIdentifiers == null) {
return null;
}
return altIdentifiers.stream().map(this::mapAltId).collect(Collectors.toList());
}
@ -94,9 +106,10 @@ public interface ResearchProductMapper {
Container mapJournal(Journal journal );
@Named("mapSubjects")
default List<eu.dnetlib.dhp.oa.model.Subject> mapSubjects(List<Subject> sbjs ){
if(sbjs == null)
default List<eu.dnetlib.dhp.oa.model.Subject> mapSubjects(List<Subject> sbjs ) {
if (sbjs == null) {
return null;
}
return sbjs.stream().map(this::mapSubject).collect(Collectors.toList());
}
@ -108,9 +121,10 @@ public interface ResearchProductMapper {
SubjectSchemeValue mapSubjectSchemeValue(Subject subject);
@Named("mapCountries")
default List<ResultCountry> mapCountries(List<Country> countryList){
if(countryList == null)
default List<ResultCountry> mapCountries(List<Country> countryList) {
if (countryList == null) {
return null;
}
return countryList.stream().map(this::mapCountry).collect(Collectors.toList());
}
@ -123,9 +137,10 @@ public interface ResearchProductMapper {
eu.dnetlib.dhp.oa.model.OpenAccessColor mapOpenAccessColor(OpenAccessColor openAccessColor);
@Named("mapAuthor")
default List<eu.dnetlib.dhp.oa.model.Author> mapAuthors(List<Author> authorsList){
if(authorsList == null)
default List<eu.dnetlib.dhp.oa.model.Author> mapAuthors(List<Author> authorsList) {
if (authorsList == null) {
return null;
}
return authorsList.stream().map(this::mapAuthor).collect(Collectors.toList());
}
@ -134,9 +149,10 @@ public interface ResearchProductMapper {
eu.dnetlib.dhp.oa.model.Author mapAuthor(Author author);
@Named("mapAuthorPid")
default AuthorPid mapAuthorPid(List<Pid> authorPidList){
if(authorPidList == null)
default AuthorPid mapAuthorPid(List<Pid> authorPidList) {
if (authorPidList == null) {
return null;
}
List<Pid> orcid = authorPidList
.stream()
.filter(ap -> ModelConstants.ORCID.equals(ap.getTypeCode()))
@ -144,8 +160,9 @@ public interface ResearchProductMapper {
if (orcid.size() == 1) {
return getAuthorPid(orcid.get(0));
}
if (orcid.size() > 1 )
if (orcid.size() > 1 ) {
return null;
}
orcid = authorPidList
.stream()
.filter(ap -> ModelConstants.ORCID_PENDING.equals(ap.getTypeCode()))
@ -165,9 +182,10 @@ public interface ResearchProductMapper {
AuthorPidSchemeValue mapAuthorPidSchemeValue (Pid pid);
@Named("mapBestAccessRight")
default eu.dnetlib.dhp.oa.model.BestAccessRight mapBestAccessRight(BestAccessRight bestAccessRight){
if(bestAccessRight == null)
default eu.dnetlib.dhp.oa.model.BestAccessRight mapBestAccessRight(BestAccessRight bestAccessRight) {
if (bestAccessRight == null) {
return null;
}
if (Constants.ACCESS_RIGHTS_COAR_MAP.containsKey(bestAccessRight.getCode())) {
String code = Constants.ACCESS_RIGHTS_COAR_MAP.get(bestAccessRight.getCode());
return
@ -181,9 +199,10 @@ public interface ResearchProductMapper {
}
@Named("mapInstances")
default List<eu.dnetlib.dhp.oa.model.Instance> mapInstances(List<Instance> instanceList){
if(instanceList == null)
default List<eu.dnetlib.dhp.oa.model.Instance> mapInstances(List<Instance> instanceList) {
if (instanceList == null) {
return null;
}
return instanceList.stream().map(this::mapInstance).collect(Collectors.toList());
}
@ -197,9 +216,10 @@ public interface ResearchProductMapper {
eu.dnetlib.dhp.oa.model.Instance mapInstance(Instance instance);
@Named("mapAccessRight")
default AccessRight mapAccessRight(eu.dnetlib.dhp.schema.solr.AccessRight accessright){
if(accessright==null)
return null;
default AccessRight mapAccessRight(eu.dnetlib.dhp.schema.solr.AccessRight accessright) {
if (accessright == null) {
return null;
}
AccessRight ar = new AccessRight();
if (Constants.ACCESS_RIGHTS_COAR_MAP.containsKey(accessright.getLabel())) {
String code = Constants.ACCESS_RIGHTS_COAR_MAP.get(accessright.getLabel());

View File

@ -1,22 +1,19 @@
package eu.openaire.api.mappers.response.entities;
import eu.dnetlib.dhp.oa.model.AuthorPid;
import eu.dnetlib.dhp.oa.model.BipIndicators;
import eu.dnetlib.dhp.oa.model.Indicator;
import eu.dnetlib.dhp.oa.model.UsageCounts;
import eu.dnetlib.dhp.oa.model.graph.DatasourcePid;
import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.solr.Measure;
import eu.dnetlib.dhp.schema.solr.Pid;
import java.util.List;
import java.util.stream.Collectors;
public class Utils {
public static Indicator mapIndicators(List<Measure> measureList){
if(measureList == null)
public static Indicator mapIndicators(List<Measure> measureList) {
if (measureList == null) {
return null;
}
Indicator i = new Indicator();
for (Measure m : measureList) {
switch (m.getId()) {
@ -28,36 +25,44 @@ public class Utils {
break;
case Constants.BIP_INFLUENCE:
m.getUnit().forEach(u -> {
if (u.getCode().equals("class"))
if (u.getCode().equals("class")) {
getImpactMeasure(i).setInfluenceClass(u.getLabel());
if (u.getCode().equals("score"))
}
if (u.getCode().equals("score")) {
getImpactMeasure(i).setInfluence(Double.parseDouble(u.getLabel()));
}
});
break;
case Constants.BIP_POPULARITY:
m.getUnit().forEach(u -> {
if (u.getCode().equals("class"))
if (u.getCode().equals("class")) {
getImpactMeasure(i).setPopularityClass(u.getLabel());
if (u.getCode().equals("score"))
}
if (u.getCode().equals("score")) {
getImpactMeasure(i).setPopularity(Double.parseDouble(u.getLabel()));
}
});
break;
case Constants.BIP_INFLUENCE_ALT:
m.getUnit().forEach(u -> {
if (u.getCode().equals("class"))
if (u.getCode().equals("class")) {
getImpactMeasure(i).setCitationClass(u.getLabel());
if (u.getCode().equals("score"))
}
if (u.getCode().equals("score")) {
getImpactMeasure(i).setCitationCount(Double.parseDouble(u.getLabel()));
}
});
break;
case Constants.BIP_POPULARITY_ALT:
break;
case Constants.BIP_IMPULSE:
m.getUnit().forEach(u -> {
if (u.getCode().equals("class"))
if (u.getCode().equals("class")) {
getImpactMeasure(i).setImpulseClass(u.getLabel());
if (u.getCode().equals("score"))
}
if (u.getCode().equals("score")) {
getImpactMeasure(i).setImpulse(Double.parseDouble(u.getLabel()));
}
});
break;
default:

View File

@ -0,0 +1,42 @@
package eu.openaire.api.services;
import eu.dnetlib.dhp.schema.sx.api.model.v2.PageResultType;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;
@Service
@RequiredArgsConstructor
public class ScholixService {
private final RestClient restClient;
private final Logger log = LogManager.getLogger(this.getClass());
private static final String OPENAIRE_ID_PREFIX = "50|";
@Timed
public PageResultType getLinks(String sourcePid, String sourceType, int page) {
try {
if (!sourcePid.startsWith(OPENAIRE_ID_PREFIX)) {
sourcePid = OPENAIRE_ID_PREFIX + sourcePid;
}
String finalSourcePid = sourcePid;
return restClient.get()
.uri(uriBuilder -> uriBuilder
.path("/v2/Links")
.queryParam("sourcePid", finalSourcePid)
.queryParam("sourceType", sourceType)
.queryParam("page", page)
.build())
.retrieve()
.body(PageResultType.class);
} catch (Exception e) {
log.error(e.getMessage());
throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
}
}
}

View File

@ -7,6 +7,8 @@ openapi.description=The Graph API allows developers to access metadata records o
solr.collection=${SOLR_COLLECTION}
solr.zkHosts=${ZK_HOSTS}
scholix.server-base-url=${SCHOLIX_SERVER_BASE_URL}
logging.level.org.springframework.web=DEBUG
#removes 'trace' field from error responses; alternatively remove 'spring-boot-devtools' dependency

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Checks to make sure the code meets the ActiveMQ coding guidelines which
It also enforces a bunch of other "BestPractices like method
lengths, if/try depths, etc...
-->
<module name="Checker">
<module name="TreeWalker">
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="MethodLength">
<property name="max" value="200"/>
<property name="countEmpty" value="false"/>
</module>
<module name="ParameterNumber">
<property name="max" value="7"/>
</module>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="WhitespaceAfter">
<property name="tokens" value="COMMA, SEMI"/>
</module>
<module name="WhitespaceAround">
<property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN,TYPE_EXTENSION_AND"/>
</module>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="LeftCurly"/>
<module name="RightCurly"/>
<module name="NeedBraces">
<property name="tokens"
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
</module>
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<!--<module name="ArrayTrailingComma"/>-->
<!--<module name="AvoidInlineConditionals"/>-->
<module name="CovariantEquals"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="IllegalInstantiation"/>
<module name="MissingSwitchDefault"/>
<module name="NestedIfDepth">
<property name="max" value="8"/>
</module>
<module name="NestedTryDepth">
<property name="max" value="8"/>
</module>
<module name="EmptyCatchBlock"/>
<module name="OneTopLevelClass"/>
</module>
</module>