Subversion Repositories SmartDukaan

Rev

Rev 3208 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3208 vikas 1
package in.shop2020.datalogger.event;
2
 
3
import in.shop2020.datalogger.EventType;
4
 
5
import java.util.ArrayList;
6
import java.util.List;
7
import java.util.StringTokenizer;
8
 
9
import org.json.JSONArray;
10
import org.json.JSONException;
11
import org.json.JSONObject;
12
 
13
 
14
public class ProceedToPay extends Event{
15
 
16
    private long cartId;
17
    private List<Long> itemIds;
18
 
19
    public ProceedToPay(String[] eventFileds) {
20
        super(eventFileds);
21
        cartId = Long.parseLong(eventFileds[5].trim());
22
        itemIds = new ArrayList<Long>();
3210 vikas 23
        if (eventFileds.length > 6) {
3208 vikas 24
            StringTokenizer tokenizer = new StringTokenizer(eventFileds[6].trim(), "_");
25
            while (tokenizer.hasMoreTokens()) {
26
                itemIds.add(Long.parseLong(tokenizer.nextToken().trim())); 
27
            }
28
        }
29
    }
30
 
31
    public ProceedToPay(EventType eType, String sessionId, long userId, String email, String[] logData) {
32
        super(eType, sessionId, userId, email);
33
        cartId = Long.parseLong(logData[0].trim());
34
        itemIds = new ArrayList<Long>();
35
        if (logData.length > 1) {
36
            StringTokenizer tokenizer = new StringTokenizer(logData[1].trim(), "_");
37
            while (tokenizer.hasMoreTokens()) {
38
                itemIds.add(Long.parseLong(tokenizer.nextToken().trim())); 
39
            }
40
        }
41
    }
42
 
43
    public String toString() {
44
        StringBuilder sb = new StringBuilder();
45
        sb.append(eventType.name() + ", ");
46
        sb.append("userEmail : " + userEmail);
47
        sb.append(" cartId : " + cartId);
48
        sb.append(" itemIds : " + itemIds);
49
        sb.append(" time : " + time);
50
        sb.append(" session : " + sessionId);
51
 
52
        return sb.toString();
53
    }
54
 
55
    @Override
56
    public JSONObject getLogDataInJson() {
57
        JSONObject logDataInJson = new JSONObject();
58
        try {
59
            logDataInJson.put("cartId_long", cartId);
60
            JSONArray itemIdsJson = new JSONArray(itemIds);
61
            logDataInJson.put("itemIds_long_list", itemIdsJson);
62
        } catch (JSONException e) {
63
            e.printStackTrace();
64
        }
65
        return logDataInJson;
66
    }
67
 
68
    public long getcartId() {
69
        return cartId;
70
    }
71
 
72
    public void setCartId(long cartId) {
73
        this.cartId = cartId;
74
    }
75
 
76
    public List<Long> getItemIds() {
77
        return itemIds;
78
    }
79
 
80
    public void setItemIds(List<Long> itemIds) {
81
        this.itemIds = itemIds;
82
    }
83
}