* get the data from data source * to be used in simulation or execution * * @param int $dataloadId * @param string|null $file * @return array|NotFoundResponse * @throws NotFoundResponse * @throws \OCP\DB\Exception */
(int $dataloadId, ?string $file = null, bool $enforceOwnership = true)
| 306 | * @throws \OCP\DB\Exception |
| 307 | */ |
| 308 | public function getDataFromDatasource(int $dataloadId, ?string $file = null, bool $enforceOwnership = true) |
| 309 | { |
| 310 | $dataloadMetadata = $this->getDataloadMetadata($dataloadId, $enforceOwnership); |
| 311 | |
| 312 | if (!empty($dataloadMetadata)) { |
| 313 | |
| 314 | if ($dataloadMetadata['datasource'] !== 0) { |
| 315 | $dataloadMetadata['link'] = $dataloadMetadata['option']; //remap until data source table is renamed link=>option |
| 316 | unset($dataloadMetadata['cacheKey']); |
| 317 | if ($file !== null && $file !== '') { |
| 318 | $option = json_decode($dataloadMetadata['link'], true); |
| 319 | if (!is_array($option)) { |
| 320 | $option = []; |
| 321 | } |
| 322 | $option['link'] = $file; |
| 323 | $option['file'] = $file; |
| 324 | $dataloadMetadata['link'] = json_encode($option); |
| 325 | $this->logger->info('Analytics flow dataload file override', [ |
| 326 | 'dataloadId' => $dataloadId, |
| 327 | 'datasetId' => $dataloadMetadata['dataset'], |
| 328 | 'datasourceId' => $dataloadMetadata['datasource'], |
| 329 | 'file' => $file, |
| 330 | 'filename' => basename($file), |
| 331 | ]); |
| 332 | } |
| 333 | |
| 334 | $result = $this->DatasourceController->read((int)$dataloadMetadata['datasource'], $dataloadMetadata, false); |
| 335 | $result['datasetId'] = $dataloadMetadata['dataset']; |
| 336 | } else { |
| 337 | // this is a deletion request. Just run the simulation and return the possible row count in the expected result array |
| 338 | $option = json_decode($dataloadMetadata['option'], true); |
| 339 | |
| 340 | // deletion jobs are using the same dimension/option/value settings a report filter |
| 341 | $filter = array(); |
| 342 | $filter['filteroptions'] = '{"filter":{"' . $option['filterDimension'] . '":{"option":"' . $option['filterOption'] . '","value":"' . $option['filterValue'] . '"}}}'; |
| 343 | // Text variables like %xx% could be in use here |
| 344 | $filter = $this->VariableService->replaceFilterVariables($filter); |
| 345 | |
| 346 | $result = [ |
| 347 | 'header' => '', |
| 348 | 'dimensions' => '', |
| 349 | 'data' => $this->StorageService->deleteWithFilterSimulate($dataloadMetadata['dataset'], json_decode($filter['filteroptions'], true)), |
| 350 | 'error' => 0, |
| 351 | ]; |
| 352 | } |
| 353 | |
| 354 | return $result; |
| 355 | } else { |
| 356 | return new NotFoundResponse(); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | // Data Manipulation |
| 361 | // Data Manipulation |