Search in sources :

Example 96 with Dataset

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

the class JsonPrinterTest method testJson_RoleAssignment.

@Test
public void testJson_RoleAssignment() {
    DataverseRole aRole = new DataverseRole();
    PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUserIn;
    Dataset dataset = new Dataset();
    dataset.setId(123l);
    String privateUrlToken = "e1d53cf6-794a-457a-9709-7c07629a8267";
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    JsonObjectBuilder job = JsonPrinter.json(ra);
    assertNotNull(job);
    JsonObject jsonObject = job.build();
    assertEquals("#42", jsonObject.getString("assignee"));
    assertEquals(123, jsonObject.getInt("definitionPointId"));
    assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("privateUrlToken"));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 97 with Dataset

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

the class FileUtilTest method testIsDownloadPopupRequiredDraft.

@Test
public void testIsDownloadPopupRequiredDraft() {
    Dataset dataset = new Dataset();
    DatasetVersion dsv1 = dataset.getEditVersion();
    assertEquals(DatasetVersion.VersionState.DRAFT, dsv1.getVersionState());
    assertEquals(false, FileUtil.isDownloadPopupRequired(dsv1));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Test(org.junit.Test)

Example 98 with Dataset

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

the class FileUtilTest method testIsPubliclyDownloadable2.

@Test
public void testIsPubliclyDownloadable2() {
    FileMetadata nonRestrictedFileMetadata = new FileMetadata();
    DatasetVersion dsv = new DatasetVersion();
    TermsOfUseAndAccess termsOfUseAndAccess = new TermsOfUseAndAccess();
    termsOfUseAndAccess.setTermsOfUse("be excellent to each other");
    dsv.setTermsOfUseAndAccess(termsOfUseAndAccess);
    dsv.setVersionState(DatasetVersion.VersionState.RELEASED);
    nonRestrictedFileMetadata.setDatasetVersion(dsv);
    Dataset dataset = new Dataset();
    dsv.setDataset(dataset);
    nonRestrictedFileMetadata.setRestricted(false);
    assertEquals(false, FileUtil.isPubliclyDownloadable(nonRestrictedFileMetadata));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) TermsOfUseAndAccess(edu.harvard.iq.dataverse.TermsOfUseAndAccess) Test(org.junit.Test)

Example 99 with Dataset

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

the class FileUtilTest method testIsPubliclyDownloadable.

@Test
public void testIsPubliclyDownloadable() {
    assertEquals(false, FileUtil.isPubliclyDownloadable(null));
    FileMetadata restrictedFileMetadata = new FileMetadata();
    restrictedFileMetadata.setRestricted(true);
    assertEquals(false, FileUtil.isPubliclyDownloadable(restrictedFileMetadata));
    FileMetadata nonRestrictedFileMetadata = new FileMetadata();
    DatasetVersion dsv = new DatasetVersion();
    dsv.setVersionState(DatasetVersion.VersionState.RELEASED);
    nonRestrictedFileMetadata.setDatasetVersion(dsv);
    Dataset dataset = new Dataset();
    dsv.setDataset(dataset);
    nonRestrictedFileMetadata.setRestricted(false);
    assertEquals(true, FileUtil.isPubliclyDownloadable(nonRestrictedFileMetadata));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Test(org.junit.Test)

Example 100 with Dataset

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

the class Dataverses method createDataset.

@POST
@Path("{identifier}/datasets")
public Response createDataset(String jsonBody, @PathParam("identifier") String parentIdtf) {
    try {
        User u = findUserOrDie();
        Dataverse owner = findDataverseOrDie(parentIdtf);
        JsonObject json;
        try (StringReader rdr = new StringReader(jsonBody)) {
            json = Json.createReader(rdr).readObject();
        } catch (JsonParsingException jpe) {
            LOGGER.log(Level.SEVERE, "Json: {0}", jsonBody);
            return error(Status.BAD_REQUEST, "Error parsing Json: " + jpe.getMessage());
        }
        Dataset ds = new Dataset();
        ds.setOwner(owner);
        JsonObject jsonVersion = json.getJsonObject("datasetVersion");
        if (jsonVersion == null) {
            return error(Status.BAD_REQUEST, "Json POST data are missing datasetVersion object.");
        }
        try {
            try {
                DatasetVersion version = new DatasetVersion();
                version.setDataset(ds);
                // Use the two argument version so that the version knows which dataset it's associated with.
                version = jsonParser().parseDatasetVersion(jsonVersion, version);
                // force "initial version" properties
                version.setMinorVersionNumber(null);
                version.setVersionNumber(null);
                version.setVersionState(DatasetVersion.VersionState.DRAFT);
                LinkedList<DatasetVersion> versions = new LinkedList<>();
                versions.add(version);
                version.setDataset(ds);
                ds.setVersions(versions);
            } catch (javax.ejb.TransactionRolledbackLocalException rbe) {
                throw rbe.getCausedByException();
            }
        } catch (JsonParseException ex) {
            LOGGER.log(Level.INFO, "Error parsing dataset version from Json", ex);
            return error(Status.BAD_REQUEST, "Error parsing datasetVersion: " + ex.getMessage());
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "Error parsing dataset version from Json", e);
            return error(Status.INTERNAL_SERVER_ERROR, "Error parsing datasetVersion: " + e.getMessage());
        }
        Dataset managedDs = execCommand(new CreateDatasetCommand(ds, createDataverseRequest(u)));
        return created("/datasets/" + managedDs.getId(), Json.createObjectBuilder().add("id", managedDs.getId()).add("persistentId", managedDs.getGlobalId()));
    } catch (WrappedResponse ex) {
        return ex.getResponse();
    }
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) Dataset(edu.harvard.iq.dataverse.Dataset) CreateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand) JsonObject(javax.json.JsonObject) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) Dataverse(edu.harvard.iq.dataverse.Dataverse) LinkedList(java.util.LinkedList) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) EJBException(javax.ejb.EJBException) JsonParsingException(javax.json.stream.JsonParsingException) ConstraintViolationException(javax.validation.ConstraintViolationException) StringReader(java.io.StringReader) JsonParsingException(javax.json.stream.JsonParsingException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

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