|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Linq.Expressions; |
| 7 | +using System.Runtime.Serialization; |
| 8 | +using Elasticsearch.Net.Utf8Json; |
| 9 | + |
| 10 | +namespace Nest |
| 11 | +{ |
| 12 | + [InterfaceDataContract] |
| 13 | + public interface IUriPartsProcessor : IProcessor |
| 14 | + { |
| 15 | + /// <summary> |
| 16 | + /// The field to decode |
| 17 | + /// </summary> |
| 18 | + [DataMember(Name = "field")] |
| 19 | + Field Field { get; set; } |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// If <c>true</c> the processor copies the unparsed URI to <target_field>.original. |
| 23 | + /// </summary> |
| 24 | + [DataMember(Name = "keep_original")] |
| 25 | + bool? KeepOriginal { get; set; } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// The field to assign the converted value to, by default <see cref="Field" /> is updated in-place |
| 29 | + /// </summary> |
| 30 | + [DataMember(Name = "target_field")] |
| 31 | + Field TargetField { get; set; } |
| 32 | + |
| 33 | + /// <summary> |
| 34 | + /// If <c>true</c> the processor removes the <see cref="Field" /> after parsing the URI string. |
| 35 | + /// If parsing fails, the processor does not remove the <see cref="Field" />. |
| 36 | + /// </summary> |
| 37 | + [DataMember(Name = "remove_if_successful")] |
| 38 | + bool? RemoveIfSuccessful { get; set; } |
| 39 | + } |
| 40 | + |
| 41 | + /// <inheritdoc cref="IUriPartsProcessor" /> |
| 42 | + public class UriPartsProcessor : ProcessorBase, IUriPartsProcessor |
| 43 | + { |
| 44 | + /// <inheritdoc /> |
| 45 | + [DataMember(Name = "field")] |
| 46 | + public Field Field { get; set; } |
| 47 | + |
| 48 | + /// <inheritdoc /> |
| 49 | + [DataMember(Name = "keep_original")] |
| 50 | + public bool? KeepOriginal { get; set; } |
| 51 | + |
| 52 | + /// <inheritdoc /> |
| 53 | + [DataMember(Name = "target_field")] |
| 54 | + public Field TargetField { get; set; } |
| 55 | + |
| 56 | + /// <inheritdoc /> |
| 57 | + [DataMember(Name = "remove_if_successful")] |
| 58 | + public bool? RemoveIfSuccessful { get; set; } |
| 59 | + |
| 60 | + protected override string Name => "uri_parts"; |
| 61 | + } |
| 62 | + |
| 63 | + /// <inheritdoc cref="IUriPartsProcessor" /> |
| 64 | + public class UriPartsProcessorDescriptor<T> |
| 65 | + : ProcessorDescriptorBase<UriPartsProcessorDescriptor<T>, IUriPartsProcessor>, IUriPartsProcessor |
| 66 | + where T : class |
| 67 | + { |
| 68 | + protected override string Name => "uri_parts"; |
| 69 | + |
| 70 | + Field IUriPartsProcessor.Field { get; set; } |
| 71 | + bool? IUriPartsProcessor.KeepOriginal { get; set; } |
| 72 | + Field IUriPartsProcessor.TargetField { get; set; } |
| 73 | + bool? IUriPartsProcessor.RemoveIfSuccessful { get; set; } |
| 74 | + |
| 75 | + /// <inheritdoc cref="IUriPartsProcessor.Field" /> |
| 76 | + public UriPartsProcessorDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v); |
| 77 | + |
| 78 | + /// <inheritdoc cref="IUriPartsProcessor.Field" /> |
| 79 | + public UriPartsProcessorDescriptor<T> Field<TValue>(Expression<Func<T, TValue>> objectPath) => |
| 80 | + Assign(objectPath, (a, v) => a.Field = v); |
| 81 | + |
| 82 | + /// <inheritdoc cref="IUriPartsProcessor.TargetField" /> |
| 83 | + public UriPartsProcessorDescriptor<T> TargetField(Field field) => Assign(field, (a, v) => a.TargetField = v); |
| 84 | + |
| 85 | + /// <inheritdoc cref="IUriPartsProcessor.TargetField" /> |
| 86 | + public UriPartsProcessorDescriptor<T> TargetField<TValue>(Expression<Func<T, TValue>> objectPath) => |
| 87 | + Assign(objectPath, (a, v) => a.TargetField = v); |
| 88 | + |
| 89 | + /// <inheritdoc cref="IUriPartsProcessor.KeepOriginal" /> |
| 90 | + public UriPartsProcessorDescriptor<T> KeepOriginal(bool? keepOriginal = true) => |
| 91 | + Assign(keepOriginal, (a, v) => a.KeepOriginal = v); |
| 92 | + |
| 93 | + /// <inheritdoc cref="IUriPartsProcessor.RemoveIfSuccessful" /> |
| 94 | + public UriPartsProcessorDescriptor<T> RemoveIfSuccessful(bool? removeIfSuccessful = true) => |
| 95 | + Assign(removeIfSuccessful, (a, v) => a.RemoveIfSuccessful = v); |
| 96 | + } |
| 97 | +} |
0 commit comments