Subversion Repositories SmartDukaan

Rev

Rev 5945 | 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
 
892 chandransh 103
	public static void reduceReservationCount(long itemId, long warehouseId, double quantity){
104
		GWT.log("Got a call to reduce the reservation count for item " + itemId + " and warehouse " + warehouseId);
105
		try{
5948 mandeep.dh 106
			InventoryClient catalogServiceClient = new InventoryClient();
892 chandransh 107
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
108
			catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
109
		}catch(Exception e){
110
			// TODO: Oops! We couldn't reduce the item reservation count. This will
111
			// result in underestimation of inventory stock. Should be corrected
112
			// periodically.
113
			e.printStackTrace();
114
		}
115
	}
116
 
4363 rajveer 117
 
5110 mandeep.dh 118
	public static Map<Long, String> getWarehousesForBillingWarehouse(long warehouseId){
4363 rajveer 119
		try{
5948 mandeep.dh 120
		    InventoryClient catalogServiceClient = new InventoryClient();
4363 rajveer 121
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
5110 mandeep.dh 122
			List<Warehouse> warehouses = catalogClient.getWarehouses(null, InventoryType.GOOD, 0, warehouseId, 0);
123
			Map<Long, String> warehouseMap = new HashMap<Long, String>();
124
			for(Warehouse warehouse: warehouses){
125
				warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
4363 rajveer 126
			}
5110 mandeep.dh 127
			return warehouseMap;
4363 rajveer 128
		}catch(Exception e){
129
			// TODO: Oops! We couldn't reduce the item reservation count. This will
130
			// result in underestimation of inventory stock. Should be corrected
131
			// periodically.
132
			e.printStackTrace();
133
		}
134
		return null;
135
	}
136
 
5684 mandeep.dh 137
    public static Warehouse getWarehouse(long warehouseId) {
138
        try{
5948 mandeep.dh 139
            InventoryClient catalogServiceClient = new InventoryClient();
5684 mandeep.dh 140
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
141
            return catalogClient.getWarehouse(warehouseId);
142
        }catch(Exception e){
143
            e.printStackTrace();
144
        }
145
        return null;
146
    }
147
 
148
    private static Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem){
585 chandransh 149
		Item item = new Item(thriftItem.getId(),
960 chandransh 150
				thriftItem.getProductGroup(),
151
				thriftItem.getBrand(),
585 chandransh 152
				thriftItem.getModelNumber(),
153
				thriftItem.getModelName(),
608 chandransh 154
				thriftItem.getColor(),
585 chandransh 155
				thriftItem.getCategory(),
156
				thriftItem.getComments(),
157
				thriftItem.getCatalogItemId(),
158
				thriftItem.getFeatureId(),
159
				thriftItem.getFeatureDescription(),
160
				//thriftItem.getItemInventory(),
161
				thriftItem.getMrp(),
4779 mandeep.dh 162
				//thriftItem.getMop(),
585 chandransh 163
				thriftItem.getSellingPrice(),
4779 mandeep.dh 164
				//thriftItem.getDealerPrice(),
585 chandransh 165
				thriftItem.getWeight(),
166
				thriftItem.getAddedOn(),
167
				thriftItem.getStartDate(),
608 chandransh 168
				thriftItem.getRetireDate(),
169
				thriftItem.getUpdatedOn(),
585 chandransh 170
				//thriftItem.getItemStatus(),
608 chandransh 171
				thriftItem.getBestDealText(),
172
				thriftItem.getBestDealValue());
585 chandransh 173
		return item;
174
	}
584 chandransh 175
}