<commit_before>package fr.wseduc.actualites.controllers;


import java.util.Map;

import org.entcore.common.http.filter.ResourceFilter;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.RouteMatcher;
import org.vertx.java.platform.Container;

import fr.wseduc.actualites.controllers.helpers.InfoControllerHelper;
import fr.wseduc.actualites.controllers.helpers.StateControllerHelper;
import fr.wseduc.actualites.controllers.helpers.ThreadControllerHelper;
import fr.wseduc.actualites.filters.DeleteInfoFilter;
import fr.wseduc.actualites.filters.PublishFilter;
import fr.wseduc.actualites.filters.StateDraftFilter;
import fr.wseduc.actualites.filters.StatePendingFilter;
import fr.wseduc.actualites.filters.StatePublishedFilter;
import fr.wseduc.actualites.filters.StateTrashFilter;
import fr.wseduc.actualites.services.InfoService;
import fr.wseduc.actualites.services.ThreadService;
import fr.wseduc.rs.ApiDoc;
import fr.wseduc.rs.Delete;
import fr.wseduc.rs.Get;
import fr.wseduc.rs.Post;
import fr.wseduc.rs.Put;
import fr.wseduc.security.ActionType;
import fr.wseduc.security.SecuredAction;
import fr.wseduc.webutils.http.BaseController;

public class ActualitesController extends BaseController {

	private final ThreadControllerHelper threadHelper;
	private final InfoControllerHelper infoHelper;
	private final StateControllerHelper stateHelper;

	public ActualitesController(final String collection, final ThreadService threadService, final InfoService infoService) {
		this.threadHelper = new ThreadControllerHelper(collection, threadService);
		this.infoHelper = new InfoControllerHelper(infoService);
		this.stateHelper = new StateControllerHelper(infoService, threadService);
	}

	@Override
	public void init(Vertx vertx, Container container, RouteMatcher rm, Map<String, fr.wseduc.webutils.security.SecuredAction> securedActions) {
		super.init(vertx, container, rm, securedActions);
		this.threadHelper.init(vertx, container, rm, securedActions);
		this.infoHelper.init(vertx, container, rm, securedActions);
		this.stateHelper.init(vertx, container, rm, securedActions);
	}

	@Get("")
	@SecuredAction("actualites.view")
	public void view(final HttpServerRequest request) {
		renderView(request);
	}

	@Get("/threads")
	@ApiDoc("Get Thread by id.")
	@SecuredAction("actualites.threads.list")
	public void listThreads(final HttpServerRequest request) {
		threadHelper.listThreads(request);
	}


	@Post("/threads")
	@ApiDoc("Create a new Thread.")
	@SecuredAction("actualites.create")
	public void createThread(final HttpServerRequest request) {
		threadHelper.createThread(request);
	}

	@Get("/thread/:id")
	@ApiDoc("Get Thread by id.")
	@SecuredAction(value = "thread.read", type = ActionType.RESOURCE)
	public void getThread(final HttpServerRequest request) {
		threadHelper.retrieveThread(request);
	}

	@Put("/thread/:id")
	@ApiDoc("Update thread by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void updateThread(final HttpServerRequest request) {
		threadHelper.updateThread(request);
	}

	@Delete("/thread/:id")
	@ApiDoc("Delete thread by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void deleteThread(final HttpServerRequest request) {
		threadHelper.deleteThread(request);
	}


	@Get("/share/json/:id")
	@ApiDoc("Share thread by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void shareThread(final HttpServerRequest request) {
		threadHelper.shareThread(request);
	}

	@Put("/share/json/:id")
	@ApiDoc("Share thread by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void shareThreadSubmit(final HttpServerRequest request) {
		threadHelper.shareThreadSubmit(request);
	}

	@Put("/share/remove/:id")
	@ApiDoc("Remove Share by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void shareThreadRemove(final HttpServerRequest request) {
		threadHelper.shareThreadRemove(request);
	}


	@Get("/infos")
	@ApiDoc("Get infos in thread by status and by thread id.")
	@SecuredAction("actualites.infos.list")
	public void listInfos(final HttpServerRequest request) {
		// TODO IMPROVE : Security on Infos visibles by statuses / dates is not enforced
		infoHelper.listInfos(request);
	}

	@Get("/linker/infos")
	@ApiDoc("List infos without their content. Used by linker")
	@SecuredAction("actualites.view")
	public void listInfosForLinker(final HttpServerRequest request) {
		// TODO IMPROVE : Security on Infos visibles by statuses / dates is not enforced
		infoHelper.listInfosForLinker(request);
	}


	@Get("/thread/:id/infos")
	@ApiDoc("Get infos in thread by thread id.")
	@SecuredAction(value = "thread.read", type = ActionType.RESOURCE)
	public void listThreadInfos(final HttpServerRequest request) {
		// TODO IMPROVE : Security on Infos visibles by statuses / dates is not enforced
		infoHelper.listThreadInfos(request);
	}


