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.api.core.domain.ProjectdocMetaData; 22 import de.smartics.util.lang.Arg; 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} 86 * annotation. 87 */ 88 private String name; 89 90 /** 91 * The type that defines the report set, if no name is specified explicitly. 92 */ 93 private String type; 94 95 /** 96 * The Javadoc comment to the descriptor. 97 */ 98 private String comment; 99 100 /** 101 * The document instance metadata. 102 */ 103 private DocumentMetaData metadata = new ProjectdocMetaData(); 104 105 // ***************************** Initializer ****************************** 106 107 // ***************************** Constructors ***************************** 108 109 // ***************************** Inner Classes **************************** 110 111 // ******************************** Methods ******************************* 112 113 // --- init --------------------------------------------------------------- 114 115 // --- get&set ------------------------------------------------------------ 116 117 /** 118 * Sets the name of the property set as read from the 119 * {@link de.smartics.properties.api.core.annotations.PropertySet} 120 * annotation. 121 * 122 * @param name the name of the property set. 123 * @return a reference to the builder. 124 */ 125 public Builder withPropertySetName(final String name) 126 { 127 this.name = name; 128 return this; 129 } 130 131 /** 132 * Sets the type that defines the report set, if no name is specified 133 * explicitly. 134 * 135 * @param type the type that defines the report set, if no name is specified 136 * explicitly. 137 * @return a reference to the builder. 138 */ 139 public Builder withType(final String type) 140 { 141 this.type = type; 142 return this; 143 } 144 145 /** 146 * Sets the Javadoc comment to the descriptor. 147 * 148 * @param comment the Javadoc comment to the descriptor. 149 * @return a reference to the builder. 150 */ 151 public Builder withComment(final String comment) 152 { 153 this.comment = comment; 154 return this; 155 } 156 157 /** 158 * Set the document instance metadata. 159 * 160 * @param metadata the document instance metadata. 161 * @return a reference to the builder. 162 * @throws NullArgumentException if {@code metadata} is <code>null</code>. 163 */ 164 public Builder with(final DocumentMetaData metadata) 165 throws NullArgumentException 166 { 167 this.metadata = Arg.checkNotNull("metadata", metadata); 168 return this; 169 } 170 171 // --- business ----------------------------------------------------------- 172 173 /** 174 * Creates the report item. 175 * 176 * @return the report item. 177 */ 178 public PropertyReportSet build() 179 { 180 if (StringUtils.isBlank(type)) 181 { 182 throw new BlankArgumentException("type", 183 "Building property set failed."); 184 } 185 return new PropertyReportSet(this); 186 } 187 188 // --- object basics ------------------------------------------------------ 189 } 190 191 // ********************************* Methods ******************************** 192 193 // --- init ----------------------------------------------------------------- 194 195 // --- get&set -------------------------------------------------------------- 196 197 /** 198 * Returns the type that defines the report set, if no name is specified 199 * explicitly. 200 * 201 * @return the type that defines the report set, if no name is specified 202 * explicitly. 203 */ 204 public String getType() 205 { 206 return type; 207 } 208 209 /** 210 * Returns the Javadoc comment to the descriptor. 211 * 212 * @return the Javadoc comment to the descriptor. 213 */ 214 public String getComment() 215 { 216 return comment; 217 } 218 219 /** 220 * Returns the document instance metadata. 221 * 222 * @return the document instance metadata. 223 */ 224 public DocumentMetaData getMetaData() 225 { 226 return metadata; 227 } 228 229 /** 230 * Returns the name that uniquely identifies the property set report. 231 * 232 * @return the name that uniquely identifies the property set report. 233 */ 234 public String getName() 235 { 236 if (StringUtils.isNotBlank(name)) 237 { 238 return name; 239 } 240 241 final String metadataName = metadata.getName(); 242 if (StringUtils.isNotBlank(metadataName)) 243 { 244 return metadataName; 245 } 246 247 return type; 248 } 249 250 /** 251 * Returns the space the report item belongs to. 252 * 253 * @return the space the report item belongs to. 254 */ 255 public String getSpace() 256 { 257 final String metadataSpace = metadata.getSpace(); 258 if (StringUtils.isNotBlank(metadataSpace)) 259 { 260 return metadataSpace; 261 } 262 263 return "property-set:" + type; 264 } 265 266 /** 267 * Returns the unique title of the report within the space. 268 * 269 * @return the unique title of the report within the space. 270 */ 271 public String getTitle() 272 { 273 final String metadataTitle = metadata.getTitle(); 274 if (StringUtils.isNotBlank(metadataTitle)) 275 { 276 return metadataTitle; 277 } 278 279 return type; 280 } 281 282 // --- business ------------------------------------------------------------- 283 284 // --- object basics -------------------------------------------------------- 285 286 }