use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetUserFromRoleAssignmentSucess.
@Test
public void testGetUserFromRoleAssignmentSucess() {
DataverseRole aRole = null;
PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUserIn;
DvObject dataset = new Dataset();
dataset.setId(123l);
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
PrivateUrlUser privateUrlUserOut = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(ra);
assertNotNull(privateUrlUserOut);
}
use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class IngestUtilTest method testCheckForDuplicateFileNamesTabular.
@Test
public /**
* Test tabular files (e.g., .dta) are changed when .tab files with the same
* name exist.
*/
void testCheckForDuplicateFileNamesTabular() throws Exception {
SimpleDateFormat dateFmt = new SimpleDateFormat("yyyyMMdd");
// create dataset
Dataset dataset = makeDataset();
// create dataset version
DatasetVersion datasetVersion = dataset.getEditVersion();
datasetVersion.setCreateTime(dateFmt.parse("20001012"));
datasetVersion.setLastUpdateTime(datasetVersion.getLastUpdateTime());
datasetVersion.setId(MocksFactory.nextId());
datasetVersion.setReleaseTime(dateFmt.parse("20010101"));
datasetVersion.setVersionState(DatasetVersion.VersionState.RELEASED);
datasetVersion.setMinorVersionNumber(0L);
datasetVersion.setVersionNumber(1L);
datasetVersion.setFileMetadatas(new ArrayList<>());
// create datafiles
List<DataFile> dataFileList = new ArrayList<>();
DataFile datafile1 = new DataFile("application/x-strata");
datafile1.setStorageIdentifier("foobar.dta");
datafile1.setFilesize(200);
datafile1.setModificationTime(new Timestamp(new Date().getTime()));
datafile1.setCreateDate(new Timestamp(new Date().getTime()));
datafile1.setPermissionModificationTime(new Timestamp(new Date().getTime()));
datafile1.setOwner(dataset);
datafile1.setIngestDone();
datafile1.setChecksumType(DataFile.ChecksumType.SHA1);
datafile1.setChecksumValue("Unknown");
DataTable dt1 = new DataTable();
dt1.setOriginalFileFormat("application/x-stata");
datafile1.setDataTable(dt1);
// set metadata and add version
FileMetadata fmd1 = new FileMetadata();
fmd1.setId(1L);
fmd1.setLabel("foobar.tab");
fmd1.setDataFile(datafile1);
datafile1.getFileMetadatas().add(fmd1);
datasetVersion.getFileMetadatas().add(fmd1);
fmd1.setDatasetVersion(datasetVersion);
DataFile datafile2 = new DataFile("application/x-strata");
datafile2.setStorageIdentifier("foobar.dta");
datafile2.setFilesize(200);
datafile2.setModificationTime(new Timestamp(new Date().getTime()));
datafile2.setCreateDate(new Timestamp(new Date().getTime()));
datafile2.setPermissionModificationTime(new Timestamp(new Date().getTime()));
datafile2.setOwner(dataset);
datafile2.setIngestDone();
datafile2.setChecksumType(DataFile.ChecksumType.SHA1);
datafile2.setChecksumValue("Unknown");
DataTable dt2 = new DataTable();
dt2.setOriginalFileFormat("application/x-stata");
datafile2.setDataTable(dt2);
// set metadata and add version
FileMetadata fmd2 = new FileMetadata();
fmd2.setId(2L);
fmd2.setLabel("foobar.dta");
fmd2.setDataFile(datafile2);
datafile2.getFileMetadatas().add(fmd2);
dataFileList.add(datafile2);
IngestUtil.checkForDuplicateFileNamesFinal(datasetVersion, dataFileList);
boolean file2NameAltered = false;
for (DataFile df : dataFileList) {
if (df.getFileMetadata().getLabel().equals("foobar-1.dta")) {
file2NameAltered = true;
}
}
// check filename is altered since tabular and will change to .tab after ingest
assertEquals(file2NameAltered, true);
}
use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class IngestUtilTest method testCheckForDuplicateFileNamesWithEmptyDirectoryLabels.
@Test
public /**
* Test adding duplicate file name labels to a dataset version with empty
* directory labels. This should simulate what happens when uploading a file
* via the file upload UI.
*/
void testCheckForDuplicateFileNamesWithEmptyDirectoryLabels() throws Exception {
SimpleDateFormat dateFmt = new SimpleDateFormat("yyyyMMdd");
// create dataset
Dataset dataset = makeDataset();
// create dataset version
DatasetVersion datasetVersion = dataset.getEditVersion();
datasetVersion.setCreateTime(dateFmt.parse("20001012"));
datasetVersion.setLastUpdateTime(datasetVersion.getLastUpdateTime());
datasetVersion.setId(MocksFactory.nextId());
datasetVersion.setReleaseTime(dateFmt.parse("20010101"));
datasetVersion.setVersionState(DatasetVersion.VersionState.RELEASED);
datasetVersion.setMinorVersionNumber(0L);
datasetVersion.setVersionNumber(1L);
datasetVersion.setFileMetadatas(new ArrayList<>());
// create datafiles
List<DataFile> dataFileList = new ArrayList<>();
DataFile datafile1 = new DataFile("application/octet-stream");
datafile1.setStorageIdentifier("datafile1.txt");
datafile1.setFilesize(200);
datafile1.setModificationTime(new Timestamp(new Date().getTime()));
datafile1.setCreateDate(new Timestamp(new Date().getTime()));
datafile1.setPermissionModificationTime(new Timestamp(new Date().getTime()));
datafile1.setOwner(dataset);
datafile1.setIngestDone();
datafile1.setChecksumType(DataFile.ChecksumType.SHA1);
datafile1.setChecksumValue("Unknown");
// set metadata and add verson
FileMetadata fmd1 = new FileMetadata();
fmd1.setId(1L);
fmd1.setLabel("datafile1.txt");
fmd1.setDirectoryLabel("");
fmd1.setDataFile(datafile1);
datafile1.getFileMetadatas().add(fmd1);
datasetVersion.getFileMetadatas().add(fmd1);
fmd1.setDatasetVersion(datasetVersion);
dataFileList.add(datafile1);
DataFile datafile2 = new DataFile("application/octet-stream");
datafile2.setStorageIdentifier("datafile2.txt");
datafile2.setFilesize(200);
datafile2.setModificationTime(new Timestamp(new Date().getTime()));
datafile2.setCreateDate(new Timestamp(new Date().getTime()));
datafile2.setPermissionModificationTime(new Timestamp(new Date().getTime()));
datafile2.setOwner(dataset);
datafile2.setIngestDone();
datafile2.setChecksumType(DataFile.ChecksumType.SHA1);
datafile2.setChecksumValue("Unknown");
// set metadata and add version
FileMetadata fmd2 = new FileMetadata();
fmd2.setId(2L);
fmd2.setLabel("datafile2.txt");
fmd2.setDirectoryLabel("");
fmd2.setDataFile(datafile2);
datafile2.getFileMetadatas().add(fmd2);
datasetVersion.getFileMetadatas().add(fmd2);
fmd2.setDatasetVersion(datasetVersion);
dataFileList.add(datafile2);
IngestUtil.checkForDuplicateFileNamesFinal(datasetVersion, dataFileList);
boolean file1NameAltered = false;
boolean file2NameAltered = false;
for (DataFile df : dataFileList) {
if (df.getFileMetadata().getLabel().equals("datafile1-1.txt")) {
file1NameAltered = true;
}
if (df.getFileMetadata().getLabel().equals("datafile2-1.txt")) {
file2NameAltered = true;
}
}
// check filenames are unique and unaltered
assertEquals(file1NameAltered, true);
assertEquals(file2NameAltered, true);
// try to add data files with "-1" duplicates and see if it gets incremented to "-2"
IngestUtil.checkForDuplicateFileNamesFinal(datasetVersion, dataFileList);
for (DataFile df : dataFileList) {
if (df.getFileMetadata().getLabel().equals("datafile1-2.txt")) {
file1NameAltered = true;
}
if (df.getFileMetadata().getLabel().equals("datafile2-2.txt")) {
file2NameAltered = true;
}
}
// check filenames are unique and unaltered
assertEquals(file1NameAltered, true);
assertEquals(file2NameAltered, true);
}
use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class RepositoryStorageAbstractionLayerUtilTest method testGetVerifyDataCommand.
@Test
public void testGetVerifyDataCommand() {
System.out.println("getVerifyDataCommand");
Dataset dataset = new Dataset();
dataset.setIdentifier("identifierPartOfPersistentID");
String result = RepositoryStorageAbstractionLayerUtil.getVerifyDataCommand(dataset);
assertEquals("cd identifierPartOfPersistentID ; shasum -c files.sha", result);
}
use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class RepositoryStorageAbstractionLayerUtilTest method testGetLocalDataAccessDirectory.
@Test
public void testGetLocalDataAccessDirectory() {
System.out.println("getLocalDataAccessDirectory");
String localDataAccessParentDir = "/opt/data";
Dataset dataset = new Dataset();
dataset.setIdentifier("identifierPartOfPersistentID");
dataset.setAuthority("10.5072/FK2");
String result = RepositoryStorageAbstractionLayerUtil.getLocalDataAccessDirectory(localDataAccessParentDir, dataset);
assertEquals("/opt/data/10.5072/FK2/identifierPartOfPersistentID", result);
}
Aggregations