Skip to content

Commit

Permalink
refactor(EdcAdapterService): improved null value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-rm-meyer-ISST committed May 15, 2024
1 parent cd17779 commit 517a2c7
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Response sendGetRequest(List<String> pathSegments) throws IOException {
* Any caller of this method has the responsibility to close
* the returned Response object after using it.
*
* @param requestBody The request body; null if no body is needed
* @param requestBody The request body, not null
* @param pathSegments The path segments
* @return The response from your control plane
* @throws IOException If the connection to your control plane fails
Expand All @@ -124,11 +124,7 @@ private Response sendPostRequest(JsonNode requestBody, List<String> pathSegments
for (var pathSegment : pathSegments) {
urlBuilder.addPathSegment(pathSegment);
}
RequestBody body = null;

if (requestBody != null) {
body = RequestBody.create(requestBody.toString(), MediaType.parse("application/json"));
}
RequestBody body = RequestBody.create(requestBody.toString(), MediaType.parse("application/json"));

var request = new Request.Builder()
.post(body)
Expand Down Expand Up @@ -1116,19 +1112,23 @@ private boolean testSingleConstraint(Optional<JsonNode> constraintToTest, String

JsonNode leftOperandNode = con.get("odrl:leftOperand");
if (leftOperandNode == null || !targetLeftOperand.equals(leftOperandNode.asText())) {
log.debug("Left operand {} odes not equal expected value {}.", leftOperandNode.asText(), targetLeftOperand);
String leftOperand = leftOperandNode == null ? "null" : leftOperandNode.asText();
log.debug("Left operand '{}' does not equal expected value '{}'.", leftOperand, targetLeftOperand);
return false;
}

JsonNode operatorNode = con.get("odrl:operator").get("@id");
JsonNode operatorNode = con.get("odrl:operator");
operatorNode = operatorNode == null ? null : operatorNode.get("@id");
if (operatorNode == null || !targetOperator.equals(operatorNode.asText())) {
log.debug("Operator {} does not equal expected value {}.", operatorNode.asText(), targetOperator);
String operator = operatorNode == null ? "null" : operatorNode.asText();
log.debug("Operator '{}' does not equal expected value '{}'.", operator, targetOperator);
return false;
}

JsonNode rightOperandNode = con.get("odrl:rightOperand");
if (operatorNode == null || !targetRightOperand.equals(rightOperandNode.asText())) {
log.debug("Right operand {} odes not equal expected value {}.", rightOperandNode.asText(), targetRightOperand);
String rightOperand = rightOperandNode == null ? "null" : rightOperandNode.asText();
log.debug("Right operand '{}' odes not equal expected value '{}'.", rightOperand, targetRightOperand);
return false;
}

Expand Down

0 comments on commit 517a2c7

Please sign in to comment.