Skip to content

Commit

Permalink
chore(dsp-contract-negotiation-transform): refactor type method to la…
Browse files Browse the repository at this point in the history
…mbda expression and remove unnecessary dependency
  • Loading branch information
janpmeyer committed Apr 25, 2023
1 parent 3403644 commit e39de4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ plugins {
}

dependencies {
api(project(":spi:common:core-spi"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,32 @@
*/
public class JsonObjectToContractNegotiationEventMessageTransformer extends AbstractJsonLdTransformer<JsonObject, ContractNegotiationEventMessage> {

private TransformerContext context;
private ContractNegotiationEventMessage.Type eventType;

public JsonObjectToContractNegotiationEventMessageTransformer() {
super(JsonObject.class, ContractNegotiationEventMessage.class);
}

@Override
public @Nullable ContractNegotiationEventMessage transform(@NotNull JsonObject object, @NotNull TransformerContext context) {
this.context = context;

var builder = ContractNegotiationEventMessage.Builder.newInstance();
builder.protocol(DATASPACE_PROTOCOL_HTTP);
transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID), builder::processId, context);
transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_CHECKSUM), builder::checksum, context);

transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE), this::type, context);

if (eventType == null) {
return null;
}

builder.type(eventType);
transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE), (value) -> {
switch (value) {
case DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED:
builder.type(ACCEPTED);
break;
case DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED:
builder.type(FINALIZED);
break;
default:
context.reportProblem(String.format("Could not map type %s", value));
}
}, context);

return builder.build();
}

private void type(String type) {
switch (type) {
case DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED:
eventType = ACCEPTED;
break;
case DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED:
eventType = FINALIZED;
break;
default:
context.reportProblem(String.format("Could not map type %s", type));
}
}

}

0 comments on commit e39de4a

Please sign in to comment.