@Override public SudoRetrieveThingResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thing, dittoHeaders); }
/** * Creates a new instance of {@code SudoRetrieveThingResponse}. * * @param thing the retrieved Thing. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static SudoRetrieveThingResponse of(final JsonObject thing, final DittoHeaders dittoHeaders) { return new SudoRetrieveThingResponse(HttpStatusCode.OK, thing, dittoHeaders); }
@SuppressWarnings({"squid:MethodCyclomaticComplexity", "squid:S1067", "pmd:SimplifyConditional"}) @Override public boolean equals(@Nullable final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final SudoRetrieveThingResponse that = (SudoRetrieveThingResponse) o; return that.canEqual(this) && Objects.equals(thing, that.thing) && super.equals(that); }
private Function<Jsonifiable<?>, PlainJson> supplyPlainJsonFromSudoRetrieveThingResponse() { return jsonifiable -> { if (jsonifiable instanceof SudoRetrieveThingResponse) { final SudoRetrieveThingResponse response = (SudoRetrieveThingResponse) jsonifiable; final String json = response.getEntityPlainString().orElseGet(() -> response.getEntity(response.getImplementedSchemaVersion()).toString()); return PlainJson.of(response.getId(), json); } else { return null; } }; }
@Override public SudoRetrieveThingResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(entity.asObject(), getDittoHeaders()); }
private void handleSyncThingResponse(final SudoRetrieveThingResponse response) { log.debug("Retrieved thing response='{}' for thing ID='{}' (attempt={}).", response, thingId, syncAttempts); final Thing syncedThing = response.getThing(); updateThingSearchIndex(syncedThing); }
/** * Creates a new {@code SudoRetrieveThingResponse} from a JSON string. * * @param jsonString the JSON string of which a new SudoRetrieveThingResponse instance is to be created. * @param dittoHeaders the optional command headers of the request. * @return the {@code SudoRetrieveThingResponse} which was created from the given JSON string. * @throws NullPointerException if {@code dittoHeaders} is {@code null}. * @throws DittoJsonException if the passed in {@code jsonString} was {@code null}, empty or not in the expected * 'SudoRetrieveThingResponse' format. */ public static SudoRetrieveThingResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { final JsonObject jsonObject = DittoJsonException.wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); return fromJson(jsonObject, dittoHeaders); }
@Override public SudoRetrieveThingResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(entity.asObject(), getDittoHeaders()); }
private void handleSyncThingResponse(final SudoRetrieveThingResponse response) { log.debug("Retrieved thing response='{}' for thing ID='{}' (attempt={}).", response, thingId, syncAttempts); final Thing syncedThing = response.getThing(); updateThingSearchIndex(syncedThing); }
/** * Creates a new {@code SudoRetrieveThingResponse} from a JSON string. * * @param jsonString the JSON string of which a new SudoRetrieveThingResponse instance is to be created. * @param dittoHeaders the optional command headers of the request. * @return the {@code SudoRetrieveThingResponse} which was created from the given JSON string. * @throws NullPointerException if {@code dittoHeaders} is {@code null}. * @throws DittoJsonException if the passed in {@code jsonString} was {@code null}, empty or not in the expected * 'SudoRetrieveThingResponse' format. */ public static SudoRetrieveThingResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { final JsonObject jsonObject = DittoJsonException.wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); return fromJson(jsonObject, dittoHeaders); }
@Override public SudoRetrieveThingResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thing, dittoHeaders); }
@Nullable private static Entry<Enforcer> handleSudoRetrieveThingResponse(final Object response) { if (response instanceof SudoRetrieveThingResponse) { final SudoRetrieveThingResponse sudoRetrieveThingResponse = (SudoRetrieveThingResponse) response; final Thing thing = sudoRetrieveThingResponse.getThing(); final Optional<AccessControlList> accessControlListOptional = thing.getAccessControlList(); if (accessControlListOptional.isPresent()) { final AccessControlList accessControlList = accessControlListOptional.get(); final long revision = thing.getRevision().map(ThingRevision::toLong) .orElseThrow(badThingResponse("no revision")); return Entry.of(revision, AclEnforcer.of(accessControlList)); } else { // The thing exists, but it has a policy. Remove entry from cache. return null; } } else if (response instanceof ThingNotAccessibleException) { return Entry.nonexistent(); } else { throw new IllegalStateException("expect SudoRetrieveThingResponse, got: " + response); } }
/** * Creates a new instance of {@code SudoRetrieveThingResponse}. * * @param thing the retrieved Thing. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static SudoRetrieveThingResponse of(final JsonObject thing, final DittoHeaders dittoHeaders) { return new SudoRetrieveThingResponse(HttpStatusCode.OK, thing, dittoHeaders); }
@SuppressWarnings({"squid:MethodCyclomaticComplexity", "squid:S1067", "pmd:SimplifyConditional"}) @Override public boolean equals(@Nullable final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final SudoRetrieveThingResponse that = (SudoRetrieveThingResponse) o; return that.canEqual(this) && Objects.equals(thing, that.thing) && super.equals(that); }
/** * Creates a new {@code SudoRetrieveThingResponse} from a JSON object. * * @param jsonObject the JSON object of which a new SudoRetrieveThingResponse instance is to be created. * @param dittoHeaders the optional command headers of the request. * @return the {@code SudoRetrieveThingResponse} which was created from the given JSON object. * @throws NullPointerException if any argument is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * 'SudoRetrieveThingResponse' format. */ public static SudoRetrieveThingResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<SudoRetrieveThingResponse>(TYPE, jsonObject) .deserialize(statusCode -> { final JsonObject extractedThing = jsonObject.getValueOrThrow(JSON_THING); return of(extractedThing, dittoHeaders); }); }
private static Entry<EntityId> handleSudoRetrieveThingResponse(final Object response) { if (response instanceof SudoRetrieveThingResponse) { final SudoRetrieveThingResponse sudoRetrieveThingResponse = (SudoRetrieveThingResponse) response; final Thing thing = sudoRetrieveThingResponse.getThing(); final String thingId = thing.getId().orElseThrow(badThingResponse("no ThingId")); final long revision = thing.getRevision().map(ThingRevision::toLong) .orElseThrow(badThingResponse("no revision")); final Optional<AccessControlList> accessControlListOptional = thing.getAccessControlList(); if (accessControlListOptional.isPresent()) { final EntityId resourceKey = EntityId.of(ThingCommand.RESOURCE_TYPE, thingId); return Entry.of(revision, resourceKey); } else { final String policyId = thing.getPolicyId().orElseThrow(badThingResponse("no PolicyId or ACL")); final EntityId resourceKey = EntityId.of(PolicyCommand.RESOURCE_TYPE, policyId); return Entry.of(revision, resourceKey); } } else if (response instanceof ThingNotAccessibleException) { return Entry.nonexistent(); } else { throw new IllegalStateException("expect SudoRetrieveThingResponse, got: " + response); } }
/** * Creates a new {@code SudoRetrieveThingResponse} from a JSON object. * * @param jsonObject the JSON object of which a new SudoRetrieveThingResponse instance is to be created. * @param dittoHeaders the optional command headers of the request. * @return the {@code SudoRetrieveThingResponse} which was created from the given JSON object. * @throws NullPointerException if any argument is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * 'SudoRetrieveThingResponse' format. */ public static SudoRetrieveThingResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<SudoRetrieveThingResponse>(TYPE, jsonObject) .deserialize(statusCode -> { final JsonObject extractedThing = jsonObject.getValueOrThrow(JSON_THING); return of(extractedThing, dittoHeaders); }); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final SudoRetrieveThing command) { final Thing theThing = getThingOrThrow(thing); final JsonSchemaVersion jsonSchemaVersion = determineSchemaVersion(command, theThing); final JsonObject thingJson = command.getSelectedFields() .map(selectedFields -> theThing.toJson(jsonSchemaVersion, selectedFields, FieldType.regularOrSpecial())) .orElseGet(() -> theThing.toJson(jsonSchemaVersion, FieldType.regularOrSpecial())); return ResultFactory.newQueryResult(command, thing, SudoRetrieveThingResponse.of(thingJson, command.getDittoHeaders()), this); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final SudoRetrieveThing command) { final Thing theThing = getThingOrThrow(thing); final JsonSchemaVersion jsonSchemaVersion = determineSchemaVersion(command, theThing); final JsonObject thingJson = command.getSelectedFields() .map(selectedFields -> theThing.toJson(jsonSchemaVersion, selectedFields, FieldType.regularOrSpecial())) .orElseGet(() -> theThing.toJson(jsonSchemaVersion, FieldType.regularOrSpecial())); return ResultFactory.newQueryResult(command, thing, SudoRetrieveThingResponse.of(thingJson, command.getDittoHeaders()), this); }