From fc10adbd133235f88a0da72118c6002b289032fa Mon Sep 17 00:00:00 2001 From: Niklas Date: Thu, 15 Feb 2024 12:05:37 +0100 Subject: [PATCH] Fix partial `license` objects being returned by `/api/v1/component` for components with unresolved license (#578) --- .../model/sqlmapping/ComponentProjection.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/dependencytrack/model/sqlmapping/ComponentProjection.java b/src/main/java/org/dependencytrack/model/sqlmapping/ComponentProjection.java index 17cc0fb4e..a986a3163 100644 --- a/src/main/java/org/dependencytrack/model/sqlmapping/ComponentProjection.java +++ b/src/main/java/org/dependencytrack/model/sqlmapping/ComponentProjection.java @@ -217,23 +217,22 @@ public static Component mapToComponent(ComponentProjection result) { project.setVersion(result.projectVersion); componentPersistent.setProject(project); - var license = new License(); - license.setName(result.licenseName); if (result.licenseUuid != null) { + final var license = new License(); license.setUuid(UUID.fromString(result.licenseUuid)); + license.setLicenseId(result.licenseId); + license.setName(result.licenseName); + if (result.isCustomLicense != null) { + license.setCustomLicense(result.isCustomLicense); + } + if (result.isFsfLibre != null) { + license.setFsfLibre(result.isFsfLibre); + } + if (result.isOsiApproved != null) { + license.setOsiApproved(result.isOsiApproved); + } + componentPersistent.setResolvedLicense(license); } - if (result.isCustomLicense != null) { - license.setCustomLicense(result.isCustomLicense); - } - if (result.isFsfLibre != null) { - license.setFsfLibre(result.isFsfLibre); - } - license.setLicenseId(result.licenseId); - if (result.isOsiApproved != null) { - license.setOsiApproved(result.isOsiApproved); - } - license.setName(result.licenseName); - componentPersistent.setResolvedLicense(license); var componentMetaInformation = new ComponentMetaInformation(result.publishedAt, result.integrityCheckStatus != null ? IntegrityMatchStatus.valueOf(result.integrityCheckStatus) : null,