Subversion Repositories SmartDukaan

Rev

Rev 3184 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.datalogger.event;

import in.shop2020.datalogger.EventType;

import org.json.JSONException;
import org.json.JSONObject;

public class NewSession extends Event{
    
    private String source;
    private String firstSource;

    public NewSession(String[] eventFileds) {
        super(eventFileds);
        source = eventFileds[5].trim();
        firstSource = "";
        if (eventFileds.length > 5) {
            firstSource = eventFileds[6].trim();
        }
    }
    
    public NewSession(EventType eType, String sessionId, long userId, String email, String[] logData) {
        super(eType, sessionId, userId, email);
        source = logData[0].trim();
        firstSource = "";
        if (logData.length > 1) {
            firstSource = logData[1].trim();
        }
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(eventType.name() + ", ");
        sb.append("userEmail : " + userEmail);
        sb.append(" source : " + source);
        sb.append(" first source : " + firstSource);
        sb.append(" time : " + time);
        sb.append(" session : " + sessionId);
        
        return sb.toString();
    }
    
    @Override
    public JSONObject getLogDataInJson() {
        JSONObject logDataInJson = new JSONObject();
        try {
            if (source.length() > 500) {
                source = source.substring(0, 500);
            }
            logDataInJson.put("source", source);
            if (firstSource.length() > 500) {
                firstSource = firstSource.substring(0, 500);
            }
            logDataInJson.put("firstSource", firstSource);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return logDataInJson;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }
}