implemented Scholix V1 APIs

This commit is contained in:
Sandro La Bruzzo 2022-02-14 09:16:37 +01:00
parent fc74c86ba9
commit d5a089869c
15 changed files with 323 additions and 245 deletions

View File

@ -14,12 +14,10 @@
<artifactId>scholexplorer-api</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
@ -29,15 +27,11 @@
<groupId>eu.dnetlib.dhp</groupId>
<artifactId>dhp-schemas</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -1,16 +1,22 @@
package eu.dnetlib.scholix.api.controller;
import eu.dnetlib.common.controller.AbstractDnetController;
import eu.dnetlib.scholix.api.ScholixException;
import eu.dnetlib.scholix.api.index.ScholixIndexManager;
import eu.dnetlib.scholix.api.model.v1.LinkPublisher;
import io.micrometer.core.annotation.Timed;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@ -20,16 +26,24 @@ import java.util.List;
})
public class DatasourceV1 extends AbstractDnetController {
@Autowired
private ScholixIndexManager manager;
@Timed(value = "scholix.v1.datasources", description = "Time taken to return all datasources on Version 1.0 of Scholix")
@Operation(
summary = "Get all Datasources",
description = "returns a list of all datasources")
@GetMapping("/listDatasources")
public List<LinkPublisher> getDatasources() {
return Arrays.asList(
new LinkPublisher().name("pippo").totalRelationships(30),
new LinkPublisher().name("pluto").totalRelationships(30),
new LinkPublisher().name("peppa").totalRelationships(30)
);
public List<LinkPublisher> getDatasources() throws ScholixException {
final List<Pair<String, Long>> result = manager.totalLinksByProvider(null);
if (result == null)
return new ArrayList<>();
return result.stream().map(p -> new LinkPublisher().name(p.getKey()).totalRelationships(p.getValue().intValue())).collect(Collectors.toList());
}
}

View File

@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@ -36,7 +35,7 @@ public class LinkProviderV2 {
@Parameter(in = ParameterIn.QUERY, description = "Filter the link provider name") @RequestParam(required = false) String name
) throws ScholixException {
List<Pair<String, Long>> result = manager.linksByProvider(null);
List<Pair<String, Long>> result = manager.totalLinksByProvider(name);
if (result==null)
return new ArrayList<>();

View File

@ -1,16 +1,21 @@
package eu.dnetlib.scholix.api.controller;
import eu.dnetlib.scholix.api.ScholixException;
import eu.dnetlib.scholix.api.index.ScholixIndexManager;
import eu.dnetlib.scholix.api.model.v2.LinkProviderType;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/v2/LinkPublisher")
@ -19,6 +24,9 @@ import java.util.List;
})
public class LinkPublisherV2 {
@Autowired
ScholixIndexManager manager;
@Operation(
summary = "Get All Publishers that provide source object",
description = "Return a List of all Publishers that provide source objects in Scholix " +
@ -26,12 +34,13 @@ public class LinkPublisherV2 {
@GetMapping("/inSource")
public List<LinkProviderType> getInSource(
@Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name
) {
return Arrays.asList(
new LinkProviderType().name("pippo").totalRelationships(30),
new LinkProviderType().name("pluto").totalRelationships(30),
new LinkProviderType().name("peppa").totalRelationships(30)
);
) throws ScholixException {
List<Pair<String, Long>> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.source,name);
if (result==null)
return new ArrayList<>();
return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList());
}
@Operation(
@ -41,11 +50,12 @@ public class LinkPublisherV2 {
@GetMapping("/inTarget")
public List<LinkProviderType> getInTarget(
@Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name
) {
return Arrays.asList(
new LinkProviderType().name("pippo").totalRelationships(30),
new LinkProviderType().name("pluto").totalRelationships(30),
new LinkProviderType().name("peppa").totalRelationships(30)
);
) throws ScholixException {
List<Pair<String, Long>> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.target,name);
if (result==null)
return new ArrayList<>();
return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList());
}
}

View File

