use of org.springframework.data.domain.ExampleMatcher 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);
// marque
Marque marque = new Marque();
marque.setNom(search);
// setting groupe , marque , soufamille to engin
engin.setGroupe(groupe);
engin.setSousFamille(sousFamille);
// 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);
}
}
use of org.springframework.data.domain.ExampleMatcher 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);
}
}
use of org.springframework.data.domain.ExampleMatcher 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);
if (marqueRepo.findByNom(search).isPresent()) {
sousFamille.setMarque(marqueRepo.findByNom(search).get());
}
if (familleRepo.findByNom(search).isPresent()) {
sousFamille.setFamille(familleRepo.findByNom(search).get());
}
// 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);
}
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-commons by spring-projects.
the class ExampleMatcherUnitTests method shouldCompareUsingHashCodeAndEquals.
// DATACMNS-900
@Test
public void shouldCompareUsingHashCodeAndEquals() throws Exception {
matcher = //
matching().withIgnorePaths("foo", "bar", //
"baz").withNullHandler(//
NullHandler.IGNORE).withIgnoreCase(//
"ignored-case").withMatcher("hello", //
GenericPropertyMatchers.contains().caseSensitive()).withMatcher("world", matcher -> matcher.endsWith());
ExampleMatcher sameAsMatcher = //
matching().withIgnorePaths("foo", "bar", //
"baz").withNullHandler(//
NullHandler.IGNORE).withIgnoreCase(//
"ignored-case").withMatcher("hello", //
GenericPropertyMatchers.contains().caseSensitive()).withMatcher("world", matcher -> matcher.endsWith());
ExampleMatcher different = //
matching().withIgnorePaths("foo", "bar", //
"baz").withNullHandler(//
NullHandler.IGNORE).withMatcher("hello", GenericPropertyMatchers.contains().ignoreCase());
assertThat(matcher.hashCode()).isEqualTo(sameAsMatcher.hashCode());
assertThat(matcher.hashCode()).isNotEqualTo(different.hashCode());
assertThat(matcher).isEqualTo(sameAsMatcher);
assertThat(matcher).isNotEqualTo(different);
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-commons by spring-projects.
the class ExampleMatcherUnitTests method withCreatesNewInstance.
// DATACMNS-810
@Test
public void withCreatesNewInstance() throws Exception {
matcher = matching().withIgnorePaths("foo", "bar", "foo");
ExampleMatcher configuredExampleSpec = matcher.withIgnoreCase();
assertThat(matcher).isNotEqualTo(sameInstance(configuredExampleSpec));
assertThat(matcher.getIgnoredPaths()).hasSize(2);
assertThat(matcher.isIgnoreCaseEnabled()).isFalse();
assertThat(configuredExampleSpec.getIgnoredPaths()).hasSize(2);
assertThat(configuredExampleSpec.isIgnoreCaseEnabled()).isTrue();
}
Aggregations