Search in sources :

Example 61 with CommandException

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);
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) RevokeRoleCommand(edu.harvard.iq.dataverse.engine.command.impl.RevokeRoleCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 62 with CommandException

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);
    }
}
Also used : UpdateDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 63 with CommandException

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 "";
}
Also used : CreateTemplateCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateTemplateCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 64 with CommandException

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();
}
Also used : CreateExplicitGroupCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateExplicitGroupCommand) GroupException(edu.harvard.iq.dataverse.authorization.groups.GroupException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) FacesMessage(javax.faces.application.FacesMessage) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) GroupException(edu.harvard.iq.dataverse.authorization.groups.GroupException) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 65 with CommandException

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";
}
Also used : UpdateDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Timestamp(java.sql.Timestamp) Date(java.util.Date) UpdateDataverseGuestbookCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseGuestbookCommand) EJBException(javax.ejb.EJBException) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)86 Dataset (edu.harvard.iq.dataverse.Dataset)21 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)20 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)19 Test (org.junit.Test)16 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)15 EJBException (javax.ejb.EJBException)13 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)12 DataFile (edu.harvard.iq.dataverse.DataFile)11 Dataverse (edu.harvard.iq.dataverse.Dataverse)9 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)9 ConstraintViolation (javax.validation.ConstraintViolation)9 DatasetThumbnail (edu.harvard.iq.dataverse.dataset.DatasetThumbnail)8 IOException (java.io.IOException)8 Timestamp (java.sql.Timestamp)8 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 FacesMessage (javax.faces.application.FacesMessage)7 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)6 SwordError (org.swordapp.server.SwordError)6