Commit 7ea4e698 authored by Maxym Borodenko's avatar Maxym Borodenko

Versioned Datasets: update

Uncomment test
parent 84694442
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,6 +17,7 @@ package org.genesys.catalog.model.dataset;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
......@@ -35,12 +36,16 @@ import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonGetter;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.Publishable;
......@@ -66,10 +71,10 @@ import com.fasterxml.jackson.annotation.JsonView;
*
* @author Matija Obreza
* @author Andrey Lugovskoy
* @author Maxim Borodenko
* @author Maxym Borodenko
*/
@Entity
@Table(name = "dataset")
@Table(name = "dataset", uniqueConstraints = @UniqueConstraint(name = "UQ_current_dataset_version", columnNames={"versionsId", "current"}))
@Cacheable
@Audited
@Document(indexName = "dataset")
......@@ -79,11 +84,13 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Acl
private static final long serialVersionUID = -4601980446454791177L;
/** The versions. */
@ManyToOne(cascade = CascadeType.ALL, optional = false)
@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = false)
@JoinColumn(name = "versionsId", updatable = false)
@JsonIgnore
private DatasetVersions versions;
private Boolean current;
/** The owner. */
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "partnerId", updatable = false)
......@@ -195,6 +202,16 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Acl
@Enumerated(EnumType.ORDINAL)
private PublishState state = PublishState.DRAFT;
@Transient
private UUID currentVersion;
@PostLoad
protected void postLoad() {
if (this.versions != null && versions.getCurrentVersion() != null && !this.uuid.equals(versions.getCurrentVersion().getUuid())) {
this.currentVersion = versions.getCurrentVersion().getUuid();
}
}
/**
* Preupdate.
*/
......@@ -215,6 +232,43 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Acl
trimStringsToNull();
}
/**
* Gets the current.
*
* @return the current
*/
public Boolean getCurrent() {
return current;
}
/**
* Sets current value
*
* @param current the new value of current
*/
public void setCurrent(final Boolean current) {
this.current = current;
}
/**
* Gets the UUID of current dataset
*
* @return the UUID of current dataset
*/
@JsonGetter
public UUID getCurrentVersion() {
return currentVersion;
}
/**
* Sets the UUID of current dataset
*
* @param currentVersion the UUID of current dataset
*/
public void setCurrentVersion(final UUID currentVersion) {
this.currentVersion = currentVersion;
}
/**
* Owner is the ACL parent object for the dataset
*/
......
......@@ -463,4 +463,12 @@ public interface DatasetService {
*/
void writeXlsxMCPD(Dataset dataset, OutputStream outputStream) throws IOException;
/**
* Method creating a new version of Dataset based on an existing published Dataset.
*
* @param source the source
* @return saved Dataset in db.
*/
Dataset createNewVersion(@Valid Dataset source);
}
......@@ -26,9 +26,11 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
......@@ -174,12 +176,15 @@ public class DatasetServiceImpl implements DatasetService {
public Dataset createDataset(@Valid final Dataset source) {
LOG.info("Create Dataset. Input data {}", source);
final DatasetVersions datasetVersions = new DatasetVersions();
datasetVersions.setCurrentVersion(null);
datasetVersionsRepository.save(datasetVersions);
Dataset dataset = new Dataset();
dataset.setUuid(source.getUuid());
dataset.setVersions(datasetVersions);
dataset.setCurrent(null);
copyValues(dataset, source);
dataset.setState(PublishState.DRAFT);
dataset.setOwner(source.getOwner());
dataset.setVersionTag(source.getVersionTag());
dataset.setDescriptors(new ArrayList<>());
......@@ -195,22 +200,8 @@ public class DatasetServiceImpl implements DatasetService {
// Make dataset publicly not-readable
aclService.makePubliclyReadable(dataset, false);
try {
final Path datasetPath = Paths.get(datasetRepositoryPath, dataset.getUuid().toString());
final Partner partner = dataset.getOwner();
// Ensure folder ownership
asAdminInvoker.invoke(() -> {
// Ensure target folder exists for the Dataset
return repositoryService.ensureFolder(datasetPath, partner);
});
} catch (Exception e) {
LOG.warn("Could not update Folder properties: {}", e.getMessage());
}
datasetVersions.setCurrentVersion(dataset);
datasetVersionsRepository.save(datasetVersions);
// Make dataset folder
makeDatasetFolder(dataset.getUuid());
return dataset;
}
......@@ -364,6 +355,82 @@ public class DatasetServiceImpl implements DatasetService {
downloadService.writeXlsxMCPD(queryAccessionId, outputStream, "", "/datasets/" + dataset.getUuid());
}
/**
* {@inheritDoc}
*/
@Override
@Transactional
@PreAuthorize("(hasRole('ADMINISTRATOR') || hasPermission(#source, 'write')) && #source.published")
public Dataset createNewVersion(@Valid Dataset source) {
source = loadDataset(source);
final Dataset dataset = new Dataset();
copyValues(dataset, source);
dataset.setState(PublishState.DRAFT);
dataset.setCurrent(null);
dataset.setUuid(null);
dataset.setVersions(source.getVersions());
dataset.setDescriptors(new ArrayList<>());
copyDescriptors(dataset, source.getDescriptors());
final Dataset saved = lazyLoad(datasetRepository.save(dataset));
setAccessionRefs(saved, new HashSet<>(source.getAccessionRefs()));
// Copy creators
saved.setCreators(new ArrayList<>());
source.getCreators().forEach(creator -> {
entityManager.detach(creator);
creator.setDataset(saved);
creator.setId(null);
creator.setVersion(null);
creator.setUuid(null);
saved.getCreators().add(datasetCreatorRepository.save(creator));
});
// Copy locations
saved.setLocations(new ArrayList<>());
source.getLocations().forEach(location -> {
entityManager.detach(location);
location.setDataset(saved);
location.setId(null);
location.setVersion(null);
location.setUuid(null);
saved.getLocations().add(locationRepository.save(location));
});
saved.setCurrentVersion(source.getUuid());
// Make dataset publicly not-readable
aclService.makePubliclyReadable(saved, false);
// Make dataset folder
makeDatasetFolder(saved.getUuid());
return lazyLoad(saved);
}
private void makeDatasetFolder(final UUID uuid) {
final Dataset dataset = datasetRepository.findByUuid(uuid);
if (dataset == null) {
LOG.warn("Folder wasn't created. No such dataset with UUID={}", uuid.toString());
return;
}
try {
final Path datasetPath = Paths.get(datasetRepositoryPath, dataset.getUuid().toString());
final Partner partner = dataset.getOwner();
// Ensure folder ownership
asAdminInvoker.invoke(() -> {
// Ensure target folder exists for the Dataset
return repositoryService.ensureFolder(datasetPath, partner);
});
} catch (Exception e) {
LOG.warn("Could not update Folder properties: {}", e.getMessage());
}
}
/**
* {@inheritDoc}
*/
......@@ -394,9 +461,11 @@ public class DatasetServiceImpl implements DatasetService {
*/
@Override
public Page<Dataset> listDatasets(final DatasetFilter filter, final Pageable page) {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Dataset> res = datasetRepository.findAll(new BooleanBuilder().and(filter.buildPredicate()).and(QDataset.dataset.state.in(PublishState.PUBLISHED)),
markdownSortPageRequest);
final Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
final BooleanBuilder published = new BooleanBuilder();
published.and(QDataset.dataset.state.eq(PublishState.PUBLISHED).and(QDataset.dataset.current.isTrue()));
published.and(filter.buildPredicate());
final Page<Dataset> res = datasetRepository.findAll(published, markdownSortPageRequest);
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
}
......@@ -576,6 +645,9 @@ public class DatasetServiceImpl implements DatasetService {
if (dataset.getCrops() != null) {
dataset.getCrops().size();
}
if (dataset.getVersions() != null && dataset.getVersions().getAllVersions() != null) {
dataset.getVersions().getAllVersions().size();
}
return dataset;
}
......@@ -705,6 +777,16 @@ public class DatasetServiceImpl implements DatasetService {
// Make dataset publicly readable
aclService.makePubliclyReadable(loaded, true);
final DatasetVersions datasetVersions = loaded.getVersions();
final Dataset oldCurrentDataset = datasetVersions.getAllVersions().stream().filter(s -> Objects.equals(s.getCurrent(), Boolean.TRUE)).findFirst().orElse(null);
if (oldCurrentDataset != null) {
oldCurrentDataset.setCurrent(null);
datasetRepository.save(oldCurrentDataset);
}
loaded.setCurrent(Boolean.TRUE);
datasetVersions.setCurrentVersion(loaded);
datasetVersionsRepository.save(datasetVersions);
return lazyLoad(datasetRepository.save(loaded));
}
......@@ -749,7 +831,7 @@ public class DatasetServiceImpl implements DatasetService {
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'administration')")
public Dataset rejectDataset(final Dataset dataset) {
final Dataset loaded = reloadFromDatabase(dataset);
Dataset loaded = reloadFromDatabase(dataset);
if (loaded == null) {
throw new NotFoundElement("No dataset with specified uuid and version");
}
......@@ -761,6 +843,29 @@ public class DatasetServiceImpl implements DatasetService {
}
}
if (loaded.isPublished() && Objects.equals(loaded.getCurrent(), true)) {
final DatasetVersions datasetVersions = loaded.getVersions();
if (datasetVersions.getAllVersions().size() > 1) {
UUID youngestDatasetUUID = datasetVersions.getAllVersions().stream()
.filter(s -> s.getCurrent() == null)
.max(Comparator.comparing(Dataset::getCreatedDate)).get().getUuid();
loaded.setCurrent(null);
datasetRepository.save(loaded);
Dataset youngestDataset = datasetRepository.findByUuid(youngestDatasetUUID);
youngestDataset.setCurrent(true);
datasetRepository.save(youngestDataset);
datasetVersions.setCurrentVersion(youngestDataset);
} else {
loaded.setCurrent(null);
datasetVersions.setCurrentVersion(null);
}
datasetVersionsRepository.save(datasetVersions);
} else if (loaded.isPublished() && Objects.isNull(loaded.getCurrent())) {
throw new InvalidApiUsageException("Cannot be un-published. The dataset is not the latest version.");
}
loaded.setState(PublishState.DRAFT);
{
......
......@@ -568,4 +568,16 @@ public class DatasetController extends ApiBaseController {
LOG.warn("Download was aborted: {}", e.getMessage());
}
}
/**
* Create a new version of Dataset based on an existing published Dataset.
*
* @param uuid Dataset UUID
* @return the new version of Dataset
*/
@PostMapping(value = "/create-new-version")
public Dataset createNewVersion(@RequestParam(value = "uuid", required = true) final UUID uuid) {
final Dataset dataset = datasetService.loadDataset(uuid);
return datasetService.createNewVersion(dataset);
}
}
......@@ -471,19 +471,39 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
this.source = source;
}
/**
* Gets the owner.
*
* @return the owner
*/
public Partner getOwner() {
return owner;
}
/**
* Sets the owner.
*
* @param owner the owner
*/
public void setOwner(Partner owner) {
this.owner = owner;
}
/**
* Gets the UUID of current subset
*
* @return the UUID of current subset
*/
@JsonGetter
public UUID getCurrentVersion() {
return currentVersion;
}
/**
* Sets the UUID of current subset
*
* @param currentVersion the UUID of current subset
*/
public void setCurrentVersion(UUID currentVersion) {
this.currentVersion = currentVersion;
}
......
......@@ -20,7 +20,9 @@ import static org.genesys2.server.model.impl.QSubsetCreator.subsetCreator;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
......@@ -727,7 +729,8 @@ public class SubsetServiceImpl implements SubsetService {
subset.setUuid(null);
subset.setVersions(source.getVersions());
Subset saved = lazyLoad(subsetRepository.save(subset));
setAccessionRefs(saved, new HashSet<>(source.getAccessionRefs()));
saved.setCreators(new ArrayList<>());
// Copy creators
source.getCreators().forEach(creator -> {
entityManager.detach(creator);
......@@ -735,10 +738,8 @@ public class SubsetServiceImpl implements SubsetService {
creator.setId(null);
creator.setVersion(null);
creator.setUuid(null);
subsetCreatorRepository.save(creator);
saved.getCreators().add(subsetCreatorRepository.save(creator));
});
setAccessionRefs(saved, new HashSet<>(source.getAccessionRefs()));
saved.setCurrentVersion(source.getUuid());
// Make Subset publicly not-readable
......
......@@ -5783,3 +5783,28 @@ databaseChangeLog:
- sql:
comment: Organization renamed to PGRFANetwork
sql: update classpk set classname='org.genesys2.server.model.impl.PGRFANetwork', shortName='pgrfanetwork' where classname='org.genesys2.server.model.impl.Organization';
- changeSet:
id: 1552920444624-1
author: mborodenko
comment: Extend dataset table
changes:
- addColumn:
tableName: dataset
columns:
- column:
name: current
type: BIT(1)
defaultValue: null
- sql:
comment: dataset#current should be true if dataset is published
sql: update dataset set current = true where state = 1
- changeSet:
id: 1552920444624-2
author: mborodenko
changes:
- sql:
comment: dataset_version#currentVersion_id must be null if subset is not published
sql: update dataset_version dv inner join dataset d on dv.currentVersion_id = d.id
set dv.currentVersion_id = null where d.state != 1
......@@ -15,23 +15,32 @@
*/
package org.genesys.test.base;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetCreator;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.catalog.persistence.dataset.DatasetCreatorRepository;
import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.persistence.dataset.DatasetVersionsRepository;
import org.genesys.catalog.persistence.traits.DescriptorRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.filerepository.persistence.RepositoryFilePersistence;
import org.genesys.test.config.ApplicationConfig;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.model.impl.SubsetCreator;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.junit.After;
import org.junit.Before;
......@@ -58,14 +67,25 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public abstract class AbstractApiTest extends AbstractTest {
@Autowired
protected ObjectMapper objectMapper;
protected static final ObjectMapper objectMapper;
protected static final ObjectMapper verboseMapper = new ObjectMapper();
static {
objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
}
@Autowired
private WebApplicationContext webApplicationContext;
@Autowired
protected DatasetRepository datasetRepository;
@Autowired
protected DatasetVersionsRepository datasetVersionsRepository;
@Autowired
protected DatasetCreatorRepository datasetCreatorRepository;
@Autowired
private PartnerRepository partnerRepository;
@Autowired
protected DescriptorRepository descriptorRepository;
......@@ -99,6 +119,8 @@ public abstract class AbstractApiTest extends AbstractTest {
@Override
@Transactional
public void cleanup() throws Exception {
datasetVersionsRepository.deleteAll();
datasetCreatorRepository.deleteAll();
datasetRepository.deleteAll();
repositoryFilePersistence.deleteAll();
partnerRepository.deleteAll();
......@@ -106,20 +128,55 @@ public abstract class AbstractApiTest extends AbstractTest {
super.cleanup();
}
protected Dataset setUpDataset(final PublishState state) {
return setupDataset("Test Dataset Title", "Test Dataset Description", setUpPartner("Partner", true, "PartnerShortName", UUID.randomUUID()), state);
protected Dataset setUpDataset() {
return setupDataset("Test Dataset Title", "Test Dataset Description", setUpPartner("Partner", true, "PartnerShortName", UUID.randomUUID()));
}
protected Dataset setupDataset(final String title, final String description, final Partner owner, final PublishState state) {
protected Dataset setupDataset(final String title, final String description, final Partner owner) {
final Dataset input = new Dataset();
input.setTitle(title);
input.setDescription(description);
input.setOwner(owner);
// input.setAccessions(accessions);
input.setState(state);
return input;
}
protected Dataset toPublished(Dataset dataset) {
if (datasetRepository.findByUuid(dataset.getUuid()) == null) {
dataset = datasetService.createDataset(dataset);
assertThat(dataset.getState(), is(PublishState.DRAFT));
}
if (dataset.getState() == PublishState.DRAFT) {
dataset = datasetService.reviewDataset(dataset);
assertThat(dataset.getState(), is(PublishState.REVIEWING));
}
if (dataset.getState() == PublishState.REVIEWING) {
dataset = datasetService.approveDataset(dataset);
assertThat(dataset.getState(), is(PublishState.PUBLISHED));
}
return dataset;
}
protected DatasetCreator buildDatasetCreator(final String fullName, final String email, final String phoneNumber, final Dataset dataset) {
final DatasetCreator datasetCreator = new DatasetCreator();
datasetCreator.setDataset(dataset);
datasetCreator.setFullName(fullName);
datasetCreator.setRole(DatasetCreator.DatasetCreatorRole.MANAGER);
datasetCreator.setEmail(email);
datasetCreator.setPhoneNumber(phoneNumber);
return datasetCreator;
}
protected SubsetCreator buildSubsetCreator(final String fullName, final String email, final String phoneNumber, final Subset subset) {
final SubsetCreator subsetCreator = new SubsetCreator();
subsetCreator.setSubset(subset);
subsetCreator.setFullName(fullName);
subsetCreator.setRole(SubsetCreator.SubsetCreatorRole.MANAGER);
subsetCreator.setEmail(email);
subsetCreator.setPhoneNumber(phoneNumber);
return subsetCreator;
}
protected Partner setUpPartner(final String name, final boolean isActive, final String shortName, final UUID uuid) {
final Partner partner = new Partner();
partner.setName(name);
......
......@@ -73,8 +73,8 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
@After
@Override
public void cleanup() throws Exception {
datasetRepository.deleteAll();
datasetVersionsRepository.deleteAll();
datasetRepository.deleteAll();
descriptorRepository.deleteAll();
repositoryFilePersistence.deleteAll();
super.cleanup();
......@@ -93,6 +93,19 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
return input;
}
protected Dataset toPublished(Dataset dataset) {
if (datasetRepository.findByUuid(dataset.getUuid()) == null) {
dataset = datasetService.createDataset(buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT));
}
if (dataset.getState() == PublishState.DRAFT) {
dataset = datasetService.reviewDataset(dataset);
}
if (dataset.getState() == PublishState.REVIEWING) {
dataset = datasetService.approveDataset(dataset);
}
return dataset;
}
protected DatasetCreator buildDatasetCreator(final String fullName, final String email, final String phoneNumber, final Dataset dataset) {
final DatasetCreator datasetCreator = new DatasetCreator();
datasetCreator.setDataset(dataset);
......
......@@ -36,8 +36,6 @@ public class DatasetPublishingTest extends AbstractDatasetServiceTest {
@Transactional
public void cleanup() throws Exception {
savedDataset = null;
descriptorRepository.deleteAll();
datasetRepository.deleteAll();
super.cleanup();
}
......
......@@ -71,7 +71,8 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
assertThat(input, not(nullValue()));
assertThat(input.getId(), not(nullValue()));
assertThat(input.getVersions(), not(nullValue()));
assertThat(input.getVersions().getCurrentVersion(), is(input));
assertNull(input.getVersions().getCurrentVersion());
assertEquals(input.getState(), PublishState.DRAFT);
}
/**
......@@ -446,9 +447,9 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
@Test
public void testListMarkdownSortDatasets() {
final Dataset dataset1 = buildAndSaveDataset("Dataset 1", DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED);
final Dataset dataset2 = buildAndSaveDataset("*Dataset* 2", DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED);
final Dataset dataset3 = buildAndSaveDataset("Dataset 3", DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED);
final Dataset dataset1 = toPublished(buildAndSaveDataset("Dataset 1", DATASET_DESCRIPTION_1, partner, PublishState.DRAFT));
final Dataset dataset2 = toPublished(buildAndSaveDataset("*Dataset* 2", DATASET_DESCRIPTION_1, partner, PublishState.DRAFT));
final Dataset dataset3 = toPublished(buildAndSaveDataset("Dataset 3", DATASET_DESCRIPTION_1, partner, PublishState.DRAFT));
final String[] strs = new String[] { "title" };
final Pageable pageable = new PageRequest(0, Integer.min(50, 100), Sort.Direction.ASC, strs);
......@@ -465,25 +466,30 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
// not listed
buildAndSaveDataset("Not published " + DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
// listed
final Dataset input = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.PUBLISHED);
final Dataset published = toPublished(new Dataset());
final String[] strs = new String[] { "title" };
final Pageable pageable = new PageRequest(0, Integer.min(50, 100), Sort.Direction.ASC, strs);
final Page<?> page = datasetService.listDatasets(new DatasetFilter(), pageable);
final String[] sortBy = new String[] { "title" };
final Pageable pageable = new PageRequest(0, Integer.min(50, 100), Sort.Direction.ASC, sortBy);
final Page<Dataset> page = datasetService.listDatasets(new DatasetFilter(), pageable);
assertThat(page.getTotalElements(), is(1L));
assertThat(((Dataset) page.getContent().get(0)).getUuid(), is(input.getUuid()));
assertThat((page.getContent().get(0)).getUuid(), is(published.getUuid()));
}
@Test
public void testLoadCurrentVersionList() {
final Dataset result = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT);
final Dataset dataset_1 = toPublished(buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, PublishState.DRAFT));
assertTrue(dataset_1.getCurrent());
final String[] strs = new String[] { "title" };
final Pageable pageable = new PageRequest(0, Integer.min(50, 100), Sort.Direction.ASC, strs);
final Page<?> page = datasetService.loadCurrentVersionList(pageable);
final Dataset dataset_2 = datasetService.createNewVersion(dataset_1);
assertNull(dataset_2.getCurrent());
assertTrue(datasetRepository.findByUuid(dataset_1.getUuid()).getCurrent());