Skip to content

Commit

Permalink
Issue #1043: Removed empty topic path and its usage. Ditto Protocol m…
Browse files Browse the repository at this point in the history
…essages are always required to have a topic. Thus an empty topic path implementation did not make sense.

Signed-off-by: Juergen Fickel <juergen.fickel@bosch.io>
  • Loading branch information
Juergen Fickel committed May 3, 2021
1 parent adf9b5f commit 23e05cc
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 371 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonObjectBuilder;
import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException;
import org.eclipse.ditto.model.base.headers.DittoHeaders;

Expand Down Expand Up @@ -62,18 +60,21 @@ public static ImmutableJsonifiableAdaptable fromJson(final JsonObject jsonObject
.map(ProtocolFactory::newHeaders)
.orElse(DittoHeaders.empty());

final TopicPath topicPath;
return new ImmutableJsonifiableAdaptable(ImmutableAdaptable.of(tryToDeserializeTopicPath(jsonObject, headers),
ProtocolFactory.newPayload(jsonObject),
headers));
}

private static TopicPath tryToDeserializeTopicPath(final JsonObject jsonObject, final DittoHeaders dittoHeaders) {
try {
topicPath = jsonObject.getValue(JsonFields.TOPIC)
.map(ProtocolFactory::newTopicPath)
.orElseGet(ProtocolFactory::emptyTopicPath);
return deserializeTopicPath(jsonObject);
} catch (final DittoRuntimeException e) {
throw e.setDittoHeaders(headers);
throw e.setDittoHeaders(dittoHeaders);
}
}

return new ImmutableJsonifiableAdaptable(ImmutableAdaptable.of(topicPath,
ProtocolFactory.newPayload(jsonObject), headers));
private static TopicPath deserializeTopicPath(final JsonObject jsonObject) {
return ProtocolFactory.newTopicPath(jsonObject.getValueOrThrow(JsonFields.TOPIC));
}

@Override
Expand All @@ -98,11 +99,8 @@ public JsonObject toJson() {

@Override
public JsonObject toJson(final DittoHeaders specificHeaders) {
final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder();
if (!getTopicPath().equals(ProtocolFactory.emptyTopicPath())) {
jsonObjectBuilder.set(JsonFields.TOPIC, getTopicPath().getPath());
}
return jsonObjectBuilder
return JsonObject.newBuilder()
.set(JsonFields.TOPIC, getTopicPath().getPath())
.set(JsonFields.HEADERS, specificHeaders.toJson())
.setAll(getPayload().toJson())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ public static Adaptable setExtra(final Adaptable existingAdaptable, final JsonOb
.build();
}

/**
* Returns an empty {@code TopicPath}.
*
* @return the topic path.
*/
public static TopicPath emptyTopicPath() {
return EmptyTopicPath.getInstance();
}

/**
* Parses the string argument as a {@link TopicPath}.
*
Expand Down

This file was deleted.

0 comments on commit 23e05cc

Please sign in to comment.