[EDIT] CAMBIO 10 06 2024

parent 72a5609b
......@@ -31,14 +31,10 @@ public class ConsoleApi {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
output.append("\n").append(line);
}
int exitCode = process.waitFor();
return ResponseEntity.ok(
"Exit Code: " + exitCode + "\n" +
output.toString());
process.waitFor();
return ResponseEntity.ok(output.toString().replace("[sudo] contraseña para wildfly: ",""));
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
......
......@@ -3,6 +3,7 @@ package web.multitask.trismegistoservices.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
......@@ -42,5 +43,4 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
public void configureClientInboundChannel(ChannelRegistration registration) {
registration.interceptors(authChannelInterceptorAdapter);
}
}
\ No newline at end of file
......@@ -28,13 +28,12 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.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();
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 {
workbook.write(outByteStream);
workbook.close();
......@@ -57,54 +56,56 @@ public class ExcelService {
buildSheet(workbook, sheet, json);
JSONArray identifiers = json.getJSONArray("identifiers");
for (int i = 0; i < identifiers.length(); i++) {
// sheet.setColumnWidth(i, 16 * 512);
findLargerTextByIdentifer(sheet,json.getJSONArray("data"),identifiers);
if (json.optBoolean("auto_adjustment", true)) {
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 {
JSONArray sheetArray = json.optJSONArray("sheetArray", new JSONArray());
// if (sizeOfBytes < 100000) {
for (int i = 0; i < sheetArray.length(); i++) {
JSONObject jsonObject = sheetArray.getJSONObject(i);
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);
findLargerTextByIdentifer(sheet,jsonObject.getJSONArray("data"),identifiers);
for (int i = 0; i < sheetArray.length(); i++) {
JSONObject jsonObject = sheetArray.getJSONObject(i);
XSSFSheet sheet = workbook.createSheet(jsonObject.optString("sheet_name", "no_name"));
JSONArray identifiers = jsonObject.getJSONArray("identifiers");
for (int j = 0; j < identifiers.length(); j++) {
if (jsonObject.optBoolean("auto_adjustment", true)) {
findLargerTextByIdentifer(sheet, jsonObject.getJSONArray("data"), identifiers);
}
buildSheet(workbook, sheet, jsonObject);
}
// } 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();
// }
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));
}
}
}
}
}
private void findLargerTextByIdentifer(XSSFSheet sheet,JSONArray data, JSONArray identifiers){
private void findLargerTextByIdentifer(XSSFSheet sheet, JSONArray data, JSONArray identifiers) {
int[] maxLengthByIdentifier = new int[identifiers.length()];
for (int i = 0; i < data.length(); i++) {
JSONObject row_data = data.optJSONObject(i);
for (int j = 0; j < identifiers.length(); j++) {
int length = row_data.optString(identifiers.optString(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);
}
}
}
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 {
JSONArray data = json.optJSONArray("data", new JSONArray());
JSONArray styles = json.optJSONArray("styles", new JSONArray());
fillStylesArray(styles,workbook,stylesSaved,styleObjectsSaved);
fillStylesArray(styles, workbook, stylesSaved, styleObjectsSaved);
int i = 0;
if(json.has("title")){
if (json.has("title")) {
row = sheet.createRow(i);
JSONObject titleJson = json.getJSONObject("title");
JSONObject style = titleJson.optJSONObject("style", new JSONObject());
JSONObject style = titleJson.optJSONObject("style", new JSONObject());
cell = row.createCell(0);
cell.setCellValue(titleJson.optString("text",""));
if(style.isEmpty()){
cell.setCellValue(titleJson.optString("text", ""));
if (style.isEmpty()) {
cell.setCellStyle(defaultStyle);
}else{
if(!stylesSaved.contains(style.toString())){
} else {
if (!stylesSaved.contains(style.toString())) {
stylesSaved.add(style.toString());
cellStyle = createCellStyle(workbook,style);
cellStyle = createCellStyle(workbook, style);
cell.setCellStyle(cellStyle);
styleObjectsSaved.add(cellStyle);
}else{
} else {
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++;
}
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);
JSONObject row_data = data.optJSONObject(index);
for (int j = 0; j < identifiers.length(); j++) {
cell = row.createCell(j);
JSONArray styleArray = styles.optJSONArray(index, new JSONArray());
JSONObject style = styleArray.optJSONObject(j, new JSONObject());
String value = row_data.optString(identifiers.getString(j),row_data.optString(String.valueOf(j), ""));
if(style.isEmpty()){
String value = row_data.optString(identifiers.getString(j), row_data.optString(String.valueOf(j), ""));
if (style.isEmpty()) {
cell.setCellStyle(defaultStyle);
cell.setCellValue(value);
}else{
if(!stylesSaved.contains(style.toString())){
} else {
if (!stylesSaved.contains(style.toString())) {
stylesSaved.add(style.toString());
cellStyle = createCellStyle(workbook,style);
cellStyle = createCellStyle(workbook, style);
cell.setCellStyle(cellStyle);
styleObjectsSaved.add(cellStyle);
cell.setCellValue(value);
}else{
} else {
cell.setCellStyle(styleObjectsSaved.get(stylesSaved.indexOf(style.toString())));
cell.setCellValue(value);
}
if(style.has("format")){
setCellFormat(cell,style.optString("format","text"),value );
if (style.has("format")) {
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)));
}
}
}
}
}
public void setCellFormat (XSSFCell cell, String format, String value){
switch (format){
public void setCellFormat(XSSFCell cell, String format, String value) {
switch (format) {
case "number":
cell.setCellType(CellType.NUMERIC);
XSSFCellStyle style = cell.getCellStyle();
......@@ -206,48 +209,6 @@ public class ExcelService {
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) {
......@@ -258,7 +219,7 @@ public class ExcelService {
String align = styleJson.optString("textAlign", "center");
XSSFCellStyle style = workbook.createCellStyle();
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.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
......@@ -272,7 +233,11 @@ public class ExcelService {
style.setBorderColor(BorderSide.TOP, getXSSFColor("#333333"));
style.setBorderColor(BorderSide.LEFT, 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.TOP, getXSSFColor("#aaaaaa"));
style.setBorderColor(BorderSide.LEFT, getXSSFColor("#aaaaaa"));
......@@ -299,8 +264,7 @@ public class ExcelService {
int blue = Integer.parseInt(rgb.substring(5, 7), 16);
Color awtColor = new Color(red, green, blue);
XSSFColor xssfColor = new XSSFColor();
xssfColor
.setRGB(new byte[] { (byte) awtColor.getRed(), (byte) awtColor.getGreen(), (byte) awtColor.getBlue() });
xssfColor.setRGB(new byte[]{(byte) awtColor.getRed(), (byte) awtColor.getGreen(), (byte) awtColor.getBlue()});
return xssfColor;
}
......@@ -318,9 +282,9 @@ public class ExcelService {
JSONArray styleArray = styles.optJSONArray(i, new JSONArray());
for (int j = 0; j < styleArray.length(); j++) {
JSONObject style = styleArray.optJSONObject(j, new JSONObject());
if(!stylesSaved.contains(style.toString())){
if (!stylesSaved.contains(style.toString())) {
stylesSaved.add(style.toString());
XSSFCellStyle cellStyle = createCellStyle(workbook,style);
XSSFCellStyle cellStyle = createCellStyle(workbook, style);
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