diff options
Diffstat (limited to 'prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java')
-rw-r--r-- | prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java index 4a7d9282..505d2a9a 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java @@ -19,25 +19,19 @@ */ package org.onap.dcaegen2.services.prh.tasks; -import com.google.gson.Gson; import org.onap.dcaegen2.services.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.configuration.AppConfig; import org.onap.dcaegen2.services.prh.configuration.Config; import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; -import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.services.service.AAIProducerClient; -import org.onap.dcaegen2.services.utils.HttpRequestDetails; +import org.onap.dcaegen2.services.service.HttpUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Optional; +import java.io.IOException; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 @@ -45,11 +39,10 @@ import java.util.Optional; @Component public class AAIProducerTaskImpl extends AAIProducerTask<AAIClientConfiguration, ConsumerDmaapModel, Object> { - private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); + private static final Logger logger = LoggerFactory.getLogger(AAIProducerTaskImpl.class); private final Config prhAppConfig; - private AAIProducerClient producerClient; - private Optional<String> response; + @Autowired public AAIProducerTaskImpl(AppConfig prhAppConfig) { @@ -59,19 +52,24 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIClientConfiguration, @Override protected Object publish(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException { logger.trace("Method %M called with arg {}", consumerDmaapModel); - producerClient = new AAIProducerClient(prhAppConfig.getAAIClientConfiguration()); - //TODO: @Piotr Wielebski - response = producerClient.getHttpResponse(null); - return response.get(); + AAIProducerClient producerClient = new AAIProducerClient(resolveConfiguration()); + try { + return producerClient.getHttpResponse(consumerDmaapModel) + .filter(HttpUtils::isSuccessfulResponseCode); + } catch (IOException e) { + logger.warn("Patch request not successful", e); + throw new AAINotFoundException("Patch request not successful"); + } } @Override - public Object execute(Object object) throws PrhTaskException { + public Object execute(Object object) throws AAINotFoundException { logger.trace("Method %M called with arg {}", object); + if (object instanceof ConsumerDmaapModel) { - //TODO: @Piotr Wielebski return publish((ConsumerDmaapModel) object); } + throw new AAINotFoundException("Incorrect object type"); } @@ -84,5 +82,4 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIClientConfiguration, protected AAIClientConfiguration resolveConfiguration() { return prhAppConfig.getAAIClientConfiguration(); } - } |