60 public function getReport($request, $response, $args)
62 $uploadId = $request->getHeaderLine(
'uploadId');
63 $reportFormat = $request->getHeaderLine(
'reportFormat');
65 if (! in_array($reportFormat, $this->reportsAllowed)) {
66 $error =
new Info(400,
67 "reportFormat must be from [" . implode(
",", $this->reportsAllowed) .
"]",
69 return $response->withJson($error->getArray(), $error->getCode());
72 if (get_class($upload) === Info::class) {
73 return $response->withJson($upload->getArray(), $upload->getCode());
80 switch ($reportFormat) {
81 case $this->reportsAllowed[0]:
82 case $this->reportsAllowed[1]:
83 case $this->reportsAllowed[2]:
84 $spdxGenerator = $this->restHelper->getPlugin(
'ui_spdx2');
85 list ($jobId, $jobQueueId, $error) = $spdxGenerator->scheduleAgent(
88 case $this->reportsAllowed[3]:
89 $readmeGenerator = $this->restHelper->getPlugin(
'ui_readmeoss');
90 list ($jobId, $jobQueueId, $error) = $readmeGenerator->scheduleAgent(
93 case $this->reportsAllowed[4]:
94 $unifiedGenerator = $this->restHelper->getPlugin(
'agent_founifiedreport');
95 list ($jobId, $jobQueueId, $error) = $unifiedGenerator->scheduleAgent(
99 $error =
new Info(500,
"Some error occured!", InfoType::ERROR);
100 return $response->withJson($error->getArray(), $error->getCode());
102 }
catch (\Exception $e) {
103 $error =
new Info(500, $e->getMessage(), InfoType::ERROR);
104 return $response->withJson($error->getArray(), $error->getCode());
106 if (! empty($error)) {
107 $info =
new Info(500, $error, InfoType::ERROR);
110 $info =
new Info(201, $download_path, InfoType::INFO);
112 return $response->withJson($info->getArray(), $info->getCode());
124 if (empty($uploadId) || ! is_numeric($uploadId) || $uploadId <= 0) {
125 $upload =
new Info(400,
"uploadId must be a positive integer!",
128 $uploadDao = $this->restHelper->getUploadDao();
129 if (! $uploadDao->isAccessible($uploadId, $this->restHelper->getGroupId())) {
130 $upload =
new Info(403,
"Upload is not accessible!", InfoType::ERROR);
132 if ($upload !== null) {
135 $upload = $uploadDao->getUpload($uploadId);
136 if ($upload === null) {
137 $upload =
new Info(404,
"Upload does not exists!", InfoType::ERROR);
150 $path = $request->getUri()->getHost();
151 $path .= $request->getRequestTarget();
152 $url_parts = parse_url($path);
154 if (array_key_exists(
"scheme", $url_parts)) {
155 $download_path .= $url_parts[
"scheme"] .
"://";
157 if (array_key_exists(
"user", $url_parts)) {
158 $download_path .= $url_parts[
"user"];
160 if (array_key_exists(
"pass", $url_parts)) {
161 $download_path .=
':' . $url_parts[
"pass"];
163 if (array_key_exists(
"host", $url_parts)) {
164 $download_path .= $url_parts[
"host"];
166 if (array_key_exists(
"port", $url_parts)) {
167 $download_path .=
':' . $url_parts[
"port"];
169 if ($url_parts[
"path"][-1] !==
'/') {
170 $url_parts[
"path"] .=
'/';
172 $download_path .= $url_parts[
"path"] . $jobId;
173 if (array_key_exists(
"query", $url_parts)) {
174 $download_path .=
'?' . $url_parts[
"query"];
176 if (array_key_exists(
"fragment", $url_parts)) {
177 $download_path .=
'#' . $url_parts[
"fragment"];
179 return $download_path;
190 public function downloadReport($request, $response, $args)
194 if ($returnVal !==
true) {
195 $newResponse = $response;
196 if ($returnVal->getCode() == 503) {
197 $newResponse = $response->withHeader(
'Retry-After',
'10');
199 return $newResponse->withJson($returnVal->getArray(),
200 $returnVal->getCode());
202 $ui_download = $this->restHelper->getPlugin(
'download');
207 $responseFile = $ui_download->getReport($args[
'id']);
208 $responseContent = $responseFile->getFile();
209 $newResponse = $response->withHeader(
'Content-Description',
211 ->withHeader(
'Content-Type',
212 $responseFile->headers->get(
'Content-Type'))
213 ->withHeader(
'Content-Disposition',
214 $responseFile->headers->get(
'Content-Disposition'))
215 ->withHeader(
'Cache-Control',
'must-revalidate')
216 ->withHeader(
'Pragma',
'private')
217 ->withHeader(
'Content-Length', filesize($responseContent));
219 readfile($responseContent);
221 }
catch (\Exception $e) {
222 $error =
new Info(500, $e->getMessage(), InfoType::ERROR);
223 return $response->withJson($error->getArray(), $error->getCode());
235 $dbManager = $this->dbHelper->getDbManager();
236 $row = $dbManager->getSingleRow(
237 'SELECT jq_type FROM jobqueue WHERE jq_job_fk = $1', array(
239 ),
"reportValidity");
240 if (! in_array($row[
'jq_type'], $this->reportsAllowed)) {
241 return new Info(404,
"No report scheduled with given job id.",
244 $row = $dbManager->getSingleRow(
'SELECT job_upload_fk FROM job WHERE job_pk = $1',
245 array($id),
"reportFileUpload");
246 $uploadId = intval($row[
'job_upload_fk']);
247 $uploadDao = $this->restHelper->getUploadDao();
248 if (! $uploadDao->isAccessible($uploadId, $this->restHelper->getGroupId())) {
249 return new Info(403,
"Report is not accessible.", InfoType::INFO);
251 $row = $dbManager->getSingleRow(
'SELECT * FROM reportgen WHERE job_fk = $1',
252 array($id),
"reportFileName");
253 if ($row ===
false) {
254 return new Info(503,
"Report is not ready. Retry after 10s.", InfoType::INFO);
Base controller for REST calls.
Controller for report path.
buildDownloadPath($request, $jobId)
getReport($request, $response, $args)
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Info model to contain general error and return values.
static getGroupId()
Get the current user's group id.