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);
134 $obligationId = intval($args[
'id']);
135 if (!$this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obligationId)) {
138 $this->obligationMap->deleteObligation($obligationId);
139 $returnVal =
new Info(200,
"Successfully removed Obligation.", InfoType::INFO);
140 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
152 public function importObligationsFromCSV($request, $response, $args)
157 $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
159 $adminLicenseObligationFromCsv = $this->restHelper->getPlugin(
'admin_obligation_from_csv');
161 $uploadedFile = $symReq->files->get($adminLicenseObligationFromCsv->getFileInputName($apiVersion),
167 if (array_key_exists(
"delimiter", $requestBody) && !empty($requestBody[
"delimiter"])) {
168 $delimiter = $requestBody[
"delimiter"];
170 if (array_key_exists(
"enclosure", $requestBody) && !empty($requestBody[
"enclosure"])) {
171 $enclosure = $requestBody[
"enclosure"];
174 $res = $adminLicenseObligationFromCsv->handleFileUpload($uploadedFile, $delimiter, $enclosure,
true);
176 throw new HttpBadRequestException($res[1]);
179 $newInfo =
new Info($res[2], $res[1], InfoType::INFO);
180 return $response->withJson($newInfo->getArray(), $newInfo->getCode());
195 $query = $request->getQueryParams();
197 if (array_key_exists(
'id', $query)) {
198 $obPk = intval($query[
'id']);
201 ! $this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obPk)) {
205 $dbManager = $this->dbHelper->getDbManager();
207 $content = $obligationCsvExport->createCsv($obPk);
208 $fileName =
"fossology-obligations-export-".date(
"YMj-Gis");
209 $newResponse = $response->withHeader(
'Content-type',
'text/csv, charset=UTF-8')
210 ->withHeader(
'Content-Disposition',
'attachment; filename=' . $fileName .
'.csv')
211 ->withHeader(
'Pragma',
'no-cache')
212 ->withHeader(
'Cache-Control',
'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0')
213 ->withHeader(
'Expires',
'Expires: Thu, 19 Nov 1981 08:52:00 GMT');
214 $sf =
new StreamFactory();
215 return $newResponse->withBody(
216 $content ? $sf->createStream($content) : $sf->createStream(
'')
229 public function importObligationsFromJSON($request, $response, $args)
234 $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
236 $adminLicenseObligationFromCsv = $this->restHelper->getPlugin(
'admin_obligation_from_csv');
238 $uploadedFile = $symReq->files->get($adminLicenseObligationFromCsv->getFileInputName($apiVersion),
241 $res = $adminLicenseObligationFromCsv->handleFileUpload($uploadedFile,
',',
'"',
true);
246 $newInfo =
new Info($res[2], $res[1], InfoType::INFO);
247 return $response->withJson($newInfo->getArray(), $newInfo->getCode());
261 $query = $request->getQueryParams();
263 if (array_key_exists(
'id', $query)) {
264 $obPk = intval($query[
'id']);
267 ! $this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obPk)) {
271 $dbManager = $this->dbHelper->getDbManager();
273 $content = $obligationCsvExport->createCsv($obPk,
true);
274 $fileName =
"fossology-obligations-export-".date(
"YMj-Gis");
275 $newResponse = $response->withHeader(
'Content-type',
'text/json; charset=UTF-8')
276 ->withHeader(
'Content-Disposition',
'attachment; filename=' . $fileName .
'.json')
277 ->withHeader(
'Pragma',
'no-cache')
278 ->withHeader(
'Cache-Control',
'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0')
279 ->withHeader(
'Expires',
'Expires: Thu, 19 Nov 1981 08:52:00 GMT');
280 $sf =
new StreamFactory();
281 return $newResponse->withBody(
282 $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)