Skip to content
This repository was archived by the owner on Apr 24, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
public class TechnicalEvaluationDTODeserializer extends UpdateOrDelete.Deserializer<TechnicalEvaluationDTO> {
@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,28 @@
public class TechnicalEvaluationDTO {
@JsonProperty
@Schema(description = "Whether this node requires a technical evaluation.")
private Optional<Boolean> requiresEvaluation = Optional.empty();
private boolean requiresEvaluation;

@JsonProperty
@Schema(description = "Notes for the technical evaluation of this node.")
private Optional<String> comment = Optional.empty();

public TechnicalEvaluationDTO(Optional<Boolean> requiresEvaluation, Optional<String> comment) {
public TechnicalEvaluationDTO(boolean requiresEvaluation, Optional<String> comment) {
this.requiresEvaluation = requiresEvaluation;
this.comment = comment;
}

public static Optional<TechnicalEvaluationDTO> 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<Boolean> requiresEvaluation() {
public boolean requiresEvaluation() {
return requiresEvaluation;
}

public void setRequiresEvaluation(Optional<Boolean> requiresEvaluation) {
public void setRequiresEvaluation(boolean requiresEvaluation) {
this.requiresEvaluation = requiresEvaluation;
}

Expand Down
49 changes: 12 additions & 37 deletions src/test/java/no/ndla/taxonomy/rest/v1/NodesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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();
Expand Down
Loading