Skip to content
Open
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
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"

######################
#### RDF SETTINGS ####
######################
SPARQL_ENDPOINT='https://idsm.elixir-czech.cz/sparql/endpoint/molmedb'
SPARQL_QUERY_PREFIX='?query='
DB_RDF_PREFIX='https://rdf.molmedb.upol.cz/'
17 changes: 17 additions & 0 deletions app/Helpers/SPARQLurl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
namespace App\Helpers;

class SPARQLurl {
public static function rdfDescribeUrl($rdf_suffix)
{
$ep = env('SPARQL_ENDPOINT');
$rdf_prefix = env('DB_RDF_PREFIX');
$sparql_prefix = env('SPARQL_QUERY_PREFIX');
$suffix = urldecode($rdf_suffix);

$fullUri = $rdf_prefix . ltrim($suffix, '/');
$query = rawurlencode('DESCRIBE <'.$fullUri.'>');
$uiUrl = $ep.$sparql_prefix.$query;
return $uiUrl;
}
}
38 changes: 38 additions & 0 deletions app/Http/Controllers/RdfController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Http\Controllers;

use App\Helpers\SPARQLurl;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;

class RdfController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}

/**
* return redirect to external SPARQL endpoint for RDF/Semantic queries
*/
public function simple_rdf($rdf_suffix)
{
// Validate the suffix after URL-decoding so we can return a custom
// status code when the suffix contains disallowed characters.
$decoded = urldecode($rdf_suffix);

// Allowed characters: letters, numbers, slash, dash, underscore and dot
$allowedPattern = '/^[A-Za-z0-9\/\-_.]+$/';
if (!preg_match($allowedPattern, $decoded)) {
return response()->json(['error' => 'Invalid RDF suffix'], 400);
}

$uiUrl = SPARQLurl::rdfDescribeUrl($rdf_suffix);
return redirect()->away($uiUrl, 303);

}
}
4 changes: 4 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\MethodController;
use App\Http\Controllers\ProteinController;
use App\Http\Controllers\PublicationController;
use App\Http\Controllers\RdfController;
use App\Http\Controllers\SearchController;
use App\Http\Controllers\StatsController;
use App\Http\Controllers\StructureController;
Expand Down Expand Up @@ -97,4 +98,7 @@
Route::get('/{identifier}/form/select/methods', 'formSelectMethods');
Route::get('/{identifier}/similarities', 'similarities');
});

Route::get('rdf/{rdf_suffix}', [RdfController::class, 'simple_rdf'])
->where('rdf_suffix', '.*');
});