Example usage for org.apache.commons.lang3.exception ExceptionUtils getRootCauseMessage

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getRootCauseMessage

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils getRootCauseMessage.

Prototype

public static String getRootCauseMessage(final Throwable th) 

Source Link

Document

Gets a short message summarising the root cause exception.

Usage

From source file:org.xwiki.wysiwyg.internal.plugin.alfresco.server.DefaultAlfrescoTokenManager.java

@Override
public void setTicket(String atiket) {
    final XWikiContext context = getXWikiContext();
    XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStore;
    String originalDatabase = context.getDatabase();
    context.setDatabase(context.getMainXWiki());
    final String usr = context.getUser();
    final AlfrescoTiket newTiket = new AlfrescoTiket(usr, atiket);
    try {//w  w  w .  ja  v a  2  s  .c o  m
        store.executeWrite(context, new XWikiHibernateBaseStore.HibernateCallback<Object>() {
            @Override
            public Object doInHibernate(Session session) throws HibernateException {
                AlfrescoTiket tiket = (AlfrescoTiket) session.createCriteria(AlfrescoTiket.class)
                        .add(Restrictions.eq(userfield, usr)).uniqueResult();
                if (tiket != null) {
                    session.delete(tiket);
                }
                session.save(newTiket);
                return null;
            }
        });
    } catch (XWikiException e) {
        this.logger.warn("Failed to save user-token to database. Reason: [{}]",
                ExceptionUtils.getRootCauseMessage(e));
    } finally {
        context.setDatabase(originalDatabase);
    }
}

From source file:org.xwiki.wysiwyg.internal.plugin.alfresco.server.DefaultAlfrescoTokenManager.java

/**
 * @return alfresco tiket/*from  ww w  . j a  v  a 2s. c om*/
 *
 */
@Override
public AlfrescoTiket getTicket() {

    XWikiContext context = getXWikiContext();
    XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStore;
    String originalDatabase = context.getDatabase();
    context.setDatabase(context.getMainXWiki());
    final String usr = context.getUser();
    try {
        AlfrescoTiket alfToken = store.failSafeExecuteRead(context,
                new XWikiHibernateBaseStore.HibernateCallback<AlfrescoTiket>() {
                    @Override
                    public AlfrescoTiket doInHibernate(Session session) throws HibernateException {
                        return (AlfrescoTiket) session.createCriteria(AlfrescoTiket.class)
                                .add(Restrictions.eq(userfield, usr)).uniqueResult();
                    }
                });
        return alfToken;
    } catch (Exception e) {
        this.logger.warn("Failed to get user-token to database. Reason: [{}]",
                ExceptionUtils.getRootCauseMessage(e));
    } finally {
        context.setDatabase(originalDatabase);
    }
    return null;
}

From source file:org.xwiki.wysiwyg.script.WysiwygEditorScriptService.java

/**
 * Builds the annotated XHTML needed to import the specified office attachment in the WYSIWYG editor.
 * //from  w w  w  .j  a  v  a2 s .  c  o m
 * @param attachmentReference the office attachment to import
 * @param parameters the import parameters; {@code filterStyles} controls whether styles are filtered when importing
 *            office text documents; {@code useOfficeViewer} controls whether the office viewer macro is used
 *            instead of converting the content of the office file to wiki syntax
 * @return the annotated XHTML needed to import the specified attachment into the content of the WYSIWYG editor
 */
public String importOfficeAttachment(AttachmentReference attachmentReference, Map<String, Object> parameters) {
    try {
        return this.officeAttachmentImporter.toHTML(attachmentReference, parameters);
    } catch (Exception e) {
        this.logger.warn("Failed to import office attachment [{}]. Root cause is: {}",
                this.entityReferenceSerializer.serialize(attachmentReference),
                ExceptionUtils.getRootCauseMessage(e));
        return null;
    }
}

From source file:richtercloud.document.scanner.gui.ScannerSelectionDialog.java

private void scannerDialogEditButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scannerDialogEditButtonActionPerformed
    assert this.scannerDialogTable.getSelectedRow() != -1;
    SaneDevice device = this.tableModel.getDevices().get(this.scannerDialogTable.getSelectedRow());
    ScannerEditDialog scannerEditDialog;
    try {/*ww w .jav  a 2s .c o m*/
        ScannerEditDialog.configureDefaultOptionValues(device, this.changedOptions, false);
        scannerEditDialog = new ScannerEditDialog(this, device, this.changedOptions, this.messageHandler);
        scannerEditDialog.setVisible(true);
    } catch (IOException | SaneException ex) {
        this.messageHandler.handle(new Message(
                String.format("Exception during scanner configuration", ExceptionUtils.getRootCauseMessage(ex)),
                JOptionPane.ERROR_MESSAGE, "Exception occured"));
    }
}

