Subversion Repositories SmartDukaan

Rev

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

Rev 4754 Rev 4846
Line 1... Line 1...
1
package in.shop2020.inventory.controllers;
1
package in.shop2020.inventory.controllers;
2
 
2
 
-
 
3
import in.shop2020.generic.ExceptionType;
3
import in.shop2020.model.v1.catalog.InventoryServiceException;
4
import in.shop2020.model.v1.catalog.InventoryServiceException;
-
 
5
import in.shop2020.model.v1.catalog.Item;
4
import in.shop2020.purchase.PurchaseServiceException;
6
import in.shop2020.purchase.PurchaseServiceException;
5
import in.shop2020.thrift.clients.CatalogClient;
7
import in.shop2020.thrift.clients.CatalogClient;
6
import in.shop2020.thrift.clients.PurchaseClient;
8
import in.shop2020.thrift.clients.PurchaseClient;
7
import in.shop2020.thrift.clients.WarehouseClient;
9
import in.shop2020.thrift.clients.WarehouseClient;
-
 
10
import in.shop2020.utils.ModelUtils;
8
import in.shop2020.warehouse.InventoryItem;
11
import in.shop2020.warehouse.InventoryItem;
9
import in.shop2020.warehouse.ScanType;
12
import in.shop2020.warehouse.ScanType;
10
import in.shop2020.warehouse.WarehouseService.Client;
13
import in.shop2020.warehouse.WarehouseService.Client;
11
import in.shop2020.warehouse.WarehouseServiceException;
14
import in.shop2020.warehouse.WarehouseServiceException;
12
 
15
 
-
 
16
import java.util.ArrayList;
-
 
17
import java.util.List;
-
 
18
 
13
import javax.servlet.ServletContext;
19
import javax.servlet.ServletContext;
14
 
20
 
15
import org.apache.struts2.convention.annotation.Result;
21
import org.apache.struts2.convention.annotation.Result;
16
import org.apache.struts2.convention.annotation.Results;
22
import org.apache.struts2.convention.annotation.Results;
17
import org.apache.thrift.TException;
23
import org.apache.thrift.TException;
Line 30... Line 36...
30
    private ServletContext context;
36
    private ServletContext context;
31
    private String id;
37
    private String id;
32
    private String itemId;
38
    private String itemId;
33
    private String itemNo;
39
    private String itemNo;
34
    private String errorMsg = "";
40
    private String errorMsg = "";
-
 
41
    private List<Item> items;
35
 
42
 
36
    private String purchaseOrderId;
43
    private String purchaseOrderId;
37
 
44
 
