package org.commcare.android.analytics;

import org.commcare.android.database.user.models.User;
import org.commcare.android.util.SessionUnavailableException;
import org.commcare.dalvik.application.CommCareApplication;

import java.io.Serializable;
import java.util.Date;

/**
 * @author Phillip Mates (pmates@dimagi.com)
 */
public class XPathErrorEntry implements Serializable {
    private final Date time;
    private final String expression;
    private final String username;
    private final String errorMessage;
    private final String session;

    protected XPathErrorEntry(String expression, String errorMessage) {
        this.expression = expression;
        this.errorMessage = errorMessage;

        this.time = new Date();
        this.username = getUsername();

        // TODO PLM
        this.session = "";
    }

    private static String getUsername() {
        User currentUser;
        try {
            currentUser = CommCareApplication._().getSession().getLoggedInUser();
        } catch (SessionUnavailableException e) {
            currentUser = null;
        }
        if (currentUser != null) {
            return currentUser.getUsername();
        } else {
            return "no user";
        }
    }

    @Override
    public String toString() {
        return time.toString() + " | " + username + " encountered " +
                errorMessage + " caused by " + expression +
                "\n" + "session: " + session;
    }
}

@@ -38,63 +38,8 @@
 s;%0A%0A
-import org.commcare.android.database.user.models.User;%0A
 impo
@@ -155,16 +155,53 @@
 ication;
+%0Aimport org.javarosa.core.model.User;
 %0A%0Aimport

Fix user import