Skip to content

Commit

Permalink
Add WPS client module
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-morvan committed Apr 30, 2015
1 parent f89fc81 commit c4023bd
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 2 deletions.
Expand Up @@ -84,6 +84,7 @@

};
return {
mergeDefaultParams: mergeDefaultParams,

getWMSCapabilities: function(url) {
var defer = $q.defer();
Expand Down
@@ -0,0 +1,98 @@
(function() {
goog.provide('gn_wps_directive');

var module = angular.module('gn_wps_directive', [
]);

module.directive('gnWpsProcessForm', [
'gnWpsService',
function(gnWpsService) {

var inputTypeMapping = {
string: 'text',
float: 'number'
};

var defaultValue = function(literalData) {
var value = undefined;
if (literalData.defaultValue != undefined) {
value = literalData.defaultValue;
}
if (literalData.dataType.value == 'float') {
value = parseFloat(value);
}
if (literalData.dataType.value == 'string') {
value = value || '';
}
return value;
};

return {
restrict: 'AE',
scope: {
uri: '=',
processId: '=',
},
templateUrl: function(elem, attrs) {
return attrs.template ||
'../../catalog/components/viewer/wps/partials/processform.html';
},

link: function(scope, element, attrs) {

scope.status = 'loading';
gnWpsService.describeProcess(scope.uri, scope.processId)
.then(
function(data) {
scope.processDescription = data.processDescription[0];
scope.title = scope.processDescription.title.value
scope.inputs = [];
angular.forEach(scope.processDescription.dataInputs.input,
function(input) {
scope.inputs.push({
name: input.identifier.value,
title: input.title.value,
type: inputTypeMapping[input.literalData.dataType.value],
value: defaultValue(input.literalData),
required: input.minOccurs == 1 ? true : false
})
}
);
scope.status = 'loaded';
},
function(data) {
scope.exception = data;
scope.status = 'error';
}
);

scope.close = function() {
element.remove();
};

scope.submit = function() {
var inputs = scope.inputs.reduce(function(o, v, i) {
o[v.name] = v.value.toString();
return o;
}, {});
gnWpsService.execute(
scope.uri,
scope.processId,
inputs,
scope.processDescription.processOutputs.output[0].identifier.value,
false
).then(
function(data) {
window.open(data);
},
function(data) {
scope.exception = data;
scope.status = 'error';
}
);
};
}
};
}
]);
})();
@@ -0,0 +1,11 @@
(function() {
goog.provide('gn_wps');

goog.require('gn_wps_directive');
goog.require('gn_wps_service');

var module = angular.module('gn_wps', [
'gn_wps_service',
'gn_wps_directive'
]);
})();
186 changes: 186 additions & 0 deletions web-ui/src/main/resources/catalog/components/viewer/wps/WpsService.js
@@ -0,0 +1,186 @@
(function() {
goog.provide('gn_wps_service');

var module = angular.module('gn_wps_service', []);

// WPS Client
// Jsonix wrapper to read or write WPS response or request
var context = new Jsonix.Context(
[XLink_1_0, OWS_1_1_0, WPS_1_0_0],
{
namespacePrefixes: {
'http://www.w3.org/1999/xlink': 'xlink',
'http://www.opengis.net/ows/1.1': 'ows',
'http://www.opengis.net/wps/1.0.0': 'wps'
}
}
);
var unmarshaller = context.createUnmarshaller();
var marshaller = context.createMarshaller();

module.service('gnWpsService', [
'$http',
'gnOwsCapabilities',
'gnUrlUtils',
'gnGlobalSettings',
'$q',
function($http, gnOwsCapabilities, gnUrlUtils, gnGlobalSettings, $q) {

this.proxyUrl = function(url) {
return gnGlobalSettings.proxyUrl+encodeURIComponent(url);
};

this.describeProcess = function(uri, processId) {
url = gnOwsCapabilities.mergeDefaultParams(uri, {
service: 'WPS',
version: '1.0.0',
request: 'DescribeProcess',
identifier: processId
});

//send request and decode result
if (gnUrlUtils.isValid(url)) {
var defer = $q.defer();

var proxyUrl = this.proxyUrl(url);
$http.get(proxyUrl, {
cache: true
}).then(
function(data) {
var response = unmarshaller.unmarshalString(data.data).value;
if (response.exception != undefined) {
defer.reject({msg:"wpsDescribeProcessFailed",
owsExceptionReport: response});
}
else {
defer.resolve(response);
}
},
function(data) {
defer.reject({msg:"wpsDescribeProcessFailed",
httpResponse: data});
}
);

return defer.promise;
}
};

this.execute = function(uri, processId, inputs, output) {
var defer = $q.defer();

var me = this;

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

var url = me.proxyUrl(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) {
var inputValue;
request.value.dataInputs.input.push({
identifier: {
value: input.identifier.value
},
data: {
literalData: {
value: data
}
}
});
};

for (i=0, ii=description.dataInputs.input.length; i<ii; ++i) {
input = description.dataInputs.input[i];
if (inputs[input.identifier.value] !== undefined) {
setInputData(input, inputs[input.identifier.value]);
}
}

var getOutputIndex = function(outputs, identifier) {
var output;
if (identifier) {
for (var i=outputs.length-1; i>=0; --i) {
if (outputs[i].identifier.value === identifier) {
output = i;
break;
}
}
} else {
output = 0;
}
return output;
};

var setResponseForm = function(options) {
options = options || {};
var output = description.processOutputs.output[options.outputIndex || 0];
request.value.responseForm = {
responseDocument: {
lineage: false,
storeExecuteResponse: true,
status: false,
output: [{
asReference: true,
identifier: {
value: output.identifier.value
}
}]
}
};
};

var outputIndex = getOutputIndex(
description.processOutputs.output, output);
setResponseForm({outputIndex: outputIndex});

var body = marshaller.marshalString(request);

$http.post(url, body, {
headers: {'Content-Type': 'application/xml'}
}).then(
function(data) {
var response = unmarshaller.unmarshalString(data.data).value;
var status = response.status;
if (status.processFailed != undefined) {
defer.reject({msg:"wpsExecuteFailed",
owsExceptionReport: status.processFailed.exceptionReport});
} else {
var url = response.processOutputs.output[0].reference.href;
defer.resolve(url);
}
},
function(data) {
defer.reject({msg:"wpsExecuteFailed",
httpResponse: data});
}
);

},
function(data) {
defer.reject(data);
}
);

return defer.promise;
};
}
]);
})();
@@ -0,0 +1,45 @@
<div class="panel-body panel-wps">
<button type="button" class="btn btn-default close" data-ng-click="close()">×</button>

