blob: c3515638df431a00d9a5055f20a175c98ebe79fa [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;
38 private final String origin;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090039 private final ApplicationRole role;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080040 private final Set<Permission> permissions;
41 private final Optional<URI> featuresRepo;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080042 private final List<String> features;
Thomas Vachuska761f0042015-11-11 19:10:17 -080043 private final List<String> requiredApps;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080044
45 /**
46 * Creates a new application descriptor using the supplied data.
47 *
48 * @param appId application identifier
49 * @param version application version
50 * @param description application description
51 * @param origin origin company
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090052 * @param role application role
Thomas Vachuska02aeb032015-01-06 22:36:30 -080053 * @param permissions requested permissions
54 * @param featuresRepo optional features repo URI
55 * @param features application features
Thomas Vachuska761f0042015-11-11 19:10:17 -080056 * @param requiredApps list of required application names
Thomas Vachuska02aeb032015-01-06 22:36:30 -080057 */
58 public DefaultApplication(ApplicationId appId, Version version,
59 String description, String origin,
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090060 ApplicationRole role, Set<Permission> permissions,
Thomas Vachuska761f0042015-11-11 19:10:17 -080061 Optional<URI> featuresRepo, List<String> features,
62 List<String> requiredApps) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080063 this.appId = checkNotNull(appId, "ID cannot be null");
64 this.version = checkNotNull(version, "Version cannot be null");
65 this.description = checkNotNull(description, "Description cannot be null");
66 this.origin = checkNotNull(origin, "Origin cannot be null");
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090067 this.role = checkNotNull(role, "Role cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080068 this.permissions = checkNotNull(permissions, "Permissions cannot be null");
69 this.featuresRepo = checkNotNull(featuresRepo, "Features repo cannot be null");
70 this.features = checkNotNull(features, "Features cannot be null");
Thomas Vachuska761f0042015-11-11 19:10:17 -080071 this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080072 checkArgument(!features.isEmpty(), "There must be at least one feature");
73 }
74
75 @Override
76 public ApplicationId id() {
77 return appId;
78 }
79
80 @Override
81 public Version version() {
82 return version;
83 }
84
85 @Override
86 public String description() {
87 return description;
88 }
89
90 @Override
91 public String origin() {
92 return origin;
93 }
94
95 @Override
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090096 public ApplicationRole role() {
97 return role;
98 }
99
100 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800101 public Set<Permission> permissions() {
102 return permissions;
103 }
104
105 @Override
106 public Optional<URI> featuresRepo() {
107 return featuresRepo;
108 }
109
110 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -0800111 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800112 return features;
113 }
114
115 @Override
Thomas Vachuska761f0042015-11-11 19:10:17 -0800116 public List<String> requiredApps() {
117 return requiredApps;
118 }
119
120 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800121 public int hashCode() {
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900122 return Objects.hash(appId, version, description, origin, role, permissions,
Thomas Vachuska761f0042015-11-11 19:10:17 -0800123 featuresRepo, features, requiredApps);
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800124 }
125
126 @Override
127 public boolean equals(Object obj) {
128 if (this == obj) {
129 return true;
130 }
131 if (obj == null || getClass() != obj.getClass()) {
132 return false;
133 }
134 final DefaultApplication other = (DefaultApplication) obj;
135 return Objects.equals(this.appId, other.appId) &&
136 Objects.equals(this.version, other.version) &&
137 Objects.equals(this.description, other.description) &&
138 Objects.equals(this.origin, other.origin) &&
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900139 Objects.equals(this.role, other.role) &&
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800140 Objects.equals(this.permissions, other.permissions) &&
141 Objects.equals(this.featuresRepo, other.featuresRepo) &&
Thomas Vachuska761f0042015-11-11 19:10:17 -0800142 Objects.equals(this.features, other.features) &&
143 Objects.equals(this.requiredApps, other.requiredApps);
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800144 }
145
146 @Override
147 public String toString() {
148 return toStringHelper(this)
149 .add("appId", appId)
150 .add("version", version)
151 .add("description", description)
152 .add("origin", origin)
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900153 .add("role", role)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800154 .add("permissions", permissions)
155 .add("featuresRepo", featuresRepo)
156 .add("features", features)
Thomas Vachuska761f0042015-11-11 19:10:17 -0800157 .add("requiredApps", requiredApps)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800158 .toString();
159 }
160}