Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package es.weso.rdfshape.server.api.routes.endpoint.logic

import cats.data.EitherT
import cats.effect.IO
import cats.implicits.catsSyntaxEitherId
import com.typesafe.scalalogging.LazyLogging
import es.weso.rdf.RDFReader
import es.weso.rdf.jena.{Endpoint => EndpointJena}
Expand Down Expand Up @@ -65,17 +65,17 @@ private[api] object Endpoint extends LazyLogging {
*/
def getEndpointUrl(
partsMap: PartsMap
): EitherT[IO, String, URL] = for {
maybeStr <- EitherT.liftF[IO, String, Option[String]](
partsMap.optPartValue("endpoint")
)
ep <- maybeStr match {
case None =>
EitherT.leftT[IO, URL](s"No value provided for parameter endpoint")
case Some(str) =>
Try(new URL(str)) match {
case Success(url) => EitherT.rightT[IO, String](url)
case Failure(ex) => EitherT.leftT[IO, URL](ex.getMessage)
): IO[Either[String, URL]] = for {
maybeStr <- partsMap.optPartValue("endpoint").map(_.toRight(""))

ep = maybeStr match {
case Left(_) =>
val msg = s"No value provided for parameter endpoint"
msg.asLeft[URL]
case Right(endpointStr) =>
Try(new URL(endpointStr)) match {
case Success(url) => url.asRight[String]
case Failure(ex) => ex.getMessage.asLeft[URL]
}
}
} yield ep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import es.weso.rdfshape.server.api.definitions.ApiDefinitions.api
import es.weso.rdfshape.server.api.routes.ApiService
import es.weso.rdfshape.server.api.routes.endpoint.logic.Endpoint.{
getEndpointAsRDFReader,
getEndpointInfo,
getEndpointUrl
}
import es.weso.rdfshape.server.api.routes.endpoint.logic.EndpointStatus._
import es.weso.rdfshape.server.api.routes.endpoint.logic.Outgoing
import es.weso.rdfshape.server.api.routes.endpoint.logic.Outgoing.getOutgoing
import es.weso.rdfshape.server.api.routes.endpoint.logic.query.SparqlQuery
import es.weso.rdfshape.server.api.routes.endpoint.logic.query.SparqlQuery.mkSparqlQuery
import es.weso.rdfshape.server.api.routes.endpoint.logic.{Endpoint, Outgoing}
import es.weso.rdfshape.server.api.utils.parameters.IncomingRequestParameters.{
EndpointParameter,
LimitParameter,
Expand Down Expand Up @@ -56,12 +54,14 @@ class EndpointService(client: Client[IO])
* - results [Object]: Query results
* - bindings: [Array]: Query results, each item being an object mapping each variable to its value
*/
/**
*/
case req @ POST -> Root / `api` / `verb` / "query" =>
req.decode[Multipart[IO]] { m =>
val partsMap = PartsMap(m.parts)

val r: EitherT[IO, String, Json] = for {
endpointUrl <- getEndpointUrl(partsMap)
endpointUrl <- EitherT(getEndpointUrl(partsMap))
endpoint <- getEndpointAsRDFReader(endpointUrl)
either <- EitherT
.liftF[IO, String, Either[
Expand All @@ -73,7 +73,6 @@ class EndpointService(client: Client[IO])
eitherQuery <- EitherT.fromEither[IO](either)

json <- {

eitherQuery.rawQuery.fold(
err => EitherT.left(IO.pure(err)),
raw => {
Expand All @@ -97,37 +96,6 @@ class EndpointService(client: Client[IO])
} yield resp
}

/** Attempt to contact an endpoint and return metadata about it.
* Receives a JSON object with the input endpoint:
* - endpoint [String]: Target endpoint
* Returns a JSON object with the endpoint response:
* - head [Object]: Query metadata
* - vars: [Array]: Query variables
* - results [Object]: Query results
* - bindings: [Array]: Query results, each item being an object mapping each variable to its value
*/
case req @ POST -> Root / `api` / `verb` / "info" =>
req.decode[Multipart[IO]] { m =>
val partsMap = PartsMap(m.parts)
for {
endpointUrl <- getEndpointUrl(partsMap).value
response <- endpointUrl match {
case Left(err) => errorResponseJson(err, BadRequest)
case Right(endpointUrl) =>
val endpointInfo = getEndpointInfo(endpointUrl)
endpointInfo match {
case Endpoint(errMsg, OFFLINE) =>
errorResponseJson(
errMsg,
InternalServerError
)
case _ => Ok(endpointInfo.asJson)
}
}
} yield response

}

/** Attempt to contact a wikibase endpoint and return the data (triplets) about a node in it.
* Receives a JSON object with the input endpoint, node and limits:
* - endpoint [String]: Target endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,13 @@ private[wikibase] case class WikibaseSchemaExtract(
.fromString(strRdf, Turtle.name)
.flatMap(
_.use(rdf =>
for {
rdfSerialized <- rdf.serialize(Turtle.name)
nodeSelector = RDFNodeSelector(IRI(entityUri))
inferred <- SchemaInfer.runInferSchema(
rdf,
nodeSelector,
Schemas.shEx.name,
IRI(s"http://example.org/Shape_${wdEntity.localName}"),
InferOptions.defaultOptions.copy(maxFollowOn = 3)
)
} yield inferred
SchemaInfer.runInferSchema(
rdf,
RDFNodeSelector(IRI(entityUri)),
Schemas.shEx.name,
IRI(s"http://example.org/Shape_${wdEntity.localName}"),
InferOptions.defaultOptions.copy(maxFollowOn = 3)
)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class WikibaseService(client: Client[IO])
} yield response
}

// TODO: Needs exhaustive testing and client changes
// TODO: Needs exhaustive testing. Timeouts.
/** Attempts to extract an schema (ShEx) from a given entity present in wikidata
* using SheXer. See [[https://github.com/DaniFdezAlvarez/shexer]].
* Receives an entity URI as payload.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ object NetworkingUtils extends LazyLogging {
def getUrlContents(urlString: String): Either[String, String] = {
Try {
val url = new URL(urlString)
getUrlContents(url)
} match {
case Failure(exception) => Left(exception.getMessage)
case Success(value) => value
}
}

def getUrlContents(url: URL): Either[String, String] = {
Try {
val src = Source.fromURL(url)
val str = src.mkString
src.close()
Expand All @@ -24,7 +33,7 @@ object NetworkingUtils extends LazyLogging {
case Success(urlContent) => Right(urlContent)
case Failure(exception) =>
val msg =
s"Could not obtain data from url $urlString."
s"Could not obtain data from url $url."
logger.warn(s"$msg - ${exception.getMessage}")
Left(msg)
}
Expand Down

This file was deleted.

Binary file modified website/static/favicon.ico
Binary file not shown.