03ef70ab6d15bfee278496377f7ee515cd00fdb3
[dcaegen2/collectors/datafile.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.dcaegen2.collectors.datafile.configuration;
20
21 import com.google.gson.JsonObject;
22
23 import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
24 import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
25 import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapConsumerConfiguration;
26 import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapPublisherConfiguration;
27
28 /**
29  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 9/19/18
30  */
31 public class CloudConfigParser {
32
33     private final JsonObject jsonObject;
34
35     CloudConfigParser(JsonObject jsonObject) {
36         this.jsonObject = jsonObject;
37     }
38
39     DmaapPublisherConfiguration getDmaapPublisherConfig() {
40         return new ImmutableDmaapPublisherConfiguration.Builder()
41             .dmaapTopicName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapTopicName").getAsString())
42             .dmaapUserPassword(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserPassword").getAsString())
43             .dmaapPortNumber(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapPortNumber").getAsInt())
44             .dmaapProtocol(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapProtocol").getAsString())
45             .dmaapContentType(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapContentType").getAsString())
46             .dmaapHostName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapHostName").getAsString())
47             .dmaapUserName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserName").getAsString())
48             .build();
49     }
50
51     DmaapConsumerConfiguration getDmaapConsumerConfig() {
52         return new ImmutableDmaapConsumerConfiguration.Builder()
53             .timeoutMS(jsonObject.get("dmaap.dmaapConsumerConfiguration.timeoutMS").getAsInt())
54             .dmaapHostName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapHostName").getAsString())
55             .dmaapUserName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapUserName").getAsString())
56             .dmaapUserPassword(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapUserPassword").getAsString())
57             .dmaapTopicName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapTopicName").getAsString())
58             .dmaapPortNumber(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapPortNumber").getAsInt())
59             .dmaapContentType(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapContentType").getAsString())
60             .messageLimit(jsonObject.get("dmaap.dmaapConsumerConfiguration.messageLimit").getAsInt())
61             .dmaapProtocol(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapProtocol").getAsString())
62             .consumerId(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerId").getAsString())
63             .consumerGroup(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerGroup").getAsString())
64             .build();
65     }
66
67     public FtpesConfig getFtpesConfig() {
68         return new ImmutableFtpesConfig.Builder()
69                 .keyCert(jsonObject.get("dmaap.ftpesConfig.keyCert").getAsString())
70                 .keyPassword(jsonObject.get("dmaap.ftpesConfig.keyPassword").getAsString())
71                 .trustedCA(jsonObject.get("dmaap.ftpesConfig.trustedCA").getAsString())
72                 .trustedCAPassword(jsonObject.get("dmaap.ftpesConfig.trustedCAPassword").getAsString())
73                 .build();
74     }
75 }