Skip to content

Commit

Permalink
Merge pull request #97 from abes-esr/develop
Browse files Browse the repository at this point in the history
merge dev dans test
  • Loading branch information
EryneKL authored Nov 27, 2024
2 parents 3fd0123 + 1598915 commit 97ec26b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>itembackoffice</artifactId>
<groupId>fr.abes.item</groupId>
<version>3.2.0</version>
<version>3.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
3 changes: 2 additions & 1 deletion batch/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- CONSOLE -->
<Console name="Console">
<PatternLayout
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{dark,yellow}: %msg%n%throwable" />
pattern="%style{%d{ISO8601}}{white} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{dark,yellow}: %msg%n%throwable" />
</Console>
<ItemLogAppender name="ItemLogAppender" />
</Appenders>
Expand All @@ -14,6 +14,7 @@
<AppenderRef ref="Console"/>
</Root>
<Logger name="fr.abes.item" level="debug" additivity="false">
<AppenderRef ref="Console"/>
<AppenderRef ref="ItemLogAppender"/>
</Logger>
</Loggers>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>itembackoffice</artifactId>
<groupId>fr.abes.item</groupId>
<version>3.2.0</version>
<version>3.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.*;
import java.nio.file.Path;
import java.util.List;

Expand All @@ -38,10 +35,11 @@ public void writePpnInFile(String ppn, Exemplaire exemplaire, String typeDoc) th
PrintWriter out = new PrintWriter(bw)) {
// création de la liste de référence pour trouver l'emplacement de chaque zone et sous-zone
List<String> listDeReference = referenceService.constructHeaderCsv();
listDeReference.remove(0);
listDeReference.remove(0);
listDeReference.subList(0, 4).clear();
// ajout de la ligne
out.println(typeDoc + ";" + ppn + ";" + gererZones(listDeReference, exemplaire));
String rcr = exemplaire.findZone("930", 0).findSubLabel("$b");
String epn = exemplaire.findZone("A99", 0).getValeur();
out.println(typeDoc + ";" + ppn + ";" + rcr + ";" + epn + ";" + gererZones(listDeReference, exemplaire));
} catch (IOException ex) {
throw new StorageException("Impossible d'écrire dans le fichier de sauvegarde csv");
}
Expand Down Expand Up @@ -110,13 +108,25 @@ public void checkFileContent(Demande d) throws FileCheckingException, IOExceptio
}

