Subversion Repositories SmartDukaan

Rev

Rev 6154 | Rev 6194 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6154 Rev 6161
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import in.shop2020.model.v1.order.RechargeOrder;
3
import in.shop2020.model.v1.order.RechargeOrder;
-
 
4
import in.shop2020.model.v1.order.RechargeType;
4
import in.shop2020.support.utils.ReportsUtils;
5
import in.shop2020.support.utils.ReportsUtils;
5
import in.shop2020.thrift.clients.TransactionClient;
6
import in.shop2020.thrift.clients.TransactionClient;
6
 
7
 
7
import java.text.DateFormat;
8
import java.text.DateFormat;
8
import java.text.SimpleDateFormat;
9
import java.text.SimpleDateFormat;
9
import java.util.Calendar;
10
import java.util.Calendar;
10
import java.util.List;
11
import java.util.List;
-
 
12
import java.util.Map;
-
 
13
import java.util.Map.Entry;
11
 
14
 
12
import javax.servlet.ServletContext;
15
import javax.servlet.ServletContext;
13
import javax.servlet.http.HttpServletRequest;
16
import javax.servlet.http.HttpServletRequest;
14
import javax.servlet.http.HttpSession;
17
import javax.servlet.http.HttpSession;
15
 
18
 
Line 39... Line 42...
39
    private HttpSession session;
42
    private HttpSession session;
40
    private ServletContext context;
43
    private ServletContext context;
41
    
44
    
42
	private List<RechargeOrder> allOrders;
45
	private List<RechargeOrder> allOrders;
43
 
46
 
-
 
47
    private static Map<Long, String> providers;
44
    
48
 
45
    private TransactionClient tsc;
49
    private TransactionClient tsc;
46
    private in.shop2020.model.v1.order.TransactionService.Client tClient;
50
    private in.shop2020.model.v1.order.TransactionService.Client tClient;
47
    
51
    
48
    private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
52
    private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
49
	
53
	
Line 54... Line 58...
54
        } catch (Exception e) {
58
        } catch (Exception e) {
55
            logger.error("Error connecting to one of the user, order or payment service", e);
59
            logger.error("Error connecting to one of the user, order or payment service", e);
56
        }
60
        }
57
	}
61
	}
58
		
62
		
-
 
63
    static{
-
 
64
    	TransactionClient tc;
-
 
65
        try {
-
 
66
            tc = new TransactionClient();
-
 
67
            providers = tc.getClient().getServiceProviders(RechargeType.MOBILE);
-
 
68
            for(Entry<Long, String> providerEntry: tc.getClient().getServiceProviders(RechargeType.DTH).entrySet()){
-
 
69
            	providers.put(providerEntry.getKey(), providerEntry.getValue());
-
 
70
            }
-
 
71
             
-
 
72
        } catch (Exception e) {
-
 
73
            logger.error("Cannot get providers", e);
-
 
74
        }
-
 
75
    }
-
 
76
    
59
	public String index() {
77
	public String index() {
60
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
78
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
61
            return "authfail";
79
            return "authfail";
62
        }
80
        }
63
        getStats();
81
        getStats();
Line 74... Line 92...
74
	}
92
	}
75
	
93
	
76
    public List<RechargeOrder> getValidOrders() {
94
    public List<RechargeOrder> getValidOrders() {
77
        return allOrders;
95
        return allOrders;
78
    }
96
    }
-
 
97
 
-
 
98
    public String getOperator(long operatorId) {
-
 
99
        return providers.get(operatorId);
79
    
100
    }
-
 
101
 
80
    public String getDateTime(long milliseconds) {
102
    public String getDateTime(long milliseconds) {
81
        Calendar cal = Calendar.getInstance();
103
        Calendar cal = Calendar.getInstance();
82
        cal.setTimeInMillis(milliseconds);
104
        cal.setTimeInMillis(milliseconds);
83
        return formatter.format(cal.getTime());
105
        return formatter.format(cal.getTime());
84
    }
106
    }
Line 95... Line 117...
95
    }
117
    }
96
 
118
 
97
    public String getServletContextPath() {
119
    public String getServletContextPath() {
98
        return context.getContextPath();
120
        return context.getContextPath();
99
    }
121
    }
-
 
122
    
-
 
123
    public Map<Long, String> getProviderMap() {
-
 
124
        return providers;
-
 
125
    }
100
}
126
}
101
 
127