Subversion Repositories SmartDukaan

Rev

Rev 3336 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3336 Rev 4152
Line 1... Line 1...
1
package in.shop2020.social.controllers;
1
package in.shop2020.social.controllers;
2
 
2
 
3
import in.shop2020.datalogger.SocialEventType;
3
import in.shop2020.datalogger.SocialEventType;
4
import in.shop2020.utils.DataLogger;
4
import in.shop2020.utils.DataLogger;
5
 
5
 
-
 
6
import java.util.ArrayList;
-
 
7
import java.util.List;
6
import java.util.Map;
8
import java.util.Map;
7
import javax.servlet.ServletContext;
9
import javax.servlet.ServletContext;
8
import org.apache.struts2.interceptor.ParameterAware;
10
import org.apache.struts2.interceptor.ParameterAware;
9
import org.apache.struts2.util.ServletContextAware;
11
import org.apache.struts2.util.ServletContextAware;
10
import com.thoughtworks.xstream.core.util.Base64Encoder;
12
import com.thoughtworks.xstream.core.util.Base64Encoder;
11
 
13
 
12
public class CommunityPromotionController implements ParameterAware, ServletContextAware {
14
public class CommunityPromotionController implements ParameterAware, ServletContextAware {
-
 
15
	public static class DisplayItem	{
-
 
16
		private String name;
-
 
17
		private String price;
-
 
18
		private long entityId;
13
 
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
	}
14
    protected Map<String, String[]> parameters;
38
    protected Map<String, String[]> parameters;
15
    protected ServletContext context;
39
    protected ServletContext context;
16
    private String pid;
40
    private String pid;
17
    
-
 
18
    public CommunityPromotionController() {
41
    private List<DisplayItem> displayItems = new ArrayList<DisplayItem>();
19
    }
-
 
20
 
42
 
21
    public String index()  {
43
    public String index()  {
-
 
44
    	if (pid != null && pid.equals("bb"))	{
-
 
45
    		DataLogger.logSocialData(SocialEventType.BLACKBERRY_PROMOTION_VIEWED , "1000");
-
 
46
    		return "bb-promo";
-
 
47
    	} else	{
22
    	DataLogger.logSocialData(SocialEventType.COMMUNITY_PROMOTION_VIEWED, "1000");
48
    		DataLogger.logSocialData(SocialEventType.COMMUNITY_PROMOTION_VIEWED, "1000");
-
 
49
    	
23
        return "success";
50
    		return "success";
-
 
51
    	}
24
    }
52
    }
25
    
53
    
26
    public String create()  {
54
    public String create()  {
27
    	
55
    	
28
    	if (pid != null && pid.equals("bb"))	{
56
    	if (pid != null && pid.equals("bb"))	{
Line 62... Line 90...
62
    }
90
    }
63
    
91
    
64
    public String getFBPostedJSON()  {
92
    public String getFBPostedJSON()  {
65
        System.out.println(this.parameters);
93
        System.out.println(this.parameters);
66
 
94
 
-
 
95
        if (this.parameters.get("signed_request").length > 0)	{
67
        String str = this.parameters.get("signed_request")[0];
96
            String str = this.parameters.get("signed_request")[0];
68
        System.out.println(str);
97
            System.out.println(str);
69
        Base64Encoder decoder = new Base64Encoder();
98
            Base64Encoder decoder = new Base64Encoder();
70
        try {
99
            try {
71
        	System.out.println(str.split("\\."));
100
            	System.out.println(str.split("\\."));
72
            byte[] decodedBytes = decoder.decode(str.split("\\.")[1]);
101
                byte[] decodedBytes = decoder.decode(str.split("\\.")[1]);
73
            String s = new String(decodedBytes).trim();
102
                String s = new String(decodedBytes).trim();
74
            String encodedString = decoder.encode(s.getBytes());
103
                String encodedString = decoder.encode(s.getBytes());
75
            System.out.println(encodedString);
104
                System.out.println(encodedString);
76
            System.out.println(encodedString.equals(str));
105
                System.out.println(encodedString.equals(str));
77
            System.out.println(s);
106
                System.out.println(s);
78
            return s;
107
                return s;
79
        }
108
            }
80
        catch (ArrayIndexOutOfBoundsException e) {
109
            catch (ArrayIndexOutOfBoundsException e) {
81
            e.printStackTrace();
110
                e.printStackTrace();
82
            return "{}";
111
                return "{}";
-
 
112
            }
83
        }
113
        }
-
 
114
        return "{}";
84
    }
115
    }
85
    
116
    
86
    public String test()  {
117
    public String test()  {
87
        String[] test = new String[] {"str1", "str2", "str3"};
118
        String[] test = new String[] {"str1", "str2", "str3"};
88
        String str = "";
119
        String str = "";
Line 94... Line 125...
94
    }
125
    }
95
    
126
    
96
    public String getServletContextPath(){
127
    public String getServletContextPath(){
97
        return context.getContextPath();
128
        return context.getContextPath();
98
    }
129
    }
-
 
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
    }
99
}
141
}
100
142