Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-aai / src / main / java / org / onap / dcae / apod / analytics / aai / AAIClientFactory.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
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
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 package org.onap.dcae.apod.analytics.aai;
22
23 import com.google.inject.AbstractModule;
24 import com.google.inject.Guice;
25 import com.google.inject.Injector;
26 import org.onap.dcae.apod.analytics.aai.domain.config.AAIHttpClientConfig;
27 import org.onap.dcae.apod.analytics.aai.module.AnalyticsAAIModule;
28 import org.onap.dcae.apod.analytics.aai.service.AAIEnrichmentClient;
29 import org.onap.dcae.apod.analytics.aai.service.AAIEnrichmentClientFactory;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * Factory to create A&AI API Client.
35  *
36  * @author Rajiv Singla . Creation Date: 9/18/2017.
37  */
38 public class AAIClientFactory {
39
40     private static final Logger LOG = LoggerFactory.getLogger(AAIClientFactory.class);
41
42     private final Injector injector;
43
44     public AAIClientFactory(final AbstractModule guiceModule) {
45         LOG.info("Creating instance of AAI Client Factory with Module: {}", guiceModule.getClass().getSimpleName());
46         this.injector = Guice.createInjector(guiceModule);
47     }
48
49     /**
50      * Creates an instance of {@link AAIEnrichmentClient}.
51      *
52      * @param aaiHttpClientConfig A&AI Http Client Config
53      *
54      * @return An instance of A&AI Enrichment Client to fetch enrichment details from A&AI API.
55      */
56     public AAIEnrichmentClient getEnrichmentClient(final AAIHttpClientConfig aaiHttpClientConfig) {
57         LOG.info("Creating instance of A&AI Enrichment Client with A&AI HttpClientConfig: {}", aaiHttpClientConfig);
58         final AAIEnrichmentClientFactory aaiEnrichmentClientFactory =
59                 injector.getInstance(AAIEnrichmentClientFactory.class);
60         return aaiEnrichmentClientFactory.create(aaiHttpClientConfig);
61     }
62
63
64     /**
65      * Static method used to create an instance of {@link AAIClientFactory} itself using default
66      * guice {@link AnalyticsAAIModule}
67      *
68      * @return An instance of AAI Client Factory with {@link AnalyticsAAIModule} guice module configuration
69      */
70     public static AAIClientFactory create() {
71         return new AAIClientFactory(new AnalyticsAAIModule());
72     }
73
74 }