introduce Throwable cause to AbstractPlatformResourceNotFoundException (re. FINERACT-942)
This commit is contained in:
committed by
Yemdjih Kaze Nasser
parent
eb2b39f160
commit
24d4c45d9a
+25
-2
@@ -18,6 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.infrastructure.core.exception;
|
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.
|
* 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 String defaultUserMessage;
|
||||||
private final Object[] defaultUserMessageArgs;
|
private final Object[] defaultUserMessageArgs;
|
||||||
|
|
||||||
public AbstractPlatformResourceNotFoundException(final String globalisationMessageCode, final String defaultUserMessage,
|
protected AbstractPlatformResourceNotFoundException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||||
final Object... defaultUserMessageArgs) {
|
final Object... defaultUserMessageArgs) {
|
||||||
|
super(findThrowableCause(defaultUserMessageArgs));
|
||||||
this.globalisationMessageCode = globalisationMessageCode;
|
this.globalisationMessageCode = globalisationMessageCode;
|
||||||
this.defaultUserMessage = defaultUserMessage;
|
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() {
|
public String getGlobalisationMessageCode() {
|
||||||
|
|||||||
+5
@@ -19,6 +19,7 @@
|
|||||||
package org.apache.fineract.useradministration.exception;
|
package org.apache.fineract.useradministration.exception;
|
||||||
|
|
||||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||||
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link RuntimeException} thrown when role resources are not found.
|
* A {@link RuntimeException} thrown when role resources are not found.
|
||||||
@@ -32,4 +33,8 @@ public class RoleNotFoundException extends AbstractPlatformResourceNotFoundExcep
|
|||||||
public RoleNotFoundException(final String name) {
|
public RoleNotFoundException(final String name) {
|
||||||
super("error.msg.role.name.invalid", "Role with name " + name + " does not exist", 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -68,13 +68,12 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RoleData retrieveOne(final Long id) {
|
public RoleData retrieveOne(final Long id) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String sql = "select " + this.roleRowMapper.schema() + " where r.id=?";
|
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) {
|
} 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"
|
final String sql = "select " + this.roleRowMapper.schema() + " inner join m_appuser_role"
|
||||||
+ " ar on ar.role_id = r.id where ar.appuser_id= ?";
|
+ " 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user