2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.cdap.tca.utils;
\r
23 import com.google.common.base.Function;
\r
24 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCAAppPreferences;
\r
25 import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig;
\r
27 import javax.annotation.Nonnull;
\r
29 import static org.openecomp.dcae.apod.analytics.cdap.common.utils.ValidationUtils.isPresent;
\r
33 * Function which translates {@link TCAAppPreferences} to {@link DMaaPMRPublisherConfig}
\r
35 * @author Rajiv Singla . Creation Date: 11/17/2016.
\r
37 public class AppPreferencesToPublisherConfigMapper implements Function<TCAAppPreferences, DMaaPMRPublisherConfig> {
\r
40 * Factory method to convert {@link TCAAppPreferences} to {@link DMaaPMRPublisherConfig} object
\r
42 * @param tcaAppPreferences tca App Preferences
\r
44 * @return publisher config object
\r
46 public static DMaaPMRPublisherConfig map(final TCAAppPreferences tcaAppPreferences) {
\r
47 return new AppPreferencesToPublisherConfigMapper().apply(tcaAppPreferences);
\r
51 * Implementation to convert {@link TCAAppPreferences} to {@link DMaaPMRPublisherConfig} object
\r
53 * @param tcaAppPreferences tca App Preferences
\r
55 * @return publisher config object
\r
59 public DMaaPMRPublisherConfig apply(@Nonnull TCAAppPreferences tcaAppPreferences) {
\r
61 // Create a new publisher settings builder
\r
62 final DMaaPMRPublisherConfig.Builder publisherConfigBuilder = new DMaaPMRPublisherConfig.Builder(
\r
63 tcaAppPreferences.getPublisherHostName(), tcaAppPreferences.getPublisherTopicName());
\r
65 // Setup up any optional publisher parameters if they are present
\r
66 final Integer publisherHostPort = tcaAppPreferences.getPublisherHostPort();
\r
67 if (publisherHostPort != null) {
\r
68 publisherConfigBuilder.setPortNumber(publisherHostPort);
\r
70 final String publisherProtocol = tcaAppPreferences.getPublisherProtocol();
\r
71 if (isPresent(publisherProtocol)) {
\r
72 publisherConfigBuilder.setProtocol(publisherProtocol);
\r
74 final String publisherUserName = tcaAppPreferences.getPublisherUserName();
\r
75 if (isPresent(publisherUserName)) {
\r
76 publisherConfigBuilder.setUserName(publisherUserName);
\r
78 final String publisherUserPassword = tcaAppPreferences.getPublisherUserPassword();
\r
79 if (isPresent(publisherUserPassword)) {
\r
80 publisherConfigBuilder.setUserPassword(publisherUserPassword);
\r
82 final String publisherContentType = tcaAppPreferences.getPublisherContentType();
\r
83 if (isPresent(publisherContentType)) {
\r
84 publisherConfigBuilder.setContentType(publisherContentType);
\r
86 final Integer publisherMaxBatchSize = tcaAppPreferences.getPublisherMaxBatchSize();
\r
87 if (publisherMaxBatchSize != null) {
\r
88 publisherConfigBuilder.setMaxBatchSize(publisherMaxBatchSize);
\r
90 final Integer publisherMaxRecoveryQueueSize = tcaAppPreferences.getPublisherMaxRecoveryQueueSize();
\r
91 if (publisherMaxRecoveryQueueSize != null) {
\r
92 publisherConfigBuilder.setMaxRecoveryQueueSize(publisherMaxRecoveryQueueSize);
\r
95 return publisherConfigBuilder.build();
\r