var url = null;
var method = null;
var contenttype = null;
var body = null;
var PersonId = null;
var XsltId = null;
var title = null;
var showscenario = null;
$(document).ready(function(){
$("#loading").hide();
$("#demo").hide();
});
function startDemo() {
$("#loading").show();
reset();
$("#demo").show('slow');
$("#loading").hide();
}
function sendRequest() {
$("#loading").show();
if(url==null){
alert("Please select a scenario!");
} else if(title=="add-new-item"||title=="create-new-xslt-stylesheet") {
switch(title) {
case "add-new-item":
$.ajax({
url: url,
type: method,
data: $("#requestBody").val(),
contentType: contenttype,
success: function (data, textStatus, jqXHR) {
$("#loading").hide();
$("#responseStatusCode").val(jqXHR.status);
$("#responseStatusDescription").val(jqXHR.statusText);
$("#responseHeaders").val(jqXHR.getAllResponseHeaders());
$("#responseLocation").val(jqXHR.getResponseHeader('Location'));
var responseloccation = jqXHR.getResponseHeader('Location');
PersonId = extractIDs(responseloccation);
},
error: function ( jqXHR, textStatus, errorThrown) {
$("#loading").hide();
$("#responseStatusCode").val(jqXHR.status);
$("#responseStatusDescription").val(jqXHR.statusText);
}
});
title = null;
break;
case "create-new-xslt-stylesheet":
$.ajax({
url: url,
type: method,
data: $("#requestBody").val(),
contentType: contenttype,
success: function (data, textStatus, jqXHR) {
$("#loading").hide();
$("#responseStatusCode").val(jqXHR.status);
$("#responseStatusDescription").val(jqXHR.statusText);
$("#responseHeaders").val(jqXHR.getAllResponseHeaders());
$("#responseLocation").val(jqXHR.getResponseHeader('Location'));
var responseloccation = jqXHR.getResponseHeader('Location');
XsltId = extractIDs(responseloccation);
},
error: function ( jqXHR, textStatus, errorThrown) {
$("#loading").hide();
$("#responseStatusCode").val(jqXHR.status);
$("#responseStatusDescription").val(jqXHR.statusText);
}
});
title = null;
break;
}
} else {
SendHttpRequest();
}
}
function setValues(){
clear();
var scenario = event.target.id;
showscenario = $(event.target).text();
// Remove all active items
$("a").removeClass("active");
$("a").addClass("inactive");
$(event.target).removeClass("inactive");
$(event.target).addClass("active");
switch (scenario){
case "read-all-resources":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/";
method = "GET";
contenttype = "application/xml";
ShowSelectedDataInFields();
break;
case "create-new-list":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/";
method = "POST";
contenttype = "application/xml";
body = ' people @id ';
ShowSelectedDataInFields();
break;
case "read-list-metadata":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/meta/";
method = "GET";
contenttype = "application/rdf+xml";
ShowSelectedDataInFields();
break;
case "create-schema":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/meta/schema/";
method = "PUT";
contenttype = "application/xml";
body = '';
ShowSelectedDataInFields();
break;
case "add-new-item":
title = "add-new-item";
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/";
method = "POST";
contenttype = "application/xml";
body = 'AlexeyTschudnowskytschudnowsky';
ShowSelectedDataInFields();
break;
case "read-list":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/";
method = "GET";
contenttype = "application/xml";
ShowSelectedDataInFields();
break;
case "create-new-uri-template":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/meta";
method = "POST";
contenttype = "text/n3";
body = '@prefix meta: .\n\r meta:urlTemplate [meta:url "people/{value}"; meta:xPath "//person[short = \'{value}\']"].';
ShowSelectedDataInFields();
break;
case "read-items-by-uri-template":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/tschudnowsky/";
method = "GET";
contenttype = "application/xml";
ShowSelectedDataInFields();
break;
case "create-another-list":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/";
method = "POST";
contenttype = "application/xml";
body = ' projects ';
ShowSelectedDataInFields();
break;
case "create-relationship":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/meta/relationships/";
method = "POST";
contenttype = "text/n3";
body = '@prefix dm: .\n\r<> dm:source .\n\r<> dm:target .\n\r<> dm:predicate .\n\r<> dm:inverse-predicate .\n\r<> dm:target-alias "participatedProjects".\n\r<> dm:source-alias "participants".';
ShowSelectedDataInFields();
break;
case "add-new-relationship-item":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/{personId}/projects/";
method = "POST";
contenttype = "application/xml";
body = ' DataGridService 1.0 ';
if(PersonId!=null) {
url = url.replace("{personId}",PersonId);
ShowSelectedDataInFields();
} else {
alert('This step is based on scenario "Add some XML item", please perform the the scenario first!');
}
break;
case "read-linked-resources":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/{personId}/projects/";
method = "GET";
contenttype = "application/xml";
if(PersonId!=null) {
url = url.replace("{personId}",PersonId);
ShowSelectedDataInFields();
} else {
alert('This step is based on scenario "Add some XML item", please perform the the scenario first!');
}
break;
case "create-new-rdf-xml-resource":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/";
method = "POST";
contenttype = "application/xml";
body = ' people/rdf ';
ShowSelectedDataInFields();
break;
case "create-new-xslt-list":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/";
method = "POST";
contenttype = "application/xml";
body = ' xslts ';
ShowSelectedDataInFields();
break;
case "create-new-xslt-stylesheet":
title = "create-new-xslt-stylesheet";
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/xslts/";
method = "POST";
contenttype = "application/xml";
body = ' ';
ShowSelectedDataInFields();
break;
case "configure-rdf-xml-resource":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/meta/";
method = "POST";
contenttype = "text/n3";
body = '.';
if(XsltId!=null) {
body = body.replace("{xsltId}",XsltId);
ShowSelectedDataInFields();
} else {
alert('This step is based on scenario "Create new XSLT stylesheet", please perform the the scenario first!');
}
break;
case "read-rdf-xml-resource":
url = "https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/rdf/";
method = "GET";
contenttype = "application/rdf+xml";
ShowSelectedDataInFields();
break;
}
}
function clear(){
$("#requestUri").val("");
$("#requestHeaders").val("");
$("#requestBody").val("");
$("#responseStatusCode").val("");
$("#responseStatusDescription").val("");
$("#responseHeaders").val("");
$("#responseBody").val("");
$("#responseLocation").val("");
url = null;
method = null;
contenttype = null;
body = null;
}
function reset() {
var urls = new Array("https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/",
"https://vsr-demo.informatik.tu-chemnitz.de/demodgs/people/rdf",
"https://vsr-demo.informatik.tu-chemnitz.de/demodgs/xslts/",
"https://vsr-demo.informatik.tu-chemnitz.de/demodgs/projects");
var i;
for(i = 0; i < 5; i++) {
$.ajax({
url: urls[i],
type: "DELETE",
success: function (result) {
}
});
}
clear();
}
function extractIDs(Location) {
var n = Location.lastIndexOf('/');
var id = Location.substring(n+1);
return id;
}
function SendHttpRequest() {
$.ajax({
url: url,
type: method,
data: $("#requestBody").val(),
contentType: contenttype,
success: function (data, textStatus, jqXHR) {
$("#loading").hide();
$("#responseStatusCode").val(jqXHR.status);
$("#responseStatusDescription").val(jqXHR.statusText);
var headers = jqXHR.getAllResponseHeaders();
$("#responseHeaders").val(headers);
$("#responseLocation").val(jqXHR.getResponseHeader('Location'));
if(data) {
if (typeof data == 'string' || data instanceof String)
$("#responseBody").val(data);
else {
var responsebody = new XMLSerializer().serializeToString(data);
$("#responseBody").val(responsebody);
}
}
else
$("#responseBody").val("");
},
error: function ( jqXHR, textStatus, errorThrown) {
$("#loading").hide();
$("#responseStatusCode").val(jqXHR.status);
$("#responseStatusDescription").val(jqXHR.statusText);
}
});
}
function ShowSelectedDataInFields() {
$("#requestUri").val(url);
$('#requestMethod').val(method);
$("#requestHeaders").val("Content-Type:" + contenttype + ";");
$("#requestBody").val(body);
}