Skip to content

Commit

Permalink
SPARQL query is passed through POST for UPDATE requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ali1k committed Oct 29, 2016
1 parent 9eef615 commit 2d0c60e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
3 changes: 2 additions & 1 deletion services/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export default {
query = queryObject.activateUser(endpointParameters.type, authGraphName[0], params.resourceURI);
//build http uri
//send request
rp.post({uri: getHTTPGetURL(getHTTPQuery('update', query, endpointParameters, outputFormat))}).then(function(res){
HTTPQueryObject = getHTTPQuery('update', query, endpointParameters, outputFormat);
rp.post({uri: HTTPQueryObject.uri, form: HTTPQueryObject.params}).then(function(res){
if(enableEmailNotifications){
sendMail('userActivation', '', params.email, '', '', '');
}
Expand Down
23 changes: 15 additions & 8 deletions services/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(enableLogs){
const outputFormat = 'application/sparql-results+json';
const headers = {'Accept': 'application/sparql-results+json'};
/*-----------------------------------*/
let endpointParameters, category, cGraphName, graphName, propertyURI, resourceURI, objectURI, objectValue, query, queryObject, utilObject, configurator, propertyPath;
let endpointParameters, category, cGraphName, graphName, propertyURI, resourceURI, objectURI, objectValue, query, queryObject, utilObject, configurator, propertyPath, HTTPQueryObject;
queryObject = new ResourceQuery();
utilObject = new ResourceUtil();

Expand Down Expand Up @@ -156,7 +156,8 @@ export default {
query = queryObject.getPrefixes() + queryObject.getAddTripleQuery(endpointParameters, cGraphName, params.resourceURI, params.propertyURI, params.objectValue, params.valueType, params.dataType);
//build http uri
//send request
rp.post({uri: getHTTPGetURL(getHTTPQuery('update', query, endpointParameters, outputFormat))}).then(function(res){
HTTPQueryObject = getHTTPQuery('update', query, endpointParameters, outputFormat);
rp.post({uri: HTTPQueryObject.uri, form: HTTPQueryObject.params}).then(function(res){
if(enableLogs){
log.info('\n User: ' + user.accountName + ' \n Query: \n' + query);
}
Expand Down Expand Up @@ -199,7 +200,8 @@ export default {
}
//build http uri
//send request
rp.post({uri: getHTTPGetURL(getHTTPQuery('update', query, endpointParameters, outputFormat))}).then(function(res){
HTTPQueryObject = getHTTPQuery('update', query, endpointParameters, outputFormat);
rp.post({uri: HTTPQueryObject.uri, form: HTTPQueryObject.params}).then(function(res){
if(enableLogs){
log.info('\n User: ' + user.accountName + ' \n Query: \n' + query);
}
Expand Down Expand Up @@ -241,7 +243,8 @@ export default {
query = queryObject.getPrefixes() + queryObject.getUpdateTripleQuery(endpointParameters, cGraphName, params.resourceURI, params.propertyURI, params.oldObjectValue, params.newObjectValue, params.valueType, params.dataType);
//build http uri
//send request
rp.post({uri: getHTTPGetURL(getHTTPQuery('update', query, endpointParameters, outputFormat))}).then(function(res){
HTTPQueryObject = getHTTPQuery('update', query, endpointParameters, outputFormat);
rp.post({uri: HTTPQueryObject.uri, form: HTTPQueryObject.params}).then(function(res){
if(enableLogs){
log.info('\n User: ' + user.accountName + ' \n Query: \n' + query);
}
Expand Down Expand Up @@ -288,7 +291,8 @@ export default {
query = queryObject.getPrefixes() + queryObject.getUpdateObjectTriplesForSesame(endpointParameters, cGraphName, params.resourceURI, params.propertyURI, params.oldObjectValue, params.newObjectValue, params.valueType, params.dataType, params.detailData);
//build http uri
//send request
rp.post({uri: getHTTPGetURL(getHTTPQuery('update', query, endpointParameters, outputFormat))}).then(function(res){
HTTPQueryObject = getHTTPQuery('update', query, endpointParameters, outputFormat);
rp.post({uri: HTTPQueryObject.uri, form: HTTPQueryObject.params}).then(function(res){
if(enableLogs){
log.info('\n User: ' + user.accountName + ' \n Query: \n' + query);
}
Expand Down Expand Up @@ -327,7 +331,8 @@ export default {
query = queryObject.getPrefixes() + queryObject.getUpdateTriplesQuery(endpointParameters, cGraphName, params.resourceURI, params.propertyURI, params.changes);
//build http uri
//send request
rp.post({uri: getHTTPGetURL(getHTTPQuery('update', query, endpointParameters, outputFormat))}).then(function(res){
HTTPQueryObject = getHTTPQuery('update', query, endpointParameters, outputFormat);
rp.post({uri: HTTPQueryObject.uri, form: HTTPQueryObject.params}).then(function(res){
if(enableLogs){
log.info('\n User: ' + user.accountName + ' \n Query: \n' + query);
}
Expand Down Expand Up @@ -369,7 +374,8 @@ export default {
query = queryObject.getPrefixes() + queryObject.getDeleteTripleQuery(endpointParameters, cGraphName, params.resourceURI, params.propertyURI, params.objectValue, params.valueType, params.dataType);
//build http uri
//send request
rp.post({uri: getHTTPGetURL(getHTTPQuery('update', query, endpointParameters, outputFormat))}).then(function(res){
HTTPQueryObject = getHTTPQuery('update', query, endpointParameters, outputFormat);
rp.post({uri: HTTPQueryObject.uri, form: HTTPQueryObject.params}).then(function(res){
if(enableLogs){
log.info('\n User: ' + user.accountName + ' \n Query: \n' + query);
}
Expand Down Expand Up @@ -406,7 +412,8 @@ export default {
query = queryObject.getPrefixes() + queryObject.getDeleteTriplesQuery(endpointParameters, cGraphName, params.resourceURI, params.propertyURI, params.changes);
//build http uri
//send request
rp.post({uri: getHTTPGetURL(getHTTPQuery('update', query, endpointParameters, outputFormat))}).then(function(res){
HTTPQueryObject = getHTTPQuery('update', query, endpointParameters, outputFormat);
rp.post({uri: HTTPQueryObject.uri, form: HTTPQueryObject.params}).then(function(res){
if(enableLogs){
log.info('\n User: ' + user.accountName + ' \n Query: \n' + query);
}
Expand Down
14 changes: 7 additions & 7 deletions services/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
},
//build the write URI and params for different SPARQL endpoints
getHTTPQuery: function(mode, query, endpointParameters, outputFormat) {
let outputObject = {url: '', params: {}};
let outputObject = {uri: '', params: {}};

if(endpointParameters.useReasoning){
outputObject.params['reasoning'] = 'true';
Expand All @@ -52,13 +52,13 @@ export default {
switch (endpointParameters.type) {
case 'virtuoso':

outputObject.url = 'http://' + endpointParameters.httpOptions.host + ':' + endpointParameters.httpOptions.port + endpointParameters.httpOptions.path;
outputObject.uri = 'http://' + endpointParameters.httpOptions.host + ':' + endpointParameters.httpOptions.port + endpointParameters.httpOptions.path;
outputObject.params['query'] = query;
outputObject.params['format'] = outputFormat;

break;
case 'stardog':
outputObject.url = 'http://' + endpointParameters.httpOptions.host + ':' + endpointParameters.httpOptions.port + endpointParameters.httpOptions.path;
outputObject.uri = 'http://' + endpointParameters.httpOptions.host + ':' + endpointParameters.httpOptions.port + endpointParameters.httpOptions.path;
outputObject.params['query'] = query;
outputObject.params['Accept'] = outputFormat;

Expand All @@ -67,11 +67,11 @@ export default {
case 'sesame':
if(mode === 'update'){
ext = '';
outputObject.url = 'http://' + endpointParameters.httpOptions.host + ':' + endpointParameters.httpOptions.port + endpointParameters.httpOptions.path + '/statements';
outputObject.uri = 'http://' + endpointParameters.httpOptions.host + ':' + endpointParameters.httpOptions.port + endpointParameters.httpOptions.path + '/statements';
outputObject.params['update'] = query;
}else{
outputObject.params['query'] = query;
outputObject.url = 'http://' + endpointParameters.httpOptions.host + ':' + endpointParameters.httpOptions.port + endpointParameters.httpOptions.path;
outputObject.uri = 'http://' + endpointParameters.httpOptions.host + ':' + endpointParameters.httpOptions.port + endpointParameters.httpOptions.path;
outputObject.params['Accept'] = outputFormat;
}

Expand All @@ -81,8 +81,8 @@ export default {
},
///builds the HTTP get URL for SPARQL requests
getHTTPGetURL(object){
let url = object.url + '?' + queryString.stringify(object.params);
return url;
let uri = object.uri + '?' + queryString.stringify(object.params);
return uri;
},
getQueryDataTypeValue(valueType, dataType, objectValue) {
let newValue, dtype;
Expand Down

0 comments on commit 2d0c60e

Please sign in to comment.