From 02b0b3fe6956e1a8b1f7a1f2c87f03443059d741 Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 24 Mar 2020 15:08:35 +0800 Subject: [PATCH] fix bug: exception when aai enrichment is false Issue-ID: DCAEGEN2-2145 Signed-off-by: Kai Lu Change-Id: Ifa02ff50947b70791fb7252859e6071d7f9d45ce --- .../tca/web/aai/TcaAaiEnrichmentContextImpl.java | 20 +++++++++--- .../analytics/tca/web/config/TcaAaiConfig.java | 36 ++-------------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/aai/TcaAaiEnrichmentContextImpl.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/aai/TcaAaiEnrichmentContextImpl.java index 73a600a..e1444ff 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/aai/TcaAaiEnrichmentContextImpl.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/aai/TcaAaiEnrichmentContextImpl.java @@ -22,6 +22,10 @@ package org.onap.dcae.analytics.tca.web.aai; import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentContext; import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentService; import org.onap.dcae.analytics.tca.web.TcaAppProperties; +import org.onap.dcae.analytics.tca.web.util.function.TcaAppPropsToAaiRestClientPrefsFunction; +import org.onap.dcae.analytics.web.http.HttpClientPreferencesCustomizer; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.web.client.RestTemplate; /** * @author Rajiv Singla @@ -29,15 +33,14 @@ import org.onap.dcae.analytics.tca.web.TcaAppProperties; public class TcaAaiEnrichmentContextImpl implements TcaAaiEnrichmentContext { private final TcaAppProperties tcaAppProperties; - private final TcaAaiEnrichmentService tcaAaiEnrichmentService; + private final RestTemplateBuilder restTemplateBuilder; public TcaAaiEnrichmentContextImpl(final TcaAppProperties tcaAppProperties, - final TcaAaiEnrichmentService tcaAaiEnrichmentService) { + final RestTemplateBuilder restTemplateBuilder) { this.tcaAppProperties = tcaAppProperties; - this.tcaAaiEnrichmentService = tcaAaiEnrichmentService; + this.restTemplateBuilder = restTemplateBuilder; } - @Override public boolean isAaiEnrichmentEnabled() { return tcaAppProperties.getTca().getAai().getEnableEnrichment(); @@ -45,6 +48,13 @@ public class TcaAaiEnrichmentContextImpl implements TcaAaiEnrichmentContext { @Override public TcaAaiEnrichmentService getAaiEnrichmentService() { - return tcaAaiEnrichmentService; + TcaAaiRestClientPreferences aaiRestClientPreferences = new TcaAppPropsToAaiRestClientPrefsFunction() + .apply(tcaAppProperties); + if (aaiRestClientPreferences == null) { + return null; + } + RestTemplate aaiRestTemplate = restTemplateBuilder + .additionalCustomizers(new HttpClientPreferencesCustomizer<>(aaiRestClientPreferences)).build(); + return new TcaAaiEnrichmentServiceImpl(tcaAppProperties, aaiRestTemplate); } } diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaAaiConfig.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaAaiConfig.java index 4ec42d5..d2ed48c 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaAaiConfig.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaAaiConfig.java @@ -20,17 +20,11 @@ package org.onap.dcae.analytics.tca.web.config; import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentContext; -import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentService; import org.onap.dcae.analytics.tca.web.TcaAppProperties; import org.onap.dcae.analytics.tca.web.aai.TcaAaiEnrichmentContextImpl; -import org.onap.dcae.analytics.tca.web.aai.TcaAaiEnrichmentServiceImpl; -import org.onap.dcae.analytics.tca.web.aai.TcaAaiRestClientPreferences; -import org.onap.dcae.analytics.tca.web.util.function.TcaAppPropsToAaiRestClientPrefsFunction; -import org.onap.dcae.analytics.web.http.HttpClientPreferencesCustomizer; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.RestTemplate; /** * @author Rajiv Singla @@ -38,36 +32,10 @@ import org.springframework.web.client.RestTemplate; @Configuration public class TcaAaiConfig { - @Bean - public TcaAaiRestClientPreferences aaiRestClientPreferences(final TcaAppProperties tcaAppProperties) { - return new TcaAppPropsToAaiRestClientPrefsFunction().apply(tcaAppProperties); - } - - @Bean - public RestTemplate aaiRestTemplate(final TcaAaiRestClientPreferences aaiRestClientPreferences, - final RestTemplateBuilder restTemplateBuilder) { - if(aaiRestClientPreferences == null) { - return null; - } - return restTemplateBuilder - .additionalCustomizers(new HttpClientPreferencesCustomizer<>(aaiRestClientPreferences)) - .build(); - } - - @Bean - public TcaAaiEnrichmentService aaiEnrichmentService(final TcaAppProperties tcaAppProperties, - final RestTemplate aaiRestTemplate) { - if (aaiRestTemplate == null) { - return null; - } - return new TcaAaiEnrichmentServiceImpl(tcaAppProperties, aaiRestTemplate); - } - - @Bean public TcaAaiEnrichmentContext tcaAaiEnrichmentContext(final TcaAppProperties tcaAppProperties, - final TcaAaiEnrichmentService aaiEnrichmentService) { - return new TcaAaiEnrichmentContextImpl(tcaAppProperties, aaiEnrichmentService); + final RestTemplateBuilder restTemplateBuilder) { + return new TcaAaiEnrichmentContextImpl(tcaAppProperties, restTemplateBuilder); } } -- 2.16.6