-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
481 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
owlcms/src/main/java/app/owlcms/data/technicalofficial/TechnicalOfficialWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package app.owlcms.data.technicalofficial; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
import org.apache.poi.ss.usermodel.Cell; | ||
import org.apache.poi.ss.usermodel.CellStyle; | ||
import org.apache.poi.ss.usermodel.Font; | ||
import org.apache.poi.ss.usermodel.Row; | ||
import org.apache.poi.ss.usermodel.Sheet; | ||
import org.apache.poi.ss.usermodel.Workbook; | ||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import ch.qos.logback.classic.Logger; | ||
|
||
public class TechnicalOfficialWriter { | ||
private final static Logger logger = (Logger) LoggerFactory.getLogger(TechnicalOfficialWriter.class); | ||
|
||
public static InputStream write() { | ||
try (Workbook workbook = new XSSFWorkbook()) { | ||
Sheet sheet = workbook.createSheet("Technical Officials"); | ||
|
||
// Create header style | ||
CellStyle headerStyle = workbook.createCellStyle(); | ||
Font headerFont = workbook.createFont(); | ||
headerFont.setBold(true); | ||
headerStyle.setFont(headerFont); | ||
|
||
// Create headers | ||
Row headerRow = sheet.createRow(0); | ||
String[] headers = {"LastName", "FirstName", "Level", "IWFId", "Federation", "FederationId"}; | ||
for (int i = 0; i < headers.length; i++) { | ||
Cell cell = headerRow.createCell(i); | ||
cell.setCellValue(headers[i]); | ||
cell.setCellStyle(headerStyle); | ||
} | ||
|
||
// Add data rows | ||
List<TechnicalOfficial> officials = TechnicalOfficialRepository.findAll(); | ||
int rowNum = 1; | ||
for (TechnicalOfficial official : officials) { | ||
Row row = sheet.createRow(rowNum++); | ||
row.createCell(0).setCellValue(official.getLastName() != null ? official.getLastName() : ""); | ||
row.createCell(1).setCellValue(official.getFirstName() != null ? official.getFirstName() : ""); | ||
row.createCell(2).setCellValue(official.getLevel() != null ? official.getLevel().toString() : ""); | ||
row.createCell(3).setCellValue(official.getIwfId() != null ? official.getIwfId() : ""); | ||
row.createCell(4).setCellValue(official.getFederation() != null ? official.getFederation() : ""); | ||
row.createCell(5).setCellValue(official.getFederationId() != null ? official.getFederationId() : ""); | ||
} | ||
|
||
// Autosize columns | ||
for (int i = 0; i < headers.length; i++) { | ||
sheet.autoSizeColumn(i); | ||
} | ||
|
||
// Write to byte array | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
workbook.write(outputStream); | ||
return new ByteArrayInputStream(outputStream.toByteArray()); | ||
|
||
} catch (IOException e) { | ||
logger.error("Error writing technical officials: {}", e); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
owlcms/src/main/java/app/owlcms/nui/preparation/TechnicalOfficialsUploadDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package app.owlcms.nui.preparation; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.slf4j.LoggerFactory; | ||
|
||
import com.vaadin.flow.component.button.Button; | ||
import com.vaadin.flow.component.dialog.Dialog; | ||
import com.vaadin.flow.component.html.NativeLabel; | ||
import com.vaadin.flow.component.upload.Upload; | ||
import com.vaadin.flow.component.upload.receivers.MemoryBuffer; | ||
|
||
import app.owlcms.data.technicalofficial.TechnicalOfficialReader; | ||
import app.owlcms.i18n.Translator; | ||
import ch.qos.logback.classic.Logger; | ||
|
||
@SuppressWarnings("serial") | ||
public class TechnicalOfficialsUploadDialog extends Dialog { | ||
Logger logger = (Logger) LoggerFactory.getLogger(TechnicalOfficialsUploadDialog.class); | ||
private Runnable callback; | ||
private MemoryBuffer buffer = new MemoryBuffer(); | ||
private Upload upload; | ||
|
||
public TechnicalOfficialsUploadDialog() { | ||
Button uploadButton = new Button(Translator.translate("TechnicalOfficials.Upload")); | ||
upload = new Upload(buffer); | ||
upload.setUploadButton(uploadButton); | ||
upload.setDropLabel(new NativeLabel(Translator.translate("TechnicalOfficials.UploadDropZone"))); | ||
upload.addSucceededListener(e -> { | ||
try { | ||
InputStream is = buffer.getInputStream(); | ||
TechnicalOfficialReader.importFromXLS(is); | ||
logger.warn("imported"); | ||
close(); | ||
if (callback != null) { | ||
callback.run(); | ||
} | ||
} catch (Exception ex) { | ||
// Handle error | ||
} | ||
}); | ||
add(upload); | ||
} | ||
|
||
public void setCallback(Runnable callback) { | ||
this.callback = callback; | ||
} | ||
} |
Oops, something went wrong.