Subversion Repositories SmartDukaan

Rev

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

package in.shop2020.support.utils;

import java.util.List;

import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import in.shop2020.thrift.clients.HelperClient;
import in.shop2020.utils.Report;

public class ReportsUtils {

    public static Logger logger = LoggerFactory.getLogger(ReportsUtils.class);
    
    public static final String USER_NAME = "username", PASSWORD = "password", ROLE = "role", USER_EMAIL="useremail";
    
    private static HelperClient hsc;
    
    static {
        try {
            hsc = new HelperClient();
        } catch (Exception e) {
            logger.error("Unable to initialize connection to the helper service", e);
        }
    }
    
    public static boolean canAccessReport(long role, String reportStr) {
        if(reportStr.startsWith("/")) {
            reportStr = reportStr.substring(1, reportStr.length());
        }
        List<Report> reports = getReports(role);
        for(Report r : reports) {
            if(r.getController().equals(reportStr))
                return true;
        }
        return false;
    }
    
    public static List<Report> getReports(long role) {
        List<Report> reports = null;
        try {
            reports = hsc.getClient().getReports(role);
        } catch (TException e) {
            logger.error("Unable to get reports for the role: " + role, e);
        }
        return reports;
    }
}