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; |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 38 | private final String category; |
| 39 | private final String url; |
| 40 | private final String readme; |
| 41 | private final byte[] icon; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 42 | private final String origin; |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 43 | private final ApplicationRole role; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 44 | private final Set<Permission> permissions; |
| 45 | private final Optional<URI> featuresRepo; |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 46 | private final List<String> features; |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 47 | private final List<String> requiredApps; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Creates a new application descriptor using the supplied data. |
| 51 | * |
| 52 | * @param appId application identifier |
| 53 | * @param version application version |
| 54 | * @param description application description |
| 55 | * @param origin origin company |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 56 | * @param category application category |
| 57 | * @param url application URL |
| 58 | * @param readme application readme |
| 59 | * @param icon application icon |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 60 | * @param role application role |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 61 | * @param permissions requested permissions |
| 62 | * @param featuresRepo optional features repo URI |
| 63 | * @param features application features |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 64 | * @param requiredApps list of required application names |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 65 | */ |
| 66 | public DefaultApplication(ApplicationId appId, Version version, |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 67 | String description, String origin, String category, |
| 68 | String url, String readme, byte[] icon, |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 69 | ApplicationRole role, Set<Permission> permissions, |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 70 | Optional<URI> featuresRepo, List<String> features, |
| 71 | List<String> requiredApps) { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 72 | this.appId = checkNotNull(appId, "ID cannot be null"); |
| 73 | this.version = checkNotNull(version, "Version cannot be null"); |
| 74 | this.description = checkNotNull(description, "Description cannot be null"); |
| 75 | this.origin = checkNotNull(origin, "Origin cannot be null"); |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 76 | this.category = checkNotNull(category, "Category cannot be null"); |
Jian Li | 01b0f595 | 2016-01-20 11:02:07 -0800 | [diff] [blame^] | 77 | this.url = url; |
Jian Li | 8bcb4f2 | 2016-01-20 10:36:18 -0800 | [diff] [blame] | 78 | this.readme = checkNotNull(readme, "Readme cannot be null"); |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 79 | this.icon = icon; |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 80 | this.role = checkNotNull(role, "Role cannot be null"); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 81 | this.permissions = checkNotNull(permissions, "Permissions cannot be null"); |
| 82 | this.featuresRepo = checkNotNull(featuresRepo, "Features repo cannot be null"); |
| 83 | this.features = checkNotNull(features, "Features cannot be null"); |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 84 | this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null"); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 85 | checkArgument(!features.isEmpty(), "There must be at least one feature"); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public ApplicationId id() { |
| 90 | return appId; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public Version version() { |
| 95 | return version; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String description() { |
| 100 | return description; |
| 101 | } |
| 102 | |
| 103 | @Override |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 104 | public String category() { |
| 105 | return category; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public String url() { |
| 110 | return url; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public String readme() { |
| 115 | return readme; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public byte[] icon() { |
| 120 | return icon; |
| 121 | } |
| 122 | |
| 123 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 124 | public String origin() { |
| 125 | return origin; |
| 126 | } |
| 127 | |
| 128 | @Override |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 129 | public ApplicationRole role() { |
| 130 | return role; |
| 131 | } |
| 132 | |
| 133 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 134 | public Set<Permission> permissions() { |
| 135 | return permissions; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public Optional<URI> featuresRepo() { |
| 140 | return featuresRepo; |
| 141 | } |
| 142 | |
| 143 | @Override |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 144 | public List<String> features() { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 145 | return features; |
| 146 | } |
| 147 | |
| 148 | @Override |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 149 | public List<String> requiredApps() { |
| 150 | return requiredApps; |
| 151 | } |
| 152 | |
| 153 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 154 | public int hashCode() { |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 155 | return Objects.hash(appId, version, description, origin, category, url, |
| 156 | readme, role, permissions, featuresRepo, features, requiredApps); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public boolean equals(Object obj) { |
| 161 | if (this == obj) { |
| 162 | return true; |
| 163 | } |
| 164 | if (obj == null || getClass() != obj.getClass()) { |
| 165 | return false; |
| 166 | } |
| 167 | final DefaultApplication other = (DefaultApplication) obj; |
| 168 | return Objects.equals(this.appId, other.appId) && |
| 169 | Objects.equals(this.version, other.version) && |
| 170 | Objects.equals(this.description, other.description) && |
| 171 | Objects.equals(this.origin, other.origin) && |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 172 | Objects.equals(this.category, other.category) && |
| 173 | Objects.equals(this.url, other.url) && |
| 174 | Objects.equals(this.readme, other.readme) && |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 175 | Objects.equals(this.role, other.role) && |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 176 | Objects.equals(this.permissions, other.permissions) && |
| 177 | Objects.equals(this.featuresRepo, other.featuresRepo) && |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 178 | Objects.equals(this.features, other.features) && |
| 179 | Objects.equals(this.requiredApps, other.requiredApps); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public String toString() { |
| 184 | return toStringHelper(this) |
| 185 | .add("appId", appId) |
| 186 | .add("version", version) |
| 187 | .add("description", description) |
| 188 | .add("origin", origin) |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 189 | .add("category", category) |
| 190 | .add("url", url) |
| 191 | .add("readme", readme) |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 192 | .add("role", role) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 193 | .add("permissions", permissions) |
| 194 | .add("featuresRepo", featuresRepo) |
| 195 | .add("features", features) |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 196 | .add("requiredApps", requiredApps) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 197 | .toString(); |
| 198 | } |
| 199 | } |