Search in sources :

Example 11 with OperationFailedException

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

the class EnginServiceImpl method enginList.

@Override
public Page<Engin> enginList(Pageable pageable, String search) {
    log.info("Service- EnginServiceImpl Calling enginList with params :" + pageable + ", " + search);
    try {
        if (search.isEmpty()) {
            log.debug("fetching engin page");
            return enginRepo.findAll(pageable);
        } else {
            log.debug("Searching by :" + search);
            // creating example
            Engin engin = new Engin();
            engin.setNumeroSerie(search);
            engin.setCode(search);
            // sousfamille
            SousFamille sousFamille = new SousFamille();
            sousFamille.setNom(search);
            // groupe
            Groupe groupe = new Groupe();
            groupe.setNom(search);
            // setting groupe , soufamille to engin
            engin.setGroupe(groupe);
            engin.setSousFamille(sousFamille);
            engin.setObjectif(null);
            engin.setConsommationMoyenne(null);
            // creating matcher
            ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
            Example<Engin> example = Example.of(engin, matcher);
            log.debug("getting search results");
            return enginRepo.findAll(example, pageable);
        }
    } catch (Exception e) {
        log.debug("Failed retrieving list of engins");
        throw new OperationFailedException("Operation échouée, problème de saisi", e);
    }
}
Also used : SousFamille(me.kadarh.mecaworks.domain.others.SousFamille) Groupe(me.kadarh.mecaworks.domain.others.Groupe) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) Engin(me.kadarh.mecaworks.domain.others.Engin) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) NoSuchElementException(java.util.NoSuchElementException)

Example 12 with OperationFailedException

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

the class MarqueServiceImpl method marqueList.

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

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

the class AdminUserController method addPost.

@PostMapping("/add")
public String addPost(Model model, Pageable pageable, @Valid User user, BindingResult result) {
    if (result.hasErrors()) {
        model.addAttribute("page", userRepo.findAll(pageable));
        model.addAttribute("roles", AuthoritiesConstants.getRoles());
        return "admin/users/add";
    }
    if (userRepo.findByUsername(user.getUsername()).isPresent())
        throw new OperationFailedException("Nom d'utilisateur déja utilisé");
    user.setPassword(encoder.encode(user.getPassword()));
    userRepo.save(user);
    return "redirect:/admin/users/add";
}
Also used : OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 14 with OperationFailedException

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

the class EmployeServiceImpl method employesList.

/**
 * search with nom
 *
 * @param pageable page description
 * @param search   keyword
 * @return Page
 */
@Override
public Page<Employe> employesList(Pageable pageable, String search) {
    log.info("Service- employeServiceImpl Calling employeList with params :" + pageable + ", " + search);
    try {
        if (search.isEmpty()) {
            log.debug("fetching employe page");
            return employeRepo.findAll(pageable);
        } else {
            log.debug("Searching by :" + search);
            // creating example
            Employe employe = new Employe();
            employe.setNom(search);
            employe.setMetier(search);
            // creating matcher
            ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
            Example<Employe> example = Example.of(employe, matcher);
            log.debug("getting search results");
            return employeRepo.findAll(example, pageable);
        }
    } catch (Exception e) {
        log.debug("Failed retrieving list of employes");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : ExampleMatcher(org.springframework.data.domain.ExampleMatcher) 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) NoSuchElementException(java.util.NoSuchElementException)

Example 15 with OperationFailedException

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

the class FamilleServiceImpl method familleList.

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

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