Subversion Repositories SmartDukaan

Rev

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

Rev 5422 Rev 5547
Line 10... Line 10...
10
import java.io.FileInputStream;
10
import java.io.FileInputStream;
11
import java.io.IOException;
11
import java.io.IOException;
12
import java.io.InputStreamReader;
12
import java.io.InputStreamReader;
13
import java.text.DecimalFormat;
13
import java.text.DecimalFormat;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
-
 
15
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.Iterator;
16
import java.util.LinkedHashMap;
17
import java.util.LinkedHashMap;
17
import java.util.List;
18
import java.util.List;
18
import java.util.Map;
19
import java.util.Map;
19
 
20
 
Line 22... Line 23...
22
import org.apache.struts2.convention.annotation.Action;
23
import org.apache.struts2.convention.annotation.Action;
23
import org.apache.struts2.convention.annotation.Actions;
24
import org.apache.struts2.convention.annotation.Actions;
24
import org.apache.struts2.convention.annotation.Result;
25
import org.apache.struts2.convention.annotation.Result;
25
import org.apache.struts2.convention.annotation.Results;
26
import org.apache.struts2.convention.annotation.Results;
26
 
27
 
-
 
28
import com.opensymphony.xwork2.ActionContext;
-
 
29
 
27
/**
30
/**
28
 * 
31
 * 
29
 * @author rajveer
32
 * @author rajveer
30
 * 
33
 * 
31
 */
34
 */
Line 46... Line 49...
46
    private List<String> productNames;
49
    private List<String> productNames;
47
    private List<String> productTitles;
50
    private List<String> productTitles;
48
    private Map<String, String> snippets;
51
    private Map<String, String> snippets;
49
    private List<String> unComparedSlides;
52
    private List<String> unComparedSlides;
50
    private List<String> commonSlides;
53
    private List<String> commonSlides;
-
 
54
    private Map<String, String> hyphenatedNames = new HashMap<String, String>();
51
    private String redirectUrl;
55
    private String redirectUrl;
52
    
56
    
53
    private Map<String, String> slideNameImportanceMap;
57
    private Map<String, String> slideNameImportanceMap;
54
    
58
    
55
    private Map<String, Map<String, Double>> productSlideScores;
59
    private Map<String, Map<String, Double>> productSlideScores;
Line 102... Line 106...
102
        			prodNames.append("-vs-" + hyphenatedName);
106
        			prodNames.append("-vs-" + hyphenatedName);
103
        			requestParams.append("&p"+ (i++) + "=" + product);
107
        			requestParams.append("&p"+ (i++) + "=" + product);
104
        		}
108
        		}
105
        	}
109
        	}
106
        }
110
        }
107
        redirectUrl = "/compare-mobile-phones/" + prodNames.append(requestParams).toString().toLowerCase();
111
        redirectUrl = "/" + ActionContext.getContext().getName() + "/" + prodNames.append(requestParams).toString().toLowerCase();
108
        logger.info("301 Redirection to " + redirectUrl);
112
        logger.info("301 Redirection to " + redirectUrl);
109
        return "redirect";
113
        return "redirect";
110
    }
114
    }
111
    
115
    
112
    public String show() throws SecurityException, IOException {
116
    public String show() throws SecurityException, IOException {
-
 
117
        logger.info(ActionContext.getContext().getName());
113
    	 productList = new ArrayList<String>();
118
    	 productList = new ArrayList<String>();
114
         if(request.getParameter("p1") != null){
119
         if(request.getParameter("p1") != null){
115
             this.productList.add(request.getParameter("p1"));
120
             this.productList.add(request.getParameter("p1"));
116
         }
121
         }
117
         if(request.getParameter("p2") != null){
122
         if(request.getParameter("p2") != null){
Line 137... Line 142...
137
        productTitles = new ArrayList<String>();
142
        productTitles = new ArrayList<String>();
138
        slideNameImportanceMap = new LinkedHashMap<String, String>();
143
        slideNameImportanceMap = new LinkedHashMap<String, String>();
139
        productSlideScores = new LinkedHashMap<String, Map<String, Double>>();
144
        productSlideScores = new LinkedHashMap<String, Map<String, Double>>();
140
        Iterator<String> productListIterator = productList.iterator();
145
        Iterator<String> productListIterator = productList.iterator();
141
        while(productListIterator.hasNext()) {
146
        while(productListIterator.hasNext()) {
-
 
147
        	String productId = productListIterator.next();
142
            File f = new File(Utils.EXPORT_ENTITIES_PATH + productListIterator.next() + File.separator + "SlideNamesSnippet.html");
148
            File f = new File(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideNamesSnippet.html");
143
            FileInputStream fis = null;
149
            FileInputStream fis = null;
144
            try {
150
            try {
145
                fis = new FileInputStream(f);
151
                fis = new FileInputStream(f);
146
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
152
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
147
                String line;
153
                String line;
Line 149... Line 155...
149
                boolean isProductTitle = true;
155
                boolean isProductTitle = true;
150
                Map<String, Double> slideScores = new LinkedHashMap<String, Double>();
156
                Map<String, Double> slideScores = new LinkedHashMap<String, Double>();
151
                while((line = br.readLine()) != null){
157
                while((line = br.readLine()) != null){
152
                    if(isProductName){
158
                    if(isProductName){
153
                        productNames.add(line);
159
                        productNames.add(line);
-
 
160
                        hyphenatedNames.put(productId, line.replaceAll(" +", "-").replaceAll("/", "-").replaceAll("-+", "-"));
154
                        productSlideScores.put(line, slideScores);
161
                        productSlideScores.put(line, slideScores);
155
                        isProductName = false;
162
                        isProductName = false;
156
                        continue;
163
                        continue;
157
                    }
164
                    }
158
                    if(isProductTitle){
165
                    if(isProductTitle){
Line 352... Line 359...
352
         } catch (IOException e) {
359
         } catch (IOException e) {
353
             logger.error("Error while reading snippet", e);
360
             logger.error("Error while reading snippet", e);
354
         }
361
         }
355
         return hyphenatedName;
362
         return hyphenatedName;
356
    }
363
    }
-
 
364
    
-
 
365
    public String getUrlForGeneratedCompareWith(String productId){
-
 
366
    	return "/generated/" + hyphenatedNames.get(productId).toLowerCase() + "?p1=" + productId;
-
 
367
    }
-
 
368
    
-
 
369
    public String getUrlForProductPage(String productId){
-
 
370
    	String hyphenatedCategory = ActionContext.getContext().getName();
-
 
371
    	hyphenatedCategory = hyphenatedCategory.split("-", 2)[1];
-
 
372
    	return "/" + hyphenatedCategory+ "/" + hyphenatedNames.get(productId).toLowerCase() + "-" + productId;
-
 
373
    }
-
 
374
    
-
 
375
    public String getActionName(){
-
 
376
    	return ActionContext.getContext().getName();
-
 
377
    }
357
}
378
}