/** * Get the ServiceCall object representing how to call the current Assessment Item to be * presented to a candidate in a given Assessment Test $session. * * @param AssessmentTestSession $session An AssessmentTestSession Object. * @param string $testDefinition URI The URI of the knowledge base resource representing the folder where the QTI Test Definition is stored. * @param string $testCompilation URI The URI of the knowledge base resource representing the folder where the QTI Test Compilation is stored. * @return tao_models_classes_service_ServiceCall A ServiceCall object. */ public static function buildItemServiceCall(AssessmentTestSession $session, $testDefinitionUri, $testCompilationUri) { $href = $session->getCurrentAssessmentItemRef()->getHref(); // retrive itemUri & itemPath. $parts = explode('|', $href); $definition = new core_kernel_classes_Resource(INSTANCE_QTITEST_ITEMRUNNERSERVICE); $serviceCall = new tao_models_classes_service_ServiceCall($definition); $uriResource = new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_ITEMURI); $uriParam = new tao_models_classes_service_ConstantParameter($uriResource, $parts[0]); $serviceCall->addInParameter($uriParam); $pathResource = new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_ITEMPATH); $pathParam = new tao_models_classes_service_ConstantParameter($pathResource, $parts[1]); $serviceCall->addInParameter($pathParam); $dataPathResource = new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_ITEMDATAPATH); $dataPathParam = new tao_models_classes_service_ConstantParameter($dataPathResource, $parts[2]); $serviceCall->addInParameter($dataPathParam); $parentServiceCallIdResource = new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_QTITESTITEMRUNNER_PARENTCALLID); $parentServiceCallIdParam = new tao_models_classes_service_ConstantParameter($parentServiceCallIdResource, $session->getSessionId()); $serviceCall->addInParameter($parentServiceCallIdParam); $testDefinitionResource = new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_QTITEST_TESTDEFINITION); $testDefinitionParam = new tao_models_classes_service_ConstantParameter($testDefinitionResource, $testDefinitionUri); $serviceCall->addInParameter($testDefinitionParam); $testCompilationResource = new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_QTITEST_TESTCOMPILATION); $testCompilationParam = new tao_models_classes_service_ConstantParameter($testCompilationResource, $testCompilationUri); $serviceCall->addInParameter($testCompilationParam); return $serviceCall; }
private function buildCompiledDelivery(core_kernel_classes_Resource $delivery, core_kernel_classes_Resource $workflow) { $directory = $this->getCompilationDirectory($delivery); $this->replaceItemRunner($workflow, $directory); $serviceCall = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(INSTANCE_SERVICE_PROCESSRUNNER)); $param = new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_PROCESSDEFINITION), $workflow); $serviceCall->addInParameter($param); $compilationClass = new core_kernel_classes_Class(CLASS_COMPILEDDELIVERY); $compilationInstance = $compilationClass->createInstanceWithProperties(array(RDFS_LABEL => $delivery->getLabel(), PROPERTY_COMPILEDDELIVERY_DELIVERY => $delivery, PROPERTY_COMPILEDDELIVERY_FOLDER => $directory, PROPERTY_COMPILEDDELIVERY_TIME => time(), PROPERTY_COMPILEDDELIVERY_RUNTIME => $serviceCall->toOntology())); return $compilationInstance; }
function compile() { $content = $this->getResource()->getUniquePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP)); $ltiLaunchUrl = $content->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_LTI_LINK_LAUNCHURL)); $ltiLinkConsumer = $content->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_LTI_LINK_CONSUMER)); if (empty($ltiLaunchUrl)) { throw new tao_models_classes_CompilationFailedException('Missing launch Url for test ' . $this->getResource()->getUri()); } if (empty($ltiLinkConsumer)) { throw new tao_models_classes_CompilationFailedException('Missing LTI consumer for test ' . $this->getResource()->getUri()); } // Build the service call. $service = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(INSTANCE_LTI_CONSUMER_SERVICE)); $param = new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_LTI_LAUNCH_URL), $ltiLaunchUrl); $service->addInParameter($param); $param = new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_LTI_CONSUMER), $ltiLinkConsumer->getUri()); $service->addInParameter($param); common_Logger::d("LTI Test successfully compiled."); return $service; }
public static function getInputValues(tao_models_classes_service_ServiceCall $serviceCall, $callParameters) { $returnValue = array(); foreach ($serviceCall->getInParameters() as $param) { $paramKey = self::getParamName($param->getDefinition()); switch (get_class($param)) { case 'tao_models_classes_service_ConstantParameter': $returnValue[$paramKey] = $param->getValue(); break; case 'tao_models_classes_service_VariableParameter': $variableCode = (string) $param->getVariable()->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_PROCESSVARIABLES_CODE)); if (isset($callParameters[$variableCode])) { $returnValue[$paramKey] = $callParameters[$variableCode]; } else { common_Logger::w('No variable ' . $variableCode . ' provided for paramter ' . $paramKey); } break; default: throw new common_exception_Error('Unknown class of parameter: ' . get_class($param)); } } return $returnValue; }
/** * (non-PHPdoc) * @see tao_models_classes_Compiler::compile() */ public function compile() { $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Published test "%s"', $this->getResource()->getLabel())); common_ext_ExtensionsManager::singleton()->getExtensionById('taoWfTest'); // loads the extension $test = $this->getResource(); common_Logger::i('Compiling test ' . $test->getLabel() . ' items'); $process = $test->getUniquePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP)); if (count(wfEngine_models_classes_ProcessDefinitionService::singleton()->getAllActivities($process)) == 0) { return new common_report_Report(common_report_Report::TYPE_ERROR, __('An empty test cannot be published.')); } $processCloner = new wfAuthoring_models_classes_ProcessCloner(); try { $processClone = $processCloner->cloneProcess($process); $report->add(new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Cloned the process %s', $process->getLabel()))); $itemsServiceReport = $this->process($processClone); foreach ($itemsServiceReport as $subReport) { $report->add($subReport); } if ($itemsServiceReport->getType() == common_report_Report::TYPE_SUCCESS) { $serviceCall = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(INSTANCE_SERVICE_PROCESSRUNNER)); $param = new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_PROCESSDEFINITION), $processClone->getUri()); $serviceCall->addInParameter($param); $report->setData($serviceCall); } else { $report->setType(common_report_Report::TYPE_ERROR); } } catch (common_Exception $e) { $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, __('Failed to clone the process'))); $report->setType(common_report_Report::TYPE_ERROR); } if ($report->getType() != common_report_Report::TYPE_SUCCESS) { $report->setMessage(__('Failed to publish test "%s".', $this->getResource()->getLabel())); } return $report; }
/** * export a compiled delivery into an archive * * @param core_kernel_classes_Resource $compiledDelivery * @throws Exception * @return string */ public static function exportCompiledDelivery(core_kernel_classes_Resource $compiledDelivery) { $fileName = tao_helpers_Display::textCleaner($compiledDelivery->getLabel()) . '.zip'; $path = tao_helpers_File::concat(array(tao_helpers_Export::getExportPath(), $fileName)); if (!tao_helpers_File::securityCheck($path, true)) { throw new Exception('Unauthorized file name'); } $zipArchive = new ZipArchive(); if ($zipArchive->open($path, ZipArchive::CREATE) !== true) { throw new Exception('Unable to create archive at ' . $path); } $taoDeliveryVersion = common_ext_ExtensionsManager::singleton()->getInstalledVersion('taoDelivery'); $data = array('dir' => array(), 'label' => $compiledDelivery->getLabel(), 'version' => $taoDeliveryVersion); $directories = $compiledDelivery->getPropertyValues(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_DIRECTORY)); foreach ($directories as $id) { $directory = tao_models_classes_service_FileStorage::singleton()->getDirectoryById($id); tao_helpers_File::addFilesToZip($zipArchive, $directory->getPath(), $directory->getRelativePath()); $data['dir'][$id] = $directory->getRelativePath(); } $runtime = $compiledDelivery->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_RUNTIME)); $serviceCall = tao_models_classes_service_ServiceCall::fromResource($runtime); $data['runtime'] = base64_encode($serviceCall->serializeToString()); $rdfExporter = new tao_models_classes_export_RdfExporter(); $rdfdata = $rdfExporter->getRdfString(array($compiledDelivery)); if (!$zipArchive->addFromString('delivery.rdf', $rdfdata)) { throw common_Exception('Unable to add metadata to exported delivery assembly'); } $data['meta'] = 'delivery.rdf'; $content = json_encode($data); //'<?php return '.common_Utils::toPHPVariableString($data).";"; if (!$zipArchive->addFromString(self::MANIFEST_FILE, $content)) { $zipArchive->close(); unlink($path); throw common_Exception('Unable to add manifest to exported delivery assembly'); } $zipArchive->close(); return $path; }
public function getCurrentServiceCall() { $itemData = TestRunnerService::singleton()->getItemData($this->compilationId); $serviceCall = \tao_models_classes_service_ServiceCall::fromString($itemData[$this->itemExecutions[$this->current]['itemIndex']]); return $serviceCall; }
/** * Create the item's ServiceCall. * * @param core_kernel_classes_Resource $item * @param tao_models_classes_service_StorageDirectory $destinationDirectory * @return tao_models_classes_service_ServiceCall */ protected function createService(core_kernel_classes_Resource $item, tao_models_classes_service_StorageDirectory $destinationDirectory) { $service = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(INSTANCE_SERVICE_ITEMRUNNER)); $service->addInParameter(new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_ITEMPATH), $destinationDirectory->getId())); $service->addInParameter(new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_ITEMURI), $item)); return $service; }
/** * Build the Service Call definition that makes TAO able to run the compiled test * later on at delivery time. * * @return tao_models_classes_service_ServiceCall */ protected function buildServiceCall() { $service = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(INSTANCE_QTITEST_TESTRUNNERSERVICE)); $param = new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_QTITEST_TESTDEFINITION), $this->getResource()); $service->addInParameter($param); $param = new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_QTITEST_TESTCOMPILATION), $this->getPrivateDirectory()->getId() . '|' . $this->getPublicDirectory()->getId()); $service->addInParameter($param); return $service; }
protected function assertCorresponds(core_kernel_classes_Resource $step1, core_kernel_classes_Resource $step2) { //echo 'Compare '.$step1->getLabel().' and '.$step2->getLabel().'<br />'; $services1 = wfEngine_models_classes_ActivityService::singleton()->getInteractiveServices($step1); $services2 = wfEngine_models_classes_ActivityService::singleton()->getInteractiveServices($step2); $this->assertEquals(count($services1), count($services2)); if (count($services1) == count($services2)) { foreach ($services1 as $service1) { $service2 = array_shift($services2); $call1 = tao_models_classes_service_ServiceCall::fromResource($service1); $call2 = tao_models_classes_service_ServiceCall::fromResource($service2); $this->assertEquals($call1->serializeToString(), $call2->serializeToString()); } } }
public function index() { if (is_null($this->processExecution)) { common_Logger::w('ProcessBrowser invoked without processExecution'); $this->redirectToMain(); return; } if ($this->autoRedirecting) { $this->autoredirectToIndex(); return; } /* * @todo: clean usage * known use of Session::setAttribute("processUri") in: * - taoDelivery_actions_ItemDelivery::runner() * - tao_actions_Api::createAuthEnvironment() */ $this->setSessionAttribute("processUri", $this->processExecution->getUri()); //user data for browser view $userViewData = wfEngine_helpers_UsersHelper::buildCurrentUserForView(); $this->setData('userViewData', $userViewData); $browserViewData = array(); // general data for browser view. //init services: $userService = wfEngine_models_classes_UserService::singleton(); $activityService = wfEngine_models_classes_ActivityService::singleton(); $interactiveServiceService = wfEngine_models_classes_InteractiveServiceService::singleton(); //get current user: $currentUser = $userService->getCurrentUser(); if (is_null($currentUser)) { throw new wfEngine_models_classes_ProcessExecutionException("No current user found!"); } //get activity execution from currently available process definitions: $currentlyAvailableActivityExecutions = $this->processExecutionService->getAvailableCurrentActivityExecutions($this->processExecution, $currentUser, true); $activityExecution = null; if (count($currentlyAvailableActivityExecutions) == 0) { common_Logger::w('No available current activity exec found: no permission or issue in process execution'); $this->pause(); return; } else { if (!is_null($this->activityExecution) && $this->activityExecution instanceof core_kernel_classes_Resource) { foreach ($currentlyAvailableActivityExecutions as $availableActivityExec) { if ($availableActivityExec->getUri() == $this->activityExecution->getUri()) { $activityExecution = $this->processExecutionService->initCurrentActivityExecution($this->processExecution, $this->activityExecution, $currentUser); break; } } if (is_null($activityExecution)) { //invalid choice of activity execution: $this->activityExecution = null; // $invalidActivity = new core_kernel_classes_Resource($activityUri); // throw new wfEngine_models_classes_ProcessExecutionException("invalid choice of activity definition in process browser {$invalidActivity->getLabel()} ({$invalidActivity->getUri()}). \n<br/> The link may be outdated."); $this->autoredirectToIndex(); return; } } else { if (count($currentlyAvailableActivityExecutions) == 1) { $activityExecution = $this->processExecutionService->initCurrentActivityExecution($this->processExecution, reset($currentlyAvailableActivityExecutions), $currentUser); if (is_null($activityExecution)) { throw new wfEngine_models_classes_ProcessExecutionException('cannot initiate the activity execution of the unique next activity definition'); } } else { //count > 1: //parallel branch, ask the user to select activity to execute: common_Logger::i('Ask the user to select activity'); $this->pause(); return; } } } if (!is_null($activityExecution)) { $this->activityExecution = $activityExecution; $browserViewData[''] = $this->processExecution->getUri(); $browserViewData['activityExecutionUri'] = $activityExecution->getUri(); $this->activityExecutionService->createNonce($this->activityExecution); $browserViewData['activityExecutionNonce'] = $this->activityExecutionService->getNonce($activityExecution); //get interactive services (call of services): $activityDefinition = $this->activityExecutionService->getExecutionOf($activityExecution); $interactiveServices = $activityService->getInteractiveServices($activityDefinition); $services = array(); foreach ($interactiveServices as $interactiveService) { $serviceCallModel = tao_models_classes_service_ServiceCall::fromResource($interactiveService); $vars = $serviceCallModel->getRequiredVariables(); $parameters = array(); foreach ($vars as $variable) { $key = (string) $variable->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_PROCESSVARIABLES_CODE)); $value = $activityExecution->getOnePropertyValue(new core_kernel_classes_Property($variable)); if ($value instanceof core_kernel_classes_Resource) { $parameters[$key] = $value->getUri(); } elseif ($value instanceof core_kernel_classes_Literal) { $parameters[$key] = (string) $value; } } $serviceCallId = $activityExecution->getUri() . (count($interactiveServices) == 1 ? '' : $interactiveService->getUri()); $jsServiceApi = tao_helpers_ServiceJavascripts::getServiceApi($serviceCallModel, $serviceCallId, $parameters); $services[] = array('style' => $interactiveServiceService->getStyle($interactiveService), 'api' => $jsServiceApi); } $this->setData('services', $services); //set activity control: $controls = $activityService->getControls($activityDefinition); $browserViewData['controls'] = array('backward' => isset($controls[INSTANCE_CONTROL_BACKWARD]) ? (bool) $controls[INSTANCE_CONTROL_BACKWARD] : false, 'forward' => isset($controls[INSTANCE_CONTROL_FORWARD]) ? (bool) $controls[INSTANCE_CONTROL_FORWARD] : false); // If paused, resume it: if ($this->processExecutionService->isFinished($this->processExecution)) { $this->processExecutionService->resume($this->processExecution); } //get process definition: $processDefinition = $this->processExecutionService->getExecutionOf($this->processExecution); // Browser view main data. $browserViewData['processLabel'] = $processDefinition->getLabel(); $browserViewData['processExecutionLabel'] = $this->processExecution->getLabel(); $browserViewData['activityLabel'] = $activityDefinition->getLabel(); $browserViewData['processUri'] = $this->processExecution->getUri(); $browserViewData['active_Resource'] = "'" . $activityDefinition->getUri() . "'"; $browserViewData['isInteractiveService'] = true; $this->setData('browserViewData', $browserViewData); $this->setData('activity', $activityDefinition); /* <DEBUG> :populate the debug widget */ if (DEBUG_MODE) { $this->setData('debugWidget', DEBUG_MODE); $servicesResources = array(); foreach ($services as $service) { $servicesResource = $service; $servicesResource['input'] = $interactiveServiceService->getInputValues($interactiveService, $activityExecution); $servicesResource['output'] = $interactiveServiceService->getOutputValues($interactiveService, $activityExecution); $servicesResources[] = $servicesResource; } $variableService = wfEngine_models_classes_VariableService::singleton(); $this->setData('debugData', array('Activity' => $activityDefinition, 'ActivityExecution' => $activityExecution, 'CurrentActivities' => $currentlyAvailableActivityExecutions, 'Services' => $servicesResources, 'VariableStack' => $variableService->getAll())); } /* </DEBUG> */ $this->setData('activityExecutionUri', $browserViewData['activityExecutionUri']); $this->setData('processUri', $browserViewData['processUri']); $this->setData('activityExecutionNonce', $browserViewData['activityExecutionNonce']); $this->setData('client_config_url', $this->getClientConfigUrl()); $this->setView('process_browser.tpl'); } }
/** * Gets the service call to run this assembly * * @param core_kernel_classes_Resource $assembly * @return tao_models_classes_service_ServiceCall */ public function getRuntime(core_kernel_classes_Resource $assembly) { $runtimeResource = $assembly->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_RUNTIME)); return tao_models_classes_service_ServiceCall::fromResource($runtimeResource); }