7fa81149acb1827585e30a0b26b6fda20363e34a
[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
25 import org.onap.policy.common.parameters.GroupValidationResult;
26 import org.onap.policy.common.parameters.ParameterGroup;
27 import org.onap.policy.common.parameters.ValidationStatus;
28
29 /**
30  * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
31  * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
32  */
33 public class PSSDConfigurationParametersGroup implements ParameterGroup {
34     // Policy SDC Service Distribution specified field.
35     private String name;
36
37     // Interface of IConfiguration item
38     private String asdcAddress;
39     private List<String> messageBusAddress;
40     private String user;
41     private String password;
42     private int pollingInterval;
43     private int pollingTimeout;
44     private String consumerId;
45     private List<String> artifactTypes;
46     private String consumerGroup;
47     private String environmentName;
48     private String keystorePath;
49     private String keystorePassword;
50     private boolean activeserverTlsAuth;
51     private boolean isFilterinEmptyResources;
52     private Boolean isUseHttpsWithDmaap;
53
54     public String getAsdcAddress() {
55         return asdcAddress;
56     }
57
58     public List<String> getMsgBusAddress() {
59         return messageBusAddress;
60     }
61
62     public String getUser() {
63         return user;
64     }
65
66     public String getPassword() {
67         return password;
68     }
69
70     public int getPollingInterval() {
71         return pollingInterval;
72     }
73
74     public int getPollingTimeout() {
75         return pollingTimeout;
76     }
77
78     public String getConsumerID() {
79         return consumerId;
80     }
81
82     public List<String> getArtifactTypes() {
83         return artifactTypes;
84     }
85
86     public String getConsumerGroup() {
87         return consumerGroup;
88     }
89
90     public String getEnvironmentName() {
91         return environmentName;
92     }
93
94     public String getKeyStorePassword() {
95         return keystorePassword;
96     }
97
98     public String getKeyStorePath() {
99         return keystorePath;
100     }
101
102     public boolean activateServerTLSAuth() {
103         return activeserverTlsAuth;
104     }
105
106     public boolean isFilterInEmptyResources() {
107         return isFilterinEmptyResources;
108     }
109
110     public Boolean isUseHttpsWithDmaap() {
111         return isUseHttpsWithDmaap;
112     }
113
114     @Override
115     public String toString() {
116         return "name =" + name + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = "
117                 + messageBusAddress + ", user = " + user + "]";
118     }
119
120     @Override
121     public String getName() {
122         return name;
123     }
124
125     @Override
126     public GroupValidationResult validate() {
127         final GroupValidationResult validationResult = new GroupValidationResult(this);
128
129         if (name == null || name.trim().length() == 0) {
130             validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
131         }
132
133         if (asdcAddress == null || asdcAddress.trim().length() == 0) {
134             validationResult.setResult("asdcAddress", ValidationStatus.INVALID,
135                     "asdcAddress must be a non-blank string");
136         }
137
138         if (user == null || user.trim().length() == 0) {
139             validationResult.setResult("user", ValidationStatus.INVALID, "user must be a non-blank string");
140         }
141
142         if (consumerId == null || consumerId.trim().length() == 0) {
143             validationResult.setResult("consumerId", ValidationStatus.INVALID, "consumerId must be a non-blank string");
144         }
145
146         if (consumerGroup == null || consumerGroup.trim().length() == 0) {
147             validationResult.setResult("consumerGroup", ValidationStatus.INVALID,
148                     "consumerGroup must be a non-blank string");
149         }
150
151         if (keystorePath == null || keystorePath.trim().length() == 0) {
152             validationResult.setResult("keystorePath", ValidationStatus.INVALID,
153                     "keystorePath must be a non-blank string");
154         }
155
156         if (keystorePassword == null || keystorePassword.trim().length() == 0) {
157             validationResult.setResult("keystorePassword", ValidationStatus.INVALID,
158                     "keystorePassword must be a non-blank string");
159         }
160
161         if (messageBusAddress == null) {
162             validationResult.setResult("messageBusAddress", ValidationStatus.INVALID,
163                     "messageBusAddress must be a list of non-blank string");
164         } else {
165             for (final String temp : messageBusAddress) {
166                 if (temp.trim().length() == 0) {
167                     validationResult.setResult("messageBusAddress", ValidationStatus.INVALID,
168                             "the string of messageBusAddress must be a non-blank string");
169                 }
170             }
171         }
172
173         if (artifactTypes == null) {
174             validationResult.setResult("artifactTypes", ValidationStatus.INVALID,
175                     "artifactTypes must be a list of non-blank string");
176         } else {
177             for (final String temp : artifactTypes) {
178                 if (temp.trim().length() == 0) {
179                     validationResult.setResult("artifactTypes", ValidationStatus.INVALID,
180                             "the string of artifactTypes must be a non-blank string");
181                 }
182             }
183         }
184
185         if (pollingInterval <= 0) {
186             validationResult.setResult("pollingInterval", ValidationStatus.INVALID,
187                     "pollingInterval must be a positive integer");
188         }
189
190         if (pollingTimeout <= 0) {
191             validationResult.setResult("pollingTimeout", ValidationStatus.INVALID,
192                     "pollingTimeout must be a positive integer");
193         }
194
195         return validationResult;
196     }
197
198 }
199