Subversion Repositories SmartDukaan

Rev

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