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.handling.sdc;
23 import java.util.List;
25 import org.onap.policy.common.parameters.GroupValidationResult;
26 import org.onap.policy.common.parameters.ValidationStatus;
27 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
28 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
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 SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
36 private final String sdcAddress;
37 private final String user;
38 private final String password;
39 private final int pollingInterval;
40 private final int pollingTimeout;
41 private final int retryDelay;
42 private final int httpsProxyPort;
43 private final int httpProxyPort;
44 private final String httpsProxyHost;
45 private final String httpProxyHost;
46 private final String consumerId;
47 private final List<String> artifactTypes;
48 private final String consumerGroup;
49 private final String environmentName;
50 private final String keyStorePath;
51 private final String keyStorePassword;
52 private final boolean activeServerTlsAuth;
53 private final boolean isFilterInEmptyResources;
54 private final boolean isUseHttpsWithSDC;
57 * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup} class.
59 * @param builder the SDC configuration builder
61 public SdcReceptionHandlerConfigurationParameterGroup(
62 final SdcReceptionHandlerConfigurationParameterBuilder builder) {
63 sdcAddress = builder.getSdcAddress();
64 user = builder.getUser();
65 password = builder.getPassword();
66 pollingInterval = builder.getPollingInterval();
67 pollingTimeout = builder.getPollingTimeout();
68 retryDelay = builder.getRetryDelay();
69 httpsProxyPort = builder.getHttpsProxyPort();
70 httpsProxyHost = builder.getHttpsProxyHost();
71 httpProxyPort = builder.getHttpProxyPort();
72 httpProxyHost = builder.getHttpProxyHost();
73 consumerId = builder.getConsumerId();
74 artifactTypes = builder.getArtifactTypes();
75 consumerGroup = builder.getConsumerGroup();
76 environmentName = builder.getEnvironmentName();
77 keyStorePath = builder.getKeystorePath();
78 keyStorePassword = builder.getKeystorePassword();
79 activeServerTlsAuth = builder.isActiveserverTlsAuth();
80 isFilterInEmptyResources = builder.isFilterinEmptyResources();
81 isUseHttpsWithSDC = builder.getIsUseHttpsWithSDC();
85 public String getSdcAddress() {
89 public String getUser() {
93 public String getPassword() {
97 public int getPollingInterval() {
98 return pollingInterval;
101 public int getPollingTimeout() {
102 return pollingTimeout;
105 public int getRetryDelay() {
109 public String getConsumerId() {
113 public List<String> getArtifactTypes() {
114 return artifactTypes;
117 public String getConsumerGroup() {
118 return consumerGroup;
121 public String getEnvironmentName() {
122 return environmentName;
125 public String getKeyStorePassword() {
126 return keyStorePassword;
129 public boolean isActiveServerTlsAuth() {
130 return activeServerTlsAuth;
133 public String getKeyStorePath() {
137 public boolean isFilterInEmptyResources() {
138 return isFilterInEmptyResources;
141 public boolean isUseHttpsWithSDC() {
142 return isUseHttpsWithSDC;
145 public int getHttpsProxyPort() {
146 return httpsProxyPort;
149 public String getHttpsProxyHost() {
150 return httpsProxyHost;
153 public int getHttpProxyPort() {
154 return httpProxyPort;
157 public String getHttpProxyHost() {
158 return httpProxyHost;
165 public GroupValidationResult validate() {
166 final GroupValidationResult validationResult = new GroupValidationResult(this);
167 validateStringElement(validationResult, sdcAddress, "sdcAddress");
168 validateStringElement(validationResult, user, "user");
169 validateStringElement(validationResult, consumerId, "consumerId");
170 validateStringElement(validationResult, consumerGroup, "consumerGroup");
171 validateStringElement(validationResult, keyStorePath, "keyStorePath");
172 validateStringElement(validationResult, keyStorePassword, "keyStorePassword");
173 validateIntElement(validationResult, pollingInterval, "pollingInterval");
174 validateIntElement(validationResult, pollingTimeout, "pollingTimeout");
175 validateIntElement(validationResult, retryDelay, "retryDelay");
176 validateStringListElement(validationResult, artifactTypes, "artifactTypes");
177 return validationResult;
181 * Validate the integer Element.
183 * @param validationResult the result object
184 * @param element the element to validate
185 * @param elementName the element name for error message
187 private void validateIntElement(final GroupValidationResult validationResult, final int element,
188 final String elementName) {
189 if (!ParameterValidationUtils.validateIntParameter(element)) {
190 validationResult.setResult(elementName, ValidationStatus.INVALID,
191 elementName + " must be a positive integer");
196 * Validate the String List Element.
198 * @param validationResult the result object
199 * @param element the element to validate
200 * @param elementName the element name for error message
202 private void validateStringListElement(final GroupValidationResult validationResult, final List<String> element,
203 final String elementName) {
204 for (final String temp : element) {
205 if (!ParameterValidationUtils.validateStringParameter(temp)) {
206 validationResult.setResult(elementName, ValidationStatus.INVALID,
207 "the string of " + elementName + "must be a non-blank string");
213 * Validate the string element.
215 * @param validationResult the result object
216 * @param element the element to validate
217 * @param elementName the element name for error message
219 private void validateStringElement(final GroupValidationResult validationResult, final String element,
220 final String elementName) {
221 if (!ParameterValidationUtils.validateStringParameter(element)) {
222 validationResult.setResult(elementName, ValidationStatus.INVALID,
223 elementName + " must be a non-blank string");