/*
 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.optapconf.plannerbenchmark;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.optaplanner.core.api.domain.solution.Solution;
import org.optaplanner.persistence.common.api.domain.solution.SolutionFileIO;

public class ConferenceFileIO implements SolutionFileIO {

    @Override
    public String getInputFileExtension() {
        return "xlsx";
    }

    @Override
    public String getOutputFileExtension() {
        return "xlsx";
    }

    @Override
    public Solution read(File inputSolutionFile) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void write(Solution solution, File outputSolutionFile) {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("Conference");
        try {
            try (OutputStream out = new FileOutputStream(outputSolutionFile)) {
                workbook.write(out);
                workbook.close();
            }
        } catch (IOException e) {
            throw new IllegalStateException("Problem writing outputSolutionFile (" + outputSolutionFile + ").", e);
        }
    }
}

@@ -816,106 +816,430 @@
 on;%0A
-%0Aimport org.apache.poi.xssf.usermodel.XSSFSheet;%0Aimport org.apache.poi.xssf.usermodel.XSSFWorkbook
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport org.apache.poi.ss.usermodel.Cell;%0Aimport org.apache.poi.xssf.usermodel.XSSFCell;%0Aimport org.apache.poi.xssf.usermodel.XSSFRow;%0Aimport org.apache.poi.xssf.usermodel.XSSFSheet;%0Aimport org.apache.poi.xssf.usermodel.XSSFWorkbook;%0Aimport org.optaconf.domain.Conference;%0Aimport org.optaconf.domain.Room;%0Aimport org.optaconf.domain.Talk;%0Aimport org.optaconf.domain.Timeslot
 ;%0Aim
@@ -1806,32 +1806,87 @@
 SolutionFile) %7B%0A
+        Conference conference = (Conference) solution;%0A
         XSSFWork
@@ -1983,16 +1983,1370 @@
 ence%22);%0A
+        XSSFRow headerRow = sheet.createRow(0);%0A        int x = 1;%0A        Map%3CRoom, Integer%3E roomXMap = new HashMap%3C%3E(conference.getRoomList().size());%0A        for (Room room : conference.getRoomList()) %7B%0A            XSSFCell cell = headerRow.createCell(x);%0A            cell.setCellValue(room.getName());%0A            roomXMap.put(room, x);%0A            x++;%0A        %7D%0A        int y = 1;%0A        Map%3CTimeslot, XSSFRow%3E timeslotRowMap = new HashMap%3C%3E(conference.getTimeslotList().size());%0A        for (Timeslot timeslot : conference.getTimeslotList()) %7B%0A            XSSFRow row = sheet.createRow(y);%0A            XSSFCell cell = row.createCell(0);%0A            cell.setCellValue(timeslot.getDay().getName() + %22 - %22 + timeslot.getName());%0A            timeslotRowMap.put(timeslot, row);%0A            y++;%0A        %7D%0A        for (Talk talk : conference.getTalkList()) %7B%0A            Timeslot timeslot = talk.getTimeslot();%0A            Room room = talk.getRoom();%0A            if (timeslot != null && room != null) %7B%0A                XSSFCell cell = timeslotRowMap.get(timeslot).createCell(roomXMap.get(room));%0A                cell.setCellValue(talk.getTitle());%0A            %7D else %7B%0A                XSSFCell unassignedCell = sheet.createRow(y).createCell(1);%0A                unassignedCell.setCellValue(talk.getTitle());%0A                y++;%0A            %7D%0A        %7D%0A
         

Add XLSX output content