Commit fc6989f2 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'ui-84-my-list-and-creating-requests' into 'master'

Server side "My List and creating requests"

See merge request genesys-pgr/genesys-server!258
parents eff6e8d6 b2c817e3
......@@ -202,8 +202,19 @@ public class AccessionController {
}
/**
* Converts AccessionIdentifiers to UUID
* Gets accessions by list of uuid-s
*
* @param uuids accession identifi`ers to lookup in DB
* @return list of Accessions
*/
@PostMapping(value = "/for-uuid", produces = { MediaType.APPLICATION_JSON_VALUE })
public List<Accession> forUuids(@RequestBody Set<UUID> uuids) {
return accessionService.forUuids(uuids);
}
/**
* Converts AccessionIdentifiers to UUID
*
* @param identifiers accession identifiers to lookup in DB
* @return map with UUIDs and related AccessionIdentifiers
*/
......
......@@ -87,6 +87,7 @@ public interface AccessionService {
*/
Map<UUID, AccessionIdentifier3> toUUID(List<? extends AccessionIdentifier3> identifiers);
List<Accession> forUuids(Set<UUID> uuids);
/**
* Loads {@link Accession} by IDs and executes the action on each accession in a
* Spring transaction. Spring security context not supported.
......
......@@ -130,7 +130,22 @@ public class AccessionServiceImpl implements AccessionService {
return res;
}
@Override
@Override
public List<Accession> forUuids(Set<UUID> uuids) {
final int chunkSize = 100;
List<UUID> uuidList = new ArrayList<>(uuids);
List<Accession> accessions = new ArrayList<>(uuidList.size());
for (int i = 0; i < uuidList.size(); i+= chunkSize){
List<UUID> chunk = uuidList.subList(i, i+chunkSize);
accessions.addAll((List<Accession>) accessionRepository.findAll(QAccession.accession.accessionId.uuid.in(chunk)));
}
return accessions;
}
@Override
public long countAccessions(AccessionFilter filter) {
long total = elasticsearchService.count(Accession.class, filter);
......
......@@ -22,12 +22,15 @@ import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.docu
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.genesys.test.base.AbstractApiTest;
import org.genesys2.server.api.v0.AccessionController;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.*;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.AccessionIdRepository;
......@@ -35,6 +38,7 @@ import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.persistence.Taxonomy2Repository;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
......@@ -81,6 +85,8 @@ public class AccessionControllerTest extends AbstractApiTest {
private InstituteService instituteService;
@Autowired
private Taxonomy2Repository taxonomyRepository;
@Autowired
private TaxonomyService taxonomyService;
MockMvc mockMvc;
......@@ -146,6 +152,28 @@ public class AccessionControllerTest extends AbstractApiTest {
assertThat(accessionRepository.count(), is(1L));
}
@Test
public void getAccessionsTest() throws Exception {
// Also works with 2000, 5000, 10000, 15000
int amount = 1000;
List<Accession> accessions = setUpAccessions(amount);
assertThat(accessionRepository.count(), is((long)(amount)));
List<UUID> uuids = accessions.stream().map(Accession::getAccessionId).map(AccessionId::getUuid).collect(Collectors.toList());
final String s = objectMapper.writeValueAsString(uuids);
mockMvc.perform(post(org.genesys2.server.api.v1.AccessionController.API_BASE + "/for-uuid")
.contentType(MediaType.APPLICATION_JSON)
.content(s))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(amount)));
}
@Test
public void updateAccessionNoChange() throws Exception {
ObjectNode accessionJson = setUpAccession();
......@@ -367,6 +395,26 @@ public class AccessionControllerTest extends AbstractApiTest {
return objectMapper.readValue(responseBody, Accession.class);
}
private List<Accession> setUpAccessions(int amount) {
final List<Accession> accessions = new ArrayList<>(amount);
for (int i = 0; i < amount; i++) {
accessions.add(addAccessionInDB());
}
return accessionRepository.save(accessions);
}
private Accession addAccessionInDB() {
Accession a = new Accession();
a.setAccessionId(new AccessionId());
a.setInstitute(institute);
a.setAccessionNumber("ACC" + System.currentTimeMillis() + "-" + acceNumb.incrementAndGet());
Taxonomy2 taxon = new Taxonomy2();
taxon.setGenus("Hordeum");
a.setTaxonomy(taxonomyService.ensureTaxonomy(taxon));
return a;
}
private ObjectNode setUpAccession() {
ObjectNode accession = objectMapper.createObjectNode();
accession.put("instCode", institute.getCode());
......
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