// Path: src/main/java/net/atos/entng/rbs/model/ExportRequest.java
// public class ExportRequest {
// 
// 	private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
// 	public static final String USER_TZ = "usertimezone";
// 	public static final String START_DATE = "startdate";
// 	public static final String END_DATE = "enddate";
// 	public static final String FORMAT = "format";
// 	public static final String VIEW = "view";
// 	public static final String RESOURCE_IDS = "resourceIds";
// 
//     public enum Format {ICAL, PDF}
// 
//     public enum View {DAY, WEEK, LIST, NA}
// 
// 	private UserInfos userInfos;
// 	private View view = View.WEEK;
// 	private Format format = Format.ICAL;
// 	private List<Long> resourceIds = new ArrayList<>();
// 	private String userTz; // Needed for dates to be expressed in the user time zone. (UTC by default)
// 	private String startDate;
// 	private String endDate;
// 
//     public ExportRequest(JsonObject data) {
//         this(data, null);
//     }
// 
// 	public ExportRequest(JsonObject userExportRequest, UserInfos userInfos) {
// 		this.userInfos = userInfos;
// 		this.format = Format.valueOf(userExportRequest.getString(FORMAT));
// 		this.view = View.valueOf(userExportRequest.getString(VIEW));
// 		
// 		this.userTz = userExportRequest.getString(USER_TZ);
// 
//         this.startDate = userExportRequest.getString(START_DATE);
//         this.endDate = userExportRequest.getString(END_DATE);
//         checkPeriodValid(startDate, endDate);
// 
//         try {
//             JsonArray userExportResourceArray = userExportRequest.getJsonArray(RESOURCE_IDS, new fr.wseduc.webutils.collections.JsonArray());
//             for (Object resourceId : userExportResourceArray) {
//                 this.resourceIds.add(new Long((Integer) resourceId));
//             }
//         } catch (NumberFormatException | NullPointerException | ClassCastException e) {
//             throw new IllegalArgumentException("params resources must be defined with an array of Integer");
//         }
// 
//     }
// 
//     private void checkPeriodValid(String startInput, String endInput) {
//         Date start;
//         Date end;
//         try {
//             start = DATE_FORMATTER.parse(startInput);
//             end = DATE_FORMATTER.parse(endInput);
//         } catch (NullPointerException | ParseException e) {
//             throw new IllegalArgumentException("params start and end date must be defined with YYYY-MM-DD format !");
//         }
//         if (start.after(end)) {
//             throw new IllegalArgumentException("Param startdate must be before enddate");
//         }
//     }
// 
//     public UserInfos getUserInfos() {
//         return userInfos;
//     }
// 
//     public View getView() {
//         return view;
//     }
// 
//     public Format getFormat() {
//         return format;
//     }
// 
//     public List<Long> getResourceIds() {
//         return resourceIds;
//     }
// 
//     public String getStartDate() {
//         return startDate;
//     }
// 
//     public String getEndDate() {
//         return endDate;
//     }
// 
// 
//     public void setFormat(Format format) {
//         this.format = format;
//     }
// 
//     public void setView(View view) {
//         this.view = view;
//     }
// 
//     public void setResourceIds(List<Long> resourceIds) {
//         this.resourceIds = resourceIds;
//     }
// 
//     public void setStartDate(String startDate) {
//         this.startDate = startDate;
//     }
// 
// 	public void setEndDate(String endDate) {
// 		this.endDate = endDate;
// 	}
// 
// 	public String getUserTz() {
// 		return userTz;
// 	}
// 
// 	public void setUserTz(String userTz) {
// 		this.userTz = userTz;
// 	}
// }
// 
// Path: src/main/java/net/atos/entng/rbs/model/ExportResponse.java
// public static ExportRequest.View getView(JsonObject exportResponse) {
// 	String viewAsString = exportResponse.getString(ExportRequest.VIEW, ExportRequest.View.WEEK.name());
// 	return ExportRequest.View.valueOf(viewAsString);
// }


