13 namespace Fossology\UI\Api\Controllers;
24 use Psr\Http\Message\ServerRequestInterface;
25 use Slim\Psr7\Factory\StreamFactory;
38 $this->obligationMap = $this->container->get(
'businessrules.obligationmap');
52 $listVal = $this->obligationMap->getObligations();
53 foreach ($listVal as $val) {
54 $row[
'id'] = intval($val[
'ob_pk']);
55 $row[
'obligation_topic'] = $val[
'ob_topic'];
58 return $response->withJson($finVal, 200);
72 $obligationId = intval($args[
'id']);
73 if (!$this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obligationId)) {
78 return $response->withJson($obligation->getArray(), 200);
91 $obligationArray = [];
92 $listVal = $this->obligationMap->getObligations();
93 foreach ($listVal as $val) {
94 $obligationId = intval($val[
'ob_pk']);
98 return $response->withJson($obligationArray, 200);
109 $obligationInfo = $this->obligationMap->getObligationById($obligationId);
110 $licenses = $this->obligationMap->getLicenseList($obligationId);
111 $candidateLicenses = $this->obligationMap->getLicenseList($obligationId,
113 $associatedLicenses = explode(
";", $licenses);
114 $associatedCandidateLicenses = explode(
";", $candidateLicenses);
117 $associatedLicenses, $associatedCandidateLicenses);
131 $obligationId = intval($args[
'id']);
132 if (!$this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obligationId)) {
135 $this->obligationMap->deleteObligation($obligationId);
136 $returnVal =
new Info(200,
"Successfully removed Obligation.", InfoType::INFO);
137 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
149 public function importObligationsFromCSV($request, $response, $args)
153 $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
155 $adminLicenseObligationFromCsv = $this->restHelper->getPlugin(
'admin_obligation_from_csv');
157 $uploadedFile = $symReq->files->get($adminLicenseObligationFromCsv->getFileInputName(),
163 if (array_key_exists(
"delimiter", $requestBody) && !empty($requestBody[
"delimiter"])) {
164 $delimiter = $requestBody[
"delimiter"];
166 if (array_key_exists(
"enclosure", $requestBody) && !empty($requestBody[
"enclosure"])) {
167 $enclosure = $requestBody[
"enclosure"];
170 $res = $adminLicenseObligationFromCsv->handleFileUpload($uploadedFile, $delimiter, $enclosure,
true);
172 throw new HttpBadRequestException($res[1]);
175 $newInfo =
new Info($res[2], $res[1], InfoType::INFO);
176 return $response->withJson($newInfo->getArray(), $newInfo->getCode());
191 $query = $request->getQueryParams();
193 if (array_key_exists(
'id', $query)) {
194 $obPk = intval($query[
'id']);
197 ! $this->dbHelper->doesIdExist(
"obligation_ref",
"ob_pk", $obPk)) {
201 $dbManager = $this->dbHelper->getDbManager();
203 $content = $obligationCsvExport->createCsv($obPk);
204 $fileName =
"fossology-obligations-export-".date(
"YMj-Gis");
205 $newResponse = $response->withHeader(
'Content-type',
'text/csv, charset=UTF-8')
206 ->withHeader(
'Content-Disposition',
'attachment; filename=' . $fileName .
'.csv')
207 ->withHeader(
'Pragma',
'no-cache')
208 ->withHeader(
'Cache-Control',
'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0')
209 ->withHeader(
'Expires',
'Expires: Thu, 19 Nov 1981 08:52:00 GMT');
210 $sf =
new StreamFactory();
211 return $newResponse->withBody(
212 $content ? $sf->createStream($content) : $sf->createStream(
'')
Helper class to export obligations as a CSV.
Wrapper class for obligation map.
obligationsDetails($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.
Different type of infos provided by REST.
Info model to contain general error and return values.
static fromArray($db, $extended, $licenses, $candidateLicenses)