@ -2,36 +2,42 @@ package eu.dnetlib.scholix.api.controller;
import eu.dnetlib.common.controller.AbstractDnetController;
import eu.dnetlib.dhp.schema.sx.scholix.Scholix;
import eu.dnetlib.scholix.api.ScholixException;
import eu.dnetlib.scholix.api.index.ScholixIndexManager;
import eu.dnetlib.scholix.api.model.v1.ScholixV1;
import io.micrometer.core.annotation.Timed;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/v1")
@Api(tags = {
"Scholix"
})
@Api(tags = {"Scholix"})
public class ScholixControllerV1 extends AbstractDnetController {
@Autowired
ScholixIndexManager manager;
@Operation(
summary = "Get all Scholix relation collected from a publisher",
description = "return a list of scholix object published from a specific publisher"
)
@GetMapping("/linksFromPublisher")
@Timed(value = "scholix.v1.linksFromPublisher", description = "Time taken to return links on Version 1.0 of Scholix collected from a publisher")
public List<ScholixV1> linksFromPublisher(
@Parameter(
in = ParameterIn.QUERY,
@ -39,9 +45,17 @@ public class ScholixControllerV1 extends AbstractDnetController {
schema = @Schema(), required = true) String publisher,
@Parameter(in = ParameterIn.QUERY,
description = "The page number") @RequestParam(required = false) Integer page
) {
) throws ScholixException {
return new ArrayList<>();
final int currentPage = page != null ? page : 0;
Pair<Long, List<Scholix>> scholixResult =manager.linksFromPid(null,null,null,publisher,
null,null,null,null,null,null, currentPage
);
List<Scholix> scholixData = scholixResult.getValue();
if (scholixData== null)
return null;
return scholixData.stream().map(ScholixV1::fromScholix).collect(Collectors.toList());
}
@Operation(
@ -49,6 +63,7 @@ public class ScholixControllerV1 extends AbstractDnetController {
description = "return a list of scholix object collected from a specific datasource"
)
@GetMapping("/linksFromDatasource")
@Timed(value = "scholix.v1.linksFromDatasource", description = "Time taken to return links on Version 1.0 of Scholix collected from a LinkProvider")
public List<ScholixV1> linksFromDatasource(
@Parameter(
in = ParameterIn.QUERY,
@ -56,9 +71,16 @@ public class ScholixControllerV1 extends AbstractDnetController {
schema = @Schema()) @NotNull String datasource,
@Parameter(in = ParameterIn.QUERY,
description = "The page number") @RequestParam(required = false) Integer page
) {
) throws ScholixException {
return new ArrayList<>();
final int currentPage = page != null ? page : 0;
Pair<Long, List<Scholix>> scholixResult =manager.linksFromPid(datasource,null,null,null,
null,null,null,null,null,null, currentPage
);
List<Scholix> scholixData = scholixResult.getValue();
if (scholixData== null)
return null;
return scholixData.stream().map(ScholixV1::fromScholix).collect(Collectors.toList());
}
@ -67,6 +89,7 @@ public class ScholixControllerV1 extends AbstractDnetController {
description = "The linksFromPid endpoint returns a list of scholix object related from a specific persistent identifier"
)
@GetMapping("/linksFromPid")
@Timed(value = "scholix.v1.linksFromPid", description = "Time taken to return links on Version 1.0 of Scholix related from a specific persistent identifier")
public List<ScholixV1> linksFromPid(
@Parameter(in = ParameterIn.QUERY, description = "persistent Identifier") @NotNull String pid,
@Parameter(in = ParameterIn.QUERY, description = "Persistent Identifier Type") @RequestParam(required = false) String pidType,
@ -74,9 +97,16 @@ public class ScholixControllerV1 extends AbstractDnetController {
@Parameter(in = ParameterIn.QUERY, description = "a datasource provenance filter of the target relation") @RequestParam(required = false) String datasourceTarget,
@Parameter(in = ParameterIn.QUERY,
description = "The page number") @RequestParam(required = false) Integer page
) {
) throws ScholixException {
return new ArrayList<>();
final int currentPage = page != null ? page : 0;
Pair<Long, List<Scholix>> scholixResult =manager.linksFromPid(datasourceTarget,null,null,null,
typologyTarget,pid,pidType,null,null,null, currentPage
);
List<Scholix> scholixData = scholixResult.getValue();
if (scholixData== null)
return null;
return scholixData.stream().map(ScholixV1::fromScholix).collect(Collectors.toList());
}

View File

@ -2,7 +2,7 @@ package eu.dnetlib.scholix.api.controller;
import eu.dnetlib.common.controller.AbstractDnetController;
import eu.dnetlib.dhp.schema.sx.scholix.ScholixIdentifier;
import eu.dnetlib.dhp.schema.sx.scholix.Scholix;
import eu.dnetlib.scholix.api.ScholixAPIVersion;
import eu.dnetlib.scholix.api.ScholixException;
import eu.dnetlib.scholix.api.index.ScholixIndexManager;
@ -13,29 +13,13 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import eu.dnetlib.dhp.schema.sx.scholix.Scholix;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.NestedQueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.Query;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -49,9 +33,6 @@ public class ScholixControllerV2 extends AbstractDnetController {
@Autowired
private ScholixIndexManager manager;
@Timed(value = "scholix.v2.links", description = "Time taken to return links on Version 2.0 of Scholix")
@ApiOperation("Get Scholix Links")
@GetMapping("/Links")
@ -84,7 +65,7 @@ public class ScholixControllerV2 extends AbstractDnetController {
try {
final int currentPage = page != null ? page : 0;
Pair<Long, List<Scholix>> scholixResult = manager.linksFromPid(ScholixAPIVersion.V2, linkProvider, targetPid, targetPidType, targetPublisher, targetType, sourcePid, sourcePidType, sourcePublisher, sourceType, harvestedAfter, currentPage);
Pair<Long, List<Scholix>> scholixResult = manager.linksFromPid( linkProvider, targetPid, targetPidType, targetPublisher, targetType, sourcePid, sourcePidType, sourcePublisher, sourceType, harvestedAfter, currentPage);
final PageResultType pageResult = new PageResultType();
pageResult.setTotalPages(scholixResult.getLeft().intValue() / 10);
pageResult.setTotalLinks(scholixResult.getLeft().intValue());
@ -94,7 +75,4 @@ public class ScholixControllerV2 extends AbstractDnetController {
throw new ScholixException("Error on requesting url ", e);
}
}
}

View File

@ -61,7 +61,7 @@ public class ScholixIndexManager {
/**
* The enum Pid type prefix.
*/
enum pidTypePrefix {
public enum RelationPrefix {
/**
* Source pid type prefix.
*/
@ -73,7 +73,7 @@ public class ScholixIndexManager {
}
private QueryBuilder createObjectTypeQuery(final pidTypePrefix prefix, final String objectType ) throws ScholixException{
private QueryBuilder createObjectTypeQuery(final RelationPrefix prefix, final String objectType ) throws ScholixException{
if (prefix == null){
throw new ScholixException("prefix cannot be null");
}
@ -81,7 +81,7 @@ public class ScholixIndexManager {
}
private QueryBuilder createPidTypeQuery(final pidTypePrefix prefix, final String pidTypeValue ) throws ScholixException{
private QueryBuilder createPidTypeQuery(final RelationPrefix prefix, final String pidTypeValue ) throws ScholixException{
if (prefix == null){
throw new ScholixException("prefix cannot be null");
}
@ -89,7 +89,21 @@ public class ScholixIndexManager {
}
private QueryBuilder createPidValueQuery(final pidTypePrefix prefix, final String pidValue ) throws ScholixException{
private QueryBuilder createLinkProviderQuery(final String providerName ) throws ScholixException{
if (providerName == null){
throw new ScholixException("prefix cannot be null");
}
return new NestedQueryBuilder("linkprovider", new TermQueryBuilder("linkprovider.name",providerName), ScoreMode.None);
}
private QueryBuilder createLinkPublisherQuery(final RelationPrefix prefix, final String publisher ) throws ScholixException{
if (prefix == null){
throw new ScholixException("prefix cannot be null");
}
return new NestedQueryBuilder(String.format("%s.publisher", prefix), new TermQueryBuilder(String.format("%s.publisher.name",prefix), publisher), ScoreMode.None);
}
private QueryBuilder createPidValueQuery(final RelationPrefix prefix, final String pidValue ) throws ScholixException{
if (prefix == null){
throw new ScholixException("prefix cannot be null");
}
@ -116,7 +130,7 @@ public class ScholixIndexManager {
}
private void incrementPidCounter(pidTypePrefix prefix, String value) {
private void incrementPidCounter(RelationPrefix prefix, String value) {
switch (value.toLowerCase()){
case "doi": {
myCounter.increment(String.format("%s_doi", prefix));
@ -132,10 +146,13 @@ public class ScholixIndexManager {
}
public List<Pair<String, Long>> linksByProvider(final String filterName) throws ScholixException {
public List<Pair<String, Long>> totalLinksByProvider(final String filterName) throws ScholixException {
final QueryBuilder query = StringUtils.isNoneBlank(filterName)?createLinkProviderQuery(filterName):QueryBuilders.matchAllQuery();
final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.matchAllQuery())
.withQuery(query)
.withSearchType(SearchType.DEFAULT)
.withPageable(PageRequest.of(0,10))
.addAggregation(AggregationBuilders.nested("nested", "linkprovider")
@ -148,7 +165,41 @@ public class ScholixIndexManager {
final SearchHits<Scholix> hits = client.search(searchQuery, Scholix.class, IndexCoordinates.of(elasticSearchProperties.getIndexName()));
final Aggregations aggregations = hits.getAggregations();
connectionPool.returnResource(resource);
if(aggregations == null)
return null;
final Aggregation aggByMap = ((ParsedNested) aggregations.asMap().get("nested")).getAggregations().asMap().get("by_map");
return ((ParsedStringTerms) aggByMap).getBuckets()
.stream()
.map(b -> new ImmutablePair<>(b.getKeyAsString(), b.getDocCount()))
.collect(Collectors.toList());
}
public List<Pair<String, Long>> totalLinksPublisher(final RelationPrefix prefix, final String filterName) throws ScholixException {
final QueryBuilder query = StringUtils.isNoneBlank(filterName)?createLinkPublisherQuery(prefix,filterName):QueryBuilders.matchAllQuery();
final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(query)
.withSearchType(SearchType.DEFAULT)
.withPageable(PageRequest.of(0,10))
.addAggregation(AggregationBuilders.nested("nested", String.format("%s.publisher", prefix ))
.subAggregation(AggregationBuilders.terms("by_map").field(String.format("%s.publisher.name", prefix )).size(100).minDocCount(1)))
.build();
Pair<RestHighLevelClient, ElasticsearchRestTemplate> resource = connectionPool.getResource();
ElasticsearchRestTemplate client = resource.getValue();
final SearchHits<Scholix> hits = client.search(searchQuery, Scholix.class, IndexCoordinates.of(elasticSearchProperties.getIndexName()));
final Aggregations aggregations = hits.getAggregations();
connectionPool.returnResource(resource);
if(aggregations == null)
return null;
@ -171,7 +222,6 @@ public class ScholixIndexManager {
/**
* Links from pid pair.
*
* @param outputVersion the output version
* @param linkProvider the link provider
* @param targetPid the target pid
* @param targetPidType the target pid type
@ -187,51 +237,61 @@ public class ScholixIndexManager {
* @throws ScholixException the scholix exception
*/
@Timed(value = "scholix.index.request.links", description = "Time taken to request index")
public Pair<Long,List<Scholix>> linksFromPid (final ScholixAPIVersion outputVersion, final String linkProvider,
public Pair<Long,List<Scholix>> linksFromPid ( final String linkProvider,
final String targetPid, final String targetPidType, final String targetPublisher,
final String targetType, final String sourcePid, final String sourcePidType,
final String sourcePublisher, final String sourceType, final String harvestedAfter,
final Integer page) throws ScholixException {
if(outputVersion == null)
throw new ScholixException("Error outputVersion not be empty");
if (sourcePid==null && sourcePidType==null && targetPid==null && targetPidType==null && sourcePublisher==null && targetPublisher==null && linkProvider==null)
throw new ScholixException("One of sourcePid, targetPid, sourcePublisher, targetPublisher, linkProvider should be not null");
final List<QueryBuilder> queries = new ArrayList<>();
if (StringUtils.isNoneBlank(linkProvider)) {
myCounter.increment("linkProvider");
queries.add(createLinkProviderQuery(linkProvider));
}
if (StringUtils.isNoneBlank(targetPid)) {
myCounter.increment("targetPid");
queries.add(createPidValueQuery(pidTypePrefix.target, targetPid));
queries.add(createPidValueQuery(RelationPrefix.target, targetPid));
}
if (StringUtils.isNoneBlank(sourcePid)) {
myCounter.increment("sourcePid");
queries.add(createPidValueQuery(pidTypePrefix.source, sourcePid));
queries.add(createPidValueQuery(RelationPrefix.source, sourcePid));
}
if (StringUtils.isNoneBlank(targetPidType)) {
assert targetPidType != null;
incrementPidCounter(pidTypePrefix.target,targetPidType);
queries.add(createPidTypeQuery(pidTypePrefix.target, targetPidType));
incrementPidCounter(RelationPrefix.target,targetPidType);
queries.add(createPidTypeQuery(RelationPrefix.target, targetPidType));
}
if (StringUtils.isNoneBlank(sourcePidType)) {
assert sourcePidType != null;
incrementPidCounter(pidTypePrefix.source,sourcePidType);
queries.add(createPidTypeQuery(pidTypePrefix.source, sourcePidType));
incrementPidCounter(RelationPrefix.source,sourcePidType);
queries.add(createPidTypeQuery(RelationPrefix.source, sourcePidType));
}
if (StringUtils.isNoneBlank(targetType)) {
if ("dataset".equalsIgnoreCase(targetType) || "publication".equalsIgnoreCase(targetType))
myCounter.increment(String.format("targetType_%s", targetType));
queries.add(createObjectTypeQuery(pidTypePrefix.target, targetType));
queries.add(createObjectTypeQuery(RelationPrefix.target, targetType));
}
if (StringUtils.isNoneBlank(sourceType)) {
if ("dataset".equalsIgnoreCase(sourceType) || "publication".equalsIgnoreCase(sourceType)) {
myCounter.increment(String.format("sourceType_%s", sourceType));
}
queries.add(createObjectTypeQuery(pidTypePrefix.source, sourceType));
queries.add(createObjectTypeQuery(RelationPrefix.source, sourceType));
}
if (StringUtils.isNoneBlank(targetPublisher)) {
myCounter.increment("targetPublisher");
queries.add(createLinkPublisherQuery(RelationPrefix.target,targetPublisher));
}
QueryBuilder result = createFinalQuery(queries);
@ -254,8 +314,4 @@ public class ScholixIndexManager {
return new ImmutablePair<>(tt,scholixRes.stream().map(SearchHit::getContent).collect(Collectors.toList()));
}
}

View File

@ -1,11 +1,11 @@
package eu.dnetlib.scholix.api.model.v1;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.dhp.schema.sx.scholix.ScholixEntityId;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class ScholixCreator {
@ -29,22 +29,11 @@ public class ScholixCreator {
return name;
}
public void setName(String name) {
public ScholixCreator setName(String name) {
this.name = name;
}
public ScholixCreator identifier(List<ScholixIdentifier> identifier) {
this.identifier = identifier;
return this;
}
public ScholixCreator addIdentifierItem(ScholixIdentifier identifierItem) {
if (this.identifier == null) {
this.identifier = new ArrayList<ScholixIdentifier>();
}
this.identifier.add(identifierItem);
return this;
}
/**
* Get identifier
@ -55,48 +44,26 @@ public class ScholixCreator {
return identifier;
}
public void setIdentifier(List<ScholixIdentifier> identifier) {
public ScholixCreator setIdentifier(List<ScholixIdentifier> identifier) {
this.identifier = identifier;
return this;
}
public static ScholixCreator fromScholixEntityId(final ScholixEntityId provider) {
if (provider == null)
return null;
ScholixCreator instance = new ScholixCreator().setName(provider.getName());
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ScholixCreator ScholixCreator = (ScholixCreator) o;
return Objects.equals(this.name, ScholixCreator.name) &&
Objects.equals(this.identifier, ScholixCreator.identifier);
}
@Override
public int hashCode() {
return Objects.hash(name, identifier);
}
if (provider.getIdentifiers()!= null && provider.getIdentifiers().size()>0)
instance.setIdentifier(provider.getIdentifiers()
.stream()
.map(i ->new ScholixIdentifier()
.setIdentifier(i.getIdentifier())
.setSchema(i.getSchema()))
.collect(Collectors.toList()));
return instance;
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ScholixCreator {\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@ -29,8 +29,9 @@ public class ScholixIdentifier {
return identifier;
}
public void setIdentifier(String identifier) {
public ScholixIdentifier setIdentifier(String identifier) {
this.identifier = identifier;
return this;
}
public ScholixIdentifier Schema(String idScheme) {
@ -48,51 +49,23 @@ public class ScholixIdentifier {
return schema;
}
public void setSchema(String schema) {
public ScholixIdentifier setSchema(String schema) {
this.schema = schema;
return this;
}
public static ScholixIdentifier fromScholixIdentifier(eu.dnetlib.dhp.schema.sx.scholix.ScholixIdentifier input) {
if (input == null)
return null;
final ScholixIdentifier result = new ScholixIdentifier();
result.setSchema(input.getSchema());
result.setIdentifier(input.getIdentifier());
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ScholixIdentifier identifierType = (ScholixIdentifier) o;
return Objects.equals(this.identifier, identifierType.identifier) &&
Objects.equals(this.schema, identifierType.schema);
}
@Override
public int hashCode() {
return Objects.hash(identifier, schema);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class IdentifierType {\n");
sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n");
sb.append(" schema: ").append(toIndentedString(schema)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@ -1,16 +1,18 @@
package eu.dnetlib.scholix.api.model.v1;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.dhp.schema.sx.scholix.ScholixResource;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class ScholixItem {
@JsonProperty("identifier")
private ScholixIdentifier identifier;
@JsonProperty("identifiers")
private List<ScholixIdentifier> identifiers;
@JsonProperty("objectType")
private String objectType;
@ -28,22 +30,18 @@ public class ScholixItem {
private String publicationDate;
@JsonProperty("publisher")
private ScholixProvider publisher;
private List<ScholixProvider> publisher;
public ScholixItem identifier(ScholixIdentifier identifier) {
this.identifier = identifier;
@Schema(description = "The list of identifiers")
public List<ScholixIdentifier> getIdentifiers() {
return identifiers;
}
public ScholixItem setIdentifiers(List<ScholixIdentifier> identifiers) {
this.identifiers = identifiers;
return this;
}
@Schema(description = "The identifier string")
public ScholixIdentifier getIdentifier() {
return identifier;
}
public void setIdentifier(ScholixIdentifier identifier) {
this.identifier = identifier;
}
public ScholixItem objectType(String objectType) {
this.objectType = objectType;
return this;
@ -116,63 +114,48 @@ public class ScholixItem {
this.publicationDate = publicationDate;
}
@Schema(description = "The name of the publisher of the object")
public ScholixProvider getPublisher() {
@Schema(description = "The list name of the publisher of the object")
public List<ScholixProvider> getPublisher() {
return publisher;
}
public void setPublisher(ScholixProvider publisher) {
public ScholixItem setPublisher(List<ScholixProvider> publisher) {
this.publisher = publisher;
return this;
}
public static ScholixItem fromScholixResource(final ScholixResource input) {
if (input == null)
return null;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ScholixItem scholixItemType = (ScholixItem) o;
return Objects.equals(this.objectType, scholixItemType.objectType) &&
Objects.equals(this.objectSubType, scholixItemType.objectSubType) &&
Objects.equals(this.identifier, scholixItemType.identifier) &&
Objects.equals(this.title, scholixItemType.title) &&
Objects.equals(this.creator, scholixItemType.creator) &&
Objects.equals(this.publicationDate, scholixItemType.publicationDate) &&
Objects.equals(this.publisher, scholixItemType.publisher);
}
@Override
public int hashCode() {
return Objects.hash(objectType, objectSubType, identifier, title, creator, publicationDate, publisher);
}
final ScholixItem result = new ScholixItem();
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ScholixItemType {\n");
if (input.getIdentifier()!= null)
result.setIdentifiers(
input.getIdentifier().stream()
.map(ScholixIdentifier::fromScholixIdentifier)
.collect(Collectors.toList())
);
sb.append(" objectType: ").append(toIndentedString(objectType)).append("\n");
sb.append(" objectSubType: ").append(toIndentedString(objectSubType)).append("\n");
sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n");
sb.append(" title: ").append(toIndentedString(title)).append("\n");
sb.append(" creator: ").append(toIndentedString(creator)).append("\n");
sb.append(" publicationDate: ").append(toIndentedString(publicationDate)).append("\n");
sb.append(" publisher: ").append(toIndentedString(publisher)).append("\n");
sb.append("}");
return sb.toString();
}
result.setTitle(input.getTitle());
result.setObjectType(input.getObjectType());
result.setObjectSubType(input.getObjectSubType());
result.setPublicationDate(input.getPublicationDate());
if(input.getPublisher()!= null)
result.setPublisher(input.getPublisher().stream()
.map(ScholixProvider::fromScholixEntityId)
.collect(Collectors.toList())
);
if (input.getCreator()!= null)
result.setCreator(input.getCreator().stream()
.map(ScholixCreator::fromScholixEntityId)
.collect(Collectors.toList())
);
return result;
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@ -1,15 +1,36 @@
package eu.dnetlib.scholix.api.model.v1;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.dhp.schema.sx.scholix.ScholixEntityId;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class ScholixProvider {
public static ScholixProvider fromScholixEntityId(final ScholixEntityId provider) {
if (provider == null)
return null;
ScholixProvider instance = new ScholixProvider().setName(provider.getName());
if (provider.getIdentifiers()!= null && provider.getIdentifiers().size()>0)
instance.setIdentifier(provider.getIdentifiers()
.stream()
.map(i ->new ScholixIdentifier()
.setIdentifier(i.getIdentifier())
.setSchema(i.getSchema()))
.collect(Collectors.toList()));
return instance;
}
@JsonProperty("name")
private String name = null;
@ -32,8 +53,9 @@ public class ScholixProvider {
return name;
}
public void setName(String name) {
public ScholixProvider setName(String name) {
this.name = name;
return this;
}
public ScholixProvider identifier(List<ScholixIdentifier> identifier) {
@ -59,8 +81,9 @@ public class ScholixProvider {
return identifier;
}
public void setIdentifier(List<ScholixIdentifier> identifier) {
public ScholixProvider setIdentifier(List<ScholixIdentifier> identifier) {
this.identifier = identifier;
return this;
}

View File

@ -6,6 +6,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotBlank;
import java.util.Objects;
import static eu.dnetlib.scholix.api.model.v2.RelationshipType.relationMapping;
public class ScholixRelationship {
@JsonProperty("name")
@ -116,4 +118,17 @@ public class ScholixRelationship {
return o.toString().replace("\n", "\n ");
}
public static ScholixRelationship fromScholixIndexRelationship(eu.dnetlib.dhp.schema.sx.scholix.ScholixRelationship inputRel) {
if(inputRel==null)
return null;
ScholixRelationship result = new ScholixRelationship();
result.setName(relationMapping.getOrDefault(inputRel.getName(), "IsRelatedTo"));
result.setInverseRelationship(relationMapping.getOrDefault(inputRel.getInverse(), "IsRelatedTo"));
result.setSchema(inputRel.getSchema());
return result;
}
}

View File

@ -9,6 +9,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class ScholixV1 implements Serializable {
@ -161,6 +162,23 @@ public class ScholixV1 implements Serializable {
public static ScholixV1 fromScholix(Scholix input) {
return new ScholixV1();
if (input == null)
return null;
final ScholixV1 result = new ScholixV1();
if (input.getLinkprovider()!= null)
result.setLinkProvider(input.getLinkprovider()
.stream()
.map(ScholixProvider::fromScholixEntityId)
.collect(Collectors.toList()));
result.setPublicationDate(input.getPublicationDate());
result.setRelationship(ScholixRelationship.fromScholixIndexRelationship(input.getRelationship()));
result.setSource(ScholixItem.fromScholixResource(input.getSource()));
result.setTarget(ScholixItem.fromScholixResource(input.getTarget()));
return result;
}
}

View File

@ -27,7 +27,7 @@ public class RelationshipType {
private String subTypeSchema;
private static Map<String, String> relationMapping = Stream.of(new String[][] {
public static Map<String, String> relationMapping = Stream.of(new String[][] {
{ "issupplementto", "IsSupplementTo" },
{ "issupplementedby", "IsSupplementedBy" },
{ "references", "References" },

View File

@ -0,0 +1,18 @@
package eu.dnetlib.scholix.test;
import org.junit.jupiter.api.Test;
public class QueryTest {
@Test
public void featureToTest() {
}
}