Search in sources :

Example 26 with OperationFailedException

use of me.kadarh.mecaworks.service.exceptions.OperationFailedException in project mecaworks by KadarH.

the class ChantierServiceImpl method chantierList.

/**
 * search with nom and adresse
 *
 * @param pageable page description
 * @param search   keyword
 * @return Page
 */
@Override
public Page<Chantier> chantierList(Pageable pageable, String search) {
    log.info("Service- ChantierServiceImpl Calling chantierList with params :" + pageable + ", " + search);
    try {
        if (search.isEmpty()) {
            log.debug("fetching chantier page");
            return chantierRepo.findAll(pageable);
        } else {
            log.debug("Searching by :" + search);
            // creating example
            Chantier chantier = new Chantier();
            chantier.setNom(search);
            chantier.setAdresse(search);
            // creating matcher
            ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
            Example<Chantier> example = Example.of(chantier, matcher);
            log.debug("getting search results");
            return chantierRepo.findAll(example, pageable);
        }
    } catch (Exception e) {
        log.debug("Failed retrieving list of chantiers");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : Chantier(me.kadarh.mecaworks.domain.others.Chantier) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) NoSuchElementException(java.util.NoSuchElementException)

Example 27 with OperationFailedException

use of me.kadarh.mecaworks.service.exceptions.OperationFailedException in project mecaworks by KadarH.

the class BonFilterServiceImpl method filterBonLivraison.

@Override
public List<BonLivraison> filterBonLivraison(BonLivraisonDto bonLivraisonDto) {
    try {
        String chantier_Depart = bonLivraisonDto.getChantierDepart().equals("") ? null : bonLivraisonDto.getChantierDepart();
        String chantier_Arrivee = bonLivraisonDto.getChantierArrivee().equals("") ? null : bonLivraisonDto.getChantierArrivee();
        String transporteur = bonLivraisonDto.getTransporteur().equals("") ? null : bonLivraisonDto.getTransporteur();
        String pompiste = bonLivraisonDto.getPompiste().equals("") ? null : bonLivraisonDto.getPompiste();
        BonLivraison bonLivraison = new BonLivraison();
        bonLivraison.setQuantite(null);
        Chantier chantierDepart = new Chantier();
        chantierDepart.setNom(chantier_Depart);
        chantierDepart.setStock(null);
        Chantier chantierArrivee = new Chantier();
        chantierArrivee.setNom(chantier_Arrivee);
        chantierArrivee.setStock(null);
        Employe trans = new Employe();
        trans.setNom(transporteur);
        Employe pompist = new Employe();
        pompist.setNom(pompiste);
        bonLivraison.setChantierDepart(chantierDepart);
        bonLivraison.setChantierArrivee(chantierArrivee);
        bonLivraison.setPompiste(pompist);
        bonLivraison.setTransporteur(trans);
        ExampleMatcher matcher = ExampleMatcher.matchingAll().withStringMatcher(ExampleMatcher.StringMatcher.EXACT).withIgnoreCase().withIgnoreNullValues();
        Example<BonLivraison> example = Example.of(bonLivraison, matcher);
        log.debug("getting search results");
        List<BonLivraison> page = bonLivraisonRepo.findAll(example);
        try {
            page = page.stream().filter(bonLivraison1 -> bonLivraison1.getDate().isBefore(LocalDate.parse(bonLivraisonDto.getDateTo(), DateTimeFormatter.ofPattern("yyyy-MM-dd"))) || bonLivraison1.getDate().isEqual(LocalDate.parse(bonLivraisonDto.getDateTo(), DateTimeFormatter.ofPattern("yyyy-MM-dd")))).filter(bonLivraison1 -> bonLivraison1.getDate().isAfter(LocalDate.parse(bonLivraisonDto.getDateFrom(), DateTimeFormatter.ofPattern("yyyy-MM-dd"))) || bonLivraison1.getDate().isEqual(LocalDate.parse(bonLivraisonDto.getDateFrom(), DateTimeFormatter.ofPattern("yyyy-MM-dd")))).collect(Collectors.toList());
        } catch (DateTimeParseException e) {
            return page;
        }
        log.debug("filter by dates successfully");
        return page;
    } catch (Exception e) {
        log.debug("Failed retrieving list of bons");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : BonEnginRepo(me.kadarh.mecaworks.repo.bons.BonEnginRepo) BonFournisseur(me.kadarh.mecaworks.domain.bons.BonFournisseur) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) BonEnginDto(me.kadarh.mecaworks.domain.dtos.BonEnginDto) Example(org.springframework.data.domain.Example) Collectors(java.util.stream.Collectors) BonFournisseurDto(me.kadarh.mecaworks.domain.dtos.BonFournisseurDto) BonFilterService(me.kadarh.mecaworks.service.bons.BonFilterService) ArrayList(java.util.ArrayList) Slf4j(lombok.extern.slf4j.Slf4j) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) BonFournisseurRepo(me.kadarh.mecaworks.repo.bons.BonFournisseurRepo) ChronoUnit(java.time.temporal.ChronoUnit) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) BonLivraisonRepo(me.kadarh.mecaworks.repo.bons.BonLivraisonRepo) BonLivraisonDto(me.kadarh.mecaworks.domain.dtos.BonLivraisonDto) me.kadarh.mecaworks.domain.others(me.kadarh.mecaworks.domain.others) Transactional(org.springframework.transaction.annotation.Transactional) BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) DateTimeParseException(java.time.format.DateTimeParseException) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DateTimeParseException(java.time.format.DateTimeParseException)

