13 namespace Fossology\UI\Api\Controllers;
25 use Psr\Http\Message\ServerRequestInterface;
26 use Slim\Psr7\Factory\StreamFactory;
39 $this->obligationMap = $this->container->get(
'businessrules.obligationmap');
54 $listVal = $this->obligationMap->getObligations();
55 foreach ($listVal as $val) {
56 $row[
'id'] = intval($val[
'ob_pk']);
57 $row[$apiVersion == ApiVersion::V2 ?
'obligationTopic' :
'obligation_topic'] = $val[
'ob_topic'];
60 return $response->withJson($finVal, 200);
74 $obligationId = intval($args[
'id']);
75 if (!$this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obligationId)) {
80 return $response->withJson($obligation->getArray(), 200);
93 $obligationArray = [];
94 $listVal = $this->obligationMap->getObligations();
95 foreach ($listVal as $val) {
96 $obligationId = intval($val[
'ob_pk']);
100 return $response->withJson($obligationArray, 200);
111 $obligationInfo = $this->obligationMap->getObligationById($obligationId);
112 $licenses = $this->obligationMap->getLicenseList($obligationId);
113 $candidateLicenses = $this->obligationMap->getLicenseList($obligationId,
115 $associatedLicenses = explode(
";", $licenses);
116 $associatedCandidateLicenses = explode(
";", $candidateLicenses);
119 $associatedLicenses, $associatedCandidateLicenses);
133 $obligationId = intval($args[
'id']);
134 if (!$this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obligationId)) {
137 $this->obligationMap->deleteObligation($obligationId);
138 $returnVal =
new Info(200,
"Successfully removed Obligation.", InfoType::INFO);
139 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
151 public function importObligationsFromCSV($request, $response, $args)
156 $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
158 $adminLicenseObligationFromCsv = $this->restHelper->getPlugin(
'admin_obligation_from_csv');
160 $uploadedFile = $symReq->files->get($adminLicenseObligationFromCsv->getFileInputName($apiVersion),
166 if (array_key_exists(
"delimiter", $requestBody) && !empty($requestBody[
"delimiter"])) {
167 $delimiter = $requestBody[
"delimiter"];
169 if (array_key_exists(
"enclosure", $requestBody) && !empty($requestBody[
"enclosure"])) {
170 $enclosure = $requestBody[
"enclosure"];
173 $res = $adminLicenseObligationFromCsv->handleFileUpload($uploadedFile, $delimiter, $enclosure,
true);
175 throw new HttpBadRequestException($res[1]);
178 $newInfo =
new Info($res[2], $res[1], InfoType::INFO);
179 return $response->withJson($newInfo->getArray(), $newInfo->getCode());
194 $query = $request->getQueryParams();
196 if (array_key_exists(
'id', $query)) {
197 $obPk = intval($query[
'id']);
200 ! $this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obPk)) {
204 $dbManager = $this->dbHelper->getDbManager();
206 $content = $obligationCsvExport->createCsv($obPk);
207 $fileName =
"fossology-obligations-export-".date(
"YMj-Gis");
208 $newResponse = $response->withHeader(
'Content-type',
'text/csv, charset=UTF-8')
209 ->withHeader(
'Content-Disposition',
'attachment; filename=' . $fileName .
'.csv')
210 ->withHeader(
'Pragma',
'no-cache')
211 ->withHeader(
'Cache-Control',
'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0')
212 ->withHeader(
'Expires',
'Expires: Thu, 19 Nov 1981 08:52:00 GMT');
213 $sf =
new StreamFactory();
214 return $newResponse->withBody(
215 $content ? $sf->createStream($content) : $sf->createStream(
'')
228 public function importObligationsFromJSON($request, $response, $args)
233 $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
235 $adminLicenseObligationFromCsv = $this->restHelper->getPlugin(
'admin_obligation_from_csv');
237 $uploadedFile = $symReq->files->get($adminLicenseObligationFromCsv->getFileInputName($apiVersion),
240 $res = $adminLicenseObligationFromCsv->handleFileUpload($uploadedFile,
',',
'"',
true);
245 $newInfo =
new Info($res[2], $res[1], InfoType::INFO);
246 return $response->withJson($newInfo->getArray(), $newInfo->getCode());
260 $query = $request->getQueryParams();
262 if (array_key_exists(
'id', $query)) {
263 $obPk = intval($query[
'id']);
266 ! $this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obPk)) {
270 $dbManager = $this->dbHelper->getDbManager();
272 $content = $obligationCsvExport->createCsv($obPk,
true);
273 $fileName =
"fossology-obligations-export-".date(
"YMj-Gis");
274 $newResponse = $response->withHeader(
'Content-type',
'text/json; charset=UTF-8')
275 ->withHeader(
'Content-Disposition',
'attachment; filename=' . $fileName .
'.json')
276 ->withHeader(
'Pragma',
'no-cache')
277 ->withHeader(
'Cache-Control',
'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0')
278 ->withHeader(
'Expires',
'Expires: Thu, 19 Nov 1981 08:52:00 GMT');
279 $sf =
new StreamFactory();
280 return $newResponse->withBody(
281 $content ? $sf->createStream($content) : $sf->createStream(
'')
Helper class to export obligations as a CSV.
Wrapper class for obligation map.
obligationsDetails($request, $response, $args)
exportObligationsToJSON($request, $response, $args)
createExtendedObligationFromId($obligationId)
deleteObligation($request, $response, $args)
exportObligationsToCSV($request, $response, $args)
obligationsAllDetails($request, $response, $args)
obligationsList($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.
static getVersion(ServerRequestInterface $request)
Different type of infos provided by REST.
Info model to contain general error and return values.
static fromArray($db, $extended, $licenses, $candidateLicenses)