From source file:richtercloud.reflection.form.builder.components.AmountMoneyPanel.java

private void currencyManageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_currencyManageButtonActionPerformed
    AmountMoneyPanelManageDialog amountMoneyPanelManageDialog;
    try {//w ww .  ja  va  2 s .com
        amountMoneyPanelManageDialog = new AmountMoneyPanelManageDialog(amountMoneyCurrencyStorage,
                amountMoneyExchangeRateRetriever, messageHandler,
                (Frame) SwingUtilities.getWindowAncestor(this));
    } catch (AmountMoneyCurrencyStorageException ex) {
        this.messageHandler.handle(new Message(
                String.format("An exception occured during retrieval of currencies from the storage: %s",
                        ExceptionUtils.getRootCauseMessage(ex)),
                JOptionPane.ERROR_MESSAGE, "Exception occured"));
        return;
    }
    amountMoneyPanelManageDialog.pack();
    amountMoneyPanelManageDialog.setVisible(true);
    //handle manipulation result
    Currency selectedCurrency = (Currency) currencyComboBoxModel.getSelectedItem();
    //if currencyComboBoxModel is emptied item by item an item change event
    //is triggered for every removal which trigger conversion and thus
    //requires to fetch all exchange rates -> diff the model and the storage
    Set<Currency> storedCurrencies;
    try {
        storedCurrencies = amountMoneyCurrencyStorage.getCurrencies();
    } catch (AmountMoneyCurrencyStorageException ex) {
        throw new RuntimeException(ex);
    }
    for (Currency storedCurrency : storedCurrencies) {
        if (!comboBoxModelContains(currencyComboBoxModel, storedCurrency)) {
            currencyComboBoxModel.addElement(storedCurrency);
        }
    }
    for (int i = 0; i < currencyComboBoxModel.getSize(); i++) {
        Currency modelCurrency = currencyComboBoxModel.getElementAt(i);
        if (!storedCurrencies.contains(modelCurrency)) {
            currencyComboBoxModel.removeElement(modelCurrency);
        }
    }
    if (!storedCurrencies.contains(selectedCurrency)) {
        currencyComboBoxModel.setSelectedItem(currencyComboBoxModel.getElementAt(0));
    } else {
        currencyComboBoxModel.setSelectedItem(selectedCurrency);
    }
}

From source file:richtercloud.reflection.form.builder.components.AmountMoneyPanelManageDialog.java

private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
    AmountMoneyPanelEditDialog amountMoneyPanelEditDialog;
    try {//w  w w.  ja va2  s. c  om
        amountMoneyPanelEditDialog = new AmountMoneyPanelEditDialog(null, //currency (null indicates creation of a new currency)
                this.amountMoneyCurrencyStorage, this.amountMoneyExchangeRateRetriever, this.messageHandler,
                (Frame) SwingUtilities.getWindowAncestor(this) //parent
        );
    } catch (AmountMoneyCurrencyStorageException ex) {
        this.messageHandler.handle(new Message(
                String.format("An exception occured during retrieval of currencies from the storage: %s",
                        ExceptionUtils.getRootCauseMessage(ex)),
                JOptionPane.ERROR_MESSAGE, "Exception occured"));
        return;
    }
    amountMoneyPanelEditDialog.pack();
    amountMoneyPanelEditDialog.setVisible(true);
    Currency newCurrency = amountMoneyPanelEditDialog.getCurrency();
    try {
        this.amountMoneyCurrencyStorage.saveCurrency(newCurrency);
    } catch (AmountMoneyCurrencyStorageException ex) {
        this.messageHandler.handle(new Message(
                String.format("An exception occured during retrieval of currencies from the storage: %s",
                        ExceptionUtils.getRootCauseMessage(ex)),
                JOptionPane.ERROR_MESSAGE, "Exception occured"));
    }
    currencyListModel.add(0, newCurrency);
}

From source file:richtercloud.reflection.form.builder.components.AmountMoneyPanelManageDialog.java

private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
    Currency selectedCurrency = currencyList.getSelectedValue();
    if (selectedCurrency == null) {
        return;/*from  w  w w .j a  v a2  s .c o  m*/
    }
    try {
        //since AmountMoneyCurrencyStorage doesn't keep track of the order of
        //currencies, simply remove and add the old and new instance
        this.amountMoneyCurrencyStorage.removeCurrency(selectedCurrency);
    } catch (AmountMoneyCurrencyStorageException ex) {
        this.messageHandler.handle(new Message(
                String.format("An exception occured during retrieval of currencies from the storage: %s",
                        ExceptionUtils.getRootCauseMessage(ex)),
                JOptionPane.ERROR_MESSAGE, "Exception occured"));
    }
    currencyListModel.remove(currencyList.getSelectedIndex());
}

