Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | 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")
13
public class RelatedProductsController extends BaseController {
14
 
15
	private static final String relatedProductsFileName = "MostComparedProducts.html";
16
	private static final int limit = 4;  
17
    private static Logger logger = Logger.getLogger(RelatedProductsController.class);
18
	private String id;
19
    private String snippets="";
20
 
21
	public RelatedProductsController(){
22
		super();
23
	}
24
 
25
    public String show() {
26
        return "show";
27
    }
28
 
29
    public void setId(String id) {
30
    	this.id = id;
31
    }
32
 
33
    public String getSnippets(){
34
    	String itemIds = "";
35
	    try {
36
	    	itemIds = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + id + File.separator + relatedProductsFileName);
37
	    }
38
	    catch (FileNotFoundException e) {
39
	        logger.error("File not found : " + Utils.EXPORT_ENTITIES_PATH + id + File.separator + relatedProductsFileName);
40
	    }
41
	    catch (IOException e) {
42
	        logger.error("IO exception : " + Utils.EXPORT_ENTITIES_PATH + id + File.separator + relatedProductsFileName);
43
	    }
44
	    if(!itemIds.equals("")){
45
	    	String[] items = itemIds.split("\\s|\\n|\\t");
46
	    	int count = 0;
47
	    	for(String item: items){
48
	    		if(limit <= count){
49
	    			break;
50
	    		}
51
	    		try{
52
	    			long itemId = Long.parseLong(item.trim());
53
		    		try {
54
						snippets += FileUtils.read( Utils.EXPORT_ENTITIES_PATH + itemId + File.separator + "WidgetSnippet.html");
55
						count++;
56
			    	}
57
		            catch (FileNotFoundException e) {
58
		                logger.error("File not found : " + Utils.EXPORT_ENTITIES_PATH + itemId + File.separator +"WidgetSnippet.html");
59
		            }
60
		            catch (IOException e) {
61
		                logger.error("IO exception : " + Utils.EXPORT_ENTITIES_PATH + itemId + File.separator +"WidgetSnippet.html");
62
		            }	
63
	    		}catch (NumberFormatException nf){
64
	    			logger.error("Unable to convert string to long");
65
	    		}
66
	    	}
67
	    }	    
68
	    return snippets;
69
    }
70
}