2022-02-02 14:23:28 +01:00
|
|
|
package eu.dnetlib.scholix.api.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import eu.dnetlib.common.controller.AbstractDnetController;
|
2022-02-28 14:26:55 +01:00
|
|
|
import eu.dnetlib.dhp.schema.sx.api.model.v2.PageResultType;
|
|
|
|
import eu.dnetlib.dhp.schema.sx.api.model.v2.ScholixType;
|
2022-02-14 09:16:37 +01:00
|
|
|
import eu.dnetlib.dhp.schema.sx.scholix.Scholix;
|
2022-02-08 09:57:45 +01:00
|
|
|
import eu.dnetlib.scholix.api.ScholixException;
|
2022-02-07 16:36:26 +01:00
|
|
|
import eu.dnetlib.scholix.api.index.ScholixIndexManager;
|
2022-02-04 15:52:49 +01:00
|
|
|
import io.micrometer.core.annotation.Timed;
|
2022-02-02 14:23:28 +01:00
|
|
|
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;
|
2022-02-08 09:57:45 +01:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2022-02-07 16:36:26 +01:00
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
2022-02-04 15:52:49 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2022-02-02 14:23:28 +01:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
2022-02-07 16:36:26 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
2022-02-02 14:23:28 +01:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/v2")
|
|
|
|
@Api(tags = {
|
|
|
|
"Links : Operation related to the Scholix Links"
|
|
|
|
})
|
|
|
|
public class ScholixControllerV2 extends AbstractDnetController {
|
|
|
|
|
2022-02-04 15:52:49 +01:00
|
|
|
@Autowired
|
2022-02-07 16:36:26 +01:00
|
|
|
private ScholixIndexManager manager;
|
2022-02-04 15:52:49 +01:00
|
|
|
|
|
|
|
@Timed(value = "scholix.v2.links", description = "Time taken to return links on Version 2.0 of Scholix")
|
2022-02-02 14:23:28 +01:00
|
|
|
@ApiOperation("Get Scholix Links")
|
|
|
|
@GetMapping("/Links")
|
|
|
|
public PageResultType links(
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter Scholix relationships collected from a LinkProvider") String linkProvider,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter Scholix relationships having a target pid") String targetPid,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter Scholix relationships having a target pid type") String targetPidType,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter Scholix relationships having a target published in a Publisher named targetPublisher") String targetPublisher,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter Scholix relationships having a target type (literature, dataset, unknown)") String targetType,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter Scholix relationships having a source pid") String sourcePid,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter Scholix relationships having a source pid type") String sourcePidType,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter Scholix relationships having a source published in a Publisher named sourcePublisher") String sourcePublisher,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter Scholix relationships having a source type (literature, dataset, unknown)") String sourceType,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
|
|
|
description = "Filter scholix Links having collected after this date") String harvestedAfter,
|
|
|
|
@Parameter(in = ParameterIn.QUERY,
|
2022-02-04 15:52:49 +01:00
|
|
|
description = "select page of result") Integer page) throws Exception {
|
|
|
|
|
2022-02-08 09:57:45 +01:00
|
|
|
if (StringUtils.isEmpty(sourcePid) && StringUtils.isEmpty(targetPid) && StringUtils.isEmpty(sourcePublisher)&& StringUtils.isEmpty(targetPublisher)&& StringUtils.isEmpty(linkProvider))
|
|
|
|
throw new ScholixException("The method requires one of the following parameters: sourcePid, targetPid, sourcePublisher, targetPublisher, linkProvider");
|
|
|
|
|
|
|
|
try {
|
|
|
|
final int currentPage = page != null ? page : 0;
|
2022-02-14 09:16:37 +01:00
|
|
|
Pair<Long, List<Scholix>> scholixResult = manager.linksFromPid( linkProvider, targetPid, targetPidType, targetPublisher, targetType, sourcePid, sourcePidType, sourcePublisher, sourceType, harvestedAfter, currentPage);
|
2022-02-08 09:57:45 +01:00
|
|
|
final PageResultType pageResult = new PageResultType();
|
|
|
|
pageResult.setTotalPages(scholixResult.getLeft().intValue() / 10);
|
|
|
|
pageResult.setTotalLinks(scholixResult.getLeft().intValue());
|
|
|
|
pageResult.setResult(scholixResult.getRight().stream().map(ScholixType::fromScholix).collect(Collectors.toList()));
|
|
|
|
return pageResult;
|
|
|
|
} catch (Throwable e) {
|
|
|
|
throw new ScholixException("Error on requesting url ", e);
|
|
|
|
}
|
2022-02-02 14:23:28 +01:00
|
|
|
}
|
|
|
|
}
|