Subversion Repositories SmartDukaan

Rev

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