| 167 |
ashish |
1 |
package in.shop2020.hotspot.dashbaord.server.handler;
|
|
|
2 |
|
| 5110 |
mandeep.dh |
3 |
import in.shop2020.hotspot.dashbaord.server.CatalogUtils;
|
|
|
4 |
import in.shop2020.hotspot.dashbaord.server.LogisticsUtils;
|
| 167 |
ashish |
5 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthRequest;
|
|
|
6 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse;
|
| 345 |
ashish |
7 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse.NEXT;
|
| 2843 |
chandransh |
8 |
import in.shop2020.hotspot.dashbaord.shared.actions.BillingType;
|
| 2835 |
chandransh |
9 |
import in.shop2020.hotspot.dashbaord.shared.actions.UserType;
|
| 5945 |
mandeep.dh |
10 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 3132 |
rajveer |
11 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
12 |
import in.shop2020.thrift.clients.HelperClient;
|
| 2449 |
chandransh |
13 |
import in.shop2020.utils.DashboardUser;
|
| 493 |
rajveer |
14 |
import in.shop2020.utils.HelperService.Client;
|
|
|
15 |
import in.shop2020.utils.HelperServiceException;
|
| 5110 |
mandeep.dh |
16 |
|
|
|
17 |
import java.util.Map;
|
|
|
18 |
|
| 167 |
ashish |
19 |
import net.customware.gwt.dispatch.server.ActionHandler;
|
|
|
20 |
import net.customware.gwt.dispatch.server.ExecutionContext;
|
|
|
21 |
import net.customware.gwt.dispatch.shared.ActionException;
|
|
|
22 |
|
| 5110 |
mandeep.dh |
23 |
import org.apache.thrift.TException;
|
|
|
24 |
|
| 167 |
ashish |
25 |
public class AuthHandler implements ActionHandler<AuthRequest, AuthResponse>{
|
|
|
26 |
|
|
|
27 |
@Override
|
| 2449 |
chandransh |
28 |
public AuthResponse execute(AuthRequest request, ExecutionContext response) throws ActionException {
|
| 167 |
ashish |
29 |
String userName = request.getUsername();
|
| 493 |
rajveer |
30 |
String password = request.getPassword();
|
|
|
31 |
|
| 2449 |
chandransh |
32 |
boolean status = false;
|
|
|
33 |
long warehouseId = -1;
|
| 2843 |
chandransh |
34 |
UserType userType = UserType.WAREHOUSE_EXECUTIVE;
|
|
|
35 |
BillingType billingType = BillingType.EXTERNAL;
|
| 5110 |
mandeep.dh |
36 |
Map<Long, String> warehouses = null;
|
| 4603 |
rajveer |
37 |
Map<Long, String> providers = null;
|
| 5769 |
rajveer |
38 |
Map<Long, String> stores = null;
|
| 2449 |
chandransh |
39 |
NEXT nextScreen = null;
|
|
|
40 |
String message = null;
|
| 493 |
rajveer |
41 |
|
|
|
42 |
try {
|
| 3132 |
rajveer |
43 |
HelperClient hsc = new HelperClient();
|
| 2843 |
chandransh |
44 |
Client client = hsc.getClient();
|
|
|
45 |
DashboardUser dashboardUser = client.authenticateDashboardUser(userName, password);
|
|
|
46 |
switch (dashboardUser.getRole()) {
|
|
|
47 |
case ADMIN:
|
|
|
48 |
userType = UserType.ADMIN;
|
|
|
49 |
break;
|
| 4361 |
rajveer |
50 |
case WAREHOUSE_MONITOR:
|
|
|
51 |
userType = UserType.WAREHOUSE_MONITOR;
|
|
|
52 |
break;
|
| 2843 |
chandransh |
53 |
default:
|
|
|
54 |
userType = UserType.WAREHOUSE_EXECUTIVE;
|
|
|
55 |
}
|
| 2449 |
chandransh |
56 |
status = true;
|
|
|
57 |
nextScreen = NEXT.INBOX;
|
| 2843 |
chandransh |
58 |
|
| 2449 |
chandransh |
59 |
warehouseId = dashboardUser.getWarehouseId();
|
| 3132 |
rajveer |
60 |
CatalogClient csc = new CatalogClient();
|
| 5945 |
mandeep.dh |
61 |
in.shop2020.model.v1.catalog.CatalogService.Client iClient = csc.getClient();
|
| 2843 |
chandransh |
62 |
Warehouse warehouse = iClient.getWarehouse(warehouseId);
|
|
|
63 |
switch(warehouse.getBillingType()){
|
|
|
64 |
case OURS:
|
|
|
65 |
billingType = BillingType.OURS;
|
| 2835 |
chandransh |
66 |
break;
|
| 2843 |
chandransh |
67 |
case EXTERNAL:
|
|
|
68 |
billingType = BillingType.EXTERNAL;
|
| 2835 |
chandransh |
69 |
break;
|
|
|
70 |
default:
|
| 2843 |
chandransh |
71 |
billingType = BillingType.EXTERNAL;
|
| 2835 |
chandransh |
72 |
}
|
| 2843 |
chandransh |
73 |
|
| 5110 |
mandeep.dh |
74 |
warehouses = CatalogUtils.getWarehousesForBillingWarehouse(warehouseId);
|
| 4363 |
rajveer |
75 |
|
| 4603 |
rajveer |
76 |
providers = LogisticsUtils.getAllProviders();
|
|
|
77 |
|
| 5769 |
rajveer |
78 |
stores = LogisticsUtils.getAllStores();
|
|
|
79 |
|
| 2449 |
chandransh |
80 |
message = "You are charming, loving and affectionate";
|
| 493 |
rajveer |
81 |
} catch (HelperServiceException e) {
|
|
|
82 |
e.printStackTrace();
|
|
|
83 |
} catch (TException e) {
|
|
|
84 |
e.printStackTrace();
|
| 2449 |
chandransh |
85 |
} catch (Exception e) {
|
|
|
86 |
e.printStackTrace();
|
| 493 |
rajveer |
87 |
}
|
| 5769 |
rajveer |
88 |
return new AuthResponse(userName, status, message, nextScreen, warehouseId, userType, billingType, warehouses, providers, stores);
|
| 167 |
ashish |
89 |
}
|
|
|
90 |
|
|
|
91 |
@Override
|
| 2449 |
chandransh |
92 |
public Class<AuthRequest> getActionType() {
|
| 167 |
ashish |
93 |
return AuthRequest.class;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
@Override
|
|
|
97 |
public void rollback(AuthRequest arg0, AuthResponse arg1,
|
|
|
98 |
ExecutionContext arg2) throws ActionException {
|
| 2449 |
chandransh |
99 |
//TODO Auto-generated method stub
|
| 167 |
ashish |
100 |
}
|
|
|
101 |
|
|
|
102 |
}
|