Subversion Repositories SmartDukaan

Rev

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