Commit 154da81e authored by Matija Obreza's avatar Matija Obreza

Use real count of records when < 10K

parent 06595672
......@@ -87,26 +87,32 @@ public class AccessionServiceImpl implements AccessionService {
return accession;
}
@Override
public Accession getByUuid(UUID uuid) {
return lazyLoad(accessionRepository.findOneByUuid(uuid));
}
@Override
public Accession getByDoi(String doi) {
return lazyLoad(accessionRepository.findByDoi(doi));
}
/* (non-Javadoc)
* @see org.genesys2.server.service.AccessionService#list(org.genesys2.server.service.filter.AccessionFilter, org.springframework.data.domain.Pageable)
/*
* (non-Javadoc)
* @see
* org.genesys2.server.service.AccessionService#list(org.genesys2.server.service
* .filter.AccessionFilter, org.springframework.data.domain.Pageable)
*/
@Override
@Cacheable(value="apiResponses.accessionApi1.list", unless="#result == null", keyGenerator="shortFilterKeyGenerator")
@Cacheable(value = "apiResponses.accessionApi1.list", unless = "#result == null", keyGenerator = "shortFilterKeyGenerator")
public Page<Accession> list(AccessionFilter filter, Pageable page) {
List<Accession> content = accessionRepository.findAll(filter, page);
long total = elasticsearchService.count(Accession.class, filter);
if (total < 10000) {
// If total is below 10K, use actual count
accessionRepository.count(filter.buildQuery());
}
return new PageImpl<>(content, page, total);
}
}
......@@ -18,18 +18,19 @@ package org.genesys.test.server.api.v1;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.apache.commons.lang3.RandomUtils;
import org.genesys.test.base.AbstractApiTest;
import org.genesys2.server.api.v1.SubsetController;
import org.genesys2.server.model.genesys.Accession;
......@@ -100,6 +101,7 @@ public class SubsetRestControllerTest extends AbstractApiTest {
MockMvc mockMvc;
private FaoInstitute institute;
private AtomicInteger acceNumb=new AtomicInteger(1);
protected static final ObjectMapper objectMapper;
......@@ -307,7 +309,7 @@ public class SubsetRestControllerTest extends AbstractApiTest {
Accession a = new Accession();
a.setAccessionId(new AccessionId());
a.setInstitute(institute);
a.setAccessionNumber("ACC" + System.currentTimeMillis() + "-" + RandomUtils.nextLong(0, 100));
a.setAccessionNumber("ACC" + System.currentTimeMillis() + "-" + acceNumb.incrementAndGet());
Taxonomy2 taxon = new Taxonomy2();
taxon.setGenus("Hordeum");
a.setTaxonomy(taxonomyService.ensureTaxonomy(taxon));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment