Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 46 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| tao_models_classes_service_ServiceCallHelper | |
0.00% |
0 / 46 |
|
0.00% |
0 / 3 |
156 | |
0.00% |
0 / 1 |
| getBaseUrl | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
| getInputValues | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
| getParamName | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | use oat\tao\model\WfEngineOntology; |
| 24 | |
| 25 | /** |
| 26 | * Service to manage services and calls to these services |
| 27 | * |
| 28 | * @author Joel Bout, <joel@taotesting.com> |
| 29 | */ |
| 30 | class tao_models_classes_service_ServiceCallHelper |
| 31 | { |
| 32 | public const CACHE_PREFIX_URL = 'tao_service_url_'; |
| 33 | |
| 34 | public const CACHE_PREFIX_PARAM_NAME = 'tao_service_param_'; |
| 35 | |
| 36 | public static function getBaseUrl($serviceDefinitionId) |
| 37 | { |
| 38 | |
| 39 | try { |
| 40 | $url = common_cache_FileCache::singleton()->get(self::CACHE_PREFIX_URL . urlencode($serviceDefinitionId)); |
| 41 | } catch (common_cache_NotFoundException $e) { |
| 42 | $serviceDefinition = new core_kernel_classes_Resource($serviceDefinitionId); |
| 43 | $serviceDefinitionUrl = $serviceDefinition->getOnePropertyValue( |
| 44 | new core_kernel_classes_Property(WfEngineOntology::PROPERTY_SUPPORT_SERVICES_URL) |
| 45 | ); |
| 46 | |
| 47 | $serviceUrl = ($serviceDefinitionUrl instanceof core_kernel_classes_Resource) ? |
| 48 | // hack nescessary since fully qualified urls are considered to be resources |
| 49 | $serviceUrl = $serviceDefinitionUrl->getUri() : |
| 50 | $serviceUrl = $serviceDefinitionUrl->literal; // instanceof Literal |
| 51 | |
| 52 | // Remove the parameters because they are only for show, and they are actualy encoded in the variables |
| 53 | $urlPart = explode('?', $serviceUrl); |
| 54 | $url = $urlPart[0]; |
| 55 | |
| 56 | common_cache_FileCache::singleton()->put($url, self::CACHE_PREFIX_URL . urlencode($serviceDefinitionId)); |
| 57 | } |
| 58 | if ($url[0] == '/') { |
| 59 | //create absolute url (prevent issue when TAO installed on a subfolder |
| 60 | $url = ROOT_URL . ltrim($url, '/'); |
| 61 | } |
| 62 | return $url; |
| 63 | } |
| 64 | |
| 65 | public static function getInputValues(tao_models_classes_service_ServiceCall $serviceCall, $callParameters) |
| 66 | { |
| 67 | $returnValue = []; |
| 68 | foreach ($serviceCall->getInParameters() as $param) { |
| 69 | $paramKey = self::getParamName($param->getDefinition()); |
| 70 | switch (get_class($param)) { |
| 71 | case 'tao_models_classes_service_ConstantParameter': |
| 72 | $returnValue[$paramKey] = $param->getValue(); |
| 73 | break; |
| 74 | case 'tao_models_classes_service_VariableParameter': |
| 75 | $variableCode = (string)$param->getVariable()->getUniquePropertyValue( |
| 76 | new core_kernel_classes_Property(PROPERTY_PROCESSVARIABLES_CODE) |
| 77 | ); |
| 78 | if (isset($callParameters[$variableCode])) { |
| 79 | $returnValue[$paramKey] = $callParameters[$variableCode]; |
| 80 | } else { |
| 81 | common_Logger::w('No variable ' . $variableCode . ' provided for paramter ' . $paramKey); |
| 82 | } |
| 83 | break; |
| 84 | default: |
| 85 | throw new common_exception_Error('Unknown class of parameter: ' . get_class($param)); |
| 86 | } |
| 87 | } |
| 88 | return $returnValue; |
| 89 | } |
| 90 | |
| 91 | protected static function getParamName(core_kernel_classes_Resource $paramDefinition) |
| 92 | { |
| 93 | try { |
| 94 | $paramKey = common_cache_FileCache::singleton()->get( |
| 95 | self::CACHE_PREFIX_PARAM_NAME . urlencode($paramDefinition->getUri()) |
| 96 | ); |
| 97 | } catch (common_cache_NotFoundException $e) { |
| 98 | $paramKey = common_Utils::fullTrim( |
| 99 | $paramDefinition->getUniquePropertyValue( |
| 100 | new core_kernel_classes_Property(WfEngineOntology::PROPERTY_FORMAL_PARAMETER_NAME) |
| 101 | ) |
| 102 | ); |
| 103 | common_cache_FileCache::singleton()->put( |
| 104 | $paramKey, |
| 105 | self::CACHE_PREFIX_PARAM_NAME . urlencode($paramDefinition->getUri()) |
| 106 | ); |
| 107 | } |
| 108 | return $paramKey; |
| 109 | } |
| 110 | } |