<div ng-switch="status">

<div ng-switch-when="loading">
<h4><span translate>wpsLoadingProcessDescription</span></h4>
</div>

<div ng-switch-when="loaded">
<form>
<h5>{{::title}}</h5>
<div ng-repeat="input in inputs" class="form-group" ng-class="{'gn-required': input.required}">
<label for="{{::input.name}}">{{::input.title}}</label>
<input type="{{::input.type}}" id="{{::input.name}}" class="form-control input-sm" ng-model="input.value"></input>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default" data-ng-click="submit()" >
<span class="fa fa-gear"></span><span translate>wpsExecute</span>
</button>
</div>
</form>
</div>

<div ng-switch-when="error">
<h4>{{exception.msg|translate}}</h4>
<div ng-if="exception.owsExceptionReport">
<div ng-repeat="exception in exception.owsExceptionReport.exception">
<div ng-repeat="(key, value) in exception">
{{key}}: {{value}}
</div>
</div>
</div>
<div ng-if="exception.httpResponse">
<div><span translate>wpsErrorCodeReturned</span> {{exception.httpResponse.status}} - {{exception.httpResponse.statusText}}</div>
<div>{{exception.httpResponse.data}}</div>
</div>
</div>

<div ng-switch-default>
<p>{{status}}</p>
</div>

</div>
</div>
8 changes: 6 additions & 2 deletions web-ui/src/main/resources/catalog/locales/en-search.json
Expand Up @@ -279,6 +279,10 @@
"loadUserGroupsError": "Error loading user groups",
"transferOwnershipError": "Error transferring metadata ownership",
"transferOwnershipSuccessMsg": "<h4>Successfully transferred metadata to a new Owner.</h4><dl class=\"dl-horizontal\"><dt>Transferred:</dt><dd>{{done}}</dd><dt>Not Owned:</dt><dd>{{notOwner}}</dd><dt>Not found:</dt><dd>{{notFound}}</dd></dl>",
"filterGroup": "Filter groups ..."

"filterGroup": "Filter groups ...",
"wpsLoadingProcessDescription": "Loading process description ...",
"wpsDescribeProcessFailed": "DescribeProcess failed",
"wpsExecute": "Execute",
"wpsExecuteFailed": "Execute failed",
"wpsErrorCodeReturned": "The serveur returned status code"
}
6 changes: 6 additions & 0 deletions web-ui/src/main/resources/catalog/style/gn_search.less
Expand Up @@ -510,3 +510,9 @@ div[gn-transfer-ownership] .panel-body {
}
}
}

.gn-required > label:after {
content: " *";
color: #a94442;
font-weight: normal;
}

0 comments on commit c4023bd

Please sign in to comment.