1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Data Analytics |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the LICENSE.md file. |
7
|
|
|
* |
8
|
|
|
* @author Marcel Scherello <[email protected]> |
9
|
|
|
* @copyright 2019 Marcel Scherello |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Analytics\Controller; |
13
|
|
|
|
14
|
|
|
use OCA\Analytics\Datasource\ExternalFileService; |
15
|
|
|
use OCA\Analytics\Datasource\FileService; |
16
|
|
|
use OCA\Analytics\Datasource\GithubService; |
17
|
|
|
use OCP\AppFramework\Controller; |
18
|
|
|
use OCP\Files\NotFoundException; |
19
|
|
|
use OCP\ILogger; |
20
|
|
|
use OCP\IRequest; |
21
|
|
|
|
22
|
|
|
class DataSourceController extends Controller |
23
|
|
|
{ |
24
|
|
|
private $logger; |
25
|
|
|
private $GithubService; |
26
|
|
|
private $FileService; |
27
|
|
|
private $ExternalFileService; |
28
|
|
|
private $userId; |
29
|
|
|
|
30
|
|
|
const DATASET_TYPE_GROUP = 0; |
31
|
|
|
const DATASET_TYPE_INTERNAL_FILE = 1; |
32
|
|
|
const DATASET_TYPE_INTERNAL_DB = 2; |
33
|
|
|
const DATASET_TYPE_GIT = 3; |
34
|
|
|
const DATASET_TYPE_EXTERNAL_FILE = 4; |
35
|
|
|
|
36
|
|
|
public function __construct( |
37
|
|
|
string $AppName, |
38
|
|
|
IRequest $request, |
39
|
|
|
$userId, |
40
|
|
|
ILogger $logger, |
41
|
|
|
GithubService $GithubService, |
42
|
|
|
FileService $FileService, |
43
|
|
|
ExternalFileService $ExternalFileService |
44
|
|
|
) |
45
|
|
|
{ |
46
|
|
|
parent::__construct($AppName, $request); |
47
|
|
|
$this->userId = $userId; |
48
|
|
|
$this->logger = $logger; |
49
|
|
|
$this->ExternalFileService = $ExternalFileService; |
50
|
|
|
$this->GithubService = $GithubService; |
51
|
|
|
$this->FileService = $FileService; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the data from a datasource; |
56
|
|
|
* |
57
|
|
|
* @NoAdminRequired |
58
|
|
|
* @param $datasetMetadata |
59
|
|
|
* @param null $options |
|
|
|
|
60
|
|
|
* @return array |
61
|
|
|
* @throws NotFoundException |
62
|
|
|
*/ |
63
|
|
|
public function read($datasetMetadata, $options = null) |
64
|
|
|
{ |
65
|
|
|
$datasetMetadata['type'] = (int)$datasetMetadata['type']; |
66
|
|
|
//$this->logger->error('DataSourceController 65: '. $datasetMetadata['type']); |
67
|
|
|
if ($datasetMetadata['type'] === self::DATASET_TYPE_INTERNAL_FILE) $result = $this->FileService->read($datasetMetadata, $options); |
68
|
|
|
elseif ($datasetMetadata['type'] === self::DATASET_TYPE_GIT) $result = $this->GithubService->read($datasetMetadata); |
69
|
|
|
elseif ($datasetMetadata['type'] === self::DATASET_TYPE_EXTERNAL_FILE) $result = $this->ExternalFileService->read($datasetMetadata); |
70
|
|
|
else $result = new NotFoundException(); |
71
|
|
|
|
72
|
|
|
return $result; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |