/** * Migrates the passed in {@code connectionJsonObject} into the current {@link Connection} structure. * <br /> * If the {@code connectionJsonObject} is already in the current structure, simply build a {@link Connection} * instance from it. * * @param connectionJsonObject the Connection JSON to parse * @return the (potentially migrated) Connection instance */ static Connection connectionFromJsonWithMigration(@Nonnull final JsonObject connectionJsonObject) { final Function<JsonObject, JsonObject> migrateSourceFilters = new MigrateSourceFilters(); final Function<JsonObject, JsonObject> migrateAuthorizationContexts = new MigrateAuthorizationContexts(); return ConnectivityModelFactory.connectionFromJson( migrateAuthorizationContexts .andThen(migrateSourceFilters) .apply(connectionJsonObject)); }
/** * Migrates the passed in {@code connectionJsonObject} into the current {@link Connection} structure. * <br /> * If the {@code connectionJsonObject} is already in the current structure, simply build a {@link Connection} * instance from it. * * @param connectionJsonObject the Connection JSON to parse * @return the (potentially migrated) Connection instance */ static Connection connectionFromJsonWithMigration(@Nonnull final JsonObject connectionJsonObject) { final Function<JsonObject, JsonObject> migrateSourceFilters = new MigrateSourceFilters(); final Function<JsonObject, JsonObject> migrateAuthorizationContexts = new MigrateAuthorizationContexts(); return ConnectivityModelFactory.connectionFromJson( migrateAuthorizationContexts .andThen(migrateSourceFilters) .apply(connectionJsonObject)); }
/** * Creates a new {@code ModifyConnection} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static ModifyConnection fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<ModifyConnection>(TYPE, jsonObject).deserialize(() -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * Creates a new {@code TestConnection} from a JSON object. * * @param jsonObject the JSON object of which the command is to be tested. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static TestConnection fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<TestConnection>(TYPE, jsonObject).deserialize(() -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * Creates a new {@code ModifyConnection} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static ModifyConnection fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<ModifyConnection>(TYPE, jsonObject).deserialize(() -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * Creates a new {@code CreateConnectionResponse} from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the response. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static CreateConnectionResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<CreateConnectionResponse>(TYPE, jsonObject).deserialize( statusCode -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * Creates a new {@code RetrieveConnectionResponse} from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the response. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveConnectionResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveConnectionResponse>(TYPE, jsonObject).deserialize( statusCode -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * Creates a {@code ConnectionModified} event from a JSON object. * * @param jsonObject the JSON object of which the event is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the event. * @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 * format. */ public static ConnectionModified fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<ConnectionModified>(TYPE, jsonObject) .deserialize((revision, timestamp) -> { final JsonObject connectionJsonObject = jsonObject.getValueOrThrow(JsonFields.CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(connectionJsonObject); return of(readConnection, timestamp, dittoHeaders); }); }
/** * Creates a new {@code CreateConnectionResponse} from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the response. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static CreateConnectionResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<CreateConnectionResponse>(TYPE, jsonObject).deserialize( statusCode -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * Creates a {@code ConnectionCreated} event from a JSON object. * * @param jsonObject the JSON object of which the event is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the event. * @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 * format. */ public static ConnectionCreated fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<ConnectionCreated>(TYPE, jsonObject) .deserialize((revision, timestamp) -> { final JsonObject connectionJsonObject = jsonObject.getValueOrThrow(JsonFields.CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(connectionJsonObject); return of(readConnection, timestamp, dittoHeaders); }); }
/** * Creates a new {@code CreateConnection} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static CreateConnection fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<CreateConnection>(TYPE, jsonObject).deserialize(() -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * Creates a new {@code TestConnection} from a JSON object. * * @param jsonObject the JSON object of which the command is to be tested. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static TestConnection fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<TestConnection>(TYPE, jsonObject).deserialize(() -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * Creates a new {@code CreateConnection} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static CreateConnection fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<CreateConnection>(TYPE, jsonObject).deserialize(() -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * Creates a new {@code RetrieveConnectionResponse} from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the response. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveConnectionResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveConnectionResponse>(TYPE, jsonObject).deserialize( statusCode -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
@Override public Map<String, BiFunction<JsonObject, DittoHeaders, Jsonifiable>> determineStrategy() { final Map<String, BiFunction<JsonObject, DittoHeaders, Jsonifiable>> combinedStrategy = new HashMap<>(); final MappingStrategiesBuilder strategiesBuilder = MappingStrategiesBuilder.newInstance() .add(ConnectivityCommandRegistry.newInstance()) .add(ConnectivityCommandResponseRegistry.newInstance()) .add(ConnectivityEventRegistry.newInstance()) .add(ConnectivityErrorRegistry.newInstance()) .add(Connection.class, (jsonObject) -> ConnectivityModelFactory.connectionFromJson(jsonObject)) // do not replace with lambda! .add("ImmutableConnection", (jsonObject) -> ConnectivityModelFactory.connectionFromJson(jsonObject)) // do not replace with lambda! ; addMessagesStrategies(strategiesBuilder); addDevOpsStrategies(strategiesBuilder); combinedStrategy.putAll(strategiesBuilder.build()); combinedStrategy.putAll(thingsMappingStrategy.determineStrategy()); return combinedStrategy; }