Subversion Repositories SmartDukaan

Rev

Rev 1962 | Rev 2027 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1962 Rev 1992
Line 1... Line 1...
1
package in.shop2020.catalog.dashboard.server;
1
package in.shop2020.catalog.dashboard.server;
2
 
2
 
3
import in.shop2020.catalog.dashboard.client.CatalogService;
3
import in.shop2020.catalog.dashboard.client.CatalogService;
4
import in.shop2020.catalog.dashboard.shared.Item;
4
import in.shop2020.catalog.dashboard.shared.Item;
5
import in.shop2020.model.v1.catalog.InventoryService;
5
import in.shop2020.model.v1.catalog.InventoryService;
-
 
6
import in.shop2020.model.v1.catalog.VendorItemPricing;
6
import in.shop2020.thrift.clients.CatalogServiceClient;
7
import in.shop2020.thrift.clients.CatalogServiceClient;
7
 
8
 
8
import java.util.ArrayList;
9
import java.util.ArrayList;
-
 
10
import java.util.HashMap;
9
import java.util.List;
11
import java.util.List;
-
 
12
import java.util.Map;
-
 
13
import java.util.Map.Entry;
10
 
14
 
11
import com.google.gwt.core.client.GWT;
15
import com.google.gwt.core.client.GWT;
12
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
16
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
13
 
17
 
14
@SuppressWarnings("serial")
18
@SuppressWarnings("serial")
Line 20... Line 24...
20
        try {
24
        try {
21
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
25
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
22
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
26
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
23
            
27
            
24
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
28
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
-
 
29
            
25
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
30
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
-
 
31
                List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
26
                itemList.add(getItemFromThriftItem(thriftItem));
32
                itemList.add(getItemFromThriftItem(thriftItem, vip));
-
 
33
            }
27
        } catch (Exception e) {
34
        } catch (Exception e) {
28
            e.printStackTrace();
35
            e.printStackTrace();
29
        }
36
        }
30
        
37
        
31
        return itemList;
38
        return itemList;
Line 37... Line 44...
37
        try {
44
        try {
38
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
45
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
39
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
46
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
40
            
47
            
41
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
48
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
42
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
49
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
-
 
50
                List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
43
                itemList.add(getItemFromThriftItem(thriftItem));
51
                itemList.add(getItemFromThriftItem(thriftItem, vip));
-
 
52
            }
44
        } catch(Exception e){
53
        } catch(Exception e){
45
            e.printStackTrace();
54
            e.printStackTrace();
46
        }
55
        }
47
        
56
        
48
        return itemList;
57
        return itemList;
Line 54... Line 63...
54
        try {
63
        try {
55
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
64
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
56
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
65
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
57
            
66
            
58
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
67
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
59
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
68
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
-
 
69
                List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
60
                itemList.add(getItemFromThriftItem(thriftItem));
70
                itemList.add(getItemFromThriftItem(thriftItem, vip));
-
 
71
            }
61
        } catch(Exception e){
72
        } catch(Exception e){
62
            e.printStackTrace();
73
            e.printStackTrace();
63
        }
74
        }
64
        
75
        
65
        return itemList;        
76
        return itemList;        
Line 71... Line 82...
71
        try {
82
        try {
72
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
83
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
73
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
84
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
74
            
85
            
75
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
86
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
76
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
87
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
-
 
88
                List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
77
                itemList.add(getItemFromThriftItem(thriftItem));
89
                itemList.add(getItemFromThriftItem(thriftItem, vip));
-
 
90
            }
78
        } catch(Exception e){
91
        } catch(Exception e){
79
            e.printStackTrace();
92
            e.printStackTrace();
80
        }
93
        }
81
        
94
        
82
        return itemList;
95
        return itemList;
Line 85... Line 98...
85
    public Item getItem(long itemId){
98
    public Item getItem(long itemId){
86
        try{
99
        try{
87
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
100
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
88
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
101
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
89
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
102
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
-
 
103
            
-
 
104
            List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
90
            return getItemFromThriftItem(thriftItem);
105
            return getItemFromThriftItem(thriftItem, vip);
91
        }catch(Exception e){
106
        }catch(Exception e){
92
            // Oops! We didn't receive the details. We should let the user know
107
            // Oops! We didn't receive the details. We should let the user know
93
            // that the catalog service is currently unavailable.
108
            // that the catalog service is currently unavailable.
94
            e.printStackTrace();
109
            e.printStackTrace();
95
        }
110
        }
Line 108... Line 123...
108
            // periodically.
123
            // periodically.
109
            e.printStackTrace();
124
            e.printStackTrace();
110
        }
125
        }
111
    }
126
    }
112
    
127
    
113
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem){
128
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, List<in.shop2020.model.v1.catalog.VendorItemPricing> thriftItemPricings){
-
 
129
        
-
 
130
        Map<Long, double[]> vendorPricings = new HashMap<Long, double[]>();
-
 
131
        double[] prices;
-
 
132
        if(thriftItemPricings != null) {
-
 
133
            for(VendorItemPricing v : thriftItemPricings) {
-
 
134
                prices = new double[3];
-
 
135
                prices[0] = v.getMop();
-
 
136
                prices[1] = v.getDealerPrice();
-
 
137
                prices[2] = v.getTransferPrice();
-
 
138
                vendorPricings.put(v.getVendorId(), prices);
-
 
139
            }
-
 
140
        }
-
 
141
        
114
        Item item = new Item(thriftItem.getId(),
142
        Item item = new Item(thriftItem.getId(),
115
                thriftItem.getProductGroup(),
143
                thriftItem.getProductGroup(),
116
                thriftItem.getBrand(),
144
                thriftItem.getBrand(),
117
                thriftItem.getModelNumber(),
145
                thriftItem.getModelNumber(),
118
                thriftItem.getModelName(),
146
                thriftItem.getModelName(),
Line 120... Line 148...
120
                thriftItem.getCategory(),
148
                thriftItem.getCategory(),
121
                thriftItem.getComments(),
149
                thriftItem.getComments(),
122
                thriftItem.getCatalogItemId(),
150
                thriftItem.getCatalogItemId(),
123
                thriftItem.getFeatureId(),
151
                thriftItem.getFeatureId(),
124
                thriftItem.getFeatureDescription(),
152
                thriftItem.getFeatureDescription(),
125
                //thriftItem.getItemInventory(),
-
 
126
                thriftItem.getMrp(),
153
                thriftItem.getMrp(),
127
                thriftItem.getMop(),
154
                thriftItem.getMop(),
128
                thriftItem.getSellingPrice(),
155
                thriftItem.getSellingPrice(),
129
                thriftItem.getDealerPrice(),
156
                thriftItem.getDealerPrice(),
130
                thriftItem.getWeight(),
157
                thriftItem.getWeight(),
131
                thriftItem.getAddedOn(),
158
                thriftItem.getAddedOn(),
132
                thriftItem.getStartDate(),
159
                thriftItem.getStartDate(),
133
                thriftItem.getRetireDate(),
160
                thriftItem.getRetireDate(),
134
                thriftItem.getUpdatedOn(),
161
                thriftItem.getUpdatedOn(),
135
                //thriftItem.getItemStatus(),
162
                thriftItem.getItemStatus().name(),
136
                thriftItem.getOtherInfo(),
163
                thriftItem.getOtherInfo(),
137
                thriftItem.getBestDealText(),
164
                thriftItem.getBestDealText(),
138
                thriftItem.getBestDealValue());
165
                thriftItem.getBestDealValue(),
-
 
166
                (thriftItem.getItemInventory() != null ? thriftItem.getItemInventory().getAvailability() : null),
-
 
167
                vendorPricings
-
 
168
                );
-
 
169
 
-
 
170
        
139
        return item;
171
        return item;
140
    }
172
    }
141
 
173
 
142
    @Override
174
    @Override
143
    public void updatePrice(long itemId, double sellingPrice) {
175
    public boolean updateItem(Item item) {
144
        GWT.log("Got a call to update price of " + itemId + ", selling price " + sellingPrice);
176
        GWT.log("Got a call to update item, Item Id: " + item.getId());
145
        try{
177
        try{
146
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
178
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
147
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
179
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
-
 
180
            
-
 
181
            in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
-
 
182
//            tItem.setAddedOn(item.getAddedOn());
-
 
183
//            tItem.setBestDealText(item.getBestDealsText());
-
 
184
//            tItem.setBrand(item.getBrand());
-
 
185
//            tItem.setCatalogItemId(item.getCatalogItemId());
-
 
186
//            tItem.setCategory(item.getCategory());
-
 
187
//            tItem.setColor(item.getColor());
-
 
188
//            tItem.setComments(item.getComments());
-
 
189
//            tItem.setDealerPrice(item.getDealerPrice()); 
-
 
190
//            tItem.setFeatureId(item.getFeatureId());
-
 
191
//            tItem.setFeatureDescription(item.getFeatureDescription());
-
 
192
//            tItem.setModelName(item.getModelName());
-
 
193
//            tItem.setModelNumber(item.getModelNumber());
-
 
194
            
-
 
195
            tItem.setMrp(item.getMrp());
-
 
196
//            tItem.setMop(item.getMop());
-
 
197
            tItem.setSellingPrice(item.getSellingPrice());
-
 
198
//            tItem.setTransferPrice(item.getTransferPrice());
-
 
199
            tItem.setWeight(item.getWeight());
-
 
200
            
-
 
201
            VendorItemPricing vip = new VendorItemPricing();
-
 
202
            for(Entry<Long, double[]> vendorItemPricing : item.getVendorPricings().entrySet()) {
-
 
203
                vip.setItemId(item.getId());
-
 
204
                vip.setVendorId(vendorItemPricing.getKey());
-
 
205
                vip.setMop(vendorItemPricing.getValue()[Item.INDEX_MOP]);
-
 
206
                vip.setDealerPrice(vendorItemPricing.getValue()[Item.INDEX_DP]);
-
 
207
                vip.setTransferPrice(vendorItemPricing.getValue()[Item.INDEX_TP]);
148
            //TODO: Implement update price method in service
208
                catalogClient.updateVendorItemPricing(vip);
-
 
209
            }
-
 
210
            
-
 
211
            if(catalogClient.updateItem(tItem) == item.getId());
-
 
212
                return true;
-
 
213
            //TODO: update left out fields of item also. Also update vendor prices and availability.
-
 
214
            
149
        }catch(Exception e){
215
        }catch(Exception e){
150
            e.printStackTrace();
216
            e.printStackTrace();
151
        }
217
        }
-
 
218
        return false;
152
    }
219
    }
153
}
220
}