Search in sources :

Example 1 with ExampleMatcher

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);
    }
}
Also used : Marque(me.kadarh.mecaworks.domain.others.Marque) 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) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with ExampleMatcher

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);
    }
}
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 3 with ExampleMatcher

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);
    }
}
Also used : SousFamille(me.kadarh.mecaworks.domain.others.SousFamille) 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 4 with ExampleMatcher

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);
}
Also used : Assertions(org.assertj.core.api.Assertions) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Before(org.junit.Before) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.Test)

Example 5 with ExampleMatcher

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();
}
Also used : ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.Test)

Aggregations

ExampleMatcher (org.springframework.data.domain.ExampleMatcher)33 Test (org.junit.jupiter.api.Test)20 Query (org.springframework.data.relational.core.query.Query)17 NoSuchElementException (java.util.NoSuchElementException)9 OperationFailedException (me.kadarh.mecaworks.service.exceptions.OperationFailedException)9 ResourceNotFoundException (me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException)9 Objects (java.util.Objects)2 Classe (me.kadarh.mecaworks.domain.others.Classe)2 Marque (me.kadarh.mecaworks.domain.others.Marque)2 SousFamille (me.kadarh.mecaworks.domain.others.SousFamille)2 Assertions (org.assertj.core.api.Assertions)2 Test (org.junit.Test)2 Example (org.springframework.data.domain.Example)2 BaseEntity (com.google.cloud.datastore.BaseEntity)1 BaseKey (com.google.cloud.datastore.BaseKey)1 Cursor (com.google.cloud.datastore.Cursor)1 Datastore (com.google.cloud.datastore.Datastore)1 DatastoreReaderWriter (com.google.cloud.datastore.DatastoreReaderWriter)1 Entity (com.google.cloud.datastore.Entity)1 Builder (com.google.cloud.datastore.Entity.Builder)1