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

Item 311 restaurer une demande archivee #108

Merged
merged 12 commits into from
Dec 6, 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
8 changes: 5 additions & 3 deletions batch/src/main/java/fr/abes/item/batch/JobConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import fr.abes.item.core.constant.Constant;
import fr.abes.item.core.constant.TYPE_DEMANDE;
import fr.abes.item.core.service.ReferenceService;
import jakarta.persistence.EntityManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
Expand All @@ -38,6 +37,7 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.transaction.PlatformTransactionManager;

Expand All @@ -56,6 +56,7 @@ public class JobConfiguration {
private final StrategyFactory strategyFactory;
private final ProxyRetry proxyRetry;
private final ReferenceService referenceService;
private final JdbcTemplate jdbcTemplate;
@Value("${batch.min.hour}")
int minHour;

Expand All @@ -71,10 +72,11 @@ public class JobConfiguration {
private Integer nbPpnInFileResult;


public JobConfiguration(StrategyFactory strategyFactory, ProxyRetry proxyRetry, ReferenceService referenceService) {
public JobConfiguration(StrategyFactory strategyFactory, ProxyRetry proxyRetry, ReferenceService referenceService, @Qualifier("itemJdbcTemplate") JdbcTemplate jdbcTemplate) {
this.strategyFactory = strategyFactory;
this.proxyRetry = proxyRetry;
this.referenceService = referenceService;
this.jdbcTemplate = jdbcTemplate;
}

@Bean
Expand Down Expand Up @@ -123,7 +125,7 @@ public Tasklet authentifierSurSudocTasklet()

//statistiques application
@Bean
public Tasklet exportStatistiquesTasklet() { return new ExportStatistiquesTasklet(); }
public Tasklet exportStatistiquesTasklet() { return new ExportStatistiquesTasklet(jdbcTemplate); }


//Archivage automatique des demandes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public void saveExemplaire(DemandeModif demande, LigneFichierDtoModif ligneFichi
//récupération de la exemplaire correpondant à la ligne du fichier en cours
String exemplaire = traitementService.getNoticeFromEPN(ligneFichierDtoModif.getEpn());
//modification de la exemplaire d'exemplaire
Exemplaire noticeTraitee = ligneFichierModifService.getNoticeTraitee(demande, exemplaire, ligneFichierDtoMapper.getLigneFichierEntity(ligneFichierDtoModif));
traitementService.saveExemplaire(noticeTraitee.toString(), ligneFichierDtoModif.getEpn());
if (exemplaire != null) {
Exemplaire noticeTraitee = ligneFichierModifService.getNoticeTraitee(demande, exemplaire, ligneFichierDtoMapper.getLigneFichierEntity(ligneFichierDtoModif));
traitementService.saveExemplaire(noticeTraitee.toString(), ligneFichierDtoModif.getEpn());
}
} catch (IOException ex) {
log.error("Erreur de communication avec le CBS sur demande modif {} / ligne fichier n°{} / epn : {}", demande.getId(), ligneFichierDtoModif.getNumLigneFichier(), ligneFichierDtoModif.getEpn());
//si un pb de communication avec le CBS est détecté, on se reconnecte, et on renvoie l'exception pour que le retry retente la méthode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,90 @@
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.io.FileWriter;
import java.util.Date;
import java.util.List;

@Slf4j
public class ExportStatistiquesTasklet implements Tasklet, StepExecutionListener {
@Autowired
protected DataSource itemDataSource;

@Autowired
protected JdbcTemplate itemJdbcTemplate;
private final JdbcTemplate itemJdbcTemplate;

private Integer annee;
private Integer mois;
private List<NbDemandesTraiteesDto> listeDemandesTraitees;
private List<NbExemplairesTraitesDto> listeExemplairesTraites;

private Date dateDebut;
private Date dateFin;

@Value("${files.upload.statistiques.path}")
private String uploadPath;

public ExportStatistiquesTasklet(JdbcTemplate itemJdbcTemplate) {
this.itemJdbcTemplate = itemJdbcTemplate;
}


@Override
public void beforeStep(StepExecution stepExecution) {
Date dateDebut = (Date) stepExecution.getJobExecution().getExecutionContext().get("dateDebut");
Date dateFin = (Date) stepExecution.getJobExecution().getExecutionContext().get("dateFin");
annee = (int) stepExecution.getJobExecution().getExecutionContext().get("annee");
mois = (int) stepExecution.getJobExecution().getExecutionContext().get("mois");
listeDemandesTraitees = getNbDemandesTraitees(dateDebut, dateFin);
listeExemplairesTraites = getNbExemplairesTraites(dateDebut, dateFin);
this.dateDebut = (Date) stepExecution.getJobExecution().getExecutionContext().get("dateDebut");
this.dateFin = (Date) stepExecution.getJobExecution().getExecutionContext().get("dateFin");
this.annee = (int) stepExecution.getJobExecution().getExecutionContext().get("annee");
this.mois = (int) stepExecution.getJobExecution().getExecutionContext().get("mois");

}

@Override
public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull ChunkContext chunkContext) throws Exception {
try (CSVWriter writer = new CSVWriter(new FileWriter(getFilename(Constant.STAT_NBDEMANDESTRAITEES_FILENAME)), ';', CSVWriter.NO_QUOTE_CHARACTER)){
exportStatistiquesDemandesModif();
exportStatistiquesDemandesSupp();
return RepeatStatus.FINISHED;
}

private void exportStatistiquesDemandesModif() {
try (CSVWriter writer = new CSVWriter(new FileWriter(getFilename(Constant.STAT_NBDEMANDESMODIFTRAITEES_FILENAME)), ';', CSVWriter.NO_QUOTE_CHARACTER)){
List<NbDemandesTraiteesDto> listeDemandesTraitees = getNbDemandesTraiteesModif(dateDebut, dateFin);
for (NbDemandesTraiteesDto demande : listeDemandesTraitees) {
writer.writeNext(new String[]{demande.getRcr(), demande.getNbDemandesTraitees().toString()});
}
} catch (Exception e) {
log.error(Constant.ERROR_OPENING_FILE_FOR_NUMBER_OF_REQUESTS_PROCESSED_BY_RCR);
log.error(Constant.ERR_FILE_STAT_MODIF_DEMANDES);
}
try (CSVWriter writer = new CSVWriter(new FileWriter(getFilename(Constant.STAT_NBEXEMPLAIRESTRAITES_FILENAME)), ';', CSVWriter.NO_QUOTE_CHARACTER)) {
try (CSVWriter writer = new CSVWriter(new FileWriter(getFilename(Constant.STAT_NBEXEMPLAIRESMODIFTRAITES_FILENAME)), ';', CSVWriter.NO_QUOTE_CHARACTER)) {
List<NbExemplairesTraitesDto> listeExemplairesTraites = getNbExemplairesTraitesModif(dateDebut, dateFin);
for (NbExemplairesTraitesDto exemp : listeExemplairesTraites) {
writer.writeNext(new String[]{exemp.getRcr(), exemp.getTypeTraitement().toString(), exemp.getNbExemplaires().toString()});
}
} catch (Exception e) {
log.error(Constant.ERROR_OPENING_FILE_FOR_NUMBER_OF_EXEMPLARIES_PROCESSES_BY_RCR_AND_TREATMENT);
log.error(Constant.ERR_FILE_STAT_MODIF_EXEMP);
}
}

private void exportStatistiquesDemandesSupp() {
try (CSVWriter writer = new CSVWriter(new FileWriter(getFilename(Constant.STAT_NBDEMANDESSUPPTRAITEES_FILENAME)), ';', CSVWriter.NO_QUOTE_CHARACTER)){
List<NbDemandesTraiteesDto> listeDemandesTraitees = getNbDemandesTraiteesSupp(dateDebut, dateFin);
for (NbDemandesTraiteesDto demande : listeDemandesTraitees) {
writer.writeNext(new String[]{demande.getRcr(), demande.getNbDemandesTraitees().toString()});
}
} catch (Exception e) {
log.error(Constant.ERR_FILE_STAT_SUPP_DEMANDES);
}
try (CSVWriter writer = new CSVWriter(new FileWriter(getFilename(Constant.STAT_NBEXEMPLAIRESSUPPTRAITES_FILENAME)), ';', CSVWriter.NO_QUOTE_CHARACTER)) {
List<NbExemplairesSuppTraitesDto> listeExemplairesTraites = getNbExemplairesTraitesSupp(dateDebut, dateFin);
for (NbExemplairesSuppTraitesDto exemp : listeExemplairesTraites) {
writer.writeNext(new String[]{exemp.getRcr(), exemp.getNbExemplaires().toString()});
}
} catch (Exception e) {
log.error(Constant.ERR_FILE_STAT_SUPP_EXEMP);
}
return RepeatStatus.FINISHED;
}

private List<NbDemandesTraiteesDto> getNbDemandesTraitees(Date dateDebut, Date dateFin) {
String query = "select RCR, count(*) from DEMANDE_MODIF d, JOURNAL_DEMANDE_MODIF j where j.JOU_DEM_ID = d.NUM_DEMANDE and j.JOU_ETA_ID=7 and j.DATE_ENTREE between ? and ? group by d.RCR";
private List<NbDemandesTraiteesDto> getNbDemandesTraiteesModif(Date dateDebut, Date dateFin) {
String query = "select RCR, count(distinct d.NUM_DEMANDE) from DEMANDE_MODIF d join JOURNAL_DEMANDE_MODIF j on j.JOU_DEM_ID = d.NUM_DEMANDE where j.JOU_ETA_ID IN (7, 9) and j.DATE_ENTREE between ? and ? group by d.RCR";
return itemJdbcTemplate.query(query, new Object[] {dateDebut, dateFin}, new NbDemandesTraiteesMapper());
}

private List<NbExemplairesTraitesDto> getNbExemplairesTraites(Date dateDebut, Date dateFin) {
private List<NbExemplairesTraitesDto> getNbExemplairesTraitesModif(Date dateDebut, Date dateFin) {
String query = "select d.DEM_TRAIT_ID, d.RCR, count(*) " +
"from JOURNAL_DEMANDE_MODIF j, DEMANDE_MODIF d, LIGNE_FICHIER_MODIF lf " +
"where j.DATE_ENTREE between ? and ? "+
Expand All @@ -82,6 +104,20 @@ private List<NbExemplairesTraitesDto> getNbExemplairesTraites(Date dateDebut, Da
return itemJdbcTemplate.query(query, new Object[] {dateDebut, dateFin}, new NbExemplairesTraitesMapper());
}

private List<NbDemandesTraiteesDto> getNbDemandesTraiteesSupp(Date dateDebut, Date dateFin) {
String query = "select RCR, count(distinct d.NUM_DEMANDE) from DEMANDE_SUPP d join JOURNAL_DEMANDE_SUPP j on j.JOU_DEM_ID = d.NUM_DEMANDE where j.JOU_ETA_ID IN (7, 9) and j.DATE_ENTREE between ? and ? group by d.RCR";
return itemJdbcTemplate.query(query, new Object[] {dateDebut, dateFin}, new NbDemandesTraiteesMapper());
}

private List<NbExemplairesSuppTraitesDto> getNbExemplairesTraitesSupp(Date dateDebut, Date dateFin) {
String query = "select d.RCR, count(*) " +
"from JOURNAL_DEMANDE_SUPP j, DEMANDE_SUPP d, LIGNE_FICHIER_SUPP lf " +
"where j.DATE_ENTREE between ? and ? "+
"and j.JOU_ETA_ID=6 and j.JOU_DEM_ID = d.NUM_DEMANDE and d.NUM_DEMANDE = lf.REF_DEMANDE and lf.TRAITEE=1 " +
"group by d.RCR";
return itemJdbcTemplate.query(query, new Object[] {dateDebut, dateFin}, new NbExemplairesSuppTraitesMapper());
}

private String getFilename(String filename) {
return uploadPath + annee + ((mois < 10) ? '0' + mois.toString() : mois.toString()) + "_" + filename + Constant.EXTENSIONCSV;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fr.abes.item.batch.webstats;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@NoArgsConstructor
@Getter
@Setter
public class NbExemplairesSuppTraitesDto {
private String rcr;
private Integer nbExemplaires;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.abes.item.batch.webstats;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class NbExemplairesSuppTraitesMapper implements RowMapper<NbExemplairesSuppTraitesDto> {
@Override
public NbExemplairesSuppTraitesDto mapRow(ResultSet resultSet, int i) throws SQLException {
NbExemplairesSuppTraitesDto nbExemp = new NbExemplairesSuppTraitesDto();
nbExemp.setRcr(resultSet.getString("RCR"));
nbExemp.setNbExemplaires(resultSet.getInt("count"));
return nbExemp;
}
}
12 changes: 8 additions & 4 deletions core/src/main/java/fr/abes/item/core/constant/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ public class Constant implements Serializable {
public static final int TAILLEMAX = 9;

/**Specific messages on mails sents and stats*/
public static final String STAT_NBDEMANDESTRAITEES_FILENAME = "demandesTraiteesRCR";
public static final String STAT_NBEXEMPLAIRESTRAITES_FILENAME = "exemplairesTraitesTraitementRCR";
public static final String STAT_NBDEMANDESMODIFTRAITEES_FILENAME = "demandesTraiteesModifRCR";
public static final String STAT_NBEXEMPLAIRESMODIFTRAITES_FILENAME = "exemplairesModifTraitesTraitementRCR";
public static final String STAT_NBDEMANDESSUPPTRAITEES_FILENAME = "demandesSuppTraiteesRCR";
public static final String STAT_NBEXEMPLAIRESSUPPTRAITES_FILENAME = "exemplairesSuppTraitesRCR";
public static final String DEMANDE_MODIFICATION_START = "Demande de modification d'exemplaires N° ";
public static final String DEMANDE_SUPPRESSION_START = "Demande de suppression d'exemplaires N° ";
public static final String DEMANDE_EXEMPLARISATION_START = "Votre exemplarisation - ";
Expand Down Expand Up @@ -200,8 +202,10 @@ public class Constant implements Serializable {
public static final String STRATEGY_ANNOTATION_FOR_BEAN_FAILED ="Ne peut résoudre l'annotation strategy pour ce bean.";
public static final String STRATEGY_RETURN_DEFAULT_STRATEGY_NO_TYPE_DEMANDE_SELECTED = "No type_demande selected, returning default strategy";
public static final String STRATEGY_RETURN_DEFAULT_STRATEGY_NO_TYPE_DEMANDE_SPECIFIC_STRATEGY_SELECTED = "No type_demande specific strategy found, returning default strategy";
public static final String ERROR_OPENING_FILE_FOR_NUMBER_OF_REQUESTS_PROCESSED_BY_RCR = "Erreur dans l'ouverture du fichier pour nb demandeModifs traitées par RCR.";
public static final String ERROR_OPENING_FILE_FOR_NUMBER_OF_EXEMPLARIES_PROCESSES_BY_RCR_AND_TREATMENT = "Erreur dans l'ouverture du fichier pour nb exemplaires traites par RCR et Traitement.";
public static final String ERR_FILE_STAT_MODIF_DEMANDES = "Erreur dans l'ouverture du fichier pour nb demande modif traitées par RCR.";
public static final String ERR_FILE_STAT_MODIF_EXEMP = "Erreur dans l'ouverture du fichier pour nb exemplaires de demande de modif traites par RCR et Traitement.";
public static final String ERR_FILE_STAT_SUPP_DEMANDES = "Erreur dans l'ouverture du fichier pour nb demande supp traitées par RCR.";
public static final String ERR_FILE_STAT_SUPP_EXEMP = "Erreur dans l'ouverture du fichier pour nb exemplaires de demande de supp traites par RCR.";
public static final String ERROR_RESPONDING_WITH_UNAUTHORIZED_ERROR = "Erreur : répond avec une erreur d'autorisation : message - {0}";
public static final String ERROR_ACCESS_DATABASE = "Erreur acces a la base";
public static final String ERROR_GENERIC_TECHNICAL_PROBLEMS = "Nous rencontrons actuellement des problèmes techniques.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class JournalDemandeExemp implements Serializable, GenericEntity<Integer>
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="NUM_JOURNAL")
private Integer numJournal;
@Temporal(TemporalType.DATE) @Column(name="DATE_ENTREE")
@Temporal(TemporalType.TIMESTAMP) @Column(name="DATE_ENTREE")
private Date dateEntree;
@ManyToOne @JoinColumn(name="JOU_USER_ID") @NotNull
private Utilisateur user;
Expand All @@ -30,7 +30,6 @@ public class JournalDemandeExemp implements Serializable, GenericEntity<Integer>


public JournalDemandeExemp(Date dateEntree, Utilisateur user, EtatDemande etatDemande, DemandeExemp demandeExemp) {
super();
this.dateEntree = dateEntree;
this.user = user;
this.etatDemande = etatDemande;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class JournalDemandeModif implements Serializable, GenericEntity<Integer>
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="NUM_JOURNAL")
private Integer numJournal;
@Temporal(TemporalType.DATE) @Column(name="DATE_ENTREE")
@Temporal(TemporalType.TIMESTAMP) @Column(name="DATE_ENTREE")
private Date dateEntree;
@ManyToOne @JoinColumn(name="JOU_USER_ID") @NotNull
private Utilisateur user;
Expand All @@ -30,7 +30,6 @@ public class JournalDemandeModif implements Serializable, GenericEntity<Integer>


public JournalDemandeModif(Date dateEntree, Utilisateur user, EtatDemande etatDemande, DemandeModif demandeModif) {
super();
this.dateEntree = dateEntree;
this.user = user;
this.etatDemande = etatDemande;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package fr.abes.item.core.entities.item;

import fr.abes.item.core.entities.GenericEntity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

@Entity
@NoArgsConstructor
@Table(name="JOURNAL_DEMANDE_RECOUV")
@Getter
@Setter
public class JournalDemandeRecouv implements Serializable, GenericEntity<Integer> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="NUM_JOURNAL")
private Integer numJournal;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="DATE_ENTREE")
private Date dateEntree;
@ManyToOne @JoinColumn(name="JOU_USER_ID") @NotNull
private Utilisateur user;
@ManyToOne @JoinColumn(name="JOU_DEM_ID") @NotNull
private DemandeRecouv demandeRecouv;
@ManyToOne @JoinColumn(name="JOU_ETA_ID") @NotNull
private EtatDemande etatDemande;

public JournalDemandeRecouv(Date dateEntree, Utilisateur utilisateur, EtatDemande etatDemande, DemandeRecouv demandeRecouv) {
this.dateEntree = dateEntree;
this.user = utilisateur;
this.demandeRecouv = demandeRecouv;
this.etatDemande = etatDemande;
}

@Override
public Integer getId() {
return numJournal;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package fr.abes.item.core.entities.item;

import fr.abes.item.core.entities.GenericEntity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

@Entity
@NoArgsConstructor
@Table(name="JOURNAL_DEMANDE_SUPP")
@Getter
@Setter
public class JournalDemandeSupp implements Serializable, GenericEntity<Integer> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="NUM_JOURNAL")
private Integer numJournal;
@Temporal(TemporalType.TIMESTAMP) @Column(name="DATE_ENTREE")
private Date dateEntree;
@ManyToOne @JoinColumn(name="JOU_USER_ID") @NotNull
private Utilisateur user;
@ManyToOne @JoinColumn(name="JOU_DEM_ID") @NotNull
private DemandeSupp demandeSupp;
@ManyToOne @JoinColumn(name="JOU_ETA_ID") @NotNull
private EtatDemande etatDemande;

public JournalDemandeSupp(Date dateEntree, Utilisateur utilisateur, EtatDemande etatDemande, DemandeSupp demandeSupp) {
this.dateEntree = dateEntree;
this.user = utilisateur;
this.demandeSupp = demandeSupp;
this.etatDemande = etatDemande;
}

@Override
public Integer getId() {
return numJournal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@ItemConfiguration
public interface IJournalDemandeExempDao extends JpaRepository<JournalDemandeExemp, Integer> {
List<JournalDemandeExemp> findAllByDemandeExemp_NumDemandeOrderByDateEntreeDesc(Integer numDemande);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@ItemConfiguration
public interface IJournalDemandeModifDao extends JpaRepository<JournalDemandeModif, Integer> {
List<JournalDemandeModif> findAllByDemandeModif_NumDemandeOrderByDateEntreeDesc(Integer numDemande);
}
Loading
Loading