blob: 3e520015c891a1b82212f831f19c2d05f2b4eb6e [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.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;
38 private final String description;
39 private final String origin;
Jian Lic35415d2016-01-14 17:22:31 -080040 private final String category;
41 private final String url;
42 private final String readme;
43 private final byte[] icon;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090044 private final ApplicationRole role;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080045 private final Set<Permission> permissions;
46 private final Optional<URI> featuresRepo;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080047 private final List<String> features;
Thomas Vachuska761f0042015-11-11 19:10:17 -080048 private final List<String> requiredApps;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080049
50 /**
51 * Creates a new application descriptor using the supplied data.
52 *
53 * @param name application name
54 * @param version application version
55 * @param description application description
56 * @param origin origin company
Jian Lic35415d2016-01-14 17:22:31 -080057 * @param category application category
58 * @param url application URL
59 * @param readme application readme
60 * @param icon application icon
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090061 * @param role application role
Thomas Vachuska02aeb032015-01-06 22:36:30 -080062 * @param permissions requested permissions
63 * @param featuresRepo optional features repo URI
64 * @param features application features
Thomas Vachuska761f0042015-11-11 19:10:17 -080065 * @param requiredApps list of required application names
Thomas Vachuska02aeb032015-01-06 22:36:30 -080066 */
67 public DefaultApplicationDescription(String name, Version version,
Jian Lic35415d2016-01-14 17:22:31 -080068 String description, String origin, String category,
69 String url, String readme, byte[] icon,
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090070 ApplicationRole role, Set<Permission> permissions,
Thomas Vachuska761f0042015-11-11 19:10:17 -080071 URI featuresRepo, List<String> features,
72 List<String> requiredApps) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080073 this.name = checkNotNull(name, "Name cannot be null");
74 this.version = checkNotNull(version, "Version cannot be null");
75 this.description = checkNotNull(description, "Description cannot be null");
76 this.origin = checkNotNull(origin, "Origin cannot be null");
Jian Lic35415d2016-01-14 17:22:31 -080077 this.category = checkNotNull(category, "Category cannot be null");
78 this.url = checkNotNull(url, "URL cannot be null");
79 this.readme = readme;
80 this.icon = icon;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090081 this.role = checkNotNull(role, "Role cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080082 this.permissions = checkNotNull(permissions, "Permissions cannot be null");
83 this.featuresRepo = Optional.ofNullable(featuresRepo);
84 this.features = checkNotNull(features, "Features cannot be null");
Thomas Vachuska761f0042015-11-11 19:10:17 -080085 this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080086 checkArgument(!features.isEmpty(), "There must be at least one feature");
87 }
88
89 @Override
90 public String name() {
91 return name;
92 }
93
94 @Override
95 public Version version() {
96 return version;
97 }
98
99 @Override
100 public String description() {
101 return description;
102 }
103
104 @Override
Jian Lic35415d2016-01-14 17:22:31 -0800105 public String category() {
106 return category;
107 }
108
109 @Override
110 public String url() {
111 return url;
112 }
113
114 @Override
115 public String readme() {
116 return readme;
117 }
118
119 @Override
120 public byte[] icon() {
121 return icon;
122 }
123
124 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800125 public String origin() {
126 return origin;
127 }
128
129 @Override
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900130 public ApplicationRole role() {
131 return role;
132 }
133
134 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800135 public Set<Permission> permissions() {
136 return permissions;
137 }
138
139 @Override
140 public Optional<URI> featuresRepo() {
141 return featuresRepo;
142 }
143
144 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -0800145 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800146 return features;
147 }
148
149 @Override
Thomas Vachuska761f0042015-11-11 19:10:17 -0800150 public List<String> requiredApps() {
151 return requiredApps;
152 }
153
154 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800155 public String toString() {
156 return toStringHelper(this)
157 .add("name", name)
158 .add("version", version)
159 .add("description", description)
160 .add("origin", origin)
Jian Lic35415d2016-01-14 17:22:31 -0800161 .add("category", category)
162 .add("url", url)
163 .add("readme", readme)
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900164 .add("role", role)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800165 .add("permissions", permissions)
166 .add("featuresRepo", featuresRepo)
167 .add("features", features)
Thomas Vachuska761f0042015-11-11 19:10:17 -0800168 .add("requiredApps", requiredApps)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800169 .toString();
170 }
171}