<commit_before>import Entity.URL;
import Entity.User;
import eu.bitwalker.useragentutils.UserAgent;
import spark.ModelAndView;
import spark.Session;
import spark.template.freemarker.FreeMarkerEngine;

import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;

import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.post;

/**
 * Created by <NAME> on 19-Jun-16.
 */
public class pageCreator {

    static String current_username;

    public pageCreator() throws Exception {

        generateGets();
        generatePost();
        generateFilters();
    }

    private static void generateFilters()
    {
        before("/*", (request, response) -> {

            Map<String, Object> attributes = new HashMap<>();
            if (request.session().attribute("user")!= null)
            {
                current_username= request.session().attribute("user");
            }
            else
            {
                current_username="guest";
            }


        });
    }

    private static void generateGets() {

        get("/", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("message", "Welcome");
            attributes.put("pagename","Home");
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            List<URL> urls = DatabaseManager.FetchAllURLForUser(current_username);
            attributes.put("urls",urls);

            return new ModelAndView(attributes, "index.ftl");
        }, new FreeMarkerEngine());

        get("/viewall", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("message", "Welcome");
            attributes.put("pagename","View All Users");
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            List<URL> urls = DatabaseManager.FetchAllURL();
            attributes.put("urls",urls);

            return new ModelAndView(attributes, "viewall.ftl");
        }, new FreeMarkerEngine());

        get("/register", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Register");
            attributes.put("message", "Welcome");
            return new ModelAndView(attributes, "register.ftl");
        }, new FreeMarkerEngine());


        get("/login", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Login");
            attributes.put("message", "Welcome");
            return new ModelAndView(attributes, "login.ftl");
        }, new FreeMarkerEngine());

        get("/instructions", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Instructions");
            return new ModelAndView(attributes, "instructions.ftl");
        }, new FreeMarkerEngine());


        get("/logout", (req, res) -> {
            req.session().invalidate();
            res.redirect("/");

            return "<h1>You have bee logged out</h1>";
        }  );

        get("/users", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Users Management");
            List<User> userList= DatabaseManager.FetchAllUsers();
            attributes.put("userList",userList);
            return new ModelAndView(attributes, "usersview.ftl");
        }, new FreeMarkerEngine());

        get("/p/:urlid/stats", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            String urlid =request.params(":urlid");
            attributes.put("urlid",urlid);
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Link Stats");
            String QrUrl = ResourceFetcher.getQrCodeURL(DatabaseManager.FetchOriginalURL(urlid));
            attributes.put("QrUrl",QrUrl);

            attributes.put("allBrowsers",DatabaseManager.FetchAllBrowser());
            attributes.put("allOs",DatabaseManager.FetchAllOS());
            attributes.put("allCountries",DatabaseManager.FetchAllCountries());




            Map<java.sql.Date, Integer> data = DatabaseManager.FetchURLDataByDate(urlid);
            Set<java.sql.Date> legend = DatabaseManager.ShowDateMapLegend(data);
            DateFormat df = new SimpleDateFormat("yyyy,MM,dd");
            ArrayList<String> arr = new ArrayList<String>();
            for (java.sql.Date key: legend) {

                String theValue= "new Date("+df.format(key) + "),"+ data.get(key);<commit_msg>commit<commit_after>import Entity.URL;
import Entity.User;
import eu.bitwalker.useragentutils.UserAgent;
import spark.ModelAndView;
import spark.Session;
import spark.template.freemarker.FreeMarkerEngine;

import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;

import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.post;

/**
 * Created by <NAME> on 19-Jun-16.
 */
public class pageCreator {

    static String current_username;

    public pageCreator() throws Exception {

        generateGets();
        generatePost();
        generateFilters();
    }

    private static void generateFilters()
    {
        before("/*", (request, response) -> {

            Map<String, Object> attributes = new HashMap<>();
            if (request.session().attribute("user")!= null)
            {
                current_username= request.session().attribute("user");
            }
            else
            {
                current_username="guest";
            }


        });
    }

    private static void generateGets() {

        get("/", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("message", "Welcome");
            attributes.put("pagename","Home");
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            List<URL> urls = DatabaseManager.FetchAllURLForUser(current_username);
            attributes.put("urls",urls);

            return new ModelAndView(attributes, "index.ftl");
        }, new FreeMarkerEngine());

        get("/viewall", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("message", "Welcome");
            attributes.put("pagename","View All Users");
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            List<URL> urls = DatabaseManager.FetchAllURL();
            attributes.put("urls",urls);

            return new ModelAndView(attributes, "viewall.ftl");
        }, new FreeMarkerEngine());

        get("/register", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Register");
            attributes.put("message", "Welcome");
            return new ModelAndView(attributes, "register.ftl");
        }, new FreeMarkerEngine());


        get("/login", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Login");
            attributes.put("message", "Welcome");
            return new ModelAndView(attributes, "login.ftl");
        }, new FreeMarkerEngine());

        get("/instructions", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Instructions");
            return new ModelAndView(attributes, "instructions.ftl");
        }, new FreeMarkerEngine());


        get("/logout", (req, res) -> {
            req.session().invalidate();
            res.redirect("/");

            return "<h1>You have bee logged out</h1>";
        }  );

        get("/users", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Users Management");
            List<User> userList= DatabaseManager.FetchAllUsers();
            attributes.put("userList",userList);
            return new ModelAndView(attributes, "usersview.ftl");
        }, new FreeMarkerEngine());

        get("/p/:urlid/stats", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            String urlid =request.params(":urlid");
            attributes.put("urlid",urlid);
            attributes.put("user",DatabaseManager.FetchUser(current_username));
            attributes.put("pagename","Link Stats");
            String QrUrl = ResourceFetcher.getQrCodeURL(DatabaseManager.FetchOriginalURL(urlid));
            attributes.put("QrUrl",QrUrl);
            ArrayList<String> allbrow = DatabaseManager.FetchAllBrowser();
            ArrayList<String> allOs = DatabaseManager.FetchAllOS();
            ArrayList<String> allCount = DatabaseManager.FetchAllCountries();
            for (String s:allbrow) {
                System.out.println("The BROwSER is:"+s);
            }
            for (String s:allOs) {
                System.out.println("The OS is:"+s);
            }
            for (String s:allCount) {
                System.out.println("The Cuntry is:"+s);
            }
            attributes.put("allBrowsers",allbrow);
            attributes.put("allOs",allOs);
            attributes.put("allCountries",allCount);




            Map<java.sql.Date, Integer> data = DatabaseManager.FetchURLDataByDate(urlid);
            Set<java.sql.Date> legend = DatabaseManager.ShowDateMapLegend(data);
            DateFormat df = new SimpleDateFormat("yyyy,MM,dd");
            ArrayList<String> arr = new ArrayList<String>();
            for (java.sql.Date key: legend) {

                String theValue= "new Date("+df.format(key) + "),"+ data.get(key);
{'fraction_non_alphanumeric': 0.1407812794866956, 'fraction_numerical': 0.0011322891111530478, 'mean_word_length': 2.5353569046030686, 'pattern_counts': {'":': 2, '<': 58, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3078819', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2672, 'n_words': 522}