New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(API): import csv-license file #2292
Merged
GMishx
merged 1 commit into
fossology:master
from
dushimsam:dushimsam/feat/import-license
Sep 5, 2022
Merged
feat(API): import csv-license file #2292
GMishx
merged 1 commit into
fossology:master
from
dushimsam:dushimsam/feat/import-license
Sep 5, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dushimsam
force-pushed
the
dushimsam/feat/import-license
branch
from
August 16, 2022 19:12
ecede9e
to
fa13f6a
Compare
shaheemazmalmmd
added
needs code review
needs test
GSoC-22
Label to tag issues and pull request for GSOC 2022 activities
labels
Aug 19, 2022
GMishx
requested changes
Aug 24, 2022
dushimsam
force-pushed
the
dushimsam/feat/import-license
branch
2 times, most recently
from
August 28, 2022 18:44
fc68e23
to
766cc4d
Compare
Moving I have done following changes to move them to request body: diff --git a/src/www/ui/api/Controllers/LicenseController.php b/src/www/ui/api/Controllers/LicenseController.php
index c0222c405..cb501a6ae 100644
--- a/src/www/ui/api/Controllers/LicenseController.php
+++ b/src/www/ui/api/Controllers/LicenseController.php
@@ -385,8 +385,15 @@ class LicenseController extends RestController
$uploadedFile = $symReq->files->get($adminLicenseFromCsv->getFileInputName(),
null);
- $delimiter = $request->getHeaderLine('delimiter') ? : ',';
- $enclosure = $request->getHeaderLine('enclosure') ?: '"';
+ $requestBody = $request->getParsedBody();
+ $delimiter = ',';
+ $enclosure = '"';
+ if (array_key_exists("delimiter", $requestBody) && !empty($requestBody["delimiter"])) {
+ $delimiter = $requestBody["delimiter"];
+ }
+ if (array_key_exists("enclosure", $requestBody) && !empty($requestBody["enclosure"])) {
+ $enclosure = $requestBody["enclosure"];
+ }
$res = $adminLicenseFromCsv->handleFileUpload($uploadedFile,$delimiter,$enclosure);
diff --git a/src/www/ui/api/documentation/openapi.yaml b/src/www/ui/api/documentation/openapi.yaml
index 9f96ae99f..928d99280 100644
--- a/src/www/ui/api/documentation/openapi.yaml
+++ b/src/www/ui/api/documentation/openapi.yaml
@@ -1629,19 +1629,6 @@ paths:
default:
$ref: '#/components/responses/defaultResponse'
/license/import-csv:
- parameters:
- - name: delimiter
- in: header
- required: false
- description: delimiter of the license
- schema:
- type: string
- - name: enclosure
- description: enclosure of the license
- in: header
- required: false
- schema:
- type: string
post:
operationId: importLicense
tags:
@@ -1657,9 +1644,21 @@ paths:
schema:
type: object
properties:
+ enclosure:
+ type: string
+ description: Enclosure for string in CSV
+ default: '"'
+ required: false
+ delimiter:
+ type: string
+ description: Delimiters for fields in CSV
+ default: ','
+ required: false
file_input:
type: string
format: binary
+ description: CSV to be imported
+ required: true
responses:
'400':
description: Validation Error
diff --git a/src/www/ui/api/index.php b/src/www/ui/api/index.php
index c37fb2063..d4c9f9a13 100644
--- a/src/www/ui/api/index.php
+++ b/src/www/ui/api/index.php
@@ -225,7 +225,7 @@ $app->group('/license',
function (\Slim\Routing\RouteCollectorProxy $app) {
$app->get('', LicenseController::class . ':getAllLicenses');
$app->post('', LicenseController::class . ':createLicense');
- $app->post('/import', LicenseController::class . ':handleImportLicense');
+ $app->post('/import-csv', LicenseController::class . ':handleImportLicense');
$app->get('/{shortname:.+}', LicenseController::class . ':getLicense');
$app->patch('/{shortname:.+}', LicenseController::class . ':updateLicense');
$app->any('/{params:.*}', BadRequestController::class); |
dushimsam
force-pushed
the
dushimsam/feat/import-license
branch
from
September 4, 2022 09:27
766cc4d
to
5b7518d
Compare
Done |
GMishx
requested changes
Sep 5, 2022
dushimsam
force-pushed
the
dushimsam/feat/import-license
branch
from
September 5, 2022 05:21
5b7518d
to
4280fa7
Compare
Signed-off-by: dushimsam <dushsam@gmail.com>
dushimsam
force-pushed
the
dushimsam/feat/import-license
branch
from
September 5, 2022 05:28
4280fa7
to
7fbbe73
Compare
GMishx
approved these changes
Sep 5, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes looks good. Tested, working as expected.
10 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Signed-off-by: dushimsam dushsam100@gmail.com
Description
The controller function to handle the import of a csv license file.
Changes
LicenseController
.AdminLicenseFromCSV.php
to be reusable by the outside callers.index.php
) by adding a new routePOST
/license/import
.openapi.yaml
file to introduce a new API.How to test
Example
FIRST SCENARIO
SECOND SCENARIO
Related Issue:
Fixes #2291
cc: @shaheemazmalmmd @GMishx