blob: 5ce5ee714e537e2054dfaafdada10877893bb032 [file] [log] [blame]
Thomas Vachuska02aeb032015-01-06 22:36:30 -08001/*
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 */
16package org.onosproject.core;
17
Changhoon Yoonb856b812015-08-10 03:47:19 +090018import org.onosproject.security.Permission;
19
Thomas Vachuska02aeb032015-01-06 22:36:30 -080020import java.net.URI;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090021import java.util.Set;
22import java.util.Optional;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080023import java.util.List;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080024import java.util.Objects;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080025
26import static com.google.common.base.MoreObjects.toStringHelper;
27import static com.google.common.base.Preconditions.checkArgument;
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * Default implementation of network control/management application descriptor.
32 */
33public class DefaultApplication implements Application {
34
35 private final ApplicationId appId;
36 private final Version version;
37 private final String description;
Jian Lic35415d2016-01-14 17:22:31 -080038 private final String category;
39 private final String url;
40 private final String readme;
41 private final byte[] icon;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080042 private final String origin;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090043 private final ApplicationRole role;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080044 private final Set<Permission> permissions;
45 private final Optional<URI> featuresRepo;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080046 private final List<String> features;
Thomas Vachuska761f0042015-11-11 19:10:17 -080047 private final List<String> requiredApps;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080048
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 Lic35415d2016-01-14 17:22:31 -080056 * @param category application category
57 * @param url application URL
58 * @param readme application readme
59 * @param icon application icon
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090060 * @param role application role
Thomas Vachuska02aeb032015-01-06 22:36:30 -080061 * @param permissions requested permissions
62 * @param featuresRepo optional features repo URI
63 * @param features application features
Thomas Vachuska761f0042015-11-11 19:10:17 -080064 * @param requiredApps list of required application names
Thomas Vachuska02aeb032015-01-06 22:36:30 -080065 */
66 public DefaultApplication(ApplicationId appId, Version version,
Jian Lic35415d2016-01-14 17:22:31 -080067 String description, String origin, String category,
68 String url, String readme, byte[] icon,
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090069 ApplicationRole role, Set<Permission> permissions,
Thomas Vachuska761f0042015-11-11 19:10:17 -080070 Optional<URI> featuresRepo, List<String> features,
71 List<String> requiredApps) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080072 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 Lic35415d2016-01-14 17:22:31 -080076 this.category = checkNotNull(category, "Category cannot be null");
Jian Li01b0f5952016-01-20 11:02:07 -080077 this.url = url;
Jian Li8bcb4f22016-01-20 10:36:18 -080078 this.readme = checkNotNull(readme, "Readme cannot be null");
Jian Lic35415d2016-01-14 17:22:31 -080079 this.icon = icon;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090080 this.role = checkNotNull(role, "Role cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080081 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 Vachuska761f0042015-11-11 19:10:17 -080084 this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080085 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 Lic35415d2016-01-14 17:22:31 -0800104 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 Vachuska02aeb032015-01-06 22:36:30 -0800124 public String origin() {
125 return origin;
126 }
127
128 @Override
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900129 public ApplicationRole role() {
130 return role;
131 }
132
133 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800134 public Set<Permission> permissions() {
135 return permissions;
136 }
137
138 @Override
139 public Optional<URI> featuresRepo() {
140 return featuresRepo;
141 }
142
143 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -0800144 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800145 return features;
146 }
147
148 @Override
Thomas Vachuska761f0042015-11-11 19:10:17 -0800149 public List<String> requiredApps() {
150 return requiredApps;
151 }
152
153 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800154 public int hashCode() {
Jian Lic35415d2016-01-14 17:22:31 -0800155 return Objects.hash(appId, version, description, origin, category, url,
156 readme, role, permissions, featuresRepo, features, requiredApps);
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800157 }
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 Lic35415d2016-01-14 17:22:31 -0800172 Objects.equals(this.category, other.category) &&
173 Objects.equals(this.url, other.url) &&
174 Objects.equals(this.readme, other.readme) &&
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900175 Objects.equals(this.role, other.role) &&
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800176 Objects.equals(this.permissions, other.permissions) &&
177 Objects.equals(this.featuresRepo, other.featuresRepo) &&
Thomas Vachuska761f0042015-11-11 19:10:17 -0800178 Objects.equals(this.features, other.features) &&
179 Objects.equals(this.requiredApps, other.requiredApps);
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800180 }
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 Lic35415d2016-01-14 17:22:31 -0800189 .add("category", category)
190 .add("url", url)
191 .add("readme", readme)
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900192 .add("role", role)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800193 .add("permissions", permissions)
194 .add("featuresRepo", featuresRepo)
195 .add("features", features)
Thomas Vachuska761f0042015-11-11 19:10:17 -0800196 .add("requiredApps", requiredApps)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800197 .toString();
198 }
199}