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

Use real count of records when < 10K

parent 06595672
...@@ -43,10 +43,10 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -43,10 +43,10 @@ public class AccessionServiceImpl implements AccessionService {
/** The accession repository. */ /** The accession repository. */
@Autowired @Autowired
private AccessionRepository accessionRepository; private AccessionRepository accessionRepository;
@Autowired @Autowired
private ElasticsearchService elasticsearchService; private ElasticsearchService elasticsearchService;
private <T extends AccessionData> T lazyLoad(T accession) { private <T extends AccessionData> T lazyLoad(T accession) {
if (accession != null) { if (accession != null) {
AccessionId accessionId = accession.getAccessionId(); AccessionId accessionId = accession.getAccessionId();
...@@ -80,33 +80,39 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -80,33 +80,39 @@ public class AccessionServiceImpl implements AccessionService {
if (accessionId.getGeo() != null) { if (accessionId.getGeo() != null) {
accessionId.getGeo().getId(); accessionId.getGeo().getId();
} }
if (accessionId.getPdci() != null) if (accessionId.getPdci() != null)
accessionId.getPdci().getId(); accessionId.getPdci().getId();
} }
return accession; return accession;
} }
@Override @Override
public Accession getByUuid(UUID uuid) { public Accession getByUuid(UUID uuid) {
return lazyLoad(accessionRepository.findOneByUuid(uuid)); return lazyLoad(accessionRepository.findOneByUuid(uuid));
} }
@Override @Override
public Accession getByDoi(String doi) { public Accession getByDoi(String doi) {
return lazyLoad(accessionRepository.findByDoi(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 @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) { public Page<Accession> list(AccessionFilter filter, Pageable page) {
List<Accession> content = accessionRepository.findAll(filter, page); List<Accession> content = accessionRepository.findAll(filter, page);
long total = elasticsearchService.count(Accession.class, filter); 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); return new PageImpl<>(content, page, total);
} }
} }
...@@ -18,18 +18,19 @@ package org.genesys.test.server.api.v1; ...@@ -18,18 +18,19 @@ package org.genesys.test.server.api.v1;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; 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.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 static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.RandomUtils;
import org.genesys.test.base.AbstractApiTest; import org.genesys.test.base.AbstractApiTest;
import org.genesys2.server.api.v1.SubsetController; import org.genesys2.server.api.v1.SubsetController;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
...@@ -100,6 +101,7 @@ public class SubsetRestControllerTest extends AbstractApiTest { ...@@ -100,6 +101,7 @@ public class SubsetRestControllerTest extends AbstractApiTest {
MockMvc mockMvc; MockMvc mockMvc;
private FaoInstitute institute; private FaoInstitute institute;
private AtomicInteger acceNumb=new AtomicInteger(1);
protected static final ObjectMapper objectMapper; protected static final ObjectMapper objectMapper;
...@@ -307,7 +309,7 @@ public class SubsetRestControllerTest extends AbstractApiTest { ...@@ -307,7 +309,7 @@ public class SubsetRestControllerTest extends AbstractApiTest {
Accession a = new Accession(); Accession a = new Accession();
a.setAccessionId(new AccessionId()); a.setAccessionId(new AccessionId());
a.setInstitute(institute); a.setInstitute(institute);
a.setAccessionNumber("ACC" + System.currentTimeMillis() + "-" + RandomUtils.nextLong(0, 100)); a.setAccessionNumber("ACC" + System.currentTimeMillis() + "-" + acceNumb.incrementAndGet());
Taxonomy2 taxon = new Taxonomy2(); Taxonomy2 taxon = new Taxonomy2();
taxon.setGenus("Hordeum"); taxon.setGenus("Hordeum");
a.setTaxonomy(taxonomyService.ensureTaxonomy(taxon)); 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