Skip to content
Snippets Groups Projects
Commit 3082c4bf authored by alangrafu's avatar alangrafu
Browse files

Script to create /delete services and class modules

parent 46deda24
No related branches found
No related tags found
No related merge requests found
...@@ -60,7 +60,11 @@ $localUri = $uri; ...@@ -60,7 +60,11 @@ $localUri = $uri;
if($uri == $conf['basedir']){ if($uri == $conf['basedir']){
header('Location: '.$conf['root']); header('Location: '.$conf['root']);
exit(0); exit(0);
}elseif(preg_match("|^".$conf['basedir'].$conf['special']['uri']."|", $uri)){ }
//Service module
if(preg_match("|^".$conf['basedir'].$conf['special']['uri']."|", $uri)){
include_once($conf['special']['class']); include_once($conf['special']['class']);
$context = array(); $context = array();
$context['contentType'] = $acceptContentType; $context['contentType'] = $acceptContentType;
...@@ -69,6 +73,9 @@ if($uri == $conf['basedir']){ ...@@ -69,6 +73,9 @@ if($uri == $conf['basedir']){
$sp->execute($uri, $context); $sp->execute($uri, $context);
exit(0); exit(0);
} }
//End of Service module
//Class module
if($conf['mirror_external_uris']){ if($conf['mirror_external_uris']){
$uri = $conf['ns']['local'].$_GET['q']; $uri = $conf['ns']['local'].$_GET['q'];
$localUri = $conf['basedir'].$_GET['q']; $localUri = $conf['basedir'].$_GET['q'];
...@@ -135,6 +142,6 @@ if(is_array($results)){ ...@@ -135,6 +142,6 @@ if(is_array($results)){
$resultsObj = $results; $resultsObj = $results;
} }
Utils::processDocument($viewFile, $base, $resultsObj); Utils::processDocument($viewFile, $base, $resultsObj);
//}
//end of Class module
?> ?>
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
formats=( html rdf ttl nt json all )
operations=( create delete )
modules=( class service uri )
currentOperation=
currentFormat=
currentModule=
if [[ ${operations[@]} =~ $1 ]]
then
currentOperation=$1
else
echo "Operation \"$1\" not valid"
exit 1
fi
if [[ ${modules[@]} =~ $2 ]]
then
currentModule=$2
else
echo "Module \"$2\" not valid"
exit 1
fi
if [[ ${formats[@]} =~ $4 ]]
then
currentFormat=$4
else
echo "Format \"$4\" not valid"
exit 1
fi
currentUnit=$3
if [[ $currentOperation == "create" ]]
then
$DIR/modules/create-$currentModule.sh "$currentUnit" "$currentFormat"
fi
if [[ $currentOperation == "delete" ]]
then
$DIR/modules/delete-$currentModule.sh "$currentUnit" "$currentFormat"
fi
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
initToken='class'
modelHtml=$(cat <<QUERY
SELECT ?s2 ?p2 ?s1 ?p1 WHERE {
{
<{{uri}}> ?s1 ?p1 .
}UNION{
?s2 ?p2 <{{uri}}> .
}
}
QUERY
)
viewHtml=$(cat <<VIEW
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}"
{%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
<head>
<title>Page about {{base.this.value}}</title>
<link href="{{base.baseUrl}}/lodspeakr/css/basic.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{base.this.value}}.rdf" />
<link rel="alternate" type="text/turtle" title="Turtle Version" href="{{base.this.value}}.ttl" />
<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}}">
<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.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.main %}
{% if row.s2%}
<tr>
<td><a href='{{row.s2.value}}'>{{row.s2.curie}}</a></td>
<td><a rev='[{{row.p2.curie}}]' href='{{row.s2.value}}'>{{row.p2.curie}}</a></td>
</tr>
{%endif %}
{% endfor %}
</table>
</div>
</body>
</html>
VIEW)
modelRdf=$(cat <<QUERY
DESCRIBE ?resource WHERE {
[] a ?resource .
}
QUERY)
viewRdf=$(cat <<VIEW
{{r|safe}}
VIEW)
modelTtl=$modelRdf
viewTtl=$viewRdf
modelNt=$modelRdf
viewNt=$viewRdf
modelJson=$modelRdf
viewJson=$viewJson
#Check models
mainModelDir=$DIR/../../models/$initToken.$1
if [ -e "$mainModelDir" ]
then
echo "WARNING: At least one model for $1 exists." >&2
else
mkdir $mainModelDir
fi
obj=( )
if [ "$2" == "all" ]
then
obj=( html rdf ttl nt json )
else
obj=( $2 )
fi
for i in ${obj[@]}
do
if [ -e $mainModelDir/$i.queries ]
then
echo ERROR: $initToken.$1/$i.queries exists in models. Operation aborted >&2
exit 1
fi
done
#Check views
mainViewDir=$DIR/../../views/$initToken.$1
if [ -e "$mainViewDir" ]
then
echo "WARNING: At least one view for $1 exists." >&2
else
mkdir $mainViewDir
fi
for i in ${obj[@]}
do
if [ -e $mainViewDir/$i.template ]
then
echo ERROR: $initToken.$1/$i already exist in views. Operation aborted >&2
exit 1
fi
done
#Create file structure
for i in ${obj[@]}
do
mkdir $mainModelDir/$i.queries
if [ "$i" == "html" ]
then
echo "$modelHtml" > $mainModelDir/$i.queries/main.query
echo "$viewHtml" > $mainViewDir/$i.template
else
echo "$modelRdf" > $mainModelDir/$i.queries/main.query
echo "$viewRdf" > $mainViewDir/$i.template
fi
done
echo $initToken.$1 created/modified successfully! >&2
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
initToken='service'
modelHtml=$(cat <<QUERY
{%for h in base.header %}
PREFIX {{h.prefix}}: <{{h.ns}}>
{%endfor%}
SELECT DISTINCT ?resource WHERE {
{%if base.args.arg0 %}GRAPH <{{base.args.arg0}}>{ {%endif%}
[] a ?resource .
{%if base.args.arg0 %} } {%endif%}
}
QUERY)
viewHtml=$(cat <<VIEW
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}"
{%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
<head>
<title>Classes available</title>
<link href="{{base.baseUrl}}/lodspeakr/css/basic.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<h1>Classes available</h1>
{%include "header.inc"%}
<ul>
{% for row in r %}
<li><a href="{{base.baseUrl}}special/instances/{{ row.resource.curie }}">{{row.resource.curie}}</a></li>
{% endfor %}
</ul>
</body>
</html>
VIEW)
modelRdf=$(cat <<QUERY
DESCRIBE ?resource WHERE {
[] a ?resource .
}
QUERY)
viewRdf=$(cat <<QUERY
{{r|safe}}
QUERY)
modelTtl=$modelRdf
viewTtl=$viewRdf
modelNt=$modelRdf
viewNt=$viewRdf
modelJson=$modelRdf
viewJson=$viewJson
#Check models
mainModelDir=$DIR/../../models/$initToken.$1
if [ -e "$mainModelDir" ]
then
echo "WARNING: At least one model for $1 exists." >&2
else
mkdir $mainModelDir
fi
obj=( )
if [ "$2" == "all" ]
then
obj=( html rdf ttl nt json )
else
obj=( $2 )
fi
for i in ${obj[@]}
do
if [ -e $mainModelDir/$i.queries ]
then
echo ERROR: $initToken.$1/$i.queries exists in models. Operation aborted >&2
exit 1
fi
done
#Check views
mainViewDir=$DIR/../../views/$initToken.$1
if [ -e "$mainViewDir" ]
then
echo "WARNING: At least one view for $1 exists." >&2
else
mkdir $mainViewDir
fi
for i in ${obj[@]}
do
if [ -e $mainViewDir/$i.template ]
then
echo ERROR: $initToken.$1/$i already exist in views. Operation aborted >&2
exit 1
fi
done
#Create file structure
for i in ${obj[@]}
do
mkdir $mainModelDir/$i.queries
if [ "$i" == "html" ]
then
echo "$modelHtml" > $mainModelDir/$i.queries/main.query
echo "$viewHtml" > $mainViewDir/$i.template
else
echo "$modelRdf" > $mainModelDir/$i.queries/main.query
echo "$viewRdf" > $mainViewDir/$i.template
fi
done
echo $initToken.$1 created/modified successfully! >&2
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
initToken='class'
#Check models
mainModelDir=$DIR/../../models/$initToken.$1
if [ ! -e "$mainModelDir" ]
then
echo "ERROR: $initToken.$1 doesn't exist in models. Operation aborted" >&2
exit 1
fi
obj=( )
if [ "$2" == "all" ]
then
obj=( html rdf ttl nt json )
else
obj=( $2 )
fi
for i in ${obj[@]}
do
if [ ! -e $mainModelDir/$i.queries ]
then
echo "WARNING: $initToken.$1/$i.query does not exists in models." >&2
fi
done
#Check views
mainViewDir=$DIR/../../views/$initToken.$1
if [ ! -e "$mainViewDir" ]
then
echo "ERROR: $initToken.$1 doesn't exist in views. Operation aborted." >&2
fi
for i in ${obj[@]}
do
if [ ! -e $mainViewDir/$i.template ]
then
echo "WARNING: $mainViewDir/$i.template doesn't exist in views." >&2
fi
done
#Delete file structure
if [ "$2" == "all" ]
then
rm -rf $mainModelDir
rm -rf $mainViewDir
else
for i in ${obj[@]}
do
rm -rf $mainModelDir/$i.queries
rm -rf $mainViewDir/$i.template
done
fi
echo $initToken.$1 deleted successfully! >&2
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
initToken='service'
#Check models
mainModelDir=$DIR/../../models/$initToken.$1
if [ ! -e "$mainModelDir" ]
then
echo "ERROR: $initToken.$1 doesn't exist in models. Operation aborted" >&2
exit 1
fi
obj=( )
if [ "$2" == "all" ]
then
obj=( html rdf ttl nt json )
else
obj=( $2 )
fi
for i in ${obj[@]}
do
if [ ! -e $mainModelDir/$i.queries ]
then
echo "WARNING: $initToken.$1/$i.query does not exists in models." >&2
fi
done
#Check views
mainViewDir=$DIR/../../views/$initToken.$1
if [ ! -e "$mainViewDir" ]
then
echo "ERROR: $initToken.$1 doesn't exist in views. Operation aborted." >&2
fi
for i in ${obj[@]}
do
if [ ! -e $mainViewDir/$i.template ]
then
echo "WARNING: $mainViewDir/$i.template doesn't exist in views." >&2
fi
done
#Delete file structure
if [ "$2" == "all" ]
then
rm -rf $mainModelDir
rm -rf $mainViewDir
else
for i in ${obj[@]}
do
rm -rf $mainModelDir/$i.queries
rm -rf $mainViewDir/$i.template
done
fi
echo $initToken.$1 deleted successfully! >&2
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