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

Quick fix : component author column mapping #970

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.dependencytrack.model.Vulnerability;
import org.dependencytrack.model.VulnerableSoftware;
import org.dependencytrack.persistence.jdbi.mapping.ExternalReferenceMapper;
import org.dependencytrack.persistence.jdbi.mapping.OrganizationalContactMapper;
import org.dependencytrack.persistence.jdbi.mapping.VulnerabilityRowMapper;
import org.dependencytrack.persistence.jdbi.mapping.VulnerableSoftwareRowMapper;
import org.jdbi.v3.sqlobject.config.RegisterColumnMapper;
Expand Down Expand Up @@ -396,6 +397,7 @@ SELECT DISTINCT ON ("V"."ID")
and "C"."PROJECT_ID" = :projectId
""")
@RegisterFieldMapper(Component.class)
@RegisterColumnMapper(OrganizationalContactMapper.class)
@RegisterColumnMapper(ExternalReferenceMapper.class)
List<Component> getVulnerableComponents(@Bind long projectId, @Bind List<Long> vulnerabilityIds);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This file is part of Dependency-Track.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) OWASP Foundation. All Rights Reserved.
*/
package org.dependencytrack.persistence.jdbi.mapping;

import org.dependencytrack.model.OrganizationalContact;
import org.dependencytrack.persistence.converter.OrganizationalContactsJsonConverter;
import org.jdbi.v3.core.mapper.ColumnMapper;
import org.jdbi.v3.core.statement.StatementContext;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class OrganizationalContactMapper implements ColumnMapper<List<OrganizationalContact>> {

@Override
public List<OrganizationalContact> map(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException {
if (r.getBytes(columnNumber) == null) {
return new ArrayList<>();
}
sahibamittal marked this conversation as resolved.
Show resolved Hide resolved
return new OrganizationalContactsJsonConverter().convertToAttribute(r.getString(columnNumber));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.dependencytrack.model.Component;
import org.dependencytrack.model.Epss;
import org.dependencytrack.model.ExternalReference;
import org.dependencytrack.model.OrganizationalContact;
import org.dependencytrack.model.Project;
import org.dependencytrack.model.Severity;
import org.dependencytrack.model.Vulnerability;
Expand Down Expand Up @@ -709,6 +710,10 @@ public void setupData() {
extRef.setType(org.cyclonedx.model.ExternalReference.Type.WEBSITE);
extRef.setUrl("www.test.com");
component.addExternalReference(extRef);
var author = new OrganizationalContact();
author.setName("author");
component.setAuthors(List.of(author));

component.setVulnerabilities(List.of(vulnA, vulnB));

Component component2 = new Component();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ public void getVulnerabilitiesByProjectTest() {
"uuid": "${json-unit.any-string}",
"expandDependencyGraph": false,
"isInternal": false,
"externalReferences":[]
"externalReferences":[],
"authors":[]
}
],
"uuid": "${json-unit.any-string}",
Expand Down Expand Up @@ -238,7 +239,8 @@ public void getVulnerabilitiesByProjectTest() {
"uuid": "${json-unit.any-string}",
"expandDependencyGraph": false,
"isInternal": false,
"externalReferences":[]
"externalReferences":[],
"authors":[]
}
],
"uuid": "${json-unit.any-string}",
Expand Down Expand Up @@ -271,7 +273,8 @@ public void getVulnerabilitiesByProjectTest() {
"uuid": "${json-unit.any-string}",
"expandDependencyGraph": false,
"isInternal": false,
"externalReferences":[]
"externalReferences":[],
"authors":[]
}
],
"uuid": "${json-unit.any-string}",
Expand All @@ -294,7 +297,8 @@ public void getVulnerabilitiesByProjectTest() {
"uuid": "${json-unit.any-string}",
"expandDependencyGraph": false,
"isInternal": false,
"externalReferences":[]
"externalReferences":[],
"authors":[]
}
],
"uuid": "${json-unit.any-string}",
Expand Down Expand Up @@ -343,7 +347,8 @@ public void getVulnerabilitiesByProjectIncludeProjectSuppressedTest() {
"uuid": "${json-unit.any-string}",
"expandDependencyGraph": false,
"isInternal": false,
"externalReferences":[]
"externalReferences":[],
"authors":[]
}
],
"uuid": "${json-unit.any-string}",
Expand All @@ -366,7 +371,8 @@ public void getVulnerabilitiesByProjectIncludeProjectSuppressedTest() {
"uuid": "${json-unit.any-string}",
"expandDependencyGraph": false,
"isInternal": false,
"externalReferences":[]
"externalReferences":[],
"authors":[]
}
],
"uuid": "${json-unit.any-string}",
Expand Down
Loading