Subversion Repositories SmartDukaan

Rev

Rev 3213 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1941 ankur.sing 1
package in.shop2020.support.utils;
2
 
3
import java.util.List;
4
 
5
import org.apache.thrift.TException;
3213 chandransh 6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
1941 ankur.sing 8
 
3125 rajveer 9
import in.shop2020.thrift.clients.HelperClient;
1941 ankur.sing 10
import in.shop2020.utils.Report;
11
 
12
public class ReportsUtils {
13
 
3213 chandransh 14
    public static Logger logger = LoggerFactory.getLogger(ReportsUtils.class);
15
 
12256 kshitij.so 16
    public static final String USER_NAME = "username", PASSWORD = "password", ROLE = "role", USER_EMAIL="useremail";
1941 ankur.sing 17
 
3125 rajveer 18
    private static HelperClient hsc;
1941 ankur.sing 19
 
20
    static {
21
        try {
3125 rajveer 22
            hsc = new HelperClient();
1941 ankur.sing 23
        } catch (Exception e) {
3213 chandransh 24
            logger.error("Unable to initialize connection to the helper service", e);
1941 ankur.sing 25
        }
26
    }
27
 
28
    public static boolean canAccessReport(long role, String reportStr) {
29
        if(reportStr.startsWith("/")) {
30
            reportStr = reportStr.substring(1, reportStr.length());
31
        }
32
        List<Report> reports = getReports(role);
33
        for(Report r : reports) {
34
            if(r.getController().equals(reportStr))
35
                return true;
36
        }
37
        return false;
38
    }
39
 
40
    public static List<Report> getReports(long role) {
41
        List<Report> reports = null;
42
        try {
43
            reports = hsc.getClient().getReports(role);
44
        } catch (TException e) {
3213 chandransh 45
            logger.error("Unable to get reports for the role: " + role, e);
1941 ankur.sing 46
        }
47
        return reports;
48
    }
49
}