View Javadoc

1   package com.atlassian.plugins.rest.doclet.generators.schema.beans.issue;
2   
3   import com.atlassian.annotations.ExperimentalApi;
4   import com.google.common.base.Objects;
5   import com.google.common.base.Preconditions;
6   import com.google.common.collect.ImmutableMap;
7   import org.codehaus.jackson.annotate.JsonIgnoreProperties;
8   import org.codehaus.jackson.annotate.JsonProperty;
9   import org.codehaus.jackson.map.annotate.JsonSerialize;
10  
11  import java.util.Map;
12  
13  /**
14   * Represents the complete set of metadata for a history changegroup.
15   *
16   * @since JIRA 6.3
17   */
18  @ExperimentalApi
19  @JsonSerialize (include = JsonSerialize.Inclusion.NON_NULL)
20  @JsonIgnoreProperties (ignoreUnknown = true)
21  public final class HistoryMetadata
22  {
23      @JsonProperty
24      private String type;
25  
26      @JsonProperty
27      private String description;
28  
29      @JsonProperty
30      private String descriptionKey;
31  
32      @JsonProperty
33      private String activityDescription;
34  
35      @JsonProperty
36      private String activityDescriptionKey;
37  
38      @JsonProperty
39      private String emailDescription;
40  
41      @JsonProperty
42      private String emailDescriptionKey;
43  
44      @JsonProperty
45      private HistoryMetadataParticipant actor;
46  
47      @JsonProperty
48      private HistoryMetadataParticipant generator;
49  
50      @JsonProperty
51      private HistoryMetadataParticipant cause;
52  
53      @JsonProperty
54      private Map<String, String> extraData;
55  
56      // for jackson
57      private HistoryMetadata()
58      {
59      }
60  
61      private HistoryMetadata(final HistoryMetadataBuilder builder)
62      {
63          this.type = builder.type;
64          this.description = builder.description;
65          this.descriptionKey = builder.descriptionKey;
66          this.activityDescription = builder.activityDescription;
67          this.activityDescriptionKey = builder.activityDescriptionKey;
68          this.emailDescription = builder.emailDescription;
69          this.emailDescriptionKey = builder.emailDescriptionKey;
70          this.actor = builder.actor;
71          this.generator = builder.generator;
72          this.cause = builder.cause;
73          this.extraData = builder.extraData.build();
74      }
75  
76      /**
77       * The person or agent that triggered the history change
78       */
79      public HistoryMetadataParticipant getActor()
80      {
81          return actor;
82      }
83  
84      /**
85       * The system that triggered the history change
86       */
87      public HistoryMetadataParticipant getGenerator()
88      {
89          return generator;
90      }
91  
92      /**
93       * The event or state that triggered the history change
94       */
95      public HistoryMetadataParticipant getCause()
96      {
97          return cause;
98      }
99  
100     /**
101      * A unique id to identify the plugin/system that generated this metadata
102      */
103     public String getType()
104     {
105         return type;
106     }
107 
108     /**
109      * Textual description of the change
110      */
111     public String getDescription()
112     {
113         return description;
114     }
115 
116     /**
117      * i18n key for the textual description of the change, will be used before description if present
118      */
119     public String getDescriptionKey()
120     {
121         return descriptionKey;
122     }
123 
124     /**
125      * Textual description of the change for the activity stream
126      */
127     public String getActivityDescription()
128     {
129         return activityDescription;
130     }
131 
132     /**
133      * i18n key for the description of the change for the activity stream, will be used before activityDescription if present
134      */
135     public String getActivityDescriptionKey()
136     {
137         return activityDescriptionKey;
138     }
139 
140     /**
141      * Textual description of the change for notification emails
142      */
143     public String getEmailDescription()
144     {
145         return emailDescription;
146     }
147 
148     /**
149      * i18n key for the textual description of the change for the notification email, will be used before emailDescription if present
150      */
151     public String getEmailDescriptionKey()
152     {
153         return emailDescriptionKey;
154     }
155 
156     /**
157      * Additional metadata related to the history change
158      */
159     public Map<String, String> getExtraData()
160     {
161         return extraData;
162     }
163 
164     /**
165      * This method is implemented for usage in Unit Tests.
166      */
167     @Override
168     public int hashCode()
169     {
170         return Objects.hashCode(type, actor, generator, cause, extraData, description, descriptionKey,
171                 activityDescription, activityDescriptionKey, emailDescription, emailDescriptionKey);
172     }
173 
174     /**
175      * This method is implemented for usage in Unit Tests.
176      */
177     @Override
178     public boolean equals(final Object obj)
179     {
180         if (this == obj)
181         {
182             return true;
183         }
184         if (obj == null || getClass() != obj.getClass())
185         {
186             return false;
187         }
188         final HistoryMetadata other = (HistoryMetadata) obj;
189         return Objects.equal(this.type, other.type) && Objects.equal(this.actor, other.actor) && Objects.equal(this.generator, other.generator) &&
190                 Objects.equal(this.cause, other.cause) && Objects.equal(this.extraData, other.extraData) &&
191                 Objects.equal(this.description, other.description) && Objects.equal(this.descriptionKey, other.descriptionKey) &&
192                 Objects.equal(this.activityDescription, other.activityDescription) && Objects.equal(this.activityDescriptionKey, other.activityDescriptionKey) &&
193                 Objects.equal(this.emailDescription, other.emailDescription) && Objects.equal(this.emailDescriptionKey, other.emailDescriptionKey);
194     }
195 
196     /**
197      * @param type the type of the metadata object being created
198      * @return a builder for a HistoryMetadata object
199      */
200     public static HistoryMetadataBuilder builder(String type)
201     {
202         return new HistoryMetadataBuilder(type);
203     }
204 
205     @ExperimentalApi
206     public static class HistoryMetadataBuilder
207     {
208         private String type;
209         private String description;
210         private String descriptionKey;
211         private String activityDescription;
212         private String activityDescriptionKey;
213         private String emailDescription;
214         private String emailDescriptionKey;
215         private HistoryMetadataParticipant actor;
216         private HistoryMetadataParticipant generator;
217         private HistoryMetadataParticipant cause;
218         private ImmutableMap.Builder<String, String> extraData = ImmutableMap.builder();
219 
220         private HistoryMetadataBuilder(final String type)
221         {
222             this.type = Preconditions.checkNotNull(type);
223         }
224 
225         public HistoryMetadataBuilder description(String description)
226         {
227             this.description = description;
228             return this;
229         }
230 
231         public HistoryMetadataBuilder descriptionKey(String descriptionKey)
232         {
233             this.descriptionKey = descriptionKey;
234             return this;
235         }
236 
237         public HistoryMetadataBuilder activityDescription(String activityDescription)
238         {
239             this.activityDescription = activityDescription;
240             return this;
241         }
242 
243         public HistoryMetadataBuilder activityDescriptionKey(String activityDescriptionKey)
244         {
245             this.activityDescriptionKey = activityDescriptionKey;
246             return this;
247         }
248 
249         public HistoryMetadataBuilder emailDescription(String emailDescription)
250         {
251             this.emailDescription = emailDescription;
252             return this;
253         }
254 
255         public HistoryMetadataBuilder emailDescriptionKey(String emailDescriptionKey)
256         {
257             this.emailDescriptionKey = emailDescriptionKey;
258             return this;
259         }
260 
261         public HistoryMetadataBuilder actor(HistoryMetadataParticipant actor)
262         {
263             this.actor = actor;
264             return this;
265         }
266 
267         public HistoryMetadataBuilder generator(HistoryMetadataParticipant generator)
268         {
269             this.generator = generator;
270             return this;
271         }
272 
273         public HistoryMetadataBuilder cause(HistoryMetadataParticipant cause)
274         {
275             this.cause = cause;
276             return this;
277         }
278 
279         public HistoryMetadataBuilder extraData(Map<String, String> extraData)
280         {
281             this.extraData.putAll(extraData);
282             return this;
283         }
284 
285         public HistoryMetadataBuilder extraData(String extraDataKey, String extraDataValue)
286         {
287             this.extraData.put(extraDataKey, extraDataValue);
288             return this;
289         }
290 
291         public HistoryMetadata build()
292         {
293             return new HistoryMetadata(this);
294         }
295     }
296 }