Subversion Repositories SmartDukaan

Rev

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

Rev 5404 Rev 5566
Line 5... Line 5...
5
import in.shop2020.metamodel.definitions.Catalog;
5
import in.shop2020.metamodel.definitions.Catalog;
6
import in.shop2020.metamodel.definitions.Category;
6
import in.shop2020.metamodel.definitions.Category;
7
import in.shop2020.metamodel.definitions.DefinitionsContainer;
7
import in.shop2020.metamodel.definitions.DefinitionsContainer;
8
import in.shop2020.metamodel.util.CreationUtils;
8
import in.shop2020.metamodel.util.CreationUtils;
9
 
9
 
-
 
10
import java.io.BufferedReader;
-
 
11
import java.io.InputStreamReader;
-
 
12
import java.net.URL;
-
 
13
import java.net.URLConnection;
10
import java.util.ArrayList;
14
import java.util.ArrayList;
11
import java.util.Arrays;
15
import java.util.Arrays;
12
import java.util.HashMap;
16
import java.util.HashMap;
13
import java.util.List;
17
import java.util.List;
14
import java.util.Map;
18
import java.util.Map;
Line 56... Line 60...
56
		categorySynonyms.put((long) 10018, Arrays.asList(catSynonyms.get("Carrying Case").split(",")));
60
		categorySynonyms.put((long) 10018, Arrays.asList(catSynonyms.get("Carrying Case").split(",")));
57
		this.entities = entities;
61
		this.entities = entities;
58
	}
62
	}
59
	
63
	
60
	public void generate()	{
64
	public void generate()	{
61
		StringBuilder sb = new StringBuilder();
65
		Map<String,Map<String, String>> map = new HashMap<String, Map<String,String>>();
62
		
-
 
63
		for(Entity entity: entities)	{
66
		for(Entity entity: entities)	{
64
			
67
			
65
			long categoryId = entity.getCategoryID();
68
			long categoryId = entity.getCategoryID();
66
			String url = getProductURL(entity);
69
			String url = getProductURL(entity);
67
			
70
			
Line 73... Line 76...
73
					String text = compatibilitySlide.getFreeformContent().getFreeformText();
76
					String text = compatibilitySlide.getFreeformContent().getFreeformText();
74
					
77
					
75
					if(text.indexOf("<ul>") > -1)	continue;
78
					if(text.indexOf("<ul>") > -1)	continue;
76
					for(String name: getHandsetNames(text))	{
79
					for(String name: getHandsetNames(text))	{
77
						for(String categoryLabel : getCategorySynonyms(categoryId)){
80
						for(String categoryLabel : getCategorySynonyms(categoryId)){
78
							sb.append(indentation[1] + "<div>\n");
81
							String displayName = name + " " + categoryLabel;
79
							sb.append(indentation[2] + "<a href='" + url + "'>" + name + " " + categoryLabel + "</a>\n");
82
							String startsWith = displayName.substring(0,1).toLowerCase();
-
 
83
							Map <String, String> map1;
-
 
84
							if(map.containsKey(startsWith)){
-
 
85
								map1 = map.get(startsWith);
-
 
86
							}else {
80
							sb.append(indentation[1] + "</div>\n");
87
								map1 = new HashMap<String, String>();
-
 
88
								map.put(startsWith, map1);
-
 
89
							}
-
 
90
							map1.put(displayName, url);
81
						}
91
						}
82
					}
92
					}
83
					
93
					
84
				} catch (NullPointerException e) {
94
				} catch (NullPointerException e) {
85
					// TODO: handle exception
95
					// TODO: handle exception
86
				}
96
				}
87
			}
97
			}
88
		}
98
		}
-
 
99
		String alphabeticalTemplate = "Product starting with <b>{0}</b>";
-
 
100
		String levelOneTitle = "Accessories Compatibility Index";
-
 
101
		String levelTwoTitle = "";
-
 
102
		LevelHierarchy lh = new LevelHierarchy(alphabeticalTemplate, levelOneTitle, levelTwoTitle, map);
-
 
103
		lh.generatePages();
-
 
104
 
89
		
105
		
90
		String indexFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "compatible-accessories-index.html";
-
 
91
		
-
 
92
		try	{
-
 
93
			DBUtils.store(sb.toString(), indexFilename);
-
 
94
			
-
 
95
		} catch (Exception e) {
-
 
96
			e.printStackTrace();
-
 
97
		}
-
 
98
	}
106
	}
99
	
107
	
100
	private String getProductURL(Entity entity)	{
108
	private String getProductURL(Entity entity)	{
101
 
109
 
102
		Category category = defContainer.getCategory(entity.getCategoryID());
110
		Category category = defContainer.getCategory(entity.getCategoryID());
103
		try {
111
		try {
104
			Category parentCategory = category.getParentCategory();
112
			Category parentCategory = category.getParentCategory();
105
			
113
			
106
			String url = "http://www.saholic.com/" + parentCategory.getLabel().toLowerCase().replace(' ', '-') + "/";
114
			String url = "/" + parentCategory.getLabel().toLowerCase().replace(' ', '-') + "/";
107
			String productUrl = ((entity.getBrand() != null) ? entity.getBrand().trim() + " " : "").toLowerCase().replace(' ', '-')
115
			String productUrl = ((entity.getBrand() != null) ? entity.getBrand().trim() + " " : "").toLowerCase().replace(' ', '-')
108
	        + "-" + ((entity.getModelName() != null) ? entity.getModelName().trim() + " " : "").toLowerCase().replace(' ', '-') 
116
	        + "-" + ((entity.getModelName() != null) ? entity.getModelName().trim() + " " : "").toLowerCase().replace(' ', '-') 
109
		    + "-" + ((entity.getModelNumber() != null ) ? entity.getModelNumber().trim() + " ": "" ).toLowerCase().replace(' ', '-')
117
		    + "-" + ((entity.getModelNumber() != null ) ? entity.getModelNumber().trim() + " ": "" ).toLowerCase().replace(' ', '-')
110
	        + "-" + entity.getID();
118
	        + "-" + entity.getID();
111
			productUrl = productUrl.replaceAll("/", "-");
119
			productUrl = productUrl.replaceAll("/", "-");