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

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

Introduction

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

Prototype

public static String getStackTrace(final Throwable throwable) 

Source Link

Document

Gets the stack trace from a Throwable as a String.

The result of this method vary by JDK version as this method uses Throwable#printStackTrace(java.io.PrintWriter) .

Usage

From source file:ke.co.tawi.babblesms.server.persistence.utils.ContactsResetUtil.java

/**
 * //  ww  w.j  av  a2  s  . c o m
 */
public void resetPhoneContacts() {
    RandomDataGenerator randomGenerator = new RandomDataGenerator();

    // get all contact uuids for this account
    List<String> uuids = new LinkedList<>();

    List<Contact> contactsList = contactDAO.getContacts(account);

    for (Contact contact : contactsList) {
        uuids.add(contact.getUuid());
    }

    // Get all the phone objects of this account
    List<Phone> phoneList = new LinkedList<>();

    List<Phone> ctPhoneList;
    for (Contact contact : contactsList) {
        // get a list of all phone object associated with a contact
        ctPhoneList = phoneDAO.getPhones(contact);
        phoneList.addAll(ctPhoneList);
    }

    // get all phone numbers specifically
    List<String> phoneNumbers = new LinkedList<>();
    for (Phone phone : phoneList) {
        phoneNumbers.add(phone.getPhonenumber());
    }

    // generate new phone numbers and add to the list
    String phonenumber;
    for (int j = 0; j < 50; j++) {
        phonenumber = "254" + Integer.toString(randomGenerator.nextInt(700000000, 729000000));
        phoneNumbers.add(phonenumber);
    }

    // Update the IncomingLog with the new phone numbers      
    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement pstmt = conn.prepareStatement(
                    "UPDATE incominglog SET origin=? " + "WHERE recipientuuid=? AND uuid=?");) {

        int index;
        for (String uuid : uuids) {
            index = randomGenerator.nextInt(0, phoneNumbers.size() - 1);

            pstmt.setString(1, phoneNumbers.get(index));
            pstmt.setString(2, account.getUuid());
            pstmt.setString(3, uuid);
            pstmt.executeUpdate();
        }

    } catch (SQLException e) {
        logger.error("SQLException when updating IncomingLog phonenumbers");
        logger.error(ExceptionUtils.getStackTrace(e));
    }
}

From source file:com.aurel.track.persist.TNavigatorColumnPeer.java

/**
 * Saves a navigator field in layout//from   w w  w  .j a v  a 2  s.com
 * @param navigatorLayoutBean
 * @return
 */
