blob: ab72c6f556f80971208f570e0a333baf3ccf1ecf [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
18import java.net.URI;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090019import java.util.Set;
20import java.util.Optional;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080021import java.util.List;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080022import java.util.Objects;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080023
24import static com.google.common.base.MoreObjects.toStringHelper;
25import static com.google.common.base.Preconditions.checkArgument;
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Default implementation of network control/management application descriptor.
30 */
31public class DefaultApplication implements Application {
32
33 private final ApplicationId appId;
34 private final Version version;
35 private final String description;
36 private final String origin;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090037 private final ApplicationRole role;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080038 private final Set<Permission> permissions;
39 private final Optional<URI> featuresRepo;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080040 private final List<String> features;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080041
42 /**
43 * Creates a new application descriptor using the supplied data.
44 *
45 * @param appId application identifier
46 * @param version application version
47 * @param description application description
48 * @param origin origin company
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090049 * @param role application role
Thomas Vachuska02aeb032015-01-06 22:36:30 -080050 * @param permissions requested permissions
51 * @param featuresRepo optional features repo URI
52 * @param features application features
53 */
54 public DefaultApplication(ApplicationId appId, Version version,
55 String description, String origin,
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090056 ApplicationRole role, Set<Permission> permissions,
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080057 Optional<URI> featuresRepo, List<String> features) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080058 this.appId = checkNotNull(appId, "ID cannot be null");
59 this.version = checkNotNull(version, "Version cannot be null");
60 this.description = checkNotNull(description, "Description cannot be null");
61 this.origin = checkNotNull(origin, "Origin cannot be null");
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090062 this.role = checkNotNull(role, "Role cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080063 this.permissions = checkNotNull(permissions, "Permissions cannot be null");
64 this.featuresRepo = checkNotNull(featuresRepo, "Features repo cannot be null");
65 this.features = checkNotNull(features, "Features cannot be null");
66 checkArgument(!features.isEmpty(), "There must be at least one feature");
67 }
68
69 @Override
70 public ApplicationId id() {
71 return appId;
72 }
73
74 @Override
75 public Version version() {
76 return version;
77 }
78
79 @Override
80 public String description() {
81 return description;
82 }
83
84 @Override
85 public String origin() {
86 return origin;
87 }
88
89 @Override
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090090 public ApplicationRole role() {
91 return role;
92 }
93
94 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -080095 public Set<Permission> permissions() {
96 return permissions;
97 }
98
99 @Override
100 public Optional<URI> featuresRepo() {
101 return featuresRepo;
102 }
103
104 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -0800105 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800106 return features;
107 }
108
109 @Override
110 public int hashCode() {
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900111 return Objects.hash(appId, version, description, origin, role, permissions,
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800112 featuresRepo, features);
113 }
114
115 @Override
116 public boolean equals(Object obj) {
117 if (this == obj) {
118 return true;
119 }
120 if (obj == null || getClass() != obj.getClass()) {
121 return false;
122 }
123 final DefaultApplication other = (DefaultApplication) obj;
124 return Objects.equals(this.appId, other.appId) &&
125 Objects.equals(this.version, other.version) &&
126 Objects.equals(this.description, other.description) &&
127 Objects.equals(this.origin, other.origin) &&
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900128 Objects.equals(this.role, other.role) &&
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800129 Objects.equals(this.permissions, other.permissions) &&
130 Objects.equals(this.featuresRepo, other.featuresRepo) &&
131 Objects.equals(this.features, other.features);
132 }
133
134 @Override
135 public String toString() {
136 return toStringHelper(this)
137 .add("appId", appId)
138 .add("version", version)
139 .add("description", description)
140 .add("origin", origin)
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900141 .add("role", role)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800142 .add("permissions", permissions)
143 .add("featuresRepo", featuresRepo)
144 .add("features", features)
145 .toString();
146 }
147}