Skip to content

Commit

Permalink
add mapping for component external references
Browse files Browse the repository at this point in the history
  • Loading branch information
sahibamittal committed Jun 4, 2024
1 parent b19f101 commit 55fda62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ public Component updateComponent(Component transientComponent, boolean commitInd
component.setInternal(transientComponent.isInternal());
component.setAuthor(transientComponent.getAuthor());
component.setSupplier(transientComponent.getSupplier());
component.setExternalReferences(transientComponent.getExternalReferences());
final Component result = persist(component);
Event.dispatch(new IndexEvent(IndexEvent.Action.UPDATE, result));
commitSearchIndex(commitIndex, Component.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ public Response updateComponent(Component jsonComponent) {
component.setSha3_256(StringUtils.trimToNull(jsonComponent.getSha3_256()));
component.setSha3_384(StringUtils.trimToNull(jsonComponent.getSha3_384()));
component.setSha3_512(StringUtils.trimToNull(jsonComponent.getSha3_512()));
component.setExternalReferences(jsonComponent.getExternalReferences());

final License resolvedLicense = qm.getLicense(jsonComponent.getLicense());
if (resolvedLicense != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.dependencytrack.ResourceTest;
import org.dependencytrack.model.Component;
import org.dependencytrack.model.ConfigPropertyConstants;
import org.dependencytrack.model.ExternalReference;
import org.dependencytrack.model.Project;
import org.dependencytrack.model.RepositoryMetaComponent;
import org.dependencytrack.model.RepositoryType;
Expand Down Expand Up @@ -557,17 +558,29 @@ public void updateComponentTest() {
component.setProject(project);
component.setName("My Component");
component.setVersion("1.0");
component = qm.createComponent(component, false);
component.setDescription("Test component");
qm.createComponent(component, false);

var jsonComponent = new Component();
jsonComponent.setUuid(component.getUuid());
jsonComponent.setPurl("pkg:maven/org.acme/abc");
jsonComponent.setName("My Component");
jsonComponent.setVersion("1.0");
jsonComponent.setDescription("Test component");
var externalReference = new ExternalReference();
externalReference.setType(org.cyclonedx.model.ExternalReference.Type.WEBSITE);
externalReference.setUrl("test.com");
jsonComponent.setExternalReferences(List.of(externalReference));

Response response = jersey.target(V1_COMPONENT).request()
.header(X_API_KEY, apiKey)
.post(Entity.entity(component, MediaType.APPLICATION_JSON));
.post(Entity.entity(jsonComponent, MediaType.APPLICATION_JSON));
Assert.assertEquals(200, response.getStatus(), 0);
JsonObject json = parseJsonObject(response);
Assert.assertNotNull(json);
Assert.assertEquals("My Component", json.getString("name"));
Assert.assertEquals("1.0", json.getString("version"));
Assert.assertEquals("Test component", json.getString("description"));
Assert.assertEquals(1, json.getJsonArray("externalReferences").size());
}

@Test
Expand Down

0 comments on commit 55fda62

Please sign in to comment.