Search in sources :

Example 6 with OperationFailedException

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

the class SousFamilleServiceImpl method sousFamilleList.

@Override
public Page<SousFamille> sousFamilleList(Pageable pageable, String search) {
    log.info("Service- SousFamilleServiceImpl Calling sousFamilleList with params :" + pageable + ", " + search);
    try {
        if (search.isEmpty()) {
            log.debug("fetching sousFamille page");
            return sousFamilleRepo.findAll(pageable);
        } else {
            log.debug("Searching by :" + search);
            // creating example
            SousFamille sousFamille = new SousFamille();
            sousFamille.setNom(search);
            Famille famille = new Famille();
            famille.setNom(search);
            Marque marque = new Marque();
            marque.setNom(search);
            sousFamille.setFamille(famille);
            sousFamille.setMarque(marque);
            // creating matcher
            ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
            Example<SousFamille> example = Example.of(sousFamille, matcher);
            log.debug("getting search results");
            return sousFamilleRepo.findAll(example, pageable);
        }
    } catch (Exception e) {
        log.debug("Failed retrieving list of SousFamilles");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : Marque(me.kadarh.mecaworks.domain.others.Marque) SousFamille(me.kadarh.mecaworks.domain.others.SousFamille) Famille(me.kadarh.mecaworks.domain.others.Famille) SousFamille(me.kadarh.mecaworks.domain.others.SousFamille) 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 7 with OperationFailedException

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

the class SousFamilleServiceImpl method add.

@Override
public SousFamille add(SousFamille sousFamille) {
    log.info("Service= SousFamilleServiceImpl - calling methode add");
    try {
        sousFamille.setFamille(familleService.get(sousFamille.getFamille().getId()));
        sousFamille.setMarque(marqueService.get(sousFamille.getMarque().getId()));
        return sousFamilleRepo.save(sousFamille);
    } catch (ResourceNotFoundException e) {
        log.debug("cannot find famille or marque , failed operation");
        throw new OperationFailedException("L'ajout de la Sous-famille a echouée,famille ou marque introuvable ", e);
    } catch (Exception e) {
        log.debug("cannot add SousFamille , failed operation");
        throw new OperationFailedException("L'ajout de la Sous-famille a echouée ", e);
    }
}
Also used : OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) NoSuchElementException(java.util.NoSuchElementException)

Example 8 with OperationFailedException

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

the class BonEnginServiceImpl method add.

/*--------------------------------------------------------------------------- */
/* ------------ CRUD METHODES -------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
@Override
public BonEngin add(BonEngin bonEngin) {
    log.info("Service= BonEnginServiceImpl - calling methode add");
    bonEngin = calculAbsoluService.fillBon(bonEngin);
    try {
        if (bonEngin.getPlein())
            bonEngin = calculService.calculConsommation(bonEngin);
        if (bonEngin.getChantierGazoil() != bonEngin.getChantierTravail()) {
            log.info("Service= BonEnginServiceImpl - Il faut inserer un bon de livraison virtuel");
            bonLivraisonService.insertBonLivraison(bonEngin);
        }
        bonEngin = bonEnginRepo.save(bonEngin);
        miseAjourBonsService.doMiseAjour(bonEngin);
        persistService.insertAlertes(bonEngin);
        log.info("Alertes Bon Engin inserted");
        persistService.insertStock(bonEngin);
        log.info("Stock Bon Engin inserted");
        persistService.insertAlerteConsommation(bonEngin);
        log.info("Alertes Bon Engin Consomation inserted");
        return bonEngin;
    } catch (DataIntegrityViolationException e) {
        log.debug("cannot add bonEngin , failed operation");
        throw new OperationFailedException("L'ajout du bonEngin a echouée , le code engin existe déjà", e);
    } catch (Exception e) {
        log.debug("cannot add bonEngin , failed operation");
        throw new OperationFailedException("L'ajout du bonEngin a echouée ", e);
    }
}
Also used : OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 9 with OperationFailedException

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

the class BonFournisseurServiceImpl method add.

@Override
public BonFournisseur add(BonFournisseur bonFournisseur) {
    log.info("Service- BonFournisseurServiceImpl Calling add ");
    try {
        bonFournisseurRepo.save(fill(bonFournisseur));
        insertStock_Fournisseur(bonFournisseur);
        return bonFournisseur;
    } catch (Exception e) {
        throw new OperationFailedException("l'ajout du bon a été suspendu, opération echouée", e);
    }
}
Also used : 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 10 with OperationFailedException

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

the class AlerteServiceImpl method hideAlert.

@Override
public void hideAlert(Long id) {
    log.info("Service- BonEnginServiceImpl Calling hideAlert with params :" + id);
    try {
        Alerte alerte = alerteRepo.getOne(id);
        alerte.setEtat(false);
        alerteRepo.save(alerte);
    } catch (Exception e) {
        log.debug("Failed hiding alert id:" + id);
        throw new OperationFailedException("Alerte introuvable", e);
    }
}
Also used : Alerte(me.kadarh.mecaworks.domain.alertes.Alerte) 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