diff --git a/src/main/java/io/openliberty/sample/application/CrewMember.java b/src/main/java/io/openliberty/sample/application/CrewMember.java index 6cd1fe2..c11eefe 100644 --- a/src/main/java/io/openliberty/sample/application/CrewMember.java +++ b/src/main/java/io/openliberty/sample/application/CrewMember.java @@ -30,9 +30,6 @@ public class CrewMember { @Positive(message = "ID Number must be a non-negative integer!") private int crewID; - @NotNull(message = "Crew member must be assigned to one of the listed ships!") - private Ship ship; - public String getName() { return name; } @@ -57,16 +54,8 @@ public void setCrewID(int crewID) { this.crewID = crewID; } - public Ship getShip() { - return ship; - } - - public void setShip(Ship ship) { - this.ship = ship; - } - public String toString() { - return "Name: " + name + "
CrewID: " + crewID + "
Rank: " + rank + ship.name != null ? "
Ship: " + ship.name : ""; + return "Name: " + name + "
CrewID: " + crewID + "
Rank: " + rank; } diff --git a/src/main/java/io/openliberty/sample/application/CrewService.java b/src/main/java/io/openliberty/sample/application/CrewService.java index 74b0de6..dd0682a 100755 --- a/src/main/java/io/openliberty/sample/application/CrewService.java +++ b/src/main/java/io/openliberty/sample/application/CrewService.java @@ -65,8 +65,7 @@ public String retrieve() { JsonObject json = Json.createObjectBuilder() .add("Name", c.getName()) .add("CrewID", c.getCrewID()) - .add("Rank",c.getRank().toString()) - .add("Ship", c.getShip().name).build(); + .add("Rank",c.getRank().toString()).build(); jab.add(json); }); @@ -80,8 +79,7 @@ public String retrieveByRank(@PathParam("rank") String rank) { for (CrewMember c : crewMembers.findByRank(Rank.fromString(rank))) { JsonObject json = Json.createObjectBuilder() .add("Name", c.getName()) - .add("CrewID", c.getCrewID()) - .add("Ship", c.getShip().name).build(); + .add("CrewID", c.getCrewID()).build(); jab.add(json); } return jab.build().toString(); diff --git a/src/main/java/io/openliberty/sample/application/RankDeserializer.java b/src/main/java/io/openliberty/sample/application/RankDeserializer.java index 947451d..6d68f1e 100644 --- a/src/main/java/io/openliberty/sample/application/RankDeserializer.java +++ b/src/main/java/io/openliberty/sample/application/RankDeserializer.java @@ -11,7 +11,8 @@ public class RankDeserializer implements JsonbDeserializer { @Override public Rank deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) { - return Rank.fromString(parser.getString()); + String name = parser.getValue().toString().replaceAll("\"", ""); + return Rank.fromString(name); } } \ No newline at end of file diff --git a/src/main/java/io/openliberty/sample/application/Ship.java b/src/main/java/io/openliberty/sample/application/Ship.java deleted file mode 100644 index 56bfbfb..0000000 --- a/src/main/java/io/openliberty/sample/application/Ship.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.openliberty.sample.application; - -import java.io.Serializable; - -import jakarta.json.bind.annotation.JsonbTypeDeserializer; - -@JsonbTypeDeserializer(ShipDeserializer.class) -public class Ship implements Serializable { - public static enum Size { - small, large - } - - public String name; - - public Size size; - - Ship(String name, Size size) { - this.name = name; - this.size = size; - } - -} diff --git a/src/main/java/io/openliberty/sample/application/ShipDeserializer.java b/src/main/java/io/openliberty/sample/application/ShipDeserializer.java deleted file mode 100644 index 02e0205..0000000 --- a/src/main/java/io/openliberty/sample/application/ShipDeserializer.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.openliberty.sample.application; - -import java.lang.reflect.Type; - -import jakarta.json.bind.serializer.DeserializationContext; -import jakarta.json.bind.serializer.JsonbDeserializer; -import jakarta.json.stream.JsonParser; - -public class ShipDeserializer implements JsonbDeserializer { - - @Override - public Ship deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) { - String shipName = parser.getString(); - if (shipName.equals("Liberty Saucer")) { - return new Ship(shipName, Ship.Size.small); - } else if (shipName.equals("Jakarta Sailboat")) { - return new Ship(shipName, Ship.Size.small); - } else if (shipName.equals("WebSphere Battleship")) { - return new Ship(shipName, Ship.Size.large); - } else { - return null; - } - - } - -} diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index 3d5897a..e2c3747 100755 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -53,14 +53,6 @@

