2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2023 Nordix Foundation.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END============================================
19 * ===================================================================
23 package org.onap.policy.common.endpoints.event.comm.bus.internal;
25 import java.util.Properties;
26 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
28 public class BusHelper {
35 * Complete the properties param with common fields for both BusConsumer and BusPublisher.
36 * @param busTopicParams topics
37 * @param dme2RouteOffer route
38 * @param props properties
40 public static void setCommonProperties(BusTopicParams busTopicParams, String dme2RouteOffer, Properties props) {
41 props.setProperty("Environment", busTopicParams.getEnvironment());
42 props.setProperty("AFT_ENVIRONMENT", busTopicParams.getAftEnvironment());
44 if (busTopicParams.getPartner() != null) {
45 props.setProperty("Partner", busTopicParams.getPartner());
47 if (dme2RouteOffer != null) {
48 props.setProperty(PolicyEndPointProperties.DME2_ROUTE_OFFER_PROPERTY, dme2RouteOffer);
51 props.setProperty("Latitude", busTopicParams.getLatitude());
52 props.setProperty("Longitude", busTopicParams.getLongitude());
54 /* These are optional, will default to these values if not set in additionalProps */
55 props.setProperty("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
56 props.setProperty("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
57 props.setProperty("AFT_DME2_EP_CONN_TIMEOUT", "15000");
58 props.setProperty("Version", "1.0");
59 props.setProperty("SubContextPath", "/");
60 props.setProperty("sessionstickinessrequired", "no");
62 /* These should not change */
63 props.setProperty("TransportType", "DME2");
67 * Throws exception when any of the checks are invalid.
68 * @param busTopicParams topics
69 * @param topicType topic type (sink or source)
71 public static void validateBusTopicParams(BusTopicParams busTopicParams, String topicType) {
72 if (busTopicParams.isEnvironmentInvalid()) {
73 throw paramException(busTopicParams.getTopic(), topicType,
74 PolicyEndPointProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX);
76 if (busTopicParams.isAftEnvironmentInvalid()) {
77 throw paramException(busTopicParams.getTopic(), topicType,
78 PolicyEndPointProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX);
80 if (busTopicParams.isLatitudeInvalid()) {
81 throw paramException(busTopicParams.getTopic(), topicType,
82 PolicyEndPointProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX);
84 if (busTopicParams.isLongitudeInvalid()) {
85 throw paramException(busTopicParams.getTopic(), topicType,
86 PolicyEndPointProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX);
90 private static IllegalArgumentException paramException(String topic, String topicType, String propertyName) {
91 return new IllegalArgumentException("Missing " + topicType + "."
92 + topic + propertyName + " property for DME2 in DMaaP");