Example usage for org.springframework.util Assert notEmpty

List of usage examples for org.springframework.util Assert notEmpty

Introduction

In this page you can find the example usage for org.springframework.util Assert notEmpty.

Prototype

@Deprecated
public static void notEmpty(@Nullable Map<?, ?> map) 

Source Link

Document

Assert that a Map contains entries; that is, it must not be null and must contain at least one entry.

Usage

From source file:com.google.code.guice.repository.SimpleBatchStoreJpaRepository.java

@Override
public void saveInBatch(Iterable<T> entities, int batchSize) {
    List<T> list = Lists.newArrayList(entities);
    Assert.notEmpty(list);
    Assert.isTrue(batchSize > 0);//from   w  w w.  j  ava 2 s.  c o m

    String entityClassName = list.iterator().next().getClass().getSimpleName();
    logger.info(String.format("batch for [%d] of [%s]", list.size(), entityClassName));

    int startIndex = 0;
    int count = list.size();
    while (startIndex < count) {
        int endIndex = startIndex + batchSize;

        if (endIndex > count) {
            endIndex = count;
        }

        Iterable<T> batch = list.subList(startIndex, endIndex);
        try {
            logger.info(String.format("Storing elements: [%d - %d]", startIndex, endIndex));
            saveInBatch(batch);
            logger.info(String.format("[%d - %d] stored", startIndex, endIndex));
        } catch (Exception e) {
            logger.error(String.format("Error while storing [%d - %d] of [%s], trying single store...",
                    startIndex, endIndex, entityClassName), e);
            for (T entity : batch) {
                T saved = saveAndFlush(entity);
                if (saved != null) {
                    entityManager.detach(entity);
                }
            }
        } finally {
            startIndex += batchSize;
        }
    }

    logger.info(String.format("batch for [%d] of [%s] stored", list.size(), entityClassName));
}

From source file:grails.plugin.searchable.internal.compass.index.DefaultIndexMethod.java

public Object invoke(Object[] args) {
    Map options = SearchableMethodUtils.getOptionsArgument(args, getDefaultOptions());
    final Class clazz = (Class) (options.containsKey("match") ? options.remove("match")
            : options.remove("class"));
    final List ids = getIds(args);
    final List objects = getObjects(args);

    validateArguments(args, clazz, ids, objects, options);

    if (args.length == 0 || (args.length == 1 && args[0] instanceof Map && clazz != null)) {
        CompassGpsUtils.index(compassGps, clazz);
        return null;
    }/*from ww w . ja  v a 2 s  .  co m*/

    return doInCompass(new CompassCallback() {
        public Object doInCompass(CompassSession session) throws CompassException {
            List objectsToSave = objects;
            if (clazz != null && !ids.isEmpty()) {
                Assert.isTrue(objects.isEmpty(), "Either provide ids or objects, not both");
                objectsToSave = (List) InvokerHelper.invokeStaticMethod(clazz, "getAll", ids);
            }
            Assert.notEmpty(objectsToSave);
            for (Iterator iter = objectsToSave.iterator(); iter.hasNext();) {
                Object o = iter.next();
                if (o != null) {
                    session.save(o);
                }
            }
            return ids.isEmpty() ? (objectsToSave.size() == 1 ? objectsToSave.get(0) : objectsToSave)
                    : (ids.size() == 1 ? objectsToSave.get(0) : objectsToSave);
        }
    });
}

From source file:org.oncoblocks.centromere.mongodb.test.GenericMongoRepositoryTests.java

@Test
public void findBySimpleCriteriaTest() {

    List<QueryCriteria> searchCriterias = new ArrayList<>();
    searchCriterias.add(new QueryCriteria("primaryGeneSymbol", "GeneB"));
    List<EntrezGene> genes = geneRepository.find(searchCriterias);
    Assert.notNull(genes);/*from  w  ww  .ja va  2 s. c  om*/
    Assert.notEmpty(genes);
    Assert.isTrue(genes.size() == 1);

    EntrezGene gene = genes.get(0);
    Assert.notNull(gene);
    Assert.isTrue(gene.getEntrezGeneId().equals(2L));
    Assert.isTrue("GeneB".equals(gene.getPrimaryGeneSymbol()));

}

From source file:org.esco.portlet.flashinfo.FlashInfoDaoTest.java

@Test
public void testJackson() throws Exception {
    mockServer.expect(MockRestRequestMatchers.requestTo("/mockGuestService"))
            .andRespond(MockRestResponseCreators.withSuccess(resource, MediaType.APPLICATION_OCTET_STREAM));

    List<FlashInfo> fil = flashInfoResourceJackson.retrieveInfos("/mockGuestService");
    //flashInfoResourceJackson.retrieveInfos("https://test-lycee.reciaent.fr/static/mockGuestService");
    Assert.notNull(fil);/*ww  w  . j  av a  2 s  .  com*/
    Assert.notEmpty(fil);
    Assert.isTrue(fil.size() == 4);
}

From source file:org.oncoblocks.centromere.sql.test.SqlBuilderTests.java

