|
| 1 | +package com.github.m0nk3y2k4.thetvdb.internal.api.impl.model; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 4 | +import com.github.m0nk3y2k4.thetvdb.api.model.APIResponse; |
| 5 | + |
| 6 | +import java.util.Collections; |
| 7 | +import java.util.List; |
| 8 | +import java.util.Optional; |
| 9 | + |
| 10 | +@JsonIgnoreProperties(ignoreUnknown = true) |
| 11 | +public class APIResponseImpl<T> implements APIResponse<T> { |
| 12 | + |
| 13 | + /** Requested record data */ |
| 14 | + private T data; |
| 15 | + /** Additional error information */ |
| 16 | + private JSONErrors errors; |
| 17 | + /** Additional paging information */ |
| 18 | + private Links links; |
| 19 | + |
| 20 | + @Override |
| 21 | + public T getData() { |
| 22 | + return data; |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Set the data |
| 27 | + * |
| 28 | + * @param data the data to set |
| 29 | + */ |
| 30 | + public void setData(T data) { |
| 31 | + this.data = data; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public Optional<JSONErrors> getErrors() { |
| 36 | + return Optional.ofNullable(errors); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Set the errors |
| 41 | + * |
| 42 | + * @param errors the errors to set |
| 43 | + */ |
| 44 | + public void setErrors(JSONErrors errors) { |
| 45 | + this.errors = errors; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public Optional<Links> getLinks() { |
| 50 | + return Optional.ofNullable(links); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Set the links |
| 55 | + * |
| 56 | + * @param links the links to set |
| 57 | + */ |
| 58 | + public void setLinks(Links links) { |
| 59 | + this.links = links; |
| 60 | + } |
| 61 | + |
| 62 | + @JsonIgnoreProperties(ignoreUnknown = true) |
| 63 | + public static class JSONErrorsImpl implements JSONErrors { |
| 64 | + |
| 65 | + /** JSON properties mapped as Java types */ |
| 66 | + private List<String> invalidFilters; |
| 67 | + private String invalidLanguage; |
| 68 | + private List<String> invalidQueryParams; |
| 69 | + |
| 70 | + public JSONErrorsImpl() { |
| 71 | + super(); |
| 72 | + this.invalidFilters = Collections.emptyList(); |
| 73 | + this.invalidQueryParams = Collections.emptyList(); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public List<String> getInvalidFilters() { |
| 78 | + return invalidFilters; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Set the invalidFilters |
| 83 | + * |
| 84 | + * @param invalidFilters the invalidFilters to set |
| 85 | + */ |
| 86 | + public void setInvalidFilters(List<String> invalidFilters) { |
| 87 | + this.invalidFilters = invalidFilters; |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public String getInvalidLanguage() { |
| 92 | + return invalidLanguage; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Set the invalidLanguage |
| 97 | + * |
| 98 | + * @param invalidLanguage the invalidLanguage to set |
| 99 | + */ |
| 100 | + public void setInvalidLanguage(String invalidLanguage) { |
| 101 | + this.invalidLanguage = invalidLanguage; |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public List<String> getInvalidQueryParams() { |
| 106 | + return invalidQueryParams; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Set the invalidQueryParams |
| 111 | + * |
| 112 | + * @param invalidQueryParams the invalidQueryParams to set |
| 113 | + */ |
| 114 | + public void setInvalidQueryParams(List<String> invalidQueryParams) { |
| 115 | + this.invalidQueryParams = invalidQueryParams; |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + @JsonIgnoreProperties(ignoreUnknown = true) |
| 120 | + public static class LinksImpl implements Links { |
| 121 | + |
| 122 | + /** JSON properties mapped as Java types */ |
| 123 | + private int first; |
| 124 | + private int last; |
| 125 | + private int next; |
| 126 | + private int previous; |
| 127 | + |
| 128 | + @Override |
| 129 | + public int getFirst() { |
| 130 | + return first; |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * Set the first |
| 135 | + * |
| 136 | + * @param first the first to set |
| 137 | + */ |
| 138 | + public void setFirst(int first) { |
| 139 | + this.first = first; |
| 140 | + } |
| 141 | + |
| 142 | + @Override |
| 143 | + public int getLast() { |
| 144 | + return last; |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Set the last |
| 149 | + * |
| 150 | + * @param last the last to set |
| 151 | + */ |
| 152 | + public void setLast(int last) { |
| 153 | + this.last = last; |
| 154 | + } |
| 155 | + |
| 156 | + @Override |
| 157 | + public int getNext() { |
| 158 | + return next; |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * Set the next |
| 163 | + * |
| 164 | + * @param next the next to set |
| 165 | + */ |
| 166 | + public void setNext(int next) { |
| 167 | + this.next = next; |
| 168 | + } |
| 169 | + |
| 170 | + @Override |
| 171 | + public int getPrevious() { |
| 172 | + return previous; |
| 173 | + } |
| 174 | + |
| 175 | + /** |
| 176 | + * Set the previous |
| 177 | + * |
| 178 | + * @param previous the previous to set |
| 179 | + */ |
| 180 | + public void setPrevious(int previous) { |
| 181 | + this.previous = previous; |
| 182 | + } |
| 183 | + } |
| 184 | +} |
0 commit comments