	@Post("/thread/:id/info")
	@ApiDoc("Add a new Info")
	@SecuredAction(value = "thread.contrib", type = ActionType.RESOURCE)
	public void createDraft(final HttpServerRequest request) {
		infoHelper.create(request);<commit_msg>#1628 rename workflow right (according to #1457)<commit_after>package fr.wseduc.actualites.controllers;


import java.util.Map;

import org.entcore.common.http.filter.ResourceFilter;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.RouteMatcher;
import org.vertx.java.platform.Container;

import fr.wseduc.actualites.controllers.helpers.InfoControllerHelper;
import fr.wseduc.actualites.controllers.helpers.StateControllerHelper;
import fr.wseduc.actualites.controllers.helpers.ThreadControllerHelper;
import fr.wseduc.actualites.filters.DeleteInfoFilter;
import fr.wseduc.actualites.filters.PublishFilter;
import fr.wseduc.actualites.filters.StateDraftFilter;
import fr.wseduc.actualites.filters.StatePendingFilter;
import fr.wseduc.actualites.filters.StatePublishedFilter;
import fr.wseduc.actualites.filters.StateTrashFilter;
import fr.wseduc.actualites.services.InfoService;
import fr.wseduc.actualites.services.ThreadService;
import fr.wseduc.rs.ApiDoc;
import fr.wseduc.rs.Delete;
import fr.wseduc.rs.Get;
import fr.wseduc.rs.Post;
import fr.wseduc.rs.Put;
import fr.wseduc.security.ActionType;
import fr.wseduc.security.SecuredAction;
import fr.wseduc.webutils.http.BaseController;

public class ActualitesController extends BaseController {

	private final ThreadControllerHelper threadHelper;
	private final InfoControllerHelper infoHelper;
	private final StateControllerHelper stateHelper;

	public ActualitesController(final String collection, final ThreadService threadService, final InfoService infoService) {
		this.threadHelper = new ThreadControllerHelper(collection, threadService);
		this.infoHelper = new InfoControllerHelper(infoService);
		this.stateHelper = new StateControllerHelper(infoService, threadService);
	}

	@Override
	public void init(Vertx vertx, Container container, RouteMatcher rm, Map<String, fr.wseduc.webutils.security.SecuredAction> securedActions) {
		super.init(vertx, container, rm, securedActions);
		this.threadHelper.init(vertx, container, rm, securedActions);
		this.infoHelper.init(vertx, container, rm, securedActions);
		this.stateHelper.init(vertx, container, rm, securedActions);
	}

	@Get("")
	@SecuredAction("actualites.view")
	public void view(final HttpServerRequest request) {
		renderView(request);
	}

	@Get("/threads")
	@ApiDoc("Get Thread by id.")
	@SecuredAction("actualites.threads.list")
	public void listThreads(final HttpServerRequest request) {
		threadHelper.listThreads(request);
	}


	@Post("/threads")
	@ApiDoc("Create a new Thread.")
	@SecuredAction("actualites.create")
	public void createThread(final HttpServerRequest request) {
		threadHelper.createThread(request);
	}

	@Get("/thread/:id")
	@ApiDoc("Get Thread by id.")
	@SecuredAction(value = "thread.read", type = ActionType.RESOURCE)
	public void getThread(final HttpServerRequest request) {
		threadHelper.retrieveThread(request);
	}

	@Put("/thread/:id")
	@ApiDoc("Update thread by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void updateThread(final HttpServerRequest request) {
		threadHelper.updateThread(request);
	}

	@Delete("/thread/:id")
	@ApiDoc("Delete thread by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void deleteThread(final HttpServerRequest request) {
		threadHelper.deleteThread(request);
	}


	@Get("/share/json/:id")
	@ApiDoc("Share thread by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void shareThread(final HttpServerRequest request) {
		threadHelper.shareThread(request);
	}

	@Put("/share/json/:id")
	@ApiDoc("Share thread by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void shareThreadSubmit(final HttpServerRequest request) {
		threadHelper.shareThreadSubmit(request);
	}

	@Put("/share/remove/:id")
	@ApiDoc("Remove Share by id.")
	@SecuredAction(value = "thread.manager", type = ActionType.RESOURCE)
	public void shareThreadRemove(final HttpServerRequest request) {
		threadHelper.shareThreadRemove(request);
	}


	@Get("/infos")
	@ApiDoc("Get infos in thread by status and by thread id.")
	@SecuredAction("actualites.infos.list")
	public void listInfos(final HttpServerRequest request) {
		// TODO IMPROVE : Security on Infos visibles by statuses / dates is not enforced
		infoHelper.listInfos(request);
	}

	@Get("/linker/infos")
	@ApiDoc("List infos without their content. Used by linker")
	@SecuredAction("actualites.infos.list")
	public void listInfosForLinker(final HttpServerRequest request) {
		// TODO IMPROVE : Security on Infos visibles by statuses / dates is not enforced
		infoHelper.listInfosForLinker(request);
	}


	@Get("/thread/:id/infos")
	@ApiDoc("Get infos in thread by thread id.")
	@SecuredAction(value = "thread.read", type = ActionType.RESOURCE)
	public void listThreadInfos(final HttpServerRequest request) {
		// TODO IMPROVE : Security on Infos visibles by statuses / dates is not enforced
		infoHelper.listThreadInfos(request);
	}


	@Post("/thread/:id/info")
	@ApiDoc("Add a new Info")
	@SecuredAction(value = "thread.contrib", type = ActionType.RESOURCE)
	public void createDraft(final HttpServerRequest request) {
		infoHelper.create(request);
{'fraction_non_alphanumeric': 0.11450090571074459, 'fraction_numerical': 0.0007627037849175327, 'mean_word_length': 6.068733153638814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7591673', 'n_tokens_mistral': 3265, 'n_tokens_neox': 3184, 'n_words': 691}