bbee652a501487e9045e8cb4a70b1283158660a6
[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 java.util.UUID;
25
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ValidationStatus;
28 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
29 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
30
31 /**
32  * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
33  * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
34  */
35 public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
36
37     private String asdcAddress;
38     private List<String> messageBusAddress;
39     private String user;
40     private String password;
41     private int pollingInterval;
42     private int pollingTimeout;
43     private String consumerId;
44     private List<String> artifactTypes;
45     private String consumerGroup;
46     private String environmentName;
47     private String keyStorePath;
48     private String keyStorePassword;
49     private boolean activeServerTlsAuth;
50     private boolean isFilterInEmptyResources;
51     private boolean isUseHttpsWithDmaap;
52
53     /**
54      * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup} 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      * Set the name of this group.
140      *
141      * @param name the name to set.
142      */
143     @Override
144     public void setName(final String name) {
145         super.setName(name + "_" + UUID.randomUUID().toString());
146     }
147
148     /**
149      * {@inheritDoc}
150      */
151     @Override
152     public GroupValidationResult validate() {
153         final GroupValidationResult validationResult = new GroupValidationResult(this);
154         validateStringElement(validationResult, asdcAddress, "asdcAddress");
155         validateStringElement(validationResult, user, "user");
156         validateStringElement(validationResult, consumerId, "consumerId");
157         validateStringElement(validationResult, consumerGroup, "consumerGroup");
158         validateStringElement(validationResult, keyStorePath, "keyStorePath");
159         validateStringElement(validationResult, keyStorePassword, "keyStorePassword");
160         validateIntElement(validationResult, pollingInterval, "pollingInterval");
161         validateIntElement(validationResult, pollingTimeout, "pollingTimeout");
162         validateStringListElement(validationResult, messageBusAddress, "messageBusAddress");
163         validateStringListElement(validationResult, artifactTypes, "artifactTypes");
164         return validationResult;
165     }
166
167     /**
168      * Validate the integer Element.
169      *
170      * @param validationResult the result object
171      * @param element the element to validate
172      * @param elementName the element name for error message
173      */
174     private void validateIntElement(final GroupValidationResult validationResult, final int element,
175             final String elementName) {
176         if (!ParameterValidationUtils.validateIntParameter(element)) {
177             validationResult.setResult(elementName, ValidationStatus.INVALID,
178                     elementName + " must be a positive integer");
179         }
180     }
181
182     /**
183      * Validate the String List Element.
184      *
185      * @param validationResult the result object
186      * @param element the element to validate
187      * @param elementName the element name for error message
188      */
189     private void validateStringListElement(final GroupValidationResult validationResult, final List<String> element,
190             final String elementName) {
191         for (final String temp : element) {
192             if (!ParameterValidationUtils.validateStringParameter(temp)) {
193                 validationResult.setResult(elementName, ValidationStatus.INVALID,
194                         "the string of " + elementName + "must be a non-blank string");
195             }
196         }
197     }
198
199     /**
200      * Validate the string element.
201      *
202      * @param validationResult the result object
203      * @param element the element to validate
204      * @param elementName the element name for error message
205      */
206     private void validateStringElement(final GroupValidationResult validationResult, final String element,
207             final String elementName) {
208         if (!ParameterValidationUtils.validateStringParameter(element)) {
209             validationResult.setResult(elementName, ValidationStatus.INVALID,
210                     elementName + " must be a non-blank string");
211         }
212     }
213 }
214