/*
 * Copyright © Région Nord Pas de Calais-Picardie,  Département 91, Région Aquitaine-Limousin-Poitou-Charentes, 2016.
 *
 * This file is part of OPEN ENT NG. OPEN ENT NG is a versatile ENT Project based on the JVM and ENT Core Project.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation (version 3 of the License).
 *
 * For the sake of explanation, any module that communicate over native
 * Web protocols, such as HTTP, with OPEN ENT NG is outside the scope of this
 * license and could be license under its own terms. This is merely considered
 * normal use of OPEN ENT NG, and does not fall under the heading of "covered work".
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

package net.atos.entng.actualites;

import net.atos.entng.actualites.controllers.CommentController;
import net.atos.entng.actualites.controllers.InfoController;
import net.atos.entng.actualites.controllers.ThreadController;
import net.atos.entng.actualites.controllers.DisplayController;
import net.atos.entng.actualites.services.impl.ActualitesRepositoryEvents;

import net.atos.entng.actualites.services.impl.ActualitesSearchingEvents;
import org.entcore.common.http.BaseServer;
import org.entcore.common.http.filter.ShareAndOwner;
import org.entcore.common.service.impl.SqlCrudService;
import org.entcore.common.service.impl.SqlSearchService;
import org.entcore.common.share.impl.SqlShareService;
import org.entcore.common.sql.SqlConf;
import org.entcore.common.sql.SqlConfs;
import org.vertx.java.core.eventbus.EventBus;
import org.vertx.java.core.json.JsonArray;

public class Actualites extends BaseServer {
	public final static String THREAD_RESOURCE_ID = "threadid";
	public final static String THREAD_TABLE = "thread";
	public final static String THREAD_SHARE_TABLE = "thread_shares";

	public final static String INFO_RESOURCE_ID = "infoid";
	public final static String INFO_TABLE = "info";
	public final static String INFO_SHARE_TABLE = "info_shares";

	public final static String COMMENT_TABLE = "comment";

	public final static String MANAGE_RIGHT_ACTION = "net-atos-entng-actualites-controllers-ThreadController|updateThread";

	@Override
	public void start() {
		super.start();
		final EventBus eb = getEventBus(vertx);

		// Subscribe to events published for transition
		setRepositoryEvents(new ActualitesRepositoryEvents(config.getBoolean("share-old-groups-to-users", false)));
		setSearchingEvents(new ActualitesSearchingEvents(new SqlSearchService(getSchema(), INFO_TABLE, INFO_SHARE_TABLE)));

		addController(new DisplayController());

		// set default rights filter
		setDefaultResourceFilter(new ShareAndOwner());

		// thread table
		SqlConf confThread = SqlConfs.createConf(ThreadController.class.getName());
		confThread.setResourceIdLabel(THREAD_RESOURCE_ID);
		confThread.setTable(THREAD_TABLE);
		confThread.setShareTable(THREAD_SHARE_TABLE);
		confThread.setSchema(getSchema());

		// thread controller
		ThreadController threadController = new ThreadController();
		SqlCrudService threadSqlCrudService = new SqlCrudService(getSchema(), THREAD_TABLE, THREAD_SHARE_TABLE, new JsonArray().addString("*"), new JsonArray().add("*"), true);
		threadController.setCrudService(threadSqlCrudService);
		threadController.setShareService(new SqlShareService(getSchema(),THREAD_SHARE_TABLE, eb, securedActions, null));
		addController(threadController);

		// info table
		SqlConf confInfo = SqlConfs.createConf(InfoController.class.getName());
		confInfo.setResourceIdLabel(INFO_RESOURCE_ID);
		confInfo.setTable(INFO_TABLE);
		confInfo.setShareTable(INFO_SHARE_TABLE);
		confInfo.setSchema(getSchema());

		// info controller
		InfoController infoController = new InfoController();
		SqlCrudService infoSqlCrudService = new SqlCrudService(getSchema(), INFO_TABLE, INFO_SHARE_TABLE, new JsonArray().addString("*"), new JsonArray().add("*"), true);
		infoController.setCrudService(infoSqlCrudService);
		infoController.setShareService(new SqlShareService(getSchema(),INFO_SHARE_TABLE, eb, securedActions, null));
		addController(infoController);

		// comment table
		SqlConf confComment = SqlConfs.createConf(CommentController.class.getName());
		confComment.setTable(COMMENT_TABLE);
		confComment.setSchema(getSchema());

		// comment controller
		CommentController commentController = new CommentController();
		SqlCrudService commentSqlCrudService = new SqlCrudService(getSchema(), COMMENT_TABLE);
		commentController.setCrudService(commentSqlCrudService);
		addController(commentController);

	}

}

@@ -2656,16 +2656,70 @@
 lse)));%0A
+%0A%09%09if (config.getBoolean(%22searching-event%22, true)) %7B%0A%09
 %09%09setSea
@@ -2823,24 +2823,28 @@
 RE_TABLE)));
+%0A%09%09%7D
 %0A%0A%09%09addContr

Adding capacity to desactivate searching events in json conf : "searching-event": false