Skip to content
Snippets Groups Projects
Commit 60029fdd authored by alangrafu's avatar alangrafu
Browse files

Fixed bugs in modules

Service now return 406 if service exists but the content type is not
supported

Fixed use of previously returned values in classModule

Adding new format for ref:Resource

Delete old format
parent bf61fc58
No related branches found
No related tags found
No related merge requests found
Showing
with 86 additions and 63 deletions
......@@ -6,7 +6,7 @@ class SpecialFunction extends AbstractSpecialFunction{
protected function getFunction($uri){
global $conf;
$count = 1;
$prefixUri = $conf['basedir'].$conf['special']['uri']."/";
$prefixUri = $conf['basedir'];
$aux = str_replace($prefixUri, '', $uri, $count);
$functionAndParams = explode('/', $aux);
return $functionAndParams[0];
......@@ -15,7 +15,7 @@ class SpecialFunction extends AbstractSpecialFunction{
protected function getParams($uri){
global $conf;
$count = 1;
$prefixUri = $conf['basedir'].$conf['special']['uri'];
$prefixUri = $conf['basedir'];
$functionAndParams = explode('/', str_replace($prefixUri, '', $uri, $count));
if(sizeof($functionAndParams) > 1){
array_shift($functionAndParams);
......@@ -38,10 +38,10 @@ class SpecialFunction extends AbstractSpecialFunction{
$extension = Utils::getExtension($acceptContentType);
$args = array();
try{
$viewFile = $conf['special']['uri'].".".$f.$conf['view']['extension'].".".$extension;
$modelFile = $conf['special']['uri'].".".$f.$conf['model']['extension'].".".$extension;
$viewFile = $conf['service']['prefix'].$f."/".$extension.".template";
$modelFile = $conf['service']['prefix'].$f."/".$extension.".queries";
if(!(is_dir($conf['model']['directory'].$modelFile) || is_file($conf['model']['directory'].$modelFile))){
$msg = '<h1>Method does not exist!</h1><br/>This means that <tt>'.$conf['model']['directory'].$modelFile."</tt> doesn't exist.<br/>Please refer to this tutorial to create one.<br/>";
$msg = '<h1>Method does not exist!</h1><br/>This means that <tt>'.$modelFile."</tt> doesn't exist.<br/>Please refer to this tutorial to create one.<br/>";
throw new Exception($msg);
}
if(!is_file($conf['view']['directory'].$viewFile)){
......
......@@ -18,7 +18,7 @@ class Utils{
public static function send406($uri){
header("HTTP/1.0 406 Not Acceptable");
echo "I can't find a representation suitable for the content type you accept\n\n";
echo "LODSPeaKr can't find a representation suitable for the content type you accept\n\n";
exit(0);
}
......@@ -287,7 +287,8 @@ class Utils{
global $first;
$uri = $base['this']['value'];
$data = array();
$strippedModelFile = str_replace('.query', '',$modelFile);
if(!is_dir($modelFile)){
require_once($conf['home'].'lib/Haanga/lib/Haanga.php');
......@@ -315,25 +316,25 @@ class Utils{
echo $query;
}
trigger_error("Running query on endpoint", E_USER_NOTICE);
$aux = $e->query($query, Utils::getResultsType($query));
$aux = $e->query($query, Utils::getResultsType($query));
if($modelFile != $base['type']){
if(!isset($rPointer[$modelFile])){
$rPointer[$modelFile] = array();
$first[$modelFile] = array();
if(!isset($rPointer[$strippedModelFile])){
$rPointer[$strippedModelFile] = array();
$first[$strippedModelFile] = array();
}
if(Utils::getResultsType($query) == $conf['output']['select']){
$rPointer[$modelFile] = Utils::sparqlResult2Obj($aux);
$fPointer[$modelFile] = $rPointer[$modelFile][0];
$rPointer[$strippedModelFile] = Utils::sparqlResult2Obj($aux);
$fPointer[$strippedModelFile] = $rPointer[$strippedModelFile][0];
/*if(sizeof($rPointer)>0){
$rPointer[$modelFile]['first'] = $rPointer[$modelFile][0];
}*/
}else{
$rPointer[$modelFile] = $aux;
$rPointer[$strippedModelFile] = $aux;
}
}else{
if(Utils::getResultsType($query) == $conf['output']['select']){
$rPointer = Utils::sparqlResult2Obj($aux);
$fPointer[$modelFile] = $rPointer[0];
$fPointer[$strippedModelFile] = $rPointer[0];
/*if(sizeof($rPointer)>0){
$rPointer['first'] = $rPointer[0];
}*/
......@@ -342,12 +343,12 @@ class Utils{
}
}
}else{
trigger_error("$modelFile is a directory, will process it later", E_USER_NOTICE);
trigger_error("$modelFile is a directory, will process it later", E_USER_NOTICE);
if($modelFile != $base['type']){
if(!isset($rPointer[$modelFile])){
$rPointer[$modelFile] = array();
if(!isset($rPointer[$strippedModelFile])){
$rPointer[$strippedModelFile] = array();
}
Utils::queryDir($modelFile, $rPointer[$modelFile], $fPointer[$modelFile]);
Utils::queryDir($modelFile, $rPointer[$strippedModelFile], $fPointer[$strippedModelFile]);
}else{
Utils::queryDir($modelFile, $rPointer, $fPointer);
}
......@@ -409,7 +410,7 @@ class Utils{
unset($base['first']);
$vars = compact('base', 'r', 'first');
if($conf['debug']){
var_dump($vars);
var_dump($r);
}
if(is_file($base['view']['directory'].$view)){
Haanga::Load($view, $vars);
......
......@@ -32,8 +32,8 @@ $conf['http_accept']['json'] = array('application/json', 'application/x-javascri
$conf['http_accept']['nt'] = array('text/plain');
$conf['special']['uri'] = 'special';
$conf['special']['class'] = 'classes/BasicSpecialFunction.php';
$conf['service']['prefix'] = 'service.';
$conf['service']['class'] = 'classes/BasicSpecialFunction.php';
//Frontpage when user goes to http://example.org/
$conf['root'] = 'index.html';
......
SELECT ?s2 ?p2 ?s1 ?p1 WHERE {
{
<{{uri}}> ?s1 ?p1 .
}UNION{
?s2 ?p2 <{{uri}}> .
}
}
DESCRIBE ?resource WHERE {
[] a ?resource .
}
DESCRIBE ?resource WHERE {
[] a ?resource .
}
DESCRIBE ?resource WHERE {
[] a ?resource .
}
DESCRIBE ?resource WHERE {
[] a ?resource .
}
SELECT ?s2 ?p2 ?s1 ?p1 WHERE {
{
<{{uri}}> ?s1 ?p1 .
}UNION{
?s2 ?p2 <{{uri}}> .
}
}
DESCRIBE <{{uri}}>
{%for h in base.header %}
PREFIX {{h.prefix}}: <{{h.ns}}>
{%endfor%}
SELECT DISTINCT ?resource WHERE {
?resource a {{base.args.arg0}} .
}
SELECT DISTINCT ?g WHERE {
GRAPH ?g{
?s ?p ?o .
}
}
......@@ -38,6 +38,8 @@ class ClassModule extends abstractModule{
global $acceptContentType;
global $endpoints;
global $base;
global $results;
global $first;
list($res, $page, $format) = $pair;
//If resource is not the page, send a 303 to the document
if($res == $localUri){
......@@ -75,7 +77,7 @@ class ClassModule extends abstractModule{
chdir($conf['home'].$conf['model']['directory']);
// echo $conf['home'].$conf['model']['directory'].$modelFile;exit(0);
Utils::queryFile($modelFile, $endpoints['local'], $results, $first);
$results = Utils::internalize($results);
......@@ -92,17 +94,14 @@ class ClassModule extends abstractModule{
private static function getModelandView($t, $extension){
global $conf;
global $results;
global $rPointer;
//Defining default views and models
$curieType="";
$modelFile = $conf['model']['default'].$conf['model']['extension'].".".$extension;
$viewFile = $conf['view']['default'].$conf['view']['extension'].".".$extension;
$modelFile = 'class.rdfs:Resource/'.$extension.'.queries';
$viewFile = 'class.rdfs:Resource/'.$extension.'.template';
//Get the first class available
/* TODO: Allow user to priotize
* which class should be used
* Example: URI is foaf:Person and ex:Student
* If both, prefer ex:Student
*/
$typesAndValues = array();
foreach($t as $v){
$curie = Utils::uri2curie($v);
......
......@@ -4,18 +4,40 @@ class ServiceModule extends abstractModule{
//Service module
public function match($uri){
global $conf;
return preg_match("|^".$conf['basedir'].$conf['special']['uri']."|", $uri);
global $conf;
global $acceptContentType;
$q = preg_replace('|^'.$conf['basedir'].'|', '', $uri);
$qArr = explode('/', $q);
if(sizeof($qArr)==0){
return FALSE;
}
$extension = Utils::getExtension($acceptContentType);
$auxViewFile = $conf['home'].$conf['view']['directory'].$conf['service']['prefix'].$qArr[0]."/".$extension.".template";
$auxModelFile = $conf['home'].$conf['model']['directory'].$conf['service']['prefix'].$qArr[0]."/".$extension.".queries";
if(is_dir($auxModelFile) && is_file($auxViewFile)){
return $uri;// $qArr[0];
}
$auxViewFile = $conf['home'].$conf['view']['directory'].$conf['service']['prefix'].$qArr[0];
$auxModelFile = $conf['home'].$conf['model']['directory'].$conf['service']['prefix'].$qArr[0];
if(is_dir($auxModelFile) && is_dir($auxViewFile)){
Utils::send406($uri);// $qArr[0];
}
if(is_dir($auxModelFile) && is_file($auxViewFile)){
return $uri;// $qArr[0];
}
return FALSE;
}
public function execute($pair){
public function execute($service){
global $conf;
global $localUri;
global $uri;
global $acceptContentType;
global $endpoints;
global $base;
require_once($conf['home'].$conf['special']['class']);
require_once($conf['home'].$conf['service']['class']);
$context = array();
$context['contentType'] = $acceptContentType;
$context['endpoints'] = $endpoints;
......
......@@ -11,32 +11,32 @@
<link rel="alternate" type="text/plain" title="N-Triples Version" href="{{base.this.value}}.nt" />
<link rel="alternate" type="application/json" title="RDFJSON Version" href="{{base.this.value}}.json" />
</head>
<body about="{{base.this.value}}">
<body about="{{base.this.value}}">
<h1>Page about <a href='{{base.this.value}}'>{{base.this.curie}}</a></h1>
<div>
<h2>Information from {{base.this.curie}}</h2>
<table>
{% for row in r %}
<table>
{% for row in r.main %}
{% if row.s1%}
<tr>
<td><a href='{{row.s1.value}}'>{{row.s1.curie}}</a></td>
{% if row.p1.uri == 1 %}
<td><a rel='{{row.s1.curie}}' href='{{row.p1.value}}'>{{row.p1.curie}}</a></td>
{% else %}
<td><span property='{{row.s1.curie}}'>{{row.p1.value}}</span></td>
{% endif %}
</tr>
{% endif %}
{% endfor %}
</table>
<br/><br/>
<h2>Information pointing to {{base.this.curie}}</h2>
<table>
{% for row in r %}
<table>
{% for row in r.main %}
{% if row.s2%}
<tr>
<td><a href='{{row.s2.value}}'>{{row.s2.curie}}</a></td>
......@@ -48,4 +48,3 @@
</div>
</body>
</html>
{{r.main|safe}}
{{r.main|safe}}
{{r|safe}}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment