|
|
@ -26,32 +26,24 @@ public class ReportUtil { |
|
|
|
private static final Log _log = LogFactoryUtil.getLog(ReportUtil.class); |
|
|
|
private static final Log _log = LogFactoryUtil.getLog(ReportUtil.class); |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
* Considerazioni per report generati con <i>modalità asincrona</i>. Il |
|
|
|
* Considerazioni per report generati con <i>modalità asincrona</i>. Il risultato finale sarà inviato tramite |
|
|
|
* risultato finale sarà inviato tramite message bus su una destinazione |
|
|
|
* message bus su una destinazione passata in input. La chiave di legame tra l'ack iniziale e il messaggio di esito |
|
|
|
* passata in input. La chiave di legame tra l'ack iniziale e il messaggio |
|
|
|
* è il <code>reportTaskId</code>.<br /> <b>LIMITAZIONI</b> Il campo <code>parameters</code> non può contenetere |
|
|
|
* di esito è il <code>reportTaskId</code>.<br /> <b>LIMITAZIONI</b> Il |
|
|
|
* <code>Array[]</code> ma solo <code>List</code> che saranno gestite dall'engine come <code>ArrayList</code> che |
|
|
|
* campo <code>parameters</code> non può contenetere <code>Array[]</code> ma |
|
|
|
* chiaramente non potranno essere tipati come <code>List<Array[]></code> ma |
|
|
|
* solo <code>List</code> che saranno gestite dall'engine come |
|
|
|
* <code>List<List<>></code> nel caso di matrici. All'interno di template Velocity si dovrà rifare |
|
|
|
* <code>ArrayList</code> che chiaramente non potranno essere tipati come |
|
|
|
* rimento al bean direttamente al campo e non con metodi get (es: <code>$user.firstName</code> e non |
|
|
|
* <code>List<Array[]></code> ma <code>List<List<>></code> |
|
|
|
* <code>$user.getFirstName()</code>). In generale parametri "semplici" (come background task). |
|
|
|
* nel caso di matrici. All'interno di template Velocity si dovrà rifare |
|
|
|
|
|
|
|
* rimento al bean direttamente al campo e non con metodi get (es: |
|
|
|
|
|
|
|
* <code>$user.firstName</code> e non <code>$user.getFirstName()</code>). In |
|
|
|
|
|
|
|
* generale parametri "semplici" (come background task). |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public static ReportResultDto generateReport(long companyId, long userId, ReportDto reportDto, |
|
|
|
public static ReportResultDto generateReport(long companyId, long userId, ReportDto reportDto, Object dataSource) |
|
|
|
Object dataSource) throws ReportGenerationException { |
|
|
|
throws ReportGenerationException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
Message message = new Message(); |
|
|
|
Message message = new Message(); |
|
|
|
|
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.SYNC, Collections.singletonList(reportDto), |
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.SYNC, |
|
|
|
dataSource, null); |
|
|
|
Collections.singletonList(reportDto), dataSource, null); |
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage(ReportDestinationNames.SYNC, message, 1); |
|
|
|
|
|
|
|
|
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage(ReportDestinationNames.SYNC, |
|
|
|
|
|
|
|
message, 1); |
|
|
|
|
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
_log.error(e); |
|
|
|
_log.error(e); |
|
|
@ -63,33 +55,24 @@ public class ReportUtil { |
|
|
|
Object dataSource) throws ReportGenerationException { |
|
|
|
Object dataSource) throws ReportGenerationException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
Message message = new Message(); |
|
|
|
Message message = new Message(); |
|
|
|
|
|
|
|
|
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.SYNC, reportDtos, dataSource, null); |
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.SYNC, reportDtos, dataSource, null); |
|
|
|
|
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage(ReportDestinationNames.SYNC, message, 1); |
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage(ReportDestinationNames.SYNC, |
|
|
|
|
|
|
|
message, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
throw new ReportGenerationException(e); |
|
|
|
throw new ReportGenerationException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static ReportResultDto generateReport(long companyId, long userId, ReportDto reportDto, |
|
|
|
public static ReportResultDto generateReport(long companyId, long userId, ReportDto reportDto, Object dataSource, |
|
|
|
Object dataSource, String responseDestinationName) throws ReportGenerationException { |
|
|
|
String responseDestinationName) throws ReportGenerationException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
Message message = new Message(); |
|
|
|
Message message = new Message(); |
|
|
|
|
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.ASYNC, Collections.singletonList(reportDto), |
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.ASYNC, |
|
|
|
dataSource, responseDestinationName); |
|
|
|
Collections.singletonList(reportDto), dataSource, responseDestinationName); |
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage(ReportDestinationNames.SERIAL, message, |
|
|
|
|
|
|
|
TimeUnit.SECONDS.toMillis(60)); |
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage(ReportDestinationNames.SERIAL, |
|
|
|
|
|
|
|
message, TimeUnit.SECONDS.toMillis(60)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
throw new ReportGenerationException(e); |
|
|
|
throw new ReportGenerationException(e); |
|
|
@ -100,15 +83,11 @@ public class ReportUtil { |
|
|
|
Object dataSource, String responseDestinationName) throws ReportGenerationException { |
|
|
|
Object dataSource, String responseDestinationName) throws ReportGenerationException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
Message message = new Message(); |
|
|
|
Message message = new Message(); |
|
|
|
|
|
|
|
|
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.ASYNC, reportDtos, dataSource, |
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.ASYNC, reportDtos, dataSource, |
|
|
|
responseDestinationName); |
|
|
|
responseDestinationName); |
|
|
|
|
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage(ReportDestinationNames.SERIAL, message, |
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage(ReportDestinationNames.SERIAL, |
|
|
|
TimeUnit.SECONDS.toMillis(60)); |
|
|
|
message, TimeUnit.SECONDS.toMillis(60)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
throw new ReportGenerationException(e); |
|
|
|
throw new ReportGenerationException(e); |
|
|
@ -119,40 +98,29 @@ public class ReportUtil { |
|
|
|
throws ReportGenerationException { |
|
|
|
throws ReportGenerationException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
Message message = new Message(); |
|
|
|
Message message = new Message(); |
|
|
|
|
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.SYNC, Collections.singletonList(reportDto), null, |
|
|
|
setMessage(message, companyId, userId, ReportProcessMode.SYNC, |
|
|
|
ReportDestinationNames.SYNC_PROTOCOLLO); |
|
|
|
Collections.singletonList(reportDto), null, ReportDestinationNames.SYNC_PROTOCOLLO); |
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage(ReportDestinationNames.SYNC_PROTOCOLLO, |
|
|
|
|
|
|
|
message, 1); |
|
|
|
String json = (String) MessageBusUtil.sendSynchronousMessage( |
|
|
|
|
|
|
|
ReportDestinationNames.SYNC_PROTOCOLLO, message, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
return JSONFactoryUtil.looseDeserialize(json, ReportResultDto.class); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
throw new ReportGenerationException(e); |
|
|
|
throw new ReportGenerationException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void setMessage(Message message, long companyId, long userId, |
|
|
|
private static void setMessage(Message message, long companyId, long userId, ReportProcessMode processMode, |
|
|
|
ReportProcessMode processMode, List<ReportDto> reportDtos, Object dataSource, |
|
|
|
List<ReportDto> reportDtos, Object dataSource, String responseDestinationName) throws Exception { |
|
|
|
String responseDestinationName) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message.put(ReportConstants.COMPANY_ID, companyId); |
|
|
|
message.put(ReportConstants.COMPANY_ID, companyId); |
|
|
|
message.put(ReportConstants.USER_ID, userId); |
|
|
|
message.put(ReportConstants.USER_ID, userId); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Serializable> map = new HashMap<String, Serializable>(); |
|
|
|
Map<String, Serializable> map = new HashMap<String, Serializable>(); |
|
|
|
|
|
|
|
|
|
|
|
JSONArray reportJsonArray = JSONFactoryUtil.createJSONArray(); |
|
|
|
JSONArray reportJsonArray = JSONFactoryUtil.createJSONArray(); |
|
|
|
|
|
|
|
|
|
|
|
for (ReportDto reportDto : reportDtos) { |
|
|
|
for (ReportDto reportDto : reportDtos) { |
|
|
|
|
|
|
|
|
|
|
|
String json = JSONFactoryUtil.looseSerializeDeep(reportDto); |
|
|
|
String json = JSONFactoryUtil.looseSerializeDeep(reportDto); |
|
|
|
JSONObject jsonObject = JSONFactoryUtil.createJSONObject(json); |
|
|
|
JSONObject jsonObject = JSONFactoryUtil.createJSONObject(json); |
|
|
|
|
|
|
|
|
|
|
|
reportJsonArray.put(jsonObject); |
|
|
|
reportJsonArray.put(jsonObject); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
map.put(ReportConstants.PARAM_REPORTS, reportJsonArray.toString()); |
|
|
|
map.put(ReportConstants.PARAM_REPORTS, reportJsonArray.toString()); |
|
|
|
map.put(ReportConstants.PARAM_RESPONSE_DESTINATION_NAME, responseDestinationName); |
|
|
|
map.put(ReportConstants.PARAM_RESPONSE_DESTINATION_NAME, responseDestinationName); |
|
|
|
map.put(ReportConstants.PARAM_PROCESS_MODE, processMode.toString()); |
|
|
|
map.put(ReportConstants.PARAM_PROCESS_MODE, processMode.toString()); |
|
|
|