Skip to content

Commit

Permalink
FKS-706 publishing applicationCategory to Kafka
Browse files Browse the repository at this point in the history
  • Loading branch information
Erling Jahr committed Apr 23, 2024
1 parent 3a17b84 commit 81164ef
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,3 @@ private Optional<ApplicationResource> 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"

Original file line number Diff line number Diff line change
@@ -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<String,String> appCategory){
appCategory.forEach((key,value) -> {
log.info("{} :: {}", key, value);
entityProducer.send(
EntityProducerRecord.<String>builder()
.topicNameParameters(entityTopicNameParameters)
.key(key)
.value(value)
.build()

);
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@
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
@Slf4j
public class FintResourceApplikasjonsKategoriService {
private final FintCache<String, ApplikasjonskategoriResource> applikasjonskategoriResourceFintCache;
private final FintCache<String, ApplikasjonResource> applikasjonResourceFintCache;
private final ApplicationCategoryProduserService applicationCategoryProduserService;

public FintResourceApplikasjonsKategoriService(
FintCache<String, ApplikasjonskategoriResource> applikasjonskategoriResourceFintCache,
FintCache<String, ApplikasjonResource> applikasjonResourceFintCache
FintCache<String, ApplikasjonResource> applikasjonResourceFintCache, ApplicationCategoryProduserService applicationCategoryProduserService
) {
this.applikasjonskategoriResourceFintCache = applikasjonskategoriResourceFintCache;
this.applikasjonResourceFintCache = applikasjonResourceFintCache;
this.applicationCategoryProduserService = applicationCategoryProduserService;
}

public List<String> getApplikasjonskategori(LisensResource lisensResource) {
Expand All @@ -49,8 +53,8 @@ public List<String> getApplikasjonskategori(LisensResource lisensResource) {
.toList();
}


public Map<String,String> getAllApplicationCategories(){
@Scheduled(initialDelay = 5000, fixedDelay = 50000)
public Map<String,String> getAllApplicationCategoriesAndPublish(){
Map<String,String> applicationCategories = new HashMap<>();
applicationCategories = applikasjonskategoriResourceFintCache.getAllDistinct()
.stream()
Expand All @@ -61,11 +65,7 @@ public Map<String,String> getAllApplicationCategories(){
Map.Entry::getValue,
(existing, replacement) -> replacement
));

applicationCategories.forEach((key,value) -> {
log.info("{} :: {}", key, value);

});
applicationCategoryProduserService.publish(applicationCategories);


return applicationCategories;
Expand Down

0 comments on commit 81164ef

Please sign in to comment.