blob: 15f0900b595a2f110a64c81418f9d047582f8973 [file] [log] [blame]
Thomas Vachuska02aeb032015-01-06 22:36:30 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska02aeb032015-01-06 22:36:30 -08003 *
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.app;
17
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090018import org.onosproject.core.ApplicationRole;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080019import org.onosproject.core.Version;
Changhoon Yoonb856b812015-08-10 03:47:19 +090020import org.onosproject.security.Permission;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080021
22import java.net.URI;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080023import java.util.List;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080024import java.util.Optional;
25import java.util.Set;
26
27import static com.google.common.base.MoreObjects.toStringHelper;
28import static com.google.common.base.Preconditions.checkArgument;
29import static com.google.common.base.Preconditions.checkNotNull;
30
31/**
32 * Default implementation of network control/management application descriptor.
33 */
34public class DefaultApplicationDescription implements ApplicationDescription {
35
36 private final String name;
37 private final Version version;
Simon Huntafae2f72016-03-04 21:18:23 -080038 private final String title;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080039 private final String description;
40 private final String origin;
Jian Lic35415d2016-01-14 17:22:31 -080041 private final String category;
42 private final String url;
43 private final String readme;
44 private final byte[] icon;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090045 private final ApplicationRole role;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080046 private final Set<Permission> permissions;
47 private final Optional<URI> featuresRepo;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080048 private final List<String> features;
Thomas Vachuska761f0042015-11-11 19:10:17 -080049 private final List<String> requiredApps;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080050
51 /**
52 * Creates a new application descriptor using the supplied data.
53 *
54 * @param name application name
55 * @param version application version
Simon Huntafae2f72016-03-04 21:18:23 -080056 * @param title application title
Thomas Vachuska02aeb032015-01-06 22:36:30 -080057 * @param description application description
58 * @param origin origin company
Jian Lic35415d2016-01-14 17:22:31 -080059 * @param category application category
60 * @param url application URL
61 * @param readme application readme
62 * @param icon application icon
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090063 * @param role application role
Thomas Vachuska02aeb032015-01-06 22:36:30 -080064 * @param permissions requested permissions
65 * @param featuresRepo optional features repo URI
66 * @param features application features
Thomas Vachuska761f0042015-11-11 19:10:17 -080067 * @param requiredApps list of required application names
Thomas Vachuska02aeb032015-01-06 22:36:30 -080068 */
Simon Huntafae2f72016-03-04 21:18:23 -080069 public DefaultApplicationDescription(String name, Version version, String title,
Jian Lic35415d2016-01-14 17:22:31 -080070 String description, String origin, String category,
71 String url, String readme, byte[] icon,
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090072 ApplicationRole role, Set<Permission> permissions,
Thomas Vachuska761f0042015-11-11 19:10:17 -080073 URI featuresRepo, List<String> features,
74 List<String> requiredApps) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080075 this.name = checkNotNull(name, "Name cannot be null");
76 this.version = checkNotNull(version, "Version cannot be null");
Simon Huntafae2f72016-03-04 21:18:23 -080077 this.title = checkNotNull(title, "Title cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080078 this.description = checkNotNull(description, "Description cannot be null");
79 this.origin = checkNotNull(origin, "Origin cannot be null");
Jian Lic35415d2016-01-14 17:22:31 -080080 this.category = checkNotNull(category, "Category cannot be null");
Jian Li01b0f5952016-01-20 11:02:07 -080081 this.url = url;
Jian Li8bcb4f22016-01-20 10:36:18 -080082 this.readme = checkNotNull(readme, "Readme cannot be null");
Jian Lic35415d2016-01-14 17:22:31 -080083 this.icon = icon;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090084 this.role = checkNotNull(role, "Role cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080085 this.permissions = checkNotNull(permissions, "Permissions cannot be null");
86 this.featuresRepo = Optional.ofNullable(featuresRepo);
87 this.features = checkNotNull(features, "Features cannot be null");
Thomas Vachuska761f0042015-11-11 19:10:17 -080088 this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080089 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 Huntafae2f72016-03-04 21:18:23 -0800103 public String title() {
104 return title;
105 }
106
107 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800108 public String description() {
109 return description;
110 }
111
112 @Override
Jian Lic35415d2016-01-14 17:22:31 -0800113 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 Vachuska02aeb032015-01-06 22:36:30 -0800133 public String origin() {
134 return origin;
135 }
136
137 @Override
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900138 public ApplicationRole role() {
139 return role;
140 }
141
142 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800143 public Set<Permission> permissions() {
144 return permissions;
145 }
146
147 @Override
148 public Optional<URI> featuresRepo() {
149 return featuresRepo;
150 }
151
152 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -0800153 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800154 return features;
155 }
156
157 @Override
Thomas Vachuska761f0042015-11-11 19:10:17 -0800158 public List<String> requiredApps() {
159 return requiredApps;
160 }
161
162 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800163 public String toString() {
164 return toStringHelper(this)
165 .add("name", name)
166 .add("version", version)
167 .add("description", description)
Simon Huntafae2f72016-03-04 21:18:23 -0800168 .add("title", title)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800169 .add("origin", origin)
Jian Lic35415d2016-01-14 17:22:31 -0800170 .add("category", category)
171 .add("url", url)
172 .add("readme", readme)
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900173 .add("role", role)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800174 .add("permissions", permissions)
175 .add("featuresRepo", featuresRepo)
176 .add("features", features)
Thomas Vachuska761f0042015-11-11 19:10:17 -0800177 .add("requiredApps", requiredApps)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800178 .toString();
179 }
180}