Search in sources :

Example 16 with OperationFailedException

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

the class GroupeServiceImpl method groupesList.

/**
 * search with nom
 *
 * @param pageable page description
 * @param search   keyword
 * @return Page
 */
@Override
public Page<Groupe> groupesList(Pageable pageable, String search) {
    log.info("Service- GroupeServiceImpl Calling GroupeList with params :" + pageable + ", " + search);
    try {
        if (search.isEmpty()) {
            log.debug("fetching Groupe page");
            return groupeRepo.findAll(pageable);
        } else {
            log.debug("Searching by :" + search);
            // creating example
            Groupe groupe = new Groupe();
            groupe.setNom(search);
            // creating matcher
            ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
            Example<Groupe> example = Example.of(groupe, matcher);
            log.debug("getting search results");
            return groupeRepo.findAll(example, pageable);
        }
    } catch (Exception e) {
        log.debug("Failed retrieving list of groupes");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : Groupe(me.kadarh.mecaworks.domain.others.Groupe) 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 17 with OperationFailedException

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

the class BonEnginServiceImpl method getPage.

/**
 * Search by Pompiste, Chauffeur, code, engin and date
 *
 * @param pageable
 * @param search
 * @return
 */
@Override
public Page<BonEngin> getPage(Pageable pageable, String search) {
    log.info("Service- BonEnginServiceImpl Calling bonEnginList with params :" + pageable + ", " + search);
    try {
        if (search.isEmpty()) {
            log.debug("fetching bonEngins page");
            return bonEnginRepo.findAll(pageable);
        } else {
            log.debug("Searching by :" + search);
            // creating example by pompiste / chauffeur / code bon / code engin
            BonEngin bonEngin = new BonEngin();
            bonEngin.setCode(search);
            bonEngin.setCompteurAbsoluKm(null);
            bonEngin.setCompteurKm(null);
            bonEngin.setCompteurH(null);
            bonEngin.setCompteurAbsoluH(null);
            bonEngin.setConsommationH(null);
            bonEngin.setConsommationKm(null);
            bonEngin.setQuantite(null);
            bonEngin.setCarburant(null);
            bonEngin.setCompteurPompe(null);
            bonEngin.setCompteurHenPanne(null);
            bonEngin.setCompteurKmenPanne(null);
            bonEngin.setNbrHeures(null);
            bonEngin.setNbrKm(null);
            bonEngin.setConsommationPrevu(null);
            bonEngin.setChargeHoraire(null);
            Employe employe = new Employe();
            employe.setNom(search);
            Engin engin = new Engin();
            engin.setCode(search);
            engin.setNumeroSerie(search);
            engin.setNumeroSerie(null);
            engin.setConsommationMoyenne(null);
            engin.setObjectif(null);
            Chantier chantier = new Chantier();
            chantier.setStock(null);
            chantier.setNom(search);
            bonEngin.setChantierGazoil(chantier);
            bonEngin.setPompiste(employe);
            bonEngin.setChauffeur(employe);
            bonEngin.setEngin(engin);
            try {
                bonEngin.setDate(LocalDate.parse(search, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            } catch (Exception e) {
                log.debug("Cannot search by date : keyword doesn't match date pattern");
            }
            // creating matcher
            ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
            Example<BonEngin> example = Example.of(bonEngin, matcher);
            log.debug("getting search results");
            return bonEnginRepo.findAll(example, pageable);
        }
    } catch (Exception e) {
        log.debug("Failed retrieving list of bons");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) me.kadarh.mecaworks.service.impl.bons.bonEngin(me.kadarh.mecaworks.service.impl.bons.bonEngin) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 18 with OperationFailedException

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

the class BonEnginServiceImpl method delete.

@Override
public void delete(Long id) {
    log.info("Service= BonEnginServiceImpl - calling methode delete");
    try {
        BonEngin bonEngin = bonEnginRepo.getOne(id);
        log.info("Suppression du dernier bon");
        Long idChantier = bonEngin.getChantierTravail().getId();
        Long idGasoil = bonEngin.getChantierGazoil().getId();
        stockManagerService.deleteStock(idGasoil, idChantier, id, TypeBon.BE);
        alerteRepo.deleteAllByBonEngin_Id(id);
        bonEnginRepo.deleteById(id);
        miseAjourBonsService.doMiseAjour(bonEngin);
        alerteRepo.findAllByIdBonEngin(bonEngin.getId()).forEach(alerteRepo::delete);
    } catch (Exception e) {
        throw new OperationFailedException("Probleme lors de la suppression du bon, ce bon ne peut pas être supprimer", e);
    }
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 19 with OperationFailedException

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

the class BonFournisseurServiceImpl method delete.

@Override
public void delete(Long id) {
    log.info("Service- BonFournisseurServiceImpl Calling delete with param id = " + id);
    try {
        BonFournisseur bonFournisseur = bonFournisseurRepo.getOne(id);
        Long idChantier = bonFournisseur.getChantier().getId();
        stockManagerService.deleteStock(null, idChantier, id, TypeBon.BF);
        bonFournisseurRepo.delete(bonFournisseur);
    } catch (NoSuchElementException e) {
        throw new ResourceNotFoundException("opération échouée , l'élement est introuvable", e);
    } catch (Exception e) {
        throw new OperationFailedException("opération echouée , la suppression du bon a echouée", e);
    }
}
Also used : BonFournisseur(me.kadarh.mecaworks.domain.bons.BonFournisseur) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) NoSuchElementException(java.util.NoSuchElementException) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) NoSuchElementException(java.util.NoSuchElementException)

Example 20 with OperationFailedException

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

the class BonFournisseurServiceImpl method bonList.

/**
 * Search by code, date, fournisseur and chantier
 *
 * @param pageable
 * @param search
 * @return
 */
@Override
public Page<BonFournisseur> bonList(Pageable pageable, String search) {
    log.info("Service- BonFournisseurServiceImpl Calling bonList with params :" + pageable + ", " + search);
    try {
        if (search.isEmpty()) {
            log.debug("fetching bonEngins page");
            return bonFournisseurRepo.findAll(pageable);
        } else {
            log.debug("Searching by :" + search);
            // creating example
            BonFournisseur bonFournisseur = new BonFournisseur();
            Chantier chantier = new Chantier();
            chantier.setNom(search);
            Fournisseur fournisseur = new Fournisseur();
            fournisseur.setNom(search);
            bonFournisseur.setChantier(chantier);
            bonFournisseur.setFournisseur(fournisseur);
            bonFournisseur.setCode(search);
            try {
                bonFournisseur.setDate(LocalDate.parse(search, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            } catch (Exception e) {
                log.debug("Cannot search by date : keyword doesn't match date pattern");
            }
            // creating matcher
            ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
            Example<BonFournisseur> example = Example.of(bonFournisseur, matcher);
            log.debug("getting search results");
            return bonFournisseurRepo.findAll(example, pageable);
        }
    } catch (Exception e) {
        log.debug("Failed retrieving list of employes");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : BonFournisseur(me.kadarh.mecaworks.domain.bons.BonFournisseur) Fournisseur(me.kadarh.mecaworks.domain.others.Fournisseur) BonFournisseur(me.kadarh.mecaworks.domain.bons.BonFournisseur) 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)

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