View Javadoc
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.List;
21  import java.util.Set;
22  
23  import com.fasterxml.jackson.annotation.JsonFilter;
24  
25  import static org.apache.logging.log4j.catalog.api.constant.Constants.DEFAULT_CATALOG;
26  
27  /**
28   * Basic attributes common to all events.
29   */
30  @JsonFilter("catalogEvent")
31  public class Event implements Serializable {
32  
33      private static final long serialVersionUID = 1512172827909901054L;
34      private Long id;
35      private String name;
36      private String displayName;
37      private String description;
38      private Set<String> aliases;
39      private String catalogId;
40      private List<EventAttribute> attributes;
41  
42      /**
43       * Set default values.
44       */
45      public Event() {
46          catalogId = DEFAULT_CATALOG;
47      }
48      
49      /**
50       * Return the id or the event.
51       * @return the Event's id.
52       */
53      public Long getId() {
54          return id;
55      }
56  
57      /**
58       * Set the event's id.
59       * @param id the Event's id.
60       */
61      public void setId(Long id) {
62          this.id = id;
63      }
64  
65      /**
66       * Return the name of the event.
67       * @return the name of the event.
68       */
69      public String getName() {
70          return name;
71      }
72  
73      /**
74       * Sets the name of the event.
75       * @param name The name of the event.
76       * @return this Event.
77       */
78      public Event setName(String name) {
79          this.name = name;
80          return this;
81      }
82  
83      /**
84       * Returns the name to display for this event.
85       * @return the display name for this event.
86       */
87      public String getDisplayName() {
88          return displayName;
89      }
90  
91      /**
92       * Set the display name for this event.
93       * @param name the name to display for this event.
94       * @return this Event.
95       */
96      public Event setDisplayName(String name) {
97          this.displayName = name;
98          return this;
99      }
100 
101     /**
102      * Return the description of the event.
103      * @return the event description.
104      */
105     public String getDescription() {
106         return description;
107     }
108 
109     /**
110      * Set the event description.
111      * @param description The description of the event.
112      * @return this Event.
113      */
114     public Event setDescription(String description) {
115         this.description = description;
116         return this;
117     }
118 
119     /**
120      * Get the Catalog Id this Event is associated with.
121      * @return the catalog id or null.
122      */
123     public String getCatalogId() {
124         return catalogId;
125     }
126 
127     /**
128      * Set the catalog id this Event is associated with.
129      * @param catalogId The catalog id or null.
130      */
131     public Event setCatalogId(String catalogId) {
132         if (catalogId != null) {
133             this.catalogId = catalogId;
134         }
135         return this;
136     }
137 
138     /**
139      * Returns the Set of alias Strings.
140      * @return the Set of alias Strings.
141      */
142     public Set<String> getAliases() {
143         return aliases;
144     }
145 
146     /**
147      * Sets the Set of alias Strings.
148      * @param aliases the Set of alias Strings.
149      * @return this Event.
150      */
151     public Event setAliases(Set<String> aliases) {
152         this.aliases = aliases;
153         return this;
154     }
155 
156     /**
157      * Returns the List of Attribute names.
158      * @return the List of Attribute names.
159      */
160     public List<EventAttribute> getAttributes() {
161         return attributes;
162     }
163 
164     /**
165      * Sets the List of Atribute names.
166      * @param attributes The List of Attribute names.
167      * @return this Event.
168      */
169     public Event setAttributes(List<EventAttribute> attributes) {
170         this.attributes = attributes;
171         return this;
172     }
173 
174     public String toString() {
175         StringBuilder sb = new StringBuilder();
176         sb.append("{\"name\" : \"").append(name).append("\", \"displayName\" : \"").append(displayName).append("\"");
177         sb.append(", \"description\" : \"").append(description).append("\", \"attributes\" : [");
178         boolean first = true;
179         for (EventAttribute attribute : attributes) {
180             if (!first) {
181                 sb.append(", ");
182             } else {
183                 first = false;
184             }
185             sb.append("{\"name\" : \"").append(attribute.getName()).append("\", \"required\" : ").append(attribute.isRequired()).append("}");
186         }
187         sb.append("]}");
188         return sb.toString();
189     }
190 }