38
    public String editNew() {
45
    public String editNew() {
39
        purchaseOrderId = request.getParameter("poId");
46
        purchaseOrderId = request.getParameter("poId");
Line 83... Line 90...
83
        String imeiNumber = request.getParameter("imeiNo");
90
        String imeiNumber = request.getParameter("imeiNo");
84
 
91
 
85
        try {
92
        try {
86
            WarehouseClient warehouseClient = new WarehouseClient();
93
            WarehouseClient warehouseClient = new WarehouseClient();
87
            Client client = warehouseClient.getClient();
94
            Client client = warehouseClient.getClient();
88
            InventoryItem inventoryItem = client
95
            InventoryItem inventoryItem = null;
-
 
96
            if (itemId != null) {
89
                    .createSerializedInventoryItemFromItemNumber(itemNumber,
97
                inventoryItem = client.createSerializedInventoryItem(Long.parseLong(itemId), itemNumber, imeiNumber, id);
-
 
98
            }
90
                            imeiNumber, id);
99
            else {
-
 
100
                inventoryItem = client.createSerializedInventoryItemFromItemNumber(itemNumber, imeiNumber, id);
-
 
101
            }
-
 
102
 
91
            client.scanSerializedItem(inventoryItem.getId(), ScanType.PURCHASE,
103
            client.scanSerializedItem(inventoryItem.getId(), ScanType.PURCHASE,
92
                    PurchaseOrderController.WAREHOUSE_ID);
104
                    PurchaseOrderController.WAREHOUSE_ID);
93
            in.shop2020.model.v1.catalog.InventoryService.Client catalaogClient = new CatalogClient()
105
            in.shop2020.model.v1.catalog.InventoryService.Client catalaogClient = new CatalogClient()
94
                    .getClient();
106
                    .getClient();
95
            catalaogClient.addInventory(inventoryItem.getItemId(), PurchaseOrderController.WAREHOUSE_ID,
107
            catalaogClient.addInventory(inventoryItem.getItemId(), PurchaseOrderController.WAREHOUSE_ID,
Line 98... Line 110...
98
            errorMsg = "Error while establishing connection to the warehouse server";
110
            errorMsg = "Error while establishing connection to the warehouse server";
99
            logger.error(errorMsg, e);
111
            logger.error(errorMsg, e);
100
        } catch (WarehouseServiceException e) {
112
        } catch (WarehouseServiceException e) {
101
            errorMsg = e.getMessage();
113
            errorMsg = e.getMessage();
102
            logger.error(errorMsg, e);
114
            logger.error(errorMsg, e);
-
 
115
            if (ExceptionType.MULTIPLE_ITEMS_FOUND.equals(e.getExceptionType())) {
-
 
116
                try {
-
 
117
                    items = new ArrayList<Item>();
-
 
118
                    in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = new CatalogClient().getClient();
-
 
119
                    for (String itemId : e.getMessage().split(",")) {
-
 
120
                        items.add(catalogClient.getItem(Long.parseLong(itemId)));
-
 
121
                    }
-
 
122
                }
-
 
123
                catch(Exception e1) {
-
 
124
                    logger.error("Could not lookup items: " + e.getMessage(), e1);
-
 
125
                }
-
 
126
                errorMsg = "Multiple items found for Item number: " + itemNumber + ". Please select appropriate item.";
-
 
127
            }
103
        } catch (TException e) {
128
        } catch (TException e) {
104
            errorMsg = "Error while scanning in the item";
129
            errorMsg = "Error while scanning in the item";
105
            logger.error(errorMsg, e);
130
            logger.error(errorMsg, e);
106
        } catch (InventoryServiceException e) {
131
        } catch (InventoryServiceException e) {
107
            errorMsg = "Error while incresing item's inventory availability";
132
            errorMsg = "Error while incresing item's inventory availability";
108
            logger.error(errorMsg, e);
133
            logger.error(errorMsg, e);
109
        }
134
        }
110
        if (!errorMsg.isEmpty()) {
135
        if (!errorMsg.isEmpty()) {
111
            addActionError(errorMsg);
136
            addActionError(errorMsg);
112
        }
137
        }
-
 
138
 
113
        return "show";
139
        return "show";
114
    }
140
    }
115
 
141
 
116
    public String destroy() {
142
    public String destroy() {
117
        long id = Long.parseLong(this.id);
143
        long id = Long.parseLong(this.id);
Line 147... Line 173...
147
        }
173
        }
148
 
174
 
149
        return show();
175
        return show();
150
    }
176
    }
151
 
177
 
-
 
178
    public String getName(Item item){
-
 
179
        return ModelUtils.extractProductNameFromItem(item);
-
 
180
    }
-
 
181
 
152
    public void setId(String id) {
182
    public void setId(String id) {
153
        this.id = id;
183
        this.id = id;
154
    }
184
    }
155
 
185
 
156
    public String getId() {
186
    public String getId() {
Line 183... Line 213...
183
 
213
 
184
    public void setItemNo(String itemNo) {
214
    public void setItemNo(String itemNo) {
185
        this.itemNo = itemNo;
215
        this.itemNo = itemNo;
186
    }
216
    }
187
 
217
 
-
 
218
    public List<Item> getItems() {
-
 
219
        return items;
-
 
220
    }
-
 
221
 
-
 
222
    public void setItems(List<Item> items) {
-
 
223
        this.items = items;
-
 
224
    }
-
 
225
 
188
}
226
}