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.report.data;
17  
18  import org.apache.commons.lang.StringUtils;
19  
20  import de.smartics.properties.api.core.domain.DocumentMetaData;
21  import de.smartics.properties.spi.core.metadata.projectdoc.ProjectdocMetaData;
22  import de.smartics.util.lang.Arguments;
23  import de.smartics.util.lang.BlankArgumentException;
24  import de.smartics.util.lang.NullArgumentException;
25  
26  /**
27   * Report information for a particular property set.
28   */
29  public final class PropertyReportSet
30  {
31    // ********************************* Fields *********************************
32  
33    // --- constants ------------------------------------------------------------
34  
35    // --- members --------------------------------------------------------------
36  
37    /**
38     * The name of the property set as read from the
39     * {@link de.smartics.properties.api.core.annotations.PropertySet} annotation.
40     */
41    private final String name;
42  
43    /**
44     * The type that defines the report set, if no name is specified explicitly.
45     */
46    private final String type;
47  
48    /**
49     * The Javadoc comment to the descriptor.
50     */
51    private final String comment;
52  
53    /**
54     * The document instance metadata.
55     */
56    private final DocumentMetaData metadata;
57  
58    // ****************************** Initializer *******************************
59  
60    // ****************************** Constructors ******************************
61  
62    private PropertyReportSet(final Builder builder)
63    {
64      this.name = builder.name;
65      this.type = builder.type;
66      this.comment = builder.comment;
67      this.metadata = builder.metadata;
68    }
69  
70    // ****************************** Inner Classes *****************************
71  
72    /**
73     * Builder to create instances of enclosing class.
74     */
75    public static final class Builder
76    {
77      // ******************************** Fields ********************************
78  
79      // --- constants ----------------------------------------------------------
80  
81      // --- members ------------------------------------------------------------
82  
83      /**
84       * The name of the property set as read from the
85       * {@link de.smartics.properties.api.core.annotations.PropertySet} annotation.
86       */
87      private String name;
88  
89      /**
90       * The type that defines the report set, if no name is specified explicitly.
91       */
92      private String type;
93  
94      /**
95       * The Javadoc comment to the descriptor.
96       */
97      private String comment;
98  
99      /**
100      * The document instance metadata.
101      */
102     private DocumentMetaData metadata = new ProjectdocMetaData();
103 
104     // ***************************** Initializer ******************************
105 
106     // ***************************** Constructors *****************************
107 
108     // ***************************** Inner Classes ****************************
109 
110     // ******************************** Methods *******************************
111 
112     // --- init ---------------------------------------------------------------
113 
114     // --- get&set ------------------------------------------------------------
115 
116     /**
117      * Sets the name of the property set as read from the
118      * {@link de.smartics.properties.api.core.annotations.PropertySet} annotation.
119      *
120      * @param name the name of the property set.
121      * @return a reference to the builder.
122      */
123     public Builder withPropertySetName(final String name)
124     {
125       this.name = name;
126       return this;
127     }
128 
129     /**
130      * Sets the type that defines the report set, if no name is specified
131      * explicitly.
132      *
133      * @param type the type that defines the report set, if no name is specified
134      *          explicitly.
135      * @return a reference to the builder.
136      */
137     public Builder withType(final String type)
138     {
139       this.type = type;
140       return this;
141     }
142 
143     /**
144      * Sets the Javadoc comment to the descriptor.
145      *
146      * @param comment the Javadoc comment to the descriptor.
147      * @return a reference to the builder.
148      */
149     public Builder withComment(final String comment)
150     {
151       this.comment = comment;
152       return this;
153     }
154 
155     /**
156      * Set the document instance metadata.
157      *
158      * @param metadata the document instance metadata.
159      * @return a reference to the builder.
160      * @throws NullArgumentException if {@code metadata} is <code>null</code>.
161      */
162     public Builder with(final DocumentMetaData metadata)
163       throws NullArgumentException
164     {
165       Arguments.checkNotNull("metadata", metadata);
166       this.metadata = metadata;
167       return this;
168     }
169 
170     // --- business -----------------------------------------------------------
171 
172     /**
173      * Creates the report item.
174      *
175      * @return the report item.
176      */
177     public PropertyReportSet build()
178     {
179       if (StringUtils.isBlank(type))
180       {
181         throw new BlankArgumentException("type",
182             "Building property set failed.");
183       }
184       return new PropertyReportSet(this);
185     }
186 
187     // --- object basics ------------------------------------------------------
188   }
189 
190   // ********************************* Methods ********************************
191 
192   // --- init -----------------------------------------------------------------
193 
194   // --- get&set --------------------------------------------------------------
195 
196   /**
197    * Returns the type that defines the report set, if no name is specified
198    * explicitly.
199    *
200    * @return the type that defines the report set, if no name is specified
201    *         explicitly.
202    */
203   public String getType()
204   {
205     return type;
206   }
207 
208   /**
209    * Returns the Javadoc comment to the descriptor.
210    *
211    * @return the Javadoc comment to the descriptor.
212    */
213   public String getComment()
214   {
215     return comment;
216   }
217 
218   /**
219    * Returns the document instance metadata.
220    *
221    * @return the document instance metadata.
222    */
223   public DocumentMetaData getMetaData()
224   {
225     return metadata;
226   }
227 
228   /**
229    * Returns the name that uniquely identifies the property set report.
230    *
231    * @return the name that uniquely identifies the property set report.
232    */
233   public String getName()
234   {
235     if (StringUtils.isNotBlank(name))
236     {
237       return name;
238     }
239 
240     final String metadataName = metadata.getName();
241     if (StringUtils.isNotBlank(metadataName))
242     {
243       return metadataName;
244     }
245 
246     return type;
247   }
248 
249   /**
250    * Returns the space the report item belongs to.
251    *
252    * @return the space the report item belongs to.
253    */
254   public String getSpace()
255   {
256     final String metadataSpace = metadata.getSpace();
257     if (StringUtils.isNotBlank(metadataSpace))
258     {
259       return metadataSpace;
260     }
261 
262     return "property-set:" + type;
263   }
264 
265   /**
266    * Returns the unique title of the report within the space.
267    *
268    * @return the unique title of the report within the space.
269    */
270   public String getTitle()
271   {
272     final String metadataTitle = metadata.getTitle();
273     if (StringUtils.isNotBlank(metadataTitle))
274     {
275       return metadataTitle;
276     }
277 
278     return type;
279   }
280 
281   // --- business -------------------------------------------------------------
282 
283   // --- object basics --------------------------------------------------------
284 
285 }