Skip to content

Commit 792818e

Browse files
Merge pull request fossology#3200 from krrish175-byte/feat/spdx3-api-support
feat(api): Add SPDX3 Format Support to API Report Endpoint Reviewed-by: shaheem.azmal@siemens.com Tested-by: shaheem.azmal@siemens.com
2 parents 0a88b35 + 4c85ba0 commit 792818e

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

src/www/ui/api/Controllers/ReportController.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Fossology\DecisionImporter\UI\AgentDecisionImporterPlugin;
1818
use Fossology\ReadmeOSS\UI\ReadMeOssPlugin;
1919
use Fossology\Spdx\UI\SpdxTwoGeneratorUi;
20+
use Fossology\Spdx\UI\SpdxThreeGeneratorUi;
2021
use Fossology\UI\Api\Exceptions\HttpBadRequestException;
2122
use Fossology\UI\Api\Exceptions\HttpErrorException;
2223
use Fossology\UI\Api\Exceptions\HttpForbiddenException;
@@ -54,7 +55,10 @@ class ReportController extends RestController
5455
'unifiedreport',
5556
'clixml',
5657
'decisionexporter',
57-
'cyclonedx'
58+
'cyclonedx',
59+
'spdx3json',
60+
'spdx3rdf',
61+
'spdx3jsonld'
5862
);
5963

6064
/**
@@ -140,6 +144,14 @@ public function getReport($request, $response, $args)
140144
list ($jobId, $jobQueueId) = $cyclonedxGenerator->scheduleAgent(
141145
$this->restHelper->getGroupId(), $upload);
142146
break;
147+
case $this->reportsAllowed[8]:
148+
case $this->reportsAllowed[9]:
149+
case $this->reportsAllowed[10]:
150+
/** @var SpdxThreeGeneratorUi $spdx3Generator */
151+
$spdx3Generator = $this->restHelper->getPlugin('ui_spdx3');
152+
list ($jobId, $jobQueueId, $error) = $spdx3Generator->scheduleAgent(
153+
$this->restHelper->getGroupId(), $upload, $reportFormat);
154+
break;
143155
default:
144156
throw new HttpInternalServerErrorException("Some error occured!");
145157
}

src/www/ui/api/documentation/openapi.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4424,6 +4424,9 @@ paths:
44244424
- unifiedreport
44254425
- clixml
44264426
- cyclonedx
4427+
- spdx3json
4428+
- spdx3rdf
4429+
- spdx3jsonld
44274430
- name: groupName
44284431
description: The group name to chose while generating a report
44294432
in: header

src/www/ui/api/documentation/openapiv2.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4261,6 +4261,9 @@ paths:
42614261
- unifiedreport
42624262
- clixml
42634263
- cyclonedx
4264+
- spdx3json
4265+
- spdx3rdf
4266+
- spdx3jsonld
42644267
- name: groupName
42654268
description: The group name to chose while generating a report
42664269
in: query

src/www/ui_tests/api/Controllers/ReportControllerTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ class ReportControllerTest extends \PHPUnit\Framework\TestCase
5151
'readmeoss',
5252
'unifiedreport',
5353
'clixml',
54-
'decisionexporter'
54+
'decisionexporter',
55+
'cyclonedx',
56+
'spdx3json',
57+
'spdx3rdf',
58+
'spdx3jsonld'
5559
);
5660

5761
/**
@@ -114,6 +118,18 @@ class ReportControllerTest extends \PHPUnit\Framework\TestCase
114118
*/
115119
private $decisionExporterPlugin;
116120

121+
/**
122+
* @var M\MockInterface $cyclonedxPlugin
123+
* CycloneDXGeneratorUi mock
124+
*/
125+
private $cyclonedxPlugin;
126+
127+
/**
128+
* @var M\MockInterface $spdx3Plugin
129+
* SpdxThreeGeneratorUi mock
130+
*/
131+
private $spdx3Plugin;
132+
117133
/**
118134
* @var DbManager $dbManager
119135
* DbManager mock
@@ -151,6 +167,8 @@ protected function setUp() : void
151167
$this->clixmlPlugin = M::mock('CliXmlGeneratorUi');
152168
$this->unifiedPlugin = M::mock('FoUnifiedReportGenerator');
153169
$this->decisionExporterPlugin = M::mock('DecisionExporterAgentPlugin');
170+
$this->cyclonedxPlugin = M::mock('CycloneDXGeneratorUi');
171+
$this->spdx3Plugin = M::mock('SpdxThreeGeneratorUi');
154172
$this->downloadPlugin = M::mock('ui_download');
155173

156174
$this->dbHelper->shouldReceive('getDbManager')->andReturn($this->dbManager);
@@ -172,6 +190,10 @@ protected function setUp() : void
172190
->andReturn($this->unifiedPlugin);
173191
$this->restHelper->shouldReceive('getPlugin')
174192
->withArgs(['agent_fodecisionexporter'])->andReturn($this->decisionExporterPlugin);
193+
$this->restHelper->shouldReceive('getPlugin')
194+
->withArgs(array('ui_cyclonedx'))->andReturn($this->cyclonedxPlugin);
195+
$this->restHelper->shouldReceive('getPlugin')
196+
->withArgs(array('ui_spdx3'))->andReturn($this->spdx3Plugin);
175197

176198
$container->shouldReceive('get')->withArgs(array(
177199
'helper.restHelper'))->andReturn($this->restHelper);
@@ -278,6 +300,12 @@ public function testGetReportAllFormats()
278300
->withArgs([$this->groupId, $upload])->andReturn([32, 33, ""]);
279301
$this->decisionExporterPlugin->shouldReceive('scheduleAgent')
280302
->withArgs([$this->groupId, $upload])->andReturn([32, 33]);
303+
$this->cyclonedxPlugin->shouldReceive('scheduleAgent')
304+
->withArgs([$this->groupId, $upload])->andReturn([32, 33]);
305+
$this->spdx3Plugin->shouldReceive('scheduleAgent')
306+
->withArgs([$this->groupId, $upload, M::anyOf($this->reportsAllowed[8],
307+
$this->reportsAllowed[9], $this->reportsAllowed[10])])
308+
->andReturn([32, 33, ""]);
281309

282310
$expectedResponse = new Info(201, "http://localhost/repo/api/v1/report/32",
283311
InfoType::INFO);

0 commit comments

Comments
 (0)