Subversion Repositories SmartDukaan

Rev

Rev 3336 | Go to most recent revision | 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";
47
    	} else	{
48
    		DataLogger.logSocialData(SocialEventType.COMMUNITY_PROMOTION_VIEWED, "1000");
49
 
50
    		return "success";
51
    	}
2351 varun.gupt 52
    }
53
 
54
    public String create()  {
3298 varun.gupt 55
 
56
    	if (pid != null && pid.equals("bb"))	{
3336 varun.gupt 57
        	DataLogger.logSocialData(SocialEventType.BLACKBERRY_PROMOTION_VIEWED , "1000");
3298 varun.gupt 58
    		return "bb-promo";
59
    	} else	{
3336 varun.gupt 60
        	DataLogger.logSocialData(SocialEventType.COMMUNITY_PROMOTION_VIEWED, "1000");
61
 
3298 varun.gupt 62
            return "success";
63
    	}
2351 varun.gupt 64
    }
3298 varun.gupt 65
 
66
    public void setPid(String pid) {
67
		this.pid = pid;
68
	}
2351 varun.gupt 69
 
70
    @Override
71
    public void setParameters(Map<String, String[]> parameters) {
72
        this.parameters = parameters;
73
    }
3298 varun.gupt 74
 
2351 varun.gupt 75
    @Override
76
    public void setServletContext(ServletContext context) {
77
        this.context = context;
78
    }
79
 
80
    public String getParameter(String key)    {
81
        String str = "";
82
        for (int i = 0; i < this.parameters.get(key).length; i ++)  {
83
            str += this.parameters.get(key)[i];
84
        }
85
        return str;
86
    }
87
 
88
    public Map<String, String[]> getParameters()   {
89
        return this.parameters;
90
    }
91
 
92
    public String getFBPostedJSON()  {
3298 varun.gupt 93
        System.out.println(this.parameters);
94
 
4152 varun.gupt 95
        if (this.parameters.get("signed_request").length > 0)	{
96
            String str = this.parameters.get("signed_request")[0];
97
            System.out.println(str);
98
            Base64Encoder decoder = new Base64Encoder();
99
            try {
100
            	System.out.println(str.split("\\."));
101
                byte[] decodedBytes = decoder.decode(str.split("\\.")[1]);
102
                String s = new String(decodedBytes).trim();
103
                String encodedString = decoder.encode(s.getBytes());
104
                System.out.println(encodedString);
105
                System.out.println(encodedString.equals(str));
106
                System.out.println(s);
107
                return s;
108
            }
109
            catch (ArrayIndexOutOfBoundsException e) {
110
                e.printStackTrace();
111
                return "{}";
112
            }
2468 varun.gupt 113
        }
4152 varun.gupt 114
        return "{}";
2351 varun.gupt 115
    }
116
 
117
    public String test()  {
118
        String[] test = new String[] {"str1", "str2", "str3"};
119
        String str = "";
120
 
121
        for (int i = 0; i < test.length; i ++)  {
122
            str += test[i];
123
        }
124
        return str;
125
    }
126
 
127
    public String getServletContextPath(){
128
        return context.getContextPath();
129
    }
4152 varun.gupt 130
 
131
    public void addDisplayItem(String name, String price, long entityId)	{
132
    	this.displayItems.add(new DisplayItem(name, price, entityId));
133
    }
134
 
135
    public List<DisplayItem> getDisplayItems()	{
136
    	for (DisplayItem item: this.displayItems)	{
137
    		System.out.println(item.getName());
138
    	}
139
    	return this.displayItems;
140
    }
2351 varun.gupt 141
}