fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject [fineract] branch develop updated: introduce Throwable cause to AbstractPlatformResourceNotFoundException (re. FINERACT-942)
Date Wed, 24 Jun 2020 15:03:22 GMT
This is an automated email from the ASF dual-hosted git repository.

kaze 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 24d4c45  introduce Throwable cause to AbstractPlatformResourceNotFoundException (re.
FINERACT-942)
24d4c45 is described below

commit 24d4c45d9a43928147acf8d6d027ee74ca9b13e2
Author: Michael Vorburger <mike@vorburger.ch>
AuthorDate: Tue Jun 23 23:09:38 2020 +0200

    introduce Throwable cause to AbstractPlatformResourceNotFoundException (re. FINERACT-942)
---
 .../AbstractPlatformResourceNotFoundException.java | 27 ++++++++++++++++++++--
 .../exception/RoleNotFoundException.java           |  5 ++++
 .../service/RoleReadPlatformServiceImpl.java       |  7 +++---
 3 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/exception/AbstractPlatformResourceNotFoundException.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/exception/AbstractPlatformResourceNotFoundException.java
index 1f0d7c7..b6174ce 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/exception/AbstractPlatformResourceNotFoundException.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/exception/AbstractPlatformResourceNotFoundException.java
@@ -18,6 +18,9 @@
  */
 package org.apache.fineract.infrastructure.core.exception;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * A {@link RuntimeException} thrown when resources that are queried for are not found.
  */
@@ -27,11 +30,31 @@ public abstract class AbstractPlatformResourceNotFoundException extends
RuntimeE
     private final String defaultUserMessage;
     private final Object[] defaultUserMessageArgs;
 
-    public AbstractPlatformResourceNotFoundException(final String globalisationMessageCode,
final String defaultUserMessage,
+    protected AbstractPlatformResourceNotFoundException(final String globalisationMessageCode,
final String defaultUserMessage,
             final Object... defaultUserMessageArgs) {
+        super(findThrowableCause(defaultUserMessageArgs));
         this.globalisationMessageCode = globalisationMessageCode;
         this.defaultUserMessage = defaultUserMessage;
-        this.defaultUserMessageArgs = defaultUserMessageArgs;
+        this.defaultUserMessageArgs = filterThrowableCause(defaultUserMessageArgs);
+    }
+
+    private static Throwable findThrowableCause(Object[] defaultUserMessageArgs) {
+        for (Object defaultUserMessageArg : defaultUserMessageArgs) {
+            if (defaultUserMessageArg instanceof Throwable) {
+                return (Throwable) defaultUserMessageArg;
+            }
+        }
+        return null;
+    }
+
+    private static Object[] filterThrowableCause(Object[] defaultUserMessageArgs) {
+        List<Object> filteredDefaultUserMessageArgs = new ArrayList<>(defaultUserMessageArgs.length);
+        for (Object defaultUserMessageArg : defaultUserMessageArgs) {
+            if (!(defaultUserMessageArg instanceof Throwable)) {
+                filteredDefaultUserMessageArgs.add(defaultUserMessageArg);
+            }
+        }
+        return filteredDefaultUserMessageArgs.toArray();
     }
 
     public String getGlobalisationMessageCode() {
diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/exception/RoleNotFoundException.java
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/exception/RoleNotFoundException.java
index ab7d3d6..9e5e0cf 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/exception/RoleNotFoundException.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/exception/RoleNotFoundException.java
@@ -19,6 +19,7 @@
 package org.apache.fineract.useradministration.exception;
 
 import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
+import org.springframework.dao.EmptyResultDataAccessException;
 
 /**
  * A {@link RuntimeException} thrown when role resources are not found.
@@ -32,4 +33,8 @@ public class RoleNotFoundException extends AbstractPlatformResourceNotFoundExcep
     public RoleNotFoundException(final String name) {
         super("error.msg.role.name.invalid", "Role with name " + name + " does not exist",
name);
     }
+
+    public RoleNotFoundException(Long id, EmptyResultDataAccessException e) {
+        super("error.msg.role.id.invalid", "Role with identifier " + id + " does not exist",
id, e);
+    }
 }
diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java
index f4a4a06..c9b8edb 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java
@@ -68,13 +68,12 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService
{
 
     @Override
     public RoleData retrieveOne(final Long id) {
-
         try {
             final String sql = "select " + this.roleRowMapper.schema() + " where r.id=?";
 
-            return this.jdbcTemplate.queryForObject(sql, this.roleRowMapper, new Object[]
{ id });
+            return this.jdbcTemplate.queryForObject(sql, this.roleRowMapper, id);
         } catch (final EmptyResultDataAccessException e) {
-            throw new RoleNotFoundException(id);
+            throw new RoleNotFoundException(id, e);
         }
     }
 
@@ -101,6 +100,6 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService
{
         final String sql = "select " + this.roleRowMapper.schema() + " inner join m_appuser_role"
                 + " ar on ar.role_id = r.id where ar.appuser_id= ?";
 
-        return this.jdbcTemplate.query(sql, this.roleRowMapper, new Object[] { appUserId
});
+        return this.jdbcTemplate.query(sql, this.roleRowMapper, appUserId);
     }
 }


Mime
View raw message