diff --git a/src/main/java/no/ndla/taxonomy/domain/TechnicalEvaluationDTODeserializer.java b/src/main/java/no/ndla/taxonomy/domain/TechnicalEvaluationDTODeserializer.java index 56b2089a..8c3ba665 100644 --- a/src/main/java/no/ndla/taxonomy/domain/TechnicalEvaluationDTODeserializer.java +++ b/src/main/java/no/ndla/taxonomy/domain/TechnicalEvaluationDTODeserializer.java @@ -14,9 +14,8 @@ public class TechnicalEvaluationDTODeserializer extends UpdateOrDelete.Deserializer { @Override protected TechnicalEvaluationDTO deserializeInner(JsonNode node) { - var requiresEvaluation = Optional.ofNullable(node.get("requiresEvaluation")) - .filter(JsonNode::isBoolean) - .map(JsonNode::booleanValue); + var requiresEvaluationNode = node.get("requiresEvaluation"); + var requiresEvaluation = requiresEvaluationNode != null && requiresEvaluationNode.booleanValue(); var comment = Optional.ofNullable(node.get("comment")).map(JsonNode::textValue); return new TechnicalEvaluationDTO(requiresEvaluation, comment); } diff --git a/src/main/java/no/ndla/taxonomy/rest/v1/commands/NodePostPut.java b/src/main/java/no/ndla/taxonomy/rest/v1/commands/NodePostPut.java index f8f80a3b..15116198 100644 --- a/src/main/java/no/ndla/taxonomy/rest/v1/commands/NodePostPut.java +++ b/src/main/java/no/ndla/taxonomy/rest/v1/commands/NodePostPut.java @@ -119,10 +119,8 @@ public void apply(Node node) { node.setTechnicalEvaluationComment(Optional.empty()); } else { this.technicalEvaluation.getValue().ifPresent(te -> { - te.requiresEvaluation().ifPresent(requiresEvaluation -> { - node.setRequiresTechnicalEvaluation(Optional.of(requiresEvaluation)); - node.setTechnicalEvaluationComment(requiresEvaluation ? te.getComment() : Optional.empty()); - }); + node.setRequiresTechnicalEvaluation(Optional.of(te.requiresEvaluation())); + node.setTechnicalEvaluationComment(te.requiresEvaluation() ? te.getComment() : Optional.empty()); }); } diff --git a/src/main/java/no/ndla/taxonomy/service/dtos/TechnicalEvaluationDTO.java b/src/main/java/no/ndla/taxonomy/service/dtos/TechnicalEvaluationDTO.java index 09b15bf4..45db2351 100644 --- a/src/main/java/no/ndla/taxonomy/service/dtos/TechnicalEvaluationDTO.java +++ b/src/main/java/no/ndla/taxonomy/service/dtos/TechnicalEvaluationDTO.java @@ -16,31 +16,28 @@ public class TechnicalEvaluationDTO { @JsonProperty @Schema(description = "Whether this node requires a technical evaluation.") - private Optional requiresEvaluation = Optional.empty(); + private boolean requiresEvaluation; @JsonProperty @Schema(description = "Notes for the technical evaluation of this node.") private Optional comment = Optional.empty(); - public TechnicalEvaluationDTO(Optional requiresEvaluation, Optional comment) { + public TechnicalEvaluationDTO(boolean requiresEvaluation, Optional comment) { this.requiresEvaluation = requiresEvaluation; this.comment = comment; } public static Optional fromNode(Node node) { - if (node.requiresTechnicalEvaluation().isEmpty() - && node.getTechnicalEvaluationComment().isEmpty()) { - return Optional.empty(); - } - return Optional.of( - new TechnicalEvaluationDTO(node.requiresTechnicalEvaluation(), node.getTechnicalEvaluationComment())); + return node.requiresTechnicalEvaluation() + .map(requiresEvaluation -> + new TechnicalEvaluationDTO(requiresEvaluation, node.getTechnicalEvaluationComment())); } - public Optional requiresEvaluation() { + public boolean requiresEvaluation() { return requiresEvaluation; } - public void setRequiresEvaluation(Optional requiresEvaluation) { + public void setRequiresEvaluation(boolean requiresEvaluation) { this.requiresEvaluation = requiresEvaluation; } diff --git a/src/test/java/no/ndla/taxonomy/rest/v1/NodesTest.java b/src/test/java/no/ndla/taxonomy/rest/v1/NodesTest.java index 4140301b..c3558b14 100644 --- a/src/test/java/no/ndla/taxonomy/rest/v1/NodesTest.java +++ b/src/test/java/no/ndla/taxonomy/rest/v1/NodesTest.java @@ -1854,8 +1854,8 @@ public void that_updating_requires_technical_evaluation_to_false_removes_comment var command = new NodePostPut() { { nodeType = NodeType.TOPIC; - technicalEvaluation = UpdateOrDelete.Update( - new TechnicalEvaluationDTO(Optional.of(true), Optional.of("Needs review"))); + technicalEvaluation = + UpdateOrDelete.Update(new TechnicalEvaluationDTO(true, Optional.of("Needs review"))); } }; var id = getId(testUtils.createResource("/v1/nodes", command)); @@ -1866,8 +1866,8 @@ public void that_updating_requires_technical_evaluation_to_false_removes_comment var command2 = new NodePostPut() { { - technicalEvaluation = UpdateOrDelete.Update( - new TechnicalEvaluationDTO(Optional.of(false), Optional.of("Needs review"))); + technicalEvaluation = + UpdateOrDelete.Update(new TechnicalEvaluationDTO(false, Optional.of("Needs review"))); } }; testUtils.updateResource("/v1/nodes/" + id, command2); @@ -1881,8 +1881,7 @@ public void that_technical_evluation_comment_can_be_updated() throws Exception { var command = new NodePostPut() { { nodeType = NodeType.TOPIC; - technicalEvaluation = - UpdateOrDelete.Update(new TechnicalEvaluationDTO(Optional.of(true), Optional.empty())); + technicalEvaluation = UpdateOrDelete.Update(new TechnicalEvaluationDTO(true, Optional.empty())); } }; var id = getId(testUtils.createResource("/v1/nodes", command)); @@ -1893,8 +1892,8 @@ public void that_technical_evluation_comment_can_be_updated() throws Exception { var command2 = new NodePostPut() { { - technicalEvaluation = UpdateOrDelete.Update( - new TechnicalEvaluationDTO(Optional.of(true), Optional.of("Needs review"))); + technicalEvaluation = + UpdateOrDelete.Update(new TechnicalEvaluationDTO(true, Optional.of("Needs review"))); } }; testUtils.updateResource("/v1/nodes/" + id, command2); @@ -1909,8 +1908,8 @@ public void that_comment_cannot_be_set_without_requiring_technical_evaluation() var command = new NodePostPut() { { nodeType = NodeType.TOPIC; - technicalEvaluation = UpdateOrDelete.Update( - new TechnicalEvaluationDTO(Optional.of(false), Optional.of("Needs review"))); + technicalEvaluation = + UpdateOrDelete.Update(new TechnicalEvaluationDTO(false, Optional.of("Needs review"))); } }; var id = getId(testUtils.createResource("/v1/nodes", command)); @@ -1925,8 +1924,8 @@ public void that_technical_evaluation_is_included_in_node_response() throws Exce var command = new NodePostPut() { { nodeType = NodeType.TOPIC; - technicalEvaluation = UpdateOrDelete.Update( - new TechnicalEvaluationDTO(Optional.of(true), Optional.of("Needs review"))); + technicalEvaluation = + UpdateOrDelete.Update(new TechnicalEvaluationDTO(true, Optional.of("Needs review"))); } }; var id = getId(testUtils.createResource("/v1/nodes", command)); @@ -1935,34 +1934,10 @@ public void that_technical_evaluation_is_included_in_node_response() throws Exce var nodeDTO = testUtils.getObject(NodeDTO.class, response); var te = nodeDTO.getTechnicalEvaluation().orElseThrow(); - assertTrue(te.requiresEvaluation().orElseThrow()); + assertTrue(te.requiresEvaluation()); assertEquals("Needs review", te.getComment().orElseThrow()); } - @Test - public void that_setting_comment_with_empty_requires_evaluation_does_nothing() throws Exception { - var command = new NodePostPut() { - { - nodeType = NodeType.TOPIC; - technicalEvaluation = - UpdateOrDelete.Update(new TechnicalEvaluationDTO(Optional.of(true), Optional.empty())); - } - }; - var id = getId(testUtils.createResource("/v1/nodes", command)); - - var command2 = new NodePostPut() { - { - technicalEvaluation = UpdateOrDelete.Update( - new TechnicalEvaluationDTO(Optional.empty(), Optional.of("Needs review"))); - } - }; - testUtils.updateResource("/v1/nodes/" + id, command2); - - var found = nodeRepository.getByPublicId(id); - assertTrue(found.requiresTechnicalEvaluation().orElseThrow()); - assertTrue(found.getTechnicalEvaluationComment().isEmpty()); - } - public void testQualityEvaluationAverage(Node inputNode, int expectedCount, double expectedAverage) { var node = nodeRepository.findFirstByPublicId(inputNode.getPublicId()).orElseThrow(); var qe = node.getChildQualityEvaluationAverage().orElseThrow();