| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- Lib::loadClass('Type_WpsProcess');
- Lib::loadClass('Api_OwsException');
- class Api_WpsHelper {
- static function getUserWpsProcessList($userLogin = null) {
- // TODO: $userLogin
- $defaultWpsProcessList = self::getDefaultWpsProcessList();
- if (array_key_exists($identifier, $defaultWpsProcessList)) return Type_WpsProcess::build( $defaultWpsProcessList[$identifier] );
- $wpsProcessList = [];
- // TODO: fetch from DB - `CRM_#CACHE_ACL_FUNCTIONS` or object like UrlActions
- $wpsProcessList = array_merge($defaultWpsProcessList, $wpsProcessList);
- return array_map(function ($wpsProcess, $identifier) {
- return (object)[ 'identifier' => $identifier, 'title' => $wpsProcess['title'], 'description' => $wpsProcess['description'] ];
- }, $wpsProcessList, array_keys($wpsProcessList));
- return $wpsProcessList;
- }
- static function getUserWpsProcess($identifier, $userLogin = null) {
- // TODO: $userLogin
- $defaultWpsProcessList = self::getDefaultWpsProcessList();
- if (array_key_exists($identifier, $defaultWpsProcessList)) return Type_WpsProcess::build( $defaultWpsProcessList[$identifier] );
- // TODO: fetch from DB - `CRM_#CACHE_ACL_FUNCTIONS` or object like UrlActions
- throw new Exception("Forbidden - wps function not exists or access denied", 403);
- }
- static function getDefaultWpsProcessList() {
- $defaultWpsProcessList = [];
- {
- $selectFeatureArgTypeName = [
- 'maxOccurs' => "1",
- 'minOccurs' => "1",
- 'identifier' => 'typeName',
- 'title' => "Feature typeName",
- 'description' => "Feature typeName eg. default_db/PROBLEMS",
- 'type' => 'literal',
- ];
- $selectFeatureArgPrimaryKey = [
- 'maxOccurs' => "unbounded",
- 'minOccurs' => "1",
- 'identifier' => 'primaryKey',
- 'title' => "Feature primaryKey",
- 'description' => "Feature primaryKey",
- 'type' => 'literal',
- ];
- $selectFeatureBase = [
- 'dataInputs' => [
- $selectFeatureArgTypeName,
- $selectFeatureArgPrimaryKey,
- ],
- // 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
- 'defaultOutput' => [ 'MimeType' => "application/json" ], // TODO: result type - like Insert Wfs Transaction result - list of: Success (primaryKey = 123), ...
- 'supportedOutput' => [
- [ 'MimeType' => "application/json" ],
- [ 'MimeType' => "text/xml; subtype=wfs-collection/1.0" ],
- [ 'MimeType' => "text/xml; subtype=wfs-collection/1.1" ],
- // [ 'MimeType' => "application/wfs-collection-1.0" ],
- // [ 'MimeType' => "application/wfs-collection-1.1" ],
- // [ 'MimeType' => "application/zip" ],
- ]
- ];
- $defaultWpsProcessList['p5:selectFeature'] = array_merge([ 'title' => "Select feature", 'descriptin' => "Select feature (set attribute @selected to true)" ], $selectFeatureBase);
- $defaultWpsProcessList['p5:unselectFeature'] = array_merge([ 'title' => "Unselect feature", 'descriptin' => "Unselect feature (set attribute @selected to false)" ], $selectFeatureBase);
- $defaultWpsProcessList['p5:getSelectedFeatures'] = array_merge([ 'title' => "Get selected features", 'descriptin' => "Get list of selected features (with attribute @selected = true)" ], $selectFeatureBase);
- $defaultWpsProcessList['p5:unselectAllFeatures'] = array_merge([ 'title' => "Unselect all features", 'descriptin' => "Unselect all features (set attribute @selected to false)" ], $selectFeatureBase, [
- 'dataInputs' => [
- $selectFeatureArgTypeName
- ]
- ]);
- }
- array_walk($defaultWpsProcessList, function (&$wpsFunction, $identifier) {
- $wpsFunction['identifier'] = $identifier;
- });
- return $defaultWpsProcessList;
- }
- static function validateProcessArgs($wpsProcess, $args) {
- foreach ($wpsProcess->dataInputs as $input) {
- $identifier = $input->identifier;
- // TODO: required? minOccurs > 0
- if ($input->minOccurs > 0 && empty($args[ $identifier ])) throw new Api_OwsException("Missing value for '{$identifier}'", 501, null, 'MissingParameterValue', 'request');
- $totalValues = count($args[ $identifier ]);
- if ($totalValues > 1) {
- if ( 'unbounded' !== $input->maxOccurs && $totalValues > $input->maxOccurs ) {
- throw new Api_OwsException("Too many values for '{$identifier}'", 501, null, 'TooManyParameterValues', 'request');
- }
- }
- // TODO: validate values with type definition - _xsdType
- }
- }
- static function executeProcess($wpsProcess, $args, $responseForm = 'json') {
- $className = implode("_", array_merge(
- [
- 'Api',
- 'Process',
- ], array_map('ucfirst', explode(':', $wpsProcess->identifier))
- ) );
- if (!Lib::tryLoadClass($className)) {
- throw new Api_OwsException("Api Process not found '{$wpsProcess->identifier}'", 500, null, 'ApiProcessNotFound', 'request');
- }
- $className::run($args, $responseForm);
- }
- }
|