use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.
the class PendingWorkflowInvocation method reCreateContext.
public WorkflowContext reCreateContext(RoleAssigneeServiceBean roleAssignees) {
DataverseRequest aRequest = new DataverseRequest((User) roleAssignees.getRoleAssignee(userId), IpAddress.valueOf(ipAddress));
final WorkflowContext workflowContext = new WorkflowContext(aRequest, dataset, nextVersionNumber, nextMinorVersionNumber, WorkflowContext.TriggerType.values()[typeOrdinal], doiProvider);
workflowContext.setInvocationId(invocationId);
return workflowContext;
}
use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.
the class CreateSavedSearchCommand method execute.
@Override
public SavedSearch execute(CommandContext ctxt) throws CommandException {
String query = savedSearchToCreate.getQuery();
if (query == null) {
/**
* @todo This probably shouldn't be the default. We are disallowing
* wildcard searches. Go fix the DataversePage and make sure the
* query is set.
*/
String wildcardSearch = "*";
savedSearchToCreate.setQuery(wildcardSearch);
}
SavedSearch persistedSavedSearch = ctxt.savedSearches().save(savedSearchToCreate);
if (persistedSavedSearch != null) {
try {
DataverseRequest dataverseRequest = new DataverseRequest(savedSearchToCreate.getCreator(), SavedSearchServiceBean.getHttpServletRequest());
JsonObjectBuilder result = ctxt.savedSearches().makeLinksForSingleSavedSearch(dataverseRequest, persistedSavedSearch, true);
logger.log(Level.INFO, "result from attempt to make links from saved search: {0}", result.build().toString());
} catch (SearchException ex) {
logger.info(ex.getLocalizedMessage());
}
return persistedSavedSearch;
} else {
return null;
}
}
use of edu.harvard.iq.dataverse.engine.command.DataverseRequest 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.engine.command.DataverseRequest in project dataverse by IQSS.
the class Files method restrictFileInDataset.
/**
* Restrict or Unrestrict an Existing File
* @author sarahferry
*
* @param fileToRestrictId
* @param restrictStr
* @return
*/
@PUT
@Path("{id}/restrict")
public Response restrictFileInDataset(@PathParam("id") Long fileToRestrictId, String restrictStr) {
// create request
DataverseRequest dataverseRequest = null;
// get the datafile
DataFile dataFile = fileService.find(fileToRestrictId);
if (dataFile == null) {
return error(BAD_REQUEST, "Could not find datafile with id " + fileToRestrictId);
}
boolean restrict = Boolean.valueOf(restrictStr);
try {
dataverseRequest = createDataverseRequest(findUserOrDie());
} catch (WrappedResponse wr) {
return error(BAD_REQUEST, "Couldn't find user to execute command: " + wr.getLocalizedMessage());
}
// try to restrict the datafile
try {
engineSvc.submit(new RestrictFileCommand(dataFile, dataverseRequest, restrict));
} catch (CommandException ex) {
return error(BAD_REQUEST, "Problem trying to update restriction status on " + dataFile.getDisplayName() + ": " + ex.getLocalizedMessage());
}
// update the dataset
try {
engineSvc.submit(new UpdateDatasetCommand(dataFile.getOwner(), dataverseRequest));
} catch (CommandException ex) {
return error(BAD_REQUEST, "Problem saving datafile " + dataFile.getDisplayName() + ": " + ex.getLocalizedMessage());
}
String text = restrict ? "restricted." : "unrestricted.";
return ok("File " + dataFile.getDisplayName() + " " + text);
}
use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.
the class Files method getMapLayerMetadatas.
// end: replaceFileInDataset
@DELETE
@Path("{id}/map")
public Response getMapLayerMetadatas(@PathParam("id") Long idSupplied) {
DataverseRequest dataverseRequest = null;
try {
dataverseRequest = createDataverseRequest(findUserOrDie());
} catch (WrappedResponse wr) {
return error(BAD_REQUEST, "Couldn't find user to execute command: " + wr.getLocalizedMessage());
}
DataFile dataFile = fileService.find(idSupplied);
try {
boolean deleted = engineSvc.submit(new DeleteMapLayerMetadataCommand(dataverseRequest, dataFile));
if (deleted) {
return ok("Map deleted from file id " + dataFile.getId());
} else {
return error(BAD_REQUEST, "Could not delete map from file id " + dataFile.getId());
}
} catch (CommandException ex) {
return error(BAD_REQUEST, "Problem trying to delete map from file id " + dataFile.getId() + ": " + ex.getLocalizedMessage());
}
}
Aggregations