Search in sources :

Example 1 with GroupException

use of edu.harvard.iq.dataverse.authorization.groups.GroupException in project dataverse by IQSS.

the class ManageGroupsPage method saveExplicitGroup.

public void saveExplicitGroup(ActionEvent ae) {
    ExplicitGroup eg = selectedGroup;
    if (getSelectedGroupAddRoleAssignees() != null) {
        try {
            for (RoleAssignee ra : getSelectedGroupAddRoleAssignees()) {
                eg.add(ra);
            }
        } catch (GroupException ge) {
            JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group edit failed.", ge.getMessage());
            return;
        }
    }
    try {
        eg = engineService.submit(new UpdateExplicitGroupCommand(dvRequestService.getDataverseRequest(), eg));
        JsfHelper.addSuccessMessage("Succesfully saved group " + eg.getDisplayName());
    } catch (CommandException ex) {
        JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group Save 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 : UpdateExplicitGroupCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateExplicitGroupCommand) GroupException(edu.harvard.iq.dataverse.authorization.groups.GroupException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) 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 2 with GroupException

use of edu.harvard.iq.dataverse.authorization.groups.GroupException 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 3 with GroupException

use of edu.harvard.iq.dataverse.authorization.groups.GroupException in project dataverse by IQSS.

the class AddRoleAssigneesToExplicitGroupCommand method execute.

@Override
public ExplicitGroup execute(CommandContext ctxt) throws CommandException {
    List<String> nonexistentRAs = new LinkedList<>();
    for (String rai : roleAssigneeIdentifiers) {
        RoleAssignee ra = null;
        try {
            ra = ctxt.roleAssignees().getRoleAssignee(rai);
        } catch (EJBException iae) {
            if (iae.getCausedByException() instanceof IllegalArgumentException) {
                throw new IllegalCommandException("Bad role assignee name:" + rai, this);
            }
        }
        if (ra == null) {
            nonexistentRAs.add(rai);
        } else {
            try {
                explicitGroup.add(ra);
            } catch (GroupException ex) {
                Logger.getLogger(AddRoleAssigneesToExplicitGroupCommand.class.getName()).log(Level.WARNING, "Error adding role assignee " + rai + " to group" + " " + explicitGroup.getIdentifier(), ex);
                throw new IllegalCommandException("Error adding " + rai + " to group " + explicitGroup.getIdentifier() + ": " + ex.getMessage(), this);
            }
        }
    }
    if (nonexistentRAs.isEmpty()) {
        return ctxt.explicitGroups().persist(explicitGroup);
    } else {
        StringBuilder sb = new StringBuilder();
        for (String s : nonexistentRAs) {
            sb.append(s).append(", ");
        }
        sb.setLength(sb.length() - 2);
        throw new IllegalCommandException("The following role assignees were not found: " + sb.toString(), this);
    }
}
Also used : IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) GroupException(edu.harvard.iq.dataverse.authorization.groups.GroupException) EJBException(javax.ejb.EJBException) LinkedList(java.util.LinkedList) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Aggregations

RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)3 GroupException (edu.harvard.iq.dataverse.authorization.groups.GroupException)3 ExplicitGroup (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)2 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)2 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)1 CreateExplicitGroupCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateExplicitGroupCommand)1 UpdateExplicitGroupCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateExplicitGroupCommand)1 LinkedList (java.util.LinkedList)1 EJBException (javax.ejb.EJBException)1 FacesMessage (javax.faces.application.FacesMessage)1