Subversion Repositories SmartDukaan

Rev

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

Rev 3964 Rev 4143
Line 4... Line 4...
4
import in.shop2020.model.v1.catalog.Item;
4
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.utils.CategoryManager;
5
import in.shop2020.utils.CategoryManager;
6
 
6
 
7
import java.io.File;
7
import java.io.File;
8
import java.util.ArrayList;
8
import java.util.ArrayList;
-
 
9
import java.util.HashMap;
9
import java.util.List;
10
import java.util.List;
10
import java.util.Map;
11
import java.util.Map;
11
 
12
 
12
import org.apache.commons.lang.StringUtils;
13
import org.apache.commons.lang.StringUtils;
-
 
14
import org.json.JSONObject;
13
 
15
 
14
 
16
 
15
/**
17
/**
16
 * Command line utility to generate xml file for partners
18
 * Command line utility to generate xml file for partners
17
 * 
19
 * 
Line 97... Line 99...
97
		}
99
		}
98
		return true;
100
		return true;
99
	}
101
	}
100
	
102
	
101
	/**
103
	/**
-
 
104
	 * Checks whether a product is laptop or not
-
 
105
	 */
-
 
106
	private boolean isLaptop(Item item) {
-
 
107
		Category category = CategoryManager.getCategoryManager().getCategory(item.getCategory());
-
 
108
        long parentCategoryId = category.getParent_category_id();
-
 
109
        
-
 
110
        return category.getId() == Utils.LAPTOPS_CATEGORY ? true : false;
-
 
111
	}
-
 
112
	
-
 
113
	/**
102
	 * 
114
	 * 
103
	 * @param item
115
	 * @param item
104
	 * @return
116
	 * @return
105
	 */
117
	 */
106
	private String getProductTitle(Item item){
118
	private String getProductTitle(Item item){
Line 177... Line 189...
177
	 * get xml feed for partner sites
189
	 * get xml feed for partner sites
178
	 * @param irDataXMLSnippets
190
	 * @param irDataXMLSnippets
179
	 * @throws Exception
191
	 * @throws Exception
180
	 */
192
	 */
181
	private void getProductsJavascript(StringBuffer sb) throws Exception{
193
	private void getProductsJavascript(StringBuffer sb) throws Exception{
-
 
194
 
-
 
195
		Map<String, Long> mobilePhones = new HashMap<String, Long>();
182
		boolean isFirst = true;
196
		Map<String, Long> laptops = new HashMap<String, Long>();
183
		
197
		
184
		for(Long entityId: entityIdItemMap.keySet()){
198
		for(Long entityId: entityIdItemMap.keySet())	{
185
			List<Item> items = entityIdItemMap.get(entityId);
199
			Item item = entityIdItemMap.get(entityId).get(0);
186
			Item firstItem = items.get(0);
200
			
187
			if(!isMobile(firstItem)){
201
			if (isMobile(item))	{
188
				continue;
202
				mobilePhones.put(getProductTitle(item), entityId);
189
			}
203
			}
190
			String title = getProductTitle(firstItem);
-
 
191
			if(isFirst){
204
			else if (isLaptop(item))	{
192
				sb.append("\"" + title + "\":" + entityId);
-
 
193
				isFirst = false;
-
 
194
			}else{
-
 
195
				sb.append(",\"" + title + "\":" + entityId);
205
				laptops.put(getProductTitle(item), entityId);
196
			}
206
			}
197
		}
207
		}
-
 
208
		Map<String, Map<String, Long>> products = new HashMap<String, Map<String,Long>>();
-
 
209
		products.put("mobiles", mobilePhones);
-
 
210
		products.put("laptops", laptops);
-
 
211
		sb.append(new JSONObject(products));
198
	}
212
	}
199
	
213
	
200
	
214
	
201
	/**
215
	/**
202
	 * Generate the javascript list of all the active phones and store in a file
216
	 * Generate the javascript list of all the active phones and store in a file
203
	 * @throws Exception
217
	 * @throws Exception
204
	 */
218
	 */
205
	public void generateProductListJavascript() throws Exception {
219
	public void generateProductListJavascript() throws Exception {
206
		StringBuffer productsJavascript = new StringBuffer();
220
		StringBuffer productsJavascript = new StringBuffer();
207
		
221
		
208
		productsJavascript.append("var productIdNames={");
222
		productsJavascript.append("var productIdNames=");
209
		
223
		
210
		getProductsJavascript(productsJavascript);
224
		getProductsJavascript(productsJavascript);
211
		
225
		
212
		productsJavascript.append("};");
226
		productsJavascript.append(";");
213
		
227
		
214
		// Write it to file
228
		// Write it to file
215
		String productXMLFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "saholicmobilephones.js";
229
		String productXMLFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "saholicmobilephones.js";
216
		DBUtils.store(productsJavascript.toString(), productXMLFilename);
230
		DBUtils.store(productsJavascript.toString(), productXMLFilename);
217
	}
231
	}
218
 
-
 
219
}
232
}
220
233