Subversion Repositories SmartDukaan

Rev

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

Rev 5048 Rev 5322
Line 19... Line 19...
19
import org.apache.commons.lang.StringUtils;
19
import org.apache.commons.lang.StringUtils;
20
import org.apache.log4j.Logger;
20
import org.apache.log4j.Logger;
21
import org.apache.struts2.convention.annotation.Action;
21
import org.apache.struts2.convention.annotation.Action;
22
import org.apache.struts2.convention.annotation.Actions;
22
import org.apache.struts2.convention.annotation.Actions;
23
import org.apache.struts2.convention.annotation.Result;
23
import org.apache.struts2.convention.annotation.Result;
-
 
24
import org.apache.struts2.convention.annotation.Results;
24
 
25
 
25
/**
26
/**
26
 * 
27
 * 
27
 * @author rajveer
28
 * @author rajveer
28
 * 
29
 * 
29
 */
30
 */
30
 
31
 
-
 
32
@Results({
31
@Result(name = "show", location = "compare-show.vm")
33
    @Result(name = "show", location = "compare-show.vm"),
-
 
34
    @Result(name = "redirect", location = "${redirectUrl}", type = "redirect", params={"statusCode", "301"})
-
 
35
})
32
public class CompareController extends BaseController {
36
public class CompareController extends BaseController {
33
 
37
 
34
    private static final long serialVersionUID = 1L;
38
    private static final long serialVersionUID = 1L;
35
 
39
 
36
    private static Logger logger = Logger.getLogger(Class.class);
40
    private static Logger logger = Logger.getLogger(Class.class);
Line 41... Line 45...
41
    private List<String> productNames;
45
    private List<String> productNames;
42
    private List<String> productTitles;
46
    private List<String> productTitles;
43
    private Map<String, String> snippets;
47
    private Map<String, String> snippets;
44
    private List<String> unComparedSlides;
48
    private List<String> unComparedSlides;
45
    private List<String> commonSlides;
49
    private List<String> commonSlides;
-
 
50
    private String redirectUrl;
46
    
51
    
47
    private Map<String, String> slideNameImportanceMap;
52
    private Map<String, String> slideNameImportanceMap;
48
    
53
    
49
    private Map<String, Map<String, Double>> productSlideScores;
54
    private Map<String, Map<String, Double>> productSlideScores;
50
    
55
    
Line 62... Line 67...
62
        @Action("/compare")
67
        @Action("/compare")
63
    })
68
    })
64
    
69
    
