diff options
author | Kai <lukai@chinamobile.com> | 2020-03-24 15:08:35 +0800 |
---|---|---|
committer | Kai <lukai@chinamobile.com> | 2020-03-24 16:12:04 +0800 |
commit | 02b0b3fe6956e1a8b1f7a1f2c87f03443059d741 (patch) | |
tree | 6fa071434be683193f6d42e90b67afdfdf126f12 /dcae-analytics | |
parent | 5869f5d2556b4fb8e31ac0544080f31eea16717e (diff) |
fix bug: exception when aai enrichment is false1.0.1
Issue-ID: DCAEGEN2-2145
Signed-off-by: Kai Lu <lukai@chinamobile.com>
Change-Id: Ifa02ff50947b70791fb7252859e6071d7f9d45ce
Diffstat (limited to 'dcae-analytics')
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 @@ -39,35 +33,9 @@ import org.springframework.web.client.RestTemplate; 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); } } |