Search in sources :

Example 6 with ReportField

use of org.acra.ReportField in project acra by ACRA.

the class HttpSender method remap.

@NonNull
private Map<String, String> remap(@NonNull Map<ReportField, Element> report) {
    Set<ReportField> fields = config.getReportFields();
    if (fields.isEmpty()) {
        fields = new ImmutableSet<ReportField>(ACRAConstants.DEFAULT_REPORT_FIELDS);
    }
    final Map<String, String> finalReport = new HashMap<String, String>(report.size());
    for (ReportField field : fields) {
        Element element = report.get(field);
        String value = element != null ? TextUtils.join("\n", element.flatten()) : null;
        if (mMapping == null || mMapping.get(field) == null) {
            finalReport.put(field.toString(), value);
        } else {
            finalReport.put(mMapping.get(field), value);
        }
    }
    return finalReport;
}
Also used : ReportField(org.acra.ReportField) HashMap(java.util.HashMap) Element(org.acra.model.Element) NonNull(android.support.annotation.NonNull)

Example 7 with ReportField

use of org.acra.ReportField in project acra by ACRA.

the class JsonUtils method toCrashReportData.

public static CrashReportData toCrashReportData(JSONObject json) {
    CrashReportData data = new CrashReportData();
    for (Iterator<String> iterator = json.keys(); iterator.hasNext(); ) {
        String key = iterator.next();
        try {
            ReportField field = ReportField.valueOf(key);
            Object value = json.get(key);
            if (value instanceof JSONObject) {
                data.put(field, new ComplexElement((JSONObject) value));
            } else if (value instanceof Number) {
                data.putNumber(field, (Number) value);
            } else if (value instanceof Boolean) {
                data.putBoolean(field, (Boolean) value);
            } else {
                data.putString(field, value.toString());
            }
        } catch (IllegalArgumentException e) {
            Log.w(LOG_TAG, "Unknown report key " + key, e);
        } catch (JSONException e) {
            Log.w(LOG_TAG, "Unable to read report field " + key, e);
        }
    }
    return data;
}
Also used : CrashReportData(org.acra.collector.CrashReportData) ReportField(org.acra.ReportField) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ComplexElement(org.acra.model.ComplexElement)

Aggregations

ReportField (org.acra.ReportField)7 Element (org.acra.model.Element)4 NonNull (android.support.annotation.NonNull)3 ComplexElement (org.acra.model.ComplexElement)3 HashMap (java.util.HashMap)2 CrashReportData (org.acra.collector.CrashReportData)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Intent (android.content.Intent)1 BufferedReader (java.io.BufferedReader)1 Map (java.util.Map)1 BooleanElement (org.acra.model.BooleanElement)1 NumberElement (org.acra.model.NumberElement)1 StringElement (org.acra.model.StringElement)1