da6033597b62be1501188c0aa7d46bbd041b5aa9
[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 package org.onap.policy.distribution.reception.handling.sdc;
21 import java.util.List;
22 import java.io.FileReader;
23 import java.io.IOException;
24
25 import com.google.gson.Gson;
26 import com.google.gson.GsonBuilder;
27
28 import org.onap.policy.common.parameters.GroupValidationResult;
29 import org.onap.policy.common.parameters.ParameterConstants;
30 import org.onap.policy.common.parameters.ParameterGroup;
31 import org.onap.policy.common.parameters.ValidationStatus;
32
33 /**
34 * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json 
35 * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
36 */
37 public class  PSSDConfigurationParametersGroup implements ParameterGroup {
38     //Policy SDC Service Distribution specified field.
39     private String name;
40     
41     //Interface of IConfiguration item
42     private String asdcAddress;
43     private List<String> messageBusAddress;
44     private String user;
45     private String password;
46     private int pollingInterval;
47     private int pollingTimeout;
48     private String consumerId;
49     private List<String> artifactTypes;
50     private String consumerGroup;
51     private String environmentName;
52     private String keystorePath;
53     private String keystorePassword;
54     private boolean activeserverTlsAuth;
55     private boolean isFilterinEmptyResources;
56     private Boolean isUseHttpsWithDmaap;
57
58     public String getAsdcAddress(){
59         return asdcAddress;
60     }
61
62     public List<String> getMsgBusAddress(){
63         return messageBusAddress;
64     }
65
66     public String getUser() {
67         return user;
68     }
69
70     public String getPassword() {
71         return password;
72     }
73
74     public int getPollingInterval() {
75         return pollingInterval;
76     }
77     
78     public int getPollingTimeout() {
79         return pollingTimeout;
80     }
81
82     public String getConsumerID() {
83         return consumerId;
84     }
85
86     public List<String> getArtifactTypes(){
87         return artifactTypes;
88     }
89
90     public String getConsumerGroup() {
91         return consumerGroup;
92     }
93
94     public String getEnvironmentName() {
95         return environmentName;
96     }
97
98     public String getKeyStorePassword() {
99         return keystorePassword;
100     }
101
102     public String getKeyStorePath() {
103         return keystorePath;
104     }
105
106     public boolean activateServerTLSAuth() {
107         return activeserverTlsAuth;
108     }
109
110     public boolean isFilterInEmptyResources() {
111         return isFilterinEmptyResources;
112     }
113
114     public Boolean isUseHttpsWithDmaap() {
115         return isUseHttpsWithDmaap;
116     }
117
118     @Override
119     public String toString() {
120         return "name =" + name +",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = " + messageBusAddress + 
121                 ", user = "+ user + "]";
122     }
123
124     @Override
125     public String getName() {
126         return name;
127     }
128
129     @Override
130     public GroupValidationResult validate() {
131         GroupValidationResult validationResult = new GroupValidationResult(this);
132
133         if (name == null || name.trim().length() == 0) {
134             validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
135         }
136
137         if (asdcAddress == null || asdcAddress.trim().length() == 0) {
138             validationResult.setResult("asdcAddress", ValidationStatus.INVALID, "asdcAddress must be a non-blank string");
139         }
140
141         if (user == null || user.trim().length() == 0) {
142             validationResult.setResult("user", ValidationStatus.INVALID, "user must be a non-blank string");
143         }
144
145         if (consumerId == null || consumerId.trim().length() == 0) {
146             validationResult.setResult("consumerId", ValidationStatus.INVALID, "consumerId must be a non-blank string");
147         }
148
149         if (consumerGroup == null || consumerGroup.trim().length() == 0) {
150             validationResult.setResult("consumerGroup", ValidationStatus.INVALID, "consumerGroup must be a non-blank string");
151         }
152
153         if (keystorePath == null || keystorePath.trim().length() == 0) {
154             validationResult.setResult("keystorePath", ValidationStatus.INVALID, "keystorePath must be a non-blank string");
155         }
156
157         if (keystorePassword == null || keystorePassword.trim().length() == 0) {
158             validationResult.setResult("keystorePassword", ValidationStatus.INVALID, "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(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(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