blob: 569183a7e9d6b000be30b1c3990e5dce8b4c82d8 [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;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090040 private final ApplicationRole role;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080041 private final Set<Permission> permissions;
42 private final Optional<URI> featuresRepo;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080043 private final List<String> features;
Thomas Vachuska761f0042015-11-11 19:10:17 -080044 private final List<String> requiredApps;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080045
46 /**
47 * Creates a new application descriptor using the supplied data.
48 *
49 * @param name application name
50 * @param version application version
51 * @param description application description
52 * @param origin origin company
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090053 * @param role application role
Thomas Vachuska02aeb032015-01-06 22:36:30 -080054 * @param permissions requested permissions
55 * @param featuresRepo optional features repo URI
56 * @param features application features
Thomas Vachuska761f0042015-11-11 19:10:17 -080057 * @param requiredApps list of required application names
Thomas Vachuska02aeb032015-01-06 22:36:30 -080058 */
59 public DefaultApplicationDescription(String name, Version version,
60 String description, String origin,
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090061 ApplicationRole role, Set<Permission> permissions,
Thomas Vachuska761f0042015-11-11 19:10:17 -080062 URI featuresRepo, List<String> features,
63 List<String> requiredApps) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080064 this.name = checkNotNull(name, "Name cannot be null");
65 this.version = checkNotNull(version, "Version cannot be null");
66 this.description = checkNotNull(description, "Description cannot be null");
67 this.origin = checkNotNull(origin, "Origin cannot be null");
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090068 this.role = checkNotNull(role, "Role cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080069 this.permissions = checkNotNull(permissions, "Permissions cannot be null");
70 this.featuresRepo = Optional.ofNullable(featuresRepo);
71 this.features = checkNotNull(features, "Features cannot be null");
Thomas Vachuska761f0042015-11-11 19:10:17 -080072 this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080073 checkArgument(!features.isEmpty(), "There must be at least one feature");
74 }
75
76 @Override
77 public String name() {
78 return name;
79 }
80
81 @Override
82 public Version version() {
83 return version;
84 }
85
86 @Override
87 public String description() {
88 return description;
89 }
90
91 @Override
92 public String origin() {
93 return origin;
94 }
95
96 @Override
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090097 public ApplicationRole role() {
98 return role;
99 }
100
101 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800102 public Set<Permission> permissions() {
103 return permissions;
104 }
105
106 @Override
107 public Optional<URI> featuresRepo() {
108 return featuresRepo;
109 }
110
111 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -0800112 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800113 return features;
114 }
115
116 @Override
Thomas Vachuska761f0042015-11-11 19:10:17 -0800117 public List<String> requiredApps() {
118 return requiredApps;
119 }
120
121 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800122 public String toString() {
123 return toStringHelper(this)
124 .add("name", name)
125 .add("version", version)
126 .add("description", description)
127 .add("origin", origin)
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900128 .add("role", role)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800129 .add("permissions", permissions)
130 .add("featuresRepo", featuresRepo)
131 .add("features", features)
Thomas Vachuska761f0042015-11-11 19:10:17 -0800132 .add("requiredApps", requiredApps)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800133 .toString();
134 }
135}