private ModifyFeature(final String thingId, final Feature feature, final DittoHeaders dittoHeaders) { super(TYPE, dittoHeaders); ThingIdValidator.getInstance().accept(thingId, dittoHeaders); this.thingId = thingId; this.feature = checkNotNull(feature, "Feature"); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> feature.toJsonString().length(), () -> dittoHeaders); }
private ModifyFeature(final String thingId, final Feature feature, final DittoHeaders dittoHeaders) { super(TYPE, dittoHeaders); ThingIdValidator.getInstance().accept(thingId, dittoHeaders); this.thingId = thingId; this.feature = checkNotNull(feature, "Feature"); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> feature.toJsonString().length(), () -> dittoHeaders); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final ModifyFeature command) { final Thing nonNullThing = getThingOrThrow(thing); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> { final long lengthWithOutFeature = nonNullThing.removeFeature(command.getFeatureId()) .toJsonString() .length(); final long featureLength = command.getFeature().toJsonString().length() + command.getFeatureId().length() + 5L; return lengthWithOutFeature + featureLength; }, command::getDittoHeaders); return extractFeature(command, nonNullThing) .map(feature -> getModifyResult(context, nextRevision, command)) .orElseGet(() -> getCreateResult(context, nextRevision, command)); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final ModifyFeature command) { final Thing nonNullThing = getThingOrThrow(thing); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> { final long lengthWithOutFeature = nonNullThing.removeFeature(command.getFeatureId()) .toJsonString() .length(); final long featureLength = command.getFeature().toJsonString().length() + command.getFeatureId().length() + 5L; return lengthWithOutFeature + featureLength; }, command::getDittoHeaders); return extractFeature(command, nonNullThing) .map(feature -> getModifyResult(context, nextRevision, command)) .orElseGet(() -> getCreateResult(context, nextRevision, command)); }