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);
}
}
......@@ -69,7 +69,6 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
final Dataset input = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
assertThat(input, not(nullValue()));
assertThat(input.getId(), not(nullValue()));
assertThat(input.getAccessionRefs().size(), is(1));
assertThat(input.getVersions(), not(nullValue()));
assertThat(input.getVersions().getCurrentVersion(), is(input));
}
......@@ -90,7 +89,7 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
@Test
public void testCreateDatasetWithCrops() {
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, null, PublishState.PUBLISHED);
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED);
input.setCrops(Sets.newHashSet("maize", "wheat"));
input = datasetService.createDataset(input);
assertThat(input, not(nullValue()));
......@@ -121,14 +120,14 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
public void testCreateDatasetForCopyDescriptors() {
final Descriptor savedDescriptor = descriptorService.createDescriptor(createDescriptor(partner, "D1", "1.0", DataType.NUMERIC));
final Dataset input2 = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, null, PublishState.DRAFT);
final Dataset input2 = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
input2.setDescriptors(Lists.newArrayList(savedDescriptor, savedDescriptor));
datasetService.createDataset(input2);
}
@Test
public void testUpdateAccessionIdentifiersInDataset() {
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, null, PublishState.DRAFT);
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
input = datasetService.createDataset(input);
final Set<AccessionRef> datasetAccessionRefs = Sets.newHashSet(makeAccessionIdentifier(TEST_INSTCODE, "TestAcc", "TestGen", null));
......@@ -148,7 +147,7 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
public void testLookupAccessionsForAccessionIdentifiersInDataset() {
final Accession accession = upsertAccession(TEST_INSTCODE, "TestAccNum", "TestGen");
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, null, PublishState.DRAFT);
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
input = datasetService.createDataset(input);
final Set<AccessionRef> datasetAccessionRefs = Sets.newHashSet(makeAccessionIdentifier(TEST_INSTCODE, "TestAccNum", "TestGen", null));
......@@ -170,7 +169,7 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
final Accession accession2 = upsertAccession(TEST_INSTCODE2, TEST_ACCNUM2, TEST_GEN2);
final Accession accession3 = upsertAccession(TEST_INSTCODE3, TEST_ACCNUM3, TEST_GEN3);
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, null, PublishState.DRAFT);
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
input = datasetService.createDataset(input);
final Set<AccessionRef> datasetAccessionRefs = Sets.newHashSet(makeAccessionIdentifier(TEST_INSTCODE, TEST_ACCNUM, TEST_GEN, null), makeAccessionIdentifier(TEST_INSTCODE2,
......@@ -208,7 +207,7 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
public void testListDatasetsByAccession() {
final Accession accession = upsertAccession(TEST_INSTCODE, TEST_ACCNUM, TEST_GEN);
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, null, PublishState.PUBLISHED);
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED);
input = datasetService.createDataset(input);
// add DatasetAccessionRef to dataset
......@@ -271,10 +270,7 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
@Test
public void testUpdateDataset() {
final Dataset result = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
final Set<AccessionRef> datasetAccessionRefs = Sets.newHashSet(makeAccessionIdentifier(TEST_INSTCODE, "TestAcc1", "TestGen1", null));
final Dataset result2 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, datasetAccessionRefs, PublishState.DRAFT));
final Dataset result2 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT));
assertThat(result.isPublished(), is(false));
......@@ -579,7 +575,7 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
@Test
public void upsertAccessions() {
Dataset result = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, null, PublishState.DRAFT));
Dataset result = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT));
assertThat(result.getAccessionCount(), nullValue());
final Set<AccessionRef> datasetAccessionRefs = Sets.newHashSet(makeAccessionIdentifier(TEST_INSTCODE, "TestAccNum", "TestGen", null), makeAccessionIdentifier(TEST_INSTCODE,
......@@ -599,14 +595,16 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
ids1.add(makeAccessionIdentifier(TEST_INSTCODE, "A1", "Musa", null));
ids1.add(makeAccessionIdentifier(TEST_INSTCODE, "A2", "Musa", null));
ids1.add(makeAccessionIdentifier(TEST_INSTCODE, "A8", "Musa", null));
final Dataset dataset1 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, ids1, PublishState.PUBLISHED));
Dataset dataset1 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED));
dataset1 = datasetService.updateAccessionRefs(dataset1, ids1);
assertThat(dataset1.getAccessionCount(), is(3));
final Set<AccessionRef> ids2 = new HashSet<>();
ids2.add(makeAccessionIdentifier(TEST_INSTCODE, "A1", "Musa", null));
ids2.add(makeAccessionIdentifier(TEST_INSTCODE, "A2", "Musa", null));
ids2.add(makeAccessionIdentifier(TEST_INSTCODE, "A3", "Manihot", null));
final Dataset dataset2 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, ids2, PublishState.PUBLISHED));
Dataset dataset2 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED));
dataset2 = datasetService.updateAccessionRefs(dataset2, ids2);
assertThat(dataset2.getAccessionCount(), is(3));
final DatasetFilter filter = new DatasetFilter();
......@@ -808,17 +806,17 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
ids1.add(makeAccessionIdentifier(TEST_INSTCODE, "A1", "Musa", null));
ids1.add(makeAccessionIdentifier(TEST_INSTCODE, "A2", "Musa", null));
ids1.add(makeAccessionIdentifier(TEST_INSTCODE, "A8", "Musa", null));
final Dataset dataset1 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, ids1, PublishState.PUBLISHED));
Dataset dataset1 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED));
dataset1 = datasetService.updateAccessionRefs(dataset1, ids1);
assertThat(dataset1.getAccessionCount(), is(3));
dataset1.getAccessionRefs().forEach(acceRef -> assertThat(acceRef.getAccession(), nullValue()));
final Set<AccessionRef> ids2 = new HashSet<>();
ids2.add(makeAccessionIdentifier(TEST_INSTCODE, "A1", "Musa", null));
ids2.add(makeAccessionIdentifier(TEST_INSTCODE, "A2", "Musa", null));
ids2.add(makeAccessionIdentifier(TEST_INSTCODE, "A3", "Manihot", null));
final Dataset dataset2 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, ids2, PublishState.PUBLISHED));
Dataset dataset2 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED));
dataset2 = datasetService.updateAccessionRefs(dataset2, ids2);
assertThat(dataset2.getAccessionCount(), is(3));
dataset2.getAccessionRefs().forEach(acceRef -> assertThat(acceRef.getAccession(), nullValue()));
final Accession accession1 = upsertAccession(TEST_INSTCODE, "A2", "Musa");
datasetService.rematchDatasetAccessions(dataset1);
......@@ -828,7 +826,7 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
assertThat(datasets1, not(nullValue()));
assertThat(datasetRepository.count(), is(2l));
assertThat(datasets1.size(), is(2));
datasets1.forEach(ds -> assertThat(datasetService.loadDataset(ds).getAccessionRefs().size(), is(3)));
datasets1.forEach(ds -> assertThat(datasetService.loadDataset(ds).getAccessionCount(), is(3)));
final Accession accession2 = upsertAccession(TEST_INSTCODE, "A8", "Musa");
datasetService.rematchDatasetAccessions(dataset1);
......@@ -836,7 +834,7 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
datasets1 = datasetService.listByAccession(accession2);
assertThat(datasets1.size(), is(1));
assertThat(datasets1.get(0).getUuid(), is(dataset1.getUuid()));
assertThat(datasetService.loadDataset(datasets1.get(0)).getAccessionRefs().size(), is(3));
assertThat(datasetService.loadDataset(datasets1.get(0)).getAccessionCount(), is(3));
}
@Test
......@@ -848,21 +846,24 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
ids1.add(makeAccessionIdentifier(TEST_INSTCODE, "A1", "Musa", null));
ids1.add(makeAccessionIdentifier(TEST_INSTCODE, "A2", "Musa", null));
ids1.add(makeAccessionIdentifier(TEST_INSTCODE, "A8", "Musa", null));
Dataset dataset1 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, ids1, PublishState.PUBLISHED));
Dataset dataset1 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED));
dataset1 = datasetService.updateAccessionRefs(dataset1, ids1);
assertThat(dataset1.getAccessionCount(), is(3));
final Set<AccessionRef> ids2 = new HashSet<>();
ids2.add(makeAccessionIdentifier(TEST_INSTCODE, "A1", "Musa", null));
ids2.add(makeAccessionIdentifier(TEST_INSTCODE, "A2", "Musa", null));
ids2.add(makeAccessionIdentifier(TEST_INSTCODE, "A3", "Manihot", null));
Dataset dataset2 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, ids2, PublishState.PUBLISHED));
Dataset dataset2 = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED));
dataset2 = datasetService.updateAccessionRefs(dataset2, ids2);
assertThat(dataset2.getAccessionCount(), is(3));
dataset1 = datasetService.loadDataset(dataset1.getUuid());
dataset2 = datasetService.loadDataset(dataset2.getUuid());
AccessionRef acceRef1 = dataset1.getAccessionRefs().stream().filter(acceRef -> acceRef.getAcceNumb().equals("A8") && acceRef.getAccession() != null).findFirst().orElse(
null);
AccessionRef acceRef2 = dataset2.getAccessionRefs().stream().filter(acceRef -> acceRef.getAccession() != null).findFirst().orElse(null);
AccessionRef acceRef1 = datasetService.listAccessions(dataset1.getUuid(), new PageRequest(0, 4)).getContent()
.stream().filter(acceRef -> acceRef.getAcceNumb().equals("A8") && acceRef.getAccession() != null).findFirst().orElse