Migliorie process report

This commit is contained in:
2024-11-12 10:41:00 +01:00
parent 417fd440fd
commit c3a262e31b
7 changed files with 113 additions and 201 deletions

View File

@@ -82,6 +82,21 @@
<option name="PROGRAM_PARAMETERS" value="" />
</SHUTDOWN>
</ConfigurationWrapper>
<ConfigurationWrapper VM_VAR="JAVA_OPTS" RunnerId="Profile ">
<option name="USE_ENV_VARIABLES" value="true" />
<STARTUP>
<option name="USE_DEFAULT" value="true" />
<option name="SCRIPT" value="" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
</STARTUP>
<SHUTDOWN>
<option name="USE_DEFAULT" value="true" />
<option name="SCRIPT" value="" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
</SHUTDOWN>
</ConfigurationWrapper>
<ConfigurationWrapper VM_VAR="JAVA_OPTS" RunnerId="Run">
<option name="USE_ENV_VARIABLES" value="true" />
<STARTUP>

View File

@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tomcat (FAST)" type="#com.intellij.j2ee.web.tomcat.TomcatRunConfigurationFactory" factoryName="Local" APPLICATION_SERVER_NAME="Tomcat" ALTERNATIVE_JRE_ENABLED="false">
<option name="COMMON_VM_ARGUMENTS" value="-DDISABLE_DROOLS_COMPILE=TRUE -Xms6G -Xmx6G -XX:MaxPermSize=1G -XX:PermSize=512M" />
<option name="COMMON_VM_ARGUMENTS" value="-DDISABLE_DROOLS_COMPILE=TRUE -Xms1G -Xmx6G" />
<deployment>
<artifact name="ems-engine:war exploded">
<settings>
@@ -82,6 +82,21 @@
<option name="PROGRAM_PARAMETERS" value="" />
</SHUTDOWN>
</ConfigurationWrapper>
<ConfigurationWrapper VM_VAR="JAVA_OPTS" RunnerId="Profile ">
<option name="USE_ENV_VARIABLES" value="true" />
<STARTUP>
<option name="USE_DEFAULT" value="true" />
<option name="SCRIPT" value="" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
</STARTUP>
<SHUTDOWN>
<option name="USE_DEFAULT" value="true" />
<option name="SCRIPT" value="" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
</SHUTDOWN>
</ConfigurationWrapper>
<ConfigurationWrapper VM_VAR="JAVA_OPTS" RunnerId="Run">
<option name="USE_ENV_VARIABLES" value="true" />
<STARTUP>

View File

