1
|
from fastapi import FastAPI, Query,HTTPException
|
2
|
from pydantic import BaseModel, Schema
|
3
|
from typing import Dict, List
|
4
|
from v3.responseModel import *
|
5
|
from eu.dnetlib.ScholixConnector import ScholixConnector
|
6
|
from datetime import datetime
|
7
|
import time
|
8
|
import logging
|
9
|
|
10
|
|
11
|
subapi_v3 = FastAPI(title="Scholexplorer API 3.0",
|
12
|
version="3.0.0",
|
13
|
description="scholexplorer API version 3.0",openapi_prefix="/v3", docs_url="/ui/")
|
14
|
|
15
|
req_fields = ['sourcePid', 'targetPid', 'sourcePublisher', 'targetPublisher', 'linkProvider']
|
16
|
|
17
|
@subapi_v3.get("/LinkProvider", response_model=List[LinkProvider], tags=['LinkProvider : Operation related to the Link Provider'], description="Return a list of link provider and relative number of relations",summary="Get All Link Providers")
|
18
|
def linkProvider(name: str = Query(None, title="name", description="Filter the link provider by a name")):
|
19
|
s = ScholixConnector()
|
20
|
|
21
|
return s.list_datasources(name)
|
22
|
|
23
|
@subapi_v3.get("/LinkPublisher/inSource", response_model=List[LinkPublisher],
|
24
|
tags=['LinkPublisher : Operation related to the Link Publisher'],
|
25
|
description="Return a List of all Publishers that provide source objects in Scholix links and the total number of links where the source object comes from this publisher",
|
26
|
summary="Get All Publishers that provide source object")
|
27
|
def linkPublisherInSource(name: str = Query(None, title="name", description="Filter the link publisher by a name")):
|
28
|
s = ScholixConnector()
|
29
|
return s.list_publisher('source',name)
|
30
|
|
31
|
@subapi_v3.get("/LinkPublisher/inTarget", response_model=List[LinkPublisher],
|
32
|
tags=['LinkPublisher : Operation related to the Link Publisher'],
|
33
|
description="Return a List of all Publishers that provide target objects in Scholix links and the total number of links where the target object comes from this publisher",
|
34
|
summary="Get All Publishers that provide target object")
|
35
|
def linkPublisherInTarget(name: str = Query(None, title="name", description="Filter the link publisher by a name")):
|
36
|
s = ScholixConnector()
|
37
|
return s.list_publisher('target',name)
|
38
|
|
39
|
|
40
|
@subapi_v3.get("/Links", response_model=PageResultType, tags=['Links : Operation related to the Scholix Links'],
|
41
|
response_description="A list of List of scholix Links following the schema <a href='https://github.com/scholix/schema/tree/master/json/v3/schema.json'>https://github.com/scholix/schema/tree/master/json/v3/schema.json</a>",
|
42
|
description="""Return a List of scholix Links, this method <b>require one of the following parameters </b> (<b>sourcePid, targetPid, sourcePublisher,\
|
43
|
\ targetPublisher, linkProvider</b>) all parameters can be combined""",summary="Get Scholix Links")
|
44
|
def links(
|
45
|
linkProvider: str = Query(None, title="linkProvider", description="Filter Scholix relationships collected from a LinkProvider"),
|
46
|
targetPid: str = Query(None, title="targetPid", description="Filter Scholix relationships having a target pid"),
|
47
|
targetPublisher: str = Query(None, title="targetPublisher", description="Filter Scholix relationships having a target published in a Publisher named targetPublisher"),
|
48
|
targetPidType: str = Query(None, title="targetPidType", description="Filter Scholix relationships having a target pid type"),
|
49
|
targetType: str = Query(None, title="targetType", description="Filter Scholix relationships having a target type (literature, dataset, unknown)"),
|
50
|
sourceType: str = Query(None, title="sourceType", description="Filter Scholix relationships having a source type (literature, dataset, unknown)"),
|
51
|
sourcePid: str = Query(None, title="sourcePid", description="Filter Scholix relationships having a source pid"),
|
52
|
sourcePublisher: str = Query(None, title="sourcePublisher", description="Filter Scholix relationships having a source published in a Publisher named sourcePublisher"),
|
53
|
sourcePidType: str = Query(None, title="sourcePidType", description="Filter Scholix relationships having a source pid type"),
|
54
|
harvestedAfter: str = Query(None, title="harvestedAfter", description="Filter scholix Links having collected after this date"),
|
55
|
page:int= Query(None, title="page", description="select page of result"),
|
56
|
):
|
57
|
|
58
|
log = logging.getLogger("scholexplorer")
|
59
|
|
60
|
log.debug("request Link page")
|
61
|
if not (sourcePid or targetPid or sourcePublisher or targetPublisher or linkProvider):
|
62
|
raise HTTPException(status_code=400,detail='The method requires one of the following parameters: sourcePid, targetPid, sourcePublisher, targetPublisher, linkProvider')
|
63
|
|
64
|
s = ScholixConnector()
|
65
|
m_page = 0
|
66
|
if page:
|
67
|
m_page= page*100
|
68
|
|
69
|
return create_response(s.links(provider = linkProvider, s_pid=sourcePid, t_pid=targetPid, s_publisher=sourcePublisher,
|
70
|
t_publisher=targetPublisher, s_pid_type=sourcePidType,
|
71
|
t_pid_type=targetPidType, page=m_page, target_Type=targetType, source_Type=sourceType),m_page, sourcePid,targetPid)
|
72
|
|