298607b5f5012c82f98210a2b2ca3270f2362781
[policy/common.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP POLICY
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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  * ===================================================================
20  *
21  */
22
23 package org.onap.policy.common.endpoints.event.comm.bus.internal;
24
25 import java.util.Properties;
26 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
27
28 public class BusHelper {
29
30     private BusHelper() {
31         /* no constructor */
32     }
33
34     /**
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
39      */
40     public static void setCommonProperties(BusTopicParams busTopicParams, String dme2RouteOffer, Properties props) {
41         props.setProperty("Environment", busTopicParams.getEnvironment());
42         props.setProperty("AFT_ENVIRONMENT", busTopicParams.getAftEnvironment());
43
44         if (busTopicParams.getPartner() != null) {
45             props.setProperty("Partner", busTopicParams.getPartner());
46         }
47         if (dme2RouteOffer != null) {
48             props.setProperty(PolicyEndPointProperties.DME2_ROUTE_OFFER_PROPERTY, dme2RouteOffer);
49         }
50
51         props.setProperty("Latitude", busTopicParams.getLatitude());
52         props.setProperty("Longitude", busTopicParams.getLongitude());
53
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");
61
62         /* These should not change */
63         props.setProperty("TransportType", "DME2");
64     }
65
66     /**
67      * Throws exception when any of the checks are invalid.
68      * @param busTopicParams topics
69      * @param topicType topic type (sink or source)
70      */
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);
75         }
76         if (busTopicParams.isAftEnvironmentInvalid()) {
77             throw paramException(busTopicParams.getTopic(), topicType,
78                 PolicyEndPointProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX);
79         }
80         if (busTopicParams.isLatitudeInvalid()) {
81             throw paramException(busTopicParams.getTopic(), topicType,
82                 PolicyEndPointProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX);
83         }
84         if (busTopicParams.isLongitudeInvalid()) {
85             throw paramException(busTopicParams.getTopic(), topicType,
86                 PolicyEndPointProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX);
87         }
88     }
89
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");
93
94     }
95 }