Subversion Repositories SmartDukaan

Rev

Rev 6746 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
5948 mandeep.dh 11
import in.shop2020.thrift.clients.InventoryClient;
3132 rajveer 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;
8303 amar.kumar 34
		long sourceId = -1;
2843 chandransh 35
		UserType userType = UserType.WAREHOUSE_EXECUTIVE;
36
		BillingType billingType = BillingType.EXTERNAL;
5110 mandeep.dh 37
		Map<Long, String> warehouses = null;
4603 rajveer 38
		Map<Long, String> providers = null;
5769 rajveer 39
		Map<Long, String> stores = null;
2449 chandransh 40
		NEXT nextScreen = null;
41
		String message = null;
493 rajveer 42
 
43
		try {
3132 rajveer 44
            HelperClient hsc = new HelperClient();
2843 chandransh 45
            Client client = hsc.getClient();
46
            DashboardUser dashboardUser = client.authenticateDashboardUser(userName, password);
47
            switch (dashboardUser.getRole()) {
48
            case ADMIN:
49
                userType = UserType.ADMIN;
50
                break;
4361 rajveer 51
            case WAREHOUSE_MONITOR:
52
                userType = UserType.WAREHOUSE_MONITOR;
53
                break;
2843 chandransh 54
            default:
55
                userType = UserType.WAREHOUSE_EXECUTIVE;
56
            }
2449 chandransh 57
			status = true;
58
			nextScreen = NEXT.INBOX;
2843 chandransh 59
 
2449 chandransh 60
			warehouseId = dashboardUser.getWarehouseId();
8303 amar.kumar 61
			sourceId = dashboardUser.getSource();
5948 mandeep.dh 62
			InventoryClient csc = new InventoryClient();
63
			in.shop2020.model.v1.inventory.InventoryService.Client iClient = csc.getClient();
2843 chandransh 64
			Warehouse warehouse = iClient.getWarehouse(warehouseId);
65
			switch(warehouse.getBillingType()){
66
			case OURS:
67
			    billingType = BillingType.OURS;
2835 chandransh 68
			    break;
2843 chandransh 69
			case EXTERNAL:
70
			    billingType = BillingType.EXTERNAL;
2835 chandransh 71
			    break;
6746 rajveer 72
			case OURS_EXTERNAL:
73
			    billingType = BillingType.OURS_EXTERNAL;
74
			    break;
2835 chandransh 75
			default:
2843 chandransh 76
			    billingType = BillingType.EXTERNAL;
2835 chandransh 77
			}
2843 chandransh 78
 
5110 mandeep.dh 79
			warehouses = CatalogUtils.getWarehousesForBillingWarehouse(warehouseId);
4363 rajveer 80
 
4603 rajveer 81
			providers = LogisticsUtils.getAllProviders();
82
 
5769 rajveer 83
			stores = LogisticsUtils.getAllStores();
84
 
2449 chandransh 85
			message = "You are charming, loving and affectionate";
493 rajveer 86
		} catch (HelperServiceException e) {
87
			e.printStackTrace();
88
		} catch (TException e) {
89
			e.printStackTrace();
2449 chandransh 90
		} catch (Exception e) {
91
			e.printStackTrace();
493 rajveer 92
		}
8303 amar.kumar 93
		return new AuthResponse(userName, status, message, nextScreen, warehouseId, userType, billingType, warehouses, providers, stores, sourceId);
167 ashish 94
	}
95
 
96
	@Override
2449 chandransh 97
	public Class<AuthRequest> getActionType() {		
167 ashish 98
		return AuthRequest.class;
99
	}
100
 
101
	@Override
102
	public void rollback(AuthRequest arg0, AuthResponse arg1,
103
			ExecutionContext arg2) throws ActionException {
2449 chandransh 104
		//TODO Auto-generated method stub
167 ashish 105
	}
106
 
107
}