FOSSology  4.7.1
Open Source License Compliance by Open Source Software
ConfController.php
Go to the documentation of this file.
1 <?php
2 /*
3  Author: Soham Banerjee <sohambanerjee4abc@hotmail.com>
4  SPDX-FileCopyrightText: © 2023 Soham Banerjee <sohambanerjee4abc@hotmail.com>
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
13 namespace Fossology\UI\Api\Controllers;
14 
22 use Psr\Http\Message\ServerRequestInterface;
23 
25 {
35  public function getConfInfo($request, $response, $args)
36  {
37  $uploadPk = $args["id"];
38  $this->uploadAccessible($uploadPk);
39 
40  $uploadDao = $this->restHelper->getUploadDao();
41  $response_view = $uploadDao->getReportInfo($uploadPk);
42  $response_view['ri_cyclonedx_selection'] =
43  $uploadDao->getCyclonedxSettings($uploadPk)->toReportInfo();
44  $returnVal = new Conf($response_view);
45  return $response->withJson($returnVal->getArray(), 200);
46  }
47 
57  public function updateConfData($request, $response, $args)
58  {
59  $uploadPk = $args["id"];
60  $body = $this->getParsedBody($request);
61  $confObj = new Conf();
62 
63  $this->uploadAccessible($uploadPk);
64 
65  if (empty($body) || !array_key_exists("key", $body) ||
66  !array_key_exists("value", $body)) {
67  throw new HttpBadRequestException("Invalid request.");
68  } elseif (!$confObj->doesKeyExist($body['key'])) {
69  throw new HttpBadRequestException("Invalid key " . $body["key"] .
70  " sent.");
71  }
72 
73  $key = $body['key'];
74  $value = $body['value'];
75  try {
76  $result = $this->restHelper->getUploadDao()->updateReportInfo($uploadPk,
77  $confObj->getKeyColumnName($key), $value);
78  } catch (\UnexpectedValueException $e) {
79  throw new HttpBadRequestException($e->getMessage(), $e);
80  }
81 
82  if ($result) {
83  $info = new Info(200, "Successfully updated " . $key, InfoType::INFO);
84  } else {
85  throw new HttpInternalServerErrorException("Failed to update " . $key);
86  }
87  return $response->withJson($info->getarray(), $info->getCode());
88  }
89 }
updateConfData($request, $response, $args)
getConfInfo($request, $response, $args)
Base controller for REST calls.
getParsedBody(ServerRequestInterface $request)
Parse request body as JSON and return associative PHP array.
Override Slim response for withJson function.
Conf model to contain general error and return values.
Definition: Conf.php:23
Different type of infos provided by REST.
Definition: InfoType.php:16
Info model to contain general error and return values.
Definition: Info.php:19