Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
2351 varun.gupt 1
package in.shop2020.social.controllers;
2
 
2778 varun.gupt 3
import in.shop2020.datalogger.SocialEventType;
4
import in.shop2020.utils.DataLogger;
5
 
4152 varun.gupt 6
import java.util.ArrayList;
7
import java.util.List;
2351 varun.gupt 8
import java.util.Map;
9
import javax.servlet.ServletContext;
10
import org.apache.struts2.interceptor.ParameterAware;
11
import org.apache.struts2.util.ServletContextAware;
12
import com.thoughtworks.xstream.core.util.Base64Encoder;
13
 
14
public class CommunityPromotionController implements ParameterAware, ServletContextAware {
4152 varun.gupt 15
	public static class DisplayItem	{
16
		private String name;
17
		private String price;
18
		private long entityId;
19
 
20
		public DisplayItem(String name, String price, long entityId)	{
21
			this.name = name;
22
			this.price = price;
23
			this.entityId = entityId;
24
		}
25
 
26
		public String getName()	{
27
			return this.name;
28
		}
29
 
30
		public String getPrice()	{
31
			return this.price;
32
		}
33
 
34
		public long getEntityId()	{
35
			return this.entityId;
36
		}
37
	}
2351 varun.gupt 38
    protected Map<String, String[]> parameters;
39
    protected ServletContext context;
3298 varun.gupt 40
    private String pid;
4152 varun.gupt 41
    private List<DisplayItem> displayItems = new ArrayList<DisplayItem>();
2351 varun.gupt 42
 
43
    public String index()  {
4152 varun.gupt 44
    	if (pid != null && pid.equals("bb"))	{
45
    		DataLogger.logSocialData(SocialEventType.BLACKBERRY_PROMOTION_VIEWED , "1000");
46
    		return "bb-promo";
4156 varun.gupt 47
    	}
48
    	else if (pid != null && pid.equals("tab")){
49
    		DataLogger.logSocialData(SocialEventType.BLACKBERRY_PROMOTION_VIEWED , "1000");
50
    		return "tab";
51
    	}
52
    	else	{
4152 varun.gupt 53
    		DataLogger.logSocialData(SocialEventType.COMMUNITY_PROMOTION_VIEWED, "1000");
54
 
55
    		return "success";
56
    	}
2351 varun.gupt 57
    }
58
 
59
    public String create()  {
3298 varun.gupt 60
 
61
    	if (pid != null && pid.equals("bb"))	{
3336 varun.gupt 62
        	DataLogger.logSocialData(SocialEventType.BLACKBERRY_PROMOTION_VIEWED , "1000");
3298 varun.gupt 63
    		return "bb-promo";
4156 varun.gupt 64
    	}
65
    	else if (pid != null && pid.equals("tab")){
66
    		DataLogger.logSocialData(SocialEventType.BLACKBERRY_PROMOTION_VIEWED , "1000");
67
    		return "tab";
68
    	}
69
    	else	{
3336 varun.gupt 70
        	DataLogger.logSocialData(SocialEventType.COMMUNITY_PROMOTION_VIEWED, "1000");
71
 
3298 varun.gupt 72
            return "success";
73
    	}
2351 varun.gupt 74
    }
3298 varun.gupt 75
 
76
    public void setPid(String pid) {
77
		this.pid = pid;
78
	}
2351 varun.gupt 79
 
80
    @Override
81
    public void setParameters(Map<String, String[]> parameters) {
82
        this.parameters = parameters;
83
    }
3298 varun.gupt 84
 
2351 varun.gupt 85
    @Override
86
    public void setServletContext(ServletContext context) {
87
        this.context = context;
88
    }
89
 
90
    public String getParameter(String key)    {
91
        String str = "";
92
        for (int i = 0; i < this.parameters.get(key).length; i ++)  {
93
            str += this.parameters.get(key)[i];
94
        }
95
        return str;
96
    }
97
 
98
    public Map<String, String[]> getParameters()   {
99
        return this.parameters;
100
    }
101
 
102
    public String getFBPostedJSON()  {
3298 varun.gupt 103
        System.out.println(this.parameters);
104
 
4152 varun.gupt 105
        if (this.parameters.get("signed_request").length > 0)	{
106
            String str = this.parameters.get("signed_request")[0];
107
            System.out.println(str);
108
            Base64Encoder decoder = new Base64Encoder();
109
            try {
110
            	System.out.println(str.split("\\."));
111
                byte[] decodedBytes = decoder.decode(str.split("\\.")[1]);
112
                String s = new String(decodedBytes).trim();
113
                String encodedString = decoder.encode(s.getBytes());
114
                System.out.println(encodedString);
115
                System.out.println(encodedString.equals(str));
116
                System.out.println(s);
117
                return s;
118
            }
119
            catch (ArrayIndexOutOfBoundsException e) {
120
                e.printStackTrace();
121
                return "{}";
122
            }
2468 varun.gupt 123
        }
4152 varun.gupt 124
        return "{}";
2351 varun.gupt 125
    }
126
 
127
    public String test()  {
128
        String[] test = new String[] {"str1", "str2", "str3"};
129
        String str = "";
130
 
131
        for (int i = 0; i < test.length; i ++)  {
132
            str += test[i];
133
        }
134
        return str;
135
    }
136
 
137
    public String getServletContextPath(){
138
        return context.getContextPath();
139
    }
4152 varun.gupt 140
 
141
    public void addDisplayItem(String name, String price, long entityId)	{
142
    	this.displayItems.add(new DisplayItem(name, price, entityId));
143
    }
144
 
145
    public List<DisplayItem> getDisplayItems()	{
146
    	for (DisplayItem item: this.displayItems)	{
147
    		System.out.println(item.getName());
148
    	}
149
    	return this.displayItems;
150
    }
2351 varun.gupt 151
}