@Test
public void compoundAndOrQueryTest() {

    SqlBuilder sqlBuilder = new SqlBuilder(tableDescription);
    sqlBuilder.where(or(and(equal("name", "Joe"), equal("species", "human")),
            and(equal("name", "Mittens"), equal("species", "cat"))));

    String sql = sqlBuilder.toSql();
    System.out.println(sql);//from  ww w . j  av  a  2s .  c  o  m
    Assert.notNull(sql);

    List<Object> values = sqlBuilder.getQueryParameterValues();
    Assert.notNull(values);
    Assert.notEmpty(values);
    Assert.isTrue(values.size() == 4);
    String name = (String) values.get(2);
    Assert.isTrue("Mittens".equals(name));

}

From source file:org.codehaus.groovy.grails.plugins.searchable.compass.index.DefaultIndexMethod.java

public Object invoke(Object[] args) {
    Map options = SearchableMethodUtils.getOptionsArgument(args, getDefaultOptions());
    final Class clazz = (Class) options.get("class");
    final List ids = getIds(args);
    final List objects = getObjects(args);

    validateArguments(args, clazz, ids, objects, options);

    if (isBulkAllowed() && args.length == 0 && clazz == null) {
        CompassGpsUtils.index(compassGps);
        return null;
    }//  w w  w.java  2s .com

    return doInCompass(new CompassCallback() {
        public Object doInCompass(CompassSession session) throws CompassException {
            List objectsToSave = objects;
            if (clazz != null && !ids.isEmpty()) {
                Assert.isTrue(objects.isEmpty(), "Either provide ids or objects, not both");
                objectsToSave = (List) InvokerHelper.invokeStaticMethod(clazz, "getAll", ids);
            }
            Assert.notEmpty(objectsToSave);
            for (Iterator iter = objectsToSave.iterator(); iter.hasNext();) {
                Object o = iter.next();
                if (o != null) {
                    session.save(o);
                }
            }
            return null;
        }
    });
}

From source file:org.agatom.springatom.data.vin.decoder.resolver.DefaultWMIManufacturedInResolver.java

private void postProcessWMIBeans(final WMIBeanList wmiBeans) throws NotFoundException {
    for (final WMIBean wmiBean : wmiBeans) {
        final List<String> codes = wmiBean.codes;
        Assert.notEmpty(codes);

        final List<CountryCode> byName = CountryCode.findByName(wmiBean.country);
        if (CollectionUtils.isEmpty(byName)) {
            final String format = String.format("%s has no country code corresponding", wmiBean.country);
            LOGGER.warn(format);/*w w  w .jav a2s.c o  m*/
            continue;
        }

        for (final String code : codes) {
            final String[] split = code.split("-");

            final CodeRangeWrapper wrapper = CodeRangeWrapper.newCodeRangeWrapper(split[0],
                    split.length == 2 ? split[1] : "");
            final CountryCode countryCode = byName.get(0);

            LOGGER.trace(String.format("Key=>%s, CountryCode=%s", wrapper, countryCode));

            this.countryCodeMap.put(wrapper, countryCode);
        }
    }
}

From source file:org.oncoblocks.centromere.jpa.test.JpaRepositoryTests.java

@Test
public void findBySimpleCriteriaTest() {

    List<QueryCriteria> searchCriterias = new ArrayList<>();
    searchCriterias.add(new QueryCriteria("primaryGeneSymbol", "GeneB"));
    List<EntrezGene> genes = (List<EntrezGene>) geneRepository.find(searchCriterias);
    Assert.notNull(genes);//  www. j  ava  2  s  .c  om
    Assert.notEmpty(genes);
    Assert.isTrue(genes.size() == 1);

    EntrezGene gene = genes.get(0);
    Assert.notNull(gene);
    Assert.isTrue(gene.getEntrezGeneId().equals(2L));
    Assert.isTrue("GeneB".equals(gene.getPrimaryGeneSymbol()));

}

From source file:org.oncoblocks.centromere.sql.test.GenericJdbcRepositoryTests.java

@Test
public void queryCriteriaTest() {
    List<QueryCriteria> queryCriterias = new ArrayList<>();
    queryCriterias.add(new QueryCriteria("subjects.name", "PersonB", Evaluation.EQUALS));
    List<Subject> subjects = subjectRepository.find(queryCriterias);
    Assert.notNull(subjects);// w w  w. ja v  a  2 s.c  o  m
    Assert.notEmpty(subjects);
    Assert.isTrue(subjects.size() == 1);
    Subject subject = subjects.get(0);
    Assert.notNull(subject);
    Assert.isTrue(subject.getId().equals(2L));
    Assert.isTrue(subject.getName().equals("PersonB"));
}

From source file:org.oncoblocks.centromere.mongodb.test.GenericMongoRepositoryTests.java

@Test
public void findByNestedArrayCriteriaTest() {

    List<QueryCriteria> searchCriterias = new ArrayList<>();
    searchCriterias.add(new QueryCriteria("aliases", "DEF"));
    List<EntrezGene> genes = geneRepository.find(searchCriterias);
    Assert.notNull(genes);/*from  ww w. ja va2 s .  c o  m*/
    Assert.notEmpty(genes);
    Assert.isTrue(genes.size() == 1);

    EntrezGene gene = genes.get(0);
    Assert.notNull(gene);
    Assert.isTrue(gene.getEntrezGeneId().equals(2L));
    Assert.isTrue("GeneB".equals(gene.getPrimaryGeneSymbol()));
    Assert.isTrue(gene.getAliases().contains("DEF"));

}