@Override public int length() { return jsonPointer.length(); }
@Override public int length() { return jsonPointer.length(); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final ModifyAttribute command) { final Thing nonNullThing = getThingOrThrow(thing); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> { final long lengthWithOutAttribute = nonNullThing.removeAttribute(command.getAttributePointer()) .toJsonString() .length(); final long attributeLength = command.getAttributeValue().toString().length() + command.getAttributePointer().length() + 5L; return lengthWithOutAttribute + attributeLength; }, command::getDittoHeaders); return nonNullThing.getAttributes() .filter(attributes -> attributes.contains(command.getAttributePointer())) .map(attributes -> getModifyResult(context, nextRevision, command)) .orElseGet(() -> getCreateResult(context, nextRevision, command)); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final ModifyAttribute command) { final Thing nonNullThing = getThingOrThrow(thing); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> { final long lengthWithOutAttribute = nonNullThing.removeAttribute(command.getAttributePointer()) .toJsonString() .length(); final long attributeLength = command.getAttributeValue().toString().length() + command.getAttributePointer().length() + 5L; return lengthWithOutAttribute + attributeLength; }, command::getDittoHeaders); return nonNullThing.getAttributes() .filter(attributes -> attributes.contains(command.getAttributePointer())) .map(attributes -> getModifyResult(context, nextRevision, command)) .orElseGet(() -> getCreateResult(context, nextRevision, command)); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final ModifyFeatureProperty command) { final String featureId = command.getFeatureId(); final Thing nonNullThing = getThingOrThrow(thing); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> { final long lengthWithOutProperty = nonNullThing.removeFeatureProperty(featureId, command.getPropertyPointer()) .toJsonString() .length(); final long propertyLength = command.getPropertyValue().toString().length() + command.getPropertyPointer().length() + 5L; return lengthWithOutProperty + propertyLength; }, command::getDittoHeaders); return extractFeature(command, nonNullThing) .map(feature -> getModifyOrCreateResult(feature, context, nextRevision, command)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featureNotFound(context.getThingId(), featureId, command.getDittoHeaders()))); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final ModifyFeatureProperty command) { final String featureId = command.getFeatureId(); final Thing nonNullThing = getThingOrThrow(thing); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> { final long lengthWithOutProperty = nonNullThing.removeFeatureProperty(featureId, command.getPropertyPointer()) .toJsonString() .length(); final long propertyLength = command.getPropertyValue().toString().length() + command.getPropertyPointer().length() + 5L; return lengthWithOutProperty + propertyLength; }, command::getDittoHeaders); return extractFeature(command, nonNullThing) .map(feature -> getModifyOrCreateResult(feature, context, nextRevision, command)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featureNotFound(context.getThingId(), featureId, command.getDittoHeaders()))); }