Skip to content
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(license_import): Add endpoint to import licenses via a json file #54

Merged
merged 1 commit into from May 20, 2024

Conversation

deo002
Copy link
Collaborator

@deo002 deo002 commented May 10, 2024

Code Overview:

  • Made a generic function InsertOrUpdateLicenseOnImport for creating/updating a single license on import. This function will be used in both Populatedb function and /licenses/import endpoint.
    -InsertOrUpdateLicenseOnImport takes input a map of license fields. This was done to accomodate updates of fields with zero values as valid values( ex. Risk can be 0, Active can be false ). GORM doesn't update fields with zero values when updating using a struct.
  • Logic of addChangelogsForLicenseUpdate was kept seperate from InsertOrUpdateLicenseOnImport to make the latter generic. Populatedb won't need addChangelogsForLicenseUpdate.
  • A new template datatype NullableAndOptionalData was introduced to differentiate between fields with zero values and fields with null values/undefined fields in json(in all the cases the unmarshalled struct will have zero values).
  • InsertOrUpdateLicenseOnImport will be added to Populatedb in next PR to keep this PR size manageable.
  • InsertOrUpdateLicenseOnImport returns errMessage and importStatus along with some license structs to make it generic. This was done because in endpoint, the relevant data will be added to response body while it will be logged in 'Populatedb'.

Behaviour:

  • Inserts a new license to database if not already present(checks by shortname).
  • Updates the license with new values if license already present.
  • Updates the license with new values except for rf_text if rf_flag is set to 2(if this flag is set to 2, it means that the license text was updated manually and should not be updated via an import).

Copy link
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change needed.

pkg/api/licenses.go Outdated Show resolved Hide resolved
pkg/api/licenses.go Outdated Show resolved Hide resolved
Copy link
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good.

Copy link
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, working as expected.

@GMishx GMishx removed the needs test label May 20, 2024
@GMishx GMishx merged commit bc69f41 into fossology:main May 20, 2024
5 checks passed
@GMishx GMishx deleted the license_import branch May 20, 2024 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants