Skip to content

Commit

Permalink
FEAT : ajout simulation pour suppression exemplaires :
Browse files Browse the repository at this point in the history
- ajout méthode calcul exemplaires avant / après traitement
- Ajout changement d'état simulation
  • Loading branch information
pierre-maraval committed Sep 16, 2024
1 parent 3956a1c commit a795035
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import fr.abes.item.core.entities.item.EtatDemande;
import fr.abes.item.core.entities.item.IndexRecherche;
import fr.abes.item.core.entities.item.Traitement;
import fr.abes.item.core.entities.item.TypeExemp;
import fr.abes.item.core.repository.item.IEtatDemandeDao;
import fr.abes.item.core.repository.item.ITraitementDao;
import fr.abes.item.core.repository.item.ITypeExempDao;
import org.springframework.stereotype.Service;

Expand All @@ -15,10 +17,12 @@
public class ReferenceService {
private final IEtatDemandeDao etatDemandeDao;
private final ITypeExempDao typeExempDao;
private final ITraitementDao traitementDao;

public ReferenceService(IEtatDemandeDao etatDemandeDao, ITypeExempDao typeExempDao) {
public ReferenceService(IEtatDemandeDao etatDemandeDao, ITypeExempDao typeExempDao, ITraitementDao traitementDao) {
this.etatDemandeDao = etatDemandeDao;
this.typeExempDao = typeExempDao;
this.traitementDao = traitementDao;
}


Expand All @@ -43,4 +47,22 @@ public TypeExemp findTypeExempById(Integer id) {
public Set<IndexRecherche> getIndexRechercheFromTypeExemp(Integer id) {
return typeExempDao.findById(id).get().getIndexRechercheSet();
}

/**
* Retourner l'ensemble de la liste des traitements disponibles
*
* @return liste de tous les traitements
*/
public List<Traitement> findAll() {
return traitementDao.findAllByOrderByNumTraitementAsc();
}

public Traitement findTraitementById(Integer id) {
Optional<Traitement> traitement = traitementDao.findById(id);
return traitement.orElseThrow();
}

public Integer findTraitementByDemandeId(Integer id) {
return traitementDao.findTraitementByDemandeModifId(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import fr.abes.cbs.utilitaire.Constants;
import fr.abes.cbs.utilitaire.Utilitaire;
import fr.abes.item.core.constant.Constant;
import fr.abes.item.core.entities.item.Traitement;
import fr.abes.item.core.repository.item.ITraitementDao;
import fr.abes.item.core.utilitaire.Utilitaires;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -21,12 +19,10 @@
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Optional;

@Slf4j
@Service
public class TraitementService {
private final ITraitementDao traitementDao;

@Value("${sudoc.serveur}")
private String serveurSudoc;
Expand All @@ -39,8 +35,7 @@ public class TraitementService {
private ProcessCBS cbs;


public TraitementService(ITraitementDao traitementDao) {
this.traitementDao = traitementDao;
public TraitementService() {
cbs = new ProcessCBS();
}

Expand Down Expand Up @@ -209,23 +204,7 @@ public void disconnect() throws CBSException {
}


/**
* Retourner l'ensemble de la liste des traitements disponibles
*
* @return liste de tous les traitements
*/
public List<Traitement> findAll() {
return traitementDao.findAllByOrderByNumTraitementAsc();
}

public Traitement findTraitementById(Integer id) {
Optional<Traitement> traitement = traitementDao.findById(id);
return traitement.orElseThrow();
}

public Integer findTraitementByDemandeId(Integer id) {
return traitementDao.findTraitementByDemandeModifId(id);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ public String getQueryToSudoc(String code, Integer type, String[] valeurs) throw

public Demande majTraitement(Integer demandeId, Integer traitementId) {
DemandeModif demandeModif = this.findById(demandeId);
Traitement traitement = traitementService.findTraitementById(traitementId);
Traitement traitement = referenceService.findTraitementById(traitementId);
if (demandeModif != null) {
demandeModif.setDateModification(Calendar.getInstance().getTime());
demandeModif.setTraitement(traitement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import fr.abes.cbs.exception.CBSException;
import fr.abes.cbs.exception.ZoneException;
import fr.abes.cbs.notices.Exemplaire;
import fr.abes.item.core.components.*;
import fr.abes.item.core.configuration.factory.FichierFactory;
import fr.abes.item.core.configuration.factory.Strategy;
import fr.abes.item.core.constant.Constant;
import fr.abes.item.core.constant.TYPE_DEMANDE;
import fr.abes.item.core.constant.TYPE_SUPPRESSION;
import fr.abes.item.core.entities.item.Demande;
import fr.abes.item.core.entities.item.DemandeSupp;
import fr.abes.item.core.entities.item.EtatDemande;
import fr.abes.item.core.entities.item.LigneFichier;
import fr.abes.item.core.entities.item.*;
import fr.abes.item.core.exception.DemandeCheckingException;
import fr.abes.item.core.exception.FileCheckingException;
import fr.abes.item.core.exception.FileTypeException;
Expand All @@ -21,6 +19,7 @@
import fr.abes.item.core.service.*;
import fr.abes.item.core.utilitaire.Utilitaires;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.Level;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -29,6 +28,7 @@
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
Expand All @@ -39,6 +39,7 @@ public class DemandeSuppService extends DemandeService implements IDemandeServic
private final ReferenceService referenceService;
private final UtilisateurService utilisateurService;
private final FileSystemStorageService storageService;
private final TraitementService traitementService;

private FichierInitialSupp fichierInit;
private FichierPrepareSupp fichierPrepare;
Expand All @@ -48,7 +49,7 @@ public class DemandeSuppService extends DemandeService implements IDemandeServic
@Value("${files.upload.path}")
private String uploadPath;

public DemandeSuppService(ILibProfileDao libProfileDao, IDemandeSuppDao demandeSuppDao, FileSystemStorageService storageService, ReferenceService referenceService, UtilisateurService utilisateurService, Ppntoepn procStockeePpnToEpn, Epntoppn procStockeeEpnToPpn, LigneFichierSuppService ligneFichierSuppService) {
public DemandeSuppService(ILibProfileDao libProfileDao, IDemandeSuppDao demandeSuppDao, FileSystemStorageService storageService, ReferenceService referenceService, UtilisateurService utilisateurService, Ppntoepn procStockeePpnToEpn, Epntoppn procStockeeEpnToPpn, LigneFichierSuppService ligneFichierSuppService, TraitementService traitementService) {
super(libProfileDao);
this.demandeSuppDao = demandeSuppDao;
this.storageService = storageService;
Expand All @@ -57,6 +58,7 @@ public DemandeSuppService(ILibProfileDao libProfileDao, IDemandeSuppDao demandeS
this.procStockeePpnToEpn = procStockeePpnToEpn;
this.procStockeeEpnToPpn = procStockeeEpnToPpn;
this.ligneFichierService = ligneFichierSuppService;
this.traitementService = traitementService;
}

@Override
Expand Down Expand Up @@ -166,7 +168,7 @@ private void checkEtatDemande(DemandeSupp demande) throws DemandeCheckingExcepti

ligneFichierService.saveFile(storageService.loadAsResource(fichier.getFilename()).getFile(), demande);

changeState(demande, Constant.ETATDEM_ATTENTE);
changeState(demande, Constant.ETATDEM_SIMULATION);
}
}
}
Expand Down Expand Up @@ -353,10 +355,58 @@ public Demande returnState(Integer etape, Demande demande) throws DemandeCheckin
}

@Override
public String[] getNoticeExemplaireAvantApres(Demande demande, LigneFichier ligneFichier) throws
CBSException, ZoneException, IOException {
//todo
return new String[0];
public String[] getNoticeExemplaireAvantApres(Demande demande, LigneFichier ligneFichier) throws CBSException, ZoneException, IOException {
LigneFichierSupp ligneFichierSupp = (LigneFichierSupp) ligneFichier;
DemandeSupp demandeSupp = (DemandeSupp) demande;
try {
traitementService.authenticate("M" + demandeSupp.getRcr());
List<Exemplaire> exemplairesExistants = getExemplairesExistants(ligneFichierSupp);
if (exemplairesExistants.isEmpty()) {
return new String[] {
ligneFichierSupp.getPpn(),
"Pas d'exemplaire pour ce RCR",
"Pas d'exemplaire pour ce RCR"
};
}
List<Exemplaire> exemplairesRestants = suppExemlaire(exemplairesExistants, ligneFichierSupp.getEpn());

return new String[]{
ligneFichierSupp.getPpn(),
exemplairesExistants.stream().map(Exemplaire::toString).collect(Collectors.joining("\r\n")),
exemplairesRestants.stream().map(Exemplaire::toString).collect(Collectors.joining("\r\n"))
};
}catch (QueryToSudocException ex) {
throw new CBSException(Level.ERROR, ex.getMessage());
} finally {
traitementService.disconnect();
}
}

private List<Exemplaire> getExemplairesExistants(LigneFichierSupp ligneFichierSupp) throws IOException, QueryToSudocException, CBSException, ZoneException {
String query = "che ppn " + ligneFichierSupp.getPpn();
traitementService.getCbs().search(query);
int nbReponses = traitementService.getCbs().getNbNotices();
return switch (nbReponses) {
case 0 -> throw new QueryToSudocException(Constant.ERR_FILE_NOTICE_NOT_FOUND);
case 1 -> {
String notice = traitementService.getCbs().getClientCBS().mod("1", String.valueOf(traitementService.getCbs().getLotEncours()));
String exemplaires = Utilitaires.getExemplairesExistants(notice);
List<Exemplaire> exempList = new ArrayList<>();
if (!exemplaires.isEmpty()) {
for (String s : exemplaires.split("\r\r\r")) {
if (!s.isEmpty())
exempList.add(new Exemplaire(s));
}
}
yield exempList;
}
default ->
throw new QueryToSudocException(Constant.ERR_FILE_MULTIPLES_NOTICES_FOUND + traitementService.getCbs().getListePpn());
};
}

private List<Exemplaire> suppExemlaire(List<Exemplaire> exemplairesExistants, String epn) {
return exemplairesExistants.stream().filter(exemplaire -> !exemplaire.findZone("A99", 0).getValeur().equals(epn)).collect(Collectors.toList());
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions web/src/main/java/fr/abes/item/web/TraitementRestService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.abes.item.web;

import fr.abes.item.core.entities.item.Traitement;
import fr.abes.item.core.service.TraitementService;
import fr.abes.item.core.service.ReferenceService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -13,10 +13,10 @@
@RestController
@RequestMapping("/api/v1")
public class TraitementRestService {
private final TraitementService traitementService;
private final ReferenceService referenceService;

public TraitementRestService(TraitementService traitementService) {
this.traitementService = traitementService;
public TraitementRestService(ReferenceService referenceService) {
this.referenceService = referenceService;
}

/**
Expand All @@ -27,12 +27,12 @@ public TraitementRestService(TraitementService traitementService) {
@GetMapping(value = "/traitements")
@Operation(summary = "permet de récupérer la liste des traitements relatifs à une demandeModif")
public List<Traitement> getTraitements() {
return traitementService.findAll();
return referenceService.findAll();
}

@GetMapping(value = "/traitementFromDemande/{id}")
@Operation(summary = "permet de récupérer le type de traitement choisi pour une demande")
public Integer getTraitementFromDemande(@PathVariable Integer id) {
return traitementService.findTraitementByDemandeId(id);
return referenceService.findTraitementByDemandeId(id);
}
}

0 comments on commit a795035

Please sign in to comment.