use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class MocksFactory method makeDataset.
public static Dataset makeDataset() {
Dataset ds = new Dataset();
ds.setId(nextId());
ds.setIdentifier("sample-ds-" + ds.getId());
ds.setCategoriesByName(Arrays.asList("CatOne", "CatTwo", "CatThree"));
final List<DataFile> files = makeFiles(10);
final List<FileMetadata> metadatas = new ArrayList<>(10);
final List<DataFileCategory> categories = ds.getCategories();
Random rand = new Random();
files.forEach(df -> {
df.getFileMetadata().addCategory(categories.get(rand.nextInt(categories.size())));
metadatas.add(df.getFileMetadata());
});
ds.setFiles(files);
final DatasetVersion initialVersion = ds.getVersions().get(0);
initialVersion.setFileMetadatas(metadatas);
List<DatasetField> fields = new ArrayList<>();
DatasetField field = new DatasetField();
field.setId(nextId());
field.setSingleValue("Sample Field Value");
field.setDatasetFieldType(makeDatasetFieldType());
fields.add(field);
initialVersion.setDatasetFields(fields);
ds.setOwner(makeDataverse());
return ds;
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class GetLatestPublishedDatasetVersionCommandTest method testLatestPublishedNoDraft.
@Test
public void testLatestPublishedNoDraft() throws CommandException {
Dataset ds = MocksFactory.makeDataset();
List<DatasetVersion> versions = make10Versions(ds);
ds.setVersions(versions);
assertEquals(10l, engine.submit(new GetLatestPublishedDatasetVersionCommand(makeRequest(), ds)).getVersionNumber().longValue());
assertTrue("Published datasets should require no permissions to view", engine.getReqiredPermissionsForObjects().get(ds).isEmpty());
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class GetLatestPublishedDatasetVersionCommandTest method testLatestPublishedWithDraft.
@Test
public void testLatestPublishedWithDraft() throws CommandException {
Dataset ds = MocksFactory.makeDataset();
List<DatasetVersion> versions = make10Versions(ds);
versions.add(MocksFactory.makeDatasetVersion(ds.getCategories()));
ds.setVersions(versions);
assertEquals(10l, engine.submit(new GetLatestPublishedDatasetVersionCommand(makeRequest(), ds)).getVersionNumber().longValue());
assertTrue("Published datasets should require no permissions to view", engine.getReqiredPermissionsForObjects().get(ds).isEmpty());
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class DatasetUtilTest method testGetThumbnailCandidates.
/**
* Test of getThumbnailCandidates method, of class DatasetUtil.
*/
@Test
public void testGetThumbnailCandidates() {
assertEquals(new ArrayList<>(), DatasetUtil.getThumbnailCandidates(null, false));
Dataset dataset = MocksFactory.makeDataset();
DataFile dataFile = MocksFactory.makeDataFile();
dataFile.setContentType("image/");
dataFile.setOwner(dataset);
dataFile.setStorageIdentifier("file://src/test/resources/images/coffeeshop.png");
System.out.println(ImageThumbConverter.isThumbnailAvailable(dataFile));
DatasetVersion version = dataset.getCreateVersion();
List<FileMetadata> fmds = new ArrayList<>();
fmds.add(MocksFactory.addFileMetadata(dataFile));
version.setFileMetadatas(fmds);
assertEquals(new ArrayList<>(), DatasetUtil.getThumbnailCandidates(dataset, false));
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class PrivateUrlUtil method getDraftDatasetVersionFromRoleAssignment.
/**
* @return DatasetVersion if a draft or null.
*
* @todo If there is a use case for this outside the context of Private URL,
* move this method to somewhere more centralized.
*/
public static DatasetVersion getDraftDatasetVersionFromRoleAssignment(RoleAssignment roleAssignment) {
if (roleAssignment == null) {
return null;
}
Dataset dataset = getDatasetFromRoleAssignment(roleAssignment);
if (dataset != null) {
DatasetVersion latestVersion = dataset.getLatestVersion();
if (latestVersion.isDraft()) {
return latestVersion;
}
}
logger.fine("Couldn't find draft, returning null");
return null;
}
Aggregations