Subversion Repositories SmartDukaan

Rev

Rev 595 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 595 Rev 637
Line 1... Line 1...
1
package in.shop2020.serving.utils;
1
package in.shop2020.serving.utils;
2
 
2
 
-
 
3
import java.io.ByteArrayInputStream;
-
 
4
import java.io.ByteArrayOutputStream;
-
 
5
import java.io.File;
-
 
6
import java.io.FileInputStream;
-
 
7
import java.io.FileOutputStream;
-
 
8
import java.io.ObjectInputStream;
-
 
9
import java.io.ObjectOutputStream;
3
import java.util.ArrayList;
10
import java.util.ArrayList;
4
import java.util.Calendar;
11
import java.util.Calendar;
5
import java.util.Date;
12
import java.util.Date;
6
import java.util.HashMap;
13
import java.util.HashMap;
7
import java.util.Iterator;
14
import java.util.Iterator;
Line 27... Line 34...
27
import in.shop2020.thrift.clients.WidgetServiceClient;
34
import in.shop2020.thrift.clients.WidgetServiceClient;
28
 
35
 
29
import org.apache.thrift.TException;
36
import org.apache.thrift.TException;
30
 
37
 
31
public class Utils {
38
public class Utils {
-
 
39
	public static final String EXPORT_ENTITIES_PATH =	"/var/lib/tomcat6/webapps/export/html/entities/";
32
	/*
40
	/*
33
	private static UserContextServiceClient userContextServiceClient;
41
	private static UserContextServiceClient userContextServiceClient;
34
	private static ShoppingCartClient shoppingCartClient;
42
	private static ShoppingCartClient shoppingCartClient;
35
	private static CatalogServiceClient catalogServiceClient;
43
	private static CatalogServiceClient catalogServiceClient;
36
	private static WidgetServiceClient widgetServiceClient;
44
	private static WidgetServiceClient widgetServiceClient;
Line 260... Line 268...
260
		
268
		
261
			List<Line> lineItems = cart.getLines(); 
269
			List<Line> lineItems = cart.getLines(); 
262
		
270
		
263
			for (Line line : lineItems) {
271
			for (Line line : lineItems) {
264
				long productId = line.getItemId();
272
				long productId = line.getItemId();
265
				totalAmount =  totalAmount + line.getQuantity() * Utils.getItemPriceByCatalogId(productId);
273
				totalAmount =  totalAmount + line.getQuantity() * Utils.getItemPrice(productId);
266
			}
274
			}
267
 
275
 
268
		} catch (ShoppingCartException e) {
276
		} catch (ShoppingCartException e) {
269
			e.printStackTrace();
277
			e.printStackTrace();
270
		} catch (TException e) {
278
		} catch (TException e) {
Line 274... Line 282...
274
		}
282
		}
275
 
283
 
276
		return totalAmount;
284
		return totalAmount;
277
	}
285
	}
278
	
286
	
279
	public static double getItemPriceByCatalogId(long productId){
287
	public static double getItemPrice(long itemId){
280
		CatalogServiceClient catalogServiceClient = null;
288
		CatalogServiceClient catalogServiceClient = null;
281
		Client client = null;
289
		Client client = null;
282
		Double itemPrice = 0.0;
290
		Double itemPrice = 0.0;
283
		try {
291
		try {
284
			catalogServiceClient = new CatalogServiceClient();
292
			catalogServiceClient = new CatalogServiceClient();
285
			client = catalogServiceClient.getClient();
293
			client = catalogServiceClient.getClient();
286
			Item item = client.getItemByCatalogId(productId);
294
			Item item = client.getItem(itemId);
287
			itemPrice = item.getSellingPrice();
295
			itemPrice = item.getSellingPrice();
288
			
296
			
289
		}
297
		}
290
		catch(Exception e){
298
		catch(Exception e){
291
			e.printStackTrace();
299
			e.printStackTrace();
Line 369... Line 377...
369
			e.printStackTrace();
377
			e.printStackTrace();
370
		}
378
		}
371
		
379
		
372
	}
380
	}
373
	
381
	
-
 
382
	public static void storeCategories(Object obj) throws Exception {
-
 
383
	
-
 
384
		ByteArrayOutputStream bStream = new ByteArrayOutputStream();
-
 
385
		ObjectOutputStream oStream = new ObjectOutputStream( bStream );
-
 
386
		oStream.writeObject ( obj );
-
 
387
		
-
 
388
		byte[] byteVal = bStream. toByteArray();
-
 
389
		
-
 
390
		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
391
		Client client = catalogServiceClient.getClient();
-
 
392
		
-
 
393
		client.putCategoryObject(byteVal);
-
 
394
	}
-
 
395
	
-
 
396
	public static Object getCategories() throws Exception {
-
 
397
		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
398
		Client client = catalogServiceClient.getClient();
-
 
399
		
-
 
400
		byte[] byteVal  = client.getCategoryObject();
-
 
401
		
-
 
402
		Object obj = null;
-
 
403
		ObjectInputStream in = null;
-
 
404
		try {
-
 
405
			ByteArrayInputStream bStream = new ByteArrayInputStream(byteVal);
-
 
406
			in = new ObjectInputStream(bStream);
-
 
407
			obj = in.readObject();
-
 
408
		}
-
 
409
		finally {
-
 
410
			if(in != null) {
-
 
411
				in.close();
-
 
412
			}
-
 
413
		}
-
 
414
		return obj;
-
 
415
	}
-
 
416
/*	
-
 
417
	public static void main(String args[]) throws Exception{
-
 
418
		// to store categories
-
 
419
		Map<Long, Category> categories = new HashMap<Long, Category>();
-
 
420
		Map<Long, in.shop2020.metamodel.definitions.Category> cmsCategories = Catalog.getInstance().getDefinitionsContainer().getCategories();
-
 
421
		for(in.shop2020.metamodel.definitions.Category cmsCategory: cmsCategories.values()){
-
 
422
			Category category = new Category(cmsCategory.getID());
-
 
423
			category.setLabel(cmsCategory.getLabel());
-
 
424
			if(cmsCategory.getParentCategory()!=null){
-
 
425
				category.setParentCategoryId(cmsCategory.getParentCategory().getID());
-
 
426
			}
-
 
427
			if(cmsCategory.getChildrenCategory()!=null){
-
 
428
				for(in.shop2020.metamodel.definitions.Category childCategory: cmsCategory.getChildrenCategory()){
-
 
429
					category.addChild(childCategory.getID());
-
 
430
				}
-
 
431
			}
-
 
432
			categories.put(cmsCategory.getID(), category);
-
 
433
		}
-
 
434
		Utils.storeCategories(categories);
-
 
435
		// to get categories
-
 
436
		Map<Long, Category> categories = (Map<Long, Category>)Utils.getCategories();
-
 
437
		System.out.println("hello");
-
 
438
	}
-
 
439
	*/
374
}
440
}
375
	
441
	
376
442