@@ -11,6 +11,7 @@ import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.service.HttpRestWrapper;
import it.integry.ems.settings.Model.AvailableConnectionsModel;
import it.integry.ems.settings.Model.SettingsModel;
import it.integry.ems.sync.MultiDBTransaction.Connection;
import it.integry.ems.utility.UtilityDebug;
import it.integry.ems_model.config.EmsRestConstants;
import it.integry.ems_model.utility.UtilityDB;
@@ -21,8 +22,6 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import it.integry.ems.sync.MultiDBTransaction.Connection;
import java.util.HashMap;
import java.util.List;
@@ -62,19 +61,16 @@ public class LicenseComponent {
final HashMap<String, String> listAziende = new HashMap<>();
for (AvailableConnectionsModel model : settingsModel.getAvailableConnections()) {
if (model.getInternalDb()) {
for (AvailableConnectionsModel model : settingsModel.getAvailableConnections(true)) {
DataSource ds = new DataSource();
ds.initialize(model.getProfileName());
Connection conn = ds.getConnection();
DataSource ds = new DataSource();
ds.initialize(model.getProfileName());
Connection conn = ds.getConnection();
String sql = "SELECT part_iva FROM azienda WHERE part_iva is not null";
String partIva = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
if (!UtilityString.isNullOrEmpty(partIva)) listAziende.put(model.getProfileName(), partIva);
String sql = "SELECT part_iva FROM azienda WHERE part_iva is not null";
String partIva = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
if (!UtilityString.isNullOrEmpty(partIva)) listAziende.put(model.getProfileName(), partIva);
ds.forceClose();
}
ds.forceClose();
}
String jsonBody = jsonObjectMapper.writeValueAsString(listAziende.values());

View File

@@ -10,7 +10,6 @@ import java.util.List;
import java.util.Map;
public class JasperDTO {
private String b64XmlReport;//alternativa al resto, possibilmente dismetterlo
private byte[] compiledJasper;
private Long reportId;
private String reportName;
@@ -42,15 +41,6 @@ public class JasperDTO {
return this;
}
public String getB64XmlReport() {
return b64XmlReport;
}
public JasperDTO setB64XmlReport(String b64XmlReport) {
this.b64XmlReport = b64XmlReport;
return this;
}
public byte[] getCompiledJasper() {
return compiledJasper;
}

View File

@@ -14,7 +14,10 @@ import it.integry.ems.utility.UtilityURL;
import it.integry.ems_model.entity.WtbJrept;
import it.integry.ems_model.entity.WtbJreptSetup;
import it.integry.ems_model.service.SetupGest;
import it.integry.ems_model.utility.*;
import it.integry.ems_model.utility.Query;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityHashMap;
import it.integry.ems_model.utility.UtilityString;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.data.JsonDataSource;
@@ -38,12 +41,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@Service
@Scope("request")
@@ -73,118 +76,46 @@ public class ReportProcessor {
return UtilityDirs.getEmsApiTempDirectoryPath() + File.separator + "report_jasper" + File.separator;
}
public JasperDTO XMLToDTO(String xmlDto) throws Exception {
String b64Jrxml = null, query = null, whereCond = null, jsonSource = null,
params = null, /*formatoExport = null,*/ name = null;
JasperDTO jasperDTO = null;
Document doc = UtilityXML.convertStringToDocument(xmlDto);
if (doc == null) {
throw new Exception("XML non valido");
}
if (doc.getElementsByTagName("QUERY") != null && doc.getElementsByTagName("QUERY").getLength() > 0) {
query = doc.getElementsByTagName("QUERY").item(0).getTextContent();
}
if (doc.getElementsByTagName("WHERE_COND") != null && doc.getElementsByTagName("WHERE_COND").getLength() > 0) {
whereCond = doc.getElementsByTagName("WHERE_COND").item(0).getTextContent();
}
if (doc.getElementsByTagName("JSON_SOURCE") != null && doc.getElementsByTagName("JSON_SOURCE").getLength() > 0) {
jsonSource = doc.getElementsByTagName("JSON_SOURCE").item(0).getTextContent();
}
if (doc.getElementsByTagName("PARAMS") != null && doc.getElementsByTagName("PARAMS").getLength() > 0) {
params = doc.getElementsByTagName("PARAMS").item(0).getTextContent();
}
if (doc.getElementsByTagName("NAME") != null && doc.getElementsByTagName("NAME").getLength() > 0) {
name = doc.getElementsByTagName("NAME").item(0).getTextContent();
}
if (doc.getElementsByTagName("B64_JRXML") != null && doc.getElementsByTagName("B64_JRXML").getLength() > 0) {
b64Jrxml = doc.getElementsByTagName("B64_JRXML").item(0).getTextContent();
}
jasperDTO = new JasperDTO();
if (!UtilityString.isNullOrEmpty(name)) {
jasperDTO.setReportId(this.getReportID(name));
} else {
if (b64Jrxml != null) {
jasperDTO.setB64ReportJrxml(b64Jrxml);
Node subreports = doc.getElementsByTagName("SUB_REPORTS").item(0);
NodeList nodeListSubRep = subreports.getChildNodes();
List<SubreportDTO> subreportsList = new ArrayList<SubreportDTO>();
for (int i = 0; i < nodeListSubRep.getLength(); i++) {
SubreportDTO dto = new SubreportDTO();
Node currentNode = nodeListSubRep.item(i);
String jasperFilename = currentNode.getAttributes().getNamedItem("FILENAME").getNodeValue();
Node firstChild = currentNode.getFirstChild();
if ("B64_JASPER".equals(firstChild.getNodeName())) {
dto.setB64Report(firstChild.getTextContent()); // "B64_JASPER";
} else if ("B64_JRXML".equals(firstChild.getNodeName())) {
dto.setB64Jrxml(firstChild.getTextContent()); // "B64_JRXML";
}
dto.setName(jasperFilename);
subreportsList.add(dto);
}
jasperDTO.setSubreports(subreportsList);
} else {
throw new Exception("Report non identificato");
}
}
jasperDTO.setQuery(query);
jasperDTO.setWhereCond(whereCond);
jasperDTO.setJsonSource(jsonSource);
if (!UtilityString.isNullOrEmpty(params)) {
params = params.replaceAll("'", "\"");
PairsDTO[] pairs = jsonObjectMapper.readValue(params, PairsDTO[].class);
jasperDTO.setParams(Arrays.asList(pairs));
}
return jasperDTO;
}
private String prepareTempReportFile(JasperDTO jasperDTO, ArrayList<String> fileTempList) throws Exception {
String pathJrxml = null;
String b64ReportJrxml = jasperDTO.getB64ReportJrxml();
if (jasperDTO.getReportId() != null) {
JasperDTO jasperDTOTmp = this.getReportByID(jasperDTO.getReportId());
if (b64ReportJrxml == null) {
b64ReportJrxml = jasperDTOTmp.getB64ReportJrxml();
jasperDTO.setB64ReportJrxml(b64ReportJrxml)
.setCompiledJasper(jasperDTOTmp.getCompiledJasper());
}
if (jasperDTO.getSubreports() == null) {
jasperDTO.setSubreports(jasperDTOTmp.getSubreports());
}
}
/*
if(reportName != null && b64ReportJrxml==null) {
JasperDTO jasperDTOTmp = this.getReportByName(reportName);
b64ReportJrxml = jasperDTOTmp.getB64ReportJrxml();
jasperDTO.setB64ReportJrxml(jasperDTOTmp.getB64ReportJrxml());
jasperDTO.setSubreports(jasperDTOTmp.getSubreports());
}*/
if (b64ReportJrxml != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS");
String pathJrxmlTemp = this.getPathJrxmlTemp();
pathJrxml = pathJrxmlTemp + "tmp" + sdf.format(new Date()) + ".jrxml";
FileOutputStream fos = new FileOutputStream(new File(pathJrxml));
IOUtils.write(Base64.decodeBase64(b64ReportJrxml), fos);
fos.close();
fileTempList.add(pathJrxml);
} else {
throw new Exception("Sorgente jrxml non trovato");
}
return pathJrxml;
}
// private String prepareTempReportFile(JasperDTO jasperDTO, ArrayList<String> fileTempList) throws Exception {
// String pathJrxml = null;
// String b64ReportJrxml = jasperDTO.getB64ReportJrxml();
//
// if (jasperDTO.getReportId() != null) {
// JasperDTO jasperDTOTmp = this.getReportByID(jasperDTO.getReportId());
// if (b64ReportJrxml == null) {
// b64ReportJrxml = jasperDTOTmp.getB64ReportJrxml();
// jasperDTO.setB64ReportJrxml(b64ReportJrxml)
// .setCompiledJasper(jasperDTOTmp.getCompiledJasper());
// }
// if (jasperDTO.getSubreports() == null) {
// jasperDTO.setSubreports(jasperDTOTmp.getSubreports());
// }
// }
// /*
// if(reportName != null && b64ReportJrxml==null) {
// JasperDTO jasperDTOTmp = this.getReportByName(reportName);
// b64ReportJrxml = jasperDTOTmp.getB64ReportJrxml();
// jasperDTO.setB64ReportJrxml(jasperDTOTmp.getB64ReportJrxml());
// jasperDTO.setSubreports(jasperDTOTmp.getSubreports());
// }*/
//
// if (b64ReportJrxml != null) {
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS");
// String pathJrxmlTemp = this.getPathJrxmlTemp();
// pathJrxml = pathJrxmlTemp + "tmp" + sdf.format(new Date()) + ".jrxml";
//
// FileOutputStream fos = new FileOutputStream(new File(pathJrxml));
// IOUtils.write(Base64.decodeBase64(b64ReportJrxml), fos);
// fos.close();
// fileTempList.add(pathJrxml);
//
// } else {
// throw new Exception("Sorgente jrxml non trovato");
// }
//
// return pathJrxml;
// }
private String getSubreportPath() throws Exception {
return this.getPathJrxmlTemp();
@@ -310,26 +241,23 @@ public class ReportProcessor {
}
public byte[] processReport(JasperDTO jasperDTO) throws Exception {
ArrayList<String> fileTempList = new ArrayList<String>();
ArrayList<String> filesToClean = new ArrayList<String>();
try {
String b64XmlReport = jasperDTO.getB64XmlReport();
if (!UtilityString.isNullOrEmpty(b64XmlReport)) {
String xmlDto = new String(Base64.decodeBase64(b64XmlReport.getBytes()));
jasperDTO = this.XMLToDTO(xmlDto);
}
if (!UtilityString.isNullOrEmpty(jasperDTO.getReportName()) && jasperDTO.getReportId() == null) {
jasperDTO.setReportId(getReportID(jasperDTO.getReportName()));
}
//Refill
jasperDTO = getReportByID(jasperDTO.getReportId(), jasperDTO.getParams());
if (jasperDTO.getOrientation() == null && jasperDTO.getReportId() != null) {
String sql = "SELECT orientation FROM " + WtbJrept.ENTITY + " WHERE id = " + UtilityDB.valueToString(jasperDTO.getReportId());
int orientation = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
jasperDTO.setOrientation(WtbJreptSetup.Orientation.from(orientation));
}
String pathJrxml = this.prepareTempReportFile(jasperDTO, fileTempList);
this.prepareTempSubreportFiles(jasperDTO, fileTempList);
// this.prepareTempReportFile(jasperDTO);
this.prepareTempSubreportFiles(jasperDTO, filesToClean);
String jsonSource = jasperDTO.getJsonSource();
List<Object> javaBeans = jasperDTO.getJavaBeans();
@@ -360,12 +288,12 @@ public class ReportProcessor {
jasperReportsContext.setProperty("net.sf.jasperreports.default.pdf.embedded", "true");
jasperReportsContext.setProperty("net.sf.jasperreports.query.executer.factory.xmla-mdx", "net.sf.jasperreports.engine.query.JRXmlaQueryExecuterFactory");
byte[] jrxml = Base64.decodeBase64(jasperDTO.getB64ReportJrxml());
JasperDesign jasperDesign = JRXmlLoader.load(pathJrxml);
JasperDesign jasperDesign = JRXmlLoader.load(new ByteArrayInputStream(jrxml));
JasperReport jasperReport = null;
if(jasperDTO.getCompiledJasper() != null) {
if (jasperDTO.getCompiledJasper() != null) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(jasperDTO.getCompiledJasper());
jasperReport = (JasperReport) JRLoader.loadObject(byteArrayInputStream);
} else {
@@ -400,11 +328,7 @@ public class ReportProcessor {
throw new Exception("JasperPrint non valido");
}
if (!jp.getPages().isEmpty()) {/*
ByteArrayOutputStream output = new ByteArrayOutputStream();
JRAbstractExporter exporter = null;
if(("PDF").equals(outFormat)){*/
if (!jp.getPages().isEmpty()) {
if (jasperDTO.getOrientation() != null) {
switch (jasperDTO.getOrientation()) {
@@ -461,7 +385,7 @@ public class ReportProcessor {
} catch (Exception e) {
throw e;
} finally {
this.cleanTempFiles(fileTempList);
this.cleanTempFiles(filesToClean);
}
}
@@ -505,7 +429,7 @@ public class ReportProcessor {
return paramsMap;
}
private JasperDTO getReportByID(Long reportId) throws Exception {
private JasperDTO getReportByID(Long reportId, List<PairsDTO> params) throws Exception {
String sql = "SELECT id, " +
" CONVERT(TEXT, b64_jrxml) AS b64_jrxml," +
" compiled_jasper " +
@@ -517,6 +441,7 @@ public class ReportProcessor {
if (result == null) throw new Exception("Report non valido");
JasperDTO jasperDTO = new JasperDTO()
.setParams(params)
.setReportId(UtilityHashMap.getValueIfExists(result, "id"))
.setB64ReportJrxml(UtilityHashMap.getValueIfExists(result, "b64_jrxml"))
.setCompiledJasper(UtilityHashMap.getValueIfExists(result, "compiled_jasper"));

View File

@@ -26,8 +26,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@@ -263,34 +261,6 @@ public class EmsEngineController {
return response;
}
@RequestMapping(value = EmsRestConstants.PATH_PROCESS_JASPER, method = RequestMethod.POST)
public @ResponseBody
List<ServiceRestResponse> processJasper(HttpServletRequest request,
@RequestParam(CommonConstants.PROFILE_DB) String configuration,
@RequestBody(required = true) String b64inputValue) {
List<ServiceRestResponse> response = new ArrayList<ServiceRestResponse>();
try {
String xmlDto = new String(Base64.decodeBase64(b64inputValue));
JasperDTO jasperDTO = reportProcessor.XMLToDTO(xmlDto);
FileItem fi = new FileItem();
byte[] bytes = emsEngineService.processReport(jasperDTO);
if (bytes != null) {
fi.setFileb64Content(new String(Base64.encodeBase64(bytes)));
}
response.add(new ServiceRestResponse(EsitoType.OK, multiDBTransactionManager.getPrimaryDatasource().getProfile(), fi));
} catch (JRException e) {
logger.error(e.toString() + " - Cause: " + e.getCause());
response.add(new ServiceRestResponse(EsitoType.KO, configuration, e));
} catch (Exception e) {
logger.error(request.getRequestURI(), e);
response.add(new ServiceRestResponse(EsitoType.KO, configuration, e));
}
return response;
}
@RequestMapping(value = EmsRestConstants.PATH_RETRIEVE_GRL_ANAG_JREPT_TYPES, method = RequestMethod.GET)
public @ResponseBody
ServiceRestResponse retrieveGrlAnagJreptTypes(HttpServletRequest request) {

View File

@@ -1441,25 +1441,26 @@ public class SystemController {
for (HashMap<String, Object> document : documents) {
ArrayList<PairsDTO> params = new ArrayList<>();
String codAnag = UtilityHashMap.getValueIfExists(document, "cod_anag");
String serDoc = UtilityHashMap.getValueIfExists(document, "ser_doc");
Integer numDoc = UtilityHashMap.getValueIfExists(document, "num_doc");
Date dataDoc = UtilityHashMap.getValueIfExists(document, "data_doc");
String codDtip = UtilityHashMap.getValueIfExists(document, "cod_dtip");
params.add(new PairsDTO("cod_anag", codAnag));
params.add(new PairsDTO("ser_doc", serDoc));
params.add(new PairsDTO("num_doc", numDoc));
params.add(new PairsDTO("data_doc", dataDoc));
params.add(new PairsDTO("cod_dtip", codDtip));
JasperDTO jasperDTO = new JasperDTO()
.setParams(params)
.setReportId(20L);
calls.add(() -> {
try {
ArrayList<PairsDTO> params = new ArrayList<>();
params.add(new PairsDTO("cod_anag", codAnag));
params.add(new PairsDTO("ser_doc", serDoc));
params.add(new PairsDTO("num_doc", numDoc));
params.add(new PairsDTO("data_doc", dataDoc));
params.add(new PairsDTO("cod_dtip", codDtip));
JasperDTO jasperDTO = new JasperDTO()
.setParams(params)
.setReportId(20L);
final byte[] bytes = reportProcessor.processReport(jasperDTO);
UtilityFile.saveFile(tempDir, String.format("%s_%s_%s_%d_%s.pdf",
@@ -1492,7 +1493,7 @@ public class SystemController {
});
}
final ArrayList<Result<Triple<String, String, List<VariazioniDettaglioDTO>>>> results = UtilityThread.executeParallel(calls, 6);
final ArrayList<Result<Triple<String, String, List<VariazioniDettaglioDTO>>>> results = UtilityThread.executeParallel(calls, 10);
return ServiceRestResponse.createPositiveResponse();