|
7 | 7 |
|
8 | 8 | import org.elasticsearch.Version;
|
9 | 9 | import org.elasticsearch.common.ParseField;
|
10 |
| -import org.elasticsearch.common.Strings; |
11 | 10 | import org.elasticsearch.common.io.stream.StreamInput;
|
12 | 11 | import org.elasticsearch.common.io.stream.StreamOutput;
|
13 | 12 | import org.elasticsearch.common.io.stream.Writeable;
|
14 |
| -import org.elasticsearch.common.xcontent.ConstructingObjectParser; |
15 |
| -import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; |
16 |
| -import org.elasticsearch.common.xcontent.NamedXContentRegistry; |
17 | 13 | import org.elasticsearch.common.xcontent.ObjectParser;
|
18 | 14 | import org.elasticsearch.common.xcontent.ToXContentObject;
|
19 | 15 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
20 |
| -import org.elasticsearch.common.xcontent.XContentFactory; |
21 |
| -import org.elasticsearch.common.xcontent.XContentParser; |
22 | 16 | import org.elasticsearch.xpack.core.ml.MlParserType;
|
23 | 17 | import org.elasticsearch.xpack.core.ml.job.messages.Messages;
|
24 | 18 | import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
|
|
28 | 22 | import java.util.Collections;
|
29 | 23 | import java.util.EnumMap;
|
30 | 24 | import java.util.EnumSet;
|
31 |
| -import java.util.HashMap; |
32 | 25 | import java.util.List;
|
33 | 26 | import java.util.Map;
|
34 | 27 | import java.util.Objects;
|
@@ -57,24 +50,7 @@ public class DetectionRule implements ToXContentObject, Writeable {
|
57 | 50 | ObjectParser<Builder, Void> parser = PARSERS.get(parserType);
|
58 | 51 | assert parser != null;
|
59 | 52 | parser.declareStringArray(Builder::setActions, ACTIONS_FIELD);
|
60 |
| - parser.declareObject(Builder::setScope, (p, c) -> { |
61 |
| - Map<String, Object> unparsedScope = p.map(); |
62 |
| - if (unparsedScope.isEmpty()) { |
63 |
| - return new RuleScope(); |
64 |
| - } |
65 |
| - ConstructingObjectParser<FilterRef, Void> filterRefParser = FilterRef.PARSERS.get(parserType); |
66 |
| - Map<String, FilterRef> scope = new HashMap<>(); |
67 |
| - for (Map.Entry<String, Object> entry : unparsedScope.entrySet()) { |
68 |
| - try (XContentBuilder builder = XContentFactory.jsonBuilder()) { |
69 |
| - builder.map((Map<String, ?>) entry.getValue()); |
70 |
| - try (XContentParser scopeParser = XContentFactory.xContent(builder.contentType()).createParser( |
71 |
| - NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, Strings.toString(builder))) { |
72 |
| - scope.put(entry.getKey(), filterRefParser.parse(scopeParser, null)); |
73 |
| - } |
74 |
| - } |
75 |
| - } |
76 |
| - return new RuleScope(scope); |
77 |
| - }, SCOPE_FIELD); |
| 53 | + parser.declareObject(Builder::setScope, RuleScope.parser(parserType), SCOPE_FIELD); |
78 | 54 | parser.declareObjectArray(Builder::setConditions, (p, c) ->
|
79 | 55 | RuleCondition.PARSERS.get(parserType).apply(p, c), CONDITIONS_FIELD);
|
80 | 56 | }
|
|
0 commit comments