|
| 1 | +/* |
| 2 | + * Copyright 2021 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; |
| 17 | + |
| 18 | +import org.springframework.lang.Nullable; |
| 19 | + |
| 20 | +/** |
| 21 | + * Response object for items returned from multiget requests, encapsulating the returned data and potential error |
| 22 | + * information. |
| 23 | + * |
| 24 | + * @param <T> the entity type |
| 25 | + * @author Peter-Josef Meisch |
| 26 | + * @since 4.2 |
| 27 | + */ |
| 28 | +public class MultiGetItem<T> { |
| 29 | + @Nullable private final T item; |
| 30 | + @Nullable private final Failure failure; |
| 31 | + |
| 32 | + private MultiGetItem(@Nullable T item, @Nullable Failure failure) { |
| 33 | + this.item = item; |
| 34 | + this.failure = failure; |
| 35 | + } |
| 36 | + |
| 37 | + public static <T> MultiGetItem<T> of(@Nullable T item, @Nullable Failure failure) { |
| 38 | + return new MultiGetItem<>(item, failure); |
| 39 | + } |
| 40 | + |
| 41 | + public boolean hasItem() { |
| 42 | + return item != null; |
| 43 | + } |
| 44 | + |
| 45 | + @Nullable |
| 46 | + public T getItem() { |
| 47 | + return item; |
| 48 | + } |
| 49 | + |
| 50 | + public boolean isFailed() { |
| 51 | + return failure != null; |
| 52 | + } |
| 53 | + |
| 54 | + @Nullable |
| 55 | + public Failure getFailure() { |
| 56 | + return failure; |
| 57 | + } |
| 58 | + |
| 59 | + public static class Failure { |
| 60 | + @Nullable private final String index; |
| 61 | + @Nullable private final String type; |
| 62 | + @Nullable private final String id; |
| 63 | + @Nullable private final Exception exception; |
| 64 | + |
| 65 | + private Failure(@Nullable String index, @Nullable String type, @Nullable String id, @Nullable Exception exception) { |
| 66 | + this.index = index; |
| 67 | + this.type = type; |
| 68 | + this.id = id; |
| 69 | + this.exception = exception; |
| 70 | + } |
| 71 | + |
| 72 | + public static Failure of(String index, String type, String id, Exception exception) { |
| 73 | + return new Failure(index, type, id, exception); |
| 74 | + } |
| 75 | + |
| 76 | + @Nullable |
| 77 | + public String getIndex() { |
| 78 | + return index; |
| 79 | + } |
| 80 | + |
| 81 | + @Nullable |
| 82 | + public String getType() { |
| 83 | + return type; |
| 84 | + } |
| 85 | + |
| 86 | + @Nullable |
| 87 | + public String getId() { |
| 88 | + return id; |
| 89 | + } |
| 90 | + |
| 91 | + @Nullable |
| 92 | + public Exception getException() { |
| 93 | + return exception; |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments