blob: d8062ddf61588755f0a493defab367fc43021f55 [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 Vachuska02aeb032015-01-06 22:36:30 -080043
44 /**
45 * Creates a new application descriptor using the supplied data.
46 *
47 * @param appId application identifier
48 * @param version application version
49 * @param description application description
50 * @param origin origin company
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090051 * @param role application role
Thomas Vachuska02aeb032015-01-06 22:36:30 -080052 * @param permissions requested permissions
53 * @param featuresRepo optional features repo URI
54 * @param features application features
55 */
56 public DefaultApplication(ApplicationId appId, Version version,
57 String description, String origin,
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090058 ApplicationRole role, Set<Permission> permissions,
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080059 Optional<URI> featuresRepo, List<String> features) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080060 this.appId = checkNotNull(appId, "ID cannot be null");
61 this.version = checkNotNull(version, "Version cannot be null");
62 this.description = checkNotNull(description, "Description cannot be null");
63 this.origin = checkNotNull(origin, "Origin cannot be null");
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090064 this.role = checkNotNull(role, "Role cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080065 this.permissions = checkNotNull(permissions, "Permissions cannot be null");
66 this.featuresRepo = checkNotNull(featuresRepo, "Features repo cannot be null");
67 this.features = checkNotNull(features, "Features cannot be null");
68 checkArgument(!features.isEmpty(), "There must be at least one feature");
69 }
70
71 @Override
72 public ApplicationId id() {
73 return appId;
74 }
75
76 @Override
77 public Version version() {
78 return version;
79 }
80
81 @Override
82 public String description() {
83 return description;
84 }
85
86 @Override
87 public String origin() {
88 return origin;
89 }
90
91 @Override
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090092 public ApplicationRole role() {
93 return role;
94 }
95
96 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -080097 public Set<Permission> permissions() {
98 return permissions;
99 }
100
101 @Override
102 public Optional<URI> featuresRepo() {
103 return featuresRepo;
104 }
105
106 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -0800107 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800108 return features;
109 }
110
111 @Override
112 public int hashCode() {
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900113 return Objects.hash(appId, version, description, origin, role, permissions,
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800114 featuresRepo, features);
115 }
116
117 @Override
118 public boolean equals(Object obj) {
119 if (this == obj) {
120 return true;
121 }
122 if (obj == null || getClass() != obj.getClass()) {
123 return false;
124 }
125 final DefaultApplication other = (DefaultApplication) obj;
126 return Objects.equals(this.appId, other.appId) &&
127 Objects.equals(this.version, other.version) &&
128 Objects.equals(this.description, other.description) &&
129 Objects.equals(this.origin, other.origin) &&
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900130 Objects.equals(this.role, other.role) &&
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800131 Objects.equals(this.permissions, other.permissions) &&
132 Objects.equals(this.featuresRepo, other.featuresRepo) &&
133 Objects.equals(this.features, other.features);
134 }
135
136 @Override
137 public String toString() {
138 return toStringHelper(this)
139 .add("appId", appId)
140 .add("version", version)
141 .add("description", description)
142 .add("origin", origin)
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900143 .add("role", role)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800144 .add("permissions", permissions)
145 .add("featuresRepo", featuresRepo)
146 .add("features", features)
147 .toString();
148 }
149}