|
3 | 3 |
|
4 | 4 | package com.algolia.model.ingestion;
|
5 | 5 |
|
6 |
| -import com.algolia.exceptions.AlgoliaRuntimeException; |
7 | 6 | import com.fasterxml.jackson.annotation.*;
|
8 |
| -import com.fasterxml.jackson.core.*; |
9 |
| -import com.fasterxml.jackson.databind.*; |
10 | 7 | import com.fasterxml.jackson.databind.annotation.*;
|
11 |
| -import java.io.IOException; |
12 |
| -import java.util.logging.Logger; |
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Objects; |
13 | 11 |
|
14 | 12 | /** DestinationInput */
|
15 |
| -@JsonDeserialize(using = DestinationInput.Deserializer.class) |
16 |
| -public interface DestinationInput { |
17 |
| - class Deserializer extends JsonDeserializer<DestinationInput> { |
18 |
| - |
19 |
| - private static final Logger LOGGER = Logger.getLogger(Deserializer.class.getName()); |
20 |
| - |
21 |
| - @Override |
22 |
| - public DestinationInput deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { |
23 |
| - JsonNode tree = jp.readValueAsTree(); |
24 |
| - // deserialize DestinationIndexName |
25 |
| - if (tree.isObject()) { |
26 |
| - try (JsonParser parser = tree.traverse(jp.getCodec())) { |
27 |
| - return parser.readValueAs(DestinationIndexName.class); |
28 |
| - } catch (Exception e) { |
29 |
| - // deserialization failed, continue |
30 |
| - LOGGER.finest("Failed to deserialize oneOf DestinationIndexName (error: " + e.getMessage() + ") (type: DestinationIndexName)"); |
31 |
| - } |
32 |
| - } |
33 |
| - throw new AlgoliaRuntimeException(String.format("Failed to deserialize json element: %s", tree)); |
| 13 | +public class DestinationInput { |
| 14 | + |
| 15 | + @JsonProperty("indexName") |
| 16 | + private String indexName; |
| 17 | + |
| 18 | + @JsonProperty("recordType") |
| 19 | + private RecordType recordType; |
| 20 | + |
| 21 | + @JsonProperty("attributesToExclude") |
| 22 | + private List<String> attributesToExclude; |
| 23 | + |
| 24 | + public DestinationInput setIndexName(String indexName) { |
| 25 | + this.indexName = indexName; |
| 26 | + return this; |
| 27 | + } |
| 28 | + |
| 29 | + /** Algolia index name (case-sensitive). */ |
| 30 | + @javax.annotation.Nonnull |
| 31 | + public String getIndexName() { |
| 32 | + return indexName; |
| 33 | + } |
| 34 | + |
| 35 | + public DestinationInput setRecordType(RecordType recordType) { |
| 36 | + this.recordType = recordType; |
| 37 | + return this; |
| 38 | + } |
| 39 | + |
| 40 | + /** Get recordType */ |
| 41 | + @javax.annotation.Nullable |
| 42 | + public RecordType getRecordType() { |
| 43 | + return recordType; |
| 44 | + } |
| 45 | + |
| 46 | + public DestinationInput setAttributesToExclude(List<String> attributesToExclude) { |
| 47 | + this.attributesToExclude = attributesToExclude; |
| 48 | + return this; |
| 49 | + } |
| 50 | + |
| 51 | + public DestinationInput addAttributesToExclude(String attributesToExcludeItem) { |
| 52 | + if (this.attributesToExclude == null) { |
| 53 | + this.attributesToExclude = new ArrayList<>(); |
| 54 | + } |
| 55 | + this.attributesToExclude.add(attributesToExcludeItem); |
| 56 | + return this; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Attributes from your source to exclude from Algolia records. Not all your data attributes will |
| 61 | + * be useful for searching. Keeping your Algolia records small increases indexing and search |
| 62 | + * performance. - Exclude nested attributes with `.` notation. For example, `foo.bar` indexes the |
| 63 | + * `foo` attribute and all its children **except** the `bar` attribute. - Exclude attributes from |
| 64 | + * arrays with `[i]`, where `i` is the index of the array element. For example, `foo.[0].bar` only |
| 65 | + * excludes the `bar` attribute from the first element of the `foo` array, but indexes the |
| 66 | + * complete `foo` attribute for all other elements. Use `*` as wildcard: `foo.[*].bar` excludes |
| 67 | + * `bar` from all elements of the `foo` array. |
| 68 | + */ |
| 69 | + @javax.annotation.Nullable |
| 70 | + public List<String> getAttributesToExclude() { |
| 71 | + return attributesToExclude; |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public boolean equals(Object o) { |
| 76 | + if (this == o) { |
| 77 | + return true; |
34 | 78 | }
|
| 79 | + if (o == null || getClass() != o.getClass()) { |
| 80 | + return false; |
| 81 | + } |
| 82 | + DestinationInput destinationInput = (DestinationInput) o; |
| 83 | + return ( |
| 84 | + Objects.equals(this.indexName, destinationInput.indexName) && |
| 85 | + Objects.equals(this.recordType, destinationInput.recordType) && |
| 86 | + Objects.equals(this.attributesToExclude, destinationInput.attributesToExclude) |
| 87 | + ); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public int hashCode() { |
| 92 | + return Objects.hash(indexName, recordType, attributesToExclude); |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + public String toString() { |
| 97 | + StringBuilder sb = new StringBuilder(); |
| 98 | + sb.append("class DestinationInput {\n"); |
| 99 | + sb.append(" indexName: ").append(toIndentedString(indexName)).append("\n"); |
| 100 | + sb.append(" recordType: ").append(toIndentedString(recordType)).append("\n"); |
| 101 | + sb.append(" attributesToExclude: ").append(toIndentedString(attributesToExclude)).append("\n"); |
| 102 | + sb.append("}"); |
| 103 | + return sb.toString(); |
| 104 | + } |
35 | 105 |
|
36 |
| - /** Handle deserialization of the 'null' value. */ |
37 |
| - @Override |
38 |
| - public DestinationInput getNullValue(DeserializationContext ctxt) throws JsonMappingException { |
39 |
| - throw new JsonMappingException(ctxt.getParser(), "DestinationInput cannot be null"); |
| 106 | + /** |
| 107 | + * Convert the given object to string with each line indented by 4 spaces (except the first line). |
| 108 | + */ |
| 109 | + private String toIndentedString(Object o) { |
| 110 | + if (o == null) { |
| 111 | + return "null"; |
40 | 112 | }
|
| 113 | + return o.toString().replace("\n", "\n "); |
41 | 114 | }
|
42 | 115 | }
|
0 commit comments