2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Intel. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.distribution.reception.parameters;
23 import java.util.List;
24 import java.util.UUID;
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ParameterGroup;
28 import org.onap.policy.common.parameters.ValidationStatus;
31 * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
32 * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
34 public class PSSDConfigurationParametersGroup implements ParameterGroup {
36 // Policy SDC Service Distribution specified field.
39 // Interface of IConfiguration item
40 private String asdcAddress;
41 private List<String> messageBusAddress;
43 private String password;
44 private int pollingInterval;
45 private int pollingTimeout;
46 private String consumerId;
47 private List<String> artifactTypes;
48 private String consumerGroup;
49 private String environmentName;
50 private String keystorePath;
51 private String keystorePassword;
52 private boolean activeserverTlsAuth;
53 private boolean isFilterinEmptyResources;
54 private Boolean isUseHttpsWithDmaap;
57 *Inner static class is to used as a Builder
60 public static class PSSDConfigurationBuilder {
61 private String asdcAddress;
62 private List<String> messageBusAddress;
64 private String password;
65 private int pollingInterval;
66 private int pollingTimeout;
67 private String consumerId;
68 private List<String> artifactTypes;
69 private String consumerGroup;
70 private String environmentName;
71 private String keystorePath;
72 private String keystorePassword;
73 private boolean activeserverTlsAuth;
74 private boolean isFilterinEmptyResources;
75 private Boolean isUseHttpsWithDmaap;
77 public PSSDConfigurationBuilder setAsdcAddress(String val) {
82 public PSSDConfigurationBuilder setMessageBusAddress(List<String> val) {
83 messageBusAddress = val;
87 public PSSDConfigurationBuilder setUser(String val) {
92 public PSSDConfigurationBuilder setPassword(String val) {
97 public PSSDConfigurationBuilder setPollingInterval(int val) {
98 pollingInterval = val;
102 public PSSDConfigurationBuilder setPollingTimeout(int val) {
103 pollingTimeout = val;
107 public PSSDConfigurationBuilder setConsumerId(String val) {
112 public PSSDConfigurationBuilder setArtifactTypes(List<String> val) {
117 public PSSDConfigurationBuilder setConsumerGroup(String val) {
122 public PSSDConfigurationBuilder setEnvironmentName(String val) {
123 environmentName = val;
127 public PSSDConfigurationBuilder setKeystorePath(String val) {
132 public PSSDConfigurationBuilder setKeystorePassword(String val) {
133 keystorePassword = val;
137 public PSSDConfigurationBuilder setActiveserverTlsAuth(boolean val) {
138 activeserverTlsAuth = val;
142 public PSSDConfigurationBuilder setIsFilterinEmptyResources(boolean val) {
143 isFilterinEmptyResources = val;
147 public PSSDConfigurationBuilder setIsUseHttpsWithDmaap(Boolean val) {
148 isUseHttpsWithDmaap = val;
153 * it is to create a new PSSDConfigurationParametersGroup instance.
155 public PSSDConfigurationParametersGroup build() {
156 return new PSSDConfigurationParametersGroup(this);
161 * The constructor for instantiating PSSDConfigurationParametersGroup it is a private
162 * so that it could ONLY be instantiated by PSSDConfigurationBuilder
164 * @param builder stores all the values used by PSSDConfigurationParametersGroup
166 private PSSDConfigurationParametersGroup(PSSDConfigurationBuilder builder) {
167 asdcAddress = builder.asdcAddress;
168 messageBusAddress = builder.messageBusAddress;
170 password = builder.password;
171 pollingInterval = builder.pollingInterval;
172 pollingTimeout = builder.pollingTimeout;
173 consumerId = builder.consumerId;
174 artifactTypes = builder.artifactTypes;
175 consumerGroup = builder.consumerGroup;
176 environmentName = builder.environmentName;
177 keystorePath = builder.keystorePath;
178 keystorePassword = builder.keystorePassword;
179 activeserverTlsAuth = builder.activeserverTlsAuth;
180 isFilterinEmptyResources = builder.isFilterinEmptyResources;
181 isUseHttpsWithDmaap = builder.isUseHttpsWithDmaap;
185 public String getAsdcAddress() {
189 public List<String> getMsgBusAddress() {
190 return messageBusAddress;
193 public String getUser() {
197 public String getPassword() {
201 public int getPollingInterval() {
202 return pollingInterval;
205 public int getPollingTimeout() {
206 return pollingTimeout;
209 public String getConsumerID() {
213 public List<String> getArtifactTypes() {
214 return artifactTypes;
217 public String getConsumerGroup() {
218 return consumerGroup;
221 public String getEnvironmentName() {
222 return environmentName;
225 public String getKeyStorePassword() {
226 return keystorePassword;
229 public String getKeyStorePath() {
233 public boolean activateServerTLSAuth() {
234 return activeserverTlsAuth;
237 public boolean isFilterInEmptyResources() {
238 return isFilterinEmptyResources;
241 public Boolean isUseHttpsWithDmaap() {
242 return isUseHttpsWithDmaap;
246 * Return a string representation of the object
248 * @return textually represents this object
251 public String toString() {
252 return "name =" + name + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = "
253 + messageBusAddress + ", user = " + user + "]";
257 * Return the name of this parameter group instance
259 * @return name the parameter group name
262 public String getName() {
267 * Validate all the int Elements
270 private void validateIntElement(final GroupValidationResult validationResult) {
271 if (pollingInterval <= 0) {
272 validationResult.setResult("pollingInterval", ValidationStatus.INVALID,
273 "pollingInterval must be a positive integer");
276 if (pollingTimeout <= 0) {
277 validationResult.setResult("pollingTimeout", ValidationStatus.INVALID,
278 "pollingTimeout must be a positive integer");
283 * Validate all the String List Elements
286 private void validateStringListElement(final GroupValidationResult validationResult) {
287 if (messageBusAddress == null) {
288 validationResult.setResult("messageBusAddress", ValidationStatus.INVALID,
289 "messageBusAddress must be a list of non-blank string");
291 for (final String temp : messageBusAddress) {
292 if (temp.trim().length() == 0) {
293 validationResult.setResult("messageBusAddress", ValidationStatus.INVALID,
294 "the string of messageBusAddress must be a non-blank string");
299 if (artifactTypes == null) {
300 validationResult.setResult("artifactTypes", ValidationStatus.INVALID,
301 "artifactTypes must be a list of non-blank string");
303 for (final String temp : artifactTypes) {
304 if (temp.trim().length() == 0) {
305 validationResult.setResult("artifactTypes", ValidationStatus.INVALID,
306 "the string of artifactTypes must be a non-blank string");
313 * Validate the parameter group
314 * @return the result of the validation
317 public GroupValidationResult validate() {
318 final GroupValidationResult validationResult = new GroupValidationResult(this);
320 if (asdcAddress == null || asdcAddress.trim().length() == 0) {
321 validationResult.setResult("asdcAddress", ValidationStatus.INVALID,
322 "asdcAddress must be a non-blank string");
325 if (user == null || user.trim().length() == 0) {
326 validationResult.setResult("user", ValidationStatus.INVALID, "user must be a non-blank string");
329 if (consumerId == null || consumerId.trim().length() == 0) {
330 validationResult.setResult("consumerId", ValidationStatus.INVALID, "consumerId must be a non-blank string");
333 if (consumerGroup == null || consumerGroup.trim().length() == 0) {
334 validationResult.setResult("consumerGroup", ValidationStatus.INVALID,
335 "consumerGroup must be a non-blank string");
338 if (keystorePath == null || keystorePath.trim().length() == 0) {
339 validationResult.setResult("keystorePath", ValidationStatus.INVALID,
340 "keystorePath must be a non-blank string");
343 if (keystorePassword == null || keystorePassword.trim().length() == 0) {
344 validationResult.setResult("keystorePassword", ValidationStatus.INVALID,
345 "keystorePassword must be a non-blank string");
348 validateIntElement(validationResult);
349 validateStringListElement(validationResult);
350 return validationResult;
354 * Set the name of this group.
356 * @param name the name to set.
358 public void setName(final String name) {
359 this.name = name + "_" + UUID.randomUUID().toString();