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 int $datasource |
59
|
|
|
* @param $option |
60
|
|
|
* @return array|NotFoundException |
61
|
|
|
* @throws NotFoundException |
62
|
|
|
*/ |
63
|
|
|
public function read(int $datasource, $option) |
64
|
|
|
{ |
65
|
|
|
//$this->logger->debug('DataSourceController 66: Datasource Id: ' . $datasource . ', Option: ' . json_encode($option)); |
66
|
|
|
if ($datasource === self::DATASET_TYPE_INTERNAL_FILE) $result = $this->FileService->read($option); |
67
|
|
|
elseif ($datasource === self::DATASET_TYPE_GIT) $result = $this->GithubService->read($option); |
68
|
|
|
elseif ($datasource === self::DATASET_TYPE_EXTERNAL_FILE) $result = $this->ExternalFileService->read($option); |
69
|
|
|
else $result = new NotFoundException(); |
70
|
|
|
|
71
|
|
|
return $result; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* template for options & settings |
76
|
|
|
* |
77
|
|
|
* @NoAdminRequired |
78
|
|
|
* @param int $datasource |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function getTemplates() |
82
|
|
|
{ |
83
|
|
|
$result[self::DATASET_TYPE_INTERNAL_FILE] = $this->FileService->getTemplate(); |
|
|
|
|
84
|
|
|
$result[self::DATASET_TYPE_GIT] = $this->GithubService->getTemplate(); |
85
|
|
|
$result[self::DATASET_TYPE_EXTERNAL_FILE] = $this->ExternalFileService->getTemplate(); |
86
|
|
|
return $result; |
87
|
|
|
} |
88
|
|
|
} |