Search in sources :

Example 6 with Dataset

use of edu.harvard.iq.dataverse.Dataset 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;
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) DataFileCategory(edu.harvard.iq.dataverse.DataFileCategory) Random(java.util.Random) DatasetField(edu.harvard.iq.dataverse.DatasetField) Dataset(edu.harvard.iq.dataverse.Dataset) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion)

Example 7 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class GetPrivateUrlCommandTest method testDatasetWithoutAnId.

@Test
public void testDatasetWithoutAnId() throws Exception {
    dataset = new Dataset();
    PrivateUrl privateUrl = testEngine.submit(new GetPrivateUrlCommand(null, dataset));
    assertNull(privateUrl);
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) Test(org.junit.Test)

Example 8 with Dataset

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

Example 9 with Dataset

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

Example 10 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class GetLatestPublishedDatasetVersionCommandTest method testLatestNonePublished.

@Test
public void testLatestNonePublished() throws CommandException {
    Dataset ds = MocksFactory.makeDataset();
    assertNull(engine.submit(new GetLatestPublishedDatasetVersionCommand(makeRequest(), ds)));
}
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