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"));
}
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));
}
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));
}
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));
}
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();
}
}
Aggregations