Skip to content

Commit 853965e

Browse files
authored
Banner IT improvements after resolving issues on rocky. (#10565)
* Rocky IX * Logging pretty print * Removed use of function with hardcoded valie * Clearing banners * Added codeblock with JSON * Banners size * Trace added * Import fix * Pull test * lOG TEST * Log test * Log test * ASD * Debug commit * Debug commit * Dbug commit * Dbug commit * Bbug commit * Dbug cmmt * dbg cmmt * dbg cmmit * Dbg cmmt * reset bannermessage * Reset Admin * Reset AdminIT * Reset admin IT * Clear console output * Last changes * Last changes for this test * Last update * Locale check * Docs and makefile to build guides * Makefile changes * Value of sphinx version loaded from requirements.txt * Last changes to makefile and docs * Correction to the docs
1 parent d113d7c commit 853965e

File tree

9 files changed

+90
-50
lines changed

9 files changed

+90
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The endpoint `api/admin/bannerMessage` has been extended so the ID is returned when created

doc/sphinx-guides/source/api/native-api.rst

+2
Original file line numberDiff line numberDiff line change
@@ -5194,6 +5194,8 @@ Delete the setting under ``name``::
51945194
Manage Banner Messages
51955195
~~~~~~~~~~~~~~~~~~~~~~
51965196
5197+
.. warning:: Adding a banner message with a language that is not supported by the installation will result in a 500-Internal Server Error response when trying to access to the /bannerMessage.
5198+
51975199
Communications to users can be handled via banner messages that are displayed at the top of all pages within your Dataverse installation. Two types of banners can be configured:
51985200
51995201
- A banner message where dismissibleByUser is set to false will be displayed to anyone viewing the application. These messages will be dismissible for a given session but will be displayed in any subsequent session until they are deleted by the Admin. This type of banner message is useful for situations such as upcoming maintenance windows and other downtime.

doc/sphinx-guides/source/developers/documentation.rst

+13-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,20 @@ Open a terminal, change directories to ``doc/sphinx-guides``, activate (or react
9292
Building the Guides with a Sphinx Docker Container
9393
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9494

95+
**Building with Docker and Makefile:**
96+
97+
We have added a Makefile to simplify the process of building the guides using a Docker container, you can use some of the following from the repository root:
98+
99+
- `make docs-html`
100+
- `make docs-pdf`
101+
- `make docs-epub`
102+
- `make docs-all`
103+
104+
**Building with Docker and CLI:**
105+
95106
If you want to build the guides using a Docker container, execute the following command in the repository root:
96107

97-
``docker run -it --rm -v $(pwd):/docs sphinxdoc/sphinx:3.5.4 bash -c "cd doc/sphinx-guides && pip3 install -r requirements.txt && make html"``
108+
``docker run -it --rm -v $(pwd):/docs sphinxdoc/sphinx:7.2.6 bash -c "cd doc/sphinx-guides && pip3 install -r requirements.txt && make html"``
98109

99110
Previewing the Guides
100111
^^^^^^^^^^^^^^^^^^^^^
@@ -148,7 +159,7 @@ The HTML version of the guides is the official one. Any other formats are mainta
148159

149160
If you would like to build a PDF version of the guides and have Docker installed, please try the command below from the root of the git repo:
150161

151-
``docker run -it --rm -v $(pwd):/docs sphinxdoc/sphinx-latexpdf:3.5.4 bash -c "cd doc/sphinx-guides && pip3 install -r requirements.txt && make latexpdf LATEXMKOPTS=\"-interaction=nonstopmode\"; cd ../.. && ls -1 doc/sphinx-guides/build/latex/Dataverse.pdf"``
162+
``docker run -it --rm -v $(pwd):/docs sphinxdoc/sphinx-latexpdf:7.2.6 bash -c "cd doc/sphinx-guides && pip3 install -r requirements.txt && make latexpdf LATEXMKOPTS=\"-interaction=nonstopmode\"; cd ../.. && ls -1 doc/sphinx-guides/build/latex/Dataverse.pdf"``
152163

153164
A few notes about the command above:
154165

makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
SPHINX_VERSION = $(shell grep "Sphinx" ./doc/sphinx-guides/requirements.txt | awk -F'==' '{print $$2}')
3+
docs-html:
4+
docker run -it --rm -v $$(pwd):/docs sphinxdoc/sphinx:$(SPHINX_VERSION) bash -c "cd doc/sphinx-guides && pip3 install -r requirements.txt && make clean && make html"
5+
6+
docs-pdf:
7+
docker run -it --rm -v $$(pwd):/docs sphinxdoc/sphinx-latexpdf:$(SPHINX_VERSION) bash -c "cd doc/sphinx-guides && pip3 install -r requirements.txt && make clean && make latexpdf LATEXMKOPTS=\"-interaction=nonstopmode\"; cd ../.. && ls -1 doc/sphinx-guides/build/latex/Dataverse.pdf"
8+
9+
docs-epub:
10+
docker run -it --rm -v $$(pwd):/docs sphinxdoc/sphinx:$(SPHINX_VERSION) bash -c "cd doc/sphinx-guides && pip3 install -r requirements.txt && make clean && make epub"
11+
12+
docs-all:
13+
docker run -it --rm -v $$(pwd):/docs sphinxdoc/sphinx:$(SPHINX_VERSION) bash -c "cd doc/sphinx-guides && pip3 install -r requirements.txt && make clean && make html && make epub"
14+
docker run -it --rm -v $$(pwd):/docs sphinxdoc/sphinx-latexpdf:$(SPHINX_VERSION) bash -c "cd doc/sphinx-guides && pip3 install -r requirements.txt && make latexpdf LATEXMKOPTS=\"-interaction=nonstopmode\"; cd ../.. && ls -1 doc/sphinx-guides/build/latex/Dataverse.pdf"

src/main/java/edu/harvard/iq/dataverse/BannerMessage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void setBannerMessageTexts(Collection<BannerMessageText> bannerMessageTex
4646

4747

4848
public String getDisplayValue(){
49-
String retVal = "";
49+
String retVal = null;
5050
for (BannerMessageText msgTxt : this.getBannerMessageTexts()) {
5151
if (msgTxt.getLang().equals(BundleUtil.getCurrentLocale().getLanguage())) {
5252
retVal = msgTxt.getMessage();

src/main/java/edu/harvard/iq/dataverse/BannerMessageServiceBean.java

+2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ public List<BannerMessage> findAllBannerMessages() {
4646

4747
public void save( BannerMessage message ) {
4848
em.persist(message);
49+
em.flush();
4950
}
5051

52+
5153
public void deleteBannerMessage(Object pk) {
5254
BannerMessage message = em.find(BannerMessage.class, pk);
5355

src/main/java/edu/harvard/iq/dataverse/api/Admin.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -2357,8 +2357,13 @@ public Response addBannerMessage(JsonObject jsonObject) throws WrappedResponse {
23572357
messageText.setBannerMessage(toAdd);
23582358
toAdd.getBannerMessageTexts().add(messageText);
23592359
}
2360-
bannerMessageService.save(toAdd);
2361-
return ok("Banner Message added successfully.");
2360+
bannerMessageService.save(toAdd);
2361+
2362+
JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder()
2363+
.add("message", "Banner Message added successfully.")
2364+
.add("id", toAdd.getId());
2365+
2366+
return ok(jsonObjectBuilder);
23622367

23632368
} catch (Exception e) {
23642369
logger.warning("Unexpected Exception: " + e.getMessage());
@@ -2398,10 +2403,19 @@ public Response deactivateBannerMessage(@PathParam("id") Long id) throws Wrapped
23982403
@Path("/bannerMessage")
23992404
public Response getBannerMessages(@PathParam("id") Long id) throws WrappedResponse {
24002405

2401-
return ok(bannerMessageService.findAllBannerMessages().stream()
2402-
.map(m -> jsonObjectBuilder().add("id", m.getId()).add("displayValue", m.getDisplayValue()))
2403-
.collect(toJsonArray()));
2406+
List<BannerMessage> messagesList = bannerMessageService.findAllBannerMessages();
2407+
2408+
for (BannerMessage message : messagesList) {
2409+
if ("".equals(message.getDisplayValue())) {
2410+
return error(Response.Status.INTERNAL_SERVER_ERROR, "No banner messages found for this locale.");
2411+
}
2412+
}
24042413

2414+
JsonArrayBuilder messages = messagesList.stream()
2415+
.map(m -> jsonObjectBuilder().add("id", m.getId()).add("displayValue", m.getDisplayValue()))
2416+
.collect(toJsonArray());
2417+
2418+
return ok(messages);
24052419
}
24062420

24072421
@POST

src/test/java/edu/harvard/iq/dataverse/api/AdminIT.java

+38-28
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,21 @@
1515
import java.util.ArrayList;
1616
import java.util.HashMap;
1717
import java.util.List;
18-
import static jakarta.ws.rs.core.Response.Status.FORBIDDEN;
19-
import static jakarta.ws.rs.core.Response.Status.BAD_REQUEST;
2018

2119
import org.junit.jupiter.api.Disabled;
2220
import org.junit.jupiter.api.Test;
2321
import org.junit.jupiter.api.BeforeAll;
2422
import org.junit.jupiter.params.ParameterizedTest;
2523
import org.junit.jupiter.params.provider.ValueSource;
24+
25+
26+
2627
import java.util.Map;
2728
import java.util.UUID;
29+
import java.util.logging.Level;
2830
import java.util.logging.Logger;
2931

30-
import static jakarta.ws.rs.core.Response.Status.CREATED;
31-
import static jakarta.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
32-
import static jakarta.ws.rs.core.Response.Status.OK;
33-
import static jakarta.ws.rs.core.Response.Status.UNAUTHORIZED;
32+
import static jakarta.ws.rs.core.Response.Status.*;
3433
import static org.junit.jupiter.api.Assertions.assertEquals;
3534
import static org.hamcrest.CoreMatchers.equalTo;
3635
import static org.hamcrest.CoreMatchers.notNullValue;
@@ -832,36 +831,47 @@ public void testClearThumbnailFailureFlag(){
832831

833832
@Test
834833
public void testBannerMessages(){
835-
836-
String pathToJsonFile = "scripts/api/data/bannerMessageError.json";
837-
Response addBannerMessageErrorResponse = UtilIT.addBannerMessage(pathToJsonFile);
834+
835+
//We check for existing banner messages and get the number of existing messages
836+
Response getBannerMessageResponse = UtilIT.getBannerMessages();
837+
getBannerMessageResponse.prettyPrint();
838+
getBannerMessageResponse.then().assertThat()
839+
.statusCode(OK.getStatusCode());
840+
Integer numBannerMessages =
841+
JsonPath.from(getBannerMessageResponse.getBody().asString()).getInt("data.size()");
842+
843+
//We add a banner message with an error in the json file
844+
String pathToJsonFile = "scripts/api/data/bannerMessageError.json";
845+
Response addBannerMessageErrorResponse = UtilIT.addBannerMessage(pathToJsonFile);
838846
addBannerMessageErrorResponse.prettyPrint();
839-
String body = addBannerMessageErrorResponse.getBody().asString();
840-
String status = JsonPath.from(body).getString("status");
841-
assertEquals("ERROR", status);
847+
addBannerMessageErrorResponse.then().assertThat()
848+
.statusCode(BAD_REQUEST.getStatusCode())
849+
.body("status", equalTo("ERROR"));
842850

851+
//We add a banner message with a correct json file
843852
pathToJsonFile = "scripts/api/data/bannerMessageTest.json";
844-
845853
Response addBannerMessageResponse = UtilIT.addBannerMessage(pathToJsonFile);
846854
addBannerMessageResponse.prettyPrint();
847-
body = addBannerMessageResponse.getBody().asString();
848-
status = JsonPath.from(body).getString("status");
849-
assertEquals("OK", status);
855+
addBannerMessageResponse.then().assertThat()
856+
.statusCode(OK.getStatusCode())
857+
.body("status", equalTo("OK"))
858+
.body("data.message", equalTo("Banner Message added successfully."));
859+
Long addedBanner = Long.valueOf(
860+
JsonPath.from(addBannerMessageResponse.getBody().asString()).getLong("data.id"));
850861

851-
Response getBannerMessageResponse = UtilIT.getBannerMessages();
862+
//We get the banner messages and check that the number of messages has increased by 1
863+
getBannerMessageResponse = UtilIT.getBannerMessages();
852864
getBannerMessageResponse.prettyPrint();
853-
body = getBannerMessageResponse.getBody().asString();
854-
status = JsonPath.from(body).getString("status");
855-
assertEquals("OK", status);
856-
String deleteId = UtilIT.getBannerMessageIdFromResponse(getBannerMessageResponse.getBody().asString());
857-
858-
System.out.print("delete id: " + deleteId);
859-
860-
Response deleteBannerMessageResponse = UtilIT.deleteBannerMessage(new Long (deleteId));
865+
getBannerMessageResponse.then().assertThat()
866+
.statusCode(OK.getStatusCode())
867+
.body("data.size()", equalTo(numBannerMessages + 1));
868+
869+
//We delete the banner message
870+
Response deleteBannerMessageResponse = UtilIT.deleteBannerMessage(addedBanner);
861871
deleteBannerMessageResponse.prettyPrint();
862-
body = deleteBannerMessageResponse.getBody().asString();
863-
status = JsonPath.from(body).getString("status");
864-
assertEquals("OK", status);
872+
deleteBannerMessageResponse.then().assertThat()
873+
.statusCode(OK.getStatusCode())
874+
.body("status", equalTo("OK"));
865875

866876
}
867877

src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java

-14
Original file line numberDiff line numberDiff line change
@@ -3387,20 +3387,6 @@ static Response deleteBannerMessage(Long id) {
33873387
return deleteBannerMessageResponse;
33883388
}
33893389

3390-
static String getBannerMessageIdFromResponse(String getBannerMessagesResponse) {
3391-
StringReader rdr = new StringReader(getBannerMessagesResponse);
3392-
JsonObject json = Json.createReader(rdr).readObject();
3393-
3394-
for (JsonObject obj : json.getJsonArray("data").getValuesAs(JsonObject.class)) {
3395-
String message = obj.getString("displayValue");
3396-
if (message.equals("Banner Message For Deletion")) {
3397-
return obj.getJsonNumber("id").toString();
3398-
}
3399-
}
3400-
3401-
return "0";
3402-
}
3403-
34043390
static Response getDatasetJsonLDMetadata(Integer datasetId, String apiToken) {
34053391
Response response = given()
34063392
.header(API_TOKEN_HTTP_HEADER, apiToken)

0 commit comments

Comments
 (0)