Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 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 org.onosproject.core; |
| 17 | |
Simon Hunt | c2da488 | 2016-01-21 13:24:47 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.ImmutableSet; |
Ray Milkey | 47c9541 | 2017-09-15 10:40:48 -0700 | [diff] [blame] | 20 | |
| 21 | import org.onosproject.app.ApplicationDescription; |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 22 | import org.onosproject.security.Permission; |
| 23 | |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 24 | import java.net.URI; |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 25 | import java.util.Set; |
| 26 | import java.util.Optional; |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 27 | import java.util.List; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 28 | import java.util.Objects; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 29 | |
| 30 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 31 | import static com.google.common.base.Preconditions.checkArgument; |
| 32 | import static com.google.common.base.Preconditions.checkNotNull; |
| 33 | |
| 34 | /** |
| 35 | * Default implementation of network control/management application descriptor. |
| 36 | */ |
Ray Milkey | 47c9541 | 2017-09-15 10:40:48 -0700 | [diff] [blame] | 37 | public final class DefaultApplication implements Application { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 38 | |
| 39 | private final ApplicationId appId; |
| 40 | private final Version version; |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 41 | private final String title; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 42 | private final String description; |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 43 | private final String category; |
| 44 | private final String url; |
| 45 | private final String readme; |
| 46 | private final byte[] icon; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 47 | private final String origin; |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 48 | private final ApplicationRole role; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 49 | private final Set<Permission> permissions; |
| 50 | private final Optional<URI> featuresRepo; |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 51 | private final List<String> features; |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 52 | private final List<String> requiredApps; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 53 | |
| 54 | /** |
Ray Milkey | 47c9541 | 2017-09-15 10:40:48 -0700 | [diff] [blame] | 55 | * Default constructor is hidden to prevent calls to new. |
| 56 | */ |
| 57 | private DefaultApplication() { |
Ray Milkey | 0c484a7 | 2017-09-27 17:25:45 -0700 | [diff] [blame] | 58 | appId = null; |
| 59 | version = null; |
| 60 | title = null; |
| 61 | description = null; |
| 62 | category = null; |
| 63 | url = null; |
| 64 | readme = null; |
| 65 | icon = null; |
| 66 | origin = null; |
| 67 | role = null; |
| 68 | permissions = null; |
| 69 | featuresRepo = Optional.empty(); |
| 70 | features = ImmutableList.of(); |
| 71 | requiredApps = ImmutableList.of(); |
Ray Milkey | 47c9541 | 2017-09-15 10:40:48 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /** |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 75 | * Creates a new application descriptor using the supplied data. |
| 76 | * |
| 77 | * @param appId application identifier |
| 78 | * @param version application version |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 79 | * @param title application title |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 80 | * @param description application description |
| 81 | * @param origin origin company |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 82 | * @param category application category |
| 83 | * @param url application URL |
| 84 | * @param readme application readme |
| 85 | * @param icon application icon |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 86 | * @param role application role |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 87 | * @param permissions requested permissions |
| 88 | * @param featuresRepo optional features repo URI |
| 89 | * @param features application features |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 90 | * @param requiredApps list of required application names |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 91 | */ |
Ray Milkey | 47c9541 | 2017-09-15 10:40:48 -0700 | [diff] [blame] | 92 | private DefaultApplication(ApplicationId appId, Version version, String title, |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 93 | String description, String origin, String category, |
| 94 | String url, String readme, byte[] icon, |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 95 | ApplicationRole role, Set<Permission> permissions, |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 96 | Optional<URI> featuresRepo, List<String> features, |
| 97 | List<String> requiredApps) { |
Ray Milkey | 47c9541 | 2017-09-15 10:40:48 -0700 | [diff] [blame] | 98 | this.appId = appId; |
| 99 | this.version = version; |
| 100 | this.title = title; |
| 101 | this.description = description; |
| 102 | this.origin = origin; |
| 103 | this.category = category; |
Jian Li | 01b0f595 | 2016-01-20 11:02:07 -0800 | [diff] [blame] | 104 | this.url = url; |
Ray Milkey | 47c9541 | 2017-09-15 10:40:48 -0700 | [diff] [blame] | 105 | this.readme = readme; |
Simon Hunt | c2da488 | 2016-01-21 13:24:47 -0800 | [diff] [blame] | 106 | this.icon = icon == null ? new byte[0] : icon.clone(); |
Ray Milkey | 47c9541 | 2017-09-15 10:40:48 -0700 | [diff] [blame] | 107 | this.role = role; |
| 108 | this.permissions = ImmutableSet.copyOf(permissions); |
| 109 | this.featuresRepo = featuresRepo; |
| 110 | this.features = ImmutableList.copyOf(features); |
| 111 | this.requiredApps = ImmutableList.copyOf(requiredApps); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public ApplicationId id() { |
| 116 | return appId; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public Version version() { |
| 121 | return version; |
| 122 | } |
| 123 | |
| 124 | @Override |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 125 | public String title() { |
| 126 | return title; |
| 127 | } |
| 128 | |
| 129 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 130 | public String description() { |
| 131 | return description; |
| 132 | } |
| 133 | |
| 134 | @Override |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 135 | public String category() { |
| 136 | return category; |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public String url() { |
| 141 | return url; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public String readme() { |
| 146 | return readme; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public byte[] icon() { |
Simon Hunt | c2da488 | 2016-01-21 13:24:47 -0800 | [diff] [blame] | 151 | return icon.clone(); |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 155 | public String origin() { |
| 156 | return origin; |
| 157 | } |
| 158 | |
| 159 | @Override |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 160 | public ApplicationRole role() { |
| 161 | return role; |
| 162 | } |
| 163 | |
| 164 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 165 | public Set<Permission> permissions() { |
| 166 | return permissions; |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public Optional<URI> featuresRepo() { |
| 171 | return featuresRepo; |
| 172 | } |
| 173 | |
| 174 | @Override |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 175 | public List<String> features() { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 176 | return features; |
| 177 | } |
| 178 | |
| 179 | @Override |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 180 | public List<String> requiredApps() { |
| 181 | return requiredApps; |
| 182 | } |
| 183 | |
| 184 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 185 | public int hashCode() { |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 186 | return Objects.hash(appId, version, title, description, origin, category, url, |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 187 | readme, role, permissions, featuresRepo, features, requiredApps); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public boolean equals(Object obj) { |
| 192 | if (this == obj) { |
| 193 | return true; |
| 194 | } |
| 195 | if (obj == null || getClass() != obj.getClass()) { |
| 196 | return false; |
| 197 | } |
| 198 | final DefaultApplication other = (DefaultApplication) obj; |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 199 | // TODO: review -- do ALL the fields need to be included? |
| 200 | // It is debatable whether fields like description, url, and readme, |
| 201 | // need to be included in the notion of equivalence. |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 202 | return Objects.equals(this.appId, other.appId) && |
| 203 | Objects.equals(this.version, other.version) && |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 204 | Objects.equals(this.title, other.title) && |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 205 | Objects.equals(this.description, other.description) && |
| 206 | Objects.equals(this.origin, other.origin) && |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 207 | Objects.equals(this.category, other.category) && |
| 208 | Objects.equals(this.url, other.url) && |
| 209 | Objects.equals(this.readme, other.readme) && |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 210 | Objects.equals(this.role, other.role) && |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 211 | Objects.equals(this.permissions, other.permissions) && |
| 212 | Objects.equals(this.featuresRepo, other.featuresRepo) && |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 213 | Objects.equals(this.features, other.features) && |
| 214 | Objects.equals(this.requiredApps, other.requiredApps); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public String toString() { |
| 219 | return toStringHelper(this) |
| 220 | .add("appId", appId) |
| 221 | .add("version", version) |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 222 | .add("title", title) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 223 | .add("description", description) |
| 224 | .add("origin", origin) |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 225 | .add("category", category) |
| 226 | .add("url", url) |
| 227 | .add("readme", readme) |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 228 | .add("role", role) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 229 | .add("permissions", permissions) |
| 230 | .add("featuresRepo", featuresRepo) |
| 231 | .add("features", features) |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 232 | .add("requiredApps", requiredApps) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 233 | .toString(); |
| 234 | } |
Ray Milkey | 47c9541 | 2017-09-15 10:40:48 -0700 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * Returns a default application builder. |
| 238 | * |
| 239 | * @return builder |
| 240 | */ |
| 241 | public static Builder builder() { |
| 242 | return new Builder(); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Creates a new builder as a copy of an existing builder. |
| 247 | * |
| 248 | * @param builder existing builder to copy |
| 249 | * @return new builder |
| 250 | */ |
| 251 | public static Builder builder(Builder builder) { |
| 252 | return new Builder(builder); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Creates a new builder as a copy of an existing application. |
| 257 | * |
| 258 | * @param application existing application to copy |
| 259 | * @return new builder |
| 260 | */ |
| 261 | public static Builder builder(Application application) { |
| 262 | return new Builder(application); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Creates a new builder as a copy of an existing application description. |
| 267 | * |
| 268 | * @param appDesc existing application description |
| 269 | * @return new builder |
| 270 | */ |
| 271 | public static Builder builder(ApplicationDescription appDesc) { |
| 272 | return new Builder(appDesc); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | /** |
| 277 | * Default application builder. |
| 278 | */ |
| 279 | public static final class Builder { |
| 280 | |
| 281 | private ApplicationId appId; |
| 282 | private Version version; |
| 283 | private String title; |
| 284 | private String description; |
| 285 | private String category; |
| 286 | private String url; |
| 287 | private String readme; |
| 288 | private byte[] icon; |
| 289 | private String origin; |
| 290 | private ApplicationRole role; |
| 291 | private Set<Permission> permissions; |
| 292 | private Optional<URI> featuresRepo; |
| 293 | private List<String> features; |
| 294 | private List<String> requiredApps; |
| 295 | |
| 296 | /** |
| 297 | * Default constructor for the builder. |
| 298 | */ |
| 299 | public Builder() {} |
| 300 | |
| 301 | /** |
| 302 | * Updates the builder to be a copy of an existing builder. |
| 303 | * |
| 304 | * @param builder existing builder to copy |
| 305 | */ |
| 306 | public Builder(Builder builder) { |
| 307 | this.appId = builder.appId; |
| 308 | this.version = builder.version; |
| 309 | this.title = builder.title; |
| 310 | this.description = builder.description; |
| 311 | this.category = builder.category; |
| 312 | this.url = builder.url; |
| 313 | this.readme = builder.readme; |
| 314 | this.icon = builder.icon; |
| 315 | this.origin = builder.origin; |
| 316 | this.role = builder.role; |
| 317 | this.permissions = builder.permissions; |
| 318 | this.featuresRepo = builder.featuresRepo; |
| 319 | this.features = builder.features; |
| 320 | this.requiredApps = builder.requiredApps; |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Updates the builder to be a copy of an existing application. |
| 325 | * |
| 326 | * @param application existing application to copy |
| 327 | */ |
| 328 | public Builder(Application application) { |
| 329 | this.appId = application.id(); |
| 330 | this.version = application.version(); |
| 331 | this.title = application.title(); |
| 332 | this.description = application.description(); |
| 333 | this.category = application.category(); |
| 334 | this.url = application.url(); |
| 335 | this.readme = application.readme(); |
| 336 | this.icon = application.icon(); |
| 337 | this.origin = application.origin(); |
| 338 | this.role = application.role(); |
| 339 | this.permissions = application.permissions(); |
| 340 | this.featuresRepo = application.featuresRepo(); |
| 341 | this.features = application.features(); |
| 342 | this.requiredApps = application.requiredApps(); |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Updates the builder to be a copy of an existing application description. |
| 347 | * |
| 348 | * @param appDesc existing application description |
| 349 | */ |
| 350 | public Builder(ApplicationDescription appDesc) { |
| 351 | this.version = appDesc.version(); |
| 352 | this.title = appDesc.title(); |
| 353 | this.description = appDesc.description(); |
| 354 | this.category = appDesc.category(); |
| 355 | this.url = appDesc.url(); |
| 356 | this.readme = appDesc.readme(); |
| 357 | this.icon = appDesc.icon(); |
| 358 | this.origin = appDesc.origin(); |
| 359 | this.role = appDesc.role(); |
| 360 | this.permissions = appDesc.permissions(); |
| 361 | this.featuresRepo = appDesc.featuresRepo(); |
| 362 | this.features = appDesc.features(); |
| 363 | this.requiredApps = appDesc.requiredApps(); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Adds an application id. |
| 368 | * |
| 369 | * @param appId application id |
| 370 | * @return builder |
| 371 | */ |
| 372 | public Builder withAppId(ApplicationId appId) { |
| 373 | this.appId = appId; |
| 374 | return this; |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Adds a version string. |
| 379 | * |
| 380 | * @param version version string |
| 381 | * @return builder |
| 382 | */ |
| 383 | public Builder withVersion(Version version) { |
| 384 | this.version = version; |
| 385 | return this; |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Adds a title string. |
| 390 | * |
| 391 | * @param title title string |
| 392 | * @return builder |
| 393 | */ |
| 394 | public Builder withTitle(String title) { |
| 395 | this.title = title; |
| 396 | return this; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Adds a description string. |
| 401 | * |
| 402 | * @param description description string |
| 403 | * @return builder |
| 404 | */ |
| 405 | public Builder withDescription(String description) { |
| 406 | this.description = description; |
| 407 | return this; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Adds a category string. |
| 412 | * |
| 413 | * @param category category string |
| 414 | * @return builder |
| 415 | */ |
| 416 | public Builder withCategory(String category) { |
| 417 | this.category = category; |
| 418 | return this; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Adds a URL string. |
| 423 | * |
| 424 | * @param url url string |
| 425 | * @return builder |
| 426 | */ |
| 427 | public Builder withUrl(String url) { |
| 428 | this.url = url; |
| 429 | return this; |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Adds a readme string. |
| 434 | * |
| 435 | * @param readme readme string |
| 436 | * @return builder |
| 437 | */ |
| 438 | public Builder withReadme(String readme) { |
| 439 | this.readme = readme; |
| 440 | return this; |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Adds an icon. |
| 445 | * |
| 446 | * @param icon icon data |
| 447 | * @return builder |
| 448 | */ |
| 449 | public Builder withIcon(byte[] icon) { |
| 450 | this.icon = icon; |
| 451 | return this; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Adds an origin string. |
| 456 | * |
| 457 | * @param origin origin string |
| 458 | * @return builder |
| 459 | */ |
| 460 | public Builder withOrigin(String origin) { |
| 461 | this.origin = origin; |
| 462 | return this; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Adds an application role. |
| 467 | * |
| 468 | * @param role application role |
| 469 | * @return builder |
| 470 | */ |
| 471 | public Builder withRole(ApplicationRole role) { |
| 472 | this.role = role; |
| 473 | return this; |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Adds a permissions set. |
| 478 | * |
| 479 | * @param permissions permissions set |
| 480 | * @return builder |
| 481 | */ |
| 482 | public Builder withPermissions(Set<Permission> permissions) { |
| 483 | this.permissions = permissions; |
| 484 | return this; |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * Adds a URI for a features repository. |
| 489 | * |
| 490 | * @param featuresRepo Optional URI for a features repository |
| 491 | * @return builder |
| 492 | */ |
| 493 | public Builder withFeaturesRepo(Optional<URI> featuresRepo) { |
| 494 | this.featuresRepo = featuresRepo; |
| 495 | return this; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Adds a features list. |
| 500 | * |
| 501 | * @param features features list |
| 502 | * @return builder |
| 503 | */ |
| 504 | public Builder withFeatures(List<String> features) { |
| 505 | this.features = features; |
| 506 | return this; |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Adds a list of required applications. |
| 511 | * |
| 512 | * @param requiredApps List of name strings of required applications |
| 513 | * @return builder |
| 514 | */ |
| 515 | public Builder withRequiredApps(List<String> requiredApps) { |
| 516 | this.requiredApps = requiredApps; |
| 517 | return this; |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * Builds a default application object from the gathered parameters. |
| 522 | * |
| 523 | * @return new default application |
| 524 | */ |
| 525 | public DefaultApplication build() { |
| 526 | checkNotNull(appId, "ID cannot be null"); |
| 527 | checkNotNull(version, "Version cannot be null"); |
| 528 | checkNotNull(title, "Title cannot be null"); |
| 529 | checkNotNull(description, "Description cannot be null"); |
| 530 | checkNotNull(origin, "Origin cannot be null"); |
| 531 | checkNotNull(category, "Category cannot be null"); |
| 532 | checkNotNull(readme, "Readme cannot be null"); |
| 533 | checkNotNull(role, "Role cannot be null"); |
| 534 | checkNotNull(permissions, "Permissions cannot be null"); |
| 535 | checkNotNull(featuresRepo, "Features repo cannot be null"); |
| 536 | checkNotNull(features, "Features cannot be null"); |
| 537 | checkNotNull(requiredApps, "Required apps cannot be null"); |
| 538 | checkArgument(!features.isEmpty(), "There must be at least one feature"); |
| 539 | |
| 540 | return new DefaultApplication(appId, version, title, |
| 541 | description, origin, category, |
| 542 | url, readme, icon, |
| 543 | role, permissions, |
| 544 | featuresRepo, features, |
| 545 | requiredApps); |
| 546 | } |
| 547 | } |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 548 | } |