Subversion Repositories SmartDukaan

Rev

Rev 2754 | Rev 3599 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2754 rajveer 1
package in.shop2020.serving.controllers;
2
 
3
import in.shop2020.serving.utils.FileUtils;
4
import in.shop2020.serving.utils.Utils;
5
 
6
import java.io.File;
7
import java.io.FileNotFoundException;
8
import java.io.IOException;
9
 
10
import org.apache.log4j.Logger;
11
 
12
@SuppressWarnings("serial")
2867 rajveer 13
public class MostComparedProductsController extends BaseController {
2754 rajveer 14
 
15
	private static final String relatedProductsFileName = "MostComparedProducts.html";
2867 rajveer 16
	private static Logger logger = Logger.getLogger(MostComparedProductsController.class);
2754 rajveer 17
	private String id;
18
    private String snippets="";
19
 
2867 rajveer 20
	public MostComparedProductsController(){
2754 rajveer 21
		super();
22
	}
23
 
24
    public String show() {
25
        return "show";
26
    }
27
 
28
    public void setId(String id) {
29
    	this.id = id;
30
    }
31
 
32
    public String getSnippets(){
33
    	String itemIds = "";
34
	    try {
35
	    	itemIds = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + id + File.separator + relatedProductsFileName);
36
	    }
37
	    catch (FileNotFoundException e) {
38
	        logger.error("File not found : " + Utils.EXPORT_ENTITIES_PATH + id + File.separator + relatedProductsFileName);
39
	    }
40
	    catch (IOException e) {
41
	        logger.error("IO exception : " + Utils.EXPORT_ENTITIES_PATH + id + File.separator + relatedProductsFileName);
42
	    }
43
	    if(!itemIds.equals("")){
44
	    	String[] items = itemIds.split("\\s|\\n|\\t");
45
	    	for(String item: items){
46
	    		try{
47
	    			long itemId = Long.parseLong(item.trim());
48
		    		try {
49
						snippets += FileUtils.read( Utils.EXPORT_ENTITIES_PATH + itemId + File.separator + "WidgetSnippet.html");
50
			    	}
51
		            catch (FileNotFoundException e) {
52
		                logger.error("File not found : " + Utils.EXPORT_ENTITIES_PATH + itemId + File.separator +"WidgetSnippet.html");
53
		            }
54
		            catch (IOException e) {
55
		                logger.error("IO exception : " + Utils.EXPORT_ENTITIES_PATH + itemId + File.separator +"WidgetSnippet.html");
56
		            }	
57
	    		}catch (NumberFormatException nf){
58
	    			logger.error("Unable to convert string to long");
59
	    		}
60
	    	}
61
	    }	    
62
	    return snippets;
63
    }
64
}