Skip to content

Commit 69a9ccd

Browse files
committed
add author to json response
Signed-off-by: Ross Murphy <RossMurphy@ibm.com>
1 parent 2943064 commit 69a9ccd

5 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/main/java/org/dependencytrack/model/Component.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,17 @@ public String getPublisher() {
401401
}
402402

403403
@Deprecated
404-
@JsonIgnore
404+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
405405
public String getAuthor(){
406406
return ModelConverter.convertContactsToString(this.authors);
407407
}
408408

409409
@Deprecated
410410
public void setAuthor(String author){
411-
if(this.authors==null){
411+
if (this.authors == null) {
412412
this.authors = new ArrayList<>();
413+
} else {
414+
this.authors.clear();
413415
}
414416
this.authors.add(new OrganizationalContact() {{
415417
setName(author);

src/main/java/org/dependencytrack/model/Project.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public void setAuthors(List<OrganizationalContact> authors) {
307307
}
308308

309309
@Deprecated
310-
@JsonIgnore
310+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
311311
public String getAuthor(){
312312
return ModelConverter.convertContactsToString(this.authors);
313313
}
@@ -316,6 +316,8 @@ public String getAuthor(){
316316
public void setAuthor(String author){
317317
if(this.authors==null){
318318
this.authors = new ArrayList<>();
319+
} else{
320+
this.authors.clear();
319321
}
320322
this.authors.add(new OrganizationalContact() {{
321323
setName(author);

src/main/java/org/dependencytrack/resources/v1/ComponentResource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ public Response createComponent(@Parameter(description = "The UUID of the projec
285285
final Validator validator = super.getValidator();
286286
failOnValidationError(
287287
validator.validateProperty(jsonComponent, "authors"),
288+
validator.validateProperty(jsonComponent, "author"),
288289
validator.validateProperty(jsonComponent, "publisher"),
289290
validator.validateProperty(jsonComponent, "name"),
290291
validator.validateProperty(jsonComponent, "version"),

src/main/java/org/dependencytrack/resources/v1/ProjectResource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ public Response getProjectsByClassifier(
289289
public Response createProject(Project jsonProject) {
290290
final Validator validator = super.getValidator();
291291
failOnValidationError(
292+
validator.validateProperty(jsonProject, "author"),
292293
validator.validateProperty(jsonProject, "authors"),
293294
validator.validateProperty(jsonProject, "publisher"),
294295
validator.validateProperty(jsonProject, "group"),
@@ -429,6 +430,7 @@ public Response patchProject(
429430
Project jsonProject) {
430431
final Validator validator = getValidator();
431432
failOnValidationError(
433+
validator.validateProperty(jsonProject, "author"),
432434
validator.validateProperty(jsonProject, "authors"),
433435
validator.validateProperty(jsonProject, "publisher"),
434436
validator.validateProperty(jsonProject, "group"),

src/test/java/org/dependencytrack/resources/v1/ComponentResourceTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.UUID;
4949

5050
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
51+
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json;
5152
import static org.assertj.core.api.Assertions.assertThat;
5253

5354
public class ComponentResourceTest extends ResourceTest {
@@ -515,6 +516,7 @@ public void createComponentTest() {
515516
Assert.assertNotNull(json);
516517
Assert.assertEquals("My Component", json.getString("name"));
517518
Assert.assertEquals("SampleAuthor" ,json.getJsonArray("authors").getJsonObject(0).getString("name"));
519+
Assert.assertEquals("SampleAuthor", json.getString("author"));
518520
Assert.assertEquals("1.0", json.getString("version"));
519521
Assert.assertTrue(UuidUtil.isValidUUID(json.getString("uuid")));
520522
}

0 commit comments

Comments
 (0)