use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class Datasets method moveDataset.
@POST
@Path("{id}/move/{targetDataverseAlias}")
public Response moveDataset(@PathParam("id") String id, @PathParam("targetDataverseAlias") String targetDataverseAlias, @QueryParam("forceMove") Boolean force) {
try {
System.out.print("force: " + force);
User u = findUserOrDie();
Dataset ds = findDatasetOrDie(id);
Dataverse target = dataverseService.findByAlias(targetDataverseAlias);
if (target == null) {
return error(Response.Status.BAD_REQUEST, "Target Dataverse not found.");
}
// Command requires Super user - it will be tested by the command
execCommand(new MoveDatasetCommand(createDataverseRequest(u), ds, target, force));
return ok("Dataset moved successfully");
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class Datasets method getDatasetThumbnailCandidates.
@GET
@Path("{id}/thumbnail/candidates")
public Response getDatasetThumbnailCandidates(@PathParam("id") String idSupplied) {
try {
Dataset dataset = findDatasetOrDie(idSupplied);
boolean canUpdateThumbnail = false;
try {
canUpdateThumbnail = permissionSvc.requestOn(createDataverseRequest(findUserOrDie()), dataset).canIssue(UpdateDatasetThumbnailCommand.class);
} catch (WrappedResponse ex) {
logger.info("Exception thrown while trying to figure out permissions while getting thumbnail for dataset id " + dataset.getId() + ": " + ex.getLocalizedMessage());
}
if (!canUpdateThumbnail) {
return error(Response.Status.FORBIDDEN, "You are not permitted to list dataset thumbnail candidates.");
}
JsonArrayBuilder data = Json.createArrayBuilder();
boolean considerDatasetLogoAsCandidate = true;
for (DatasetThumbnail datasetThumbnail : DatasetUtil.getThumbnailCandidates(dataset, considerDatasetLogoAsCandidate)) {
JsonObjectBuilder candidate = Json.createObjectBuilder();
String base64image = datasetThumbnail.getBase64image();
if (base64image != null) {
logger.fine("found a candidate!");
candidate.add("base64image", base64image);
}
DataFile dataFile = datasetThumbnail.getDataFile();
if (dataFile != null) {
candidate.add("dataFileId", dataFile.getId());
}
data.add(candidate);
}
return ok(data);
} catch (WrappedResponse ex) {
return error(Response.Status.NOT_FOUND, "Could not find dataset based on id supplied: " + idSupplied + ".");
}
}
use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class Datasets method updateDraftVersion.
@PUT
@Path("{id}/versions/{versionId}")
public Response updateDraftVersion(String jsonBody, @PathParam("id") String id, @PathParam("versionId") String versionId) {
if (!":draft".equals(versionId)) {
return error(Response.Status.BAD_REQUEST, "Only the :draft version can be updated");
}
try (StringReader rdr = new StringReader(jsonBody)) {
DataverseRequest req = createDataverseRequest(findUserOrDie());
Dataset ds = findDatasetOrDie(id);
JsonObject json = Json.createReader(rdr).readObject();
DatasetVersion incomingVersion = jsonParser().parseDatasetVersion(json);
// clear possibly stale fields from the incoming dataset version.
// creation and modification dates are updated by the commands.
incomingVersion.setId(null);
incomingVersion.setVersionNumber(null);
incomingVersion.setMinorVersionNumber(null);
incomingVersion.setVersionState(DatasetVersion.VersionState.DRAFT);
incomingVersion.setDataset(ds);
incomingVersion.setCreateTime(null);
incomingVersion.setLastUpdateTime(null);
boolean updateDraft = ds.getLatestVersion().isDraft();
DatasetVersion managedVersion = execCommand(updateDraft ? new UpdateDatasetVersionCommand(req, incomingVersion) : new CreateDatasetVersionCommand(req, ds, incomingVersion));
return ok(json(managedVersion));
} catch (JsonParseException ex) {
logger.log(Level.SEVERE, "Semantic error parsing dataset version Json: " + ex.getMessage(), ex);
return error(Response.Status.BAD_REQUEST, "Error parsing dataset version: " + ex.getMessage());
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class Datasets method publishDataset.
@POST
@Path("{id}/actions/:publish")
public Response publishDataset(@PathParam("id") String id, @QueryParam("type") String type) {
try {
if (type == null) {
return error(Response.Status.BAD_REQUEST, "Missing 'type' parameter (either 'major' or 'minor').");
}
type = type.toLowerCase();
boolean isMinor;
switch(type) {
case "minor":
isMinor = true;
break;
case "major":
isMinor = false;
break;
default:
return error(Response.Status.BAD_REQUEST, "Illegal 'type' parameter value '" + type + "'. It needs to be either 'major' or 'minor'.");
}
Dataset ds = findDatasetOrDie(id);
PublishDatasetResult res = execCommand(new PublishDatasetCommand(ds, createDataverseRequest(findAuthenticatedUserOrDie()), isMinor));
return res.isCompleted() ? ok(json(res.getDataset())) : accepted(json(res.getDataset()));
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.
the class Datasets method getRsync.
@GET
@Path("{identifier}/dataCaptureModule/rsync")
public Response getRsync(@PathParam("identifier") String id) {
// TODO - does it make sense to switch this to dataset identifier for consistency with the rest of the DCM APIs?
if (!DataCaptureModuleUtil.rsyncSupportEnabled(settingsSvc.getValueForKey(SettingsServiceBean.Key.UploadMethods))) {
return error(Response.Status.METHOD_NOT_ALLOWED, SettingsServiceBean.Key.UploadMethods + " does not contain " + SystemConfig.FileUploadMethods.RSYNC + ".");
}
Dataset dataset = null;
try {
dataset = findDatasetOrDie(id);
ScriptRequestResponse scriptRequestResponse = execCommand(new RequestRsyncScriptCommand(createDataverseRequest(findUserOrDie()), dataset));
return ok(scriptRequestResponse.getScript(), MediaType.valueOf(MediaType.TEXT_PLAIN));
} catch (WrappedResponse wr) {
return wr.getResponse();
} catch (EJBException ex) {
return error(Response.Status.INTERNAL_SERVER_ERROR, "Something went wrong attempting to download rsync script: " + EjbUtil.ejbExceptionToString(ex));
}
}
Aggregations