|
37 | 37 |
|
38 | 38 | import org.apache.commons.collections4.CollectionUtils;
|
39 | 39 | import org.apache.commons.csv.CSVFormat;
|
| 40 | +import org.apache.commons.csv.CSVFormat.Builder; |
40 | 41 | import org.apache.commons.csv.CSVRecord;
|
41 | 42 | import org.apache.ofbiz.accounting.payment.PaymentGatewayServices;
|
42 | 43 | import org.apache.ofbiz.accounting.payment.PaymentWorker;
|
@@ -3310,7 +3311,7 @@ public static Map<String, Object> updatePaymentApplicationDefBd(DispatchContext
|
3310 | 3311 | errorMessageList.add(UtilProperties.getMessage(RESOURCE, "AccountingNoAmount", locale));
|
3311 | 3312 | } else {
|
3312 | 3313 | successMessage = UtilProperties.getMessage(RESOURCE,
|
3313 |
| - "AccountingApplicationSuccess", |
| 3314 | + "AccountingPaymentApplicationSuccess", |
3314 | 3315 | UtilMisc.<String, Object>toMap("amountApplied", amountApplied,
|
3315 | 3316 | "paymentId", paymentId,
|
3316 | 3317 | "isoCode", currencyUomId,
|
@@ -3672,16 +3673,16 @@ public static Map<String, Object> importInvoice(DispatchContext dctx, Map<String
|
3672 | 3673 | String organizationPartyId = (String) context.get("organizationPartyId");
|
3673 | 3674 | String encoding = System.getProperty("file.encoding");
|
3674 | 3675 | String csvString = Charset.forName(encoding).decode(fileBytes).toString();
|
3675 |
| - final BufferedReader csvReader = new BufferedReader(new StringReader(csvString)); |
3676 |
| - CSVFormat fmt = CSVFormat.DEFAULT.withHeader(); |
| 3676 | + Builder csvFormatBuilder = Builder.create().setHeader(); |
| 3677 | + CSVFormat fmt = csvFormatBuilder.build(); |
3677 | 3678 | List<String> errMsgs = new LinkedList<>();
|
3678 | 3679 | List<String> newErrMsgs;
|
3679 | 3680 | String lastInvoiceId = null;
|
3680 | 3681 | String currentInvoiceId = null;
|
3681 | 3682 | String newInvoiceId = null;
|
3682 | 3683 | int invoicesCreated = 0;
|
3683 | 3684 |
|
3684 |
| - try { |
| 3685 | + try (BufferedReader csvReader = new BufferedReader(new StringReader(csvString))) { |
3685 | 3686 | for (final CSVRecord rec : fmt.parse(csvReader)) {
|
3686 | 3687 | currentInvoiceId = rec.get("invoiceId");
|
3687 | 3688 | if (lastInvoiceId == null || !currentInvoiceId.equals(lastInvoiceId)) {
|
@@ -3758,11 +3759,18 @@ public static Map<String, Object> importInvoice(DispatchContext dctx, Map<String
|
3758 | 3759 | try {
|
3759 | 3760 | invoiceResult = dispatcher.runSync("createInvoice", invoice);
|
3760 | 3761 | if (ServiceUtil.isError(invoiceResult)) {
|
| 3762 | + // Eclipse reports here: Resource leak: '<unassigned Closeable value>' is not closed at this location |
| 3763 | + // but it's OK. As csvReader is in a try-with-ressource it will be closed anyway |
| 3764 | + // I prefer to not put @SuppressWarnings("resource") to the whole method |
| 3765 | + // BTW to be consistent Eclipse should also reports the same issue in PartyService (see there) |
3761 | 3766 | return ServiceUtil.returnError(ServiceUtil.getErrorMessage(invoiceResult));
|
3762 | 3767 | }
|
3763 | 3768 | } catch (GenericServiceException e) {
|
3764 |
| - csvReader.close(); |
3765 | 3769 | Debug.logError(e, MODULE);
|
| 3770 | + // Eclipse reports here: Resource leak: '<unassigned Closeable value>' is not closed at this location |
| 3771 | + // but it's OK. As csvReader is in a try-with-ressource it will be closed anyway |
| 3772 | + // I prefer to not put @SuppressWarnings("resource") to the whole method |
| 3773 | + // BTW to be consistent Eclipse should also reports the same issue in PartyService (see there) |
3766 | 3774 | return ServiceUtil.returnError(e.getMessage());
|
3767 | 3775 | }
|
3768 | 3776 | newInvoiceId = (String) invoiceResult.get("invoiceId");
|
@@ -3824,10 +3832,13 @@ public static Map<String, Object> importInvoice(DispatchContext dctx, Map<String
|
3824 | 3832 | try {
|
3825 | 3833 | Map<String, Object> result = dispatcher.runSync("createInvoiceItem", invoiceItem);
|
3826 | 3834 | if (ServiceUtil.isError(result)) {
|
| 3835 | + // Eclipse reports here: Resource leak: '<unassigned Closeable value>' is not closed at this location |
| 3836 | + // but it's OK. As csvReader is in a try-with-ressource it will be closed anyway |
| 3837 | + // I prefer to not put @SuppressWarnings("resource") to the whole method |
| 3838 | + // BTW to be consistent Eclipse should also reports the same issue in PartyService (see there) |
3827 | 3839 | return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result));
|
3828 | 3840 | }
|
3829 | 3841 | } catch (GenericServiceException e) {
|
3830 |
| - csvReader.close(); |
3831 | 3842 | Debug.logError(e, MODULE);
|
3832 | 3843 | return ServiceUtil.returnError(e.getMessage());
|
3833 | 3844 | }
|
|
0 commit comments