1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache license, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the license for the specific language governing permissions and
15 * limitations under the license.
16 */
17 package org.apache.logging.log4j.catalog.api;
18
19 import java.io.Serializable;
20 import java.util.Set;
21
22 import static org.apache.logging.log4j.catalog.api.constant.Constants.DEFAULT_CATALOG;
23
24 /**
25 * A Catalog AttributeDto.
26 */
27 public class Attribute implements Serializable {
28
29 private static final long serialVersionUID = -756109102178482698L;
30 private Long id;
31 private String name;
32 private String displayName;
33 private String description;
34 private DataType dataType;
35 private boolean indexed;
36 private boolean sortable;
37 private boolean required;
38 private boolean requestContext;
39 private Set<String> examples;
40 private Set<String> aliases;
41 private Set<Constraint> constraints;
42 private String catalogId;
43
44 /**
45 * Set default values.
46 */
47 public Attribute() {
48 catalogId = DEFAULT_CATALOG;
49 }
50
51 /**
52 * Return the attribute's id.
53 * @return the Attribute's id.
54 */
55 public Long getId() {
56 return id;
57 }
58
59 /**
60 * Set the Attribute's id.
61 * @param id the Attribute's id.
62 */
63 public void setId(Long id) {
64 this.id = id;
65 }
66
67 /**
68 * Returns the name of the AttributeDto.
69 */
70 public String getName() {
71 return name;
72 }
73
74 /**
75 * Set the name of the AttributeDto.
76 * @param name the name of the attribute.
77 * @return this Attribute.
78 */
79 public Attribute setName(String name) {
80 this.name = name;
81 return this;
82 }
83
84 /**
85 * Returns the name used when displaying the attribute.
86 * @return the display name of the attribute.
87 */
88 public String getDisplayName() {
89 return displayName;
90 }
91
92 /**
93 * Set the name to be displayed for this attribute.
94 * @param name the display name for the attribute.
95 * @return this Attribute.
96 */
97 public Attribute setDisplayName(String name) {
98 this.displayName = name;
99 return this;
100 }
101
102 /**
103 * Returns the description of the attribute.
104 * @return the description of the attribute.
105 */
106 public String getDescription() {
107 return description;
108 }
109
110 /**
111 * Set the description of the attribute.
112 * @param description the description of the attribute.
113 * @return this Attribute.
114 */
115 public Attribute setDescription(String description) {
116 this.description = description;
117 return this;
118 }
119
120 /**
121 * Returns the data type of this attribute.
122 * @return the data type of the attribute.
123 */
124 public DataType getDataType() {
125 return dataType;
126 }
127
128 /**
129 * Set the data type of the attribute.
130 * @param dataType the data type of the attribute.
131 * @return this Attribute.
132 */
133 public Attribute setDataType(DataType dataType) {
134 this.dataType = dataType;
135 return this;
136 }
137
138 /**
139 * Identifies whether this attribute is an index.
140 * @return true if this attribute is an index, false otherwise.
141 */
142 public boolean isIndexed() {
143 return indexed;
144 }
145
146 /**
147 * Set whether this attribute is an index.
148 * @param indexed true if this attribute is an index, false otherwise.
149 * @return this Attribute.
150 */
151 public Attribute setIndexed(boolean indexed) {
152 this.indexed = indexed;
153 return this;
154 }
155
156 /**
157 * Returns whether a sort may be performed on this attribute.
158 * @return true if a sort can be performed on this attribute, false otherwise.
159 */
160 public boolean isSortable() {
161 return sortable;
162 }
163
164 /**
165 * Set whether a sort may be performed on this attribute.
166 * @param sortable true if a sort may be performed on this attribute, false otherwise.
167 * @return this Attribute.
168 */
169 public Attribute setSortable(boolean sortable) {
170 this.sortable = sortable;
171 return this;
172 }
173
174 /**
175 * Returns whether this attribute is required.
176 * @return true if this attribute is required, false otherwise.
177 */
178 public boolean isRequired() {
179 return required;
180 }
181
182 /**
183 * Set whether this attribute is required.
184 * @param required true if this attribute is required, false otherwise.
185 * @return this Attribute.
186 */
187 public Attribute setRequired(boolean required) {
188 this.required = required;
189 return this;
190 }
191
192 /**
193 * Returns whether this attribute is part of the RequestContext.
194 * @return true if this attribute is part of the RequestContext, false otherwise.
195 */
196 public boolean isRequestContext() {
197 return requestContext;
198 }
199
200 /**
201 * Set whether this attribute is part of the RequestContext.
202 * @param isRequestContext true if this attribute is part of the RequestContext, false otherwise.
203 * @return this Attribute.
204 */
205 public Attribute setRequestContext(boolean isRequestContext) {
206 this.requestContext = isRequestContext;
207 return this;
208 }
209
210 /**
211 * Returns the List of example Strings.
212 * @return the List of example Strings.
213 */
214 public Set<String> getExamples() {
215 return examples;
216 }
217
218 /**
219 * Sets the List of example Strings.
220 * @param examples the List of example Strings.
221 * @return this Attribute.
222 */
223 public Attribute setExamples(Set<String> examples) {
224 this.examples = examples;
225 return this;
226 }
227
228 /**
229 * Returns the List of alias Strings.
230 * @return the List of alias Strings.
231 */
232 public Set<String> getAliases() {
233 return aliases;
234 }
235
236 /**
237 * Sets List of alias Strings.
238 * @param aliases The List of alias Strings.
239 * @return this Attribute.
240 */
241 public Attribute setAliases(Set<String> aliases) {
242 this.aliases = aliases;
243 return this;
244 }
245
246 /**
247 * Returns the constraints on this attribute.
248 * @return The list of constraints.
249 */
250 public Set<Constraint> getConstraints() {
251 return constraints;
252 }
253
254 /**
255 * Sets the Constraints onf the attribute.
256 * @param constraints The List of constraints.
257 * @return This Attribute.
258 */
259 public Attribute setConstraints(Set<Constraint> constraints) {
260 this.constraints = constraints;
261 return this;
262 }
263
264 /**
265 * Get the Catalog Id this attribute is associated with.
266 * @return the catalog id or null.
267 */
268 public String getCatalogId() {
269 return catalogId;
270 }
271
272 /**
273 * Set the catalog id this attribute is associated with.
274 * @param catalogId The catalog id or null.
275 */
276 public void setCatalogId(String catalogId) {
277 this.catalogId = catalogId;
278 }
279
280 @Override
281 public String toString() {
282 StringBuilder sb = new StringBuilder("{");
283 sb.append("id=\"").append(id).append("\" ");
284 sb.append("catalog id=\"").append(catalogId).append("\" ");
285 sb.append("name=\"").append(name).append("\" ");
286 sb.append("displayName=\"").append(displayName).append("\" ");
287 sb.append("description=\"").append(description).append("\" ");
288 sb.append("dataType=\"");
289 if (dataType == null) {
290 sb.append("null");
291 } else {
292 sb.append(dataType.getTypeName());
293 }
294 sb.append("\" ");
295 sb.append("indexed=\"").append(indexed).append("\" ");
296 sb.append("sortable=\"").append(sortable).append("\" ");
297 sb.append("required=\"").append(required).append("\" ");
298 sb.append("requestContext=\"").append(requestContext).append("\" ");
299 if (constraints != null) {
300 sb.append("constraints[");
301 boolean first = true;
302 for (Constraint constraint : constraints) {
303 if (!first) {
304 sb.append(" ");
305 }
306 sb.append("name=\"").append(constraint.getConstraintType().getName()).append("\"");
307 sb.append("value=\"").append(constraint.getValue()).append("\"");
308 }
309 sb.append("]");
310 }
311 sb.append("}");
312 return sb.toString();
313 }
314 }