use of edu.harvard.iq.dataverse.DatasetVersion 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.DatasetVersion 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();
}
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class Index method indexDatasetByPersistentId.
@GET
@Path("dataset")
public Response indexDatasetByPersistentId(@QueryParam("persistentId") String persistentId) {
if (persistentId == null) {
return error(Status.BAD_REQUEST, "No persistent id given.");
}
Dataset dataset = null;
try {
dataset = datasetService.findByGlobalId(persistentId);
} catch (Exception ex) {
return error(Status.BAD_REQUEST, "Problem looking up dataset with persistent id \"" + persistentId + "\". Error: " + ex.getMessage());
}
if (dataset != null) {
boolean doNormalSolrDocCleanUp = true;
Future<String> indexDatasetFuture = indexService.indexDataset(dataset, doNormalSolrDocCleanUp);
JsonObjectBuilder data = Json.createObjectBuilder();
data.add("message", "Reindexed dataset " + persistentId);
data.add("id", dataset.getId());
data.add("persistentId", dataset.getGlobalId());
JsonArrayBuilder versions = Json.createArrayBuilder();
for (DatasetVersion version : dataset.getVersions()) {
JsonObjectBuilder versionObject = Json.createObjectBuilder();
versionObject.add("semanticVersion", version.getSemanticVersion());
versionObject.add("id", version.getId());
versions.add(versionObject);
}
data.add("versions", versions);
return ok(data);
} else {
return error(Status.BAD_REQUEST, "Could not find dataset with persistent id " + persistentId);
}
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class Access method datafileBundle.
// @EJB
// TODO:
// versions? -- L.A. 4.0 beta 10
@Path("datafile/bundle/{fileId}")
@GET
@Produces({ "application/zip" })
public BundleDownloadInstance datafileBundle(@PathParam("fileId") Long fileId, @QueryParam("gbrecs") Boolean gbrecs, @QueryParam("key") String apiToken, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) /*throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/
{
DataFile df = dataFileService.find(fileId);
GuestbookResponse gbr = null;
if (df == null) {
logger.warning("Access: datafile service could not locate a DataFile object for id " + fileId + "!");
throw new NotFoundException();
}
if (apiToken == null || apiToken.equals("")) {
apiToken = headers.getHeaderString(API_KEY_HEADER);
}
// This will throw a ForbiddenException if access isn't authorized:
checkAuthorization(df, apiToken);
if (gbrecs == null && df.isReleased()) {
// Write Guestbook record if not done previously and file is released
User apiTokenUser = findAPITokenUser(apiToken);
gbr = guestbookResponseService.initAPIGuestbookResponse(df.getOwner(), df, session, apiTokenUser);
guestbookResponseService.save(gbr);
}
DownloadInfo dInfo = new DownloadInfo(df);
BundleDownloadInstance downloadInstance = new BundleDownloadInstance(dInfo);
FileMetadata fileMetadata = df.getFileMetadata();
DatasetVersion datasetVersion = df.getOwner().getLatestVersion();
downloadInstance.setFileCitationEndNote(datasetService.createCitationXML(datasetVersion, fileMetadata));
downloadInstance.setFileCitationRIS(datasetService.createCitationRIS(datasetVersion, fileMetadata));
downloadInstance.setFileCitationBibtex(new BibtexCitation(datasetVersion).toString());
ByteArrayOutputStream outStream = null;
outStream = new ByteArrayOutputStream();
try {
ddiExportService.exportDataFile(fileId, outStream, null, null);
downloadInstance.setFileDDIXML(outStream.toString());
} catch (Exception ex) {
// if we can't generate the DDI, it's ok;
// we'll just generate the bundle without it.
}
return downloadInstance;
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class Access method dsCardImage.
// Note:
// the Dataverse page is no longer using this method.
@Path("dsCardImage/{versionId}")
@GET
@Produces({ "image/png" })
public InputStream dsCardImage(@PathParam("versionId") Long versionId, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) /*throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/
{
DatasetVersion datasetVersion = versionService.find(versionId);
if (datasetVersion == null) {
logger.warning("Preview: Version service could not locate a DatasetVersion object for id " + versionId + "!");
return null;
}
// String imageThumbFileName = null;
StorageIO thumbnailDataAccess = null;
if (datasetVersion.getDataset() != null) {
DataFile logoDataFile = datasetVersion.getDataset().getThumbnailFile();
if (logoDataFile != null) {
try {
StorageIO<DataFile> dataAccess = logoDataFile.getStorageIO();
if (dataAccess != null) {
// && dataAccess.isLocalFile()) {
dataAccess.open();
thumbnailDataAccess = ImageThumbConverter.getImageThumbnailAsInputStream(dataAccess, 48);
}
} catch (IOException ioEx) {
thumbnailDataAccess = null;
}
}
if (thumbnailDataAccess != null && thumbnailDataAccess.getInputStream() != null) {
return thumbnailDataAccess.getInputStream();
}
}
return null;
}
Aggregations