Search in sources :

Example 21 with OperationFailedException

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

the class ClasseServiceImpl method classeList.

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

Example 22 with OperationFailedException

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

the class EnginServiceImpl method add.

/**
 * @param engin to add
 * @return the engin
 */
@Override
public Engin add(Engin engin) {
    log.info("Service = EnginServiceImpl - calling methode add");
    try {
        engin.setGroupe(groupeService.get(engin.getGroupe().getId()));
        engin.setSousFamille(sousFamilleService.get(engin.getSousFamille().getId()));
        return enginRepo.save(engin);
    } catch (ResourceNotFoundException e) {
        log.debug("cannot find group or sousFamille , failed operation");
        throw new OperationFailedException("L'ajout de l'engin a echouée,sous famille ou groupe introuvable ", e);
    } catch (Exception e) {
        log.debug("cannot add engin , failed operation");
        throw new OperationFailedException("L'ajout de l'engin 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 23 with OperationFailedException

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

the class FournisseurServiceImpl method fournisseurList.

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

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

the class ChantierServiceImpl method update.

/**
 * updating the chantier
 *
 * @param chantier
 * @return
 */
@Override
public Chantier update(Chantier chantier) {
    log.info("Service= ChantierServiceImpl - calling methode update");
    try {
        Chantier old = get(chantier.getId());
        if (chantier.getNom() != null) {
            old.setNom(chantier.getNom());
        }
        if (chantier.getAdresse() != null) {
            old.setAdresse(chantier.getAdresse());
        }
        if (chantier.getStock() != null) {
            if (!chantier.getStock().equals(old.getStock())) {
                Stock stock = new Stock();
                stock.setDate(LocalDate.now());
                stock.setStockC(chantier.getStock());
                stock.setStockReel(chantier.getStock());
                stock.setChantier(old);
                Stock stockC = stockService.getLastStock(chantier);
                if (stockC != null) {
                    if (stockC.getStockC() < chantier.getStock())
                        stock.setEcart_plus(chantier.getStock() - stockC.getStockC());
                    else if (stockC.getStockC() > chantier.getStock())
                        stock.setEcart_moins(stockC.getStockC() - chantier.getStock());
                } else {
                    stock.setEcart_moins(0);
                    stock.setEcart_plus(0);
                }
                stockService.add(stock);
            }
            old.setStock(chantier.getStock());
        }
        return chantierRepo.save(old);
    } catch (Exception e) {
        log.debug("cannot update Chantier , failed operation");
        throw new OperationFailedException("La modification du Chantier a echouée ", e);
    }
}
Also used : Chantier(me.kadarh.mecaworks.domain.others.Chantier) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) Stock(me.kadarh.mecaworks.domain.others.Stock) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) NoSuchElementException(java.util.NoSuchElementException)

Example 25 with OperationFailedException

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

the class ChantierServiceImpl method add.

/**
 * @param chantier to add
 * @return the chantier
 */
@Override
public Chantier add(Chantier chantier) {
    log.info("Service= ChantierServiceImpl - calling methode add");
    try {
        Stock stock = new Stock();
        stock.setDate(LocalDate.now());
        stock.setStockC(chantier.getStock());
        stock.setStockReel(chantier.getStock());
        stock.setChantier(chantier);
        stock.setEcart_plus(0);
        stock.setEcart_moins(0);
        stockService.add(stock);
        return chantierRepo.save(chantier);
    } catch (Exception e) {
        log.debug("cannot add chantier , failed operation");
        throw new OperationFailedException("L'ajout du Chantier a echouée ", e);
    }
}
Also used : OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) Stock(me.kadarh.mecaworks.domain.others.Stock) 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