Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
584 chandransh 1
package in.shop2020.hotspot.dashbaord.server;
2
 
3
import in.shop2020.hotspot.dashbaord.shared.actions.Item;
4
import in.shop2020.model.v1.catalog.InventoryService;
5
import in.shop2020.thrift.clients.CatalogServiceClient;
6
 
7
import java.util.ArrayList;
8
import java.util.List;
9
 
10
public class CatalogUtils {
11
	public static List<Item> getAllItems(){
12
		List<Item> itemList = new ArrayList<Item>();
13
 
14
		try {
15
			CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
16
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
17
 
18
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
585 chandransh 19
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
20
				itemList.add(getItemFromThriftItem(thriftItem));
584 chandransh 21
		} catch (Exception e) {
585 chandransh 22
			// Not getting any items in the catalog is as good as not having any
23
			// items in the catalog.
584 chandransh 24
			e.printStackTrace();
25
		}
26
 
27
		return itemList;
28
	}
585 chandransh 29
 
30
	public static Item getItem(long itemId){
31
		try{
32
			CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
33
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
34
			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
35
			return getItemFromThriftItem(thriftItem);
36
		}catch(Exception e){
37
			// Oops! We didn't receive the details. We should let the user know
38
			// that the catalog service is currently unavailable.
39
			e.printStackTrace();
40
		}
41
		return null;
42
	}
43
 
44
	private static Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem){
45
		Item item = new Item(thriftItem.getId(),
46
				thriftItem.getManufacturerName(),
47
				thriftItem.getModelNumber(),
48
				thriftItem.getModelName(),
49
				thriftItem.getCategory(),
50
				thriftItem.getComments(),
51
				thriftItem.getCatalogItemId(),
52
				thriftItem.getVendorItemId(),
53
				thriftItem.getFeatureId(),
54
				thriftItem.getFeatureDescription(),
55
				//thriftItem.getItemInventory(),
56
				thriftItem.getMrp(),
57
				thriftItem.getMop(),
58
				thriftItem.getSellingPrice(),
59
				thriftItem.getWeight(),
60
				thriftItem.getAddedOn(),
61
				thriftItem.getStartDate(),
62
				thriftItem.getRetireDate(), 
63
				//thriftItem.getItemStatus(),
64
				thriftItem.getOtherInfo());
65
		return item;
66
	}
584 chandransh 67
}