This is an automated email from the ASF dual-hosted git repository.

adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5b1d72d15b FINERACT-821: Replace 500 by meaningful error when request 
requires configured S3
5b1d72d15b is described below

commit 5b1d72d15ba0295f1563e8cba8c499b4e40ca8e4
Author: Arun K <[email protected]>
AuthorDate: Sun Aug 24 22:09:15 2025 +0100

    FINERACT-821: Replace 500 by meaningful error when request requires 
configured S3
---
 .../service/DatatableReportingProcessService.java  |  4 +-
 .../DatatableReportingProcessServiceTest.java      | 87 ++++++++++++++++++++++
 2 files changed, 90 insertions(+), 1 deletion(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/DatatableReportingProcessService.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/DatatableReportingProcessService.java
index cce7fe0a07..b7f416f295 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/DatatableReportingProcessService.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/DatatableReportingProcessService.java
@@ -27,6 +27,7 @@ import java.util.Optional;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.fineract.infrastructure.core.api.ApiParameterHelper;
+import 
org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
 import 
org.apache.fineract.infrastructure.dataqueries.api.RunreportsApiResource;
 import org.apache.fineract.infrastructure.dataqueries.data.ReportExportType;
 import 
org.apache.fineract.infrastructure.dataqueries.service.export.DatatableReportExportService;
@@ -59,7 +60,8 @@ public class DatatableReportingProcessService extends 
AbstractReportingProcessSe
         final String parameterTypeValue = 
ApiParameterHelper.parameterType(queryParams) ? "parameter" : "report";
         final Map<String, String> reportParams = getReportParams(queryParams);
         ResponseHolder response = findReportExportService(exportMode) //
-                .orElseThrow(() -> new IllegalArgumentException("Unsupported 
export target: " + exportMode)) //
+                .orElseThrow(() -> new 
GeneralPlatformDomainRuleException("error.msg.report.export.mode.unavailable",
+                        "Export mode %s 
unavailable".formatted(exportMode.name()))) //
                 .export(reportName, queryParams, reportParams, 
isSelfServiceUserReport, parameterTypeValue);
         Response.ResponseBuilder builder = 
Response.status(response.status().getStatusCode());
         if (StringUtils.isNotBlank(response.contentType())) {
diff --git 
a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/dataqueries/service/DatatableReportingProcessServiceTest.java
 
b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/dataqueries/service/DatatableReportingProcessServiceTest.java
new file mode 100644
index 0000000000..e9da4dd7c4
--- /dev/null
+++ 
b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/dataqueries/service/DatatableReportingProcessServiceTest.java
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.dataqueries.service;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+
+import jakarta.ws.rs.core.MultivaluedMap;
+import jakarta.ws.rs.core.Response;
+import java.util.List;
+import 
org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
+import 
org.apache.fineract.infrastructure.dataqueries.service.export.DatatableReportExportService;
+import 
org.apache.fineract.infrastructure.dataqueries.service.export.ResponseHolder;
+import org.apache.fineract.infrastructure.security.service.SqlValidator;
+import org.glassfish.jersey.internal.util.collection.MultivaluedStringMap;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class DatatableReportingProcessServiceTest {
+
+    @Test
+    void exportToS3ThrowsGeneralPlatformDomainRuleException() {
+
+        DatatableReportExportService jsonExportService = 
Mockito.mock(DatatableReportExportService.class);
+        
Mockito.doReturn(true).when(jsonExportService).supports(DatatableExportTargetParameter.JSON);
+        SqlValidator sqlValidator = Mockito.mock(SqlValidator.class);
+
+        DatatableReportingProcessService datatableReportingProcessService = 
new DatatableReportingProcessService(List.of(jsonExportService),
+                sqlValidator);
+
+        MultivaluedMap<String, String> queryParams = new 
MultivaluedStringMap();
+        queryParams.put("isSelfServiceUserReport", List.of("false"));
+        queryParams.put("R_officeId", List.of("2"));
+        queryParams.put("exportS3", List.of("true"));
+
+        GeneralPlatformDomainRuleException exception = 
assertThrows(GeneralPlatformDomainRuleException.class,
+                () -> 
datatableReportingProcessService.processRequest("clientListing", queryParams));
+
+        assertEquals("error.msg.report.export.mode.unavailable", 
exception.getGlobalisationMessageCode(),
+                "Wrong globalisation message code");
+        assertEquals("Export mode S3 unavailable", 
exception.getDefaultUserMessage(), "Wrong default user message");
+
+    }
+
+    @Test
+    void exportToS3ThrowsNoException() {
+        DatatableReportExportService jsonExportService = 
Mockito.mock(DatatableReportExportService.class);
+        
Mockito.doReturn(true).when(jsonExportService).supports(DatatableExportTargetParameter.S3);
+
+        ResponseHolder responseHolder = new 
ResponseHolder(Response.Status.CREATED);
+
+        // ContentType.APPLICATION_JSON.toString(), "export.json"
+        Mockito.doReturn(responseHolder).when(jsonExportService).export(any(), 
any(), any(), anyBoolean(), any());
+        SqlValidator sqlValidator = Mockito.mock(SqlValidator.class);
+
+        DatatableReportingProcessService datatableReportingProcessService = 
new DatatableReportingProcessService(List.of(jsonExportService),
+                sqlValidator);
+
+        MultivaluedMap<String, String> queryParams = new 
MultivaluedStringMap();
+        queryParams.put("isSelfServiceUserReport", List.of("false"));
+        queryParams.put("R_officeId", List.of("2"));
+        queryParams.put("exportS3", List.of("true"));
+
+        assertDoesNotThrow(() -> 
datatableReportingProcessService.processRequest("clientListing", queryParams));
+    }
+
+}

Reply via email to