Example 28 with OperationFailedException

use of me.kadarh.mecaworks.service.exceptions.OperationFailedException in project mecaworks by KadarH.

the class BonLivraisonServiceImpl method bonList.

/**
 * Search by any attribute of BonLivraison if possible
 *
 * @param pageable
 * @param search   keyword
 * @return Page of results
 */
@Override
public Page<BonLivraison> bonList(Pageable pageable, String search) {
    try {
        if (search.isEmpty()) {
            log.debug("fetching bonLivraison page");
            return bonLivraisonRepo.findAll(pageable);
        } else {
            log.debug("Searching by :" + search);
            // creating example
            // Searching by code, date, quantité, nom chantier, nom employe
            BonLivraison bonLivraison = new BonLivraison();
            Chantier chantier = new Chantier();
            chantier.setNom(search);
            bonLivraison.setChantierDepart(chantier);
            bonLivraison.setChantierArrivee(chantier);
            Employe employe = new Employe();
            employe.setNom(search);
            bonLivraison.setPompiste(employe);
            bonLivraison.setTransporteur(employe);
            bonLivraison.setCode(search);
            try {
                bonLivraison.setDate(LocalDate.parse(search, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            } catch (Exception e) {
                log.debug("Cannot search by date : keyword doesn't match date pattern");
            }
            try {
                bonLivraison.setQuantite(Integer.valueOf(search));
            } catch (Exception e) {
                log.debug("Cannot search by quantité : keyword is not a number");
            }
            // creating matcher
            ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
            Example<BonLivraison> example = Example.of(bonLivraison, matcher);
            Pageable pageable1 = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "date"));
            log.debug("getting search results");
            return bonLivraisonRepo.findAll(example, pageable1);
        }
    } catch (Exception e) {
        log.debug("Failed retrieving list of bons de Lisvraison");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) Chantier(me.kadarh.mecaworks.domain.others.Chantier) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) Employe(me.kadarh.mecaworks.domain.others.Employe) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) NoSuchElementException(java.util.NoSuchElementException)

Example 29 with OperationFailedException

use of me.kadarh.mecaworks.service.exceptions.OperationFailedException in project mecaworks by KadarH.

the class FillServiceImpl method fillBonEnginPart1.

public BonEngin fillBonEnginPart1(BonEngin bon) {
    try {
        bon.setEngin(enginService.get(bon.getEngin().getId()));
        bon.setChauffeur(employeService.get(bon.getChauffeur().getId()));
        bon.setPompiste(employeService.get(bon.getPompiste().getId()));
        bon.setChantierTravail(chantierService.get(bon.getChantierTravail().getId()));
        bon.setChantierGazoil(chantierService.get(bon.getChantierGazoil().getId()));
        if (bon.getCompteurH() == null)
            bon.setCompteurH(0L);
        if (bon.getCompteurKm() == null)
            bon.setCompteurKm(0L);
        return bon;
    } catch (Exception e) {
        throw new OperationFailedException("Operation echouée", e);
    }
}
Also used : OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException)

Example 30 with OperationFailedException

use of me.kadarh.mecaworks.service.exceptions.OperationFailedException in project mecaworks by KadarH.

the class FillServiceImpl method fillBonEnginPart2.

public BonEngin fillBonEnginPart2(BonEngin bon) {
    try {
        bon.setConsommationPrevu(bon.getEngin().getConsommationMoyenne().longValue() * bon.getNbrHeures());
        bon.setChargeHoraire(bon.getNbrHeures() * bon.getEngin().getPrixLocationJournalier().longValue() / bon.getEngin().getObjectif());
        log.info("Compteur Absolu H = " + bon.getCompteurAbsoluH());
        log.info("Compteur Absolu Km = " + bon.getCompteurAbsoluKm());
        log.info("Nombre Heure travaillé  = " + bon.getNbrHeures());
        log.info("Bon has been filled correctly");
        return bon;
    } catch (Exception e) {
        throw new OperationFailedException("Operation echouée", e);
    }
}
Also used : OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException)

Aggregations

OperationFailedException (me.kadarh.mecaworks.service.exceptions.OperationFailedException)32 ResourceNotFoundException (me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException)21 NoSuchElementException (java.util.NoSuchElementException)19 ExampleMatcher (org.springframework.data.domain.ExampleMatcher)14 BonEngin (me.kadarh.mecaworks.domain.bons.BonEngin)9 BonLivraison (me.kadarh.mecaworks.domain.bons.BonLivraison)8 BonFournisseur (me.kadarh.mecaworks.domain.bons.BonFournisseur)7 Chantier (me.kadarh.mecaworks.domain.others.Chantier)6 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)6 LocalDate (java.time.LocalDate)5 ChronoUnit (java.time.temporal.ChronoUnit)5 Collectors (java.util.stream.Collectors)5 Slf4j (lombok.extern.slf4j.Slf4j)5 BonEnginRepo (me.kadarh.mecaworks.repo.bons.BonEnginRepo)5 BonFournisseurRepo (me.kadarh.mecaworks.repo.bons.BonFournisseurRepo)5 BonLivraisonRepo (me.kadarh.mecaworks.repo.bons.BonLivraisonRepo)5 Service (org.springframework.stereotype.Service)5 Transactional (org.springframework.transaction.annotation.Transactional)5 DateTimeParseException (java.time.format.DateTimeParseException)4 ArrayList (java.util.ArrayList)4