From 04e7c5db32fd0ab75a40421e98ebe075941df689 Mon Sep 17 00:00:00 2001 From: Piotr Wargulak Date: Tue, 3 Sep 2024 12:45:29 +0200 Subject: [PATCH] Pass dateTimeFormat, dateFormat and decimalFormat to all Jasper reports in Angola --- .../reports/web/JasperTemplateController.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openlmis/ao/reports/web/JasperTemplateController.java b/src/main/java/org/openlmis/ao/reports/web/JasperTemplateController.java index 6df45c3..518ece3 100644 --- a/src/main/java/org/openlmis/ao/reports/web/JasperTemplateController.java +++ b/src/main/java/org/openlmis/ao/reports/web/JasperTemplateController.java @@ -9,6 +9,8 @@ import static org.openlmis.ao.reports.web.ReportTypes.STOCK_CARD_SUMMARY_REPORT; import static org.openlmis.ao.reports.web.ReportTypes.USERS_REPORT; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.time.Clock; import java.util.List; import java.util.Map; @@ -33,6 +35,7 @@ import org.openlmis.ao.utils.AuthenticationHelper; import org.openlmis.ao.utils.Message; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; @@ -70,6 +73,18 @@ public class JasperTemplateController extends BaseController { @Autowired private AuthenticationHelper authenticationHelper; + @Value("${dateTimeFormat}") + private String dateTimeFormat; + + @Value("${dateFormat}") + private String dateFormat; + + @Value("${groupingSeparator}") + private String groupingSeparator; + + @Value("${groupingSize}") + private String groupingSize; + /** * Adding report templates with ".jrxml" format to database. * @@ -184,18 +199,26 @@ public ModelAndView generateReport(HttpServletRequest request, Map map = jasperTemplateService.mapRequestParametersToTemplate( request, template ); - String fileName = jasperReportsViewService.getFilename(template, map); + map.put("format", format); map.put("imagesDirectory", "images/"); map.put("timeZone", clock.getZone().getId()); UserDto currentUser = authenticationHelper.getCurrentUser(); map.put("user", currentUser.printName()); + map.put("dateTimeFormat", dateTimeFormat); + map.put("dateFormat", dateFormat); + DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(); + decimalFormatSymbols.setGroupingSeparator(groupingSeparator.charAt(0)); + DecimalFormat decimalFormat = new DecimalFormat("", decimalFormatSymbols); + decimalFormat.setGroupingSize(Integer.parseInt(groupingSize)); + map.put("decimalFormat", decimalFormat); map.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); JasperReportsMultiFormatView jasperView = jasperReportsViewService.getJasperReportsView(template, request); + String fileName = jasperReportsViewService.getFilename(template, map); String contentDisposition = "inline; filename=" + fileName + "." + format; jasperView