diff --git a/src/main/java/fr/abes/bestppn/exception/IllegalProviderException.java b/src/main/java/fr/abes/bestppn/exception/IllegalProviderException.java index f128551..64ff153 100644 --- a/src/main/java/fr/abes/bestppn/exception/IllegalProviderException.java +++ b/src/main/java/fr/abes/bestppn/exception/IllegalProviderException.java @@ -4,4 +4,8 @@ public class IllegalProviderException extends Exception { public IllegalProviderException(Exception e) { super(e); } + + public IllegalProviderException(String message) { + super(message); + } } diff --git a/src/main/java/fr/abes/bestppn/service/KbartService.java b/src/main/java/fr/abes/bestppn/service/KbartService.java index f17e3c7..d2544f9 100644 --- a/src/main/java/fr/abes/bestppn/service/KbartService.java +++ b/src/main/java/fr/abes/bestppn/service/KbartService.java @@ -1,10 +1,7 @@ package fr.abes.bestppn.service; import fr.abes.LigneKbartImprime; -import fr.abes.bestppn.exception.BestPpnException; -import fr.abes.bestppn.exception.IllegalDateException; -import fr.abes.bestppn.exception.IllegalDoiException; -import fr.abes.bestppn.exception.IllegalPackageException; +import fr.abes.bestppn.exception.*; import fr.abes.bestppn.kafka.KafkaWorkInProgress; import fr.abes.bestppn.kafka.TopicProducer; import fr.abes.bestppn.model.BestPpn; @@ -71,16 +68,16 @@ public void processConsumerRecord(LigneKbartDto ligneFromKafka, String providerN } @Transactional - public void commitDatas(String providerName, String filename) throws IllegalPackageException, IllegalDateException, ExecutionException, InterruptedException, IOException { + public void commitDatas(String providerName, String filename) throws IllegalPackageException, IllegalDateException, ExecutionException, InterruptedException, IOException, IllegalProviderException { Optional providerOpt = providerService.findByProvider(providerName); - ProviderPackage provider = providerService.handlerProvider(providerOpt, filename, providerName); - if (!workInProgress.get(filename).isBypassed()) { - producer.sendKbart(workInProgress.get(filename).getKbartToSend(), provider, filename); - producer.sendPrintNotice(workInProgress.get(filename).getPpnToCreate(), filename); - producer.sendPpnExNihilo(workInProgress.get(filename).getPpnFromKbartToCreate(), provider, filename); - } else { - producer.sendBypassToLoad(workInProgress.get(filename).getKbartToSend(), provider, filename); - } + ProviderPackage provider = providerService.handlerProvider(providerOpt, filename); + if (!workInProgress.get(filename).isBypassed()) { + producer.sendKbart(workInProgress.get(filename).getKbartToSend(), provider, filename); + producer.sendPrintNotice(workInProgress.get(filename).getPpnToCreate(), filename); + producer.sendPpnExNihilo(workInProgress.get(filename).getPpnFromKbartToCreate(), provider, filename); + } else { + producer.sendBypassToLoad(workInProgress.get(filename).getKbartToSend(), provider, filename); + } } private static LigneKbartImprime getLigneKbartImprime(BestPpn bestPpn, LigneKbartDto ligneFromKafka) { diff --git a/src/main/java/fr/abes/bestppn/service/ProviderService.java b/src/main/java/fr/abes/bestppn/service/ProviderService.java index 51e4e58..a5608d9 100644 --- a/src/main/java/fr/abes/bestppn/service/ProviderService.java +++ b/src/main/java/fr/abes/bestppn/service/ProviderService.java @@ -1,5 +1,6 @@ package fr.abes.bestppn.service; +import fr.abes.bestppn.exception.IllegalProviderException; import fr.abes.bestppn.model.entity.bacon.Provider; import fr.abes.bestppn.model.entity.bacon.ProviderPackage; import fr.abes.bestppn.exception.IllegalDateException; @@ -29,7 +30,7 @@ public ProviderService(ProviderPackageRepository providerPackageRepository, Prov this.ligneKbartRepository = ligneKbartRepository; } - public ProviderPackage handlerProvider(Optional providerOpt, String filename, String providerName) throws IllegalPackageException, IllegalDateException { + public ProviderPackage handlerProvider(Optional providerOpt, String filename) throws IllegalPackageException, IllegalDateException, IllegalProviderException { String packageName = Utils.extractPackageName(filename); Date packageDate = Utils.extractDate(filename); if (providerOpt.isPresent()) { @@ -45,12 +46,7 @@ public ProviderPackage handlerProvider(Optional providerOpt, String fi return providerPackageRepository.save(new ProviderPackage(packageName, packageDate, provider.getIdtProvider(), 'N')); } } else { - //pas de provider, ni de package, on les crée tous les deux - Provider newProvider = new Provider(providerName); - Provider savedProvider = providerRepository.save(newProvider); - log.info("Le provider " + savedProvider.getProvider() + " a été créé."); - ProviderPackage providerPackage = new ProviderPackage(packageName, packageDate, savedProvider.getIdtProvider(), 'N'); - return providerPackageRepository.save(providerPackage); + throw new IllegalProviderException("Provider et package inconnu impossible de lancer le traitement"); } }