From source file:richtercloud.reflection.form.builder.components.AmountMoneyPanelManageDialog.java

private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
    Currency selectedCurrency = this.currencyList.getSelectedValue();
    AmountMoneyPanelEditDialog amountMoneyPanelEditDialog;
    try {/*from  w  w  w. j a v  a  2 s .  co  m*/
        amountMoneyPanelEditDialog = new AmountMoneyPanelEditDialog(selectedCurrency, //currency
                this.amountMoneyCurrencyStorage, this.amountMoneyExchangeRateRetriever, this.messageHandler,
                (Frame) SwingUtilities.getWindowAncestor(this) //parent
        );
    } catch (AmountMoneyCurrencyStorageException ex) {
        this.messageHandler.handle(new Message(
                String.format("An exception occured during retrieval of currencies from the storage: %s",
                        ExceptionUtils.getRootCauseMessage(ex)),
                JOptionPane.ERROR_MESSAGE, "Exception occured"));
        return;
    }
    amountMoneyPanelEditDialog.pack();
    amountMoneyPanelEditDialog.setVisible(true);
    Currency editedCurrency = amountMoneyPanelEditDialog.getCurrency();
    try {
        //since AmountMoneyCurrencyStorage doesn't keep track of the order of
        //currencies, simply remove and add the old and new instance
        this.amountMoneyCurrencyStorage.removeCurrency(selectedCurrency);
        this.amountMoneyCurrencyStorage.saveCurrency(editedCurrency);
    } catch (AmountMoneyCurrencyStorageException ex) {
        this.messageHandler.handle(new Message(
                String.format("An exception occured during retrieval of currencies from the storage: %s",
                        ExceptionUtils.getRootCauseMessage(ex)),
                JOptionPane.ERROR_MESSAGE, "Exception occured"));
    }
    int selectedCurrencyIndex = currencyListModel.indexOf(selectedCurrency);
    currencyListModel.remove(selectedCurrencyIndex);
    currencyListModel.add(selectedCurrencyIndex, editedCurrency);
}

From source file:richtercloud.reflection.form.builder.jpa.EntityReflectionFormPanel.java

protected void deleteButtonActionPerformed(ActionEvent evt) {
    Object instance;/*  w  ww. j  ava 2s . co m*/
    try {
        instance = this.retrieveInstance();
    } catch (IllegalArgumentException | IllegalAccessException ex) {
        String message = String.format(
                "The following exception occured during persisting entity of type '%s': %s",
                this.getEntityClass(), ExceptionUtils.getRootCauseMessage(ex));
        LOGGER.debug(message, ex);
        messageHandler.handle(new Message(message, JOptionPane.WARNING_MESSAGE, "Persisting failed"));
        return;
    }
    //check getEntityManager.contains is unnecessary because a instances should be managed
    try {
        getEntityManager().getTransaction().begin();
        getEntityManager().remove(instance);
        getEntityManager().getTransaction().commit();
        this.messageHandler.handle(new Message(
                String.format("<html>removed entity of type '%s' successfully</html>", this.getEntityClass()),
                JOptionPane.INFORMATION_MESSAGE, "Removal failed"));
    } catch (EntityExistsException ex) {
        getEntityManager().getTransaction().rollback();
        handlePersistenceException(ex);

    } catch (RollbackException ex) {
        //cannot call entityManager.getTransaction().rollback() here because transaction isn' active
        handlePersistenceException(ex);
    }
    for (EntityReflectionFormPanelUpdateListener updateListener : this.getUpdateListeners()) {
        updateListener.onUpdate(new ReflectionFormPanelUpdateEvent(
                ReflectionFormPanelUpdateEvent.INSTANCE_DELETED, null, instance));
    }
}

From source file:richtercloud.reflection.form.builder.jpa.EntityReflectionFormPanel.java

private void handlePersistenceException(Exception ex) {
    String message = String.format("the following exception occured during persisting entity of type '%s': %s",
            this.getEntityClass(), ExceptionUtils.getRootCauseMessage(ex) //since ExceptionUtils.getRootCause returns null if ex doesn't have a cause use ExceptionUtils.getRootCauseMessage (which always works)
    );/*from   w  w  w.ja v  a 2  s .  c o  m*/
    LOGGER.debug(message, ex);
    this.messageHandler.handle(new Message(message, JOptionPane.ERROR_MESSAGE, "Exception occured"));
}