-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/cleanCode' into CDE-195-creer-co…
…nsumer-pour-generer-les-2-fichiers-de-log # Conflicts: # src/main/java/fr/abes/logskbart/kafka/KbartListener.java # src/main/java/fr/abes/logskbart/service/KbartService.java # src/main/java/fr/abes/logskbart/service/KbartToTsvService.java
- Loading branch information
Showing
9 changed files
with
1 addition
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +0,0 @@ | ||
package fr.abes.logskbart.kafka; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import fr.abes.logskbart.dto.PackageKbartDto; | ||
import fr.abes.logskbart.dto.PackageKbartDtoKafka; | ||
import fr.abes.logskbart.exception.IllegalDateException; | ||
import fr.abes.logskbart.exception.IllegalPackageException; | ||
import fr.abes.logskbart.exception.IllegalProviderException; | ||
import fr.abes.logskbart.service.KbartService; | ||
import fr.abes.logskbart.utils.Utils; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
|
||
@Service | ||
@Slf4j | ||
public class KbartListener { | ||
|
||
// TODO Supprimer ce listener | ||
|
||
@Autowired | ||
private ObjectMapper mapper; | ||
|
||
@Autowired | ||
private KbartService service; | ||
|
||
@KafkaListener(topics = {"packageKbart"}, groupId = "lignesKbart", containerFactory = "kafkaKbartListenerContainerFactory") | ||
public void listenKbartFromKafka(ConsumerRecord<String, String> lignesKbart) { | ||
PackageKbartDto packageKbartDto = new PackageKbartDto(); | ||
try { | ||
packageKbartDto.setPackageName(Utils.extractPackageName(lignesKbart.key())); | ||
packageKbartDto.setProvider(Utils.extractProvider(lignesKbart.key())); | ||
packageKbartDto.setDatePackage(Utils.extractDate(lignesKbart.key())); | ||
PackageKbartDtoKafka packageFromKafka = mapper.readValue(lignesKbart.value(), PackageKbartDtoKafka.class); | ||
packageKbartDto.setLigneKbartDtos(packageFromKafka.getKbartDtos()); | ||
|
||
//traitement de la liste de dto à traiter en fonction | ||
service.chargerKbart(packageKbartDto); | ||
} catch (IllegalPackageException | IllegalProviderException | IllegalDateException e) { | ||
log.error("Erreur dans les données en entrée, provider / nom de package ou format de date incorrect"); | ||
} catch (JsonProcessingException e) { | ||
log.error(e.getMessage()); | ||
} | ||
} | ||
|
||
|
||
} | ||
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/main/java/fr/abes/logskbart/service/KbartLoaderFactory.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +0,0 @@ | ||
package fr.abes.logskbart.service; | ||
|
||
import fr.abes.logskbart.dto.PackageKbartDto; | ||
import fr.abes.logskbart.utils.LoaderType; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class KbartService { | ||
|
||
// TODO Supprimer cette classe | ||
|
||
private final KbartLoaderFactory factory; | ||
|
||
private final Environment env; | ||
|
||
public KbartService(KbartLoaderFactory factory, Environment env) { | ||
this.factory = factory; | ||
this.env = env; | ||
} | ||
|
||
public void chargerKbart(PackageKbartDto packageKbart) { | ||
KbartLoader loader = factory.getLoader(LoaderType.valueOf(env.getProperty("LOADERTYPE"))); | ||
loader.chargerPackageKbart(packageKbart); | ||
} | ||
} | ||
58 changes: 0 additions & 58 deletions
58
src/main/java/fr/abes/logskbart/service/KbartToBddService.java
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/main/java/fr/abes/logskbart/service/KbartToTsvService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +0,0 @@ | ||
package fr.abes.logskbart.service; | ||
|
||
import com.opencsv.bean.CsvBindByName; | ||
import com.opencsv.bean.CsvBindByPosition; | ||
import com.opencsv.bean.StatefulBeanToCsv; | ||
import com.opencsv.bean.StatefulBeanToCsvBuilder; | ||
import com.opencsv.exceptions.CsvDataTypeMismatchException; | ||
import com.opencsv.exceptions.CsvRequiredFieldEmptyException; | ||
import fr.abes.logskbart.dto.LigneKbartDto; | ||
import fr.abes.logskbart.dto.PackageKbartDto; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class KbartToTsvService implements KbartLoader { | ||
|
||
// TODO supprimer cette classe | ||
|
||
@Value("${path.tsvFile}") | ||
private String pathToFichier; | ||
|
||
@Override | ||
public void chargerPackageKbart(PackageKbartDto packageKbartDto) { | ||
try (Writer writer = new FileWriter(pathToFichier + packageKbartDto.getPackageName())) { | ||
writer.append(buildHeader(LigneKbartDto.class)); | ||
StatefulBeanToCsv<LigneKbartDto> sbc = new StatefulBeanToCsvBuilder<LigneKbartDto>(writer).withSeparator('\t').withApplyQuotesToAll(false).build(); | ||
sbc.write(packageKbartDto.getLigneKbartDtos()); | ||
} catch (IOException | CsvRequiredFieldEmptyException | CsvDataTypeMismatchException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
|
||
private String buildHeader(Class<LigneKbartDto> clazz) { | ||
return Arrays.stream(clazz.getDeclaredFields()) | ||
.filter(f -> f.getAnnotation(CsvBindByPosition.class) != null | ||
&& f.getAnnotation(CsvBindByName.class) != null) | ||
.sorted(Comparator.comparing(f -> f.getAnnotation(CsvBindByPosition.class).position())) | ||
.map(f -> f.getAnnotation(CsvBindByName.class).column()) | ||
.collect(Collectors.joining("\t")) + "\n"; | ||
} | ||
|
||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters