2 * ===============================LICENSE_START======================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
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===========================================
21 package org.onap.dcae.apod.analytics.cdap.tca.utils;
23 import com.google.common.base.Function;
24 import org.onap.dcae.apod.analytics.cdap.tca.settings.TCAAppPreferences;
25 import org.onap.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig;
27 import javax.annotation.Nonnull;
29 import static org.onap.dcae.apod.analytics.cdap.common.utils.ValidationUtils.isPresent;
33 * Function which translates {@link TCAAppPreferences} to {@link DMaaPMRPublisherConfig}
35 * @author Rajiv Singla . Creation Date: 11/17/2016.
37 public class AppPreferencesToPublisherConfigMapper implements Function<TCAAppPreferences, DMaaPMRPublisherConfig> {
40 * Factory method to convert {@link TCAAppPreferences} to {@link DMaaPMRPublisherConfig} object
42 * @param tcaAppPreferences tca App Preferences
44 * @return publisher config object
46 public static DMaaPMRPublisherConfig map(final TCAAppPreferences tcaAppPreferences) {
47 return new AppPreferencesToPublisherConfigMapper().apply(tcaAppPreferences);
51 * Implementation to convert {@link TCAAppPreferences} to {@link DMaaPMRPublisherConfig} object
53 * @param tcaAppPreferences tca App Preferences
55 * @return publisher config object
59 public DMaaPMRPublisherConfig apply(@Nonnull TCAAppPreferences tcaAppPreferences) {
61 // Create a new publisher settings builder
62 final DMaaPMRPublisherConfig.Builder publisherConfigBuilder = new DMaaPMRPublisherConfig.Builder(
63 tcaAppPreferences.getPublisherHostName(), tcaAppPreferences.getPublisherTopicName());
65 // Setup up any optional publisher parameters if they are present
66 final Integer publisherHostPort = tcaAppPreferences.getPublisherHostPort();
67 if (publisherHostPort != null) {
68 publisherConfigBuilder.setPortNumber(publisherHostPort);
70 final String publisherProtocol = tcaAppPreferences.getPublisherProtocol();
71 if (isPresent(publisherProtocol)) {
72 publisherConfigBuilder.setProtocol(publisherProtocol);
74 final String publisherUserName = tcaAppPreferences.getPublisherUserName();
75 if (isPresent(publisherUserName)) {
76 publisherConfigBuilder.setUserName(publisherUserName);
78 final String publisherUserPassword = tcaAppPreferences.getPublisherUserPassword();
79 if (isPresent(publisherUserPassword)) {
80 publisherConfigBuilder.setUserPassword(publisherUserPassword);
82 final String publisherContentType = tcaAppPreferences.getPublisherContentType();
83 if (isPresent(publisherContentType)) {
84 publisherConfigBuilder.setContentType(publisherContentType);
86 final Integer publisherMaxBatchSize = tcaAppPreferences.getPublisherMaxBatchSize();
87 if (publisherMaxBatchSize != null) {
88 publisherConfigBuilder.setMaxBatchSize(publisherMaxBatchSize);
90 final Integer publisherMaxRecoveryQueueSize = tcaAppPreferences.getPublisherMaxRecoveryQueueSize();
91 if (publisherMaxRecoveryQueueSize != null) {
92 publisherConfigBuilder.setMaxRecoveryQueueSize(publisherMaxRecoveryQueueSize);
95 return publisherConfigBuilder.build();