Subversion Repositories SmartDukaan

Rev

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