Skip to content

Commit

Permalink
Ne plus créer automatiquement un nouveau provider
Browse files Browse the repository at this point in the history
  • Loading branch information
jvk committed Apr 17, 2024
1 parent 3c35176 commit f9fa0c1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ public class IllegalProviderException extends Exception {
public IllegalProviderException(Exception e) {
super(e);
}

public IllegalProviderException(String message) {
super(message);
}
}
23 changes: 10 additions & 13 deletions src/main/java/fr/abes/bestppn/service/KbartService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Provider> 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) {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/fr/abes/bestppn/service/ProviderService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,7 +30,7 @@ public ProviderService(ProviderPackageRepository providerPackageRepository, Prov
this.ligneKbartRepository = ligneKbartRepository;
}

public ProviderPackage handlerProvider(Optional<Provider> providerOpt, String filename, String providerName) throws IllegalPackageException, IllegalDateException {
public ProviderPackage handlerProvider(Optional<Provider> providerOpt, String filename) throws IllegalPackageException, IllegalDateException, IllegalProviderException {
String packageName = Utils.extractPackageName(filename);
Date packageDate = Utils.extractDate(filename);
if (providerOpt.isPresent()) {
Expand All @@ -45,12 +46,7 @@ public ProviderPackage handlerProvider(Optional<Provider> 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");
}
}

Expand Down

0 comments on commit f9fa0c1

Please sign in to comment.