use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class ManagePermissionsPage method revokeRole.
// internal method used by removeRoleAssignment and saveConfiguration
private void revokeRole(RoleAssignment ra) {
try {
commandEngine.submit(new RevokeRoleCommand(ra, dvRequestService.getDataverseRequest()));
JsfHelper.addSuccessMessage(ra.getRole().getName() + " role for " + roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier()).getDisplayInfo().getTitle() + " was removed.");
RoleAssignee assignee = roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier());
notifyRoleChange(assignee, UserNotification.Type.REVOKEROLE);
} catch (PermissionException ex) {
JH.addMessage(FacesMessage.SEVERITY_ERROR, "The role assignment was not able to be removed.", "Permissions " + ex.getRequiredPermissions().toString() + " missing.");
} catch (CommandException ex) {
JH.addMessage(FacesMessage.SEVERITY_FATAL, "The role assignment could not be removed.");
logger.log(Level.SEVERE, "Error removing role assignment: " + ex.getMessage(), ex);
}
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class ManageTemplatesPage method saveDataverse.
private void saveDataverse(String successMessage) {
if (successMessage.isEmpty()) {
successMessage = "Template data updated";
}
try {
engineService.submit(new UpdateDataverseCommand(getDataverse(), null, null, dvRequestService.getDataverseRequest(), null));
// JH.addMessage(FacesMessage.SEVERITY_INFO, successMessage);
JsfHelper.addFlashMessage(successMessage);
} catch (CommandException ex) {
String failMessage = "Template update failed";
if (successMessage.equals("The template has been deleted")) {
failMessage = "The dataset template cannot be deleted.";
}
if (successMessage.equals("The template has been selected as the default template for this dataverse")) {
failMessage = "The dataset template cannot be made default.";
}
JH.addMessage(FacesMessage.SEVERITY_FATAL, failMessage);
}
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class ManageTemplatesPage method cloneTemplate.
public String cloneTemplate(Template templateIn) {
Template newOne = templateIn.cloneNewTemplate(templateIn);
String name = "Copy of " + templateIn.getName();
newOne.setName(name);
newOne.setUsageCount(new Long(0));
newOne.setCreateTime(new Timestamp(new Date().getTime()));
dataverse.getTemplates().add(newOne);
templates.add(newOne);
Template created;
try {
created = engineService.submit(new CreateTemplateCommand(newOne, dvRequestService.getDataverseRequest(), dataverse));
saveDataverse("");
String msg = "The template has been copied";
JsfHelper.addFlashMessage(msg);
return "/template.xhtml?id=" + created.getId() + "&ownerId=" + dataverse.getId() + "&editMode=METADATA&faces-redirect=true";
} catch (CommandException ex) {
JH.addMessage(FacesMessage.SEVERITY_FATAL, "Template could not be copied. ");
}
return "";
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class ManageGroupsPage method createExplicitGroup.
public void createExplicitGroup(ActionEvent ae) {
ExplicitGroup eg = explicitGroupService.getProvider().makeGroup();
eg.setDisplayName(getExplicitGroupName());
eg.setGroupAliasInOwner(getExplicitGroupIdentifier());
eg.setDescription(getNewExplicitGroupDescription());
if (getNewExplicitGroupRoleAssignees() != null) {
try {
for (RoleAssignee ra : getNewExplicitGroupRoleAssignees()) {
eg.add(ra);
}
} catch (GroupException ge) {
JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group Creation failed.", ge.getMessage());
return;
}
}
try {
eg = engineService.submit(new CreateExplicitGroupCommand(dvRequestService.getDataverseRequest(), this.dataverse, eg));
explicitGroups.add(eg);
JsfHelper.addSuccessMessage("Succesfully created group " + eg.getDisplayName() + ". Refresh to update your page.");
} catch (CreateExplicitGroupCommand.GroupAliasExistsException gaee) {
explicitGroupIdentifierField.setValid(false);
FacesContext.getCurrentInstance().addMessage(explicitGroupIdentifierField.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, gaee.getMessage(), null));
} catch (CommandException ex) {
logger.log(Level.WARNING, "Group creation failed", ex);
JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group Creation failed.", ex.getMessage());
} catch (Exception ex) {
JH.addMessage(FacesMessage.SEVERITY_FATAL, "The role was not able to be saved.");
logger.log(Level.SEVERE, "Error saving role: " + ex.getMessage(), ex);
}
showAssignmentMessages();
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class GuestbookPage method save.
public String save() {
boolean create = false;
if (!(guestbook.getCustomQuestions() == null)) {
for (CustomQuestion cq : guestbook.getCustomQuestions()) {
if (cq.getQuestionType().equals("text")) {
cq.setCustomQuestionValues(null);
}
}
Iterator<CustomQuestion> cqIt = guestbook.getCustomQuestions().iterator();
while (cqIt.hasNext()) {
CustomQuestion cq = cqIt.next();
if (StringUtils.isBlank(cq.getQuestionString())) {
cqIt.remove();
}
}
for (CustomQuestion cq : guestbook.getCustomQuestions()) {
if (cq != null && cq.getQuestionType().equals("options")) {
Iterator<CustomQuestionValue> cqvIt = cq.getCustomQuestionValues().iterator();
while (cqvIt.hasNext()) {
CustomQuestionValue cqv = cqvIt.next();
if (StringUtils.isBlank(cqv.getValueString())) {
cqvIt.remove();
}
}
}
}
for (CustomQuestion cq : guestbook.getCustomQuestions()) {
if (cq != null && cq.getQuestionType().equals("options")) {
if (cq.getCustomQuestionValues() == null || cq.getCustomQuestionValues().isEmpty()) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Guestbook Save Failed", " - An Option question requires multiple options. Please complete before saving."));
return null;
}
if (cq.getCustomQuestionValues().size() == 1) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Guestbook Save Failed", " - An Option question requires multiple options. Please complete before saving."));
return null;
}
}
}
int i = 0;
for (CustomQuestion cq : guestbook.getCustomQuestions()) {
int j = 0;
cq.setDisplayOrder(i);
if (cq.getCustomQuestionValues() != null && !cq.getCustomQuestionValues().isEmpty()) {
for (CustomQuestionValue cqv : cq.getCustomQuestionValues()) {
cqv.setDisplayOrder(j);
j++;
}
}
i++;
}
}
Command<Dataverse> cmd;
try {
if (editMode == EditMode.CREATE || editMode == EditMode.CLONE) {
guestbook.setCreateTime(new Timestamp(new Date().getTime()));
guestbook.setUsageCount(new Long(0));
guestbook.setEnabled(true);
dataverse.getGuestbooks().add(guestbook);
cmd = new UpdateDataverseCommand(dataverse, null, null, dvRequestService.getDataverseRequest(), null);
commandEngine.submit(cmd);
create = true;
} else {
cmd = new UpdateDataverseGuestbookCommand(dataverse, guestbook, 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_FATAL, "Guestbook Save Failed", " - " + error.toString()));
logger.info("Guestbook Page EJB Exception. Dataverse: " + dataverse.getName());
logger.info(error.toString());
return null;
} catch (CommandException ex) {
logger.info("Guestbook Page Command Exception. Dataverse: " + dataverse.getName());
logger.info(ex.toString());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "Guestbook Save Failed", " - " + ex.toString()));
// logger.severe(ex.getMessage());
}
editMode = null;
String msg = (create) ? "The guestbook has been created." : "The guestbook has been edited and saved.";
JsfHelper.addFlashMessage(msg);
return "/manage-guestbooks.xhtml?dataverseId=" + dataverse.getId() + "&faces-redirect=true";
}
Aggregations