View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.api.core.domain;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.apache.commons.lang.builder.ToStringBuilder;
23  
24  /**
25   * Stores document instance information for projectdoc metadata.
26   */
27  public class ProjectdocMetaData implements DocumentMetaData
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    /**
34     * The class version identifier.
35     */
36    private static final long serialVersionUID = 1L;
37  
38    // --- members --------------------------------------------------------------
39  
40    /**
41     * The reference to the parent meta data to access as default values.
42     */
43    private final ProjectdocMetaData parent;
44  
45    /**
46     * The categories associated with the document instance.
47     *
48     * @serial
49     */
50    private final List<String> categories = new ArrayList<String>();
51  
52    /**
53     * The tags associated with the document instance.
54     *
55     * @serial
56     */
57    private final List<String> tags = new ArrayList<String>();
58  
59    /**
60     * The parents associated with the document instance.
61     *
62     * @serial
63     */
64    private final List<String> parents = new ArrayList<String>();
65  
66    /**
67     * The audience the documentation targets.
68     *
69     * @serial
70     */
71    private final List<String> audience = new ArrayList<String>();
72  
73    /**
74     * The unique document identifier within the project. It is generated by the
75     * system if not given explicitly and may be expanded with context information
76     * to be unique.
77     *
78     * @serial
79     */
80    private String name;
81  
82    /**
83     * The space within which the title of a document is required to be unique.
84     *
85     * @serial
86     */
87    private String space;
88  
89    /**
90     * The title of a document, unique within the given space.
91     *
92     * @serial
93     */
94    private String title;
95  
96    /**
97     * The short description of the document to be incorporated in an overview
98     * table. Should not exceed one to three sentences.
99     *
100    * @serial
101    */
102   private String shortDescription;
103 
104   /**
105    * The short summary of contents of the document to give more detailed
106    * information to a potential reader. Should not exceed one too three
107    * paragraphs.
108    *
109    * @serial
110    */
111   private String summary;
112 
113   /**
114    * The option to sort elements. This sort key is used first for sorting the
115    * document instances in the index document of this doctype.
116    *
117    * @serial
118    */
119   private String sortKey;
120 
121   /**
122    * The list of notes appended to the document instance.
123    *
124    * @serial
125    */
126   private final List<String> notes = new ArrayList<String>();
127 
128   // ****************************** Initializer *******************************
129 
130   // ****************************** Constructors ******************************
131 
132   /**
133    * Convenience constructor without a parent to inherit from.
134    */
135   public ProjectdocMetaData()
136   {
137     this(null);
138   }
139 
140   /**
141    * Default constructor.
142    *
143    * @param parent the reference to the parent meta data to access as default
144    *          values.
145    */
146   public ProjectdocMetaData(final ProjectdocMetaData parent)
147   {
148     this.space = parent != null ? parent.space : null;
149     this.parent = parent;
150 
151     if (parent != null)
152     {
153       categories.addAll(parent.categories);
154       tags.addAll(parent.tags);
155       audience.addAll(parent.audience);
156     }
157   }
158 
159   // ****************************** Inner Classes *****************************
160 
161   // ********************************* Methods ********************************
162 
163   // --- init -----------------------------------------------------------------
164 
165   // --- get&set --------------------------------------------------------------
166 
167   /**
168    * Returns the reference to the parent meta data to access as default values.
169    *
170    * @return the reference to the parent meta data to access as default values.
171    */
172   public final ProjectdocMetaData getParent()
173   {
174     return parent;
175   }
176 
177   @Override
178   public final List<String> getCategories()
179   {
180     return categories;
181   }
182 
183   /**
184    * Adds a category. Blank category names or categories already part of the
185    * list will be ignored.
186    *
187    * @param category the category to be added.
188    */
189   public final void addCategory(final String category)
190   {
191     addElement(categories, category);
192   }
193 
194   @Override
195   public final List<String> getTags()
196   {
197     return tags;
198   }
199 
200   /**
201    * Adds a tag. Blank tag names or tags already part of the list will be
202    * ignored.
203    *
204    * @param tag the tag to be added.
205    */
206   public final void addTag(final String tag)
207   {
208     addElement(tags, tag);
209   }
210 
211   @Override
212   public final List<String> getParents()
213   {
214     return parents;
215   }
216 
217   /**
218    * Adds a parent. Blank parent names or parents already part of the list will
219    * be ignored.
220    *
221    * @param parent the parent to be added.
222    */
223   public final void addParent(final String parent)
224   {
225     addElement(parents, parent);
226   }
227 
228   @Override
229   public final String getName()
230   {
231     return name;
232   }
233 
234   /**
235    * Sets the name of the document if not blank.
236    *
237    * @param name the name of the document to set.
238    */
239   public final void setName(final String name)
240   {
241     if (StringUtils.isNotBlank(name))
242     {
243       this.name = name;
244     }
245   }
246 
247   @Override
248   public final String getShortDescription()
249   {
250     return shortDescription;
251   }
252 
253   /**
254    * Sets the short description of the document to be incorporated in an
255    * overview table. Should not exceed one to three sentences. If the value is
256    * blank, it is ignored.
257    *
258    * @param shortDescription the short description of the document to be
259    *          incorporated in an overview table.
260    */
261   public final void setShortDescription(final String shortDescription)
262   {
263     if (StringUtils.isNotBlank(shortDescription))
264     {
265       this.shortDescription = shortDescription;
266     }
267   }
268 
269   @Override
270   public final List<String> getNotes()
271   {
272     return notes;
273   }
274 
275   /**
276    * Adds a note. Blank notes or notes already part of the list will be ignored.
277    *
278    * @param note the note to be added.
279    */
280   public final void addNote(final String note)
281   {
282     addElement(notes, note);
283   }
284 
285   @Override
286   public final String getSpace()
287   {
288     return space;
289   }
290 
291   /**
292    * Sets the space within which the title of a document is required to be
293    * unique. If the value is blank it is ignored.
294    *
295    * @param space the space within which the title of a document is required to
296    *          be unique.
297    */
298   public final void setSpace(final String space)
299   {
300     if (StringUtils.isNotBlank(space))
301     {
302       this.space = space;
303     }
304   }
305 
306   @Override
307   public final String getTitle()
308   {
309     return title;
310   }
311 
312   /**
313    * Sets the title of a document, unique within the given space. If the value
314    * is blank it is ignored.
315    *
316    * @param title the title of a document, unique within the given space.
317    */
318   public final void setTitle(final String title)
319   {
320     if (StringUtils.isNotBlank(title))
321     {
322       this.title = title;
323     }
324   }
325 
326   @Override
327   public final String getSummary()
328   {
329     return summary;
330   }
331 
332   /**
333    * Sets the short summary of contents of the document to give more detailed
334    * information to a potential reader. Should not exceed one too three
335    * paragraphs. If the value is blank it is ignored.
336    *
337    * @param summary the short summary of contents of the document to give more
338    *          detailed information to a potential reader.
339    */
340   public final void setSummary(final String summary)
341   {
342     if (StringUtils.isNotBlank(summary))
343     {
344       this.summary = summary;
345     }
346   }
347 
348   @Override
349   public final String getSortKey()
350   {
351     return sortKey;
352   }
353 
354   /**
355    * Sets the option to sort elements. This sort key is used first for sorting
356    * the document instances in the index document of this doctype. If the value
357    * is blank it is ignored.
358    *
359    * @param sortKey the option to sort elements.
360    */
361   public final void setSortKey(final String sortKey)
362   {
363     if (StringUtils.isNotBlank(sortKey))
364     {
365       this.sortKey = sortKey;
366     }
367   }
368 
369   @Override
370   public final List<String> getAudience()
371   {
372     return audience;
373   }
374 
375   /**
376    * Adds the member to the intended audience of this document.
377    *
378    * @param member the audience member to add.
379    */
380   public final void addAudience(final String member)
381   {
382     addElement(audience, member);
383   }
384 
385   // --- business -------------------------------------------------------------
386 
387   /**
388    * Adds the element to the given list, if the element is neither blank nor
389    * already part of the list.
390    *
391    * @param elements the list to add to.
392    * @param element the element to be added.
393    */
394   protected static final void addElement(final List<String> elements,
395       final String element)
396   {
397     if (StringUtils.isNotBlank(element) && !elements.contains(element))
398     {
399       elements.add(element);
400     }
401   }
402 
403   // --- object basics --------------------------------------------------------
404 
405   /**
406    * Returns the string representation of the object.
407    *
408    * @return the string representation of the object.
409    */
410   @Override
411   public final String toString()
412   {
413     return ToStringBuilder.reflectionToString(this);
414   }
415 }