Search in sources :

Example 1 with ThingEvent

use of org.eclipse.ditto.things.model.signals.events.ThingEvent in project ditto by eclipse.

the class RetrieveAttributeStrategy method getAttributeValueResult.

private Result<ThingEvent<?>> getAttributeValueResult(final JsonObject attributes, final ThingId thingId, final RetrieveAttribute command, @Nullable final Thing thing) {
    final JsonPointer attributePointer = command.getAttributePointer();
    final DittoHeaders dittoHeaders = command.getDittoHeaders();
    return attributes.getValue(attributePointer).map(value -> RetrieveAttributeResponse.of(thingId, attributePointer, value, dittoHeaders)).<Result<ThingEvent<?>>>map(response -> ResultFactory.newQueryResult(command, appendETagHeaderIfProvided(command, response, thing))).orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.attributeNotFound(thingId, attributePointer, dittoHeaders), command));
}
Also used : EntityTag(org.eclipse.ditto.base.model.headers.entitytag.EntityTag) RetrieveAttributeResponse(org.eclipse.ditto.things.model.signals.commands.query.RetrieveAttributeResponse) Result(org.eclipse.ditto.internal.utils.persistentactors.results.Result) Metadata(org.eclipse.ditto.base.model.entity.metadata.Metadata) ThingId(org.eclipse.ditto.things.model.ThingId) Attributes(org.eclipse.ditto.things.model.Attributes) ResultFactory(org.eclipse.ditto.internal.utils.persistentactors.results.ResultFactory) JsonObject(org.eclipse.ditto.json.JsonObject) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) Optional(java.util.Optional) RetrieveAttribute(org.eclipse.ditto.things.model.signals.commands.query.RetrieveAttribute) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent) Immutable(javax.annotation.concurrent.Immutable) JsonPointer(org.eclipse.ditto.json.JsonPointer) Nullable(javax.annotation.Nullable) Thing(org.eclipse.ditto.things.model.Thing) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent) JsonPointer(org.eclipse.ditto.json.JsonPointer)

Example 2 with ThingEvent

use of org.eclipse.ditto.things.model.signals.events.ThingEvent in project ditto by eclipse.

the class RetrieveFeatureDefinitionStrategy method getFeatureDefinition.

private Result<ThingEvent<?>> getFeatureDefinition(final Feature feature, final ThingId thingId, final RetrieveFeatureDefinition command, @Nullable final Thing thing) {
    final String featureId = feature.getId();
    final DittoHeaders dittoHeaders = command.getDittoHeaders();
    return feature.getDefinition().map(featureDefinition -> RetrieveFeatureDefinitionResponse.of(thingId, featureId, featureDefinition, dittoHeaders)).<Result<ThingEvent<?>>>map(response -> ResultFactory.newQueryResult(command, appendETagHeaderIfProvided(command, response, thing))).orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featureDefinitionNotFound(thingId, featureId, dittoHeaders), command));
}
Also used : EntityTag(org.eclipse.ditto.base.model.headers.entitytag.EntityTag) Feature(org.eclipse.ditto.things.model.Feature) Result(org.eclipse.ditto.internal.utils.persistentactors.results.Result) Metadata(org.eclipse.ditto.base.model.entity.metadata.Metadata) ThingId(org.eclipse.ditto.things.model.ThingId) ResultFactory(org.eclipse.ditto.internal.utils.persistentactors.results.ResultFactory) RetrieveFeatureDefinitionResponse(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureDefinitionResponse) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) Optional(java.util.Optional) RetrieveFeatureDefinition(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureDefinition) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent) Immutable(javax.annotation.concurrent.Immutable) Nullable(javax.annotation.Nullable) Thing(org.eclipse.ditto.things.model.Thing) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent)

Example 3 with ThingEvent

use of org.eclipse.ditto.things.model.signals.events.ThingEvent in project ditto by eclipse.

the class RetrieveFeatureDefinitionStrategy method doApply.

@Override
protected Result<ThingEvent<?>> doApply(final Context<ThingId> context, @Nullable final Thing thing, final long nextRevision, final RetrieveFeatureDefinition command, @Nullable final Metadata metadata) {
    final ThingId thingId = context.getState();
    final String featureId = command.getFeatureId();
    return extractFeature(command, thing).map(feature -> getFeatureDefinition(feature, thingId, command, thing)).orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featureNotFound(thingId, featureId, command.getDittoHeaders()), command));
}
Also used : EntityTag(org.eclipse.ditto.base.model.headers.entitytag.EntityTag) Feature(org.eclipse.ditto.things.model.Feature) Result(org.eclipse.ditto.internal.utils.persistentactors.results.Result) Metadata(org.eclipse.ditto.base.model.entity.metadata.Metadata) ThingId(org.eclipse.ditto.things.model.ThingId) ResultFactory(org.eclipse.ditto.internal.utils.persistentactors.results.ResultFactory) RetrieveFeatureDefinitionResponse(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureDefinitionResponse) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) Optional(java.util.Optional) RetrieveFeatureDefinition(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureDefinition) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent) Immutable(javax.annotation.concurrent.Immutable) Nullable(javax.annotation.Nullable) Thing(org.eclipse.ditto.things.model.Thing) ThingId(org.eclipse.ditto.things.model.ThingId)

Example 4 with ThingEvent

use of org.eclipse.ditto.things.model.signals.events.ThingEvent in project ditto by eclipse.

