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";
}
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);
}
}
Aggregations