@Override public boolean isNull() { return wrapped.isNull(); }
@Override public boolean isNull() { return wrapped.isNull(); }
@Override public boolean isNull() { return wrapped.isNull(); }
@Override public boolean isNull() { return wrapped.isNull(); }
/** * Creates a response to a {@link RetrieveFeatureProperties} command. * * @param thingId the Thing ID of the retrieved feature properties. * @param featureId the identifier of the Feature whose Properties were retrieved. * @param jsonObject the retrieved FeatureProperties JSON. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveFeaturePropertiesResponse of(final String thingId, final String featureId, @Nullable final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final FeatureProperties featureProperties; if (jsonObject == null || jsonObject.isNull()) { featureProperties = ThingsModelFactory.nullFeatureProperties(); } else { featureProperties = ThingsModelFactory.newFeatureProperties(jsonObject); } return of(thingId, featureId, featureProperties, dittoHeaders); }
/** * Creates a response to a {@link RetrieveFeatureProperties} command. * * @param thingId the Thing ID of the retrieved feature properties. * @param featureId the identifier of the Feature whose Properties were retrieved. * @param jsonObject the retrieved FeatureProperties JSON. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveFeaturePropertiesResponse of(final String thingId, final String featureId, @Nullable final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final FeatureProperties featureProperties; if (jsonObject == null || jsonObject.isNull()) { featureProperties = ThingsModelFactory.nullFeatureProperties(); } else { featureProperties = ThingsModelFactory.newFeatureProperties(jsonObject); } return of(thingId, featureId, featureProperties, dittoHeaders); }
/** * Returns a new immutable {@link FeatureProperties} which is initialised with the values of the given JSON object. * * @param jsonObject provides the initial values of the result. * @return the new immutable initialised {@code FeatureProperties}. * @throws NullPointerException if {@code jsonObject} is {@code null}. */ public static FeatureProperties newFeatureProperties(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object for initialization"); if (!jsonObject.isNull()) { return ImmutableFeatureProperties.of(jsonObject); } else { return nullFeatureProperties(); } }
/** * Returns a new immutable {@link Attributes} which is initialised with the values of the given JSON object. * * @param jsonObject provides the initial values of the result. * @return the new immutable initialised {@code Attributes}. * @throws NullPointerException if {@code jsonObject} is {@code null}. */ public static Attributes newAttributes(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object for initialization"); if (!jsonObject.isNull()) { return ImmutableAttributes.of(jsonObject); } else { return nullAttributes(); } }
/** * Returns a new immutable {@link Attributes} which is initialised with the values of the given JSON object. * * @param jsonObject provides the initial values of the result. * @return the new immutable initialised {@code Attributes}. * @throws NullPointerException if {@code jsonObject} is {@code null}. */ public static Attributes newAttributes(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object for initialization"); if (!jsonObject.isNull()) { return ImmutableAttributes.of(jsonObject); } else { return nullAttributes(); } }
/** * Returns a new immutable {@link FeatureProperties} which is initialised with the values of the given JSON object. * * @param jsonObject provides the initial values of the result. * @return the new immutable initialised {@code FeatureProperties}. * @throws NullPointerException if {@code jsonObject} is {@code null}. */ public static FeatureProperties newFeatureProperties(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object for initialization"); if (!jsonObject.isNull()) { return ImmutableFeatureProperties.of(jsonObject); } else { return nullFeatureProperties(); } }
/** * Creates a new builder for a Feature object based on the given JSON object. * * @param jsonObject the JSON object of which a new Feature instance is to be created. * @return an object handle which allows further configuration of the Feature to be built. * @throws NullPointerException if {@code jsonObject} is {@code null}. */ public static FromJsonBuildable newFeatureFromJson(final JsonObject jsonObject) { ConditionChecker.checkNotNull(jsonObject, "Feature JSON object"); final ImmutableFeatureFromScratchBuilder result = new ImmutableFeatureFromScratchBuilder(); if (jsonObject.isNull()) { result.isFeatureValueJsonNull = true; } else { result.definition(jsonObject.getValue(Feature.JsonFields.DEFINITION) .map(ThingsModelFactory::newFeatureDefinition) .orElse(null)); result.properties(jsonObject.getValue(Feature.JsonFields.PROPERTIES) .map(ThingsModelFactory::newFeatureProperties) .orElse(null)); } return result; }
@Override public FromScratch setFeatures(final JsonObject featuresJsonObject) { checkNotNull(featuresJsonObject, "JSON object representation of Features to be set"); if (featuresJsonObject.isNull()) { return setNullFeatures(); } return setFeatures(ThingsModelFactory.newFeatures(featuresJsonObject)); }
@Override public FromScratch setFeatures(final JsonObject featuresJsonObject) { checkNotNull(featuresJsonObject, "JSON object representation of Features to be set"); if (featuresJsonObject.isNull()) { return setNullFeatures(); } return setFeatures(ThingsModelFactory.newFeatures(featuresJsonObject)); }
/** * @param jsonFields the json fields to create a new JsonObject from. * @return a null object if {@code jsonFields} is a null json object. Else this returns a new object containing the * given {code jsonFields}. */ public static JsonObject newObject(final Iterable<JsonField> jsonFields) { if (jsonFields instanceof JsonObject && ((JsonObject) jsonFields).isNull()) { return JsonFactory.nullObject(); } else { return JsonFactory.newObjectBuilder() .setAll(jsonFields) .build(); } }
@SuppressWarnings("unchecked") JsonObject buildJsonView(final Iterable<JsonField> jsonFields, final Set<String> subjectIds, final Permissions permissions) { final PolicyTrie defaultPolicyTrie = new PolicyTrie(grantRevokeIndex, Collections.emptyMap()); if (jsonFields instanceof JsonObject && ((JsonObject) jsonFields).isNull()) { return (JsonObject) jsonFields; } final JsonObjectBuilder outputObjectBuilder = JsonFactory.newObjectBuilder(); for (final JsonField field : jsonFields) { final JsonValue jsonView = getViewForJsonFieldOrNull(field, defaultPolicyTrie, subjectIds, permissions); if (null != jsonView) { final Optional<JsonFieldDefinition> definitionOptional = field.getDefinition(); if (definitionOptional.isPresent()) { outputObjectBuilder.set(definitionOptional.get(), jsonView); } else { outputObjectBuilder.set(field.getKey(), jsonView); } } } return outputObjectBuilder.build(); }
@Override public FromScratch setAttributes(final JsonObject attributesJsonObject) { checkNotNull(attributesJsonObject, "JSON object representation of Attributes to be set"); if (attributesJsonObject.isNull()) { return setNullAttributes(); } else if (attributesJsonObject.isEmpty()) { return setEmptyAttributes(); } return setAttributes(ThingsModelFactory.newAttributes(attributesJsonObject)); }
@Override public FromScratch setAttributes(final JsonObject attributesJsonObject) { checkNotNull(attributesJsonObject, "JSON object representation of Attributes to be set"); if (attributesJsonObject.isNull()) { return setNullAttributes(); } else if (attributesJsonObject.isEmpty()) { return setEmptyAttributes(); } return setAttributes(ThingsModelFactory.newAttributes(attributesJsonObject)); }
/** * Creates a response to a {@link ModifyAttributes} command from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the preceding command. * @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 ModifyAttributesResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<ModifyAttributesResponse>(TYPE, jsonObject).deserialize( statusCode -> { final String thingId = jsonObject.getValueOrThrow(ThingModifyCommandResponse.JsonFields.JSON_THING_ID); final JsonObject attributesJsonObject = jsonObject.getValueOrThrow(JSON_ATTRIBUTES); final Attributes extractedAttributes = (!attributesJsonObject.isNull()) ? ThingsModelFactory.newAttributes(attributesJsonObject) : ThingsModelFactory.nullAttributes(); return new ModifyAttributesResponse(thingId, statusCode, extractedAttributes, dittoHeaders); }); }
/** * Creates a new {@code FeaturesCreated} from a JSON object. * * @param jsonObject the JSON object from which a new FeaturesCreated instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code FeaturesCreated} 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 * 'FeaturesCreated' format. */ public static FeaturesCreated fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<FeaturesCreated>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String extractedThingId = jsonObject.getValueOrThrow(JsonFields.THING_ID); final JsonObject featuresJsonObject = jsonObject.getValueOrThrow(JSON_FEATURES); final Features extractedFeatures = (null != featuresJsonObject && !featuresJsonObject.isNull()) ? ThingsModelFactory.newFeatures(featuresJsonObject) : ThingsModelFactory.nullFeatures(); return of(extractedThingId, extractedFeatures, revision, timestamp, dittoHeaders); }); }
/** * Creates a new {@code FeatureCreated} from a JSON object. * * @param jsonObject the JSON object from which a new FeatureCreated instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code FeatureCreated} which was created from the given JSON object. * @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 * 'FeatureCreated' format. */ public static FeatureCreated fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<FeatureCreated>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String extractedThingId = jsonObject.getValueOrThrow(JsonFields.THING_ID); final String extractedFeatureId = jsonObject.getValueOrThrow(JsonFields.FEATURE_ID); final JsonObject featureJsonObject = jsonObject.getValueOrThrow(JSON_FEATURE); final Feature extractedFeature = !featureJsonObject.isNull() ? ThingsModelFactory.newFeatureBuilder(featureJsonObject).useId(extractedFeatureId).build() : ThingsModelFactory.nullFeature(extractedFeatureId); return of(extractedThingId, extractedFeature, revision, timestamp, dittoHeaders); }); }