Subversion Repositories SmartDukaan

Rev

Rev 3077 | 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 ProductView extends Event{
    
    private String productName;
    private Long itemId;
    private String refererUrl;

    public ProductView(String[] eventFileds) {
        super(eventFileds);
        productName = eventFileds[5].trim();
        if (eventFileds.length > 6){
                itemId = Long.parseLong(eventFileds[6].trim());
        }
        if (eventFileds.length > 7){
                refererUrl = eventFileds[7].trim();
        }
    }
    
    public ProductView(EventType eType, String sessionId, long userId, String email, String[] logData) {
        super(eType, sessionId, userId, email);
        productName = logData[0].trim();
        itemId = Long.parseLong(logData[1].trim());
        refererUrl = logData[2].trim();
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(eventType.name() + ", ");
        sb.append("userEmail : " + userEmail);
        sb.append(" productName : " + productName);
        sb.append("itemId : " + itemId);
        sb.append(" time : " + time);
        sb.append(" session : " + sessionId);
        sb.append("refererUrl : " + refererUrl);
        return sb.toString();
    }
    
    @Override
    public JSONObject getLogDataInJson() {
        JSONObject logDataInJson = new JSONObject();
        try {
            logDataInJson.put("productName", productName);
            logDataInJson.put("itemId_long", itemId);
            logDataInJson.put("refererUrl", refererUrl);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return logDataInJson;
    }
    
    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }
}