Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
5314 varun.gupt 1
package in.shop2020.util;
2
 
5346 amit.gupta 3
import in.shop2020.metamodel.core.EntityState;
4
import in.shop2020.metamodel.core.EntityStatus;
5
import in.shop2020.metamodel.definitions.Category;
6
import in.shop2020.metamodel.util.CreationUtils;
7
import in.shop2020.metamodel.util.ExpandedEntity;
8
 
9
import java.util.Map;
10
 
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
 
5314 varun.gupt 14
public class MostComparedIndexGenerator {
15
	private String[] indentation = {"", "    ", "        ", "            ","                "};
5346 amit.gupta 16
    private static Log log = LogFactory.getLog(MostComparedIndexGenerator.class);
5314 varun.gupt 17
 
18
	public void generate()	{
19
		StringBuilder sb = new StringBuilder();
20
 
21
		sb.append(indentation[1] + "<div>\n");
22
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002160&amp;p2=1000541'>Samsung Galaxy Y S5360 vs Samsung Galaxy Pop S5570</a>\n");
23
		sb.append(indentation[1] + "</div>\n");
24
 
25
		sb.append(indentation[1] + "<div>\n");
26
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002151&amp;p2=1002160'>Samsung Galaxy Y S5360 Vs HTC Explorer (Pico) A310e</a>\n");
27
		sb.append(indentation[1] + "</div>\n");
28
 
29
		sb.append(indentation[1] + "<div>\n");
30
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002444&amp;p2=1002153'>Samsung Galaxy Y S5360 Vs Nokia 500</a>\n");
31
		sb.append(indentation[1] + "</div>\n");
32
 
33
		sb.append(indentation[1] + "<div>\n");
34
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&amp;p2=1002444'>Spice Mi-270 Vs Samsung Galaxy Y Color</a>\n");
35
		sb.append(indentation[1] + "</div>\n");
36
 
37
		sb.append(indentation[1] + "<div>\n");
38
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1001224&amp;p2=1002467'>Spice Mi-310 Vs Spice Mi-280</a>\n");
39
		sb.append(indentation[1] + "</div>\n");
40
 
41
		sb.append(indentation[1] + "<div>\n");
42
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&amp;p2=1002467'>Spice Mi-270 Vs Spice Mi-280</a>\n");
43
		sb.append(indentation[1] + "</div>\n");
44
 
45
		sb.append(indentation[1] + "<div>\n");
46
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002467&amp;p2=1000483'>Spice Mi-280 Vs Spice Mi-270</a>\n");
47
		sb.append(indentation[1] + "</div>\n");
48
 
49
		sb.append(indentation[1] + "<div>\n");
50
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002575&amp;p2=1002444'>Samsung Galaxy Y Duos S6102 Vs Samsung Galaxy Y Color S5360s</a>\n");
51
		sb.append(indentation[1] + "</div>\n");
52
 
53
		sb.append(indentation[1] + "<div>\n");
54
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1001224&amp;p2=1000483'>Spice Mi-310 Vs Spice Mi-270</a>\n");
55
		sb.append(indentation[1] + "</div>\n");
56
 
57
		sb.append(indentation[1] + "<div>\n");
58
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&amp;p2=1000357'>Spice Mi-270 Vs Micromax Andro A60</a>\n");
59
		sb.append(indentation[1] + "</div>\n");
60
 
61
		sb.append(indentation[1] + "<div>\n");
62
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&amp;p2=1002124'>Spice Mi-270 Vs Karbonn A 1</a>\n");
63
		sb.append(indentation[1] + "</div>\n");
64
 
65
		sb.append(indentation[1] + "<div>\n");
66
		sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002575&amp;p2=1002160'>Samsung Galaxy Y Duos S6102 Vs Samsung Galaxy Y S5360</a>\n");
67
		sb.append(indentation[1] + "</div>\n");
5346 amit.gupta 68
		/*
69
		 * Auto generated comparison links, data used from most compared products.
70
		 */
71
		try {
72
			sb.append(getAutoGeneratedComparisonLinks());
73
		} catch(Exception e){
74
			log.error("Could not generate Autogenerated Comparison Links");
75
			e.printStackTrace();
76
		}
5314 varun.gupt 77
		String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "most-compared-index.html";
78
 
79
		try	{
80
			DBUtils.store(sb.toString(), indexFilename);
81
 
82
		} catch (Exception e) {
83
			e.printStackTrace();
84
		}
85
	}
86
 
87
	public static void main(String[] args) {
88
		MostComparedIndexGenerator g = new MostComparedIndexGenerator();
89
		g.generate();
90
	}
5346 amit.gupta 91
 
92
	private StringBuffer getAutoGeneratedComparisonLinks() throws Exception {
93
		Map<Long, Map<Long, Long>> comparisonStats = null;
94
		StringBuffer sb = new StringBuffer();
95
		comparisonStats = CreationUtils.getComparisonStats();
96
		if(comparisonStats != null){
97
			for(Map.Entry<Long, Map<Long, Long>> entry : comparisonStats.entrySet()){
98
				Long entityId = entry.getKey();
99
				ExpandedEntity expandedEntity = new ExpandedEntity(CreationUtils.getEntity(entityId));
100
				Category category = expandedEntity.getCategory();
101
				if(category == null){
102
					continue;
103
				}
104
				EntityState es = CreationUtils.getEntityState(entityId);
105
				if(EntityStatus.READY.equals(es.getStatus()) && category.getParentCategory().getID()==Utils.MOBILE_PHONES_CATAGORY) {
106
					String entityName = EntityUtils.getProductName(expandedEntity);
107
					String hyphendatedName = entityName.replaceAll(" +", "-").toLowerCase();
108
					for (Long anotherEntityId : entry.getValue().keySet()) {
109
						EntityState es1 = CreationUtils.getEntityState(anotherEntityId);
110
						ExpandedEntity anotherExpandedEntity = new ExpandedEntity(CreationUtils.getEntity(anotherEntityId));
111
						Category anotherCategory = anotherExpandedEntity.getCategory();
112
						if(anotherCategory == null){
113
							continue;
114
						}
115
						if(EntityStatus.READY.equals(es1.getStatus()) && anotherCategory.getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGORY){
116
							String anotherEntityName = EntityUtils.getProductName(anotherExpandedEntity);
117
							String anotherHyphenatedName = anotherEntityName.replaceAll(" +", "-").toLowerCase();
118
							sb.append(indentation[1] + "<div>\n");
119
							sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones/" + hyphendatedName + "-vs-" + anotherHyphenatedName 
120
										+"?p1=" + entityId +"&p2="+ anotherEntityId+" '>" + entityName + " Vs "+ anotherEntityName + "</a>\n");
121
							sb.append(indentation[1] + "</div>\n");
122
						}
123
					}
124
				}
125
			}
126
		}
127
 
128
		return sb;
129
 
130
	}
5314 varun.gupt 131
}