Search in sources :

Example 1 with TraceBack

use of com.axelor.exception.db.TraceBack in project axelor-open-suite by axelor.

the class TraceBackService method _create.

/**
 * Créer un log des exceptions en tant qu'anomalie.
 *
 * @param e L'exception générée.
 * @param categorySelect <code>0 = Champ manquant</code> <code>1 = Clef non unique</code> <code>
 *     2 = Aucune valeur retournée</code> <code>3 = Problème de configuration</code>
 */
private static TraceBack _create(Throwable e, String origin, int typeSelect, int categorySelect, long batchId) {
    StringWriter sw = new StringWriter();
    e.printStackTrace(new PrintWriter(sw));
    TraceBack traceBack = new TraceBack();
    traceBack.setException(e.toString());
    traceBack.setDate(ZonedDateTime.now());
    traceBack.setError(e.getStackTrace() != null && e.getStackTrace().length > 0 ? e.getStackTrace()[0].toString() : e.getMessage());
    traceBack.setOrigin(origin);
    traceBack.setTypeSelect(typeSelect);
    traceBack.setCategorySelect(categorySelect);
    traceBack.setBatchId(batchId);
    if (AuthUtils.getSubject() != null) {
        traceBack.setInternalUser(AuthUtils.getUser());
    }
    if (e.getCause() != null) {
        traceBack.setCause(e.getCause().toString());
    }
    if (e.getMessage() != null) {
        traceBack.setMessage(e.getMessage());
    }
    traceBack.setTrace(sw.toString());
    Beans.get(TraceBackRepository.class).persist(traceBack);
    return traceBack;
}
Also used : StringWriter(java.io.StringWriter) TraceBack(com.axelor.exception.db.TraceBack) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) PrintWriter(java.io.PrintWriter)

Example 2 with TraceBack

use of com.axelor.exception.db.TraceBack in project axelor-open-suite by axelor.

the class TraceBackService method _create.

private static TraceBack _create(AxelorException e, String origin, long batchId) {
    TraceBack traceBack = _create(e, origin, TYPE_FUNCTIONAL, e.getCategory(), batchId);
    if (e.getRefClass() != null) {
        traceBack.setRef(e.getRefClass().getName());
        traceBack.setRefId(e.getRefId());
    }
    return traceBack;
}
Also used : TraceBack(com.axelor.exception.db.TraceBack)

Example 3 with TraceBack

use of com.axelor.exception.db.TraceBack in project axelor-open-suite by axelor.

the class TraceBackController method showReference.

/**
 * Show reference view.
 *
 * @param request
 * @param response
 */
public void showReference(ActionRequest request, ActionResponse response) {
    TraceBack traceBack = request.getContext().asType(TraceBack.class);
    if (Strings.isNullOrEmpty(traceBack.getRef())) {
        return;
    }
    Class<?> modelClass = JPA.model(traceBack.getRef());
    final Inflector inflector = Inflector.getInstance();
    String viewName = inflector.dasherize(modelClass.getSimpleName());
    LOG.debug("Showing anomaly reference ::: {}", viewName);
    ActionViewBuilder actionViewBuilder = ActionView.define(I18n.get("Reference"));
    actionViewBuilder.model(traceBack.getRef());
    if (traceBack.getRefId() != null) {
        actionViewBuilder.context("_showRecord", traceBack.getRefId());
    } else {
        actionViewBuilder.add("grid", String.format("%s-grid", viewName));
    }
    actionViewBuilder.add("form", String.format("%s-form", viewName));
    response.setView(actionViewBuilder.map());
}
Also used : Inflector(com.axelor.common.Inflector) TraceBack(com.axelor.exception.db.TraceBack) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Aggregations

TraceBack (com.axelor.exception.db.TraceBack)3 Inflector (com.axelor.common.Inflector)1 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)1 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1