public void writeHeader() {
try (FileWriter fw = new FileWriter(this.getPath().resolve(this.getFilename()).toString(), true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw)) {
// ajout de la ligne
out.println(String.join(";", this.referenceService.constructHeaderCsv()));
if (!isHeaderExist()) {
try (FileWriter fw = new FileWriter(this.getPath().resolve(this.getFilename()).toString(), true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw)) {
// ajout de la ligne
out.println(String.join(";", this.referenceService.constructHeaderCsv()));
} catch (IOException ex) {
throw new StorageException(Constant.ERR_FILE_WRITING + "de sauvegarde csv");
}
}
}

private boolean isHeaderExist() {
try (FileReader fr = new FileReader(this.getPath().resolve(this.getFilename()).toString());
BufferedReader br = new BufferedReader(fr)) {
String line = br.readLine();
return line != null && line.startsWith("TYPE (008);PPN;");
} catch (IOException ex) {
throw new StorageException("Impossible d'écrire dans le fichier de sauvegarde csv");
throw new StorageException(Constant.ERR_FILE_READING + " de sauvegarde csv");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void writePpnInFile(String ppn, Exemplaire exemplaire) throws StorageExce
try (FileWriter fw = new FileWriter(this.getPath().resolve(this.getFilename()).toString(), true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw)) {
out.println(ppn);
out.println("PPN " + ppn);
out.print("\n");
out.println(exemplaire);
out.println("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public class Constant implements Serializable {
public static final String ERR_FILE_STORAGE_FILE = "Echec de stockage du fichier suivant : ";
public static final String ERR_FILE_STORAGE_FILE_UNREADABLE = "Fichier illisible, verifier que le format du fichier est bien un fichier texte.";
public static final String ERR_FILE_READING = "Ne peut pas lire le fichier : ";
public static final String ERR_FILE_WRITING = "Echec de l'écriture dans le fichier ";

/**Specific errors on file checking*/
public static final String ERR_FILE_LIGNE_ANORNALE = "L'en-tête du fichier est non conforme : il contient des caractères parasites. Merci de consulter la documentation utilisateur à cette adresse : <a href=\"http://documentation.abes.fr/aideitem/index.html\" target=\"_blank\" style=\"color:white\">http://documentation.abes.fr/aideitem/index.html</a>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public List<String> constructHeaderCsv() {
List<String> headerCsv = new ArrayList<>();
headerCsv.add("TYPE (008)");
headerCsv.add("PPN");
headerCsv.add("RCR");
headerCsv.add("EPN");
for (ZonesAutorisees zonesAutorisees: listZonesAutorisees) {
if(!zonesAutorisees.getLabelZone().startsWith("L")){
headerCsv.add(zonesAutorisees.getLabelZone()+zonesAutorisees.getSousZonesAutorisees().remove(0).getLibelle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public String[] getNoticeExemplaireAvantApres(Demande demande, LigneFichier lign
DemandeSupp demandeSupp = (DemandeSupp) demande;
try {
traitementService.authenticate("M" + demandeSupp.getRcr());
List<Exemplaire> exemplairesExistants = getExemplairesExistants(ligneFichierSupp);
List<Exemplaire> exemplairesExistants = getExemplairesExistants(ligneFichierSupp.getPpn());
//On ne conserve que les EPN de son RCR
exemplairesExistants = exemplairesExistants.stream().filter(exemplaire -> exemplaire.findZone("930", 0).findSubLabel("$b").equals(demandeSupp.getRcr())).toList();
if (exemplairesExistants.isEmpty()) {
Expand Down Expand Up @@ -393,15 +393,7 @@ public String getTypeDocumentFromPpn(String ppn) throws CBSException, IOExceptio
};
}

public List<Exemplaire> getExemplairesExistants(LigneFichierSupp ligneFichierSupp) throws IOException, QueryToSudocException, CBSException, ZoneException {
return getExemplairesExistants(ligneFichierSupp.getPpn());
}

public List<Exemplaire> getExemplairesExistants(String ppn) throws IOException, QueryToSudocException, CBSException, ZoneException {
return getExemplairesExistantsInternal(ppn);
}

private List<Exemplaire> getExemplairesExistantsInternal(String ppn) throws IOException, QueryToSudocException, CBSException, ZoneException {
String query = "che ppn " + ppn;
traitementService.getCbs().search(query);
int nbReponses = traitementService.getCbs().getNbNotices();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package fr.abes.item.core.service;

import fr.abes.cbs.exception.CBSException;
import fr.abes.cbs.exception.ZoneException;
import fr.abes.item.core.entities.item.SousZonesAutorisees;
import fr.abes.item.core.entities.item.ZonesAutorisees;
import fr.abes.item.core.exception.QueryToSudocException;
import fr.abes.item.core.repository.item.IEtatDemandeDao;
import fr.abes.item.core.repository.item.ITraitementDao;
import fr.abes.item.core.repository.item.ITypeExempDao;
Expand All @@ -15,7 +12,6 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -65,7 +61,7 @@ void constructHeaderCsv() {
Mockito.when(iZonesAutoriseesDao.findAll()).thenReturn(zonesAutoriseesList);

List<String> test = referenceService.constructHeaderCsv();
List<String> reference = List.of("TYPE (008);PPN;917$a;930$c;$d;".split(";"));
List<String> reference = List.of("TYPE (008);PPN;RCR;EPN;917$a;930$c;$d;".split(";"));

assertEquals(reference,test);

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>fr.abes.item</groupId>
<artifactId>itembackoffice</artifactId>
<version>3.2.0</version>
<version>3.2.1-SNAPSHOT</version>
<modules>
<module>core</module>
<module>web</module>
Expand Down Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>fr.abes.api-communes</groupId>
<artifactId>AccesCbs</artifactId>
<version>2.5.74</version>
<version>2.5.76</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>itembackoffice</artifactId>
<groupId>fr.abes.item</groupId>
<version>3.2.0</version>
<version>3.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down

0 comments on commit 97ec26b

Please sign in to comment.