Rev 5346 | Rev 5497 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.util;import in.shop2020.metamodel.core.EntityState;import in.shop2020.metamodel.core.EntityStatus;import in.shop2020.metamodel.definitions.Category;import in.shop2020.metamodel.util.CreationUtils;import in.shop2020.metamodel.util.ExpandedEntity;import java.util.Map;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;public class MostComparedIndexGenerator {private String[] indentation = {"", " ", " ", " "," "};private static Log log = LogFactory.getLog(MostComparedIndexGenerator.class);public void generate() {StringBuilder sb = new StringBuilder();sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002160&p2=1000541'>Samsung Galaxy Y S5360 vs Samsung Galaxy Pop S5570</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002151&p2=1002160'>Samsung Galaxy Y S5360 Vs HTC Explorer (Pico) A310e</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002444&p2=1002153'>Samsung Galaxy Y S5360 Vs Nokia 500</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&p2=1002444'>Spice Mi-270 Vs Samsung Galaxy Y Color</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1001224&p2=1002467'>Spice Mi-310 Vs Spice Mi-280</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&p2=1002467'>Spice Mi-270 Vs Spice Mi-280</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002467&p2=1000483'>Spice Mi-280 Vs Spice Mi-270</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002575&p2=1002444'>Samsung Galaxy Y Duos S6102 Vs Samsung Galaxy Y Color S5360s</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1001224&p2=1000483'>Spice Mi-310 Vs Spice Mi-270</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&p2=1000357'>Spice Mi-270 Vs Micromax Andro A60</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1000483&p2=1002124'>Spice Mi-270 Vs Karbonn A 1</a>\n");sb.append(indentation[1] + "</div>\n");sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones?p1=1002575&p2=1002160'>Samsung Galaxy Y Duos S6102 Vs Samsung Galaxy Y S5360</a>\n");sb.append(indentation[1] + "</div>\n");/** Auto generated comparison links, data used from most compared products.*/try {sb.append(getAutoGeneratedComparisonLinks());} catch(Exception e){log.error("Could not generate Autogenerated Comparison Links");e.printStackTrace();}String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "most-compared-index.html";try {DBUtils.store(sb.toString(), indexFilename);} catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) {MostComparedIndexGenerator g = new MostComparedIndexGenerator();g.generate();}private StringBuffer getAutoGeneratedComparisonLinks() throws Exception {Map<Long, Map<Long, Long>> comparisonStats = null;StringBuffer sb = new StringBuffer();comparisonStats = CreationUtils.getComparisonStats();if(comparisonStats != null){for(Map.Entry<Long, Map<Long, Long>> entry : comparisonStats.entrySet()){Long entityId = entry.getKey();ExpandedEntity expandedEntity = new ExpandedEntity(CreationUtils.getEntity(entityId));Category category = expandedEntity.getCategory();if(category == null){continue;}EntityState es = CreationUtils.getEntityState(entityId);if(EntityStatus.READY.equals(es.getStatus()) && category.getParentCategory().getID()==Utils.MOBILE_PHONES_CATAGORY) {String entityName = EntityUtils.getProductName(expandedEntity);String hyphendatedName = entityName.replaceAll(" +", "-").replaceAll("/+", "-").replaceAll("-+", "-").toLowerCase();for (Long anotherEntityId : entry.getValue().keySet()) {EntityState es1 = CreationUtils.getEntityState(anotherEntityId);ExpandedEntity anotherExpandedEntity = new ExpandedEntity(CreationUtils.getEntity(anotherEntityId));Category anotherCategory = anotherExpandedEntity.getCategory();if(anotherCategory == null){continue;}if(EntityStatus.READY.equals(es1.getStatus()) && anotherCategory.getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGORY){String anotherEntityName = EntityUtils.getProductName(anotherExpandedEntity);String anotherHyphenatedName = anotherEntityName.replaceAll(" +", "-").replaceAll("/+", "-").replaceAll("-+", "-").toLowerCase();sb.append(indentation[1] + "<div>\n");sb.append(indentation[2] + "<a href='http://www.saholic.com/compare-mobile-phones/" + hyphendatedName + "-vs-" + anotherHyphenatedName+"?p1=" + entityId +"&p2="+ anotherEntityId+" '>" + entityName + " Vs "+ anotherEntityName + "</a>\n");sb.append(indentation[1] + "</div>\n");}}}}}return sb;}}