0140fb532c01d1392401827e001d9fe5b349a4d4
[policy/distribution.git] /
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 import org.onap.policy.common.parameters.GroupValidationResult;
25 import org.onap.policy.common.parameters.ValidationStatus;
26 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
27 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
28
29 /**
30  * This class handles reading, parsing and validating of the Policy SDC Service Distribution
31  * parameters from Json format, which strictly adheres to the interface:IConfiguration, defined by
32  * 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 String consumerId;
43     private List<String> artifactTypes;
44     private String consumerGroup;
45     private String environmentName;
46     private String keyStorePath;
47     private String keyStorePassword;
48     private boolean activeServerTlsAuth;
49     private boolean isFilterInEmptyResources;
50     private boolean isUseHttpsWithDmaap;
51
52     /**
53      * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup}
54      * class.
55      *
56      * @param builder the SDC configuration builder
57      */
58     public SdcReceptionHandlerConfigurationParameterGroup(
59             final SdcReceptionHandlerConfigurationParameterBuilder builder) {
60         asdcAddress = builder.getAsdcAddress();
61         messageBusAddress = builder.getMessageBusAddress();
62         user = builder.getUser();
63         password = builder.getPassword();
64         pollingInterval = builder.getPollingInterval();
65         pollingTimeout = builder.getPollingTimeout();
66         consumerId = builder.getConsumerId();
67         artifactTypes = builder.getArtifactTypes();
68         consumerGroup = builder.getConsumerGroup();
69         environmentName = builder.getEnvironmentName();
70         keyStorePath = builder.getKeystorePath();
71         keyStorePassword = builder.getKeystorePassword();
72         activeServerTlsAuth = builder.isActiveserverTlsAuth();
73         isFilterInEmptyResources = builder.isFilterinEmptyResources();
74         isUseHttpsWithDmaap = builder.getIsUseHttpsWithDmaap();
75
76     }
77
78     public String getAsdcAddress() {
79         return asdcAddress;
80     }
81
82     public List<String> getMessageBusAddress() {
83         return messageBusAddress;
84     }
85
86     public String getUser() {
87         return user;
88     }
89
90     public String getPassword() {
91         return password;
92     }
93
94     public int getPollingInterval() {
95         return pollingInterval;
96     }
97
98     public int getPollingTimeout() {
99         return pollingTimeout;
100     }
101
102     public String getConsumerId() {
103         return consumerId;
104     }
105
106     public List<String> getArtifactTypes() {
107         return artifactTypes;
108     }
109
110     public String getConsumerGroup() {
111         return consumerGroup;
112     }
113
114     public String getEnvironmentName() {
115         return environmentName;
116     }
117
118     public String getKeyStorePassword() {
119         return keyStorePassword;
120     }
121
122     public boolean isActiveServerTlsAuth() {
123         return activeServerTlsAuth;
124     }
125
126     public String getKeyStorePath() {
127         return keyStorePath;
128     }
129
130     public boolean isFilterInEmptyResources() {
131         return isFilterInEmptyResources;
132     }
133
134     public boolean isUseHttpsWithDmaap() {
135         return isUseHttpsWithDmaap;
136     }
137
138     /**
139      * {@inheritDoc}
140      */
141     @Override
142     public GroupValidationResult validate() {
143         final GroupValidationResult validationResult = new GroupValidationResult(this);
144         validateStringElement(validationResult, asdcAddress, "asdcAddress");
145         validateStringElement(validationResult, user, "user");
146         validateStringElement(validationResult, consumerId, "consumerId");
147         validateStringElement(validationResult, consumerGroup, "consumerGroup");
148         validateStringElement(validationResult, keyStorePath, "keyStorePath");
149         validateStringElement(validationResult, keyStorePassword, "keyStorePassword");
150         validateIntElement(validationResult, pollingInterval, "pollingInterval");
151         validateIntElement(validationResult, pollingTimeout, "pollingTimeout");
152         validateStringListElement(validationResult, messageBusAddress, "messageBusAddress");
153         validateStringListElement(validationResult, artifactTypes, "artifactTypes");
154         return validationResult;
155     }
156
157     /**
158      * Validate the integer Element.
159      *
160      * @param validationResult the result object
161      * @param element the element to validate
162      * @param elementName the element name for error message
163      */
164     private void validateIntElement(final GroupValidationResult validationResult, final int element,
165             final String elementName) {
166         if (!ParameterValidationUtils.validateIntParameter(element)) {
167             validationResult.setResult(elementName, ValidationStatus.INVALID,
168                     elementName + " must be a positive integer");
169         }
170     }
171
172     /**
173      * Validate the String List Element.
174      *
175      * @param validationResult the result object
176      * @param element the element to validate
177      * @param elementName the element name for error message
178      */
179     private void validateStringListElement(final GroupValidationResult validationResult, final List<String> element,
180             final String elementName) {
181         for (final String temp : element) {
182             if (!ParameterValidationUtils.validateStringParameter(temp)) {
183                 validationResult.setResult(elementName, ValidationStatus.INVALID,
184                         "the string of " + elementName + "must be a non-blank string");
185             }
186         }
187     }
188
189     /**
190      * Validate the string element.
191      *
192      * @param validationResult the result object
193      * @param element the element to validate
194      * @param elementName the element name for error message
195      */
196     private void validateStringElement(final GroupValidationResult validationResult, final String element,
197             final String elementName) {
198         if (!ParameterValidationUtils.validateStringParameter(element)) {
199             validationResult.setResult(elementName, ValidationStatus.INVALID,
200                     elementName + " must be a non-blank string");
201         }
202     }
203 }
204