import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import fr.wseduc.webutils.data.FileResolver;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.shareddata.LocalMap;
import net.atos.entng.rbs.model.ExportRequest;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import java.io.StringWriter;
import java.util.Locale;
import java.util.Map;
import static fr.wseduc.webutils.Utils.handlerToAsyncHandler;
import static net.atos.entng.rbs.model.ExportResponse.getView;
				return;
			}
		});
	}

	private JsonObject prepareData(JsonObject jsonExportResponse, String host, Locale locale, String userTimeZone) {
		JsonFormatter formatter = JsonFormatter.buildFormater(jsonExportResponse, host, locale, userTimeZone);

		JsonObject convertedJson = formatter.format();
		JsonArray jsonFileArray = new fr.wseduc.webutils.collections.JsonArray();
		jsonFileArray.add(convertedJson);

		return new JsonObject().put("export", jsonFileArray);
	}

	private String fillTemplate(String templateAsString, JsonObject preparedData) {
		Mustache.Compiler compiler = Mustache.compiler().defaultValue("");
		Template template = compiler.compile(templateAsString);

		Map<String, Object> ctx = new JsonObject(preparedData.toString()).getMap();

		StringWriter writer = new StringWriter();
		template.execute(ctx, writer);
		return writer.getBuffer().toString();
	}

	private String getTemplate(JsonObject exportResponse) {
		String htmlTemplateFile;
		ExportRequest.View view = getView(exportResponse);
		switch (view) {
// Path: src/main/java/net/atos/entng/rbs/model/ExportRequest.java
// public class ExportRequest {
// 
// 	private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
// 	public static final String USER_TZ = "usertimezone";
// 	public static final String START_DATE = "startdate";
// 	public static final String END_DATE = "enddate";
// 	public static final String FORMAT = "format";
// 	public static final String VIEW = "view";
// 	public static final String RESOURCE_IDS = "resourceIds";
// 
//     public enum Format {ICAL, PDF}
// 
//     public enum View {DAY, WEEK, LIST, NA}
// 
// 	private UserInfos userInfos;
// 	private View view = View.WEEK;
// 	private Format format = Format.ICAL;
// 	private List<Long> resourceIds = new ArrayList<>();
// 	private String userTz; // Needed for dates to be expressed in the user time zone. (UTC by default)
// 	private String startDate;
// 	private String endDate;
// 
//     public ExportRequest(JsonObject data) {
//         this(data, null);
//     }
// 
// 	public ExportRequest(JsonObject userExportRequest, UserInfos userInfos) {
// 		this.userInfos = userInfos;
// 		this.format = Format.valueOf(userExportRequest.getString(FORMAT));
// 		this.view = View.valueOf(userExportRequest.getString(VIEW));
// 		
// 		this.userTz = userExportRequest.getString(USER_TZ);
// 
//         this.startDate = userExportRequest.getString(START_DATE);
//         this.endDate = userExportRequest.getString(END_DATE);
//         checkPeriodValid(startDate, endDate);
// 
//         try {
//             JsonArray userExportResourceArray = userExportRequest.getJsonArray(RESOURCE_IDS, new fr.wseduc.webutils.collections.JsonArray());
//             for (Object resourceId : userExportResourceArray) {
//                 this.resourceIds.add(new Long((Integer) resourceId));
//             }
//         } catch (NumberFormatException | NullPointerException | ClassCastException e) {
//             throw new IllegalArgumentException("params resources must be defined with an array of Integer");
//         }
// 
//     }
// 
//     private void checkPeriodValid(String startInput, String endInput) {
//         Date start;
//         Date end;
//         try {
//             start = DATE_FORMATTER.parse(startInput);
//             end = DATE_FORMATTER.parse(endInput);
//         } catch (NullPointerException | ParseException e) {
//             throw new IllegalArgumentException("params start and end date must be defined with YYYY-MM-DD format !");
//         }
//         if (start.after(end)) {
//             throw new IllegalArgumentException("Param startdate must be before enddate");
//         }
//     }
// 
//     public UserInfos getUserInfos() {
//         return userInfos;
//     }
// 
//     public View getView() {
//         return view;
//     }
// 
//     public Format getFormat() {
//         return format;
//     }
// 
//     public List<Long> getResourceIds() {
//         return resourceIds;
//     }
// 
//     public String getStartDate() {
//         return startDate;
//     }
// 
//     public String getEndDate() {
//         return endDate;
//     }
// 
// 
//     public void setFormat(Format format) {
//         this.format = format;
//     }
// 
//     public void setView(View view) {
//         this.view = view;
//     }
// 
//     public void setResourceIds(List<Long> resourceIds) {
//         this.resourceIds = resourceIds;
//     }
// 
//     public void setStartDate(String startDate) {
//         this.startDate = startDate;
//     }
// 
// 	public void setEndDate(String endDate) {
// 		this.endDate = endDate;
// 	}
// 
// 	public String getUserTz() {
// 		return userTz;
// 	}
// 
// 	public void setUserTz(String userTz) {
// 		this.userTz = userTz;
// 	}
// }
// 
// Path: src/main/java/net/atos/entng/rbs/model/ExportResponse.java
// public static ExportRequest.View getView(JsonObject exportResponse) {
// 	String viewAsString = exportResponse.getString(ExportRequest.VIEW, ExportRequest.View.WEEK.name());
// 	return ExportRequest.View.valueOf(viewAsString);
// }


// Path: src/main/java/net/atos/entng/rbs/service/pdf/PdfExportService.java
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import fr.wseduc.webutils.data.FileResolver;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.shareddata.LocalMap;
import net.atos.entng.rbs.model.ExportRequest;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import java.io.StringWriter;
import java.util.Locale;
import java.util.Map;
import static fr.wseduc.webutils.Utils.handlerToAsyncHandler;
import static net.atos.entng.rbs.model.ExportResponse.getView;

				return;
			}
		});
	}

	private JsonObject prepareData(JsonObject jsonExportResponse, String host, Locale locale, String userTimeZone) {
		JsonFormatter formatter = JsonFormatter.buildFormater(jsonExportResponse, host, locale, userTimeZone);

		JsonObject convertedJson = formatter.format();
		JsonArray jsonFileArray = new fr.wseduc.webutils.collections.JsonArray();
		jsonFileArray.add(convertedJson);

		return new JsonObject().put("export", jsonFileArray);
	}

	private String fillTemplate(String templateAsString, JsonObject preparedData) {
		Mustache.Compiler compiler = Mustache.compiler().defaultValue("");
		Template template = compiler.compile(templateAsString);

		Map<String, Object> ctx = new JsonObject(preparedData.toString()).getMap();

		StringWriter writer = new StringWriter();
		template.execute(ctx, writer);
		return writer.getBuffer().toString();
	}

	private String getTemplate(JsonObject exportResponse) {
		String htmlTemplateFile;
		ExportRequest.View view = getView(exportResponse);
		switch (view) {
			case DAY: