Search in sources :

Example 46 with Dataset

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);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 47 with Dataset

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);
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) DataTable(edu.harvard.iq.dataverse.DataTable) Dataset(edu.harvard.iq.dataverse.Dataset) MocksFactory.makeDataset(edu.harvard.iq.dataverse.mocks.MocksFactory.makeDataset) ArrayList(java.util.ArrayList) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) SimpleDateFormat(java.text.SimpleDateFormat) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.Test)

Example 48 with Dataset

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);
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) Dataset(edu.harvard.iq.dataverse.Dataset) MocksFactory.makeDataset(edu.harvard.iq.dataverse.mocks.MocksFactory.makeDataset) ArrayList(java.util.ArrayList) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) SimpleDateFormat(java.text.SimpleDateFormat) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.Test)

Example 49 with Dataset

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);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) Test(org.junit.Test)

Example 50 with Dataset

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);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) Test(org.junit.Test)

Aggregations

Dataset (edu.harvard.iq.dataverse.Dataset)142 Test (org.junit.Test)53 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)44 DataFile (edu.harvard.iq.dataverse.DataFile)41 Dataverse (edu.harvard.iq.dataverse.Dataverse)34 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)27 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)22 Path (javax.ws.rs.Path)22 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)17 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)17 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)16 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)16 Date (java.util.Date)16 JsonObjectBuilder (javax.json.JsonObjectBuilder)16 JsonObject (javax.json.JsonObject)15 DvObject (edu.harvard.iq.dataverse.DvObject)14 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)14 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)14