implement checkstyle

This commit is contained in:
Alexios Symeonidis 2024-12-19 17:36:07 +02:00
parent b37437bce5
commit 79754cb7d3
18 changed files with 284 additions and 97 deletions

17
pom.xml
View File

@ -239,6 +239,23 @@
</annotationProcessorPaths> </annotationProcessorPaths>
</configuration> </configuration>
</plugin> </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> </plugins>
</build> </build>

View File

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

View File

@ -22,14 +22,17 @@ import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject; import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder; 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 @RestController
@RequestMapping("/organizations") @RequestMapping("/organizations")
@RequiredArgsConstructor @RequiredArgsConstructor
@Tag(name = "Organizations", description = "API endpoints to explore organizations") @Tag(name = "Organizations", description = "API endpoints to explore organizations")
public class OrganizationController public class OrganizationController {
{
private final OrganizationService organizationService; private final OrganizationService organizationService;

View File

@ -22,14 +22,17 @@ import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject; import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder; 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 @RestController
@RequestMapping("/projects") @RequestMapping("/projects")
@RequiredArgsConstructor @RequiredArgsConstructor
@Tag(name = "Projects", description = "API endpoints to explore projects") @Tag(name = "Projects", description = "API endpoints to explore projects")
public class ProjectController public class ProjectController {
{
private final ProjectService projectService; private final ProjectService projectService;

View File

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

View File

@ -1,6 +1,10 @@
package eu.openaire.api.dto.request.validators; 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 jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.validation.Errors; import org.springframework.validation.Errors;

View File

@ -10,11 +10,15 @@ import java.time.ZoneOffset;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException; 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 { public class Utils {
private Utils() {} private Utils() { }
public static final String API_PAGE_DESC = """ public static final String API_PAGE_DESC = """
Page number of the results,\s 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.dto.request.DataSourceRequest;
import eu.openaire.api.mappers.Utils; import eu.openaire.api.mappers.Utils;
import eu.openaire.api.solr.SolrQueryParams; 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.ArrayList;
import java.util.Map; import java.util.Map;
@ -15,7 +19,7 @@ public interface DataSourceRequestMapper {
@Mapping(target = "rows", source = "pageSize") @Mapping(target = "rows", source = "pageSize")
@Mapping(target = "debugQuery", source = "debugQuery") @Mapping(target = "debugQuery", source = "debugQuery")
@Mapping(target = "cursor", source = "cursor") @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); SolrQueryParams toSolrQuery(DataSourceRequest src);
@Named("calculateStart") @Named("calculateStart")
@ -26,7 +30,7 @@ public interface DataSourceRequestMapper {
@AfterMapping @AfterMapping
default void paramsCustomMapping(DataSourceRequest src, @MappingTarget SolrQueryParams solrQueryParams) { 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>(); 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.dto.request.OrganizationRequest;
import eu.openaire.api.mappers.Utils; import eu.openaire.api.mappers.Utils;
import eu.openaire.api.solr.SolrQueryParams; 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.ArrayList;
import java.util.Map; import java.util.Map;
@ -11,12 +15,10 @@ import java.util.Map;
@Mapper(componentModel = "spring") @Mapper(componentModel = "spring")
public interface OrganizationRequestMapper { public interface OrganizationRequestMapper {
@Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )") @Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )")
@Mapping(target = "rows", source = "pageSize") @Mapping(target = "rows", source = "pageSize")
@Mapping(target = "debugQuery", source = "debugQuery") @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); SolrQueryParams toSolrQuery(OrganizationRequest src);
@Named("calculateStart") @Named("calculateStart")
@ -27,7 +29,7 @@ public interface OrganizationRequestMapper {
@AfterMapping @AfterMapping
default void paramsCustomMapping(OrganizationRequest src, @MappingTarget SolrQueryParams solrQueryParams) { 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>(); 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.dto.request.ProjectRequest;
import eu.openaire.api.mappers.Utils; import eu.openaire.api.mappers.Utils;
import eu.openaire.api.solr.SolrQueryParams; 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.ArrayList;
import java.util.Map; import java.util.Map;
@ -15,7 +19,7 @@ public interface ProjectRequestMapper {
@Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )") @Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )")
@Mapping(target = "rows", source = "pageSize") @Mapping(target = "rows", source = "pageSize")
@Mapping(target = "debugQuery", source = "debugQuery") @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); SolrQueryParams toSolrQuery(ProjectRequest src);
@Named("calculateStart") @Named("calculateStart")
@ -26,7 +30,7 @@ public interface ProjectRequestMapper {
@AfterMapping @AfterMapping
default void paramsCustomMapping(ProjectRequest src, @MappingTarget SolrQueryParams solrQueryParams) { 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>(); 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.dto.request.ResearchProductsRequest;
import eu.openaire.api.mappers.Utils; import eu.openaire.api.mappers.Utils;
import eu.openaire.api.solr.SolrQueryParams; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -16,7 +20,7 @@ public interface ResearchProductsRequestMapper {
@Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )") @Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )")
@Mapping(target = "rows", source = "pageSize") @Mapping(target = "rows", source = "pageSize")
@Mapping(target = "debugQuery", source = "debugQuery") @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); SolrQueryParams toSolrQuery(ResearchProductsRequest src);
@Named("calculateStart") @Named("calculateStart")
@ -27,7 +31,7 @@ public interface ResearchProductsRequestMapper {
@AfterMapping @AfterMapping
default void paramsCustomMapping(ResearchProductsRequest src, @MappingTarget SolrQueryParams solrQueryParams) { 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>(); var qList = new ArrayList<String>();

View File

@ -5,7 +5,7 @@ import java.util.Map;
public class SolrFieldsMapper { public class SolrFieldsMapper {
// mappings for the organization entity // 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 // search field mapping
Map.entry("search", "__all:(%s)"), 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") Map.entry("relevance", "score")
); );
// mappings for the datasource entity // 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 // search field mapping
Map.entry("search", "__all:(%s)"), Map.entry("search", "__all:(%s)"),
@ -48,13 +48,13 @@ public class SolrFieldsMapper {
Map.entry("relCollectedFromDatasourceId", "collectedfromdatasourceid:(%s)") 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") Map.entry("relevance", "score")
); );
// mappings for the project entity // 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 // search field mapping
Map.entry("search", "__all:(%s)"), 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("relevance", "score"),
Map.entry("startDate", "projectstartyear"), Map.entry("startDate", "projectstartyear"),
Map.entry("endDate", "projectendyear") 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 // search field mapping
Map.entry("search", "__all:(%s)"), 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("relevance", "score"),
Map.entry("publicationDate", "resultdateofacceptance"), 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.Datasource;
import eu.dnetlib.dhp.oa.model.graph.DatasourcePid; import eu.dnetlib.dhp.oa.model.graph.DatasourcePid;
import eu.dnetlib.dhp.oa.model.graph.DatasourceSchemeValue; 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.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.Named; import org.mapstruct.Named;
@ -54,23 +59,26 @@ public interface DatasourceMapper {
DatasourcePid mapPid(Pid pid); DatasourcePid mapPid(Pid pid);
@Named("mapPids") @Named("mapPids")
default List<DatasourcePid> mapPids(List<Pid> pids ){ default List<DatasourcePid> mapPids(List<Pid> pids ) {
if(pids == null) if (pids == null) {
return null; return null;
}
return pids.stream().map(this::mapPid).collect(Collectors.toList()); return pids.stream().map(this::mapPid).collect(Collectors.toList());
} }
@Named("mapSubjects") @Named("mapSubjects")
default List<String> mapSubjects(List<Subject> sbjs ){ default List<String> mapSubjects(List<Subject> sbjs ) {
if(sbjs == null) if (sbjs == null) {
return null; return null;
}
return sbjs.stream().map(Subject::getValue).collect(Collectors.toList()); return sbjs.stream().map(Subject::getValue).collect(Collectors.toList());
} }
@Named("mapPolicies") @Named("mapPolicies")
default List<String> mapPolicies(List<CodeLabel> policies ){ default List<String> mapPolicies(List<CodeLabel> policies ) {
if(policies == null) if (policies == null) {
return null; return null;
}
return policies.stream().map(CodeLabel::getLabel).collect(Collectors.toList()); return policies.stream().map(CodeLabel::getLabel).collect(Collectors.toList());
} }
@ -82,7 +90,7 @@ public interface DatasourceMapper {
@Named("mapIndicators") @Named("mapIndicators")
default Indicator mapIndicators(List<Measure> measureList){ default Indicator mapIndicators(List<Measure> measureList) {
return Utils.mapIndicators(measureList); return Utils.mapIndicators(measureList);
} }

View File

@ -35,14 +35,15 @@ public interface OrganizationMapper {
OrganizationPid mapPid(Pid pid); OrganizationPid mapPid(Pid pid);
@Named("mapPids") @Named("mapPids")
default List<OrganizationPid> mapPids(List<Pid> pids ){ default List<OrganizationPid> mapPids(List<Pid> pids ) {
if(pids == null) if (pids == null) {
return null; return null;
}
return pids.stream().map(this::mapPid).collect(Collectors.toList()); return pids.stream().map(this::mapPid).collect(Collectors.toList());
} }
@Named("mapIndicators") @Named("mapIndicators")
default Indicator mapIndicators(List<Measure> measureList){ default Indicator mapIndicators(List<Measure> measureList) {
return Utils.mapIndicators(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.Fundings;
import eu.dnetlib.dhp.oa.model.graph.Granted; import eu.dnetlib.dhp.oa.model.graph.Granted;
import eu.dnetlib.dhp.oa.model.graph.Project; 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.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.Named; import org.mapstruct.Named;
@ -39,24 +43,27 @@ public interface ProjectMapper {
Granted mapFundedAmount(eu.dnetlib.dhp.schema.solr.Project project); Granted mapFundedAmount(eu.dnetlib.dhp.schema.solr.Project project);
@Named("mapSubjects") @Named("mapSubjects")
default List<String> mapSubjects(List<Subject>subjectList){ default List<String> mapSubjects(List<Subject>subjectList) {
if(subjectList == null) if (subjectList == null) {
return null; return null;
}
return subjectList.stream().map(Subject::getValue).collect(Collectors.toList()); return subjectList.stream().map(Subject::getValue).collect(Collectors.toList());
} }
@Named("mapOpenAccessMandate") @Named("mapOpenAccessMandate")
default Boolean mapOpenAccessMandate(String mandate){ default Boolean mapOpenAccessMandate(String mandate) {
if(mandate == null) if (mandate == null) {
return Boolean.FALSE; return Boolean.FALSE;
}
return Boolean.parseBoolean(mandate); return Boolean.parseBoolean(mandate);
} }
@Named("mapFunding") @Named("mapFunding")
default List<Funder> mapFundings(Funding funding){ default List<Funder> mapFundings(Funding funding) {
if(funding == null) if (funding == null) {
return null; return null;
}
return Collections.singletonList(mapFunding(funding)); return Collections.singletonList(mapFunding(funding));
} }
@ -68,19 +75,19 @@ public interface ProjectMapper {
Funder mapFunding(Funding funding); Funder mapFunding(Funding funding);
@Named("mapFundingStream") @Named("mapFundingStream")
default Fundings mapFundingStream(Funding funding){ default Fundings mapFundingStream(Funding funding) {
Fundings fundings = new Fundings(); Fundings fundings = new Fundings();
StringBuffer description = new StringBuffer(); StringBuffer description = new StringBuffer();
FundingLevel fl = funding.getLevel0(); FundingLevel fl = funding.getLevel0();
String id ; String id ;
description.append(fl.getDescription()); description.append(fl.getDescription());
id = fl.getId(); id = fl.getId();
if(Optional.ofNullable(funding.getLevel1()).isPresent()) { if (Optional.ofNullable(funding.getLevel1()).isPresent()) {
fl = funding.getLevel1(); fl = funding.getLevel1();
id = fl.getId(); id = fl.getId();
description.append(" - ").append(fl.getDescription()); description.append(" - ").append(fl.getDescription());
} }
if(Optional.ofNullable(funding.getLevel2()).isPresent()) { if (Optional.ofNullable(funding.getLevel2()).isPresent()) {
fl = funding.getLevel2(); fl = funding.getLevel2();
id = fl.getId(); id = fl.getId();
description.append(" - ").append(fl.getDescription()); description.append(" - ").append(fl.getDescription());
@ -91,7 +98,7 @@ public interface ProjectMapper {
} }
@Named("mapIndicators") @Named("mapIndicators")
default Indicator mapIndicators(List<Measure> measureList){ default Indicator mapIndicators(List<Measure> measureList) {
return Utils.mapIndicators(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.APC;
import eu.dnetlib.dhp.oa.model.AccessRight; 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.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.oa.model.graph.GraphResult;
import eu.dnetlib.dhp.schema.common.ModelConstants; import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.solr.Author; import eu.dnetlib.dhp.schema.solr.Author;
import eu.dnetlib.dhp.schema.solr.BestAccessRight; import eu.dnetlib.dhp.schema.solr.BestAccessRight;
import eu.dnetlib.dhp.schema.solr.Country; import eu.dnetlib.dhp.schema.solr.Country;
import eu.dnetlib.dhp.schema.solr.Instance; 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.Language;
import eu.dnetlib.dhp.schema.solr.Measure; import eu.dnetlib.dhp.schema.solr.Measure;
import eu.dnetlib.dhp.schema.solr.OpenAccessColor; 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.Subject;
import eu.dnetlib.dhp.schema.solr.*;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.Named; import org.mapstruct.Named;
@ -67,21 +77,23 @@ public interface ResearchProductMapper {
ResultPid mapPid(Pid pid); ResultPid mapPid(Pid pid);
@Named("mapIndicators") @Named("mapIndicators")
default Indicator mapIndicators(List<Measure> measureList){ default Indicator mapIndicators(List<Measure> measureList) {
return Utils.mapIndicators(measureList); return Utils.mapIndicators(measureList);
} }
@Named("mapPids") @Named("mapPids")
default List<ResultPid> mapPids(List<Pid> pids ){ default List<ResultPid> mapPids(List<Pid> pids ) {
if(pids == null) if (pids == null) {
return null; return null;
}
return pids.stream().map(this::mapPid).collect(Collectors.toList()); return pids.stream().map(this::mapPid).collect(Collectors.toList());
} }
@Named("mapAltIds") @Named("mapAltIds")
default List<AlternateIdentifier> mapAltIds(List<Pid> altIdentifiers){ default List<AlternateIdentifier> mapAltIds(List<Pid> altIdentifiers) {
if(altIdentifiers == null) if (altIdentifiers == null) {
return null; return null;
}
return altIdentifiers.stream().map(this::mapAltId).collect(Collectors.toList()); return altIdentifiers.stream().map(this::mapAltId).collect(Collectors.toList());
} }
@ -94,9 +106,10 @@ public interface ResearchProductMapper {
Container mapJournal(Journal journal ); Container mapJournal(Journal journal );
@Named("mapSubjects") @Named("mapSubjects")
default List<eu.dnetlib.dhp.oa.model.Subject> mapSubjects(List<Subject> sbjs ){ default List<eu.dnetlib.dhp.oa.model.Subject> mapSubjects(List<Subject> sbjs ) {
if(sbjs == null) if (sbjs == null) {
return null; return null;
}
return sbjs.stream().map(this::mapSubject).collect(Collectors.toList()); return sbjs.stream().map(this::mapSubject).collect(Collectors.toList());
} }
@ -108,9 +121,10 @@ public interface ResearchProductMapper {
SubjectSchemeValue mapSubjectSchemeValue(Subject subject); SubjectSchemeValue mapSubjectSchemeValue(Subject subject);
@Named("mapCountries") @Named("mapCountries")
default List<ResultCountry> mapCountries(List<Country> countryList){ default List<ResultCountry> mapCountries(List<Country> countryList) {
if(countryList == null) if (countryList == null) {
return null; return null;
}
return countryList.stream().map(this::mapCountry).collect(Collectors.toList()); 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); eu.dnetlib.dhp.oa.model.OpenAccessColor mapOpenAccessColor(OpenAccessColor openAccessColor);
@Named("mapAuthor") @Named("mapAuthor")
default List<eu.dnetlib.dhp.oa.model.Author> mapAuthors(List<Author> authorsList){ default List<eu.dnetlib.dhp.oa.model.Author> mapAuthors(List<Author> authorsList) {
if(authorsList == null) if (authorsList == null) {
return null; return null;
}
return authorsList.stream().map(this::mapAuthor).collect(Collectors.toList()); 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); eu.dnetlib.dhp.oa.model.Author mapAuthor(Author author);
@Named("mapAuthorPid") @Named("mapAuthorPid")
default AuthorPid mapAuthorPid(List<Pid> authorPidList){ default AuthorPid mapAuthorPid(List<Pid> authorPidList) {
if(authorPidList == null) if (authorPidList == null) {
return null; return null;
}
List<Pid> orcid = authorPidList List<Pid> orcid = authorPidList
.stream() .stream()
.filter(ap -> ModelConstants.ORCID.equals(ap.getTypeCode())) .filter(ap -> ModelConstants.ORCID.equals(ap.getTypeCode()))
@ -144,8 +160,9 @@ public interface ResearchProductMapper {
if (orcid.size() == 1) { if (orcid.size() == 1) {
return getAuthorPid(orcid.get(0)); return getAuthorPid(orcid.get(0));
} }
if (orcid.size() > 1 ) if (orcid.size() > 1 ) {
return null; return null;
}
orcid = authorPidList orcid = authorPidList
.stream() .stream()
.filter(ap -> ModelConstants.ORCID_PENDING.equals(ap.getTypeCode())) .filter(ap -> ModelConstants.ORCID_PENDING.equals(ap.getTypeCode()))
@ -165,9 +182,10 @@ public interface ResearchProductMapper {
AuthorPidSchemeValue mapAuthorPidSchemeValue (Pid pid); AuthorPidSchemeValue mapAuthorPidSchemeValue (Pid pid);
@Named("mapBestAccessRight") @Named("mapBestAccessRight")
default eu.dnetlib.dhp.oa.model.BestAccessRight mapBestAccessRight(BestAccessRight bestAccessRight){ default eu.dnetlib.dhp.oa.model.BestAccessRight mapBestAccessRight(BestAccessRight bestAccessRight) {
if(bestAccessRight == null) if (bestAccessRight == null) {
return null; return null;
}
if (Constants.ACCESS_RIGHTS_COAR_MAP.containsKey(bestAccessRight.getCode())) { if (Constants.ACCESS_RIGHTS_COAR_MAP.containsKey(bestAccessRight.getCode())) {
String code = Constants.ACCESS_RIGHTS_COAR_MAP.get(bestAccessRight.getCode()); String code = Constants.ACCESS_RIGHTS_COAR_MAP.get(bestAccessRight.getCode());
return return
@ -181,9 +199,10 @@ public interface ResearchProductMapper {
} }
@Named("mapInstances") @Named("mapInstances")
default List<eu.dnetlib.dhp.oa.model.Instance> mapInstances(List<Instance> instanceList){ default List<eu.dnetlib.dhp.oa.model.Instance> mapInstances(List<Instance> instanceList) {
if(instanceList == null) if (instanceList == null) {
return null; return null;
}
return instanceList.stream().map(this::mapInstance).collect(Collectors.toList()); 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); eu.dnetlib.dhp.oa.model.Instance mapInstance(Instance instance);
@Named("mapAccessRight") @Named("mapAccessRight")
default AccessRight mapAccessRight(eu.dnetlib.dhp.schema.solr.AccessRight accessright){ default AccessRight mapAccessRight(eu.dnetlib.dhp.schema.solr.AccessRight accessright) {
if(accessright==null) if (accessright == null) {
return null; return null;
}
AccessRight ar = new AccessRight(); AccessRight ar = new AccessRight();
if (Constants.ACCESS_RIGHTS_COAR_MAP.containsKey(accessright.getLabel())) { if (Constants.ACCESS_RIGHTS_COAR_MAP.containsKey(accessright.getLabel())) {
String code = Constants.ACCESS_RIGHTS_COAR_MAP.get(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; 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.BipIndicators;
import eu.dnetlib.dhp.oa.model.Indicator; import eu.dnetlib.dhp.oa.model.Indicator;
import eu.dnetlib.dhp.oa.model.UsageCounts; 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.Measure;
import eu.dnetlib.dhp.schema.solr.Pid;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class Utils { public class Utils {
public static Indicator mapIndicators(List<Measure> measureList){ public static Indicator mapIndicators(List<Measure> measureList) {
if(measureList == null) if (measureList == null) {
return null; return null;
}
Indicator i = new Indicator(); Indicator i = new Indicator();
for (Measure m : measureList) { for (Measure m : measureList) {
switch (m.getId()) { switch (m.getId()) {
@ -28,36 +25,44 @@ public class Utils {
break; break;
case Constants.BIP_INFLUENCE: case Constants.BIP_INFLUENCE:
m.getUnit().forEach(u -> { m.getUnit().forEach(u -> {
if (u.getCode().equals("class")) if (u.getCode().equals("class")) {
getImpactMeasure(i).setInfluenceClass(u.getLabel()); getImpactMeasure(i).setInfluenceClass(u.getLabel());
if (u.getCode().equals("score")) }
if (u.getCode().equals("score")) {
getImpactMeasure(i).setInfluence(Double.parseDouble(u.getLabel())); getImpactMeasure(i).setInfluence(Double.parseDouble(u.getLabel()));
}
}); });
break; break;
case Constants.BIP_POPULARITY: case Constants.BIP_POPULARITY:
m.getUnit().forEach(u -> { m.getUnit().forEach(u -> {
if (u.getCode().equals("class")) if (u.getCode().equals("class")) {
getImpactMeasure(i).setPopularityClass(u.getLabel()); getImpactMeasure(i).setPopularityClass(u.getLabel());
if (u.getCode().equals("score")) }
if (u.getCode().equals("score")) {
getImpactMeasure(i).setPopularity(Double.parseDouble(u.getLabel())); getImpactMeasure(i).setPopularity(Double.parseDouble(u.getLabel()));
}
}); });
break; break;
case Constants.BIP_INFLUENCE_ALT: case Constants.BIP_INFLUENCE_ALT:
m.getUnit().forEach(u -> { m.getUnit().forEach(u -> {
if (u.getCode().equals("class")) if (u.getCode().equals("class")) {
getImpactMeasure(i).setCitationClass(u.getLabel()); getImpactMeasure(i).setCitationClass(u.getLabel());
if (u.getCode().equals("score")) }
if (u.getCode().equals("score")) {
getImpactMeasure(i).setCitationCount(Double.parseDouble(u.getLabel())); getImpactMeasure(i).setCitationCount(Double.parseDouble(u.getLabel()));
}
}); });
break; break;
case Constants.BIP_POPULARITY_ALT: case Constants.BIP_POPULARITY_ALT:
break; break;
case Constants.BIP_IMPULSE: case Constants.BIP_IMPULSE:
m.getUnit().forEach(u -> { m.getUnit().forEach(u -> {
if (u.getCode().equals("class")) if (u.getCode().equals("class")) {
getImpactMeasure(i).setImpulseClass(u.getLabel()); getImpactMeasure(i).setImpulseClass(u.getLabel());
if (u.getCode().equals("score")) }
if (u.getCode().equals("score")) {
getImpactMeasure(i).setImpulse(Double.parseDouble(u.getLabel())); getImpactMeasure(i).setImpulse(Double.parseDouble(u.getLabel()));
}
}); });
break; break;
default: default:

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>