Example usage for javax.ejb EJBException toString

List of usage examples for javax.ejb EJBException toString

Introduction

In this page you can find the example usage for javax.ejb EJBException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:edu.harvard.iq.dataverse.GuestbookPage.java

public String save() {
    boolean create = false;
    if (!(guestbook.getCustomQuestions() == null)) {
        for (CustomQuestion cq : guestbook.getCustomQuestions()) {
            if (cq.getQuestionType().equals("text")) {
                cq.setCustomQuestionValues(null);
            }//from ww  w.  ja  v  a 2s .co  m
        }

        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";
}