1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2021 Orange.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 *******************************************************************************/
25 package org.onap.dmaap.mr.tools;
27 import java.util.Properties;
29 import org.onap.dmaap.mr.client.DmaapClientConst;
30 import org.onap.dmaap.mr.client.ProtocolType;
32 public class ValidatorUtil {
34 public static final String IS_NEEDED = " is needed";
36 private ValidatorUtil() {
40 public static void validatePublisher(Properties props) {
41 String transportType = props.getProperty(DmaapClientConst.TRANSPORT_TYPE);
42 if (ProtocolType.DME2.getValue().equalsIgnoreCase(transportType)) {
43 validateForDME2(props);
45 validateForNonDME2(props);
47 String maxBatchSize = props.getProperty(DmaapClientConst.MAX_BATCH_SIZE, "");
48 if (maxBatchSize.isEmpty()) {
49 throw new IllegalArgumentException(DmaapClientConst.MAX_BATCH_SIZE + IS_NEEDED);
51 String maxAgeMs = props.getProperty(DmaapClientConst.MAX_AGE_MS, "");
52 if (maxAgeMs.isEmpty()) {
53 throw new IllegalArgumentException(DmaapClientConst.MAX_AGE_MS + IS_NEEDED);
56 String messageSentThreadOccurrence = props.getProperty(DmaapClientConst.MESSAGE_SENT_THREAD_OCCURRENCE);
57 if (messageSentThreadOccurrence == null || messageSentThreadOccurrence.isEmpty()) {
58 messageSentThreadOccurrence = props.getProperty(DmaapClientConst.MESSAGE_SENT_THREAD_OCCURRENCE_OLD);
60 if (messageSentThreadOccurrence == null || messageSentThreadOccurrence.isEmpty()) {
61 throw new IllegalArgumentException(DmaapClientConst.MESSAGE_SENT_THREAD_OCCURRENCE + IS_NEEDED);
64 Integer.parseInt(messageSentThreadOccurrence);
65 } catch (NumberFormatException e) {
66 throw new IllegalArgumentException(DmaapClientConst.MESSAGE_SENT_THREAD_OCCURRENCE + " must be an integer");
71 public static void validateSubscriber(Properties props) {
72 String transportType = props.getProperty(DmaapClientConst.TRANSPORT_TYPE);
73 if (ProtocolType.DME2.getValue().equalsIgnoreCase(transportType)) {
74 validateForDME2(props);
76 validateForNonDME2(props);
78 String group = props.getProperty(DmaapClientConst.GROUP, "");
79 if (group.isEmpty()) {
80 throw new IllegalArgumentException(DmaapClientConst.GROUP + IS_NEEDED);
82 String id = props.getProperty(DmaapClientConst.ID, "");
84 throw new IllegalArgumentException("Consumer (" + DmaapClientConst.ID + ")" + IS_NEEDED);
88 private static void validateForDME2(Properties props) {
89 String serviceName = props.getProperty(DmaapClientConst.SERVICE_NAME, "");
90 if (serviceName.isEmpty()) {
91 throw new IllegalArgumentException(DmaapClientConst.SERVICE_NAME + IS_NEEDED);
93 String topic = props.getProperty(DmaapClientConst.TOPIC, "");
94 if (topic.isEmpty()) {
95 throw new IllegalArgumentException(DmaapClientConst.TOPIC + IS_NEEDED);
97 String username = props.getProperty(DmaapClientConst.USERNAME, "");
98 if (username.isEmpty()) {
99 throw new IllegalArgumentException(DmaapClientConst.USERNAME + IS_NEEDED);
101 String password = props.getProperty(DmaapClientConst.PASSWORD, "");
102 if (password.isEmpty()) {
103 throw new IllegalArgumentException(DmaapClientConst.PASSWORD + IS_NEEDED);
105 String dme2preferredRouterFilePath = props.getProperty(DmaapClientConst.DME2PREFERRED_ROUTER_FILE_PATH, "");
106 if (dme2preferredRouterFilePath.isEmpty()) {
107 throw new IllegalArgumentException(DmaapClientConst.DME2PREFERRED_ROUTER_FILE_PATH + IS_NEEDED);
109 String partner = props.getProperty(DmaapClientConst.PARTNER, "");
110 String routeOffer = props.getProperty(DmaapClientConst.ROUTE_OFFER, "");
111 if (partner.isEmpty() && routeOffer.isEmpty()) {
112 throw new IllegalArgumentException(DmaapClientConst.PARTNER + " or " + DmaapClientConst.ROUTE_OFFER + IS_NEEDED);
114 String protocol = props.getProperty(DmaapClientConst.PROTOCOL, "");
115 if (protocol.isEmpty()) {
116 throw new IllegalArgumentException(DmaapClientConst.PROTOCOL + IS_NEEDED);
118 String methodType = props.getProperty(DmaapClientConst.METHOD_TYPE, "");
119 if (methodType.isEmpty()) {
120 throw new IllegalArgumentException(DmaapClientConst.METHOD_TYPE + IS_NEEDED);
122 String contentType = props.getProperty(DmaapClientConst.CONTENT_TYPE, "");
123 if (contentType.isEmpty()) {
124 throw new IllegalArgumentException(DmaapClientConst.CONTENT_TYPE + IS_NEEDED);
126 String latitude = props.getProperty(DmaapClientConst.LATITUDE, "");
127 if (latitude.isEmpty()) {
128 throw new IllegalArgumentException(DmaapClientConst.LATITUDE + IS_NEEDED);
130 String longitude = props.getProperty(DmaapClientConst.LONGITUDE, "");
131 if (longitude.isEmpty()) {
132 throw new IllegalArgumentException(DmaapClientConst.LONGITUDE + IS_NEEDED);
134 String aftEnv = props.getProperty(DmaapClientConst.AFT_ENVIRONMENT, "");
135 if (aftEnv.isEmpty()) {
136 throw new IllegalArgumentException(DmaapClientConst.AFT_ENVIRONMENT + IS_NEEDED);
138 String version = props.getProperty(DmaapClientConst.VERSION, "");
139 if (version.isEmpty()) {
140 throw new IllegalArgumentException(DmaapClientConst.VERSION + IS_NEEDED);
142 String environment = props.getProperty(DmaapClientConst.ENVIRONMENT, "");
143 if (environment.isEmpty()) {
144 throw new IllegalArgumentException(DmaapClientConst.ENVIRONMENT + IS_NEEDED);
146 String subContextPath = props.getProperty(DmaapClientConst.SUB_CONTEXT_PATH, "");
147 if (subContextPath.isEmpty()) {
148 throw new IllegalArgumentException(DmaapClientConst.SUB_CONTEXT_PATH + IS_NEEDED);
150 String sessionstickinessrequired = props.getProperty(DmaapClientConst.SESSION_STICKINESS_REQUIRED, "");
151 if (sessionstickinessrequired.isEmpty()) {
152 throw new IllegalArgumentException(DmaapClientConst.SESSION_STICKINESS_REQUIRED + IS_NEEDED);
156 private static void validateForNonDME2(Properties props) {
157 String host = props.getProperty(DmaapClientConst.HOST, "");
158 if (host.isEmpty()) {
159 throw new IllegalArgumentException(DmaapClientConst.HOST + IS_NEEDED);
161 String topic = props.getProperty(DmaapClientConst.TOPIC, "");
162 if (topic.isEmpty()) {
163 throw new IllegalArgumentException(DmaapClientConst.TOPIC + IS_NEEDED);
165 String contenttype = props.getProperty(DmaapClientConst.CONTENT_TYPE, "");
166 if (contenttype.isEmpty()) {
167 throw new IllegalArgumentException(DmaapClientConst.CONTENT_TYPE + IS_NEEDED);
169 String transportType = props.getProperty(DmaapClientConst.TRANSPORT_TYPE);
170 if (!ProtocolType.HTTPNOAUTH.getValue().equalsIgnoreCase(transportType)) {
171 String username = props.getProperty(DmaapClientConst.USERNAME, "");
172 if (username.isEmpty()) {
173 throw new IllegalArgumentException(DmaapClientConst.USERNAME + IS_NEEDED);
175 String password = props.getProperty(DmaapClientConst.PASSWORD, "");
176 if (password.isEmpty()) {
177 throw new IllegalArgumentException(DmaapClientConst.PASSWORD + IS_NEEDED);
180 if (ProtocolType.AUTH_KEY.getValue().equalsIgnoreCase(transportType)) {
181 String authKey = props.getProperty(DmaapClientConst.AUTH_KEY, "");
182 if (authKey.isEmpty()) {
183 throw new IllegalArgumentException(DmaapClientConst.AUTH_KEY + IS_NEEDED);
185 String authDate = props.getProperty(DmaapClientConst.AUTH_DATE, "");
186 if (authDate.isEmpty()) {
187 throw new IllegalArgumentException(DmaapClientConst.AUTH_DATE + IS_NEEDED);