/**
  * Funkce pro nalezení datového zdroje s kontrolou oprávnění přístupu
  * @param int $datasourceId
  * @throws BadRequestException
  * @return Datasource
  */
 private function findDatasourceWithCheckAccess($datasourceId)
 {
     try {
         $datasource = $this->datasourcesFacade->findDatasource($datasourceId);
         if (!$this->datasourcesFacade->checkDatasourceAccess($datasource, $this->getCurrentUser())) {
             throw new BadRequestException("You are not authorized to use the selected datasource!");
         }
     } catch (\Exception $e) {
         throw new BadRequestException("Requested datasource was not found or is not accessible!");
     }
     return $datasource;
 }
 /**
  * Akce pro vyhodnocení klasifikace
  * @SWG\Get(
  *   tags={"Evaluation"},
  *   path="/evaluation/classification",
  *   summary="Evaluate classification model",
  *   produces={"application/json","application/xml"},
  *   security={{"apiKey":{}},{"apiKeyHeader":{}}},
  *   @SWG\Parameter(
  *     name="scorer",
  *     description="Scorer type",
  *     required=true,
  *     type="string",
  *     in="query",
  *     enum={"easyMinerScorer","modelTester"}
  *   ),
  *   @SWG\Parameter(
  *     name="task",
  *     description="Task ID",
  *     required=false,
  *     type="integer",
  *     in="query"
  *   ),
  *   @SWG\Parameter(
  *     name="ruleSet",
  *     description="Rule set ID",
  *     required=false,
  *     type="integer",
  *     in="query"
  *   ),
  *   @SWG\Parameter(
  *     name="datasource",
  *     description="Datasource ID (if not specified, task datasource will be used)",
  *     required=false,
  *     type="integer",
  *     in="query"
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="Evaluation result",
  *     @SWG\Schema(
  *       ref="#/definitions/ScoringResultResponse"
  *     )
  *   ),
  *   @SWG\Response(
  *     response=400,
  *     description="Invalid API key supplied",
  *     @SWG\Schema(ref="#/definitions/StatusResponse")
  *   )
  * )
  *
  * @throws BadRequestException
  * @throws NotImplementedException
  */
 public function actionClassification()
 {
     $this->setXmlMapperElements('classification');
     $inputData = $this->getInput()->getData();
     /** @var IScorerDriver $scorerDriver */
     if (empty($inputData['scorer'])) {
         $scorerDriver = $this->scorerDriverFactory->getDefaultScorerInstance();
     } else {
         $scorerDriver = $this->scorerDriverFactory->getScorerInstance($inputData['scorer']);
     }
     if (!empty($inputData['datasource'])) {
         try {
             $datasource = $this->datasourcesFacade->findDatasource(@$inputData['datasource']);
             if (!$this->datasourcesFacade->checkDatasourceAccess($datasource, $this->getCurrentUser())) {
                 throw new \Exception();
             }
         } catch (\Exception $e) {
             throw new BadRequestException("Requested data source was not found!");
         }
     } elseif (!empty($inputData['task'])) {
         $task = $this->findTaskWithCheckAccess($inputData['task']);
         $datasource = $task->miner->datasource;
     } else {
         throw new BadRequestException("Data source was not specified!");
     }
     if (!empty($inputData['task'])) {
         if (empty($task)) {
             $task = $this->findTaskWithCheckAccess($inputData['task']);
         }
         $result = $scorerDriver->evaluateTask($task, $datasource)->getCorrectIncorrectDataArr();
         $result['task'] = $task->getDataArr(false);
     } elseif (!empty($inputData['ruleSet'])) {
         $ruleSet = $this->ruleSetsFacade->findRuleSet($inputData['ruleSet']);
         //TODO kontrola oprávnění k rule setu
         $result = $scorerDriver->evaluateRuleSet($ruleSet, $datasource)->getDataArr();
         $result['ruleSet'] = $ruleSet->getDataArr();
     } else {
         throw new BadRequestException("No task or rule set found!");
     }
     $this->resource = $result;
     $this->sendResource();
 }
 /**
  * Funkce pro kontrolu vstupů pro vytvoření nového mineru
  */
 public function validateCreate()
 {
     $currentUser = $this->getCurrentUser();
     /** @noinspection PhpMethodParametersCountMismatchInspection */
     $this->input->field('name')->addRule(IValidator::REQUIRED, 'Name is required!');
     /** @noinspection PhpMethodParametersCountMismatchInspection */
     $this->input->field('type')->addRule(IValidator::REQUIRED, 'Miner type is required!');
     /** @noinspection PhpMethodParametersCountMismatchInspection */
     $this->input->field('datasourceId')->addRule(IValidator::REQUIRED, 'Datasource ID is required!')->addRule(IValidator::CALLBACK, 'Requested datasource was not found, or is not accessible!', function ($value) use($currentUser) {
         try {
             $this->datasource = $this->datasourcesFacade->findDatasource($value);
             if ($this->datasourcesFacade->checkDatasourceAccess($this->datasource, $currentUser)) {
                 //kontrola dostupnosti kompatibilního mineru s vybraným datasource
                 $availableMinerTypes = $this->minersFacade->getAvailableMinerTypes($this->datasource->type);
                 return !empty($availableMinerTypes[$this->getInput()->getData()['type']]);
             } else {
                 return false;
             }
         } catch (\Exception $e) {
             return false;
         }
     });
     /** @noinspection PhpMethodParametersCountMismatchInspection */
     $this->input->field('ruleSetId')->addRule(IValidator::CALLBACK, 'Requested rule set was not found, or is not accessible!', function ($value) use($currentUser) {
         if (empty($value)) {
             return true;
         }
         try {
             $this->ruleSet = $this->ruleSetsFacade->findRuleSet($value);
             $this->ruleSetsFacade->checkRuleSetAccess($this->ruleSet, $currentUser);
             return true;
         } catch (\Exception $e) {
             return false;
         }
     });
 }