Skip to content

Commit

Permalink
Merge pull request #2093 from beyonnex-io/bugfix/validation-of-desire…
Browse files Browse the repository at this point in the history
…d-properties-deletion

fix wrongly done validation of removal of desired feature properties
  • Loading branch information
thjaeckle authored Jan 14, 2025
2 parents 4d9372b + 163db35 commit dd245af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.ditto.things.service.persistence.actors.strategies.commands;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -68,19 +69,9 @@ protected CompletionStage<DeleteFeatureDesiredProperties> performWotValidation(
@Nullable final Thing previousThing,
@Nullable final Thing previewThing
) {
return wotThingModelValidator.validateFeatureScopedDeletion(
Optional.ofNullable(previousThing)
.flatMap(Thing::getDefinition)
.orElse(null),
Optional.ofNullable(previousThing)
.flatMap(Thing::getFeatures)
.flatMap(f -> f.getFeature(command.getFeatureId()))
.flatMap(Feature::getDefinition)
.orElse(null),
command.getFeatureId(),
command.getResourcePath(),
command.getDittoHeaders()
).thenApply(aVoid -> command);
// it is always ok to delete a feature's desired properties - no need to validate for e.g. required properties,
// as they do not apply for desired properties
return CompletableFuture.completedFuture(command);
}

private Optional<Feature> extractFeature(final DeleteFeatureDesiredProperties command,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.ditto.things.service.persistence.actors.strategies.commands;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -71,19 +72,9 @@ protected CompletionStage<DeleteFeatureDesiredProperty> performWotValidation(
@Nullable final Thing previousThing,
@Nullable final Thing previewThing
) {
return wotThingModelValidator.validateFeatureScopedDeletion(
Optional.ofNullable(previousThing)
.flatMap(Thing::getDefinition)
.orElse(null),
Optional.ofNullable(previousThing)
.flatMap(Thing::getFeatures)
.flatMap(f -> f.getFeature(command.getFeatureId()))
.flatMap(Feature::getDefinition)
.orElse(null),
command.getFeatureId(),
command.getResourcePath(),
command.getDittoHeaders()
).thenApply(aVoid -> command);
// it is always ok to delete a feature's desired properties - no need to validate for e.g. required properties,
// as they do not apply for desired properties
return CompletableFuture.completedFuture(command);
}

private Optional<Feature> extractFeature(final DeleteFeatureDesiredProperty command, final @Nullable Thing thing) {
Expand Down

0 comments on commit dd245af

Please sign in to comment.