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.openecomp.dcae.apod.analytics.aai;
23 import com.google.inject.AbstractModule;
24 import com.google.inject.Guice;
25 import com.google.inject.Injector;
26 import org.openecomp.dcae.apod.analytics.aai.domain.config.AAIHttpClientConfig;
27 import org.openecomp.dcae.apod.analytics.aai.module.AnalyticsAAIModule;
28 import org.openecomp.dcae.apod.analytics.aai.service.AAIEnrichmentClient;
29 import org.openecomp.dcae.apod.analytics.aai.service.AAIEnrichmentClientFactory;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * Factory to create A&AI API Client.
36 * @author Rajiv Singla . Creation Date: 9/18/2017.
38 public class AAIClientFactory {
40 private static final Logger LOG = LoggerFactory.getLogger(AAIClientFactory.class);
42 private final Injector injector;
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);
50 * Creates an instance of {@link AAIEnrichmentClient}.
52 * @param aaiHttpClientConfig A&AI Http Client Config
54 * @return An instance of A&AI Enrichment Client to fetch enrichment details from A&AI API.
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);
65 * Static method used to create an instance of {@link AAIClientFactory} itself using default
66 * guice {@link AnalyticsAAIModule}
68 * @return An instance of AAI Client Factory with {@link AnalyticsAAIModule} guice module configuration
70 public static AAIClientFactory create() {
71 return new AAIClientFactory(new AnalyticsAAIModule());