[EDIT] CAMBIO 10 06 2024

parent 72a5609b
...@@ -31,14 +31,10 @@ public class ConsoleApi { ...@@ -31,14 +31,10 @@ public class ConsoleApi {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
output.append(line).append("\n"); output.append("\n").append(line);
} }
process.waitFor();
int exitCode = process.waitFor(); return ResponseEntity.ok(output.toString().replace("[sudo] contraseña para wildfly: ",""));
return ResponseEntity.ok(
"Exit Code: " + exitCode + "\n" +
output.toString());
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
...@@ -3,6 +3,7 @@ package web.multitask.trismegistoservices.config; ...@@ -3,6 +3,7 @@ package web.multitask.trismegistoservices.config;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration; import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry; import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
...@@ -42,5 +43,4 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { ...@@ -42,5 +43,4 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
public void configureClientInboundChannel(ChannelRegistration registration) { public void configureClientInboundChannel(ChannelRegistration registration) {
registration.interceptors(authChannelInterceptorAdapter); registration.interceptors(authChannelInterceptorAdapter);
} }
} }
\ No newline at end of file
...@@ -30,11 +30,10 @@ import org.springframework.stereotype.Service; ...@@ -30,11 +30,10 @@ import org.springframework.stereotype.Service;
@Service @Service
public class ExcelService { public class ExcelService {
public byte[] generateExcel(JSONObject json,int size) throws IOException { public byte[] generateExcel(JSONObject json, int size) throws IOException {
ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
// org.apache.poi.ss.usermodel.Workbook workbook s= WorkbookFactory.create(new File(System.getProperty("tmpdir") + "/file.xlsx")); createSheet(workbook, json, size);
createSheet(workbook, json,size);
try { try {
workbook.write(outByteStream); workbook.write(outByteStream);
workbook.close(); workbook.close();
...@@ -57,54 +56,56 @@ public class ExcelService { ...@@ -57,54 +56,56 @@ public class ExcelService {
buildSheet(workbook, sheet, json); buildSheet(workbook, sheet, json);
JSONArray identifiers = json.getJSONArray("identifiers"); JSONArray identifiers = json.getJSONArray("identifiers");
for (int i = 0; i < identifiers.length(); i++) { for (int i = 0; i < identifiers.length(); i++) {
// sheet.setColumnWidth(i, 16 * 512); if (json.optBoolean("auto_adjustment", true)) {
findLargerTextByIdentifer(sheet,json.getJSONArray("data"),identifiers); findLargerTextByIdentifer(sheet, json.getJSONArray("data"), identifiers);
}
}
for (int j = 0; j < json.optJSONArray("columns_size", new JSONArray()).length(); j++) {
if (json.getJSONArray("columns_size").getInt(j) > 0) {
sheet.setColumnWidth(j, json.getJSONArray("columns_size").getInt(j));
}
} }
} else { } else {
JSONArray sheetArray = json.optJSONArray("sheetArray", new JSONArray()); JSONArray sheetArray = json.optJSONArray("sheetArray", new JSONArray());
// if (sizeOfBytes < 100000) {
for (int i = 0; i < sheetArray.length(); i++) { for (int i = 0; i < sheetArray.length(); i++) {
JSONObject jsonObject = sheetArray.getJSONObject(i); JSONObject jsonObject = sheetArray.getJSONObject(i);
XSSFSheet sheet = workbook.createSheet(jsonObject.optString("sheet_name", "no_name")); XSSFSheet sheet = workbook.createSheet(jsonObject.optString("sheet_name", "no_name"));
JSONArray identifiers = jsonObject.getJSONArray("identifiers"); JSONArray identifiers = jsonObject.getJSONArray("identifiers");
for (int j = 0; j < identifiers.length(); j++) { for (int j = 0; j < identifiers.length(); j++) {
// sheet.setColumnWidth(j, 16 * 512); if (jsonObject.optBoolean("auto_adjustment", true)) {
findLargerTextByIdentifer(sheet,jsonObject.getJSONArray("data"),identifiers); findLargerTextByIdentifer(sheet, jsonObject.getJSONArray("data"), identifiers);
}
} }
buildSheet(workbook, sheet, jsonObject); buildSheet(workbook, sheet, jsonObject);
if (!jsonObject.optBoolean("auto_adjustment", true)) {
for (int k = 0; k < jsonObject.getJSONArray("columns_size").length(); k++) {
sheet.autoSizeColumn(k);
}
}
for (int j = 0; j < jsonObject.optJSONArray("columns_size", new JSONArray()).length(); j++) {
if (jsonObject.getJSONArray("columns_size").getInt(j) > 0) {
sheet.setColumnWidth(j, jsonObject.getJSONArray("columns_size").getInt(j));
}
}
} }
// } else {
// sheetArray.toList().stream().parallel().forEach(sheetObject -> {
// HashMap<String, Object> sheetMap = (HashMap<String, Object>) sheetObject;
// JSONObject jsonObject = new JSONObject(sheetMap);
// XSSFSheet sheet = workbook.createSheet(jsonObject.optString("sheet_name", "no_name"));
// JSONArray identifiers = jsonObject.getJSONArray("identifiers");
// for (int j = 0; j < identifiers.length(); j++) {
// sheet.setColumnWidth(j, 16 * 512);
// }
// CompletableFuture<Boolean> result = buildSheetAsync(workbook, sheet, jsonObject);
// results.get().add(result);
// });
// CompletableFuture.allOf(results.get().toArray(new CompletableFuture[0])).join();
// }
} }
} }
private void findLargerTextByIdentifer(XSSFSheet sheet,JSONArray data, JSONArray identifiers){ private void findLargerTextByIdentifer(XSSFSheet sheet, JSONArray data, JSONArray identifiers) {
int[] maxLengthByIdentifier = new int[identifiers.length()]; int[] maxLengthByIdentifier = new int[identifiers.length()];
for (int i = 0; i < data.length(); i++) { for (int i = 0; i < data.length(); i++) {
JSONObject row_data = data.optJSONObject(i); JSONObject row_data = data.optJSONObject(i);
for (int j = 0; j < identifiers.length(); j++) { for (int j = 0; j < identifiers.length(); j++) {
int length = row_data.optString(identifiers.optString(j, "")).length(); int length = row_data.optString(identifiers.optString(j, "")).length();
int length2 = row_data.optString(String.valueOf(j), "").length(); int length2 = row_data.optString(String.valueOf(j), "").length();
if(length > maxLengthByIdentifier[j] || length2 > maxLengthByIdentifier[j]){ if (length > maxLengthByIdentifier[j] || length2 > maxLengthByIdentifier[j]) {
maxLengthByIdentifier[j] = Math.max(length, length2); maxLengthByIdentifier[j] = Math.max(length, length2);
} }
} }
} }
for (int i = 0; i < maxLengthByIdentifier.length; i++) { for (int i = 0; i < maxLengthByIdentifier.length; i++) {
sheet.setColumnWidth(i, ((maxLengthByIdentifier[i] * 333))); sheet.setColumnWidth(i, ((maxLengthByIdentifier[i] * 375)));
} }
} }
...@@ -122,68 +123,70 @@ public class ExcelService { ...@@ -122,68 +123,70 @@ public class ExcelService {
JSONArray data = json.optJSONArray("data", new JSONArray()); JSONArray data = json.optJSONArray("data", new JSONArray());
JSONArray styles = json.optJSONArray("styles", new JSONArray()); JSONArray styles = json.optJSONArray("styles", new JSONArray());
fillStylesArray(styles,workbook,stylesSaved,styleObjectsSaved); fillStylesArray(styles, workbook, stylesSaved, styleObjectsSaved);
int i = 0; int i = 0;
if(json.has("title")){ if (json.has("title")) {
row = sheet.createRow(i); row = sheet.createRow(i);
JSONObject titleJson = json.getJSONObject("title"); JSONObject titleJson = json.getJSONObject("title");
JSONObject style = titleJson.optJSONObject("style", new JSONObject()); JSONObject style = titleJson.optJSONObject("style", new JSONObject());
cell = row.createCell(0); cell = row.createCell(0);
cell.setCellValue(titleJson.optString("text","")); cell.setCellValue(titleJson.optString("text", ""));
if(style.isEmpty()){ if (style.isEmpty()) {
cell.setCellStyle(defaultStyle); cell.setCellStyle(defaultStyle);
}else{ } else {
if(!stylesSaved.contains(style.toString())){ if (!stylesSaved.contains(style.toString())) {
stylesSaved.add(style.toString()); stylesSaved.add(style.toString());
cellStyle = createCellStyle(workbook,style); cellStyle = createCellStyle(workbook, style);
cell.setCellStyle(cellStyle); cell.setCellStyle(cellStyle);
styleObjectsSaved.add(cellStyle); styleObjectsSaved.add(cellStyle);
}else{ } else {
cell.setCellStyle(styleObjectsSaved.get(stylesSaved.indexOf(style.toString()))); cell.setCellStyle(styleObjectsSaved.get(stylesSaved.indexOf(style.toString())));
} }
} }
sheet.addMergedRegion(new CellRangeAddress(i, i, 0, style.getInt("colspan")-1)); sheet.addMergedRegion(new CellRangeAddress(i, i, 0, style.getInt("colspan") - 1));
i++; i++;
} }
for (; i < data.length(); i++) { for (; i < data.length(); i++) {
int index = json.has("title") ? i-1 : i; int index = json.has("title") ? i - 1 : i;
row = sheet.createRow(i); row = sheet.createRow(i);
JSONObject row_data = data.optJSONObject(index); JSONObject row_data = data.optJSONObject(index);
for (int j = 0; j < identifiers.length(); j++) { for (int j = 0; j < identifiers.length(); j++) {
cell = row.createCell(j); cell = row.createCell(j);
JSONArray styleArray = styles.optJSONArray(index, new JSONArray()); JSONArray styleArray = styles.optJSONArray(index, new JSONArray());
JSONObject style = styleArray.optJSONObject(j, new JSONObject()); JSONObject style = styleArray.optJSONObject(j, new JSONObject());
String value = row_data.optString(identifiers.getString(j),row_data.optString(String.valueOf(j), "")); String value = row_data.optString(identifiers.getString(j), row_data.optString(String.valueOf(j), ""));
if(style.isEmpty()){
if (style.isEmpty()) {
cell.setCellStyle(defaultStyle); cell.setCellStyle(defaultStyle);
cell.setCellValue(value); cell.setCellValue(value);
}else{ } else {
if(!stylesSaved.contains(style.toString())){ if (!stylesSaved.contains(style.toString())) {
stylesSaved.add(style.toString()); stylesSaved.add(style.toString());
cellStyle = createCellStyle(workbook,style); cellStyle = createCellStyle(workbook, style);
cell.setCellStyle(cellStyle); cell.setCellStyle(cellStyle);
styleObjectsSaved.add(cellStyle); styleObjectsSaved.add(cellStyle);
cell.setCellValue(value); cell.setCellValue(value);
}else{ } else {
cell.setCellStyle(styleObjectsSaved.get(stylesSaved.indexOf(style.toString()))); cell.setCellStyle(styleObjectsSaved.get(stylesSaved.indexOf(style.toString())));
cell.setCellValue(value); cell.setCellValue(value);
} }
if(style.has("format")){ if (style.has("format")) {
setCellFormat(cell,style.optString("format","text"),value ); setCellFormat(cell, style.optString("format", "text"), value);
} }
if(style.has("colspan")){ if (style.has("colspan")) {
sheet.addMergedRegion(new CellRangeAddress(i, i, j, j + style.optInt("colspan", 0))); sheet.addMergedRegion(new CellRangeAddress(i, i, j, j + style.optInt("colspan", 0)));
} }
} }
} }
} }
} }
public void setCellFormat (XSSFCell cell, String format, String value){ public void setCellFormat(XSSFCell cell, String format, String value) {
switch (format){ switch (format) {
case "number": case "number":
cell.setCellType(CellType.NUMERIC); cell.setCellType(CellType.NUMERIC);
XSSFCellStyle style = cell.getCellStyle(); XSSFCellStyle style = cell.getCellStyle();
...@@ -206,48 +209,6 @@ public class ExcelService { ...@@ -206,48 +209,6 @@ public class ExcelService {
break; break;
} }
} }
// @Async
// public CompletableFuture<Boolean> buildSheetAsync(XSSFWorkbook workbook, XSSFSheet sheet, JSONObject json) {
//
// final XSSFCellStyle defaultStyle = createCellStyle(workbook, new JSONObject());
// List<String> stylesSaved = new ArrayList<>();
// List<XSSFCellStyle> styleObjectsSaved = new ArrayList<>();
//
// XSSFRow row;
// XSSFCell cell;
// XSSFCellStyle cellStyle;
//
// JSONArray identifiers = json.optJSONArray("identifiers", new JSONArray());
// JSONArray data = json.optJSONArray("data", new JSONArray());
// JSONArray styles = json.optJSONArray("styles", new JSONArray());
//
// fillStylesArray(styles,workbook,stylesSaved,styleObjectsSaved);
//
// for (int i = 0; i < data.length(); i++) {
// row = sheet.createRow(i);
// JSONObject row_data = data.optJSONObject(i);
// for (int j = 0; j < identifiers.length(); j++) {
// cell = row.createCell(j);
// JSONArray styleArray = styles.optJSONArray(i, new JSONArray());
// JSONObject style = styleArray.optJSONObject(j, new JSONObject());
// if(style.isEmpty()){
// cell.setCellStyle(defaultStyle);
// }else{
// if(!stylesSaved.contains(style.toString())){
// stylesSaved.add(style.toString());
// cellStyle = createCellStyle(workbook,style);
// cell.setCellStyle(cellStyle);
// styleObjectsSaved.add(cellStyle);
// }else{
// cell.setCellStyle(styleObjectsSaved.get(stylesSaved.indexOf(style.toString())));
// }
// }
// cell.setCellValue(row_data.optString(identifiers.optString(j, "")));
// }
// }
//
// return CompletableFuture.completedFuture(true);
// }
private XSSFCellStyle createCellStyle(XSSFWorkbook workbook, JSONObject styleJson) { private XSSFCellStyle createCellStyle(XSSFWorkbook workbook, JSONObject styleJson) {
...@@ -258,7 +219,7 @@ public class ExcelService { ...@@ -258,7 +219,7 @@ public class ExcelService {
String align = styleJson.optString("textAlign", "center"); String align = styleJson.optString("textAlign", "center");
XSSFCellStyle style = workbook.createCellStyle(); XSSFCellStyle style = workbook.createCellStyle();
Font font = workbook.createFont(); Font font = workbook.createFont();
style.setAlignment( align.equals("center") ? HorizontalAlignment.CENTER : align.equals("left") ? HorizontalAlignment.LEFT : HorizontalAlignment.RIGHT); style.setAlignment(align.equals("center") ? HorizontalAlignment.CENTER : align.equals("left") ? HorizontalAlignment.LEFT : HorizontalAlignment.RIGHT);
style.setWrapText(styleJson.optBoolean("wrapText", false)); style.setWrapText(styleJson.optBoolean("wrapText", false));
style.setVerticalAlignment(VerticalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
...@@ -272,7 +233,11 @@ public class ExcelService { ...@@ -272,7 +233,11 @@ public class ExcelService {
style.setBorderColor(BorderSide.TOP, getXSSFColor("#333333")); style.setBorderColor(BorderSide.TOP, getXSSFColor("#333333"));
style.setBorderColor(BorderSide.LEFT, getXSSFColor("#333333")); style.setBorderColor(BorderSide.LEFT, getXSSFColor("#333333"));
style.setBorderColor(BorderSide.RIGHT, getXSSFColor("#333333")); style.setBorderColor(BorderSide.RIGHT, getXSSFColor("#333333"));
}else{ } else {
style.setBorderBottom(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderColor(BorderSide.BOTTOM, getXSSFColor("#aaaaaa")); style.setBorderColor(BorderSide.BOTTOM, getXSSFColor("#aaaaaa"));
style.setBorderColor(BorderSide.TOP, getXSSFColor("#aaaaaa")); style.setBorderColor(BorderSide.TOP, getXSSFColor("#aaaaaa"));
style.setBorderColor(BorderSide.LEFT, getXSSFColor("#aaaaaa")); style.setBorderColor(BorderSide.LEFT, getXSSFColor("#aaaaaa"));
...@@ -299,8 +264,7 @@ public class ExcelService { ...@@ -299,8 +264,7 @@ public class ExcelService {
int blue = Integer.parseInt(rgb.substring(5, 7), 16); int blue = Integer.parseInt(rgb.substring(5, 7), 16);
Color awtColor = new Color(red, green, blue); Color awtColor = new Color(red, green, blue);
XSSFColor xssfColor = new XSSFColor(); XSSFColor xssfColor = new XSSFColor();
xssfColor xssfColor.setRGB(new byte[]{(byte) awtColor.getRed(), (byte) awtColor.getGreen(), (byte) awtColor.getBlue()});
.setRGB(new byte[] { (byte) awtColor.getRed(), (byte) awtColor.getGreen(), (byte) awtColor.getBlue() });
return xssfColor; return xssfColor;
} }
...@@ -318,9 +282,9 @@ public class ExcelService { ...@@ -318,9 +282,9 @@ public class ExcelService {
JSONArray styleArray = styles.optJSONArray(i, new JSONArray()); JSONArray styleArray = styles.optJSONArray(i, new JSONArray());
for (int j = 0; j < styleArray.length(); j++) { for (int j = 0; j < styleArray.length(); j++) {
JSONObject style = styleArray.optJSONObject(j, new JSONObject()); JSONObject style = styleArray.optJSONObject(j, new JSONObject());
if(!stylesSaved.contains(style.toString())){ if (!stylesSaved.contains(style.toString())) {
stylesSaved.add(style.toString()); stylesSaved.add(style.toString());
XSSFCellStyle cellStyle = createCellStyle(workbook,style); XSSFCellStyle cellStyle = createCellStyle(workbook, style);
styleObjectsSaved.add(cellStyle); styleObjectsSaved.add(cellStyle);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment