Subversion Repositories SmartDukaan

Rev

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