Skip to content

Commit

Permalink
wps service now handle multiple values per input
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Jul 24, 2017
1 parent a6a2c8f commit 7c87f0c
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,23 @@
* @description
* The `gnWpsProcessForm` build up a HTML form from the describe process
* response object (after call the describe process request).
* User inputs will be saved on the wpsLink object as 'inputs' with the following structure:
* User inputs will be saved on the wpsLink object as 'inputs' with the
* following structure:
* [{
* name: 'input_name',
* value: 'value entered by the user'
* },
* ...]
* Existing inputs will be displayed in the form
* Existing inputs will be displayed in the form.
* The directive keeps a cache of process descriptions & inputs.
*
* @directiveInfo {Object} map
* @directiveInfo {Object} wpsLink
* @directiveInfo {Object} wpsLink this object holds information on the WPS
* service to use, namely name and url properties
* @directiveInfo {Object} wfsLink the WFS link object
* will be used to overload inputs based on active WFS feature filters
* @directiveInfo {boolean} hideExecuteButton if true,
* the 'execute' button is hidden
*
* TODO: Add batch mode using md.privileges.batch
* and md.privileges.batch.update services.
*
* TODO: User group only privilege
*/
module.directive('gnWpsProcessForm', [
'gnWpsService',
Expand Down Expand Up @@ -87,7 +84,6 @@
return attrs.template ||
'../../catalog/components/viewer/wps/partials/processform.html';
},

link: function(scope, element, attrs) {
scope.describeState = 'standby';
scope.executeState = '';
Expand Down Expand Up @@ -347,8 +343,8 @@
function(input) {
// count the number of non empty values
var valueCount = scope.getInputsByName(input.identifier.value)
.filter(function (value) {
return value;
.filter(function (input) {
return input.value;
}).length;

// this will be used to show errors on the form
Expand Down Expand Up @@ -426,7 +422,7 @@
scope.executeResponse = response;

// save raw graph data on view controller & hide it in wps form
if (scope.outputAsGraph) {
if (scope.outputAsGraph && response.processOutputs) {
gnViewerService.displayProfileGraph(
response.processOutputs.output[0]
.data.complexData.content
Expand Down
196 changes: 98 additions & 98 deletions web-ui/src/main/resources/catalog/components/viewer/wps/WpsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,106 +180,100 @@
* Prints a WPS Execute message as XML to be posted to a WPS service.
* Does a DescribeProcess call first
*
* @param {string} uri of the wps service
* @param {string} processId of the process
* @param {Object} inputs of the process
* @param {Object} processDescription from the wps service
* @param {Object} inputs of the process; this must be an array of
* objects like so: { name: 'input_name', value: 'input value' }
* @param {Object} options such as storeExecuteResponse,
* lineage and status
* @return {defer} promise
* @return {string} XML message
*/
this.printExecuteMessage = function(uri, processId, inputs,
this.printExecuteMessage = function(processDescription, inputs,
responseDocument) {
var me = this;

return this.describeProcess(uri, processId).then(
function(data) {
var description = data.processDescription[0];

var url = uri;
var request = {
name: {
localPart: 'Execute',
namespaceURI: 'http://www.opengis.net/wps/1.0.0'
},
value: {
service: 'WPS',
version: '1.0.0',
identifier: {
value: description.identifier.value
},
dataInputs: {
input: []
}
}
};

var setInputData = function(input, data) {
if (input.literalData && data) {
request.value.dataInputs.input.push({
identifier: {
value: input.identifier.value
},
data: {
literalData: {
value: data.toString()
}
}
});
}
if (input.complexData && data) {
var mimeType = input.complexData._default.format.mimeType;
request.value.dataInputs.input.push({
identifier: {
value: input.identifier.value
},
data: {
complexData: {
mimeType: mimeType,
content: data
}
}
});
var description = processDescription;

var request = {
name: {
localPart: 'Execute',
namespaceURI: 'http://www.opengis.net/wps/1.0.0'
},
value: {
service: 'WPS',
version: '1.0.0',
identifier: {
value: description.identifier.value
},
dataInputs: {
input: []
}
}
};

var setInputData = function(input, data) {
if (input.literalData && data) {
request.value.dataInputs.input.push({
identifier: {
value: input.identifier.value
},
data: {
literalData: {
value: data.toString()
}
if (input.boundingBoxData) {
var bbox = data.split(',');
request.value.dataInputs.input.push({
identifier: {
value: input.identifier.value
},
data: {
boundingBoxData: {
dimensions: 2,
lowerCorner: [bbox[0], bbox[1]],
upperCorner: [bbox[2], bbox[3]]
}
}
});
}
});
}
if (input.complexData && data) {
var mimeType = input.complexData._default.format.mimeType;
request.value.dataInputs.input.push({
identifier: {
value: input.identifier.value
},
data: {
complexData: {
mimeType: mimeType,
content: data
}
};

for (var i = 0; i < description.dataInputs.input.length; ++i) {
var input = description.dataInputs.input[i];
if (inputs[input.identifier.value] !== undefined) {
setInputData(input, inputs[input.identifier.value]);
}
});
}
if (input.boundingBoxData) {
var bbox = data.split(',');
request.value.dataInputs.input.push({
identifier: {
value: input.identifier.value
},
data: {
boundingBoxData: {
dimensions: 2,
lowerCorner: [bbox[0], bbox[1]],
upperCorner: [bbox[2], bbox[3]]
}
}
});
}
};

for (var i = 0; i < description.dataInputs.input.length; ++i) {
var input = description.dataInputs.input[i];
var inputName = input.identifier.value;

// for each value for this input, add to message
inputs.filter(function (inputValue) {
return inputValue.name === inputName;
}).forEach(function (inputValue) {
setInputData(input, inputValue.value);
});
}

request.value.responseForm = {
responseDocument: $.extend(true, {
lineage: false,
storeExecuteResponse: true,
status: false
}, responseDocument)
};

var body = marshaller.marshalString(request);
request.value.responseForm = {
responseDocument: $.extend(true, {
lineage: false,
storeExecuteResponse: true,
status: false
}, responseDocument)
};

return body;
},
function(data) {
return data;
}
);
return marshaller.marshalString(request);
};

/**
Expand All @@ -297,24 +291,30 @@
* @param {Object} output of the process
* @param {Object} options such as storeExecuteResponse,
* lineage and status
* @return {defer} promise
*/
this.execute = function(uri, processId, inputs, responseDocument) {
var defer = $q.defer();
var me = this;

this.printExecuteMessage(uri, processId, inputs,
responseDocument)
.then(function(body) {
return $http.post(url, body, {
headers: {'Content-Type': 'application/xml'}
});
})
.then(function(data) {
this.describeProcess(uri, processId).then(
function (data) {
// generate the XML message from the description
var description = data.processDescription[0];
var message = me.printExecuteMessage(description, inputs,
responseDocument);

// do the post request
$http.post(uri, message, {
headers: {'Content-Type': 'application/xml'}
}).then(function (data) {
var response =
unmarshaller.unmarshalString(data.data).value;
unmarshaller.unmarshalString(data.data).value;
defer.resolve(response);
}, function(data) {
defer.reject(data);
});
});

return defer.promise;
};
Expand Down

0 comments on commit 7c87f0c

Please sign in to comment.