Skip to content

Commit

Permalink
fix: serialize the leftOperand as an @id (#4185)
Browse files Browse the repository at this point in the history
* fix: serialize the leftOperand as an @id

* chore: deps file
  • Loading branch information
wolf4ood authored May 16, 2024
1 parent f558959 commit ef7b502
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ private JsonObject visitMultiplicityConstraint(String operandType, MultiplicityC
public JsonObject visitAtomicConstraint(AtomicConstraint atomicConstraint) {
var constraintBuilder = jsonFactory.createObjectBuilder();

constraintBuilder.add(ODRL_LEFT_OPERAND_ATTRIBUTE, atomicConstraint.getLeftExpression().accept(this));
var leftOperand = atomicConstraint.getLeftExpression().accept((expression) -> expression.getValue().toString());
constraintBuilder.add(ODRL_LEFT_OPERAND_ATTRIBUTE, jsonFactory.createArrayBuilder().add(jsonFactory.createObjectBuilder().add(ID, leftOperand)));
var operator = atomicConstraint.getOperator().getOdrlRepresentation();
constraintBuilder.add(ODRL_OPERATOR_ATTRIBUTE, jsonFactory.createArrayBuilder().add(jsonFactory.createObjectBuilder().add(ID, operator)));
constraintBuilder.add(ODRL_RIGHT_OPERAND_ATTRIBUTE, atomicConstraint.getRightExpression().accept(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void transform_actionWithAllAttributes_returnJsonObject() {
assertThat(actionJson.getJsonObject(ODRL_REFINEMENT_ATTRIBUTE)).isNotNull();

var constraintJson = actionJson.getJsonObject(ODRL_REFINEMENT_ATTRIBUTE);
assertThat(constraintJson.getJsonObject(ODRL_LEFT_OPERAND_ATTRIBUTE).getJsonString(VALUE).getString())
assertThat(constraintJson.getJsonArray(ODRL_LEFT_OPERAND_ATTRIBUTE).getJsonObject(0).getString(ID))
.isEqualTo(((LiteralExpression) constraint.getLeftExpression()).getValue());
assertThat(constraintJson.getJsonArray(ODRL_OPERATOR_ATTRIBUTE).getJsonObject(0).getString(ID))
.isEqualTo(constraint.getOperator().getOdrlRepresentation());
Expand Down Expand Up @@ -221,7 +221,7 @@ void transform_permissionWithConstraintAndDuty_returnJsonObject() {
assertThat(permissionJson.getJsonArray(ODRL_DUTY_ATTRIBUTE)).hasSize(1);

var constraintJson = permissionJson.getJsonArray(ODRL_CONSTRAINT_ATTRIBUTE).get(0).asJsonObject();
assertThat(constraintJson.getJsonObject(ODRL_LEFT_OPERAND_ATTRIBUTE).getJsonString(VALUE).getString())
assertThat(constraintJson.getJsonArray(ODRL_LEFT_OPERAND_ATTRIBUTE).getJsonObject(0).getString(ID))
.isEqualTo(((LiteralExpression) constraint.getLeftExpression()).getValue());
assertThat(constraintJson.getJsonArray(ODRL_OPERATOR_ATTRIBUTE).getJsonObject(0).getString(ID))
.isEqualTo(constraint.getOperator().getOdrlRepresentation());
Expand Down Expand Up @@ -253,7 +253,7 @@ void transform_prohibitionWithConstraint_returnJsonObject() {
assertThat(prohibitionJson.getJsonArray(ODRL_CONSTRAINT_ATTRIBUTE)).hasSize(1);

var constraintJson = prohibitionJson.getJsonArray(ODRL_CONSTRAINT_ATTRIBUTE).get(0).asJsonObject();
assertThat(constraintJson.getJsonObject(ODRL_LEFT_OPERAND_ATTRIBUTE).getJsonString(VALUE).getString())
assertThat(constraintJson.getJsonArray(ODRL_LEFT_OPERAND_ATTRIBUTE).getJsonObject(0).getString(ID))
.isEqualTo(((LiteralExpression) constraint.getLeftExpression()).getValue());
assertThat(constraintJson.getJsonArray(ODRL_OPERATOR_ATTRIBUTE).getJsonObject(0).getString(ID))
.isEqualTo(constraint.getOperator().getOdrlRepresentation());
Expand Down Expand Up @@ -289,7 +289,7 @@ void transform_dutyWithConstraintAndConsequence_returnJsonObject() {
assertThat(dutyJson.getJsonArray(ODRL_CONSTRAINT_ATTRIBUTE)).hasSize(1);

var constraintJson = dutyJson.getJsonArray(ODRL_CONSTRAINT_ATTRIBUTE).get(0).asJsonObject();
assertThat(constraintJson.getJsonObject(ODRL_LEFT_OPERAND_ATTRIBUTE).getJsonString(VALUE).getString())
assertThat(constraintJson.getJsonArray(ODRL_LEFT_OPERAND_ATTRIBUTE).getJsonObject(0).getString(ID))
.isEqualTo(((LiteralExpression) constraint.getLeftExpression()).getValue());
assertThat(constraintJson.getJsonArray(ODRL_OPERATOR_ATTRIBUTE).getJsonObject(0).getString(ID))
.isEqualTo(constraint.getOperator().getOdrlRepresentation());
Expand Down

0 comments on commit ef7b502

Please sign in to comment.