protected static FeatureProperties featurePropertiesFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(ThingsModelFactory::newFeatureProperties) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
protected static FeatureDefinition featureDefinitionFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asArray) .map(ThingsModelFactory::newFeatureDefinition) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
protected static Thing thingFrom(final Adaptable adaptable) { return adaptable.getPayload().getValue() .map(JsonValue::asObject) .map(ThingsModelFactory::newThing) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
protected static Attributes attributesFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(ThingsModelFactory::newAttributes) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
protected static JsonArray thingsArrayFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .filter(JsonValue::isArray) .map(JsonValue::asArray) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
protected static AccessControlList aclFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(AccessControlListModelFactory::newAcl) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
protected static JsonArray thingsArrayFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .filter(JsonValue::isArray) .map(JsonValue::asArray) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
protected static String policyIdFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asString) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private static ConnectionStatus getConnectionStatusOrThrow(final JsonObject jsonObject) { final String readConnectionStatus = jsonObject.getValueOrThrow(JsonFields.CONNECTION_STATUS); return ConnectionStatus.forName(readConnectionStatus) .orElseThrow(() -> JsonParseException.newBuilder() .message(MessageFormat.format("Connection status <{0}> is invalid!", readConnectionStatus)) .build()); }
private static Instant tryToParseModified(final CharSequence dateTime) { try { return Instant.parse(dateTime); } catch (final DateTimeParseException e) { final String msgPattern ="The JSON object's field <{0>' is not in ISO-8601 format as expected!"; throw JsonParseException.newBuilder() .message(MessageFormat.format(msgPattern, Thing.JsonFields.MODIFIED.getPointer())) .cause(e) .build(); } }
private static ConnectionType getConnectionTypeOrThrow(final JsonObject jsonObject) { final String readConnectionType = jsonObject.getValueOrThrow(JsonFields.CONNECTION_TYPE); return ConnectionType.forName(readConnectionType) .orElseThrow(() -> JsonParseException.newBuilder() .message(MessageFormat.format("Connection type <{0}> is invalid!", readConnectionType)) .build()); }
private static com.eclipsesource.json.JsonValue tryToRead(final String json) { try { return Json.parse(json); } catch (final ParseException | StackOverflowError e) { throw JsonParseException.newBuilder() .message(MessageFormat.format("Failed to parse ''{0}''!", json)) .cause(e) .build(); } }
protected static String featureIdForMessageFrom(final Adaptable adaptable) { return adaptable.getPayload().getPath() .getFeatureId() .orElseThrow(() -> JsonParseException.newBuilder().build()); }
protected static Feature featureFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(jsonObject -> ThingsModelFactory.newFeatureBuilder(jsonObject) .useId(featureIdFrom(adaptable)) .build()) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
protected static Feature featureFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(jsonObject -> ThingsModelFactory.newFeatureBuilder(jsonObject) .useId(featureIdFrom(adaptable)) .build()) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private static JsonValue tryToReadJsonValueFrom(final Reader reader) { try { return readJsonValueFrom(reader); } catch (final ParseException | IOException | StackOverflowError e) { throw JsonParseException.newBuilder() .message("Failed to parse JSON value from reader!") .cause(e) .build(); } }
protected static AclEntry aclEntryFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(permissions -> AccessControlListModelFactory .newAclEntry(leafValue(adaptable.getPayload().getPath()), permissions)) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private static com.eclipsesource.json.JsonArray tryToReadMinimalJsonArrayFrom(final String jsonString) { try { final com.eclipsesource.json.JsonValue parsedJsonString = Json.parse(jsonString); return parsedJsonString.asArray(); } catch (final ParseException | UnsupportedOperationException | StackOverflowError e) { throw JsonParseException.newBuilder() .message("Failed to create JSON array from string!") .cause(e) .build(); } }
private static com.eclipsesource.json.JsonObject tryToReadJsonObjectFrom(final String jsonString) { try { final com.eclipsesource.json.JsonValue parsedJsonString = Json.parse(jsonString); return parsedJsonString.asObject(); } catch (final ParseException | UnsupportedOperationException | StackOverflowError e) { throw JsonParseException.newBuilder() .message("Failed to create JSON object from string!") .cause(e) .build(); } }
private static DittoRuntimeException buildError(final WithDittoHeaders withDittoHeaders) { final JsonParseException jsonException = JsonParseException.newBuilder() .message("JSON contains forbidden character '\\u0000'") .build(); return new DittoJsonException(jsonException).setDittoHeaders(withDittoHeaders.getDittoHeaders()); } }