use of org.eclipse.ditto.base.model.headers.DittoHeaders in project ditto by eclipse.
the class SudoRetrieveThing method fromJson.
/**
* Creates a new {@code SudoRetrieveThing} from a JSON object.
*
* @param jsonObject the JSON string of which a new SudoRetrieveThing is to be created.
* @param dittoHeaders the optional command headers of the request.
* @return the SudoRetrieveThing which was created from the given JSON object.
* @throws NullPointerException if {@code jsonObject} is {@code null}.
* @throws org.eclipse.ditto.json.JsonMissingFieldException if the passed in {@code jsonObject} was not in the
* expected format.
*/
public static SudoRetrieveThing fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) {
final String extractedThingId = jsonObject.getValueOrThrow(SudoCommand.JsonFields.JSON_THING_ID);
final ThingId thingId = ThingId.of(extractedThingId);
final JsonFieldSelector readFieldSelector = jsonObject.getValue(SudoCommand.JsonFields.SELECTED_FIELDS).map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder().withoutUrlDecoding().build())).orElse(null);
final boolean isUseOriginalSchemaVersion = jsonObject.getValue(JSON_USE_ORIGINAL_SCHEMA_VERSION).orElse(false);
return new SudoRetrieveThing(thingId, readFieldSelector, dittoHeaders, isUseOriginalSchemaVersion);
}
use of org.eclipse.ditto.base.model.headers.DittoHeaders in project ditto by eclipse.
the class SudoRetrieveThings method fromJson.
/**
* Creates a new {@code SudoRetrieveThings} from a JSON object.
*
* @param jsonObject the JSON string of which a new SudoRetrieveThings is to be created.
* @param dittoHeaders the optional command headers of the request.
* @return the SudoRetrieveThings which was created from the given JSON object.
* @throws NullPointerException if {@code jsonObject} is {@code null}.
* @throws org.eclipse.ditto.json.JsonMissingFieldException if the passed in {@code jsonObject} was not in the
* expected format.
*/
public static SudoRetrieveThings fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) {
final List<ThingId> extractedThingIds = jsonObject.getValueOrThrow(JSON_THING_IDS).stream().filter(JsonValue::isString).map(JsonValue::asString).map(ThingId::of).collect(Collectors.toList());
final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(SudoCommand.JsonFields.SELECTED_FIELDS).map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder().withoutUrlDecoding().build())).orElse(null);
return SudoRetrieveThings.of(extractedThingIds, extractedFieldSelector, dittoHeaders);
}
use of org.eclipse.ditto.base.model.headers.DittoHeaders in project ditto by eclipse.
the class ThingLiveCommandAckRequestSetterTest method addsLiveResponseAckLabelToAlreadyRequiredAckLabels.
@Test
public void addsLiveResponseAckLabelToAlreadyRequiredAckLabels() {
final AcknowledgementRequest ackRequest1 = AcknowledgementRequest.of(AcknowledgementLabel.of("FOO"));
final AcknowledgementRequest ackRequest2 = AcknowledgementRequest.of(AcknowledgementLabel.of("BAR"));
final DittoHeaders dittoHeaders = DittoHeaders.newBuilder().channel("live").acknowledgementRequest(ackRequest1, ackRequest2).randomCorrelationId().responseRequired(true).build();
final CreateThing command = CreateThing.of(Thing.newBuilder().build(), null, dittoHeaders);
final ThingLiveCommandAckRequestSetter underTest = ThingLiveCommandAckRequestSetter.getInstance();
final DittoHeaders expectedHeaders = dittoHeaders.toBuilder().acknowledgementRequest(ackRequest1, ackRequest2, AcknowledgementRequest.of(DittoAcknowledgementLabel.LIVE_RESPONSE)).build();
final CreateThing expectedCommand = command.setDittoHeaders(expectedHeaders);
assertThat(underTest.apply(command)).isEqualTo(expectedCommand);
}
use of org.eclipse.ditto.base.model.headers.DittoHeaders in project ditto by eclipse.
the class ThingLiveCommandAckRequestSetterTest method notAddingLiveResponseAckLabelToExplicitlyEmptyRequiredAckLabels.
@Test
public void notAddingLiveResponseAckLabelToExplicitlyEmptyRequiredAckLabels() {
final DittoHeaders dittoHeaders = DittoHeaders.newBuilder().channel("live").acknowledgementRequests(Collections.emptyList()).randomCorrelationId().responseRequired(true).build();
final CreateThing command = CreateThing.of(Thing.newBuilder().build(), null, dittoHeaders);
final ThingLiveCommandAckRequestSetter underTest = ThingLiveCommandAckRequestSetter.getInstance();
final DittoHeaders expectedHeaders = dittoHeaders.toBuilder().acknowledgementRequests(Collections.emptyList()).build();
final CreateThing expectedCommand = command.setDittoHeaders(expectedHeaders);
assertThat(underTest.apply(command)).isEqualTo(expectedCommand);
}
use of org.eclipse.ditto.base.model.headers.DittoHeaders in project ditto by eclipse.
the class ThingLiveCommandAckRequestSetterTest method addLiveResponseAckLabelByDefault.
@Test
public void addLiveResponseAckLabelByDefault() {
final DittoHeaders dittoHeaders = DittoHeaders.newBuilder().channel("live").randomCorrelationId().build();
final CreateThing command = CreateThing.of(Thing.newBuilder().build(), null, dittoHeaders);
final CreateThing expected = command.setDittoHeaders(DittoHeaders.newBuilder(dittoHeaders).acknowledgementRequest(AcknowledgementRequest.of(DittoAcknowledgementLabel.LIVE_RESPONSE)).responseRequired(true).build());
final ThingLiveCommandAckRequestSetter underTest = ThingLiveCommandAckRequestSetter.getInstance();
assertThat(underTest.apply(command)).isEqualTo(expected);
}
Aggregations