use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class TemplatePage method save.
public String save(String redirectPage) {
// SEK - removed dead code 1/6/2015
boolean create = false;
Command<Void> cmd;
Long createdId = new Long(0);
Template created;
try {
if (editMode == EditMode.CREATE) {
template.setCreateTime(new Timestamp(new Date().getTime()));
template.setUsageCount(new Long(0));
dataverse.getTemplates().add(template);
created = commandEngine.submit(new CreateTemplateCommand(template, dvRequestService.getDataverseRequest(), dataverse));
createdId = created.getId();
// cmd = new UpdateDataverseCommand(dataverse, null, null, dvRequestService.getDataverseRequest(), null);
create = true;
// commandEngine.submit(cmd);
} else {
cmd = new UpdateDataverseTemplateCommand(dataverse, template, dvRequestService.getDataverseRequest());
commandEngine.submit(cmd);
}
} catch (EJBException ex) {
StringBuilder error = new StringBuilder();
error.append(ex).append(" ");
error.append(ex.getMessage()).append(" ");
Throwable cause = ex;
while (cause.getCause() != null) {
cause = cause.getCause();
error.append(cause).append(" ");
error.append(cause.getMessage()).append(" ");
}
//
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Template Save Failed", " - " + error.toString()));
System.out.print("dataverse " + dataverse.getName());
System.out.print("Ejb exception");
System.out.print(error.toString());
JH.addMessage(FacesMessage.SEVERITY_FATAL, "Template Save Failed");
return null;
} catch (CommandException ex) {
System.out.print("command exception");
System.out.print(ex.toString());
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Template Save Failed", " - " + ex.toString()));
JH.addMessage(FacesMessage.SEVERITY_FATAL, "Template Save Failed");
return null;
// logger.severe(ex.getMessage());
}
editMode = null;
String msg = (create) ? "Template has been created." : "Template has been edited and saved.";
JsfHelper.addFlashMessage(msg);
String retString = "";
if (!redirectPage.isEmpty() && createdId.intValue() > 0) {
retString = "/template.xhtml?id=" + createdId + "&ownerId=" + dataverse.getId() + "&editMode=LICENSEADD&faces-redirect=true";
} else {
retString = "/manage-templates.xhtml?dataverseId=" + dataverse.getId() + "&faces-redirect=true";
}
return retString;
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class FileDownloadServiceBean method writeGuestbookResponseRecord.
public void writeGuestbookResponseRecord(GuestbookResponse guestbookResponse) {
try {
CreateGuestbookResponseCommand cmd = new CreateGuestbookResponseCommand(dvRequestService.getDataverseRequest(), guestbookResponse, guestbookResponse.getDataset());
commandEngine.submit(cmd);
} catch (CommandException e) {
// if an error occurs here then download won't happen no need for response recs...
}
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class FilePage method save.
public String save() {
// Validate
Set<ConstraintViolation> constraintViolations = this.fileMetadata.getDatasetVersion().validate();
if (!constraintViolations.isEmpty()) {
// JsfHelper.addFlashMessage(JH.localize("dataset.message.validationError"));
fileDeleteInProgress = false;
JH.addMessage(FacesMessage.SEVERITY_ERROR, JH.localize("dataset.message.validationError"));
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Validation Error", "See below for details."));
return "";
}
Command<Dataset> cmd;
try {
cmd = new UpdateDatasetCommand(editDataset, dvRequestService.getDataverseRequest(), filesToBeDeleted);
commandEngine.submit(cmd);
} catch (EJBException ex) {
StringBuilder error = new StringBuilder();
error.append(ex).append(" ");
error.append(ex.getMessage()).append(" ");
Throwable cause = ex;
while (cause.getCause() != null) {
cause = cause.getCause();
error.append(cause).append(" ");
error.append(cause.getMessage()).append(" ");
}
return null;
} catch (CommandException ex) {
fileDeleteInProgress = false;
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
return null;
}
if (fileDeleteInProgress) {
JsfHelper.addSuccessMessage(JH.localize("file.message.deleteSuccess"));
fileDeleteInProgress = false;
} else {
JsfHelper.addSuccessMessage(JH.localize("file.message.editSuccess"));
}
setVersion("DRAFT");
return "";
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class FileRecordWriter method updateDatasetVersion.
// utils
/**
* Update the dataset version using the command engine so permissions and constraints are enforced.
* Log errors to both the glassfish log and in the job context, as the exit status "failed".
*
* @param version dataset version
*/
private void updateDatasetVersion(DatasetVersion version) {
// update version using the command engine to enforce user permissions and constraints
if (dataset.getVersions().size() == 1 && version.getVersionState() == DatasetVersion.VersionState.DRAFT) {
try {
Command<DatasetVersion> cmd;
cmd = new UpdateDatasetVersionCommand(new DataverseRequest(user, (HttpServletRequest) null), version);
commandEngine.submit(cmd);
} catch (CommandException ex) {
String commandError = "CommandException updating DatasetVersion from batch job: " + ex.getMessage();
getJobLogger().log(Level.SEVERE, commandError);
jobContext.setExitStatus("FAILED");
}
} else {
String constraintError = "ConstraintException updating DatasetVersion form batch job: dataset must be a " + "single version in draft mode.";
getJobLogger().log(Level.SEVERE, constraintError);
jobContext.setExitStatus("FAILED");
}
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetRequiredPermissions.
@Test
public void testGetRequiredPermissions() {
CreatePrivateUrlCommand createPrivateUrlCommand = new CreatePrivateUrlCommand(null, null);
CommandException ex = new CommandException(null, createPrivateUrlCommand);
List<String> strings = PrivateUrlUtil.getRequiredPermissions(ex);
assertEquals(Arrays.asList("ManageDatasetPermissions"), strings);
}
Aggregations