Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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.app; |
| 17 | |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 18 | import org.onosproject.core.ApplicationRole; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 19 | import org.onosproject.core.Version; |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 20 | import org.onosproject.security.Permission; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 21 | |
| 22 | import java.net.URI; |
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.Optional; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 28 | import static com.google.common.base.Preconditions.checkArgument; |
| 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| 30 | |
| 31 | /** |
| 32 | * Default implementation of network control/management application descriptor. |
| 33 | */ |
| 34 | public class DefaultApplicationDescription implements ApplicationDescription { |
| 35 | |
| 36 | private final String name; |
| 37 | private final Version version; |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 38 | private final String title; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 39 | private final String description; |
| 40 | private final String origin; |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 41 | private final String category; |
| 42 | private final String url; |
| 43 | private final String readme; |
| 44 | private final byte[] icon; |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 45 | private final ApplicationRole role; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 46 | private final Set<Permission> permissions; |
| 47 | private final Optional<URI> featuresRepo; |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 48 | private final List<String> features; |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 49 | private final List<String> requiredApps; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Creates a new application descriptor using the supplied data. |
| 53 | * |
| 54 | * @param name application name |
| 55 | * @param version application version |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 56 | * @param title application title |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 57 | * @param description application description |
| 58 | * @param origin origin company |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 59 | * @param category application category |
| 60 | * @param url application URL |
| 61 | * @param readme application readme |
| 62 | * @param icon application icon |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 63 | * @param role application role |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 64 | * @param permissions requested permissions |
| 65 | * @param featuresRepo optional features repo URI |
| 66 | * @param features application features |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 67 | * @param requiredApps list of required application names |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 68 | */ |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 69 | public DefaultApplicationDescription(String name, Version version, String title, |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 70 | String description, String origin, String category, |
| 71 | String url, String readme, byte[] icon, |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 72 | ApplicationRole role, Set<Permission> permissions, |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 73 | URI featuresRepo, List<String> features, |
| 74 | List<String> requiredApps) { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 75 | this.name = checkNotNull(name, "Name cannot be null"); |
| 76 | this.version = checkNotNull(version, "Version cannot be null"); |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 77 | this.title = checkNotNull(title, "Title cannot be null"); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 78 | this.description = checkNotNull(description, "Description cannot be null"); |
| 79 | this.origin = checkNotNull(origin, "Origin cannot be null"); |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 80 | this.category = checkNotNull(category, "Category cannot be null"); |
Jian Li | 01b0f595 | 2016-01-20 11:02:07 -0800 | [diff] [blame] | 81 | this.url = url; |
Jian Li | 8bcb4f2 | 2016-01-20 10:36:18 -0800 | [diff] [blame] | 82 | this.readme = checkNotNull(readme, "Readme cannot be null"); |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 83 | this.icon = icon; |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 84 | this.role = checkNotNull(role, "Role cannot be null"); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 85 | this.permissions = checkNotNull(permissions, "Permissions cannot be null"); |
| 86 | this.featuresRepo = Optional.ofNullable(featuresRepo); |
| 87 | this.features = checkNotNull(features, "Features cannot be null"); |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 88 | this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null"); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 89 | checkArgument(!features.isEmpty(), "There must be at least one feature"); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public String name() { |
| 94 | return name; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public Version version() { |
| 99 | return version; |
| 100 | } |
| 101 | |
| 102 | @Override |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 103 | public String title() { |
| 104 | return title; |
| 105 | } |
| 106 | |
| 107 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 108 | public String description() { |
| 109 | return description; |
| 110 | } |
| 111 | |
| 112 | @Override |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 113 | public String category() { |
| 114 | return category; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public String url() { |
| 119 | return url; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public String readme() { |
| 124 | return readme; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public byte[] icon() { |
| 129 | return icon; |
| 130 | } |
| 131 | |
| 132 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 133 | public String origin() { |
| 134 | return origin; |
| 135 | } |
| 136 | |
| 137 | @Override |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 138 | public ApplicationRole role() { |
| 139 | return role; |
| 140 | } |
| 141 | |
| 142 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 143 | public Set<Permission> permissions() { |
| 144 | return permissions; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public Optional<URI> featuresRepo() { |
| 149 | return featuresRepo; |
| 150 | } |
| 151 | |
| 152 | @Override |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 153 | public List<String> features() { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 154 | return features; |
| 155 | } |
| 156 | |
| 157 | @Override |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 158 | public List<String> requiredApps() { |
| 159 | return requiredApps; |
| 160 | } |
| 161 | |
| 162 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 163 | public String toString() { |
| 164 | return toStringHelper(this) |
| 165 | .add("name", name) |
| 166 | .add("version", version) |
| 167 | .add("description", description) |
Simon Hunt | afae2f7 | 2016-03-04 21:18:23 -0800 | [diff] [blame] | 168 | .add("title", title) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 169 | .add("origin", origin) |
Jian Li | c35415d | 2016-01-14 17:22:31 -0800 | [diff] [blame] | 170 | .add("category", category) |
| 171 | .add("url", url) |
| 172 | .add("readme", readme) |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 173 | .add("role", role) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 174 | .add("permissions", permissions) |
| 175 | .add("featuresRepo", featuresRepo) |
| 176 | .add("features", features) |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 177 | .add("requiredApps", requiredApps) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 178 | .toString(); |
| 179 | } |
| 180 | } |