Search in sources :

Example 1 with Famille

use of me.kadarh.mecaworks.domain.others.Famille in project mecaworks by KadarH.

the class FamilleController method add.

@GetMapping("/add")
public String add(Model model, Pageable pageable, @RequestParam(defaultValue = "") String search) {
    model.addAttribute("classes", classeService.list());
    model.addAttribute("famille", new Famille());
    model.addAttribute("page", familleService.familleList(pageable, search));
    model.addAttribute("search", search);
    return "admin/familles/add";
}
Also used : Famille(me.kadarh.mecaworks.domain.others.Famille)

Example 2 with Famille

use of me.kadarh.mecaworks.domain.others.Famille 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);
            if (classeService.findByNom(search).isPresent()) {
                famille.setClasse(classeService.findByNom(search).get());
            }
            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

Famille (me.kadarh.mecaworks.domain.others.Famille)2 NoSuchElementException (java.util.NoSuchElementException)1 Classe (me.kadarh.mecaworks.domain.others.Classe)1 OperationFailedException (me.kadarh.mecaworks.service.exceptions.OperationFailedException)1 ResourceNotFoundException (me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException)1 ExampleMatcher (org.springframework.data.domain.ExampleMatcher)1