From 79754cb7d3069844036fbc84653153b5c7e1b58d Mon Sep 17 00:00:00 2001 From: Alexios Symeonidis Date: Thu, 19 Dec 2024 17:36:07 +0200 Subject: [PATCH] implement checkstyle --- pom.xml | 17 ++++ .../api/controllers/DataSourceController.java | 9 +- .../controllers/OrganizationController.java | 9 +- .../api/controllers/ProjectController.java | 9 +- .../ResearchProductsController.java | 9 +- .../validators/PaginationValidator.java | 6 +- .../java/eu/openaire/api/mappers/Utils.java | 8 +- .../query/DataSourceRequestMapper.java | 10 +- .../query/OrganizationRequestMapper.java | 12 ++- .../mappers/query/ProjectRequestMapper.java | 10 +- .../query/ResearchProductsRequestMapper.java | 10 +- .../api/mappers/query/SolrFieldsMapper.java | 16 ++-- .../response/entities/DatasourceMapper.java | 24 +++-- .../response/entities/OrganizationMapper.java | 7 +- .../response/entities/ProjectMapper.java | 29 +++--- .../entities/ResearchProductMapper.java | 66 ++++++++----- .../api/mappers/response/entities/Utils.java | 35 ++++--- src/main/resources/checkstyle.xml | 95 +++++++++++++++++++ 18 files changed, 284 insertions(+), 97 deletions(-) create mode 100644 src/main/resources/checkstyle.xml diff --git a/pom.xml b/pom.xml index 50acf19..cd856f5 100644 --- a/pom.xml +++ b/pom.xml @@ -239,6 +239,23 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + ${project.basedir}/src/main/resources/checkstyle.xml + true + true + + + + validate + + check + + + + diff --git a/src/main/java/eu/openaire/api/controllers/DataSourceController.java b/src/main/java/eu/openaire/api/controllers/DataSourceController.java index 3b44394..90761e3 100644 --- a/src/main/java/eu/openaire/api/controllers/DataSourceController.java +++ b/src/main/java/eu/openaire/api/controllers/DataSourceController.java @@ -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; diff --git a/src/main/java/eu/openaire/api/controllers/OrganizationController.java b/src/main/java/eu/openaire/api/controllers/OrganizationController.java index d83ddb0..668b051 100644 --- a/src/main/java/eu/openaire/api/controllers/OrganizationController.java +++ b/src/main/java/eu/openaire/api/controllers/OrganizationController.java @@ -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; diff --git a/src/main/java/eu/openaire/api/controllers/ProjectController.java b/src/main/java/eu/openaire/api/controllers/ProjectController.java index d5b4013..546b3d7 100644 --- a/src/main/java/eu/openaire/api/controllers/ProjectController.java +++ b/src/main/java/eu/openaire/api/controllers/ProjectController.java @@ -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; diff --git a/src/main/java/eu/openaire/api/controllers/ResearchProductsController.java b/src/main/java/eu/openaire/api/controllers/ResearchProductsController.java index ec39255..c09493b 100644 --- a/src/main/java/eu/openaire/api/controllers/ResearchProductsController.java +++ b/src/main/java/eu/openaire/api/controllers/ResearchProductsController.java @@ -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; diff --git a/src/main/java/eu/openaire/api/dto/request/validators/PaginationValidator.java b/src/main/java/eu/openaire/api/dto/request/validators/PaginationValidator.java index 4342039..2722f45 100644 --- a/src/main/java/eu/openaire/api/dto/request/validators/PaginationValidator.java +++ b/src/main/java/eu/openaire/api/dto/request/validators/PaginationValidator.java @@ -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; diff --git a/src/main/java/eu/openaire/api/mappers/Utils.java b/src/main/java/eu/openaire/api/mappers/Utils.java index 3041725..82fe808 100644 --- a/src/main/java/eu/openaire/api/mappers/Utils.java +++ b/src/main/java/eu/openaire/api/mappers/Utils.java @@ -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 diff --git a/src/main/java/eu/openaire/api/mappers/query/DataSourceRequestMapper.java b/src/main/java/eu/openaire/api/mappers/query/DataSourceRequestMapper.java index c3a353d..af260be 100644 --- a/src/main/java/eu/openaire/api/mappers/query/DataSourceRequestMapper.java +++ b/src/main/java/eu/openaire/api/mappers/query/DataSourceRequestMapper.java @@ -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 solrFieldMapping = SolrFieldsMapper.dataSourceFieldMapping; + final Map solrFieldMapping = SolrFieldsMapper.DATASOURCE_FIELD_MAPPING; var qList = new ArrayList(); diff --git a/src/main/java/eu/openaire/api/mappers/query/OrganizationRequestMapper.java b/src/main/java/eu/openaire/api/mappers/query/OrganizationRequestMapper.java index 80b6fa3..8a08cf6 100644 --- a/src/main/java/eu/openaire/api/mappers/query/OrganizationRequestMapper.java +++ b/src/main/java/eu/openaire/api/mappers/query/OrganizationRequestMapper.java @@ -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 solrFieldMapping = SolrFieldsMapper.organizationFieldsMapping; + final Map solrFieldMapping = SolrFieldsMapper.ORGANIZATION_FIELDS_MAPPING; var qList = new ArrayList(); diff --git a/src/main/java/eu/openaire/api/mappers/query/ProjectRequestMapper.java b/src/main/java/eu/openaire/api/mappers/query/ProjectRequestMapper.java index de8bebe..2c4534b 100644 --- a/src/main/java/eu/openaire/api/mappers/query/ProjectRequestMapper.java +++ b/src/main/java/eu/openaire/api/mappers/query/ProjectRequestMapper.java @@ -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 solrFieldMapping = SolrFieldsMapper.projectFieldMapping; + final Map solrFieldMapping = SolrFieldsMapper.PROJECT_FIELD_MAPPING; var qList = new ArrayList(); diff --git a/src/main/java/eu/openaire/api/mappers/query/ResearchProductsRequestMapper.java b/src/main/java/eu/openaire/api/mappers/query/ResearchProductsRequestMapper.java index 33cb413..d031090 100644 --- a/src/main/java/eu/openaire/api/mappers/query/ResearchProductsRequestMapper.java +++ b/src/main/java/eu/openaire/api/mappers/query/ResearchProductsRequestMapper.java @@ -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 solrFieldMapping = SolrFieldsMapper.researchProductFieldMapping; + final Map solrFieldMapping = SolrFieldsMapper.RESEARCH_PRODUCT_FIELD_MAPPING; var qList = new ArrayList(); diff --git a/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java b/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java index 748b821..d14c849 100644 --- a/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java +++ b/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java @@ -5,7 +5,7 @@ import java.util.Map; public class SolrFieldsMapper { // mappings for the organization entity - public static final Map organizationFieldsMapping = java.util.Map.ofEntries( + public static final Map 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 organizationSortMapping = Map.ofEntries( + public static final Map ORGANIZATION_SORT_MAPPING = Map.ofEntries( Map.entry("relevance", "score") ); // mappings for the datasource entity - public static final Map dataSourceFieldMapping = Map.ofEntries( + public static final Map 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 dataSourceSortMapping = Map.ofEntries( + public static final Map DATASOURCE_SORT_MAPPING = Map.ofEntries( Map.entry("relevance", "score") ); // mappings for the project entity - public static final Map projectFieldMapping = Map.ofEntries( + public static final Map PROJECT_FIELD_MAPPING = Map.ofEntries( // search field mapping Map.entry("search", "__all:(%s)"), @@ -81,13 +81,13 @@ public class SolrFieldsMapper { ); - public static final Map projectSortMapping = Map.ofEntries( + public static final Map PROJECT_SORT_MAPPING = Map.ofEntries( Map.entry("relevance", "score"), Map.entry("startDate", "projectstartyear"), Map.entry("endDate", "projectendyear") ); - public static final Map researchProductFieldMapping = Map.ofEntries( + public static final Map 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 researchProductSortMapping = Map.ofEntries( + public static final Map RESEARCH_PRODUCT_SORT_MAPPING = Map.ofEntries( Map.entry("relevance", "score"), Map.entry("publicationDate", "resultdateofacceptance"), diff --git a/src/main/java/eu/openaire/api/mappers/response/entities/DatasourceMapper.java b/src/main/java/eu/openaire/api/mappers/response/entities/DatasourceMapper.java index 64a7c06..72bb798 100644 --- a/src/main/java/eu/openaire/api/mappers/response/entities/DatasourceMapper.java +++ b/src/main/java/eu/openaire/api/mappers/response/entities/DatasourceMapper.java @@ -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 mapPids(List pids ){ - if(pids == null) + default List mapPids(List pids ) { + if (pids == null) { return null; + } return pids.stream().map(this::mapPid).collect(Collectors.toList()); } @Named("mapSubjects") - default List mapSubjects(List sbjs ){ - if(sbjs == null) + default List mapSubjects(List sbjs ) { + if (sbjs == null) { return null; + } return sbjs.stream().map(Subject::getValue).collect(Collectors.toList()); } @Named("mapPolicies") - default List mapPolicies(List policies ){ - if(policies == null) + default List mapPolicies(List 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 measureList){ + default Indicator mapIndicators(List measureList) { return Utils.mapIndicators(measureList); } diff --git a/src/main/java/eu/openaire/api/mappers/response/entities/OrganizationMapper.java b/src/main/java/eu/openaire/api/mappers/response/entities/OrganizationMapper.java index f77e4fc..014489d 100644 --- a/src/main/java/eu/openaire/api/mappers/response/entities/OrganizationMapper.java +++ b/src/main/java/eu/openaire/api/mappers/response/entities/OrganizationMapper.java @@ -35,14 +35,15 @@ public interface OrganizationMapper { OrganizationPid mapPid(Pid pid); @Named("mapPids") - default List mapPids(List pids ){ - if(pids == null) + default List mapPids(List pids ) { + if (pids == null) { return null; + } return pids.stream().map(this::mapPid).collect(Collectors.toList()); } @Named("mapIndicators") - default Indicator mapIndicators(List measureList){ + default Indicator mapIndicators(List measureList) { return Utils.mapIndicators(measureList); } diff --git a/src/main/java/eu/openaire/api/mappers/response/entities/ProjectMapper.java b/src/main/java/eu/openaire/api/mappers/response/entities/ProjectMapper.java index 97e7ff2..a5890c1 100644 --- a/src/main/java/eu/openaire/api/mappers/response/entities/ProjectMapper.java +++ b/src/main/java/eu/openaire/api/mappers/response/entities/ProjectMapper.java @@ -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 mapSubjects(ListsubjectList){ - if(subjectList == null) + default List mapSubjects(ListsubjectList) { + 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 mapFundings(Funding funding){ - if(funding == null) + default List 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 measureList){ + default Indicator mapIndicators(List measureList) { return Utils.mapIndicators(measureList); } diff --git a/src/main/java/eu/openaire/api/mappers/response/entities/ResearchProductMapper.java b/src/main/java/eu/openaire/api/mappers/response/entities/ResearchProductMapper.java index df42f3e..27f884d 100644 --- a/src/main/java/eu/openaire/api/mappers/response/entities/ResearchProductMapper.java +++ b/src/main/java/eu/openaire/api/mappers/response/entities/ResearchProductMapper.java @@ -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 measureList){ + default Indicator mapIndicators(List measureList) { return Utils.mapIndicators(measureList); } @Named("mapPids") - default List mapPids(List pids ){ - if(pids == null) + default List mapPids(List pids ) { + if (pids == null) { return null; + } return pids.stream().map(this::mapPid).collect(Collectors.toList()); } @Named("mapAltIds") - default List mapAltIds(List altIdentifiers){ - if(altIdentifiers == null) + default List mapAltIds(List 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 mapSubjects(List sbjs ){ - if(sbjs == null) + default List mapSubjects(List 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 mapCountries(List countryList){ - if(countryList == null) + default List mapCountries(List 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 mapAuthors(List authorsList){ - if(authorsList == null) + default List mapAuthors(List 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 authorPidList){ - if(authorPidList == null) + default AuthorPid mapAuthorPid(List authorPidList) { + if (authorPidList == null) { return null; + } List 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 mapInstances(List instanceList){ - if(instanceList == null) + default List mapInstances(List 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()); diff --git a/src/main/java/eu/openaire/api/mappers/response/entities/Utils.java b/src/main/java/eu/openaire/api/mappers/response/entities/Utils.java index d932229..896e1db 100644 --- a/src/main/java/eu/openaire/api/mappers/response/entities/Utils.java +++ b/src/main/java/eu/openaire/api/mappers/response/entities/Utils.java @@ -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 measureList){ - if(measureList == null) + public static Indicator mapIndicators(List 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: diff --git a/src/main/resources/checkstyle.xml b/src/main/resources/checkstyle.xml new file mode 100644 index 0000000..4cfe02d --- /dev/null +++ b/src/main/resources/checkstyle.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file