DataloadController   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 214
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 214
rs 10
c 0
b 0
f 0
wmc 18

13 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteDataSimulate() 0 7 2
A create() 0 3 1
A importClipboard() 0 7 2
A updateData() 0 7 2
A __construct() 0 10 1
A execute() 0 3 1
A delete() 0 3 1
A update() 0 3 1
A simulate() 0 3 1
A deleteData() 0 7 2
A copy() 0 3 1
A read() 0 3 1
A importFile() 0 7 2
1
<?php
2
/**
3
 * Analytics
4
 *
5
 * SPDX-FileCopyrightText: 2019-2022 Marcel Scherello
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8
9
namespace OCA\Analytics\Controller;
10
11
use Exception;
12
use OCA\Analytics\Service\DataloadService;
13
use OCP\AppFramework\Controller;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use OCP\AppFramework\Http\DataResponse;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Http\DataResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use OCP\AppFramework\Http\NotFoundResponse;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Http\NotFoundResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use OCP\Files\NotFoundException;
0 ignored issues
show
Bug introduced by
The type OCP\Files\NotFoundException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use OCP\IRequest;
0 ignored issues
show
Bug introduced by
The type OCP\IRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
20
class DataloadController extends Controller
21
{
22
    private $logger;
23
    private $DataloadService;
24
25
    public function __construct(
26
        string $appName,
27
        IRequest $request,
28
        LoggerInterface $logger,
29
        DataloadService $DataloadService
30
    )
31
    {
32
        parent::__construct($appName, $request);
33
        $this->logger = $logger;
34
        $this->DataloadService = $DataloadService;
35
    }
36
37
    /**
38
     * create a new dataload
39
     *
40
     * @NoAdminRequired
41
     * @param $datasetId
42
     * @param int $datasourceId
43
     * @return DataResponse
44
     * @throws \OCP\DB\Exception
45
     */
46
    public function create($datasetId, int $datasourceId): DataResponse
47
    {
48
        return new DataResponse(['id' => $this->DataloadService->create($datasetId, $datasourceId)]);
49
    }
50
51
    /**
52
     * get all data loads for a dataset or report
53
     *
54
     * @NoAdminRequired
55
     * @param $datasetId
56
     * @param $reportId
57
     * @return DataResponse
58
     */
59
    public function read($datasetId): DataResponse
60
    {
61
        return new DataResponse(['dataloads' => $this->DataloadService->read($datasetId)]);
62
    }
63
64
    /**
65
     * update dataload
66
     *
67
     * @NoAdminRequired
68
     * @param int $dataloadId
69
     * @param $name
70
     * @param $option
71
     * @param $schedule
72
     * @return DataResponse
73
     */
74
    public function update(int $dataloadId, $name, $option, $schedule): DataResponse
75
    {
76
        return new DataResponse(['update' => $this->DataloadService->update($dataloadId, $name, $option, $schedule)]);
77
    }
78
79
    /**
80
     * copy a dataload
81
     *
82
     * @NoAdminRequired
83
     * @param int $dataloadId
84
     * @return DataResponse
85
     * @throws NotFoundException
86
     */
87
    public function copy(int $dataloadId): DataResponse
88
    {
89
        return new DataResponse($this->DataloadService->copy($dataloadId));
90
    }
91
92
    /**
93
     * delete a dataload
94
     *
95
     * @NoAdminRequired
96
     * @param int $dataloadId
97
     * @return bool
98
     */
99
    public function delete(int $dataloadId): bool
100
    {
101
        return $this->DataloadService->delete($dataloadId);
102
    }
103
104
    /**
105
     * simulate a dataload and output its data
106
     *
107
     * @NoAdminRequired
108
     * @param int $dataloadId
109
     * @return DataResponse
110
     * @throws NotFoundException
111
     */
112
    public function simulate(int $dataloadId): DataResponse
113
    {
114
        return new DataResponse($this->DataloadService->getDataFromDatasource($dataloadId));
115
    }
116
117
    /**
118
     * execute a dataload from datasource and store into dataset
119
     *
120
     * @NoAdminRequired
121
     * @param int $dataloadId
122
     * @return DataResponse
123
     * @throws Exception
124
     */
125
    public function execute(int $dataloadId): DataResponse
126
    {
127
        return new DataResponse($this->DataloadService->execute($dataloadId));
128
    }
129
130
131
    // Data Manipulation
132
    // Data Manipulation
133
    // Data Manipulation
134
135
    /**
136
     * update data from input form
137
     *
138
     * @NoAdminRequired
139
     * @param int $reportId
140
     * @param $dimension1
141
     * @param $dimension2
142
     * @param $value
143
     * @param bool $isDataset
144
     * @return DataResponse|NotFoundResponse
145
     * @throws Exception
146
     */
147
    public function updateData(int $reportId, $dimension1, $dimension2, $value, bool $isDataset)
148
    {
149
        $result = $this->DataloadService->updateData($reportId, $dimension1, $dimension2, $value, $isDataset);
150
        if ($result) {
151
            return new DataResponse($result);
152
        } else {
153
            return new NotFoundResponse();
154
        }
155
    }
156
157
    /**
158
     * delete data from input form
159
     *
160
     * @NoAdminRequired
161
     * @param int $reportId
162
     * @param $dimension1
163
     * @param $dimension2
164
     * @param bool $isDataset
165
     * @return DataResponse|NotFoundResponse
166
     */
167
    public function deleteData(int $reportId, $dimension1, $dimension2, bool $isDataset)
168
    {
169
        $result = $this->DataloadService->deleteData($reportId, $dimension1, $dimension2, $isDataset);
170
        if ($result) {
171
            return new DataResponse($result);
172
        } else {
173
            return new NotFoundResponse();
174
        }
175
    }
176
177
    /**
178
     * Simulate delete data from input form
179
     *
180
     * @NoAdminRequired
181
     * @param int $reportId
182
     * @param $dimension1
183
     * @param $dimension2
184
     * @param bool $isDataset
185
     * @return DataResponse|NotFoundResponse
186
     */
187
    public function deleteDataSimulate(int $reportId, $dimension1, $dimension2, bool $isDataset)
188
    {
189
        $result = $this->DataloadService->deleteDataSimulate($reportId, $dimension1, $dimension2, $isDataset);
190
        if ($result) {
191
            return new DataResponse($result);
192
        } else {
193
            return new NotFoundResponse();
194
        }
195
    }
196
197
    /**
198
     * Import clipboard data
199
     *
200
     * @NoAdminRequired
201
     * @param int $reportId
202
     * @param $import
203
     * @param bool $isDataset
204
     * @return DataResponse|NotFoundResponse
205
     * @throws Exception
206
     */
207
    public function importClipboard(int $reportId, $import, bool $isDataset)
208
    {
209
        $result = $this->DataloadService->importClipboard($reportId, $import, $isDataset);
210
        if ($result) {
211
            return new DataResponse($result);
212
        } else {
213
            return new NotFoundResponse();
214
        }
215
    }
216
217
    /**
218
     * Import data into dataset from an internal or external file
219
     *
220
     * @NoAdminRequired
221
     * @param int $reportId
222
     * @param $path
223
     * @param bool $isDataset
224
     * @return DataResponse|NotFoundResponse
225
     * @throws Exception
226
     */
227
    public function importFile(int $reportId, $path, bool $isDataset)
228
    {
229
        $result = $this->DataloadService->importFile($reportId, $path, $isDataset);
230
        if ($result) {
231
            return new DataResponse($result);
232
        } else {
233
            return new NotFoundResponse();
234
        }
235
    }
236
}