Commit bbb6c9e9 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Subset and Dataset accession lists

- Rename methods and API paths
- improvement of listAccessions method
- use subList
- Renamed {UUID} param
parent b440b739
......@@ -15,6 +15,10 @@
*/
package org.genesys.catalog.model.dataset;
import javax.persistence.*;
import java.util.List;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import org.genesys.blocks.auditlog.annotations.Audited;
......@@ -36,10 +40,6 @@ import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import javax.persistence.*;
import java.util.List;
import java.util.Set;
/**
* {@link Dataset} captures the metadata information as a snapshot. Multiple
* versions of the versions may exist.
......@@ -78,7 +78,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
// index
indexes = { @Index(columnList = "datasetId, instCode, acceNumb"), @Index(columnList = "datasetId, genus") })
@Field(type = FieldType.Object)
@JsonView({ JsonViews.Minimal.class })
@JsonIgnore
private Set<AccessionRef> accessionRefs;
/** The descriptors. */
......
......@@ -117,6 +117,15 @@ public interface DatasetService {
*/
Dataset loadDataset(UUID uuid, int version);
/**
* Load AccessionRef list by Dataset
*
* @param uuid uuid of Dataset
* @param page Pageable
* @return PageImpl of AccessionRef
*/
Page<AccessionRef> listAccessions(UUID uuid, Pageable page);
/**
* List published datasets by accession.
*
......
......@@ -25,6 +25,7 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
......@@ -166,10 +167,6 @@ public class DatasetServiceImpl implements DatasetService {
dataset.setLocations(new ArrayList<>());
dataset.setCrops(source.getCrops());
if (source.getAccessionRefs() != null && !source.getAccessionRefs().isEmpty()) {
dataset.setAccessionRefs(lookupMatchingAccessions(source.getAccessionRefs()));
}
copyDescriptors(dataset, source.getDescriptors());
dataset = datasetRepository.save(dataset);
......@@ -229,7 +226,9 @@ public class DatasetServiceImpl implements DatasetService {
public Dataset updateAccessionRefs(Dataset dataset, final Set<AccessionRef> accessionRefs) {
LOG.info("Update AccessionIdentifiers. Input dataset: {}, input accessionRefs {}", dataset, accessionRefs);
dataset = loadDataset(dataset);
dataset.getAccessionRefs().clear();
if (dataset.getAccessionRefs() != null && !dataset.getAccessionRefs().isEmpty()) {
dataset.getAccessionRefs().clear();
}
dataset.setAccessionRefs(lookupMatchingAccessions(accessionRefs));
return lazyLoad(datasetRepository.save(dataset));
}
......@@ -379,6 +378,24 @@ public class DatasetServiceImpl implements DatasetService {
return lazyLoad(dataset);
}
/**
* {@inheritDoc}
*/
@Override
public Page<AccessionRef> listAccessions(final UUID uuid, final Pageable page) {
final Dataset dataset = datasetRepository.findByUuid(uuid);
if (dataset == null) {
throw new NotFoundElement("Dataset not found by UUID=" + uuid.toString());
}
final Set<AccessionRef> accessionRefs = dataset.getAccessionRefs();
if (accessionRefs != null && !accessionRefs.isEmpty()) {
int fromIndex = Math.multiplyExact(page.getPageNumber(), page.getPageSize());
int toIndex = Math.min(fromIndex + page.getPageSize(), accessionRefs.size());
return new PageImpl<>(new ArrayList<AccessionRef>(accessionRefs).subList(fromIndex, toIndex), page, accessionRefs.size());
}
return new PageImpl<>(Collections.emptyList(), page, 0);
}
/**
* {@inheritDoc}
*/
......@@ -463,9 +480,6 @@ public class DatasetServiceImpl implements DatasetService {
throw new NotFoundElement("No such dataset");
}
if (dataset.getAccessionRefs() != null) {
dataset.getAccessionRefs().size();
}
if (dataset.getDescriptors() != null) {
dataset.getDescriptors().size();
}
......
......@@ -218,6 +218,20 @@ public class DatasetController extends ApiBaseController {
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, datasetService.listDatasets(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "id")));
}
/**
* Load AccessionRef list by Dataset
*
* @param uuid uuid of Dataset
* @param page Pageable
* @return the page
* @throws NotFoundElement
*/
@JsonView({ JsonViews.Minimal.class })
@GetMapping(value = "/accessions/{uuid}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<AccessionRef> listAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement {
return datasetService.listAccessions(datasetService.loadDataset(uuid), page.toPageRequest(100));
}
/**
* Removes the descriptors.
*
......
......@@ -20,18 +20,22 @@ import java.io.IOException;
import java.util.Set;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonView;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.SubsetFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -161,6 +165,20 @@ public class SubsetController {
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, subsetService.listSubsetsForCurrentUser(filterInfo.filter, page.toPageRequest(100, Sort.Direction.DESC, "lastModifiedDate")));
}
/**
* Load AccessionRef list by Subset
*
* @param uuid uuid of Subset
* @param page Pageable
* @return the page
* @throws NotFoundElement
*/
@JsonView({ JsonViews.Public.class })
@GetMapping(value = "/accessions/{uuid}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<AccessionRef> listAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement {
return subsetService.listAccessions(subsetService.get(uuid), page.toPageRequest(100));
}
/**
* Remove accessions form subset.
*
......
......@@ -47,6 +47,7 @@ import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
/**
......@@ -94,7 +95,7 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
// index
indexes = { @Index(columnList = "subsetId, instCode, acceNumb"), @Index(columnList = "subsetId, genus") })
@Field(type = FieldType.Object)
@JsonView({ JsonViews.Public.class })
@JsonIgnore
private Set<AccessionRef> accessionRefs;
/** The accession count. */
......
......@@ -23,6 +23,7 @@ import java.util.UUID;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.model.impl.SubsetCreator;
......@@ -44,6 +45,15 @@ public interface SubsetService {
*/
Page<Subset> list(SubsetFilter filter, Pageable page);
/**
* Load AccessionRef list by Subset
*
* @param uuid uuid of Subset
* @param page Pageable
* @return PageImpl of AccessionRef
*/
Page<AccessionRef> listAccessions(UUID uuid, Pageable page);
/**
* Count published subsets.
*
......
......@@ -20,6 +20,7 @@ import static org.genesys2.server.model.impl.QSubsetCreator.subsetCreator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -105,6 +106,21 @@ public class SubsetServiceImpl implements SubsetService {
return subsetRepository.findAll(published, page);
}
@Override
public Page<AccessionRef> listAccessions(final UUID uuid, final Pageable page) {
final Subset subset = subsetRepository.getByUuid(uuid);
if (subset == null) {
throw new NotFoundElement("Subset not found by UUID=" + uuid.toString());
}
final Set<AccessionRef> accessionRefs = subset.getAccessionRefs();
if (accessionRefs != null && !accessionRefs.isEmpty()) {
int fromIndex = Math.multiplyExact(page.getPageNumber(), page.getPageSize());
int toIndex = Math.min(fromIndex + page.getPageSize(), accessionRefs.size());
return new PageImpl<>(new ArrayList<AccessionRef>(accessionRefs).subList(fromIndex, toIndex), page, accessionRefs.size());
}
return new PageImpl<>(Collections.emptyList(), page, 0);
}
@Override
public long countSubsets(SubsetFilter filter) {
return subsetRepository.count(filter.buildQuery());
......@@ -138,7 +154,6 @@ public class SubsetServiceImpl implements SubsetService {
}
final Subset subset = new Subset();
copyValues(subset, source);
copyAccessions(subset, source.getAccessionRefs());
subset.setState(PublishState.DRAFT);
return deepLoad(subsetRepository.save(subset));
}
......@@ -203,9 +218,7 @@ public class SubsetServiceImpl implements SubsetService {
subset.getInstitute().getId();
if (subset.getCrops() != null)
subset.getCrops().size();
if (subset.getAccessionRefs() != null)
subset.getAccessionRefs().size();
subset.getCrops().size();
if (subset.getCreators() != null)
subset.getCreators().size();
......@@ -260,9 +273,6 @@ public class SubsetServiceImpl implements SubsetService {
public Subset update(final Subset source) {
LOG.info("Update Subset.");
final Subset subset = loadSubset(source);
subset.getAccessionRefs().clear();
copyAccessions(subset, source.getAccessionRefs());
copyValues(subset, source);
return deepLoad(subsetRepository.save(subset));
......
......@@ -15,9 +15,6 @@
*/
package org.genesys.test.catalog.services;
import java.util.List;
import java.util.Set;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetCreator;
......@@ -26,25 +23,14 @@ import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.persistence.dataset.DatasetVersionsRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.persistence.RepositoryFilePersistence;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.worker.AccessionUploader;
import org.junit.After;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
protected static final String TEST_INSTCODE = "XYZ001";
......@@ -73,10 +59,6 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
protected AccessionRepository accessionRepository;
@Autowired
protected FaoInstituteRepository instituteRepository;
@Autowired
private InstituteService instituteService;
@Autowired
private AccessionUploader accessionUploader;
public AbstractDatasetServiceTest() {
super();
......@@ -95,22 +77,16 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
datasetVersionsRepository.deleteAll();
descriptorRepository.deleteAll();
repositoryFilePersistence.deleteAll();
accessionRepository.deleteAll();
instituteRepository.deleteAll();
super.cleanup();
}
protected Dataset buildAndSaveDataset(final String datasetTitle, final String datasetDescription, final Partner partner, final PublishState state) {
final Set<AccessionRef> accessionRefs = Sets.newHashSet(new AccessionRef("InstCode", "TestAccNum", "TestGen", null));
return datasetService.createDataset(buildDataset(datasetTitle, datasetDescription, partner, accessionRefs, state));
return datasetService.createDataset(buildDataset(datasetTitle, datasetDescription, partner, state));
}
protected Dataset buildDataset(final String datasetTitle, final String datasetDescription, final Partner partner, final Set<AccessionRef> accessionRefs, final PublishState state) {
protected Dataset buildDataset(final String datasetTitle, final String datasetDescription, final Partner partner, final PublishState state) {
final Dataset input = new Dataset();
input.setTitle(datasetTitle);
input.setAccessionRefs(accessionRefs);
input.setDescription(datasetDescription);
input.setOwner(partner);
input.setState(state);
......@@ -140,47 +116,4 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
return new AccessionRef(instCode, acceNumb, genus, doi);
}
protected Accession upsertAccession(final String instCode, final String acceNumb, final String genus) {
FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
institute = new FaoInstitute();
institute.setCode(instCode);
institute.setFullName("Test institute " + instCode);
instituteService.update(Lists.newArrayList(institute));
institute = instituteService.getInstitute(instCode);
}
ObjectMapper objectMapper = new ObjectMapper();
ArrayNode updates = objectMapper.createArrayNode();
ObjectNode accession = updates.addObject();
accession.put("instituteCode", instCode);
accession.put("accessionNumber", acceNumb);
ObjectNode taxa = accession.putObject("taxonomy");
taxa.put("genus", genus);
accessionUploader.upsertAccessions(institute, updates);
return accessionRepository.findOne(institute, null, acceNumb, genus);
}
protected void deleteAccession(final String instCode, final String acceNumb, final String genus) {
FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
institute = new FaoInstitute();
institute.setCode(instCode);
institute.setFullName("Test institute " + instCode);
instituteService.update(Lists.newArrayList(institute));
institute = instituteService.getInstitute(instCode);
}
AccessionHeaderJson ah=new AccessionHeaderJson();
ah.instCode=instCode;
ah.acceNumb=acceNumb;
ah.genus=genus;
List<AccessionHeaderJson> identifiers=Lists.newArrayList(ah);
accessionUploader.deleteAccessions(institute, identifiers);
assert(accessionRepository.findOne(institute, null, acceNumb, genus) == null);
}
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ package org.genesys.test.catalog.services;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Set;
import org.genesys.catalog.model.Partner;
......@@ -35,9 +36,20 @@ import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.VocabularyService;
import org.genesys.test.base.AbstractServiceTest;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.worker.AccessionUploader;
import org.junit.After;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
......@@ -97,6 +109,18 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
@Autowired
protected ShortFilterRepository shortFilterRepository;
@Autowired
private InstituteService instituteService;
@Autowired
private AccessionUploader accessionUploader;
@Autowired
protected AccessionRepository accessionRepository;
@Autowired
protected FaoInstituteRepository instituteRepository;
protected Partner partner;
protected Partner partner2;
......@@ -106,6 +130,9 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
partnerRepository.deleteAll();
partner = setupPartner(PARTNER_1, PARTNER_ACRONYM_1, Sets.newHashSet(URL_1));
partner2 = setupPartner(PARTNER_2, PARTNER_ACRONYM_2, Sets.newHashSet(URL_1));
accessionRepository.deleteAll();
instituteRepository.deleteAll();
super.cleanup();
}
......@@ -153,4 +180,46 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
return input;
}
protected Accession upsertAccession(final String instCode, final String acceNumb, final String genus) {
FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
institute = new FaoInstitute();
institute.setCode(instCode);
institute.setFullName("Test institute " + instCode);
instituteService.update(Lists.newArrayList(institute));
institute = instituteService.getInstitute(instCode);
}
ObjectMapper objectMapper = new ObjectMapper();
ArrayNode updates = objectMapper.createArrayNode();
ObjectNode accession = updates.addObject();
accession.put("instituteCode", instCode);
accession.put("accessionNumber", acceNumb);
ObjectNode taxa = accession.putObject("taxonomy");
taxa.put("genus", genus);
accessionUploader.upsertAccessions(institute, updates);
return accessionRepository.findOne(institute, null, acceNumb, genus);
}
protected void deleteAccession(final String instCode, final String acceNumb, final String genus) {
FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
institute = new FaoInstitute();
institute.setCode(instCode);
institute.setFullName("Test institute " + instCode);
instituteService.update(Lists.newArrayList(institute));
institute = instituteService.getInstitute(instCode);
}
AccessionHeaderJson ah = new AccessionHeaderJson();
ah.instCode = instCode;
ah.acceNumb = acceNumb;
ah.genus = genus;
List<AccessionHeaderJson> identifiers = Lists.newArrayList(ah);
accessionUploader.deleteAccessions(institute, identifiers);
assert(accessionRepository.findOne(institute, null, acceNumb, genus) == null);
}
}
......@@ -3,12 +3,18 @@ package org.genesys.test.catalog.services;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import com.google.common.collect.Lists;
import org.genesys.test.base.AbstractServiceTest;
import com.google.common.collect.Sets;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.model.impl.SubsetCreator;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.persistence.SubsetCreatorRepository;
import org.genesys2.server.persistence.SubsetRepository;
import org.genesys2.server.service.InstituteService;
......@@ -20,13 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import java.util.List;
import java.util.UUID;
public class SubsetServiceTest extends AbstractServiceTest {
@Autowired
private FaoInstituteRepository instituteRepository;
public class SubsetServiceTest extends CatalogServiceTest {
@Autowired
private SubsetRepository subsetRepository;
......@@ -72,7 +72,6 @@ public class SubsetServiceTest extends AbstractServiceTest {
public void cleanup() throws Exception {
subsetCreatorRepository.deleteAll();
subsetRepository.deleteAll();
instituteRepository.deleteAll();
super.cleanup();
}
......@@ -95,6 +94,49 @@ public class SubsetServiceTest extends AbstractServiceTest {
assertThat(result.getEmail(), equalTo(newEmail));
}
@Test
public void testLoadMoreAccessions() {
final Accession accession1 = upsertAccession("instCode1", "acceNumb1", "genus1");
final Accession accession2 = upsertAccession("instCode2", "acceNumb2", "genus2");
final Accession accession3 = upsertAccession("instCode3", "acceNumb3", "genus3");
final Accession accession4 = upsertAccession("instCode4", "acceNumb4", "genus4");
final Accession accession5 = upsertAccession("instCode5", "acceNumb5", "genus5");
final int PAGE_SIZE = 2;
Set<UUID> accessionUUIDs = Sets.newHashSet(accession1.getUuid(), accession2.getUuid(), accession3.getUuid(),
accession4.getUuid(), accession5.getUuid());
// add accessions to the Subset
subset = subsetService.addAccessions(subset, accessionUUIDs);
assertThat(subset.getAccessionCount(), is(accessionUUIDs.size()));
final Set<AccessionRef> refs = new HashSet<>(5);
// fetch first page
Page<AccessionRef> page1 = subsetService.listAccessions(subset.getUuid(), new PageRequest(0, PAGE_SIZE));
assertThat(page1.getTotalElements(), is((long) subset.getAccessionCount()));
assertThat(page1.getContent().size(), is(PAGE_SIZE));
// add page content to the HashSet to be sure that we avoid duplicates
refs.addAll(page1.getContent());
// fetch second page
Page<AccessionRef> page2 = subsetService.listAccessions(subset.getUuid(), new PageRequest(1, PAGE_SIZE));
assertThat(page2.getTotalElements(), is((long) subset.getAccessionCount()));
assertThat(page2.getContent().size(), is(PAGE_SIZE));
refs.addAll(page2.getContent());
// fetch third page
Page<AccessionRef> page3 = subsetService.listAccessions(subset.getUuid(), new PageRequest(2, PAGE_SIZE));
assertThat(page3.getTotalElements(), is((long) subset.getAccessionCount()));
// it's a last page, so content size should be 1
assertThat(page3.getContent().size(), is(subset.getAccessionCount() - (PAGE_SIZE * 2)));
refs.addAll(page3.getContent());
// check that we didn't fetch duplicates
assertThat(refs.size(), is(subset.getAccessionCount()));
}
@Test
public void testRemoveSubsetCreator() {
assertThat(subsetCreatorRepository.findAll().size(), is(1));
......
......@@ -18,6 +18,7 @@ package org.genesys.test.server.api.v1;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
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.*;
......@@ -298,8 +299,105 @@ public class DatasetControllerTest extends AbstractApiTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(dataset.getUuid().toString())))
.andExpect(jsonPath("$.accessionRefs[0].acceNumb", is("TestAccNum")))
.andExpect(jsonPath("$.accessionRefs[0].instCode", is("InstCode")));
.andExpect(jsonPath("$.accessionCount", is(1)));
/*@formatter:on*/
/*@formatter:off*/
mockMvc
.perform(RestDocumentationRequestBuilders.get(DatasetController.CONTROLLER_URL.concat("/accessions/{uuid}"), dataset.getUuid())
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.totalElements", is(1)))
.andExpect(jsonPath("$.numberOfElements", is(1)))
.andExpect(jsonPath("$.content[0].acceNumb", is("TestAccNum")))
.andExpect(jsonPath("$.content[0].instCode", is("InstCode")));
/*@formatter:on*/
}
@Test
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public void loadMoreAccessionsTest() throws Exception {
Dataset dataset = datasetService.createDataset(setUpDataset(PublishState.DRAFT));
assertThat(dataset, notNullValue());
assertThat(dataset.getAccessionCount(), nullValue());
Set<AccessionRef> newAccessions = makeRandomAccessionRefs(4);
assertThat(newAccessions.size(), is(4));
dataset = datasetService.updateAccessionRefs(dataset, newAccessions);
assertThat(dataset.getAccessionCount(), is(4));
final int PAGE_SIZE = 1;
/*@formatter:off*/
// Page 1
mockMvc
.perform(get(DatasetController.CONTROLLER_URL.concat("/accessions/{uuid}?p={page}&l={pageSize}"), dataset.getUuid(), 0, PAGE_SIZE)
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.number", is(0)))
.andExpect(jsonPath("$.size", is(PAGE_SIZE)))
.andExpect(jsonPath("$.totalElements", is(dataset.getAccessionCount())))
.andExpect(jsonPath("$.numberOfElements", is(PAGE_SIZE)))
.andExpect(jsonPath("$.first", is(true)))
.andExpect(jsonPath("$.last", is(false)))
.andExpect(jsonPath("$.content[0]", not(nullValue())));
/*@formatter:on*/
/*@formatter:off*/
// Page 2
mockMvc
.perform(get(DatasetController.CONTROLLER_URL.concat("/accessions/{uuid}?p={page}&l={pageSize}"), dataset.getUuid(), 1, PAGE_SIZE)
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.number", is(1)))
.andExpect(jsonPath("$.size", is(PAGE_SIZE)))
.andExpect(jsonPath("$.totalElements", is(dataset.getAccessionCount())))
.andExpect(jsonPath("$.numberOfElements", is(PAGE_SIZE)))
.andExpect(jsonPath("$.first", is(false)))
.andExpect(jsonPath("$.last", is(false)))
.andExpect(jsonPath("$.content[0]", not(nullValue())));
/*@formatter:on*/
/*@formatter:off*/
// Page 3
mockMvc
.perform(get(DatasetController.CONTROLLER_URL.concat("/accessions/{uuid}?p={page}&l={pageSize}"), dataset.getUuid(), 2, PAGE_SIZE)
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())