2022-02-02 14:23:28 +01:00
package eu.dnetlib.scholix.api.controller ;
import eu.dnetlib.common.controller.AbstractDnetController ;
2022-02-14 09:16:37 +01:00
import eu.dnetlib.dhp.schema.sx.scholix.Scholix ;
import eu.dnetlib.scholix.api.ScholixException ;
import eu.dnetlib.scholix.api.index.ScholixIndexManager ;
2022-02-28 14:26:55 +01:00
import eu.dnetlib.dhp.schema.sx.api.model.v1.ScholixV1 ;
2022-02-14 09:16:37 +01:00
import io.micrometer.core.annotation.Timed ;
2022-02-02 14:23:28 +01:00
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 io.swagger.v3.oas.annotations.media.Schema ;
2022-02-14 09:16:37 +01:00
import org.apache.commons.lang3.tuple.Pair ;
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.RequestParam ;
import org.springframework.web.bind.annotation.RestController ;
import javax.validation.constraints.NotNull ;
import java.util.ArrayList ;
import java.util.List ;
2022-02-14 09:16:37 +01:00
import java.util.stream.Collectors ;
2022-02-02 14:23:28 +01:00
@RestController
@RequestMapping ( " /v1 " )
2022-02-14 09:16:37 +01:00
@Api ( tags = { " Scholix " } )
2022-02-02 14:23:28 +01:00
public class ScholixControllerV1 extends AbstractDnetController {
2022-02-14 09:16:37 +01:00
@Autowired
ScholixIndexManager manager ;
2022-02-02 14:23:28 +01:00
@Operation (
summary = " Get all Scholix relation collected from a publisher " ,
description = " return a list of scholix object published from a specific publisher "
)
@GetMapping ( " /linksFromPublisher " )
2022-02-14 09:16:37 +01:00
@Timed ( value = " scholix.v1.linksFromPublisher " , description = " Time taken to return links on Version 1.0 of Scholix collected from a publisher " )
2022-02-02 14:23:28 +01:00
public List < ScholixV1 > linksFromPublisher (
@Parameter (
in = ParameterIn . QUERY ,
description = " Filter Scholix relationships collected from a publisher " ,
schema = @Schema ( ) , required = true ) String publisher ,
@Parameter ( in = ParameterIn . QUERY ,
description = " The page number " ) @RequestParam ( required = false ) Integer page
2022-02-14 09:16:37 +01:00
) throws ScholixException {
final int currentPage = page ! = null ? page : 0 ;
2022-02-02 14:23:28 +01:00
2022-02-14 09:16:37 +01:00
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 ( ) ) ;
2022-02-02 14:23:28 +01:00
}
@Operation (
summary = " Get all Scholix relation collected from a datasource " ,
description = " return a list of scholix object collected from a specific datasource "
)
@GetMapping ( " /linksFromDatasource " )
2022-02-14 09:16:37 +01:00
@Timed ( value = " scholix.v1.linksFromDatasource " , description = " Time taken to return links on Version 1.0 of Scholix collected from a LinkProvider " )
2022-02-02 14:23:28 +01:00
public List < ScholixV1 > linksFromDatasource (
@Parameter (
in = ParameterIn . QUERY ,
description = " Filter Scholix relationships collected from a LinkProvider " ,
schema = @Schema ( ) ) @NotNull String datasource ,
@Parameter ( in = ParameterIn . QUERY ,
description = " The page number " ) @RequestParam ( required = false ) Integer page
2022-02-14 09:16:37 +01:00
) throws ScholixException {
2022-02-02 14:23:28 +01:00
2022-02-14 09:16:37 +01:00
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 ( ) ) ;
2022-02-02 14:23:28 +01:00
}
@Operation (
summary = " Retrieve all scholix links from a persistent identifier " ,
description = " The linksFromPid endpoint returns a list of scholix object related from a specific persistent identifier "
)
@GetMapping ( " /linksFromPid " )
2022-02-14 09:16:37 +01:00
@Timed ( value = " scholix.v1.linksFromPid " , description = " Time taken to return links on Version 1.0 of Scholix related from a specific persistent identifier " )
2022-02-02 14:23:28 +01:00
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 ,
@Parameter ( in = ParameterIn . QUERY , description = " typology target filter should be publication, dataset or unknown " ) @RequestParam ( required = false ) String typologyTarget ,
@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
2022-02-14 09:16:37 +01:00
) throws ScholixException {
2022-02-02 14:23:28 +01:00
2022-02-14 09:16:37 +01:00
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 ( ) ) ;
2022-02-02 14:23:28 +01:00
}
}