65
    public String index() throws SecurityException, IOException {
70
    public String index() throws SecurityException, IOException {
66
        productList = new ArrayList<String>();
71
        productList = new ArrayList<String>();
-
 
72
        StringBuffer prodNames = new StringBuffer("");
-
 
73
        StringBuffer requestParams = new StringBuffer("");
67
        if(request.getParameter("p1") != null){
74
        if(request.getParameter("p1") != null){
68
            this.productList.add(request.getParameter("p1"));
75
            this.productList.add(request.getParameter("p1"));
69
        }
76
        }
70
        if(request.getParameter("p2") != null){
77
        if(request.getParameter("p2") != null){
71
            this.productList.add(request.getParameter("p2"));
78
            this.productList.add(request.getParameter("p2"));
Line 77... Line 84...
77
            this.productList.add(request.getParameter("p4"));
84
            this.productList.add(request.getParameter("p4"));
78
        }
85
        }
79
        if(request.getParameter("p5") != null){
86
        if(request.getParameter("p5") != null){
80
            this.productList.add(request.getParameter("p5"));
87
            this.productList.add(request.getParameter("p5"));
81
        }
88
        }
-
 
89
        boolean first = true;
-
 
90
        int i=1;
-
 
91
        for(String product : productList){        	
-
 
92
        	String hyphenatedName = getHyphenatedName(product);
-
 
93
        	if(!hyphenatedName.equals("")){
-
 
94
        		if(first){
-
 
95
        			prodNames.append(hyphenatedName);
-
 
96
        			requestParams.append("?p"+ (i++) + "=" + product);
-
 
97
        			first = false;
-
 
98
        		} else {
-
 
99
        			prodNames.append("-vs-" + hyphenatedName);
-
 
100
        			requestParams.append("&p"+ (i++) + "=" + product);
-
 
101
        		}
-
 
102
        	}
-
 
103
        }
-
 
104
        redirectUrl = "/compare-mobile-phones/" + prodNames.append(requestParams).toString().toLowerCase();
-
 
105
        logger.info("301 Redirection to " + redirectUrl);
-
 
106
        return "redirect";
-
 
107
    }
-
 
108
    
-
 
109
    public String show() throws SecurityException, IOException {
-
 
110
    	 productList = new ArrayList<String>();
-
 
111
         if(request.getParameter("p1") != null){
-
 
112
             this.productList.add(request.getParameter("p1"));
-
 
113
         }
-
 
114
         if(request.getParameter("p2") != null){
-
 
115
             this.productList.add(request.getParameter("p2"));
-
 
116
         }
-
 
117
         if(request.getParameter("p3") != null){
-
 
118
             this.productList.add(request.getParameter("p3"));
-
 
119
         }
-
 
120
         if(request.getParameter("p4") != null){
-
 
121
             this.productList.add(request.getParameter("p4"));
-
 
122
         }
-
 
123
         if(request.getParameter("p5") != null){
-
 
124
             this.productList.add(request.getParameter("p5"));
-
 
125
         }
82
        
126
         
83
        DataLogger.logData(EventType.PRODUCT_COMPARE, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
127
         DataLogger.logData(EventType.PRODUCT_COMPARE, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
84
                StringUtils.join(productList, ", "));
128
                 StringUtils.join(productList, ", "));
85
        return "show";
129
         return "show";
86
    }
130
    }
87
    
131
    
88
    public List<String> getSlideNames() {
132
    public List<String> getSlideNames() {
89
        productNames = new ArrayList<String>();
133
        productNames = new ArrayList<String>();
90
        productTitles = new ArrayList<String>();
134
        productTitles = new ArrayList<String>();
Line 154... Line 198...
154
    
198
    
155
    public List<String> getcommonSlides(){
199
    public List<String> getcommonSlides(){
156
        return this.commonSlides;
200
        return this.commonSlides;
157
    }
201
    }
158
    
202
    
-
 
203
    public String getRedirectUrl(){
-
 
204
    	return this.redirectUrl;	
-
 
205
    }
-
 
206
    
159
    public List<Double> getOverallScores(){
207
    public List<Double> getOverallScores(){
160
        List<Double> overallScores = new ArrayList<Double>();
208
        List<Double> overallScores = new ArrayList<Double>();
161
        for(String productId : productSlideScores.keySet()){
209
        for(String productId : productSlideScores.keySet()){
162
            Map<String, Double> slideScores = productSlideScores.get(productId);
210
            Map<String, Double> slideScores = productSlideScores.get(productId);
163
            double commulativeWeightedScore = 0.0;
211
            double commulativeWeightedScore = 0.0;
Line 286... Line 334...
286
    }
334
    }
287
    
335
    
288
    public List<String> getImportances(){
336
    public List<String> getImportances(){
289
        return this.importances;
337
        return this.importances;
290
    }
338
    }
-
 
339
    
-
 
340
    private String getHyphenatedName(String productId) {
-
 
341
    	File f = new File(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideNamesSnippet.html");
-
 
342
        FileInputStream fis = null;
-
 
343
        String hyphenatedName = "";
-
 
344
    	 try {
-
 
345
             fis = new FileInputStream(f);
-
 
346
             BufferedReader br = new BufferedReader(new InputStreamReader(fis));
-
 
347
             hyphenatedName = br.readLine().replaceAll(" +", "-");
-
 
348
         } catch (IOException e) {
-
 
349
             logger.error("Error while reading snippet", e);
-
 
350
         }
-
 
351
         return hyphenatedName;
-
 
352
    }
291
}
353
}