Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evolution : ne plus créer automatiquement un nouveau provider (maintenant qu'il existe un webservice pour gérer) #89

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading