Skip to content

Commit

Permalink
Modif
Browse files Browse the repository at this point in the history
  • Loading branch information
jvk88511334 committed Apr 19, 2024
1 parent 62f031f commit 6fae563
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 28 deletions.
5 changes: 5 additions & 0 deletions batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import fr.abes.item.entities.item.LigneFichier;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
Expand All @@ -15,34 +15,54 @@
public class DemandeLoggerService {
private Demande demande;
private LigneFichier ligneFichier;
private List<Long> heureEvenements;
private String objetDeTraitementEnCours = "";
private String fonction = "";
private String operation = "";
private String alerte = "";
private String exception = "";
StringBuilder sb = new StringBuilder();

public String logInfo(){

sb.append("DEMANDE:");
sb.append("DEMANDE_NUMERO:");
if(demande != null){
sb.append(demande.getNumDemande());
sb.append("|");
}else{
sb.append("NULL");
sb.append("|");
}

sb.append("LIGNE_NUMERO:");
if(ligneFichier != null){
sb.append(ligneFichier.getNumLigneFichier());
sb.append("|");
}else{
sb.append("|");
}
sb.append("|");

if(!objetDeTraitementEnCours.isEmpty()){
sb.append("TACHE:");
sb.append(this.objetDeTraitementEnCours);
if(!fonction.isEmpty()){
sb.append("FONCTION:");
sb.append(this.fonction);
sb.append("|");
}

if(!objetDeTraitementEnCours.isEmpty()){
if(!operation.isEmpty()){
sb.append("OPERATION:");
sb.append(this.operation);
sb.append("|");
}

if(!alerte.isEmpty()){
sb.append("ALERTE:");
sb.append(this.operation);
sb.append("|");
}

if(!exception.isEmpty()){
sb.append("EXCEPTION:");
sb.append(this.exception);
sb.append("|");
}


return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ProchaineDemandeModification(int minHour, int maxHour) {

@Override
public void beforeStep(@NonNull StepExecution stepExecution) {
demandeLoggerService.setObjetDeTraitementEnCours("Obtention de la demande à traiter").setDemande(this.demande).logInfo();
log.info(demandeLoggerService.setFonction(this.getClass().getSimpleName() + "->" + getMethodeEnCours()).setOperation("Obtention de la demande à traiter").logInfo());
}

@Override
Expand All @@ -55,35 +55,34 @@ public ExitStatus afterStep(StepExecution stepExecution) {

@Override
public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull ChunkContext chunkContext) throws Exception {
demandeLoggerService.setObjetDeTraitementEnCours("Obtention de la prochaine demande à traiter");
demandeLoggerService.logInfo();
demandeLoggerService.setFonction(this.getClass().getSimpleName() + "->" + getMethodeEnCours());
try {
this.demande = (DemandeModif) demandeModifService.getIdNextDemandeToProceed(this.minHour, this.maxHour);
if (this.demande == null) {
demandeLoggerService.setObjetDeTraitementEnCours("Pas de demande à traiter, sortie");
demandeLoggerService.logInfo();
log.info(demandeLoggerService.setAlerte("Pas de demande à traiter, sortie").logInfo());
stepContribution.setExitStatus(new ExitStatus("AUCUNE DEMANDE"));
return RepeatStatus.FINISHED;
}
demandeLoggerService.setDemande(this.demande);
demandeLoggerService.setObjetDeTraitementEnCours("Passage de cette demande au statut en cours");
demandeLoggerService.logInfo();
log.info(demandeLoggerService.setDemande(this.demande).setOperation("Passage de la demande au statut en cours").logInfo());
demandeModifService.changeState(this.demande, Constant.ETATDEM_ENCOURS);
} catch (DemandeCheckingException e) {
demandeLoggerService.setException("DemandeCheckingException|" + e);
demandeLoggerService.logInfo();
log.error(demandeLoggerService.setException(e.getClass().getName() + "->" + e.getMessage()).logInfo());
stepContribution.setExitStatus(ExitStatus.FAILED);
return RepeatStatus.FINISHED;
} catch (JDBCConnectionException | ConstraintViolationException j){
log.error("Erreur hibernate JDBC");
log.error(j.toString());
log.error(demandeLoggerService.setException(j.getClass().getName() + "->" + j.getMessage()).setAlerte("Erreur Hibernate JDBC").logInfo());

} catch (DataAccessException d){
log.error("GetNextDemandeModifTasklet : Erreur d'accès à la base de donnée");
log.error(demandeLoggerService.setException(d.getClass().getName() + "->" + d.getMessage()).setAlerte("Erreur accès BDD").logInfo());
if(d.getRootCause() instanceof SQLException sqlEx){
log.error("Erreur SQL : " + sqlEx.getErrorCode());
log.error(sqlEx.getSQLState() + "|" + sqlEx.getMessage() + "|" + sqlEx.getLocalizedMessage());
log.error(demandeLoggerService.setOperation("SQL->"+ sqlEx.getErrorCode()).setAlerte(sqlEx.getSQLState() + "|" + sqlEx.getMessage() + "|" + sqlEx.getLocalizedMessage()).logInfo());
}
}
return RepeatStatus.FINISHED;
}

private static String getMethodeEnCours() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
return stackTrace[2].getMethodName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spring.batch.job.enabled=false
spring.main.banner-mode=off
logging.level.org.springframework=ERROR
logging.level.org.hibernate=ERROR
logging.level.com.zaxxer.hikari=ERROR
4 changes: 3 additions & 1 deletion batch/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ mail.ws.url=https://apicom.sudoc.fr/wsmail/
mail.admin=item@abes.fr

files.upload.path=/workdir/
files.upload.statistiques.path=/stat/
files.upload.statistiques.path=/stat/

spring.batch.job.name=jobTraiterLigneFichierExemp
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
package fr.abes.item.service.logging;

import fr.abes.item.entities.item.Demande;
import fr.abes.item.entities.item.DemandeExemp;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;

@Slf4j
@SpringBootTest
@ActiveProfiles("test")
@TestPropertySource(locations = {
"classpath:application-test-configuration.properties",
"classpath:application-localhost.properties"
})
class DemandeLoggerServiceTest {

private Demande demande;
@Test
void testLombokAccessors(){
DemandeLoggerService demandeLoggerService = new DemandeLoggerService();
//log.info(demandeLoggerService.setObjetDeTraitementEnCours("Obtention de la demande à traiter").setDemande(this.demande).logInfo());
log.info(demandeLoggerService.setFonction(this.getClass().getSimpleName() + "->" + getMethodeEnCours()).setOperation("Obtention de la demande à traiter").logInfo());
}

@Test
void testLombokAccessorsWithArguments(){
DemandeLoggerService demandeLoggerService = new DemandeLoggerService();
this.methodWithArguments(demandeLoggerService, null, "terre");
demande = new DemandeExemp();
this.methodWithArguments(demandeLoggerService, demande, "feu");
}

private void methodWithArguments(DemandeLoggerService logger, Demande demande, String argument){
log.info(logger.setFonction(this.getClass().getSimpleName() + "->" + getMethodeEnCours()).setOperation("Obtention de la demande à traiter").logInfo());
}

private static String getMethodeEnCours() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
return stackTrace[2].getMethodName();
}
}

0 comments on commit 6fae563

Please sign in to comment.