From 81164ef9777ff26a48e05d54571b1be701e4c562 Mon Sep 17 00:00:00 2001 From: Erling Jahr Date: Tue, 23 Apr 2024 11:49:49 +0200 Subject: [PATCH] FKS-706 publishing applicationCategory to Kafka --- .../ApplicationResourceService.java | 7 --- .../ApplicationCategoryProduserService.java | 46 +++++++++++++++++++ ...ntResourceApplikasjonsKategoriService.java | 16 +++---- 3 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 src/main/java/no/fintlabs/fintResourceServices/ApplicationCategoryProduserService.java diff --git a/src/main/java/no/fintlabs/applicationResource/ApplicationResourceService.java b/src/main/java/no/fintlabs/applicationResource/ApplicationResourceService.java index f427971..a57fcdc 100644 --- a/src/main/java/no/fintlabs/applicationResource/ApplicationResourceService.java +++ b/src/main/java/no/fintlabs/applicationResource/ApplicationResourceService.java @@ -84,10 +84,3 @@ private Optional createApplicationResource(LisensResource l return Optional.of(applicationResource); } } - - -// ** Avventer ** -// - applicationAccessType("") Applikasjonstilgang eller applikasjonsrolletilgang. -// - applicationAccessRole("") Evt rolle til intern tilgang i app. Ref qlik. applicationAccesstype må være -// "applikasjonsrolletilgang for at dette feltet er fylt ut" - diff --git a/src/main/java/no/fintlabs/fintResourceServices/ApplicationCategoryProduserService.java b/src/main/java/no/fintlabs/fintResourceServices/ApplicationCategoryProduserService.java new file mode 100644 index 0000000..32a592a --- /dev/null +++ b/src/main/java/no/fintlabs/fintResourceServices/ApplicationCategoryProduserService.java @@ -0,0 +1,46 @@ +package no.fintlabs.fintResourceServices; + + +import lombok.extern.slf4j.Slf4j; +import no.fintlabs.kafka.entity.EntityProducer; +import no.fintlabs.kafka.entity.EntityProducerFactory; +import no.fintlabs.kafka.entity.EntityProducerRecord; +import no.fintlabs.kafka.entity.topic.EntityTopicNameParameters; +import no.fintlabs.kafka.entity.topic.EntityTopicService; +import org.springframework.stereotype.Service; + +import java.util.Map; + +@Service +@Slf4j +public class ApplicationCategoryProduserService { + private final EntityProducer entityProducer; + private final EntityTopicNameParameters entityTopicNameParameters; + + + public ApplicationCategoryProduserService( + EntityProducerFactory entityProducerFactory, + EntityTopicService entityTopicService) { + + entityProducer = entityProducerFactory.createProducer(String.class); + entityTopicNameParameters = EntityTopicNameParameters + .builder() + .resource("applicationcategory") + .build(); + entityTopicService.ensureTopic(entityTopicNameParameters,0); + } + + public void publish(Map appCategory){ + appCategory.forEach((key,value) -> { + log.info("{} :: {}", key, value); + entityProducer.send( + EntityProducerRecord.builder() + .topicNameParameters(entityTopicNameParameters) + .key(key) + .value(value) + .build() + + ); + }); + }; +} diff --git a/src/main/java/no/fintlabs/fintResourceServices/FintResourceApplikasjonsKategoriService.java b/src/main/java/no/fintlabs/fintResourceServices/FintResourceApplikasjonsKategoriService.java index 28e6513..1fd126b 100644 --- a/src/main/java/no/fintlabs/fintResourceServices/FintResourceApplikasjonsKategoriService.java +++ b/src/main/java/no/fintlabs/fintResourceServices/FintResourceApplikasjonsKategoriService.java @@ -7,9 +7,11 @@ import no.fintlabs.fintResourceModels.resource.eiendeler.applikasjon.LisensResource; import no.fintlabs.fintResourceModels.resource.eiendeler.applikasjon.kodeverk.ApplikasjonskategoriResource; import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.util.*; +import java.util.function.BiConsumer; import java.util.stream.Collectors; @Service @@ -17,13 +19,15 @@ public class FintResourceApplikasjonsKategoriService { private final FintCache applikasjonskategoriResourceFintCache; private final FintCache applikasjonResourceFintCache; + private final ApplicationCategoryProduserService applicationCategoryProduserService; public FintResourceApplikasjonsKategoriService( FintCache applikasjonskategoriResourceFintCache, - FintCache applikasjonResourceFintCache + FintCache applikasjonResourceFintCache, ApplicationCategoryProduserService applicationCategoryProduserService ) { this.applikasjonskategoriResourceFintCache = applikasjonskategoriResourceFintCache; this.applikasjonResourceFintCache = applikasjonResourceFintCache; + this.applicationCategoryProduserService = applicationCategoryProduserService; } public List getApplikasjonskategori(LisensResource lisensResource) { @@ -49,8 +53,8 @@ public List getApplikasjonskategori(LisensResource lisensResource) { .toList(); } - - public Map getAllApplicationCategories(){ +@Scheduled(initialDelay = 5000, fixedDelay = 50000) + public Map getAllApplicationCategoriesAndPublish(){ Map applicationCategories = new HashMap<>(); applicationCategories = applikasjonskategoriResourceFintCache.getAllDistinct() .stream() @@ -61,11 +65,7 @@ public Map getAllApplicationCategories(){ Map.Entry::getValue, (existing, replacement) -> replacement )); - - applicationCategories.forEach((key,value) -> { - log.info("{} :: {}", key, value); - - }); + applicationCategoryProduserService.publish(applicationCategories); return applicationCategories;