Congrats on your shiny, new Open Liberty sample app!

-
- Ship Assignment - -
diff --git a/src/main/webapp/js/app.js b/src/main/webapp/js/app.js index 238be51..9d114a7 100644 --- a/src/main/webapp/js/app.js +++ b/src/main/webapp/js/app.js @@ -16,7 +16,6 @@ async function addCrewMember() { var rank = document.getElementById("crewMemberRank"); crewMember.rank = rank.options[rank.selectedIndex].text; crewMember.crewID = document.getElementById("crewMemberID").value; - crewMember.ship = document.getElementById("crewMemberShip").value const response = await fetch("db/crew/"+crewMember.crewID, { diff --git a/src/main/webapp/js/find-all.js b/src/main/webapp/js/find-all.js index 192ecdc..957f86a 100644 --- a/src/main/webapp/js/find-all.js +++ b/src/main/webapp/js/find-all.js @@ -21,8 +21,7 @@ async function refreshFindAll() { function addToCrewMembers(entry){ var userHtml = "
Name: " + entry.Name + "
" + "
ID: " + entry.CrewID + "
" + - "
Rank: " + entry.Rank + "
" + - "
Ship: " + entry.Ship + "
"; + "
Rank: " + entry.Rank + "
"; var userDiv = document.createElement("div"); userDiv.setAttribute("class","user flexbox"); diff --git a/src/main/webapp/js/find-by-rank.js b/src/main/webapp/js/find-by-rank.js index 798ef01..dd2602f 100644 --- a/src/main/webapp/js/find-by-rank.js +++ b/src/main/webapp/js/find-by-rank.js @@ -35,8 +35,7 @@ async function parseFindByRank(rank, response) { function addToCrewMembersByRank(entry, rank) { var userHtml = "
Name: " + entry.Name + "
" + - "
ID: " + entry.CrewID + "
" + - "
Ship: " + entry.Ship + "
"; + "
ID: " + entry.CrewID + "
"; var userDiv = document.createElement("div"); userDiv.setAttribute("class","user flexbox"); diff --git a/src/test/java/io/openliberty/sample/it/CrewServiceIT.java b/src/test/java/io/openliberty/sample/it/CrewServiceIT.java index 5cbfa37..aa44af9 100644 --- a/src/test/java/io/openliberty/sample/it/CrewServiceIT.java +++ b/src/test/java/io/openliberty/sample/it/CrewServiceIT.java @@ -71,13 +71,13 @@ public void testAddGetDeleteCrewMember() { assertEquals(204, response.getStatus(), "output: " + response.readEntity(String.class)); //Check Add - response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"75\",\"ship\":\"Liberty Saucer\"}")); + response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"75\"}")); assertEquals(200, response.getStatus(), "output: " + response.readEntity(String.class)); //Check Get response = client.target(baseURL + "db/crew").request().get(); JsonReader reader = Json.createReader(new StringReader(response.readEntity(String.class))); - JsonObject expectedObject = Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Rank", "Captain").add("Ship", "Liberty Saucer").build(); + JsonObject expectedObject = Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Rank", "Captain").build(); boolean found = false; for (JsonValue value : reader.readArray()) { @@ -92,7 +92,7 @@ public void testAddGetDeleteCrewMember() { //Confirm Delete response = client.target(baseURL + "db/crew").request().get(); reader = Json.createReader(new StringReader(response.readEntity(String.class))); - expectedObject = Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Rank", "Captain").add("Ship", "Liberty Saucer").build(); + expectedObject = Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Rank", "Captain").build(); found = false; for (JsonValue value : reader.readArray()) { @@ -104,7 +104,7 @@ public void testAddGetDeleteCrewMember() { @Test public void testValidationCrewMember() { //Name Validation - response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"\",\"rank\":\"Captain\",\"crewID\":\"75\",\"ship\":\"Liberty Saucer\"}")); + response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"\",\"rank\":\"Captain\",\"crewID\":\"75\"}")); JsonReader reader = Json.createReader(new StringReader(response.readEntity(String.class))); JsonArray array = reader.readArray(); @@ -112,7 +112,7 @@ public void testValidationCrewMember() { assertEquals("\"All crew members must have a name!\"", array.get(0).toString()); //Rank Validation - response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Scientist\",\"crewID\":\"75\",\"ship\":\"Liberty Saucer\"}")); + response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Scientist\",\"crewID\":\"75\"}")); reader = Json.createReader(new StringReader(response.readEntity(String.class))); array = reader.readArray(); @@ -120,22 +120,13 @@ public void testValidationCrewMember() { assertEquals("\"Crew member must be one of the listed ranks!\"", array.get(0).toString()); //CrewID Validation - response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"-1\",\"ship\":\"Liberty Saucer\"}")); + response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"-1\"}")); reader = Json.createReader(new StringReader(response.readEntity(String.class))); array = reader.readArray(); assertEquals(1, array.size(), "Validation array should have only contained 1 message"); assertEquals("\"ID Number must be a non-negative integer!\"", array.get(0).toString()); - //Ship Validation - response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"75\",\"ship\":\"Quarkus Speedboat\"}")); - - reader = Json.createReader(new StringReader(response.readEntity(String.class))); - array = reader.readArray(); - assertEquals(1, array.size(), "Validation array should have only contained 1 message"); - assertEquals("\"Crew member must be assigned to one of the listed ships!\"", array.get(0).toString()); - - } /** @@ -143,26 +134,26 @@ public void testValidationCrewMember() { */ @Test public void testFindByRank() { - response = client.target(baseURL + "db/crew/it1").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Engineer\",\"crewID\":75,\"ship\":\"Liberty Saucer\"}")); + response = client.target(baseURL + "db/crew/it1").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Engineer\",\"crewID\":75}")); assertEquals(200, response.getStatus(), "output: " + response.readEntity(String.class)); - response = client.target(baseURL + "db/crew/it2").request().post(Entity.json("{\"name\":\"Jim\",\"rank\":\"Captain\",\"crewID\":64,\"ship\":\"Liberty Saucer\"}")); + response = client.target(baseURL + "db/crew/it2").request().post(Entity.json("{\"name\":\"Jim\",\"rank\":\"Captain\",\"crewID\":64}")); assertEquals(200, response.getStatus(), "output: " + response.readEntity(String.class)); - response = client.target(baseURL + "db/crew/it3").request().post(Entity.json("{\"name\":\"Alex\",\"rank\":\"Engineer\",\"crewID\":15,\"ship\":\"Jakarta Sailboat\"}")); + response = client.target(baseURL + "db/crew/it3").request().post(Entity.json("{\"name\":\"Alex\",\"rank\":\"Engineer\",\"crewID\":15}")); assertEquals(200, response.getStatus(), "output: " + response.readEntity(String.class)); //Check findByRank("Captain") response = client.target(baseURL + "db/crew/rank/Captain").request().get(); JsonReader reader = Json.createReader(new StringReader(response.readEntity(String.class))); JsonArray array = reader.readArray(); - JsonArray expectedArray = Json.createArrayBuilder().add(Json.createObjectBuilder().add("Name", "Jim").add("CrewID", 64).add("Ship", "Liberty Saucer").build()).build(); + JsonArray expectedArray = Json.createArrayBuilder().add(Json.createObjectBuilder().add("Name", "Jim").add("CrewID", 64).build()).build(); assertEquals(expectedArray, array); //Check findByRank("Engineer") response = client.target(baseURL + "db/crew/rank/Engineer").request().get(); reader = Json.createReader(new StringReader(response.readEntity(String.class))); array = reader.readArray(); - expectedArray = Json.createArrayBuilder().add(Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Ship", "Liberty Saucer").build()) - .add(Json.createObjectBuilder().add("Name", "Alex").add("CrewID", 15).add("Ship", "Jakarta Sailboat").build()).build(); + expectedArray = Json.createArrayBuilder().add(Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).build()) + .add(Json.createObjectBuilder().add("Name", "Alex").add("CrewID", 15).build()).build(); assertEquals(expectedArray, array); //Check findByRank("Officer")