c204d75ff69aa4af94a210f26314fc20f11ea7f1
[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 String asdcAddress;
37     private List<String> messageBusAddress;
38     private String user;
39     private String password;
40     private int pollingInterval;
41     private int pollingTimeout;
42     private int retryDelay;
43     private int httpsProxyPort;
44     private int httpProxyPort;
45     private String httpsProxyHost;
46     private String httpProxyHost;
47     private String consumerId;
48     private List<String> artifactTypes;
49     private String consumerGroup;
50     private String environmentName;
51     private String keyStorePath;
52     private String keyStorePassword;
53     private boolean activeServerTlsAuth;
54     private boolean isFilterInEmptyResources;
55     private boolean isUseHttpsWithDmaap;
56     private boolean isUseHttpsWithSDC;
57
58     /**
59      * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup} class.
60      *
61      * @param builder the SDC configuration builder
62      */
63     public SdcReceptionHandlerConfigurationParameterGroup(
64             final SdcReceptionHandlerConfigurationParameterBuilder builder) {
65         asdcAddress = builder.getAsdcAddress();
66         messageBusAddress = builder.getMessageBusAddress();
67         user = builder.getUser();
68         password = builder.getPassword();
69         pollingInterval = builder.getPollingInterval();
70         pollingTimeout = builder.getPollingTimeout();
71         retryDelay = builder.getRetryDelay();
72         httpsProxyPort = builder.getHttpsProxyPort();
73         httpsProxyHost = builder.getHttpsProxyHost();
74         httpProxyPort = builder.getHttpProxyPort();
75         httpProxyHost = builder.getHttpProxyHost();
76         consumerId = builder.getConsumerId();
77         artifactTypes = builder.getArtifactTypes();
78         consumerGroup = builder.getConsumerGroup();
79         environmentName = builder.getEnvironmentName();
80         keyStorePath = builder.getKeystorePath();
81         keyStorePassword = builder.getKeystorePassword();
82         activeServerTlsAuth = builder.isActiveserverTlsAuth();
83         isFilterInEmptyResources = builder.isFilterinEmptyResources();
84         isUseHttpsWithDmaap = builder.getIsUseHttpsWithDmaap();
85         isUseHttpsWithSDC = builder.getIsUseHttpsWithSDC();
86
87     }
88
89     public String getAsdcAddress() {
90         return asdcAddress;
91     }
92
93     public List<String> getMessageBusAddress() {
94         return messageBusAddress;
95     }
96
97     public String getUser() {
98         return user;
99     }
100
101     public String getPassword() {
102         return password;
103     }
104
105     public int getPollingInterval() {
106         return pollingInterval;
107     }
108
109     public int getPollingTimeout() {
110         return pollingTimeout;
111     }
112
113     public int getRetryDelay() {
114         return retryDelay;
115     }
116
117     public String getConsumerId() {
118         return consumerId;
119     }
120
121     public List<String> getArtifactTypes() {
122         return artifactTypes;
123     }
124
125     public String getConsumerGroup() {
126         return consumerGroup;
127     }
128
129     public String getEnvironmentName() {
130         return environmentName;
131     }
132
133     public String getKeyStorePassword() {
134         return keyStorePassword;
135     }
136
137     public boolean isActiveServerTlsAuth() {
138         return activeServerTlsAuth;
139     }
140
141     public String getKeyStorePath() {
142         return keyStorePath;
143     }
144
145     public boolean isFilterInEmptyResources() {
146         return isFilterInEmptyResources;
147     }
148
149     public boolean isUseHttpsWithDmaap() {
150         return isUseHttpsWithDmaap;
151     }
152
153     public boolean isUseHttpsWithSDC() {
154         return isUseHttpsWithSDC;
155     }
156
157     public int getHttpsProxyPort() {
158         return httpsProxyPort;
159     }
160
161     public String getHttpsProxyHost() {
162         return httpsProxyHost;
163     }
164
165     public int getHttpProxyPort() {
166         return httpProxyPort;
167     }
168
169     public String getHttpProxyHost() {
170         return httpProxyHost;
171     }
172
173     /**
174      * {@inheritDoc}.
175      */
176     @Override
177     public GroupValidationResult validate() {
178         final GroupValidationResult validationResult = new GroupValidationResult(this);
179         validateStringElement(validationResult, asdcAddress, "asdcAddress");
180         validateStringElement(validationResult, user, "user");
181         validateStringElement(validationResult, consumerId, "consumerId");
182         validateStringElement(validationResult, consumerGroup, "consumerGroup");
183         validateStringElement(validationResult, keyStorePath, "keyStorePath");
184         validateStringElement(validationResult, keyStorePassword, "keyStorePassword");
185         validateIntElement(validationResult, pollingInterval, "pollingInterval");
186         validateIntElement(validationResult, pollingTimeout, "pollingTimeout");
187         validateIntElement(validationResult, retryDelay, "retryDelay");
188         validateStringListElement(validationResult, messageBusAddress, "messageBusAddress");
189         validateStringListElement(validationResult, artifactTypes, "artifactTypes");
190         return validationResult;
191     }
192
193     /**
194      * Validate the integer Element.
195      *
196      * @param validationResult the result object
197      * @param element the element to validate
198      * @param elementName the element name for error message
199      */
200     private void validateIntElement(final GroupValidationResult validationResult, final int element,
201             final String elementName) {
202         if (!ParameterValidationUtils.validateIntParameter(element)) {
203             validationResult.setResult(elementName, ValidationStatus.INVALID,
204                     elementName + " must be a positive integer");
205         }
206     }
207
208     /**
209      * Validate the String List Element.
210      *
211      * @param validationResult the result object
212      * @param element the element to validate
213      * @param elementName the element name for error message
214      */
215     private void validateStringListElement(final GroupValidationResult validationResult, final List<String> element,
216             final String elementName) {
217         for (final String temp : element) {
218             if (!ParameterValidationUtils.validateStringParameter(temp)) {
219                 validationResult.setResult(elementName, ValidationStatus.INVALID,
220                         "the string of " + elementName + "must be a non-blank string");
221             }
222         }
223     }
224
225     /**
226      * Validate the string element.
227      *
228      * @param validationResult the result object
229      * @param element the element to validate
230      * @param elementName the element name for error message
231      */
232     private void validateStringElement(final GroupValidationResult validationResult, final String element,
233             final String elementName) {
234         if (!ParameterValidationUtils.validateStringParameter(element)) {
235             validationResult.setResult(elementName, ValidationStatus.INVALID,
236                     elementName + " must be a non-blank string");
237         }
238     }
239 }
240