implemented Scholix V1 APIs
This commit is contained in:
parent
fc74c86ba9
commit
d5a089869c
|
@ -14,12 +14,10 @@
|
||||||
<artifactId>scholexplorer-api</artifactId>
|
<artifactId>scholexplorer-api</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-elasticsearch</artifactId>
|
<artifactId>spring-data-elasticsearch</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -29,15 +27,11 @@
|
||||||
<groupId>eu.dnetlib.dhp</groupId>
|
<groupId>eu.dnetlib.dhp</groupId>
|
||||||
<artifactId>dhp-schemas</artifactId>
|
<artifactId>dhp-schemas</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-pool2</artifactId>
|
<artifactId>commons-pool2</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
package eu.dnetlib.scholix.api.controller;
|
package eu.dnetlib.scholix.api.controller;
|
||||||
|
|
||||||
import eu.dnetlib.common.controller.AbstractDnetController;
|
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 eu.dnetlib.scholix.api.model.v1.LinkPublisher;
|
||||||
import io.micrometer.core.annotation.Timed;
|
import io.micrometer.core.annotation.Timed;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -20,16 +26,24 @@ import java.util.List;
|
||||||
})
|
})
|
||||||
public class DatasourceV1 extends AbstractDnetController {
|
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")
|
@Timed(value = "scholix.v1.datasources", description = "Time taken to return all datasources on Version 1.0 of Scholix")
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Get all Datasources",
|
summary = "Get all Datasources",
|
||||||
description = "returns a list of all datasources")
|
description = "returns a list of all datasources")
|
||||||
@GetMapping("/listDatasources")
|
@GetMapping("/listDatasources")
|
||||||
public List<LinkPublisher> getDatasources() {
|
public List<LinkPublisher> getDatasources() throws ScholixException {
|
||||||
return Arrays.asList(
|
|
||||||
new LinkPublisher().name("pippo").totalRelationships(30),
|
|
||||||
new LinkPublisher().name("pluto").totalRelationships(30),
|
final List<Pair<String, Long>> result = manager.totalLinksByProvider(null);
|
||||||
new LinkPublisher().name("peppa").totalRelationships(30)
|
|
||||||
);
|
if (result == null)
|
||||||
|
return new ArrayList<>();
|
||||||
|
|
||||||
|
return result.stream().map(p -> new LinkPublisher().name(p.getKey()).totalRelationships(p.getValue().intValue())).collect(Collectors.toList());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
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
|
@Parameter(in = ParameterIn.QUERY, description = "Filter the link provider name") @RequestParam(required = false) String name
|
||||||
) throws ScholixException {
|
) throws ScholixException {
|
||||||
|
|
||||||
List<Pair<String, Long>> result = manager.linksByProvider(null);
|
List<Pair<String, Long>> result = manager.totalLinksByProvider(name);
|
||||||
|
|
||||||
if (result==null)
|
if (result==null)
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
package eu.dnetlib.scholix.api.controller;
|
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 eu.dnetlib.scholix.api.model.v2.LinkProviderType;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/v2/LinkPublisher")
|
@RequestMapping("/v2/LinkPublisher")
|
||||||
|
@ -19,6 +24,9 @@ import java.util.List;
|
||||||
})
|
})
|
||||||
public class LinkPublisherV2 {
|
public class LinkPublisherV2 {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ScholixIndexManager manager;
|
||||||
|
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Get All Publishers that provide source object",
|
summary = "Get All Publishers that provide source object",
|
||||||
description = "Return a List of all Publishers that provide source objects in Scholix " +
|
description = "Return a List of all Publishers that provide source objects in Scholix " +
|
||||||
|
@ -26,12 +34,13 @@ public class LinkPublisherV2 {
|
||||||
@GetMapping("/inSource")
|
@GetMapping("/inSource")
|
||||||
public List<LinkProviderType> getInSource(
|
public List<LinkProviderType> getInSource(
|
||||||
@Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name
|
@Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name
|
||||||
) {
|
) throws ScholixException {
|
||||||
return Arrays.asList(
|
List<Pair<String, Long>> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.source,name);
|
||||||
new LinkProviderType().name("pippo").totalRelationships(30),
|
|
||||||
new LinkProviderType().name("pluto").totalRelationships(30),
|
if (result==null)
|
||||||
new LinkProviderType().name("peppa").totalRelationships(30)
|
return new ArrayList<>();
|
||||||
);
|
|
||||||
|
return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(
|
@Operation(
|
||||||
|
@ -41,11 +50,12 @@ public class LinkPublisherV2 {
|
||||||
@GetMapping("/inTarget")
|
@GetMapping("/inTarget")
|
||||||
public List<LinkProviderType> getInTarget(
|
public List<LinkProviderType> getInTarget(
|
||||||
@Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name
|
@Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name
|
||||||
) {
|
) throws ScholixException {
|
||||||
return Arrays.asList(
|
List<Pair<String, Long>> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.target,name);
|
||||||
new LinkProviderType().name("pippo").totalRelationships(30),
|
|
||||||
new LinkProviderType().name("pluto").totalRelationships(30),
|
if (result==null)
|
||||||
new LinkProviderType().name("peppa").totalRelationships(30)
|
return new ArrayList<>();
|
||||||
);
|
|
||||||
|
return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,36 +2,42 @@ package eu.dnetlib.scholix.api.controller;
|
||||||
|
|
||||||
|
|
||||||
import eu.dnetlib.common.controller.AbstractDnetController;
|
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 eu.dnetlib.scholix.api.model.v1.ScholixV1;
|
||||||
|
import io.micrometer.core.annotation.Timed;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/v1")
|
@RequestMapping("/v1")
|
||||||
@Api(tags = {
|
@Api(tags = {"Scholix"})
|
||||||
"Scholix"
|
|
||||||
})
|
|
||||||
public class ScholixControllerV1 extends AbstractDnetController {
|
public class ScholixControllerV1 extends AbstractDnetController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ScholixIndexManager manager;
|
||||||
|
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Get all Scholix relation collected from a publisher",
|
summary = "Get all Scholix relation collected from a publisher",
|
||||||
description = "return a list of scholix object published from a specific publisher"
|
description = "return a list of scholix object published from a specific publisher"
|
||||||
)
|
)
|
||||||
@GetMapping("/linksFromPublisher")
|
@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(
|
public List<ScholixV1> linksFromPublisher(
|
||||||
@Parameter(
|
@Parameter(
|
||||||
in = ParameterIn.QUERY,
|
in = ParameterIn.QUERY,
|
||||||
|
@ -39,9 +45,17 @@ public class ScholixControllerV1 extends AbstractDnetController {
|
||||||
schema = @Schema(), required = true) String publisher,
|
schema = @Schema(), required = true) String publisher,
|
||||||
@Parameter(in = ParameterIn.QUERY,
|
@Parameter(in = ParameterIn.QUERY,
|
||||||
description = "The page number") @RequestParam(required = false) Integer page
|
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(
|
@Operation(
|
||||||
|
@ -49,6 +63,7 @@ public class ScholixControllerV1 extends AbstractDnetController {
|
||||||
description = "return a list of scholix object collected from a specific datasource"
|
description = "return a list of scholix object collected from a specific datasource"
|
||||||
)
|
)
|
||||||
@GetMapping("/linksFromDatasource")
|
@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(
|
public List<ScholixV1> linksFromDatasource(
|
||||||
@Parameter(
|
@Parameter(
|
||||||
in = ParameterIn.QUERY,
|
in = ParameterIn.QUERY,
|
||||||
|
@ -56,9 +71,16 @@ public class ScholixControllerV1 extends AbstractDnetController {
|
||||||
schema = @Schema()) @NotNull String datasource,
|
schema = @Schema()) @NotNull String datasource,
|
||||||
@Parameter(in = ParameterIn.QUERY,
|
@Parameter(in = ParameterIn.QUERY,
|
||||||
description = "The page number") @RequestParam(required = false) Integer page
|
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"
|
description = "The linksFromPid endpoint returns a list of scholix object related from a specific persistent identifier"
|
||||||
)
|
)
|
||||||
@GetMapping("/linksFromPid")
|
@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(
|
public List<ScholixV1> linksFromPid(
|
||||||
@Parameter(in = ParameterIn.QUERY, description = "persistent Identifier") @NotNull String pid,
|
@Parameter(in = ParameterIn.QUERY, description = "persistent Identifier") @NotNull String pid,
|
||||||
@Parameter(in = ParameterIn.QUERY, description = "Persistent Identifier Type") @RequestParam(required = false) String pidType,
|
@Parameter(in = ParameterIn.QUERY, description = "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 = "a datasource provenance filter of the target relation") @RequestParam(required = false) String datasourceTarget,
|
||||||
@Parameter(in = ParameterIn.QUERY,
|
@Parameter(in = ParameterIn.QUERY,
|
||||||
description = "The page number") @RequestParam(required = false) Integer page
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package eu.dnetlib.scholix.api.controller;
|
||||||
|
|
||||||
|
|
||||||
import eu.dnetlib.common.controller.AbstractDnetController;
|
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.ScholixAPIVersion;
|
||||||
import eu.dnetlib.scholix.api.ScholixException;
|
import eu.dnetlib.scholix.api.ScholixException;
|
||||||
import eu.dnetlib.scholix.api.index.ScholixIndexManager;
|
import eu.dnetlib.scholix.api.index.ScholixIndexManager;
|
||||||
|
@ -13,29 +13,13 @@ import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
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.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
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.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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -49,9 +33,6 @@ public class ScholixControllerV2 extends AbstractDnetController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ScholixIndexManager manager;
|
private ScholixIndexManager manager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Timed(value = "scholix.v2.links", description = "Time taken to return links on Version 2.0 of Scholix")
|
@Timed(value = "scholix.v2.links", description = "Time taken to return links on Version 2.0 of Scholix")
|
||||||
@ApiOperation("Get Scholix Links")
|
@ApiOperation("Get Scholix Links")
|
||||||
@GetMapping("/Links")
|
@GetMapping("/Links")
|
||||||
|
@ -84,7 +65,7 @@ public class ScholixControllerV2 extends AbstractDnetController {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final int currentPage = page != null ? page : 0;
|
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();
|
final PageResultType pageResult = new PageResultType();
|
||||||
pageResult.setTotalPages(scholixResult.getLeft().intValue() / 10);
|
pageResult.setTotalPages(scholixResult.getLeft().intValue() / 10);
|
||||||
pageResult.setTotalLinks(scholixResult.getLeft().intValue());
|
pageResult.setTotalLinks(scholixResult.getLeft().intValue());
|
||||||
|
@ -94,7 +75,4 @@ public class ScholixControllerV2 extends AbstractDnetController {
|
||||||
throw new ScholixException("Error on requesting url ", e);
|
throw new ScholixException("Error on requesting url ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class ScholixIndexManager {
|
||||||
/**
|
/**
|
||||||
* The enum Pid type prefix.
|
* The enum Pid type prefix.
|
||||||
*/
|
*/
|
||||||
enum pidTypePrefix {
|
public enum RelationPrefix {
|
||||||
/**
|
/**
|
||||||
* Source pid type prefix.
|
* 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){
|
if (prefix == null){
|
||||||
throw new ScholixException("prefix cannot be 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){
|
if (prefix == null){
|
||||||
throw new ScholixException("prefix cannot be 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){
|
if (prefix == null){
|
||||||
throw new ScholixException("prefix cannot be 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()){
|
switch (value.toLowerCase()){
|
||||||
case "doi": {
|
case "doi": {
|
||||||
myCounter.increment(String.format("%s_doi", prefix));
|
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()
|
final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||||
.withQuery(QueryBuilders.matchAllQuery())
|
.withQuery(query)
|
||||||
.withSearchType(SearchType.DEFAULT)
|
.withSearchType(SearchType.DEFAULT)
|
||||||
.withPageable(PageRequest.of(0,10))
|
.withPageable(PageRequest.of(0,10))
|
||||||
.addAggregation(AggregationBuilders.nested("nested", "linkprovider")
|
.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 SearchHits<Scholix> hits = client.search(searchQuery, Scholix.class, IndexCoordinates.of(elasticSearchProperties.getIndexName()));
|
||||||
|
|
||||||
final Aggregations aggregations = hits.getAggregations();
|
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)
|
if(aggregations == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -171,7 +222,6 @@ public class ScholixIndexManager {
|
||||||
/**
|
/**
|
||||||
* Links from pid pair.
|
* Links from pid pair.
|
||||||
*
|
*
|
||||||
* @param outputVersion the output version
|
|
||||||
* @param linkProvider the link provider
|
* @param linkProvider the link provider
|
||||||
* @param targetPid the target pid
|
* @param targetPid the target pid
|
||||||
* @param targetPidType the target pid type
|
* @param targetPidType the target pid type
|
||||||
|
@ -187,51 +237,61 @@ public class ScholixIndexManager {
|
||||||
* @throws ScholixException the scholix exception
|
* @throws ScholixException the scholix exception
|
||||||
*/
|
*/
|
||||||
@Timed(value = "scholix.index.request.links", description = "Time taken to request index")
|
@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 targetPid, final String targetPidType, final String targetPublisher,
|
||||||
final String targetType, final String sourcePid, final String sourcePidType,
|
final String targetType, final String sourcePid, final String sourcePidType,
|
||||||
final String sourcePublisher, final String sourceType, final String harvestedAfter,
|
final String sourcePublisher, final String sourceType, final String harvestedAfter,
|
||||||
final Integer page) throws ScholixException {
|
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)
|
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");
|
throw new ScholixException("One of sourcePid, targetPid, sourcePublisher, targetPublisher, linkProvider should be not null");
|
||||||
|
|
||||||
final List<QueryBuilder> queries = new ArrayList<>();
|
final List<QueryBuilder> queries = new ArrayList<>();
|
||||||
|
|
||||||
|
if (StringUtils.isNoneBlank(linkProvider)) {
|
||||||
|
myCounter.increment("linkProvider");
|
||||||
|
queries.add(createLinkProviderQuery(linkProvider));
|
||||||
|
}
|
||||||
|
|
||||||
if (StringUtils.isNoneBlank(targetPid)) {
|
if (StringUtils.isNoneBlank(targetPid)) {
|
||||||
myCounter.increment("targetPid");
|
myCounter.increment("targetPid");
|
||||||
queries.add(createPidValueQuery(pidTypePrefix.target, targetPid));
|
queries.add(createPidValueQuery(RelationPrefix.target, targetPid));
|
||||||
}
|
}
|
||||||
if (StringUtils.isNoneBlank(sourcePid)) {
|
if (StringUtils.isNoneBlank(sourcePid)) {
|
||||||
myCounter.increment("sourcePid");
|
myCounter.increment("sourcePid");
|
||||||
queries.add(createPidValueQuery(pidTypePrefix.source, sourcePid));
|
queries.add(createPidValueQuery(RelationPrefix.source, sourcePid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNoneBlank(targetPidType)) {
|
if (StringUtils.isNoneBlank(targetPidType)) {
|
||||||
assert targetPidType != null;
|
assert targetPidType != null;
|
||||||
incrementPidCounter(pidTypePrefix.target,targetPidType);
|
incrementPidCounter(RelationPrefix.target,targetPidType);
|
||||||
queries.add(createPidTypeQuery(pidTypePrefix.target, targetPidType));
|
queries.add(createPidTypeQuery(RelationPrefix.target, targetPidType));
|
||||||
}
|
}
|
||||||
if (StringUtils.isNoneBlank(sourcePidType)) {
|
if (StringUtils.isNoneBlank(sourcePidType)) {
|
||||||
assert sourcePidType != null;
|
assert sourcePidType != null;
|
||||||
incrementPidCounter(pidTypePrefix.source,sourcePidType);
|
incrementPidCounter(RelationPrefix.source,sourcePidType);
|
||||||
queries.add(createPidTypeQuery(pidTypePrefix.source, sourcePidType));
|
queries.add(createPidTypeQuery(RelationPrefix.source, sourcePidType));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNoneBlank(targetType)) {
|
if (StringUtils.isNoneBlank(targetType)) {
|
||||||
if ("dataset".equalsIgnoreCase(targetType) || "publication".equalsIgnoreCase(targetType))
|
if ("dataset".equalsIgnoreCase(targetType) || "publication".equalsIgnoreCase(targetType))
|
||||||
myCounter.increment(String.format("targetType_%s", 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 (StringUtils.isNoneBlank(sourceType)) {
|
||||||
if ("dataset".equalsIgnoreCase(sourceType) || "publication".equalsIgnoreCase(sourceType)) {
|
if ("dataset".equalsIgnoreCase(sourceType) || "publication".equalsIgnoreCase(sourceType)) {
|
||||||
myCounter.increment(String.format("sourceType_%s", 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);
|
QueryBuilder result = createFinalQuery(queries);
|
||||||
|
@ -254,8 +314,4 @@ public class ScholixIndexManager {
|
||||||
return new ImmutablePair<>(tt,scholixRes.stream().map(SearchHit::getContent).collect(Collectors.toList()));
|
return new ImmutablePair<>(tt,scholixRes.stream().map(SearchHit::getContent).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package eu.dnetlib.scholix.api.model.v1;
|
package eu.dnetlib.scholix.api.model.v1;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import eu.dnetlib.dhp.schema.sx.scholix.ScholixEntityId;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ScholixCreator {
|
public class ScholixCreator {
|
||||||
|
|
||||||
|
@ -29,22 +29,11 @@ public class ScholixCreator {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public ScholixCreator setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
|
||||||
|
|
||||||
public ScholixCreator identifier(List<ScholixIdentifier> identifier) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScholixCreator addIdentifierItem(ScholixIdentifier identifierItem) {
|
|
||||||
if (this.identifier == null) {
|
|
||||||
this.identifier = new ArrayList<ScholixIdentifier>();
|
|
||||||
}
|
|
||||||
this.identifier.add(identifierItem);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get identifier
|
* Get identifier
|
||||||
|
@ -55,48 +44,26 @@ public class ScholixCreator {
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdentifier(List<ScholixIdentifier> identifier) {
|
public ScholixCreator setIdentifier(List<ScholixIdentifier> identifier) {
|
||||||
this.identifier = 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
|
if (provider.getIdentifiers()!= null && provider.getIdentifiers().size()>0)
|
||||||
public int hashCode() {
|
instance.setIdentifier(provider.getIdentifiers()
|
||||||
return Objects.hash(name, identifier);
|
.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 ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,9 @@ public class ScholixIdentifier {
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdentifier(String identifier) {
|
public ScholixIdentifier setIdentifier(String identifier) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScholixIdentifier Schema(String idScheme) {
|
public ScholixIdentifier Schema(String idScheme) {
|
||||||
|
@ -48,51 +49,23 @@ public class ScholixIdentifier {
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSchema(String schema) {
|
public ScholixIdentifier setSchema(String schema) {
|
||||||
this.schema = 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 ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
package eu.dnetlib.scholix.api.model.v1;
|
package eu.dnetlib.scholix.api.model.v1;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import eu.dnetlib.dhp.schema.sx.scholix.ScholixResource;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ScholixItem {
|
public class ScholixItem {
|
||||||
|
|
||||||
@JsonProperty("identifier")
|
@JsonProperty("identifiers")
|
||||||
private ScholixIdentifier identifier;
|
private List<ScholixIdentifier> identifiers;
|
||||||
|
|
||||||
@JsonProperty("objectType")
|
@JsonProperty("objectType")
|
||||||
private String objectType;
|
private String objectType;
|
||||||
|
@ -28,22 +30,18 @@ public class ScholixItem {
|
||||||
private String publicationDate;
|
private String publicationDate;
|
||||||
|
|
||||||
@JsonProperty("publisher")
|
@JsonProperty("publisher")
|
||||||
private ScholixProvider publisher;
|
private List<ScholixProvider> publisher;
|
||||||
|
|
||||||
public ScholixItem identifier(ScholixIdentifier identifier) {
|
@Schema(description = "The list of identifiers")
|
||||||
this.identifier = identifier;
|
public List<ScholixIdentifier> getIdentifiers() {
|
||||||
|
return identifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScholixItem setIdentifiers(List<ScholixIdentifier> identifiers) {
|
||||||
|
this.identifiers = identifiers;
|
||||||
return this;
|
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) {
|
public ScholixItem objectType(String objectType) {
|
||||||
this.objectType = objectType;
|
this.objectType = objectType;
|
||||||
return this;
|
return this;
|
||||||
|
@ -116,63 +114,48 @@ public class ScholixItem {
|
||||||
this.publicationDate = publicationDate;
|
this.publicationDate = publicationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Schema(description = "The name of the publisher of the object")
|
@Schema(description = "The list name of the publisher of the object")
|
||||||
public ScholixProvider getPublisher() {
|
public List<ScholixProvider> getPublisher() {
|
||||||
return publisher;
|
return publisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPublisher(ScholixProvider publisher) {
|
public ScholixItem setPublisher(List<ScholixProvider> publisher) {
|
||||||
this.publisher = 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
|
final ScholixItem result = new ScholixItem();
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(objectType, objectSubType, identifier, title, creator, publicationDate, publisher);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (input.getIdentifier()!= null)
|
||||||
public String toString() {
|
result.setIdentifiers(
|
||||||
StringBuilder sb = new StringBuilder();
|
input.getIdentifier().stream()
|
||||||
sb.append("class ScholixItemType {\n");
|
.map(ScholixIdentifier::fromScholixIdentifier)
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
|
||||||
sb.append(" objectType: ").append(toIndentedString(objectType)).append("\n");
|
result.setTitle(input.getTitle());
|
||||||
sb.append(" objectSubType: ").append(toIndentedString(objectSubType)).append("\n");
|
result.setObjectType(input.getObjectType());
|
||||||
sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n");
|
result.setObjectSubType(input.getObjectSubType());
|
||||||
sb.append(" title: ").append(toIndentedString(title)).append("\n");
|
result.setPublicationDate(input.getPublicationDate());
|
||||||
sb.append(" creator: ").append(toIndentedString(creator)).append("\n");
|
if(input.getPublisher()!= null)
|
||||||
sb.append(" publicationDate: ").append(toIndentedString(publicationDate)).append("\n");
|
result.setPublisher(input.getPublisher().stream()
|
||||||
sb.append(" publisher: ").append(toIndentedString(publisher)).append("\n");
|
.map(ScholixProvider::fromScholixEntityId)
|
||||||
sb.append("}");
|
.collect(Collectors.toList())
|
||||||
return sb.toString();
|
);
|
||||||
}
|
|
||||||
|
|
||||||
|
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 ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,36 @@
|
||||||
package eu.dnetlib.scholix.api.model.v1;
|
package eu.dnetlib.scholix.api.model.v1;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import eu.dnetlib.dhp.schema.sx.scholix.ScholixEntityId;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ScholixProvider {
|
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")
|
@JsonProperty("name")
|
||||||
private String name = null;
|
private String name = null;
|
||||||
|
|
||||||
|
@ -32,8 +53,9 @@ public class ScholixProvider {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public ScholixProvider setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScholixProvider identifier(List<ScholixIdentifier> identifier) {
|
public ScholixProvider identifier(List<ScholixIdentifier> identifier) {
|
||||||
|
@ -59,8 +81,9 @@ public class ScholixProvider {
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdentifier(List<ScholixIdentifier> identifier) {
|
public ScholixProvider setIdentifier(List<ScholixIdentifier> identifier) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static eu.dnetlib.scholix.api.model.v2.RelationshipType.relationMapping;
|
||||||
|
|
||||||
public class ScholixRelationship {
|
public class ScholixRelationship {
|
||||||
|
|
||||||
@JsonProperty("name")
|
@JsonProperty("name")
|
||||||
|
@ -116,4 +118,17 @@ public class ScholixRelationship {
|
||||||
return o.toString().replace("\n", "\n ");
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ScholixV1 implements Serializable {
|
public class ScholixV1 implements Serializable {
|
||||||
|
|
||||||
|
@ -161,6 +162,23 @@ public class ScholixV1 implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
public static ScholixV1 fromScholix(Scholix input) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class RelationshipType {
|
||||||
private String subTypeSchema;
|
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" },
|
{ "issupplementto", "IsSupplementTo" },
|
||||||
{ "issupplementedby", "IsSupplementedBy" },
|
{ "issupplementedby", "IsSupplementedBy" },
|
||||||
{ "references", "References" },
|
{ "references", "References" },
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package eu.dnetlib.scholix.test;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
|
public class QueryTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void featureToTest() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue