Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 18 | import org.onosproject.security.Permission; |
| 19 | |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 20 | import java.net.URI; |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 21 | import java.util.Set; |
| 22 | import java.util.Optional; |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 23 | import java.util.List; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 24 | import java.util.Objects; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 25 | |
| 26 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 27 | import static com.google.common.base.Preconditions.checkArgument; |
| 28 | import static com.google.common.base.Preconditions.checkNotNull; |
| 29 | |
| 30 | /** |
| 31 | * Default implementation of network control/management application descriptor. |
| 32 | */ |
| 33 | public class DefaultApplication implements Application { |
| 34 | |
| 35 | private final ApplicationId appId; |
| 36 | private final Version version; |
| 37 | private final String description; |
| 38 | private final String origin; |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 39 | private final ApplicationRole role; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 40 | private final Set<Permission> permissions; |
| 41 | private final Optional<URI> featuresRepo; |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 42 | private final List<String> features; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Creates a new application descriptor using the supplied data. |
| 46 | * |
| 47 | * @param appId application identifier |
| 48 | * @param version application version |
| 49 | * @param description application description |
| 50 | * @param origin origin company |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 51 | * @param role application role |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 52 | * @param permissions requested permissions |
| 53 | * @param featuresRepo optional features repo URI |
| 54 | * @param features application features |
| 55 | */ |
| 56 | public DefaultApplication(ApplicationId appId, Version version, |
| 57 | String description, String origin, |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 58 | ApplicationRole role, Set<Permission> permissions, |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 59 | Optional<URI> featuresRepo, List<String> features) { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 60 | this.appId = checkNotNull(appId, "ID cannot be null"); |
| 61 | this.version = checkNotNull(version, "Version cannot be null"); |
| 62 | this.description = checkNotNull(description, "Description cannot be null"); |
| 63 | this.origin = checkNotNull(origin, "Origin cannot be null"); |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 64 | this.role = checkNotNull(role, "Role cannot be null"); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 65 | this.permissions = checkNotNull(permissions, "Permissions cannot be null"); |
| 66 | this.featuresRepo = checkNotNull(featuresRepo, "Features repo cannot be null"); |
| 67 | this.features = checkNotNull(features, "Features cannot be null"); |
| 68 | checkArgument(!features.isEmpty(), "There must be at least one feature"); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public ApplicationId id() { |
| 73 | return appId; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public Version version() { |
| 78 | return version; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public String description() { |
| 83 | return description; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public String origin() { |
| 88 | return origin; |
| 89 | } |
| 90 | |
| 91 | @Override |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 92 | public ApplicationRole role() { |
| 93 | return role; |
| 94 | } |
| 95 | |
| 96 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 97 | public Set<Permission> permissions() { |
| 98 | return permissions; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public Optional<URI> featuresRepo() { |
| 103 | return featuresRepo; |
| 104 | } |
| 105 | |
| 106 | @Override |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 107 | public List<String> features() { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 108 | return features; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public int hashCode() { |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 113 | return Objects.hash(appId, version, description, origin, role, permissions, |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 114 | featuresRepo, features); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public boolean equals(Object obj) { |
| 119 | if (this == obj) { |
| 120 | return true; |
| 121 | } |
| 122 | if (obj == null || getClass() != obj.getClass()) { |
| 123 | return false; |
| 124 | } |
| 125 | final DefaultApplication other = (DefaultApplication) obj; |
| 126 | return Objects.equals(this.appId, other.appId) && |
| 127 | Objects.equals(this.version, other.version) && |
| 128 | Objects.equals(this.description, other.description) && |
| 129 | Objects.equals(this.origin, other.origin) && |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 130 | Objects.equals(this.role, other.role) && |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 131 | Objects.equals(this.permissions, other.permissions) && |
| 132 | Objects.equals(this.featuresRepo, other.featuresRepo) && |
| 133 | Objects.equals(this.features, other.features); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public String toString() { |
| 138 | return toStringHelper(this) |
| 139 | .add("appId", appId) |
| 140 | .add("version", version) |
| 141 | .add("description", description) |
| 142 | .add("origin", origin) |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 143 | .add("role", role) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 144 | .add("permissions", permissions) |
| 145 | .add("featuresRepo", featuresRepo) |
| 146 | .add("features", features) |
| 147 | .toString(); |
| 148 | } |
| 149 | } |