@Override
public Integer save(TNavigatorColumnBean navigatorFieldsBean) {
    try {
        TNavigatorColumn navigatorColumn = TNavigatorColumn.createTNavigatorColumn(navigatorFieldsBean);
        navigatorColumn.save();
        Integer objectID = navigatorColumn.getObjectID();
        navigatorFieldsBean.setObjectID(objectID);
        return objectID;
    } catch (Exception e) {
        LOGGER.error("Saving of a navigator field failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    }
}

From source file:com.aurel.track.admin.server.dbbackup.DatabaseBackupBL.java

public static void zipDatabase(String backupName, boolean includeAttachments, PropertiesConfiguration tcfg)
        throws DatabaseBackupBLException {
    String driver = tcfg.getString("torque.dsfactory.track.connection.driver");
    if (driver != null) {
        driver = driver.trim();//from  w  ww .ja  v  a2  s .com
    }
    String url = tcfg.getString("torque.dsfactory.track.connection.url");
    if (url != null) {
        url = url.trim();
    }
    String user = tcfg.getString("torque.dsfactory.track.connection.user");
    if (user != null) {
        user = user.trim();
    }
    String password = tcfg.getString("torque.dsfactory.track.connection.password");
    String backupRootDir = ApplicationBean.getInstance().getSiteBean().getBackupDir();
    String backupDirTMP = backupRootDir + File.separator + DB_BACKUP_TMP_DIR;

    File tmpDir = new File(backupDirTMP);
    FileUtil.deltree(tmpDir);
    tmpDir.mkdirs();

    DatabaseInfo databaseInfo = new DatabaseInfo(driver, url, user, password);

    try {
        DataReader.writeDataToSql(databaseInfo, tmpDir.getAbsolutePath());
    } catch (DDLException e) {
        e.printStackTrace();
    }
    String fileNameData = tmpDir.getAbsolutePath() + File.separator + DataReader.FILE_NAME_DATA;
    long size = 0;
    try {
        File file = new File(fileNameData);
        size = file.length();
    } catch (Exception ex) {
        LOGGER.error(ExceptionUtils.getStackTrace(ex), ex);
    }
    if (size <= 1024) {
        LOGGER.error("Can't write database data to file. The file size to small! FileName:" + fileNameData
                + ",size=" + size + " bytes.");
        DatabaseBackupBLException ex = new DatabaseBackupBLException(
                "Can't write database data to file(File size to small:\"" + fileNameData + "\")");
        ex.setLocalizedKey("admin.server.databaseBackup.err.cantWriteDatabaseDataToFile");
        ex.setLocalizedParams(new Object[] { fileNameData });
        throw ex;
    }

    exportSchema(tmpDir);

    zipPart2(includeAttachments, backupName, tmpDir);

}

From source file:com.aurel.track.lucene.index.associatedFields.BudgetPlanIndexer.java

/**
 * Adds an attachment to the attachment index
 * Used by attaching a new file to the workItem 
 * @param attachFile/*from  w  w  w.  j a  v  a 2 s .c o m*/
 */
@Override
public void addToIndex(Object object, boolean add) {
    if (!LuceneUtil.isUseLucene()) {
        return;
    }
    if (!ClusterBL.indexInstantly()) {
        LOGGER.debug("Index instantly is false");
        return;
    }
    IndexWriter indexWriter = LuceneIndexer.getIndexWriter(getIndexWriterID());
    if (indexWriter == null) {
        LOGGER.error("IndexWriter null by adding a budget/plan");
        return;
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Save a new " + add + " " + getLuceneFieldName());
    }
    TBudgetBean budgetBean = (TBudgetBean) object;
    if (!add) {
        Integer objectID = budgetBean.getObjectID();
        if (objectID != null) {
            Term keyTerm = new Term(getObjectIDFieldName(), objectID.toString());
            try {
                indexWriter.deleteDocuments(keyTerm);
                indexWriter.commit();
            } catch (IOException e) {
                LOGGER.error("Removing the entity " + objectID + " failed with " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
    try {
        Document doc = createDocument(budgetBean);
        if (doc != null) {
            indexWriter.addDocument(doc);
        }
    } catch (IOException e) {
        LOGGER.error("Adding a budget/plan to the index failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    try {
        indexWriter.commit();
    } catch (IOException e) {
        LOGGER.error("Flushing the budget/plan failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
}

From source file:com.aurel.track.lucene.index.listFields.NotLocalizedListIndexer.java

/** 
 * Creates a non-localized lookup document.
 * @param labelBean// w  w w  . j  av a2s  . c  o  m
 * @param type
 * @return
 */
@Override
protected Document createDocument(ILabelBean labelBean, int type) {
    String id = null;
    try {
        id = labelBean.getObjectID().toString();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Creating the not localized list option document by id " + id + " label "
                    + labelBean.getLabel() + " type " + String.valueOf(type));
        }
        Document document = new Document();
        document.add(new StringField(LuceneUtil.LIST_INDEX_FIELDS_NOT_LOCALIZED.COMBINEDKEY,
                LuceneUtil.getCombinedKeyValue(id, String.valueOf(type)), Field.Store.YES));
        document.add(new StringField(LuceneUtil.LIST_INDEX_FIELDS_NOT_LOCALIZED.VALUE, id, Field.Store.YES));
        document.add(new TextField(LuceneUtil.LIST_INDEX_FIELDS_NOT_LOCALIZED.LABEL, labelBean.getLabel(),
                Field.Store.NO));
        document.add(new StringField(LuceneUtil.LIST_INDEX_FIELDS_NOT_LOCALIZED.TYPE, String.valueOf(type),
                Field.Store.YES));
        return document;
    } catch (Exception e) {
        LOGGER.error("Creating the document for non-localized list option " + " with label "
                + labelBean.getLabel() + " id " + id + " type " + type + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    }
}

From source file:com.aurel.track.item.operation.ItemOperationSelect.java

@Override
public List<MenuItem> getChildren(TPersonBean personBean, Locale locale, Integer nodeID) {
    List<MenuItem> menuItems = new ArrayList<MenuItem>();
    List<ILabelBean> currentOptions = getOptionsInternal(personBean, locale, nodeID);
    for (int i = 0; i < currentOptions.size(); i++) {
        ILabelBean labelBean = currentOptions.get(i);
        MenuItem mit = new MenuItem();
        mit.setType(ItemNavigatorFilterBL.NODE_TYPE_PREFIX.ITEM_OPERATION
                + ItemNavigatorFilterBL.NODE_TYPE_SEPARATOR + pluginID);
        mit.setObjectID(labelBean.getObjectID());
        mit.setName(labelBean.getLabel());
        mit.setAllowDrop(getAllowDrop(labelBean));
        mit.setUseFilter(useFilter);//www .  j av  a  2 s.com
        mit.setLazyChildren(tree);
        mit.setLevel(findLevel(nodeID));
        mit.setId(pluginID + ".item_" + labelBean.getObjectID());
        String iconName = null;
        try {
            iconName = getSymbol(labelBean);
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
        }
        if (iconName != null) {
            //mit.setIcon(IconPathHelper.getListOptionIconPathForURL(iconName,listID, contextPath));            
            mit.setIcon("itemNavigator!serveIconStream.action?nodeType=" + pluginID + "&nodeObjectID="
                    + labelBean.getObjectID() + "&time=" + new Date().getTime());
        }
        String iconCls = null;
        try {
            iconCls = getIconCls(labelBean);
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
        }
        if (iconCls != null) {
            //mit.setIcon(IconPathHelper.getListOptionIconPathForURL(iconName,listID, contextPath));
            mit.setIconCls(iconCls);
        }
        menuItems.add(mit);
    }
    return menuItems;
}

From source file:namedatabasescraper.NameDatabaseScraper.java

public static void reportException(Exception e) {
    logger.log(Level.SEVERE, e.getMessage());
    logger.log(Level.SEVERE, ExceptionUtils.getStackTrace(e));
    NameDatabaseScraper.application.window.reportException(e.getMessage());
}

From source file:com.aurel.track.dbase.ReadyTesterServlet.java

public String execute(PrintWriter out, Enumeration<Locale> locales) {
    StringBuilder sb = new StringBuilder();
    ResourceBundle rb = ResourceBundleManager.getLoaderResourceBundle(locales);
    sb.append("{");
    JSONUtility.appendBooleanValue(sb, "success", true);
    sb.append("data:{");
    Boolean ready = (Boolean) getServletContext().getAttribute(ApplicationStarter.READY);
    Integer percentComplete = (Integer) getServletContext().getAttribute(ApplicationStarter.PERCENT_COMPLETE);
    String progressText = (String) getServletContext().getAttribute(ApplicationStarter.PROGRESS_TEXT);
    if (progressText == null) {
        try {//from  w  ww .  j  a  va2s.c o m
            progressText = rb.getString("progressText"); // "Progress "+"...";
        } catch (Exception ex) {
        }
    }
    if (percentComplete == null) {
        percentComplete = 1;
    }

    JSONUtility.appendIntegerValue(sb, "percentComplete", percentComplete);
    JSONUtility.appendStringValue(sb, "progressText", progressText);

    JSONUtility.appendStringValue(sb, "progress100", rb.getString("progress100"));
    JSONUtility.appendStringValue(sb, "progressPercent", rb.getString("progressPercent"));
    JSONUtility.appendStringValue(sb, "redirect", rb.getString("redirect"));
    JSONUtility.appendStringValue(sb, "initializing", rb.getString("initializing"));

    if (ready != null) {
        JSONUtility.appendBooleanValue(sb, "ready", ready, true);
    } else {
        JSONUtility.appendBooleanValue(sb, "ready", false, true);
    }
    sb.append("}}");
    try {
        out.println(sb);
    } catch (Exception e) {
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }

    return null;
}

From source file:ke.co.tawi.babblesms.server.persistence.geolocation.CountryDAO.java

/**
 *
 *//*from  w  w  w .j  av  a  2  s. c  o m*/
@Override
public List<Country> getAllCountries() {
    List<Country> list = null;

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;
    BeanProcessor b = new BeanProcessor();

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM Country;");
        rset = pstmt.executeQuery();

        list = b.toBeanList(rset, Country.class);

    } catch (SQLException e) {
        logger.error("SQL Exception when getting all networks");
        logger.error(ExceptionUtils.getStackTrace(e));

    }

    return list;
}

From source file:com.aurel.track.fieldType.runtime.matchers.run.SystemSelectMatcherRT.java

/**
 * Add a match expression to the criteria
 *//*  w  w w.jav  a2s  .  co m*/
@Override
public void addCriteria(Criteria crit) {
    String columnName = null;
    Integer[] ids = null;
    if (matchValue != null) {
        try {
            ids = (Integer[]) matchValue;
        } catch (Exception e) {
            LOGGER.warn("Converting the matcher value " + matchValue + " of type "
                    + matchValue.getClass().getName() + " to Integer failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
            return;
        }
    }
    switch (fieldID.intValue()) {
    case SystemFields.PROJECT:
        columnName = TWorkItemPeer.PROJECTKEY;
        CriteriaUtil.addActiveInactiveProjectCriteria(crit);
        break;
    case SystemFields.ISSUETYPE:
        columnName = TWorkItemPeer.CATEGORYKEY;
        break;
    case SystemFields.STATE:
        columnName = TWorkItemPeer.STATE;
        break;
    case SystemFields.MANAGER:
        columnName = TWorkItemPeer.OWNER;
        break;
    case SystemFields.RESPONSIBLE:
        columnName = TWorkItemPeer.RESPONSIBLE;
        if (ids != null && ids.length != 0) {
            if (matcherContext.isIncludeResponsiblesThroughGroup()) {
                Set<Integer> responsibleGroupIDs = GroupMemberBL.getGroupsIDsForPersons(ids);
                Set<Integer> responsiblesSet = new HashSet<Integer>();
                for (int i = 0; i < ids.length; i++) {
                    responsiblesSet.add(ids[i]);
                }
                if (responsibleGroupIDs != null) {
                    responsiblesSet.addAll(responsibleGroupIDs);
                }
                crit.addIn(columnName, responsiblesSet.toArray());
            } else {
                crit.addIn(columnName, ids);
            }
        } else {
            //from fieldExpressionSimpleList (hardcoded filter)
            addNullExpressionToCriteria(crit, columnName);
        }
        return;
    case SystemFields.RELEASE:
        if (matcherContext.getReleaseTypeSelector() == null) {
            if (ids != null && ids.length > 0) {
                crit.addIn(TWorkItemPeer.RELSCHEDULEDKEY, ids);
            }
            columnName = TWorkItemPeer.RELSCHEDULEDKEY;
        } else {
            switch (matcherContext.getReleaseTypeSelector().intValue()) {
            case FilterUpperTO.RELEASE_SELECTOR.NOTICED:
                if (ids != null && ids.length > 0) {
                    crit.addIn(TWorkItemPeer.RELNOTICEDKEY, ids);
                }
                columnName = TWorkItemPeer.RELNOTICEDKEY;
                break;
            case FilterUpperTO.RELEASE_SELECTOR.SCHEDULED:
                if (ids != null && ids.length > 0) {
                    crit.addIn(TWorkItemPeer.RELSCHEDULEDKEY, ids);
                }
                columnName = TWorkItemPeer.RELNOTICEDKEY;
                break;
            case FilterUpperTO.RELEASE_SELECTOR.NOTICED_OR_SCHEDULED:
                if (ids != null && ids.length > 0) {
                    Criterion relNoticed = crit.getNewCriterion(TWorkItemPeer.RELNOTICEDKEY, ids, Criteria.IN);
                    Criterion relScheduled = crit.getNewCriterion(TWorkItemPeer.RELSCHEDULEDKEY, ids,
                            Criteria.IN);
                    crit.add(relNoticed.or(relScheduled));
                }
                columnName = TWorkItemPeer.RELNOTICEDKEY;
                break;
            }
        }
        //if from fieldExpressionSimpleList (hardcoded filter)
        addNullExpressionToCriteria(crit, columnName);
        return;
    case SystemFields.PRIORITY:
        columnName = TWorkItemPeer.PRIORITYKEY;
        break;
    case SystemFields.SEVERITY:
        columnName = TWorkItemPeer.SEVERITYKEY;
        break;
    case SystemFields.ORIGINATOR:
        columnName = TWorkItemPeer.ORIGINATOR;
        break;
    case SystemFields.CHANGEDBY:
        columnName = TWorkItemPeer.CHANGEDBY;
        break;
    }
    if (columnName != null) {
        if (ids != null && ids.length > 0) {
            crit.addIn(columnName, ids);
        } else {
            //if from fieldExpressionSimpleList (hardcoded filter)
            addNullExpressionToCriteria(crit, columnName);
        }
    }
}