Subversion Repositories SmartDukaan

Rev

Rev 5979 | Go to most recent revision | Details | Compare with Previous | 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;
5948 mandeep.dh 4
import in.shop2020.model.v1.catalog.CatalogService;
5
import in.shop2020.model.v1.inventory.InventoryService;
5945 mandeep.dh 6
import in.shop2020.model.v1.inventory.InventoryType;
7
import in.shop2020.model.v1.inventory.Warehouse;
3132 rajveer 8
import in.shop2020.thrift.clients.CatalogClient;
5948 mandeep.dh 9
import in.shop2020.thrift.clients.InventoryClient;
584 chandransh 10
 
11
import java.util.ArrayList;
4363 rajveer 12
import java.util.HashMap;
584 chandransh 13
import java.util.List;
4363 rajveer 14
import java.util.Map;
584 chandransh 15
 
892 chandransh 16
import com.google.gwt.core.client.GWT;
17
 
584 chandransh 18
public class CatalogUtils {
19
	public static List<Item> getAllItems(){
20
		List<Item> itemList = new ArrayList<Item>();
21
 
22
		try {
3132 rajveer 23
			CatalogClient catalogServiceClient = new CatalogClient();
5948 mandeep.dh 24
			CatalogService.Client catalogClient = catalogServiceClient.getClient();
584 chandransh 25
 
26
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
585 chandransh 27
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
28
				itemList.add(getItemFromThriftItem(thriftItem));
584 chandransh 29
		} catch (Exception e) {
585 chandransh 30
			// Not getting any items in the catalog is as good as not having any
31
			// items in the catalog.
584 chandransh 32
			e.printStackTrace();
33
		}
34
 
35
		return itemList;
36
	}
585 chandransh 37
 
597 chandransh 38
	public static List<Item> getBestDeals(){
39
		List<Item> itemList = new ArrayList<Item>();
40
 
41
		try {
3132 rajveer 42
			CatalogClient catalogServiceClient = new CatalogClient();
5948 mandeep.dh 43
			CatalogService.Client catalogClient = catalogServiceClient.getClient();
597 chandransh 44
 
45
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
46
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
47
				itemList.add(getItemFromThriftItem(thriftItem));
48
		} catch(Exception e){
49
			e.printStackTrace();
50
		}
51
 
52
		return itemList;
53
	}
54
 
55
	public static List<Item> getBestSellers(){
56
		List<Item> itemList = new ArrayList<Item>();
57
 
58
		try {
3132 rajveer 59
			CatalogClient catalogServiceClient = new CatalogClient();
5948 mandeep.dh 60
			CatalogService.Client catalogClient = catalogServiceClient.getClient();
597 chandransh 61
 
62
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
63
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
64
				itemList.add(getItemFromThriftItem(thriftItem));
65
		} catch(Exception e){
66
			e.printStackTrace();
67
		}
68
 
69
		return itemList;		
70
	}
71
 
72
	public static List<Item> getLatestArrivals(){
73
		List<Item> itemList = new ArrayList<Item>();
74
 
75
		try {
3132 rajveer 76
			CatalogClient catalogServiceClient = new CatalogClient();
5948 mandeep.dh 77
			CatalogService.Client catalogClient = catalogServiceClient.getClient();
597 chandransh 78
 
79
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
80
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
81
				itemList.add(getItemFromThriftItem(thriftItem));
82
		} catch(Exception e){
83
			e.printStackTrace();
84
		}
85
 
86
		return itemList;
87
	}
88
 
585 chandransh 89
	public static Item getItem(long itemId){
90
		try{
3132 rajveer 91
			CatalogClient catalogServiceClient = new CatalogClient();
5948 mandeep.dh 92
			CatalogService.Client catalogClient = catalogServiceClient.getClient();
585 chandransh 93
			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
94
			return getItemFromThriftItem(thriftItem);
95
		}catch(Exception e){
96
			// Oops! We didn't receive the details. We should let the user know
97
			// that the catalog service is currently unavailable.
98
			e.printStackTrace();
99
		}
100
		return null;
101
	}
102
 
5110 mandeep.dh 103
	public static Map<Long, String> getWarehousesForBillingWarehouse(long warehouseId){
4363 rajveer 104
		try{
5948 mandeep.dh 105
		    InventoryClient catalogServiceClient = new InventoryClient();
4363 rajveer 106
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
5110 mandeep.dh 107
			List<Warehouse> warehouses = catalogClient.getWarehouses(null, InventoryType.GOOD, 0, warehouseId, 0);
108
			Map<Long, String> warehouseMap = new HashMap<Long, String>();
109
			for(Warehouse warehouse: warehouses){
110
				warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
4363 rajveer 111
			}
5110 mandeep.dh 112
			return warehouseMap;
4363 rajveer 113
		}catch(Exception e){
114
			// TODO: Oops! We couldn't reduce the item reservation count. This will
115
			// result in underestimation of inventory stock. Should be corrected
116
			// periodically.
117
			e.printStackTrace();
118
		}
119
		return null;
120
	}
19225 manish.sha 121
 
122
	public static Map<Long, Warehouse> getAllWarehousesForBillingWarehouse(long warehouseId){
123
		try{
124
		    InventoryClient catalogServiceClient = new InventoryClient();
125
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
126
			List<Warehouse> warehouses = catalogClient.getWarehouses(null, InventoryType.GOOD, 0, warehouseId, 0);
127
			Map<Long, Warehouse> warehouseMap = new HashMap<Long, Warehouse>();
128
			for(Warehouse warehouse: warehouses){
129
				warehouseMap.put(warehouse.getId(), warehouse);
130
			}
131
			return warehouseMap;
132
		}catch(Exception e){
133
			// TODO: Oops! We couldn't reduce the item reservation count. This will
134
			// result in underestimation of inventory stock. Should be corrected
135
			// periodically.
136
			e.printStackTrace();
137
		}
138
		return null;
139
	}
4363 rajveer 140
 
5684 mandeep.dh 141
    public static Warehouse getWarehouse(long warehouseId) {
142
        try{
5948 mandeep.dh 143
            InventoryClient catalogServiceClient = new InventoryClient();
5684 mandeep.dh 144
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
145
            return catalogClient.getWarehouse(warehouseId);
146
        }catch(Exception e){
147
            e.printStackTrace();
148
        }
149
        return null;
150
    }
151
 
152
    private static Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem){
585 chandransh 153
		Item item = new Item(thriftItem.getId(),
960 chandransh 154
				thriftItem.getProductGroup(),
155
				thriftItem.getBrand(),
585 chandransh 156
				thriftItem.getModelNumber(),
157
				thriftItem.getModelName(),
608 chandransh 158
				thriftItem.getColor(),
585 chandransh 159
				thriftItem.getCategory(),
160
				thriftItem.getComments(),
161
				thriftItem.getCatalogItemId(),
162
				thriftItem.getFeatureId(),
163
				thriftItem.getFeatureDescription(),
164
				//thriftItem.getItemInventory(),
165
				thriftItem.getMrp(),
4779 mandeep.dh 166
				//thriftItem.getMop(),
585 chandransh 167
				thriftItem.getSellingPrice(),
4779 mandeep.dh 168
				//thriftItem.getDealerPrice(),
585 chandransh 169
				thriftItem.getWeight(),
170
				thriftItem.getAddedOn(),
171
				thriftItem.getStartDate(),
608 chandransh 172
				thriftItem.getRetireDate(),
173
				thriftItem.getUpdatedOn(),
585 chandransh 174
				//thriftItem.getItemStatus(),
608 chandransh 175
				thriftItem.getBestDealText(),
176
				thriftItem.getBestDealValue());
585 chandransh 177
		return item;
178
	}
584 chandransh 179
}