Search in sources :

Example 6 with DatasetVersion

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;
}
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 DatasetVersion

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

Example 8 with DatasetVersion

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

Example 9 with DatasetVersion

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

Example 10 with DatasetVersion

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

Aggregations

DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)85 Dataset (edu.harvard.iq.dataverse.Dataset)43 Test (org.junit.Test)36 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)25 ArrayList (java.util.ArrayList)24 DataFile (edu.harvard.iq.dataverse.DataFile)19 JsonObject (javax.json.JsonObject)15 Date (java.util.Date)13 StringReader (java.io.StringReader)11 IOException (java.io.IOException)10 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)9 Timestamp (java.sql.Timestamp)9 EJBException (javax.ejb.EJBException)9 JsonParser (edu.harvard.iq.dataverse.util.json.JsonParser)8 JsonObjectBuilder (javax.json.JsonObjectBuilder)8 JsonReader (javax.json.JsonReader)8 DatasetField (edu.harvard.iq.dataverse.DatasetField)7 Dataverse (edu.harvard.iq.dataverse.Dataverse)7 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)7 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)7