Skip to content

Commit

Permalink
just pass all possible values to CreateThing.of and let the validatio…
Browse files Browse the repository at this point in the history
…n happen

Signed-off-by: Klem Yannic (INST/ECS1) <Yannic.Klem@bosch-si.com>
  • Loading branch information
Yannic92 committed Oct 22, 2018
1 parent a53896c commit 98526a4
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,16 @@ private Route things(final RequestContext ctx, final DittoHeaders dittoHeaders)
post(() -> // POST /things
extractDataBytes(payloadSource ->
handlePerRequest(ctx, dittoHeaders, payloadSource,
thingJson -> fromThingJson(thingJson, dittoHeaders)
thingJson -> CreateThing.of(createThingForPost(thingJson),
createInlinePolicyJson(thingJson), getCopyPolicyFrom(thingJson),
dittoHeaders)
)
)
)
)
);
}

private CreateThing fromThingJson(final String thingJson, final DittoHeaders dittoHeaders) {
final String policyIdOrPlaceholder = getCopyPolicyFrom(thingJson);
if (policyIdOrPlaceholder == null) {
return CreateThing.of(createThingForPost(thingJson), createInlinePolicyJson(thingJson), dittoHeaders);
} else {
return CreateThing.withCopiedPolicy(createThingForPost(thingJson), policyIdOrPlaceholder, dittoHeaders);
}
}


private Route buildRetrieveThingsRoute(final RequestContext ctx, final DittoHeaders dittoHeaders) {
return parameter(ThingsParameter.IDS.toString(), idsString ->
parameterOptional(ThingsParameter.FIELDS.toString(), fieldsString ->
Expand Down

0 comments on commit 98526a4

Please sign in to comment.