the class RetrieveFeatureDesiredPropertiesStrategy method getFeatureDesiredProperties.

private Result<ThingEvent<?>> getFeatureDesiredProperties(final Feature feature, final ThingId thingId, final RetrieveFeatureDesiredProperties command, @Nullable final Thing thing) {
    final String featureId = feature.getId();
    final DittoHeaders dittoHeaders = command.getDittoHeaders();
    return feature.getDesiredProperties().map(desiredProperties -> getFeatureDesiredPropertiesJson(desiredProperties, command)).map(desiredPropertiesJson -> RetrieveFeatureDesiredPropertiesResponse.of(thingId, featureId, desiredPropertiesJson, dittoHeaders)).<Result<ThingEvent<?>>>map(response -> ResultFactory.newQueryResult(command, appendETagHeaderIfProvided(command, response, thing))).orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featureDesiredPropertiesNotFound(thingId, featureId, dittoHeaders), command));
}
Also used : EntityTag(org.eclipse.ditto.base.model.headers.entitytag.EntityTag) Feature(org.eclipse.ditto.things.model.Feature) Result(org.eclipse.ditto.internal.utils.persistentactors.results.Result) Metadata(org.eclipse.ditto.base.model.entity.metadata.Metadata) ThingId(org.eclipse.ditto.things.model.ThingId) ResultFactory(org.eclipse.ditto.internal.utils.persistentactors.results.ResultFactory) JsonObject(org.eclipse.ditto.json.JsonObject) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) RetrieveFeatureDesiredPropertiesResponse(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureDesiredPropertiesResponse) RetrieveFeatureDesiredProperties(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureDesiredProperties) Optional(java.util.Optional) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent) Immutable(javax.annotation.concurrent.Immutable) Nullable(javax.annotation.Nullable) Thing(org.eclipse.ditto.things.model.Thing) FeatureProperties(org.eclipse.ditto.things.model.FeatureProperties) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent)

Example 5 with ThingEvent

use of org.eclipse.ditto.things.model.signals.events.ThingEvent in project ditto by eclipse.

the class RetrieveFeaturePropertiesStrategy method getFeatureProperties.

private Result<ThingEvent<?>> getFeatureProperties(final Feature feature, final ThingId thingId, final RetrieveFeatureProperties command, @Nullable final Thing thing) {
    final String featureId = feature.getId();
    final DittoHeaders dittoHeaders = command.getDittoHeaders();
    return feature.getProperties().map(featureProperties -> getFeaturePropertiesJson(featureProperties, command)).map(featurePropertiesJson -> RetrieveFeaturePropertiesResponse.of(thingId, featureId, featurePropertiesJson, dittoHeaders)).<Result<ThingEvent<?>>>map(response -> ResultFactory.newQueryResult(command, appendETagHeaderIfProvided(command, response, thing))).orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featurePropertiesNotFound(thingId, featureId, dittoHeaders), command));
}
Also used : EntityTag(org.eclipse.ditto.base.model.headers.entitytag.EntityTag) Feature(org.eclipse.ditto.things.model.Feature) Result(org.eclipse.ditto.internal.utils.persistentactors.results.Result) Metadata(org.eclipse.ditto.base.model.entity.metadata.Metadata) ThingId(org.eclipse.ditto.things.model.ThingId) ResultFactory(org.eclipse.ditto.internal.utils.persistentactors.results.ResultFactory) RetrieveFeaturePropertiesResponse(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeaturePropertiesResponse) JsonObject(org.eclipse.ditto.json.JsonObject) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) RetrieveFeatureProperties(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureProperties) Optional(java.util.Optional) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent) Immutable(javax.annotation.concurrent.Immutable) Nullable(javax.annotation.Nullable) Thing(org.eclipse.ditto.things.model.Thing) FeatureProperties(org.eclipse.ditto.things.model.FeatureProperties) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent)

Aggregations

ThingEvent (org.eclipse.ditto.things.model.signals.events.ThingEvent)42 ThingId (org.eclipse.ditto.things.model.ThingId)40 Thing (org.eclipse.ditto.things.model.Thing)39 DittoHeaders (org.eclipse.ditto.base.model.headers.DittoHeaders)36 Optional (java.util.Optional)31 Nullable (javax.annotation.Nullable)31 Immutable (javax.annotation.concurrent.Immutable)29 Metadata (org.eclipse.ditto.base.model.entity.metadata.Metadata)29 EntityTag (org.eclipse.ditto.base.model.headers.entitytag.EntityTag)29 Result (org.eclipse.ditto.internal.utils.persistentactors.results.Result)29 ResultFactory (org.eclipse.ditto.internal.utils.persistentactors.results.ResultFactory)28 JsonObject (org.eclipse.ditto.json.JsonObject)20 Feature (org.eclipse.ditto.things.model.Feature)20 WithDittoHeaders (org.eclipse.ditto.base.model.headers.WithDittoHeaders)15 JsonPointer (org.eclipse.ditto.json.JsonPointer)12 Test (org.junit.Test)11 PolicyId (org.eclipse.ditto.policies.model.PolicyId)9 SudoRetrieveThing (org.eclipse.ditto.things.api.commands.sudo.SudoRetrieveThing)8 ThingCommandSizeValidator (org.eclipse.ditto.things.model.signals.commands.ThingCommandSizeValidator)8 Metadata (org.eclipse.ditto.thingsearch.service.persistence.write.model.Metadata)8