update link to upper-constraints.txt
[multicloud/framework.git] / artifactbroker / plugins / reception-plugins / src / main / java / org / onap / policy / distribution / reception / handling / sdc / SdcReceptionHandlerConfigurationParameterGroup.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.distribution.reception.handling.sdc;
22
23 import java.util.List;
24
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;
29
30 /**
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.
33  */
34 public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
35
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;
55
56     /**
57      * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup} class.
58      *
59      * @param builder the SDC configuration builder
60      */
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();
82
83     }
84
85     public String getSdcAddress() {
86         return sdcAddress;
87     }
88
89     public String getUser() {
90         return user;
91     }
92
93     public String getPassword() {
94         return password;
95     }
96
97     public int getPollingInterval() {
98         return pollingInterval;
99     }
100
101     public int getPollingTimeout() {
102         return pollingTimeout;
103     }
104
105     public int getRetryDelay() {
106         return retryDelay;
107     }
108
109     public String getConsumerId() {
110         return consumerId;
111     }
112
113     public List<String> getArtifactTypes() {
114         return artifactTypes;
115     }
116
117     public String getConsumerGroup() {
118         return consumerGroup;
119     }
120
121     public String getEnvironmentName() {
122         return environmentName;
123     }
124
125     public String getKeyStorePassword() {
126         return keyStorePassword;
127     }
128
129     public boolean isActiveServerTlsAuth() {
130         return activeServerTlsAuth;
131     }
132
133     public String getKeyStorePath() {
134         return keyStorePath;
135     }
136
137     public boolean isFilterInEmptyResources() {
138         return isFilterInEmptyResources;
139     }
140
141     public boolean isUseHttpsWithSDC() {
142         return isUseHttpsWithSDC;
143     }
144
145     public int getHttpsProxyPort() {
146         return httpsProxyPort;
147     }
148
149     public String getHttpsProxyHost() {
150         return httpsProxyHost;
151     }
152
153     public int getHttpProxyPort() {
154         return httpProxyPort;
155     }
156
157     public String getHttpProxyHost() {
158         return httpProxyHost;
159     }
160
161     /**
162      * {@inheritDoc}.
163      */
164     @Override
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;
178     }
179
180     /**
181      * Validate the integer Element.
182      *
183      * @param validationResult the result object
184      * @param element the element to validate
185      * @param elementName the element name for error message
186      */
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");
192         }
193     }
194
195     /**
196      * Validate the String List Element.
197      *
198      * @param validationResult the result object
199      * @param element the element to validate
200      * @param elementName the element name for error message
201      */
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");
208             }
209         }
210     }
211
212     /**
213      * Validate the string element.
214      *
215      * @param validationResult the result object
216      * @param element the element to validate
217      * @param elementName the element name for error message
218      */
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");
224         }
225     }
226 }
227