From 50c0de8c1821f1c5524d34f8c8922a407dacb27b Mon Sep 17 00:00:00 2001 From: Philip Durbin Date: Tue, 9 Apr 2019 12:27:23 -0400 Subject: [PATCH] restore 4.11 JSON format for Dataverse contacts #5724 --- .../harvard/iq/dataverse/util/json/JsonPrinter.java | 13 ++++++------- .../iq/dataverse/util/json/JsonPrinterTest.java | 3 ++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java b/src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java index 8524cdee77d..e432f0586ca 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java @@ -263,14 +263,13 @@ public static JsonObjectBuilder json(Dataverse dv, Boolean hideEmail) { } public static JsonArrayBuilder json(List dataverseContacts) { - JsonArrayBuilder bld = Json.createArrayBuilder(); - for(DataverseContact dc : dataverseContacts) { - bld.add(dc.getContactEmail()); - } - - return bld; + return dataverseContacts.stream() + .map(dc -> jsonObjectBuilder() + .add("displayOrder", dc.getDisplayOrder()) + .add("contactEmail", dc.getContactEmail()) + ).collect(toJsonArray()); } - + public static JsonObjectBuilder json( DataverseTheme theme ) { final NullSafeJsonBuilder baseObject = jsonObjectBuilder() .add("id", theme.getId() ) diff --git a/src/test/java/edu/harvard/iq/dataverse/util/json/JsonPrinterTest.java b/src/test/java/edu/harvard/iq/dataverse/util/json/JsonPrinterTest.java index 4a258534b0c..5c4a4eab42a 100644 --- a/src/test/java/edu/harvard/iq/dataverse/util/json/JsonPrinterTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/util/json/JsonPrinterTest.java @@ -277,7 +277,8 @@ public void testDataversePrinter() { assertEquals("dv42", jsonObject.getString("alias")); assertEquals("Dataverse 42", jsonObject.getString("name")); assertEquals("42 Inc.", jsonObject.getString("affiliation")); - assertEquals("dv42@mailinator.com", jsonObject.getJsonArray("dataverseContacts").getString(0)); + assertEquals(0, jsonObject.getJsonArray("dataverseContacts").getJsonObject(0).getInt("displayOrder")); + assertEquals("dv42@mailinator.com", jsonObject.getJsonArray("dataverseContacts").getJsonObject(0).getString("contactEmail")); assertEquals(false, jsonObject.getBoolean("permissionRoot")); assertEquals("Description for Dataverse 42.", jsonObject.getString("description")); assertEquals("UNCATEGORIZED", jsonObject.getString("dataverseType"));