<commit_before>package nl.tudelft.ewi.dea.servlet;

import java.io.IOException;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nl.minicom.gitolite.manager.ConfigManager;
import nl.minicom.gitolite.manager.models.Config;
import nl.minicom.gitolite.manager.models.Permission;
import nl.minicom.gitolite.manager.models.Repository;
import nl.minicom.gitolite.manager.models.User;
import nl.tudelft.ewi.dea.servlet.util.Get;
import nl.tudelft.ewi.dea.servlet.util.Post;
import nl.tudelft.ewi.dea.servlet.util.Response;
import nl.tudelft.ewi.dea.servlet.util.Servlet;

import com.google.common.collect.Lists;

@Singleton
@SuppressWarnings("serial")
public class OverviewServlet extends Servlet {
	
	private final ConfigManager gitoliteManager;

	@Inject
	public OverviewServlet(ConfigManager gitoliteManager) {
		this.gitoliteManager = gitoliteManager;
	}
	
	@Override
	public void onGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Project> invitations = Lists.newArrayList(
				new Project("IN2610 Advanced Algorithms - Group 22")
		);
		
		List<Project> projects = Lists.newArrayList(
				new Project("IN2010 Algorithms - Group 5"),
				new Project("IN2105 Software Quality & Testing - Group 8"),
				new Project("IN2505 Context project 1 - Group 7")
		);
		
		getRenderer()
			.setValue("invitations", invitations)
			.setValue("projects", projects)
			.setValue("scripts", Lists.newArrayList("overview.js"))
			.render("index.tpl");
	}
	
	@Get
	public Response checkProjectName(HttpServletRequest request, HttpServletResponse response) {
		String name = request.getParameter("name");
		return new Response(isValidProjectName(name));
	}
	
	@Post
	public Response provisionNewProject(HttpServletRequest request, HttpServletResponse response) {
		String name = request.getParameter("name");
		if (!isValidProjectName(name)) {
			return new Response(false, "Project name is not valid!");
		}
		
		Response gitProvisioning = provisionGitRepository(name);
		if (!gitProvisioning.isOk()) {
			return gitProvisioning;
		}
		
		return provisionJenkins(name, "", "");
	}
	
	//TODO: david implement this...
	private Response provisionJenkins(String projectName, String gitUrl, String email) {<commit_msg>Added git repository url, and email to Jenkins hook.<commit_after>package nl.tudelft.ewi.dea.servlet;

import java.io.IOException;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nl.minicom.gitolite.manager.ConfigManager;
import nl.minicom.gitolite.manager.models.Config;
import nl.minicom.gitolite.manager.models.Permission;
import nl.minicom.gitolite.manager.models.Repository;
import nl.minicom.gitolite.manager.models.User;
import nl.tudelft.ewi.dea.servlet.util.Get;
import nl.tudelft.ewi.dea.servlet.util.Post;
import nl.tudelft.ewi.dea.servlet.util.Response;
import nl.tudelft.ewi.dea.servlet.util.Servlet;

import com.google.common.collect.Lists;

@Singleton
@SuppressWarnings("serial")
public class OverviewServlet extends Servlet {
	
	private final ConfigManager gitoliteManager;

	@Inject
	public OverviewServlet(ConfigManager gitoliteManager) {
		this.gitoliteManager = gitoliteManager;
	}
	
	@Override
	public void onGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Project> invitations = Lists.newArrayList(
				new Project("IN2610 Advanced Algorithms - Group 22")
		);
		
		List<Project> projects = Lists.newArrayList(
				new Project("IN2010 Algorithms - Group 5"),
				new Project("IN2105 Software Quality & Testing - Group 8"),
				new Project("IN2505 Context project 1 - Group 7")
		);
		
		getRenderer()
			.setValue("invitations", invitations)
			.setValue("projects", projects)
			.setValue("scripts", Lists.newArrayList("overview.js"))
			.render("index.tpl");
	}
	
	@Get
	public Response checkProjectName(HttpServletRequest request, HttpServletResponse response) {
		String name = request.getParameter("name");
		return new Response(isValidProjectName(name));
	}
	
	@Post
	public Response provisionNewProject(HttpServletRequest request, HttpServletResponse response) {
		String name = request.getParameter("name");
		if (!isValidProjectName(name)) {
			return new Response(false, "Project name is not valid!");
		}
		
		Response gitProvisioning = provisionGitRepository(name);
		if (!gitProvisioning.isOk()) {
			return gitProvisioning;
		}
		
		return provisionJenkins(name, "<EMAIL>:" + name, "<EMAIL>");
	}
	
	//TODO: david implement this...
	private Response provisionJenkins(String projectName, String gitUrl, String email) {
{'fraction_non_alphanumeric': 0.11006879299562226, 'fraction_numerical': 0.009172399416301855, 'mean_word_length': 5.215025906735751, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2656773', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1461, 'n_words': 317}