Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f89fc81
commit c4023bd
Showing
7 changed files
with
353 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
web-ui/src/main/resources/catalog/components/viewer/wps/WpsDirective.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
); | ||
}; | ||
} | ||
}; | ||
} | ||
]); | ||
})(); |
11 changes: 11 additions & 0 deletions
11
web-ui/src/main/resources/catalog/components/viewer/wps/WpsModule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
186
web-ui/src/main/resources/catalog/components/viewer/wps/WpsService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
} | ||
]); | ||
})(); |
45 changes: 45 additions & 0 deletions
45
web-ui/src/main/resources/catalog/components/viewer/wps/partials/processform.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters