// Path: src/main/java/net/atos/entng/rbs/BookingUtils.java
// public static List<String> getLocalAdminScope(final UserInfos user) {
// 	Map<String, UserInfos.Function> functions = user.getFunctions();
// 	if (functions != null && functions.containsKey(DefaultFunctions.ADMIN_LOCAL)) {
// 		Function adminLocal = functions.get(DefaultFunctions.ADMIN_LOCAL);
// 		if (adminLocal != null) {
// 			return adminLocal.getScope();
// 		}
// 	}
// 
// 	return new ArrayList<String>();
// }
// 
// Path: src/main/java/net/atos/entng/rbs/BookingStatus.java
// public enum BookingStatus {
// 	CREATED(1), VALIDATED(2), REFUSED(3), SUSPENDED(4);
// 
// 	private final int status;
// 
// 	BookingStatus(int pStatus) {
// 		this.status = pStatus;
// 	}
// 	public int status(){
// 		return status;
// 	}
// }


import org.entcore.common.service.impl.SqlCrudService;
import org.entcore.common.sql.Sql;
import org.entcore.common.sql.SqlStatementsBuilder;
import org.entcore.common.user.UserInfos;
import io.vertx.core.Handler;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import fr.wseduc.webutils.Either;
import static net.atos.entng.rbs.BookingStatus.CREATED;
import static net.atos.entng.rbs.BookingStatus.REFUSED;
import static net.atos.entng.rbs.BookingStatus.SUSPENDED;
import static net.atos.entng.rbs.BookingUtils.getLocalAdminScope;
import static org.entcore.common.sql.Sql.parseId;
import static org.entcore.common.sql.SqlResult.*;
import static org.entcore.common.sql.SqlResult.validUniqueResultHandler;
import java.util.List;
import net.atos.entng.rbs.BookingStatus;
		for (String attr : resource.fieldNames()) {
			if ("was_available".equals(attr)) {
				continue;
			}
			sb.append(attr).append(" = ?, ");
			values.add(resource.getValue(attr));
		}
		unsetFieldIfNull(resource, sb, values, "max_delay");
		unsetFieldIfNull(resource, sb, values, "min_delay");

		StringBuilder query = new StringBuilder();
		query.append("UPDATE rbs.resource")
			.append(" SET ")
			.append(sb.toString())
			.append("modified = NOW()")
			.append(" WHERE id = ?")
			.append(" RETURNING id, name");
		values.add(parseId(resourceId));

		final boolean isAvailable = resource.getBoolean("is_available");
		final boolean wasAvailable = resource.getBoolean("was_available");

		if(isAvailable == wasAvailable) {
			Sql.getInstance().prepared(query.toString(), values, validUniqueResultHandler(handler));
		}
		else {
			SqlStatementsBuilder statementsBuilder = new SqlStatementsBuilder();
			statementsBuilder.prepared(query.toString(), values);

			// Update bookings' status to "created" if resource is available again, and to "suspended" if resource is now unavailable
// Path: src/main/java/net/atos/entng/rbs/BookingUtils.java
// public static List<String> getLocalAdminScope(final UserInfos user) {
// 	Map<String, UserInfos.Function> functions = user.getFunctions();
// 	if (functions != null && functions.containsKey(DefaultFunctions.ADMIN_LOCAL)) {
// 		Function adminLocal = functions.get(DefaultFunctions.ADMIN_LOCAL);
// 		if (adminLocal != null) {
// 			return adminLocal.getScope();
// 		}
// 	}
// 
// 	return new ArrayList<String>();
// }
// 
// Path: src/main/java/net/atos/entng/rbs/BookingStatus.java
// public enum BookingStatus {
// 	CREATED(1), VALIDATED(2), REFUSED(3), SUSPENDED(4);
// 
// 	private final int status;
// 
// 	BookingStatus(int pStatus) {
// 		this.status = pStatus;
// 	}
// 	public int status(){
// 		return status;
// 	}
// }


// Path: src/main/java/net/atos/entng/rbs/service/ResourceServiceSqlImpl.java
import org.entcore.common.service.impl.SqlCrudService;
import org.entcore.common.sql.Sql;
import org.entcore.common.sql.SqlStatementsBuilder;
import org.entcore.common.user.UserInfos;
import io.vertx.core.Handler;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import fr.wseduc.webutils.Either;
import static net.atos.entng.rbs.BookingStatus.CREATED;
import static net.atos.entng.rbs.BookingStatus.REFUSED;
import static net.atos.entng.rbs.BookingStatus.SUSPENDED;
import static net.atos.entng.rbs.BookingUtils.getLocalAdminScope;
import static org.entcore.common.sql.Sql.parseId;
import static org.entcore.common.sql.SqlResult.*;
import static org.entcore.common.sql.SqlResult.validUniqueResultHandler;
import java.util.List;
import net.atos.entng.rbs.BookingStatus;

		for (String attr : resource.fieldNames()) {
			if ("was_available".equals(attr)) {
				continue;
			}
			sb.append(attr).append(" = ?, ");
			values.add(resource.getValue(attr));
		}
		unsetFieldIfNull(resource, sb, values, "max_delay");
		unsetFieldIfNull(resource, sb, values, "min_delay");

		StringBuilder query = new StringBuilder();
		query.append("UPDATE rbs.resource")
			.append(" SET ")
			.append(sb.toString())
			.append("modified = NOW()")
			.append(" WHERE id = ?")
			.append(" RETURNING id, name");
		values.add(parseId(resourceId));

		final boolean isAvailable = resource.getBoolean("is_available");
		final boolean wasAvailable = resource.getBoolean("was_available");

		if(isAvailable == wasAvailable) {
			Sql.getInstance().prepared(query.toString(), values, validUniqueResultHandler(handler));
		}
		else {
			SqlStatementsBuilder statementsBuilder = new SqlStatementsBuilder();
			statementsBuilder.prepared(query.toString(), values);

			// Update bookings' status to "created" if resource is available again, and to "suspended" if resource is now unavailable
			BookingStatus newStatus = isAvailable ? CREATED : SUSPENDED;