|
| 1 | +/* |
| 2 | + * Copyright 2024 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.elasticsearch.core.cluster; |
| 17 | + |
| 18 | +import java.util.ArrayList; |
| 19 | +import java.util.Collections; |
| 20 | +import java.util.HashMap; |
| 21 | +import java.util.Iterator; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | + |
| 25 | +import org.jetbrains.annotations.NotNull; |
| 26 | + |
| 27 | +/** |
| 28 | + * Retrieves mapping definitions of all indices in the cluster. |
| 29 | + * |
| 30 | + * @author Youssef Aouichaoui |
| 31 | + * @since 5.4 |
| 32 | + */ |
| 33 | +public class ClusterMapping implements Iterable<ClusterMapping.ClusterMappingEntry> { |
| 34 | + private final List<ClusterMappingEntry> mappings; |
| 35 | + |
| 36 | + private ClusterMapping(Builder builder) { |
| 37 | + this.mappings = builder.mappings; |
| 38 | + } |
| 39 | + |
| 40 | + @NotNull |
| 41 | + @Override |
| 42 | + public Iterator<ClusterMappingEntry> iterator() { |
| 43 | + return mappings.iterator(); |
| 44 | + } |
| 45 | + |
| 46 | + public static Builder builder() { |
| 47 | + return new Builder(); |
| 48 | + } |
| 49 | + |
| 50 | + public static class ClusterMappingEntry { |
| 51 | + private final String name; |
| 52 | + private final Map<String, Object> mappings; |
| 53 | + |
| 54 | + private ClusterMappingEntry(Builder builder) { |
| 55 | + this.name = builder.name; |
| 56 | + this.mappings = builder.mappings; |
| 57 | + } |
| 58 | + |
| 59 | + public String getName() { |
| 60 | + return name; |
| 61 | + } |
| 62 | + |
| 63 | + public Map<String, Object> getMappings() { |
| 64 | + return Collections.unmodifiableMap(mappings); |
| 65 | + } |
| 66 | + |
| 67 | + public static Builder builder(String name) { |
| 68 | + return new Builder(name); |
| 69 | + } |
| 70 | + |
| 71 | + public static class Builder { |
| 72 | + private final String name; |
| 73 | + private final Map<String, Object> mappings = new HashMap<>(); |
| 74 | + |
| 75 | + private Builder(String name) { |
| 76 | + this.name = name; |
| 77 | + } |
| 78 | + |
| 79 | + public Builder withMappings(Map<String, Object> mappings) { |
| 80 | + this.mappings.putAll(mappings); |
| 81 | + |
| 82 | + return this; |
| 83 | + } |
| 84 | + |
| 85 | + public ClusterMappingEntry build() { |
| 86 | + return new ClusterMappingEntry(this); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + public static class Builder { |
| 92 | + private final List<ClusterMappingEntry> mappings = new ArrayList<>(); |
| 93 | + |
| 94 | + private Builder() {} |
| 95 | + |
| 96 | + public Builder withMapping(ClusterMappingEntry entry) { |
| 97 | + mappings.add(entry); |
| 98 | + |
| 99 | + return this; |
| 100 | + } |
| 101 | + |
| 102 | + public ClusterMapping build() { |
| 103 | + return new ClusterMapping(this); |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments