FINERACT-1909: Retry feature for commands - no wrap for retryable exceptions

This commit is contained in:
jmarta
2023-11-03 16:56:23 +01:00
committed by Adam Saghy
parent 224dbdc040
commit a42f46957d
78 changed files with 375 additions and 446 deletions
@@ -35,7 +35,7 @@ import org.apache.fineract.accounting.closure.serialization.GLClosureCommandFrom
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.office.domain.Office; import org.apache.fineract.organisation.office.domain.Office;
import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper; import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
@@ -143,7 +143,7 @@ public class GLClosureWritePlatformServiceJpaRepositoryImpl implements GLClosure
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.glClosure.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.glClosure.unknown.data.integrity.issue",
"Unknown data integrity issue with resource GL Closure: " + realCause.getMessage()); "Unknown data integrity issue with resource GL Closure: " + realCause.getMessage());
} }
} }
@@ -36,9 +36,8 @@ import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrappe
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.NonTransientDataAccessException;
import org.springframework.orm.jpa.JpaSystemException; import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -141,7 +140,7 @@ public class FinancialActivityAccountWritePlatformServiceImpl implements Financi
} }
private void handleFinancialActivityAccountDataIntegrityIssues(final JsonCommand command, final Throwable realCause, private void handleFinancialActivityAccountDataIntegrityIssues(final JsonCommand command, final Throwable realCause,
final NonTransientDataAccessException dve) { final Exception dve) {
if (realCause.getMessage().contains("financial_activity_type")) { if (realCause.getMessage().contains("financial_activity_type")) {
final Integer financialActivityId = command final Integer financialActivityId = command
.integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue()); .integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue());
@@ -149,19 +148,7 @@ public class FinancialActivityAccountWritePlatformServiceImpl implements Financi
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.glAccount.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.glAccount.unknown.data.integrity.issue",
"Unknown data integrity issue with resource GL Account: " + realCause.getMessage());
}
private void handleFinancialActivityAccountDataIntegrityIssues(JsonCommand command, Throwable realCause, PersistenceException dve) {
if (realCause.getMessage().contains("financial_activity_type")) {
final Integer financialActivityId = command
.integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue());
throw new DuplicateFinancialActivityAccountFoundException(financialActivityId);
}
log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.glAccount.unknown.data.integrity.issue",
"Unknown data integrity issue with resource GL Account: " + realCause.getMessage()); "Unknown data integrity issue with resource GL Account: " + realCause.getMessage());
} }
@@ -42,7 +42,7 @@ import org.apache.fineract.infrastructure.codes.domain.CodeValueRepositoryWrappe
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
@@ -230,7 +230,7 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount
} }
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.glAccount.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.glAccount.unknown.data.integrity.issue",
"Unknown data integrity issue with resource GL Account: " + realCause.getMessage()); "Unknown data integrity issue with resource GL Account: " + realCause.getMessage());
} }
@@ -26,6 +26,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.apache.fineract.batch.domain.Header; import org.apache.fineract.batch.domain.Header;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
/** /**
* Provides members to hold the basic information about the exceptions raised in commandStrategy classes. * Provides members to hold the basic information about the exceptions raised in commandStrategy classes.
@@ -48,11 +48,11 @@ import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.domain.Header; import org.apache.fineract.batch.domain.Header;
import org.apache.fineract.batch.exception.BatchReferenceInvalidException; import org.apache.fineract.batch.exception.BatchReferenceInvalidException;
import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.batch.service.ResolutionHelper.BatchRequestNode; import org.apache.fineract.batch.service.ResolutionHelper.BatchRequestNode;
import org.apache.fineract.infrastructure.core.domain.BatchRequestContextHolder; import org.apache.fineract.infrastructure.core.domain.BatchRequestContextHolder;
import org.apache.fineract.infrastructure.core.exception.AbstractIdempotentCommandException; import org.apache.fineract.infrastructure.core.exception.AbstractIdempotentCommandException;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.filters.BatchCallHandler; import org.apache.fineract.infrastructure.core.filters.BatchCallHandler;
import org.apache.fineract.infrastructure.core.filters.BatchFilter; import org.apache.fineract.infrastructure.core.filters.BatchFilter;
import org.apache.fineract.infrastructure.core.filters.BatchRequestPreprocessor; import org.apache.fineract.infrastructure.core.filters.BatchRequestPreprocessor;
@@ -21,13 +21,13 @@ package org.apache.fineract.commands.service;
import static org.apache.fineract.commands.domain.CommandProcessingResultType.UNDER_PROCESSING; import static org.apache.fineract.commands.domain.CommandProcessingResultType.UNDER_PROCESSING;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.commands.domain.CommandSource; import org.apache.fineract.commands.domain.CommandSource;
import org.apache.fineract.commands.domain.CommandSourceRepository; import org.apache.fineract.commands.domain.CommandSourceRepository;
import org.apache.fineract.commands.domain.CommandWrapper; import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.exception.CommandNotFoundException; import org.apache.fineract.commands.exception.CommandNotFoundException;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUser;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -20,7 +20,6 @@ package org.apache.fineract.commands.service;
import static org.apache.fineract.commands.domain.CommandProcessingResultType.ERROR; import static org.apache.fineract.commands.domain.CommandProcessingResultType.ERROR;
import static org.apache.fineract.commands.domain.CommandProcessingResultType.PROCESSED; import static org.apache.fineract.commands.domain.CommandProcessingResultType.PROCESSED;
import static org.apache.fineract.commands.domain.CommandProcessingResultType.UNDER_PROCESSING;
import static org.apache.http.HttpStatus.SC_OK; import static org.apache.http.HttpStatus.SC_OK;
import com.google.gson.Gson; import com.google.gson.Gson;
@@ -32,7 +31,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.commands.domain.CommandProcessingResultType; import org.apache.fineract.commands.domain.CommandProcessingResultType;
import org.apache.fineract.commands.domain.CommandSource; import org.apache.fineract.commands.domain.CommandSource;
@@ -47,6 +45,7 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.domain.BatchRequestContextHolder; import org.apache.fineract.infrastructure.core.domain.BatchRequestContextHolder;
import org.apache.fineract.infrastructure.core.domain.FineractRequestContextHolder; import org.apache.fineract.infrastructure.core.domain.FineractRequestContextHolder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.IdempotentCommandProcessFailedException; import org.apache.fineract.infrastructure.core.exception.IdempotentCommandProcessFailedException;
import org.apache.fineract.infrastructure.core.exception.IdempotentCommandProcessSucceedException; import org.apache.fineract.infrastructure.core.exception.IdempotentCommandProcessSucceedException;
import org.apache.fineract.infrastructure.core.exception.IdempotentCommandProcessUnderProcessingException; import org.apache.fineract.infrastructure.core.exception.IdempotentCommandProcessUnderProcessingException;
@@ -54,6 +54,9 @@ public abstract class AbstractPlatformException extends RuntimeException {
} }
private static Throwable findThrowableCause(Object[] defaultUserMessageArgs) { private static Throwable findThrowableCause(Object[] defaultUserMessageArgs) {
if (defaultUserMessageArgs == null) {
return null;
}
for (Object defaultUserMessageArg : defaultUserMessageArgs) { for (Object defaultUserMessageArg : defaultUserMessageArgs) {
if (defaultUserMessageArg instanceof Throwable) { if (defaultUserMessageArg instanceof Throwable) {
return (Throwable) defaultUserMessageArg; return (Throwable) defaultUserMessageArg;
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.fineract.batch.exception; package org.apache.fineract.infrastructure.core.exception;
import static org.springframework.core.ResolvableType.forClassWithGenerics; import static org.springframework.core.ResolvableType.forClassWithGenerics;
@@ -36,9 +36,8 @@ import lombok.extern.slf4j.Slf4j;
import net.fortuna.ical4j.validate.ValidationException; import net.fortuna.ical4j.validate.ValidationException;
import org.apache.commons.collections4.SetUtils; import org.apache.commons.collections4.SetUtils;
import org.apache.fineract.batch.domain.Header; import org.apache.fineract.batch.domain.Header;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.exceptionmapper.DefaultExceptionMapper; import org.apache.fineract.infrastructure.core.exceptionmapper.DefaultExceptionMapper;
import org.apache.fineract.infrastructure.core.exceptionmapper.FineractExceptionMapper; import org.apache.fineract.infrastructure.core.exceptionmapper.FineractExceptionMapper;
import org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper; import org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper;
@@ -108,40 +107,45 @@ public final class ErrorHandler {
return new ErrorInfo(response.getStatus(), errorCode, msg instanceof String ? (String) msg : JSON_HELPER.toJson(msg), batchHeaders); return new ErrorInfo(response.getStatus(), errorCode, msg instanceof String ? (String) msg : JSON_HELPER.toJson(msg), batchHeaders);
} }
public RuntimeException getMappable(@NotNull Throwable thr) { public static RuntimeException getMappable(@NotNull Throwable thr) {
return getMappable(thr, null, null, null); return getMappable(thr, null, null, null);
} }
public RuntimeException getMappable(@NotNull Throwable t, String msgCode, String defaultMsg, String param, public static RuntimeException getMappable(@NotNull Throwable thr, String msgCode, String defaultMsg) {
return getMappable(thr, msgCode, defaultMsg, null);
}
public static RuntimeException getMappable(@NotNull Throwable t, String msgCode, String defaultMsg, String param,
final Object... defaultMsgArgs) { final Object... defaultMsgArgs) {
String msg = defaultMsg == null ? t.getMessage() : defaultMsg; String msg = defaultMsg == null ? t.getMessage() : defaultMsg;
param = param == null ? "unknown" : param; String codePfx = "error.msg" + (param == null ? "" : ("." + param));
Object[] args = defaultMsgArgs == null ? new Object[] { t } : defaultMsgArgs;
if (t instanceof NestedRuntimeException nre) { if (t instanceof NestedRuntimeException nre) {
Throwable cause = nre.getMostSpecificCause(); Throwable cause = nre.getMostSpecificCause();
msg = cause.getMessage(); msg = defaultMsg == null ? cause.getMessage() : defaultMsg;
if (nre instanceof NonTransientDataAccessException) { if (nre instanceof NonTransientDataAccessException) {
msgCode = msgCode == null ? "error.msg." + param + ".data.integrity.issue" : msgCode; msgCode = msgCode == null ? codePfx + ".data.integrity.issue" : msgCode;
return new PlatformDataIntegrityException(msgCode, msg, param, defaultMsgArgs); return new PlatformDataIntegrityException(msgCode, msg, param, args);
} }
} }
if (t instanceof ValidationException) { if (t instanceof ValidationException) {
msgCode = msgCode == null ? "error.msg.validation." + param + ".error" : msgCode; msgCode = msgCode == null ? codePfx + ".validation.error" : msgCode;
return new PlatformApiDataValidationException(List.of(ApiParameterError.parameterError(msgCode, msg, param, defaultMsgArgs))); return new PlatformApiDataValidationException(List.of(ApiParameterError.parameterError(msgCode, msg, param, defaultMsgArgs)));
} }
if (t instanceof PersistenceException) { if (t instanceof PersistenceException) {
msgCode = msgCode == null ? "error.msg.persistence." + param + ".error" : msgCode; msgCode = msgCode == null ? codePfx + ".persistence.error" : msgCode;
return new PlatformDataIntegrityException(msgCode, msg, param, defaultMsgArgs); return new PlatformDataIntegrityException(msgCode, msg, param, args);
} }
if (t instanceof AuthenticationException) { if (t instanceof AuthenticationException) {
msgCode = msgCode == null ? "error.msg.authentication." + param + ".error" : msgCode; msgCode = msgCode == null ? codePfx + ".authentication.error" : msgCode;
return new PlatformDataIntegrityException(msgCode, msg, param, defaultMsgArgs); return new PlatformDataIntegrityException(msgCode, msg, param, args);
} }
if (t instanceof RuntimeException re) { if (t instanceof RuntimeException re) {
return re; return re;
} }
if (t instanceof ParseException) { if (t instanceof ParseException) {
msgCode = msgCode == null ? "error.msg.parse." + param + ".error" : msgCode; msgCode = msgCode == null ? codePfx + ".parse.error" : msgCode;
return new PlatformDataIntegrityException(msgCode, msg, param, defaultMsgArgs); return new PlatformDataIntegrityException(msgCode, msg, param, args);
} }
return new RuntimeException(msg, t); return new RuntimeException(msg, t);
} }
@@ -25,6 +25,7 @@ import jakarta.ws.rs.ext.ExceptionMapper;
import java.util.InputMismatchException; import java.util.InputMismatchException;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exceptionmapper.DefaultExceptionMapper; import org.apache.fineract.infrastructure.core.exceptionmapper.DefaultExceptionMapper;
import org.apache.fineract.infrastructure.core.exceptionmapper.FineractExceptionMapper; import org.apache.fineract.infrastructure.core.exceptionmapper.FineractExceptionMapper;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@@ -67,6 +67,7 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
@@ -618,7 +619,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
private PlatformDataIntegrityException handleJournalEntryDataIntegrityIssues(final Throwable realCause, private PlatformDataIntegrityException handleJournalEntryDataIntegrityIssues(final Throwable realCause,
final NonTransientDataAccessException dve) { final NonTransientDataAccessException dve) {
log.error("Error occurred.", dve); log.error("Error occurred.", dve);
return new PlatformDataIntegrityException("error.msg.glJournalEntry.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.glJournalEntry.unknown.data.integrity.issue",
"Unknown data integrity issue with resource Journal Entry: " + realCause.getMessage()); "Unknown data integrity issue with resource Journal Entry: " + realCause.getMessage());
} }
@@ -46,7 +46,7 @@ import org.apache.fineract.infrastructure.codes.exception.CodeValueNotFoundExcep
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.organisation.office.domain.Office; import org.apache.fineract.organisation.office.domain.Office;
import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper; import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
@@ -78,7 +78,7 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.accounting.rule.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.accounting.rule.unknown.data.integrity.issue",
"Unknown data integrity issue with resource Accounting Rule: " + realCause.getMessage()); "Unknown data integrity issue with resource Accounting Rule: " + realCause.getMessage());
} }
@@ -27,6 +27,7 @@ import org.apache.fineract.adhocquery.exception.AdHocNotFoundException;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
@@ -67,16 +68,13 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause,
final NonTransientDataAccessException dve) { final NonTransientDataAccessException dve) {
if (realCause.getMessage().contains("unq_name")) { if (realCause.getMessage().contains("unq_name")) {
final String name = command.stringValueOfParameterNamed("name"); final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException("error.msg.adhocquery.duplicate.name", throw new PlatformDataIntegrityException("error.msg.adhocquery.duplicate.name",
"AdHocQuery with name `" + name + "` already exists", "name", name); "AdHocQuery with name `" + name + "` already exists", "name", name);
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.adhocquery.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.adhocquery.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
@@ -119,8 +117,8 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla
this.adHocRepository.delete(adHoc); this.adHocRepository.delete(adHoc);
return new CommandProcessingResultBuilder().withEntityId(adHocId).build(); return new CommandProcessingResultBuilder().withEntityId(adHocId).build();
} catch (final JpaSystemException | DataIntegrityViolationException e) { } catch (final JpaSystemException | DataIntegrityViolationException e) {
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", throw ErrorHandler.getMappable(e, "error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); "Unknown data integrity issue with resource: " + e.getMostSpecificCause());
} }
} }
@@ -140,8 +138,8 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla
return new CommandProcessingResultBuilder().withEntityId(adHocId).build(); return new CommandProcessingResultBuilder().withEntityId(adHocId).build();
} catch (final JpaSystemException | DataIntegrityViolationException e) { } catch (final JpaSystemException | DataIntegrityViolationException e) {
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", throw ErrorHandler.getMappable(e, "error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); "Unknown data integrity issue with resource: " + e.getMostSpecificCause());
} }
} }
@@ -161,8 +159,8 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla
return new CommandProcessingResultBuilder().withEntityId(adHocId).build(); return new CommandProcessingResultBuilder().withEntityId(adHocId).build();
} catch (final JpaSystemException | DataIntegrityViolationException e) { } catch (final JpaSystemException | DataIntegrityViolationException e) {
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", throw ErrorHandler.getMappable(e, "error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); "Unknown data integrity issue with resource: " + e.getMostSpecificCause());
} }
} }
} }
@@ -20,6 +20,7 @@ package org.apache.fineract.infrastructure;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -29,20 +30,13 @@ public class DataIntegrityErrorHandler {
public void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve, final String msgType, public void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve, final String msgType,
final String msgDescription) { final String msgDescription) {
if (realCause.getMessage().contains("external_id")) { if (realCause.getMessage().contains("external_id")) {
final String externalId = command.stringValueOfParameterNamed("externalId"); final String externalId = command.stringValueOfParameterNamed("externalId");
throw new PlatformDataIntegrityException("error.msg." + msgType + ".duplicate.externalId", throw new PlatformDataIntegrityException("error.msg." + msgType + ".duplicate.externalId",
msgDescription + ": externalId `" + externalId + "` already exists", "externalId", externalId); msgDescription + ": externalId `" + externalId + "` already exists", "externalId", externalId);
} }
log.error("Error occured.", dve);
logAsErrorUnexpectedDataIntegrityException(dve); throw ErrorHandler.getMappable(dve, "error.msg." + msgType + ".unknown.data.integrity.issue",
throw new PlatformDataIntegrityException("error.msg." + msgType + ".unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + msgDescription); "Unknown data integrity issue with resource: " + msgDescription);
} }
private void logAsErrorUnexpectedDataIntegrityException(final Exception dve) {
log.error("Error occured.", dve);
}
} }
@@ -30,6 +30,7 @@ import org.apache.fineract.infrastructure.accountnumberformat.domain.EntityAccou
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -150,7 +151,6 @@ public class AccountNumberFormatWritePlatformServiceJpaRepositoryImpl implements
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains(AccountNumberFormatConstants.ACCOUNT_TYPE_UNIQUE_CONSTRAINT_NAME)) { if (realCause.getMessage().contains(AccountNumberFormatConstants.ACCOUNT_TYPE_UNIQUE_CONSTRAINT_NAME)) {
final Integer accountTypeId = command.integerValueSansLocaleOfParameterNamed(AccountNumberFormatConstants.accountTypeParamName); final Integer accountTypeId = command.integerValueSansLocaleOfParameterNamed(AccountNumberFormatConstants.accountTypeParamName);
final EntityAccountType entityAccountType = EntityAccountType.fromInt(accountTypeId); final EntityAccountType entityAccountType = EntityAccountType.fromInt(accountTypeId);
throw new PlatformDataIntegrityException(AccountNumberFormatConstants.EXCEPTION_DUPLICATE_ACCOUNT_TYPE, throw new PlatformDataIntegrityException(AccountNumberFormatConstants.EXCEPTION_DUPLICATE_ACCOUNT_TYPE,
@@ -158,7 +158,7 @@ public class AccountNumberFormatWritePlatformServiceJpaRepositoryImpl implements
entityAccountType.getValue(), entityAccountType.getCode()); entityAccountType.getValue(), entityAccountType.getCode());
} }
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.account.number.format.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.account.number.format.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
} }
@@ -55,7 +55,7 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.api.JsonQuery; import org.apache.fineract.infrastructure.core.api.JsonQuery;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.dataqueries.data.GenericResultsetData; import org.apache.fineract.infrastructure.dataqueries.data.GenericResultsetData;
@@ -453,8 +453,7 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final Throwable realCause, private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final Throwable realCause,
final NonTransientDataAccessException dve) { final NonTransientDataAccessException dve) {
throw ErrorHandler.getMappable(dve, "error.msg.email.campaign.unknown.data.integrity.issue",
throw new PlatformDataIntegrityException("error.msg.email.campaign.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -27,6 +27,7 @@ import org.apache.fineract.infrastructure.campaigns.email.domain.EmailMessageRep
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -119,14 +120,13 @@ public class EmailWritePlatformServiceJpaRepositoryImpl implements EmailWritePla
*/ */
private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final Throwable realCause, private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final Throwable realCause,
final NonTransientDataAccessException dve) { final NonTransientDataAccessException dve) {
if (realCause.getMessage().contains("email_address")) { if (realCause.getMessage().contains("email_address")) {
throw new PlatformDataIntegrityException("error.msg.email.no.email.address.exists", throw new PlatformDataIntegrityException("error.msg.email.no.email.address.exists",
"The group, client or staff provided has no email address.", "id"); "The group, client or staff provided has no email address.", "id");
} }
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.email.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.email.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -53,8 +53,8 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.api.JsonQuery; import org.apache.fineract.infrastructure.core.api.JsonQuery;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.dataqueries.data.GenericResultsetData; import org.apache.fineract.infrastructure.dataqueries.data.GenericResultsetData;
@@ -544,7 +544,7 @@ public class SmsCampaignWritePlatformServiceJpaImpl implements SmsCampaignWriteP
} }
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause) {
throw new PlatformDataIntegrityException("error.msg.sms.campaign.unknown.data.integrity.issue", throw ErrorHandler.getMappable(realCause, "error.msg.sms.campaign.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -29,6 +29,7 @@ import org.apache.fineract.infrastructure.codes.serialization.CodeValueCommandFr
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -104,7 +105,7 @@ public class CodeValueWritePlatformServiceJpaRepositoryImpl implements CodeValue
} }
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.code.value.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.code.value.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
@@ -167,8 +168,8 @@ public class CodeValueWritePlatformServiceJpaRepositoryImpl implements CodeValue
if (realCause.getMessage().contains("code_value")) { if (realCause.getMessage().contains("code_value")) {
throw new PlatformDataIntegrityException("error.msg.codeValue.in.use", "This code value is in use", codeValueId, dve); throw new PlatformDataIntegrityException("error.msg.codeValue.in.use", "This code value is in use", codeValueId, dve);
} }
throw new PlatformDataIntegrityException("error.msg.code.value.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.code.value.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + dve.getMostSpecificCause().getMessage(), dve); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
} }
@@ -29,6 +29,7 @@ import org.apache.fineract.infrastructure.codes.serialization.CodeCommandFromApi
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -129,8 +130,8 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
this.codeRepository.delete(code); this.codeRepository.delete(code);
this.codeRepository.flush(); this.codeRepository.flush();
} catch (final JpaSystemException | DataIntegrityViolationException dve) { } catch (final JpaSystemException | DataIntegrityViolationException dve) {
throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.cund.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + dve.getMostSpecificCause(), dve); "Unknown data integrity issue with resource: " + dve.getMostSpecificCause().getMessage());
} }
return new CommandProcessingResultBuilder().withEntityId(codeId).build(); return new CommandProcessingResultBuilder().withEntityId(codeId).build();
} }
@@ -150,7 +151,7 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
} }
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.cund.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -27,7 +27,7 @@ import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurati
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -90,9 +90,8 @@ public class GlobalConfigurationWritePlatformServiceJpaRepositoryImpl implements
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final Throwable realCause, final NonTransientDataAccessException dve) { private void handleDataIntegrityIssues(final Throwable realCause, final NonTransientDataAccessException dve) {
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.globalConfiguration.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.globalConfiguration.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -22,7 +22,7 @@ import java.util.Map;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauConfiguration; import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauConfiguration;
import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauConfigurationRepository; import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauConfigurationRepository;
import org.apache.fineract.infrastructure.creditbureau.domain.OrganisationCreditBureau; import org.apache.fineract.infrastructure.creditbureau.domain.OrganisationCreditBureau;
@@ -97,8 +97,8 @@ public class CreditBureauConfigurationWritePlatformServiceImpl implements Credit
.build(); .build();
} catch (final JpaSystemException | DataIntegrityViolationException dve) { } catch (final JpaSystemException | DataIntegrityViolationException dve) {
throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.cund.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + dve.getMostSpecificCause(), dve); "Unknown data integrity issue with resource: " + dve.getMostSpecificCause().getMessage());
} }
} }
@@ -32,8 +32,8 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauConfigurations; import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauConfigurations;
import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauReportData; import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauReportData;
import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureau; import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureau;
@@ -202,18 +202,15 @@ public class CreditReportWritePlatformServiceImpl implements CreditReportWritePl
try { try {
this.creditReportRepository.delete(creditReport); this.creditReportRepository.delete(creditReport);
} catch (final JpaSystemException | DataIntegrityViolationException dve) { } catch (final JpaSystemException | DataIntegrityViolationException dve) {
throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.cund.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + dve.getMostSpecificCause(), dve); "Unknown data integrity issue with resource: " + dve.getMostSpecificCause().getMessage());
} }
} }
return new CommandProcessingResultBuilder().withEntityId(creditReport.getId()).build(); return new CommandProcessingResultBuilder().withEntityId(creditReport.getId()).build();
} }
private void handleTokenDataIntegrityIssues(final Throwable realCause) { private void handleTokenDataIntegrityIssues(final Throwable realCause) {
throw ErrorHandler.getMappable(realCause, "error.msg.cund.unknown.data.integrity.issue",
throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -32,8 +32,8 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.dataqueries.data.DatatableData; import org.apache.fineract.infrastructure.dataqueries.data.DatatableData;
import org.apache.fineract.infrastructure.dataqueries.data.EntityTables; import org.apache.fineract.infrastructure.dataqueries.data.EntityTables;
@@ -133,8 +133,7 @@ public class EntityDatatableChecksWritePlatformServiceImpl implements EntityData
handleReportDataIntegrityIssues(command, e.getMostSpecificCause(), e); handleReportDataIntegrityIssues(command, e.getMostSpecificCause(), e);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} catch (final PersistenceException dve) { } catch (final PersistenceException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleReportDataIntegrityIssues(command, ExceptionUtils.getRootCause(dve.getCause()), dve);
handleReportDataIntegrityIssues(command, throwable, dve);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} }
} }
@@ -253,23 +252,28 @@ public class EntityDatatableChecksWritePlatformServiceImpl implements EntityData
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleReportDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) { private void handleReportDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) {
String msgCode = "error.msg.entityDatatableCheck";
if (realCause.getMessage().contains("FOREIGN KEY (x_registered_table_name)")) { Throwable checkEx = realCause == null ? dae : realCause;
String msg = "Unknown data integrity issue with resource: " + checkEx.getMessage();
String param = null;
Object[] msgArgs;
if (checkEx.getMessage().contains("FOREIGN KEY (x_registered_table_name)")) {
final String datatableName = command.stringValueOfParameterNamed("datatableName"); final String datatableName = command.stringValueOfParameterNamed("datatableName");
throw new PlatformDataIntegrityException("error.msg.entityDatatableCheck.foreign.key.constraint", msgCode += ".foreign.key.constraint";
"datatable with name '" + datatableName + "' do not exist", "datatableName", datatableName); msg = "Datatable with name '" + datatableName + "' does not exist";
} param = "datatableName";
msgArgs = new Object[] { datatableName, dae };
if (realCause.getMessage().contains("unique_entity_check")) { } else if (checkEx.getMessage().contains("unique_entity_check")) {
final String datatableName = command.stringValueOfParameterNamed("datatableName"); final String datatableName = command.stringValueOfParameterNamed("datatableName");
final long status = command.longValueOfParameterNamed("status"); final long status = command.longValueOfParameterNamed("status");
final String entity = command.stringValueOfParameterNamed("entity"); final String entity = command.stringValueOfParameterNamed("entity");
final long productId = command.longValueOfParameterNamed("productId"); final long productId = command.longValueOfParameterNamed("productId");
throw new EntityDatatableCheckAlreadyExistsException(entity, status, datatableName, productId); throw new EntityDatatableCheckAlreadyExistsException(entity, status, datatableName, productId);
} else {
msgCode += ".unknown.data.integrity.issue";
msgArgs = new Object[] { dae };
} }
log.error("Error occured.", dae); log.error("Error occured.", dae);
throw new PlatformDataIntegrityException("error.msg.report.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dae, msgCode, msg, param, msgArgs);
"Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -36,7 +36,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.service.database.DatabaseIndependentQueryService; import org.apache.fineract.infrastructure.core.service.database.DatabaseIndependentQueryService;
import org.apache.fineract.infrastructure.core.service.database.DatabaseType; import org.apache.fineract.infrastructure.core.service.database.DatabaseType;
import org.apache.fineract.infrastructure.core.service.database.DatabaseTypeResolver; import org.apache.fineract.infrastructure.core.service.database.DatabaseTypeResolver;
@@ -88,7 +88,7 @@ public class GenericDataServiceImpl implements GenericDataService {
return new GenericResultsetData(columnHeaders, resultsetDataRows); return new GenericResultsetData(columnHeaders, resultsetDataRows);
} catch (DataAccessException e) { } catch (DataAccessException e) {
log.error("Reporting error: {}", e.getMessage()); log.error("Reporting error: {}", e.getMessage());
throw new PlatformDataIntegrityException("error.msg.report.unknown.data.integrity.issue", e.getClass().getName(), e); throw ErrorHandler.getMappable(e, "error.msg.report.unknown.data.integrity.issue", e.getClass().getName(), null, e);
} }
} }
@@ -45,7 +45,7 @@ import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.config.FineractProperties; import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport; import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
import org.apache.fineract.infrastructure.core.service.database.JdbcJavaType; import org.apache.fineract.infrastructure.core.service.database.JdbcJavaType;
import org.apache.fineract.infrastructure.dataqueries.data.GenericResultsetData; import org.apache.fineract.infrastructure.dataqueries.data.GenericResultsetData;
@@ -86,7 +86,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
final GenericResultsetData result = retrieveGenericResultset(name, type, queryParams, isSelfServiceUserReport); final GenericResultsetData result = retrieveGenericResultset(name, type, queryParams, isSelfServiceUserReport);
generateCsvFileBuffer(result, out); generateCsvFileBuffer(result, out);
} catch (final Exception e) { } catch (final Exception e) {
throw new PlatformDataIntegrityException("error.msg.exception.error", e.getMessage(), e); throw ErrorHandler.getMappable(e);
} }
}; };
} }
@@ -255,7 +255,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
return genaratePdf; return genaratePdf;
} catch (final Exception e) { } catch (final Exception e) {
log.error("error.msg.reporting.error:", e); log.error("error.msg.reporting.error:", e);
throw new PlatformDataIntegrityException("error.msg.exception.error", e.getMessage(), e); throw ErrorHandler.getMappable(e);
} }
} }
@@ -79,6 +79,7 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.exception.PlatformServiceUnavailableException; import org.apache.fineract.infrastructure.core.exception.PlatformServiceUnavailableException;
@@ -394,28 +395,10 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
} }
} catch (final JpaSystemException | DataIntegrityViolationException dve) { } catch (final JpaSystemException | DataIntegrityViolationException dve) {
final Throwable cause = dve.getCause(); handleDataIntegrityIssues(dataTableName, null, dve.getMostSpecificCause(), dve);
final Throwable realCause = dve.getMostSpecificCause();
// even if duplicate is only due to permission duplicate, okay to
// show duplicate datatable error msg
if (realCause.getMessage().contains("Duplicate entry") || cause.getMessage().contains("Duplicate entry")) {
throw new PlatformDataIntegrityException("error.msg.datatable.registered",
"Datatable `" + dataTableName + "` is already registered against an application table.", API_PARAM_DATATABLE_NAME,
dataTableName, dve);
}
logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", dve);
} catch (final PersistenceException dve) { } catch (final PersistenceException dve) {
final Throwable cause = dve.getCause(); handleDataIntegrityIssues(dataTableName, null, ExceptionUtils.getRootCause(dve.getCause()), dve);
if (cause.getMessage().contains("Duplicate entry")) {
throw new PlatformDataIntegrityException("error.msg.datatable.registered",
"Datatable `" + dataTableName + "` is already registered against an application table.", API_PARAM_DATATABLE_NAME,
dataTableName, dve);
}
logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", dve);
} }
} }
@@ -1353,41 +1336,11 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
} }
return CommandProcessingResult.fromCommandProcessingResult(commandProcessingResult, resourceId); return CommandProcessingResult.fromCommandProcessingResult(commandProcessingResult, resourceId);
} catch (final DataAccessException dve) { } catch (final DataAccessException dve) {
final Throwable cause = dve.getCause(); handleDataIntegrityIssues(dataTableName, appTableId, dve.getMostSpecificCause(), dve);
final Throwable realCause = dve.getMostSpecificCause(); return CommandProcessingResult.empty();
if (realCause.getMessage().contains("Duplicate entry") || cause.getMessage().contains("Duplicate entry")) {
throw new PlatformDataIntegrityException(
"error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName
+ "` and application table with identifier `" + appTableId + "`.",
API_PARAM_DATATABLE_NAME, dataTableName, appTableId, dve);
} else if (realCause.getMessage().contains("doesn't have a default value")
|| cause.getMessage().contains("doesn't have a default value")) {
throw new PlatformDataIntegrityException(
"error.msg.datatable.no.value.provided.for.required.fields", "No values provided for the datatable `"
+ dataTableName + "` and application table with identifier `" + appTableId + "`.",
API_PARAM_DATATABLE_NAME, dataTableName, appTableId, dve);
}
logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", dve);
} catch (final PersistenceException e) { } catch (final PersistenceException e) {
final Throwable cause = e.getCause(); handleDataIntegrityIssues(dataTableName, appTableId, ExceptionUtils.getRootCause(e.getCause()), e);
if (cause.getMessage().contains("Duplicate entry")) { return CommandProcessingResult.empty();
throw new PlatformDataIntegrityException(
"error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName
+ "` and application table with identifier `" + appTableId + "`.",
API_PARAM_DATATABLE_NAME, dataTableName, appTableId, e);
} else if (cause.getMessage().contains("doesn't have a default value")) {
throw new PlatformDataIntegrityException(
"error.msg.datatable.no.value.provided.for.required.fields", "No values provided for the datatable `"
+ dataTableName + "` and application table with identifier `" + appTableId + "`.",
API_PARAM_DATATABLE_NAME, dataTableName, appTableId, e);
}
logAsErrorUnexpectedDataIntegrityException(e);
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", e);
} }
} }
@@ -1785,7 +1738,36 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
return code + "_cd_" + columnName; return code + "_cd_" + columnName;
} }
private void logAsErrorUnexpectedDataIntegrityException(final Exception dve) { private void handleDataIntegrityIssues(String dataTableName, Long appTableId, final Throwable realCause, final Exception e) {
log.error("Error occurred.", dve); String msgCode = "error.msg.datatable";
String msg = "Unknown data integrity issue with datatable `" + dataTableName + "`";
String param = null;
Object[] msgArgs;
final Throwable cause = e.getCause();
if ((realCause != null && realCause.getMessage().contains("Duplicate entry"))
|| (cause != null && cause.getMessage().contains("Duplicate entry"))) {
msgCode += ".entry.duplicate";
param = API_PARAM_DATATABLE_NAME;
if (appTableId == null) {
msg = "Datatable `" + dataTableName + "` is already registered against an application table.";
msgArgs = new Object[] { dataTableName, e };
} else {
msg = "An entry already exists for datatable `" + dataTableName + "` and application table with identifier `" + appTableId
+ "`.";
msgArgs = new Object[] { dataTableName, appTableId, e };
}
} else if ((realCause != null && realCause.getMessage().contains("doesn't have a default value"))
|| (cause != null && cause.getMessage().contains("doesn't have a default value"))) {
msgCode += ".no.value.provided.for.required.fields";
msg = "No values provided for the datatable `" + dataTableName + "` and application table with identifier `" + appTableId
+ "`.";
param = API_PARAM_DATATABLE_NAME;
msgArgs = new Object[] { dataTableName, appTableId, e };
} else {
msgCode += ".unknown.data.integrity.issue";
msgArgs = new Object[] { dataTableName, e };
}
log.error("Error occured.", e);
throw ErrorHandler.getMappable(e, msgCode, msg, param, msgArgs);
} }
} }
@@ -29,6 +29,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.dataqueries.domain.Report; import org.apache.fineract.infrastructure.dataqueries.domain.Report;
import org.apache.fineract.infrastructure.dataqueries.domain.ReportParameter; import org.apache.fineract.infrastructure.dataqueries.domain.ReportParameter;
@@ -179,7 +180,6 @@ public class ReportWritePlatformServiceImpl implements ReportWritePlatformServic
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleReportDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleReportDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("unq_report_name") || realCause.getMessage().contains("report_name_UNIQUE")) { if (realCause.getMessage().contains("unq_report_name") || realCause.getMessage().contains("report_name_UNIQUE")) {
final String name = command.stringValueOfParameterNamed("reportName"); final String name = command.stringValueOfParameterNamed("reportName");
throw new PlatformDataIntegrityException("error.msg.report.duplicate.name", "A report with name '" + name + "' already exists", throw new PlatformDataIntegrityException("error.msg.report.duplicate.name", "A report with name '" + name + "' already exists",
@@ -187,7 +187,7 @@ public class ReportWritePlatformServiceImpl implements ReportWritePlatformServic
} }
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.report.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.report.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
@@ -20,7 +20,7 @@ package org.apache.fineract.infrastructure.documentmanagement.service;
import java.io.InputStream; import java.io.InputStream;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.documentmanagement.command.DocumentCommand; import org.apache.fineract.infrastructure.documentmanagement.command.DocumentCommand;
import org.apache.fineract.infrastructure.documentmanagement.command.DocumentCommandValidator; import org.apache.fineract.infrastructure.documentmanagement.command.DocumentCommandValidator;
import org.apache.fineract.infrastructure.documentmanagement.contentrepository.ContentRepository; import org.apache.fineract.infrastructure.documentmanagement.contentrepository.ContentRepository;
@@ -82,8 +82,8 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
return document.getId(); return document.getId();
} catch (final JpaSystemException | DataIntegrityViolationException dve) { } catch (final JpaSystemException | DataIntegrityViolationException dve) {
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.document.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.document.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", dve); "Unknown data integrity issue with resource.");
} }
} }
@@ -136,8 +136,8 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
return CommandProcessingResult.resourceResult(documentForUpdate.getId()); return CommandProcessingResult.resourceResult(documentForUpdate.getId());
} catch (final JpaSystemException | DataIntegrityViolationException dve) { } catch (final JpaSystemException | DataIntegrityViolationException dve) {
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.document.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.document.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", dve); "Unknown data integrity issue with resource.");
} catch (final ContentManagementException cme) { } catch (final ContentManagementException cme) {
LOG.error("Error occured.", cme); LOG.error("Error occured.", cme);
throw new ContentManagementException(documentCommand.getName(), cme.getMessage(), cme); throw new ContentManagementException(documentCommand.getName(), cme.getMessage(), cme);
@@ -26,6 +26,7 @@ import org.apache.fineract.infrastructure.codes.domain.CodeValue;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.entityaccess.api.FineractEntityApiResourceConstants; import org.apache.fineract.infrastructure.entityaccess.api.FineractEntityApiResourceConstants;
@@ -171,12 +172,8 @@ public class FineractEntityAccessWriteServiceImpl implements FineractEntityAcces
"EntityMapping from " + fromId + " to " + toId + " already exist"); "EntityMapping from " + fromId + " to " + toId + " already exist");
} }
logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.entity.mapping", "Unknown data integrity issue with resource.");
}
private void logAsErrorUnexpectedDataIntegrityException(final Exception dve) {
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw ErrorHandler.getMappable(dve, "error.msg.entity.mapping", "Unknown data integrity issue with resource.");
} }
/* /*
@@ -186,5 +183,4 @@ public class FineractEntityAccessWriteServiceImpl implements FineractEntityAcces
* @Override public CommandProcessingResult removeEntityAccess(String entityType, Long entityId, Long accessType, * @Override public CommandProcessingResult removeEntityAccess(String entityType, Long entityId, Long accessType,
* String secondEntityType, Long secondEntityId) { // TODO Auto-generated method stub return null; } * String secondEntityType, Long secondEntityId) { // TODO Auto-generated method stub return null; }
*/ */
} }
@@ -21,6 +21,7 @@ package org.apache.fineract.infrastructure.gcm.service;
import jakarta.persistence.EntityExistsException; import jakarta.persistence.EntityExistsException;
import jakarta.persistence.PersistenceException; import jakarta.persistence.PersistenceException;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.gcm.domain.DeviceRegistration; import org.apache.fineract.infrastructure.gcm.domain.DeviceRegistration;
@@ -77,13 +78,11 @@ public class DeviceRegistrationWritePlatformServiceImpl implements DeviceRegistr
} }
private void handleDataIntegrityIssues(final String registrationId, final Throwable realCause) { private void handleDataIntegrityIssues(final String registrationId, final Throwable realCause) {
if (realCause.getMessage().contains("registration_key")) { if (realCause.getMessage().contains("registration_key")) {
throw new PlatformDataIntegrityException("error.msg.duplicate.device.registration.id", throw new PlatformDataIntegrityException("error.msg.duplicate.device.registration.id",
"Registration id : " + registrationId + " already exist.", "name", registrationId); "Registration id : " + registrationId + " already exist.", "name", registrationId);
} }
throw ErrorHandler.getMappable(realCause, "error.msg.charge.unknown.data.integrity.issue",
throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
@@ -44,6 +44,7 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
@@ -309,8 +310,7 @@ public class HookWritePlatformServiceJpaRepositoryImpl implements HookWritePlatf
throw new PlatformDataIntegrityException("error.msg.hook.duplicate.name", "A hook with name '" + name + "' already exists", throw new PlatformDataIntegrityException("error.msg.hook.duplicate.name", "A hook with name '" + name + "' already exists",
"name", name); "name", name);
} }
throw ErrorHandler.getMappable(dve, "error.msg.unknown.data.integrity.issue",
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.dataqueries.domain.Report; import org.apache.fineract.infrastructure.dataqueries.domain.Report;
@@ -236,7 +237,6 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo
**/ **/
private void handleDataIntegrityIssues(final JsonCommand jsonCommand, final Throwable realCause, private void handleDataIntegrityIssues(final JsonCommand jsonCommand, final Throwable realCause,
final NonTransientDataAccessException dve) { final NonTransientDataAccessException dve) {
if (realCause.getMessage().contains(ReportMailingJobConstants.NAME_PARAM_NAME)) { if (realCause.getMessage().contains(ReportMailingJobConstants.NAME_PARAM_NAME)) {
final String name = jsonCommand.stringValueOfParameterNamed(ReportMailingJobConstants.NAME_PARAM_NAME); final String name = jsonCommand.stringValueOfParameterNamed(ReportMailingJobConstants.NAME_PARAM_NAME);
throw new PlatformDataIntegrityException("error.msg.report.mailing.job.duplicate.name", throw new PlatformDataIntegrityException("error.msg.report.mailing.job.duplicate.name",
@@ -244,8 +244,7 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo
} }
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw ErrorHandler.getMappable(dve, "error.msg.charge.unknown.data.integrity.issue",
throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -22,6 +22,7 @@ import java.util.Map;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.sms.data.SmsDataValidator; import org.apache.fineract.infrastructure.sms.data.SmsDataValidator;
import org.apache.fineract.infrastructure.sms.domain.SmsMessage; import org.apache.fineract.infrastructure.sms.domain.SmsMessage;
@@ -126,14 +127,13 @@ public class SmsWritePlatformServiceJpaRepositoryImpl implements SmsWritePlatfor
*/ */
private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final Throwable realCause, private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final Throwable realCause,
final NonTransientDataAccessException dve) { final NonTransientDataAccessException dve) {
if (realCause.getMessage().contains("mobile_no")) { if (realCause.getMessage().contains("mobile_no")) {
throw new PlatformDataIntegrityException("error.msg.sms.no.mobile.no.exists", throw new PlatformDataIntegrityException("error.msg.sms.no.mobile.no.exists",
"The group, client or staff provided has no mobile no.", "id"); "The group, client or staff provided has no mobile no.", "id");
} }
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.sms.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.sms.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -22,7 +22,7 @@ import java.util.List;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.infrastructure.survey.data.LikelihoodDataValidator; import org.apache.fineract.infrastructure.survey.data.LikelihoodDataValidator;
import org.apache.fineract.infrastructure.survey.data.LikelihoodStatus; import org.apache.fineract.infrastructure.survey.data.LikelihoodStatus;
@@ -96,9 +96,8 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService {
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final Throwable realCause, final NonTransientDataAccessException dve) { private void handleDataIntegrityIssues(final Throwable realCause, final NonTransientDataAccessException dve) {
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.likelihood.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.likelihood.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -47,6 +47,7 @@ import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
@@ -624,7 +625,6 @@ public class InteropServiceImpl implements InteropService {
*/ */
private void handleInteropDataIntegrityIssues(InteropIdentifierType idType, String accountId, final Throwable realCause, private void handleInteropDataIntegrityIssues(InteropIdentifierType idType, String accountId, final Throwable realCause,
final Exception dve) { final Exception dve) {
if (realCause.getMessage().contains("uk_interop_identifier_account")) { if (realCause.getMessage().contains("uk_interop_identifier_account")) {
throw new PlatformDataIntegrityException("error.msg.interop.duplicate.account.identifier", throw new PlatformDataIntegrityException("error.msg.interop.duplicate.account.identifier",
"Account identifier of type `" + idType.name() + "' already exists for account with externalId `" + accountId + "`", "Account identifier of type `" + idType.name() + "' already exists for account with externalId `" + accountId + "`",
@@ -632,8 +632,8 @@ public class InteropServiceImpl implements InteropService {
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.interop.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.interop.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
@NotNull @NotNull
@@ -33,6 +33,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
@@ -170,8 +171,8 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.office.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.office.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
private void validateInputDates(final JsonCommand command) { private void validateInputDates(final JsonCommand command) {
@@ -26,6 +26,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.exception.NoAuthorizationException; import org.apache.fineract.infrastructure.security.exception.NoAuthorizationException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -204,7 +205,6 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleOfficeDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleOfficeDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("externalid_org")) { if (realCause.getMessage().contains("externalid_org")) {
final String externalId = command.stringValueOfParameterNamed("externalId"); final String externalId = command.stringValueOfParameterNamed("externalId");
throw new PlatformDataIntegrityException("error.msg.office.duplicate.externalId", throw new PlatformDataIntegrityException("error.msg.office.duplicate.externalId",
@@ -216,8 +216,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.office.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.office.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
"Unknown data integrity issue with resource.");
} }
/* /*
@@ -26,6 +26,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.organisation.provisioning.domain.ProvisioningCategory; import org.apache.fineract.organisation.provisioning.domain.ProvisioningCategory;
import org.apache.fineract.organisation.provisioning.domain.ProvisioningCategoryRepository; import org.apache.fineract.organisation.provisioning.domain.ProvisioningCategoryRepository;
@@ -33,7 +34,6 @@ import org.apache.fineract.organisation.provisioning.exception.ProvisioningCateg
import org.apache.fineract.organisation.provisioning.exception.ProvisioningCategoryNotFoundException; import org.apache.fineract.organisation.provisioning.exception.ProvisioningCategoryNotFoundException;
import org.apache.fineract.organisation.provisioning.serialization.ProvisioningCategoryDefinitionJsonDeserializer; import org.apache.fineract.organisation.provisioning.serialization.ProvisioningCategoryDefinitionJsonDeserializer;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.NonTransientDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.jpa.JpaSystemException; import org.springframework.orm.jpa.JpaSystemException;
@@ -108,29 +108,14 @@ public class ProvisioningCategoryWritePlatformServiceJpaRepositoryImpl implement
/* /*
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
final NonTransientDataAccessException dve) {
if (realCause.getMessage().contains("category_name")) { if (realCause.getMessage().contains("category_name")) {
final String name = command.stringValueOfParameterNamed("category_name"); final String name = command.stringValueOfParameterNamed("category_name");
throw new PlatformDataIntegrityException("error.msg.provisioning.duplicate.categoryname", throw new PlatformDataIntegrityException("error.msg.provisioning.duplicate.categoryname",
"Provisioning Cateory with name `" + name + "` already exists", "category name", name); "Provisioning Cateory with name `" + name + "` already exists", "category name", name);
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.charge.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final PersistenceException dve) {
if (realCause.getMessage().contains("category_name")) {
final String name = command.stringValueOfParameterNamed("category_name");
throw new PlatformDataIntegrityException("error.msg.provisioning.duplicate.categoryname",
"Provisioning Cateory with name `" + name + "` already exists", "category name", name);
}
log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage());
}
} }
@@ -35,6 +35,7 @@ import org.apache.fineract.accounting.provisioning.service.ProvisioningEntriesRe
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.organisation.provisioning.constants.ProvisioningCriteriaConstants; import org.apache.fineract.organisation.provisioning.constants.ProvisioningCriteriaConstants;
@@ -158,7 +159,7 @@ public class ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl implement
"The selected products already associated with another Provisioning Criteria"); "The selected products already associated with another Provisioning Criteria");
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.provisioning.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.provisioning.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -27,6 +27,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.organisation.office.domain.Office; import org.apache.fineract.organisation.office.domain.Office;
import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper; import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
@@ -110,9 +111,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleStaffDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleStaffDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("external_id")) { if (realCause.getMessage().contains("external_id")) {
final String externalId = command.stringValueOfParameterNamed("externalId"); final String externalId = command.stringValueOfParameterNamed("externalId");
throw new PlatformDataIntegrityException("error.msg.staff.duplicate.externalId", throw new PlatformDataIntegrityException("error.msg.staff.duplicate.externalId",
"Staff with externalId `" + externalId + "` already exists", "externalId", externalId); "Staff with externalId `" + externalId + "` already exists", "externalId", externalId);
@@ -128,7 +127,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.staff.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.staff.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -34,6 +34,7 @@ import org.apache.fineract.accounting.journalentry.domain.JournalEntryType;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.exception.NoAuthorizationException; import org.apache.fineract.infrastructure.security.exception.NoAuthorizationException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -182,7 +183,6 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleTellerDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleTellerDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("m_tellers_name_unq")) { if (realCause.getMessage().contains("m_tellers_name_unq")) {
final String name = command.stringValueOfParameterNamed("name"); final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException("error.msg.teller.duplicate.name", "Teller with name `" + name + "` already exists", throw new PlatformDataIntegrityException("error.msg.teller.duplicate.name", "Teller with name `" + name + "` already exists",
@@ -190,8 +190,8 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.teller.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.teller.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
@Override @Override
@@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.portfolio.account.PortfolioAccountType; import org.apache.fineract.portfolio.account.PortfolioAccountType;
import org.apache.fineract.portfolio.account.api.StandingInstructionApiConstants; import org.apache.fineract.portfolio.account.api.StandingInstructionApiConstants;
@@ -98,15 +99,14 @@ public class StandingInstructionWritePlatformServiceImpl implements StandingInst
} }
private void handleDataIntegrityIssues(final JsonCommand command, Throwable realCause, final NonTransientDataAccessException dve) { private void handleDataIntegrityIssues(final JsonCommand command, Throwable realCause, final NonTransientDataAccessException dve) {
if (realCause.getMessage().contains("name")) { if (realCause.getMessage().contains("name")) {
final String name = command.stringValueOfParameterNamed(StandingInstructionApiConstants.nameParamName); final String name = command.stringValueOfParameterNamed(StandingInstructionApiConstants.nameParamName);
throw new PlatformDataIntegrityException("error.msg.standinginstruction.duplicate.name", throw new PlatformDataIntegrityException("error.msg.standinginstruction.duplicate.name",
"Standinginstruction with name `" + name + "` already exists", "name", name); "Standinginstruction with name `" + name + "` already exists", "name", name);
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.client.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.client.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
private boolean isLoanToSavingsAccountTransfer(final PortfolioAccountType fromAccountType, final PortfolioAccountType toAccountType) { private boolean isLoanToSavingsAccountTransfer(final PortfolioAccountType fromAccountType, final PortfolioAccountType toAccountType) {
@@ -29,6 +29,7 @@ import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrappe
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.entityaccess.domain.FineractEntityAccessType; import org.apache.fineract.infrastructure.entityaccess.domain.FineractEntityAccessType;
import org.apache.fineract.infrastructure.entityaccess.service.FineractEntityAccessUtil; import org.apache.fineract.infrastructure.entityaccess.service.FineractEntityAccessUtil;
@@ -237,7 +238,6 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("name")) { if (realCause.getMessage().contains("name")) {
final String name = command.stringValueOfParameterNamed("name"); final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException("error.msg.charge.duplicate.name", "Charge with name `" + name + "` already exists", throw new PlatformDataIntegrityException("error.msg.charge.duplicate.name", "Charge with name `" + name + "` already exists",
@@ -245,7 +245,7 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.charge.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
@@ -36,6 +36,7 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.domain.ExternalId; import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
@@ -420,17 +421,15 @@ public class ClientChargeWritePlatformServiceImpl implements ClientChargeWritePl
private void handleDataIntegrityIssues(@SuppressWarnings("unused") final Long clientId, final Long clientChargeId, private void handleDataIntegrityIssues(@SuppressWarnings("unused") final Long clientId, final Long clientChargeId,
final Throwable realCause, final NonTransientDataAccessException dve) { final Throwable realCause, final NonTransientDataAccessException dve) {
if (realCause.getMessage().contains("FK_m_client_charge_paid_by_m_client_charge")) { if (realCause.getMessage().contains("FK_m_client_charge_paid_by_m_client_charge")) {
throw new PlatformDataIntegrityException("error.msg.client.charge.cannot.be.deleted", throw new PlatformDataIntegrityException("error.msg.client.charge.cannot.be.deleted",
"Client charge with id `" + clientChargeId + "` cannot be deleted as transactions have been made on the same", "Client charge with id `" + clientChargeId + "` cannot be deleted as transactions have been made on the same",
"clientChargeId", clientChargeId); "clientChargeId", clientChargeId);
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.client.charges.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.client.charges.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -27,7 +27,7 @@ import org.apache.fineract.infrastructure.codes.exception.CodeValueNotFoundExcep
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.client.command.ClientIdentifierCommand; import org.apache.fineract.portfolio.client.command.ClientIdentifierCommand;
import org.apache.fineract.portfolio.client.domain.Client; import org.apache.fineract.portfolio.client.domain.Client;
@@ -199,7 +199,7 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl
} }
logAsErrorUnexpectedDataIntegrityException(dve); logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.clientIdentifier.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.clientIdentifier.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
@@ -43,6 +43,7 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.domain.ExternalId; import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
@@ -152,8 +153,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
} catch (final JpaSystemException | DataIntegrityViolationException dve) { } catch (final JpaSystemException | DataIntegrityViolationException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
log.error("Error occured.", throwable); log.error("Error occured.", throwable);
throw new PlatformDataIntegrityException("error.msg.client.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.client.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", dve); "Unknown data integrity issue with resource.");
} }
} }
@@ -161,9 +162,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("external_id")) { if (realCause.getMessage().contains("external_id")) {
final String externalId = command.stringValueOfParameterNamed("externalId"); final String externalId = command.stringValueOfParameterNamed("externalId");
throw new PlatformDataIntegrityException("error.msg.client.duplicate.externalId", throw new PlatformDataIntegrityException("error.msg.client.duplicate.externalId",
"Client with externalId `" + externalId + "` already exists", "externalId", externalId); "Client with externalId `" + externalId + "` already exists", "externalId", externalId);
@@ -178,8 +177,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
} }
logAsErrorUnexpectedDataIntegrityException(dve); logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.client.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.client.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
@Transactional @Transactional
@@ -26,7 +26,7 @@ import org.apache.fineract.infrastructure.codes.domain.CodeValueRepositoryWrappe
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.collateral.api.CollateralApiConstants; import org.apache.fineract.portfolio.collateral.api.CollateralApiConstants;
import org.apache.fineract.portfolio.collateral.api.CollateralApiConstants.CollateralJSONinputParams; import org.apache.fineract.portfolio.collateral.api.CollateralApiConstants.CollateralJSONinputParams;
@@ -165,7 +165,7 @@ public class CollateralWritePlatformServiceJpaRepositoryImpl implements Collater
private void handleCollateralDataIntegrityViolation(final NonTransientDataAccessException dve) { private void handleCollateralDataIntegrityViolation(final NonTransientDataAccessException dve) {
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.collateral.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.collateral.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
} }
@@ -26,6 +26,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.portfolio.floatingrates.domain.FloatingRate; import org.apache.fineract.portfolio.floatingrates.domain.FloatingRate;
import org.apache.fineract.portfolio.floatingrates.domain.FloatingRateRepositoryWrapper; import org.apache.fineract.portfolio.floatingrates.domain.FloatingRateRepositoryWrapper;
@@ -90,27 +91,17 @@ public class FloatingRateWritePlatformServiceImpl implements FloatingRateWritePl
} }
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("unq_name")) { if (realCause.getMessage().contains("unq_name")) {
final String name = command.stringValueOfParameterNamed("name"); final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException("error.msg.floatingrates.duplicate.name", throw new PlatformDataIntegrityException("error.msg.floatingrates.duplicate.name",
"Floating Rate with name `" + name + "` already exists", "name", name); "Floating Rate with name `" + name + "` already exists", "name", name);
} }
if (realCause.getMessage().contains("unq_rate_period")) { if (realCause.getMessage().contains("unq_rate_period")) {
throw new PlatformDataIntegrityException("error.msg.floatingrates.duplicate.active.fromdate", throw new PlatformDataIntegrityException("error.msg.floatingrates.duplicate.active.fromdate",
"Attempt to add multiple floating rate periods with same fromdate", "fromdate", ""); "Attempt to add multiple floating rate periods with same fromdate", "fromdate", "");
} }
logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.floatingrates.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
private void logAsErrorUnexpectedDataIntegrityException(Exception dve) {
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw ErrorHandler.getMappable(dve, "error.msg.floatingrates.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -26,6 +26,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.fund.domain.Fund; import org.apache.fineract.portfolio.fund.domain.Fund;
@@ -113,7 +114,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.fund.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -26,6 +26,7 @@ import org.apache.fineract.infrastructure.codes.domain.CodeValueRepositoryWrappe
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.client.domain.Client; import org.apache.fineract.portfolio.client.domain.Client;
@@ -96,8 +97,7 @@ public class GroupRolesWritePlatformServiceJpaRepositoryImpl implements GroupRol
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.group.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
"Unknown data integrity issue with resource.");
} }
@Override @Override
@@ -42,6 +42,7 @@ import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDoma
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
@@ -567,8 +568,8 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
} catch (final JpaSystemException | DataIntegrityViolationException dve) { } catch (final JpaSystemException | DataIntegrityViolationException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
log.error("Error occured.", throwable); log.error("Error occured.", throwable);
throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.group.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", dve); "Unknown data integrity issue with resource.");
} }
} }
@@ -727,7 +728,6 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
*/ */
private void handleGroupDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve, private void handleGroupDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve,
final GroupTypes groupLevel) { final GroupTypes groupLevel) {
String levelName = "Invalid"; String levelName = "Invalid";
switch (groupLevel) { switch (groupLevel) {
case CENTER: case CENTER:
@@ -742,16 +742,13 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
String errorMessageForUser = null; String errorMessageForUser = null;
String errorMessageForMachine = null; String errorMessageForMachine = null;
if (realCause.getMessage().contains("'external_id'")) { if (realCause.getMessage().contains("'external_id'")) {
final String externalId = command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName); final String externalId = command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName);
errorMessageForUser = levelName + " with externalId `" + externalId + "` already exists."; errorMessageForUser = levelName + " with externalId `" + externalId + "` already exists.";
errorMessageForMachine = "error.msg." + levelName.toLowerCase() + ".duplicate.externalId"; errorMessageForMachine = "error.msg." + levelName.toLowerCase() + ".duplicate.externalId";
throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser,
GroupingTypesApiConstants.externalIdParamName, externalId); GroupingTypesApiConstants.externalIdParamName, externalId);
} else if (realCause.getMessage().contains("'name'")) { } else if (realCause.getMessage().contains("'name'")) {
final String name = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName); final String name = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName);
errorMessageForUser = levelName + " with name `" + name + "` already exists."; errorMessageForUser = levelName + " with name `" + name + "` already exists.";
errorMessageForMachine = "error.msg." + levelName.toLowerCase() + ".duplicate.name"; errorMessageForMachine = "error.msg." + levelName.toLowerCase() + ".duplicate.name";
@@ -760,8 +757,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
} }
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.group.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
"Unknown data integrity issue with resource.");
} }
@Override @Override
@@ -29,9 +29,9 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.staff.domain.StaffRepositoryWrapper; import org.apache.fineract.organisation.staff.domain.StaffRepositoryWrapper;
import org.apache.fineract.portfolio.account.domain.AccountAssociationType; import org.apache.fineract.portfolio.account.domain.AccountAssociationType;
@@ -351,7 +351,7 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
private void handleGuarantorDataIntegrityIssues(final Throwable realCause, final NonTransientDataAccessException dve) { private void handleGuarantorDataIntegrityIssues(final Throwable realCause, final NonTransientDataAccessException dve) {
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.guarantor.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.guarantor.unknown.data.integrity.issue",
"Unknown data integrity issue with resource Guarantor: " + realCause.getMessage()); "Unknown data integrity issue with resource Guarantor: " + realCause.getMessage());
} }
} }
@@ -39,9 +39,9 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRescheduledDueAdjustScheduleBusinessEvent; import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRescheduledDueAdjustScheduleBusinessEvent;
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
@@ -580,11 +580,8 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
* *
**/ **/
private void handleDataIntegrityViolation(final NonTransientDataAccessException dve) { private void handleDataIntegrityViolation(final NonTransientDataAccessException dve) {
LOG.error("Error occured.", dve); LOG.error("Error occured.", dve);
throw ErrorHandler.getMappable(dve, "error.msg.loan.reschedule.unknown.data.integrity.issue",
throw new PlatformDataIntegrityException("error.msg.loan.reschedule.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
} }
@@ -49,6 +49,7 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.domain.ExternalId; import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
@@ -1188,7 +1189,6 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("loan_account_no_UNIQUE") if (realCause.getMessage().contains("loan_account_no_UNIQUE")
|| (realCause.getCause() != null && realCause.getCause().getMessage().contains("loan_account_no_UNIQUE"))) { || (realCause.getCause() != null && realCause.getCause().getMessage().contains("loan_account_no_UNIQUE"))) {
@@ -1202,12 +1202,8 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
"Loan with externalId `" + externalId + "` already exists", "externalId", externalId); "Loan with externalId `" + externalId + "` already exists", "externalId", externalId);
} }
logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
}
private void logAsErrorUnexpectedDataIntegrityException(final Exception dve) {
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw ErrorHandler.getMappable(dve, "error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
} }
@Transactional @Transactional
@@ -40,7 +40,6 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService; import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.cob.exceptions.LoanAccountLockCannotBeOverruledException; import org.apache.fineract.cob.exceptions.LoanAccountLockCannotBeOverruledException;
import org.apache.fineract.cob.service.LoanAccountLockService; import org.apache.fineract.cob.service.LoanAccountLockService;
import org.apache.fineract.infrastructure.codes.domain.CodeValue; import org.apache.fineract.infrastructure.codes.domain.CodeValue;
@@ -52,6 +51,7 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.domain.ExternalId; import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformServiceUnavailableException; import org.apache.fineract.infrastructure.core.exception.PlatformServiceUnavailableException;
@@ -19,13 +19,13 @@
package org.apache.fineract.portfolio.loanaccount.starter; package org.apache.fineract.portfolio.loanaccount.starter;
import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService; import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.cob.service.LoanAccountLockService; import org.apache.fineract.cob.service.LoanAccountLockService;
import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatRepositoryWrapper; import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatRepositoryWrapper;
import org.apache.fineract.infrastructure.codes.domain.CodeValueRepositoryWrapper; import org.apache.fineract.infrastructure.codes.domain.CodeValueRepositoryWrapper;
import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationRepositoryWrapper; import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationRepositoryWrapper;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.service.ExternalIdFactory; import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
import org.apache.fineract.infrastructure.core.service.PaginationHelper; import org.apache.fineract.infrastructure.core.service.PaginationHelper;
@@ -29,7 +29,7 @@ import java.util.Set;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProduct; import org.apache.fineract.portfolio.loanproduct.domain.LoanProduct;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProductRepository; import org.apache.fineract.portfolio.loanproduct.domain.LoanProductRepository;
@@ -192,7 +192,7 @@ public class ProductMixWritePlatformServiceJpaRepositoryImpl implements ProductM
private void handleDataIntegrityIssues(final NonTransientDataAccessException dve) { private void handleDataIntegrityIssues(final NonTransientDataAccessException dve) {
LOG.error("Error occurred.", dve); LOG.error("Error occurred.", dve);
throw new PlatformDataIntegrityException("error.msg.product.loan.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.product.loan.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
@@ -32,6 +32,7 @@ import org.apache.fineract.accounting.producttoaccountmapping.service.ProductToG
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.entityaccess.domain.FineractEntityAccessType; import org.apache.fineract.infrastructure.entityaccess.domain.FineractEntityAccessType;
@@ -331,7 +332,6 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("'external_id'")) { if (realCause.getMessage().contains("'external_id'")) {
final String externalId = command.stringValueOfParameterNamed("externalId"); final String externalId = command.stringValueOfParameterNamed("externalId");
@@ -354,8 +354,8 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
} }
logAsErrorUnexpectedDataIntegrityException(dve); logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.product.loan.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.product.loan.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", realCause); "Unknown data integrity issue with resource.", null, realCause);
} }
private static boolean containsDuplicateShortnameErrorForPostgreSQL(Throwable realCause) { private static boolean containsDuplicateShortnameErrorForPostgreSQL(Throwable realCause) {
@@ -38,6 +38,7 @@ import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDoma
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.portfolio.calendar.domain.Calendar; import org.apache.fineract.portfolio.calendar.domain.Calendar;
@@ -284,7 +285,7 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit
"A meeting with date '" + meetingDate + "' already exists", meetingDateParamName, meetingDate); "A meeting with date '" + meetingDate + "' already exists", meetingDateParamName, meetingDate);
} }
throw new PlatformDataIntegrityException("error.msg.meeting.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.meeting.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
@@ -23,6 +23,7 @@ import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.portfolio.paymenttype.api.PaymentTypeApiResourceConstants; import org.apache.fineract.portfolio.paymenttype.api.PaymentTypeApiResourceConstants;
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDataValidator; import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDataValidator;
@@ -89,7 +90,6 @@ public class PaymentTypeWriteServiceImpl implements PaymentTypeWriteService {
} }
private void handleDataIntegrityIssues(final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("acc_product_mapping")) { if (realCause.getMessage().contains("acc_product_mapping")) {
throw new PlatformDataIntegrityException("error.msg.payment.type.association.exist", throw new PlatformDataIntegrityException("error.msg.payment.type.association.exist",
"cannot.delete.payment.type.with.association"); "cannot.delete.payment.type.with.association");
@@ -97,8 +97,7 @@ public class PaymentTypeWriteServiceImpl implements PaymentTypeWriteService {
throw new PlatformDataIntegrityException("error.msg.payment.type.association.exist", throw new PlatformDataIntegrityException("error.msg.payment.type.association.exist",
"cannot.delete.payment.type.with.association"); "cannot.delete.payment.type.with.association");
} }
throw ErrorHandler.getMappable(dve, "error.msg.paymenttypes.unknown.data.integrity.issue",
throw new PlatformDataIntegrityException("error.msg.paymenttypes.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
} }
@@ -28,6 +28,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.rate.domain.Rate; import org.apache.fineract.portfolio.rate.domain.Rate;
@@ -132,7 +133,7 @@ public class RateWriteServiceImpl implements RateWriteService {
} }
log.error("Error due to Exception", dve); log.error("Error due to Exception", dve);
throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.fund.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -45,9 +45,9 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.event.business.domain.deposit.FixedDepositAccountCreateBusinessEvent; import org.apache.fineract.infrastructure.event.business.domain.deposit.FixedDepositAccountCreateBusinessEvent;
import org.apache.fineract.infrastructure.event.business.domain.deposit.RecurringDepositAccountCreateBusinessEvent; import org.apache.fineract.infrastructure.event.business.domain.deposit.RecurringDepositAccountCreateBusinessEvent;
@@ -126,26 +126,29 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
String msgCode = "error.msg." + SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
final StringBuilder errorCodeBuilder = new StringBuilder("error.msg.").append(SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME); String msg = "Unknown data integrity issue with savings account.";
String param = null;
if (realCause.getMessage().contains("'sa_account_no_UNIQUE'")) { Object[] msgArgs;
Throwable checkEx = realCause == null ? dve : realCause;
if (checkEx.getMessage().contains("sa_account_no_UNIQUE")) {
final String accountNo = command.stringValueOfParameterNamed("accountNo"); final String accountNo = command.stringValueOfParameterNamed("accountNo");
errorCodeBuilder.append(".duplicate.accountNo"); msgCode += ".duplicate.accountNo";
throw new PlatformDataIntegrityException(errorCodeBuilder.toString(), msg = "Savings account with accountNo " + accountNo + " already exists";
"Savings account with accountNo " + accountNo + " already exists", "accountNo", accountNo); param = "accountNo";
msgArgs = new Object[] { accountNo, dve };
} else if (realCause.getMessage().contains("sa_external_id_UNIQUE")) { } else if (checkEx.getMessage().contains("sa_external_id_UNIQUE")) {
final String externalId = command.stringValueOfParameterNamed("externalId"); final String externalId = command.stringValueOfParameterNamed("externalId");
errorCodeBuilder.append(".duplicate.externalId"); msgCode += ".duplicate.externalId";
throw new PlatformDataIntegrityException(errorCodeBuilder.toString(), msg = "Savings account with externalId " + externalId + " already exists";
"Savings account with externalId " + externalId + " already exists", "externalId", externalId); param = "externalId";
msgArgs = new Object[] { externalId, dve };
} else {
msgCode += ".unknown.data.integrity.issue";
msgArgs = new Object[] { dve };
} }
errorCodeBuilder.append(".unknown.data.integrity.issue");
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException(errorCodeBuilder.toString(), "Unknown data integrity issue with savings account."); throw ErrorHandler.getMappable(dve, msgCode, msg, param, msgArgs);
} }
@Transactional @Transactional
@@ -37,12 +37,13 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.charge.domain.Charge; import org.apache.fineract.portfolio.charge.domain.Charge;
import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartAssembler; import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartAssembler;
import org.apache.fineract.portfolio.savings.DepositAccountType; import org.apache.fineract.portfolio.savings.DepositAccountType;
import org.apache.fineract.portfolio.savings.SavingsApiConstants;
import org.apache.fineract.portfolio.savings.data.DepositProductDataValidator; import org.apache.fineract.portfolio.savings.data.DepositProductDataValidator;
import org.apache.fineract.portfolio.savings.domain.DepositProductAssembler; import org.apache.fineract.portfolio.savings.domain.DepositProductAssembler;
import org.apache.fineract.portfolio.savings.domain.FixedDepositProduct; import org.apache.fineract.portfolio.savings.domain.FixedDepositProduct;
@@ -85,8 +86,7 @@ public class FixedDepositProductWritePlatformServiceJpaRepositoryImpl implements
handleDataIntegrityIssues(command, e.getMostSpecificCause(), e); handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} catch (final PersistenceException dve) { } catch (final PersistenceException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, ExceptionUtils.getRootCause(dve.getCause()), dve);
handleDataIntegrityIssues(command, throwable, dve);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} }
} }
@@ -145,8 +145,7 @@ public class FixedDepositProductWritePlatformServiceJpaRepositoryImpl implements
handleDataIntegrityIssues(command, e.getMostSpecificCause(), e); handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} catch (final PersistenceException dve) { } catch (final PersistenceException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, ExceptionUtils.getRootCause(dve.getCause()), dve);
handleDataIntegrityIssues(command, throwable, dve);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} }
} }
@@ -170,25 +169,28 @@ public class FixedDepositProductWritePlatformServiceJpaRepositoryImpl implements
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) {
String msgCode = "error.msg." + SavingsApiConstants.SAVINGS_PRODUCT_RESOURCE_NAME;
if (realCause.getMessage().contains("sp_unq_name")) { String msg = "Unknown data integrity issue with savings product.";
String param = null;
Object[] msgArgs;
Throwable checkEx = realCause == null ? dae : realCause;
if (checkEx.getMessage().contains("sp_unq_name")) {
final String name = command.stringValueOfParameterNamed("name"); final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException("error.msg.product.savings.duplicate.name", msgCode += ".duplicate.name";
"Savings product with name `" + name + "` already exists", "name", name); msg = "Savings product with name `" + name + "` already exists";
} else if (realCause.getMessage().contains("sp_unq_short_name")) { param = "name";
msgArgs = new Object[] { name, dae };
} else if (checkEx.getMessage().contains("sp_unq_short_name")) {
final String shortName = command.stringValueOfParameterNamed("shortName"); final String shortName = command.stringValueOfParameterNamed("shortName");
throw new PlatformDataIntegrityException("error.msg.product.savings.duplicate.short.name", msgCode += ".duplicate.short.name";
"Savings product with short name `" + shortName + "` already exists", "shortName", shortName); msg = "Savings product with short name `" + shortName + "` already exists";
param = "shortName";
msgArgs = new Object[] { shortName, dae };
} else {
msgCode += ".unknown.data.integrity.issue";
msgArgs = new Object[] { dae };
} }
logAsErrorUnexpectedDataIntegrityException(dae);
throw new PlatformDataIntegrityException("error.msg.savingsproduct.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
private void logAsErrorUnexpectedDataIntegrityException(final Exception dae) {
log.error("Error occured.", dae); log.error("Error occured.", dae);
throw ErrorHandler.getMappable(dae, msgCode, msg, param, msgArgs);
} }
} }
@@ -37,12 +37,13 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.charge.domain.Charge; import org.apache.fineract.portfolio.charge.domain.Charge;
import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartAssembler; import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartAssembler;
import org.apache.fineract.portfolio.savings.DepositAccountType; import org.apache.fineract.portfolio.savings.DepositAccountType;
import org.apache.fineract.portfolio.savings.SavingsApiConstants;
import org.apache.fineract.portfolio.savings.data.DepositProductDataValidator; import org.apache.fineract.portfolio.savings.data.DepositProductDataValidator;
import org.apache.fineract.portfolio.savings.domain.DepositProductAssembler; import org.apache.fineract.portfolio.savings.domain.DepositProductAssembler;
import org.apache.fineract.portfolio.savings.domain.RecurringDepositProduct; import org.apache.fineract.portfolio.savings.domain.RecurringDepositProduct;
@@ -85,8 +86,7 @@ public class RecurringDepositProductWritePlatformServiceJpaRepositoryImpl implem
handleDataIntegrityIssues(command, e.getMostSpecificCause(), e); handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} catch (final PersistenceException dve) { } catch (final PersistenceException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, ExceptionUtils.getRootCause(dve.getCause()), dve);
handleDataIntegrityIssues(command, throwable, dve);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} }
} }
@@ -145,8 +145,7 @@ public class RecurringDepositProductWritePlatformServiceJpaRepositoryImpl implem
handleDataIntegrityIssues(command, e.getMostSpecificCause(), e); handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} catch (final PersistenceException dve) { } catch (final PersistenceException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, ExceptionUtils.getRootCause(dve.getCause()), dve);
handleDataIntegrityIssues(command, throwable, dve);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} }
} }
@@ -170,25 +169,28 @@ public class RecurringDepositProductWritePlatformServiceJpaRepositoryImpl implem
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) {
String msgCode = "error.msg." + SavingsApiConstants.SAVINGS_PRODUCT_RESOURCE_NAME;
if (realCause.getMessage().contains("sp_unq_name")) { String msg = "Unknown data integrity issue with recurring deposit product.";
String param = null;
Object[] msgArgs;
Throwable checkEx = realCause == null ? dae : realCause;
if (checkEx.getMessage().contains("sp_unq_name")) {
final String name = command.stringValueOfParameterNamed("name"); final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException("error.msg.product.savings.duplicate.name", msgCode += ".duplicate.name";
"Recurring Deposit product with name `" + name + "` already exists", "name", name); msg = "Recurring Deposit product with name `" + name + "` already exists";
} else if (realCause.getMessage().contains("sp_unq_short_name")) { param = "name";
msgArgs = new Object[] { name, dae };
} else if (checkEx.getMessage().contains("sp_unq_short_name")) {
final String shortName = command.stringValueOfParameterNamed("shortName"); final String shortName = command.stringValueOfParameterNamed("shortName");
throw new PlatformDataIntegrityException("error.msg.product.savings.duplicate.short.name", msgCode += ".duplicate.short.name";
"Recurring Deposit product with short name `" + shortName + "` already exists", "shortName", shortName); msg = "Recurring Deposit product with short name `" + shortName + "` already exists";
param = "shortName";
msgArgs = new Object[] { shortName, dae };
} else {
msgCode += ".unknown.data.integrity.issue";
msgArgs = new Object[] { dae };
} }
logAsErrorUnexpectedDataIntegrityException(dae);
throw new PlatformDataIntegrityException("error.msg.savingsproduct.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
private void logAsErrorUnexpectedDataIntegrityException(final Exception dae) {
log.error("Error occured.", dae); log.error("Error occured.", dae);
throw ErrorHandler.getMappable(dae, msgCode, msg, param, msgArgs);
} }
} }
@@ -51,13 +51,13 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService; import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
@@ -45,8 +45,8 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.dataqueries.data.EntityTables; import org.apache.fineract.infrastructure.dataqueries.data.EntityTables;
import org.apache.fineract.infrastructure.dataqueries.data.StatusEnum; import org.apache.fineract.infrastructure.dataqueries.data.StatusEnum;
import org.apache.fineract.infrastructure.dataqueries.service.EntityDatatableChecksWritePlatformService; import org.apache.fineract.infrastructure.dataqueries.service.EntityDatatableChecksWritePlatformService;
@@ -115,32 +115,6 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
private final GroupRepositoryWrapper groupRepositoryWrapper; private final GroupRepositoryWrapper groupRepositoryWrapper;
private final GroupSavingsIndividualMonitoringWritePlatformService gsimWritePlatformService; private final GroupSavingsIndividualMonitoringWritePlatformService gsimWritePlatformService;
/*
* Guaranteed to throw an exception no matter what the data integrity issue is.
*/
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
final StringBuilder errorCodeBuilder = new StringBuilder("error.msg.").append(SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME);
if (realCause.getMessage().contains("sa_account_no_UNIQUE")) {
final String accountNo = command.stringValueOfParameterNamed("accountNo");
errorCodeBuilder.append(".duplicate.accountNo");
throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
"Savings account with accountNo " + accountNo + " already exists", "accountNo", accountNo);
} else if (realCause.getMessage().contains("sa_externalid_UNIQUE")) {
final String externalId = command.stringValueOfParameterNamed("externalId");
errorCodeBuilder.append(".duplicate.externalId");
throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
"Savings account with externalId " + externalId + " already exists", "externalId", externalId);
}
errorCodeBuilder.append(".unknown.data.integrity.issue");
log.error("Error occured.", dve);
throw new PlatformDataIntegrityException(errorCodeBuilder.toString(), "Unknown data integrity issue with savings account.");
}
@Transactional @Transactional
@Override @Override
public CommandProcessingResult submitGSIMApplication(final JsonCommand command) { public CommandProcessingResult submitGSIMApplication(final JsonCommand command) {
@@ -709,4 +683,33 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
.setRollbackTransaction(rollbackTransaction)// .setRollbackTransaction(rollbackTransaction)//
.build(); .build();
} }
/*
* Guaranteed to throw an exception no matter what the data integrity issue is.
*/
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
String msgCode = "error.msg." + SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
String msg = "Unknown data integrity issue with savings account.";
String param = null;
Object[] msgArgs;
Throwable checkEx = realCause == null ? dve : realCause;
if (checkEx.getMessage().contains("sa_account_no_UNIQUE")) {
final String accountNo = command.stringValueOfParameterNamed("accountNo");
msgCode += ".duplicate.accountNo";
msg = "Savings account with accountNo " + accountNo + " already exists";
param = "accountNo";
msgArgs = new Object[] { accountNo, dve };
} else if (checkEx.getMessage().contains("sa_externalid_UNIQUE")) {
final String externalId = command.stringValueOfParameterNamed("externalId");
msgCode += ".duplicate.externalId";
msg = "Savings account with externalId " + externalId + " already exists";
param = "externalId";
msgArgs = new Object[] { externalId, dve };
} else {
msgCode += ".unknown.data.integrity.issue";
msgArgs = new Object[] { dve };
}
log.error("Error occured.", dve);
throw ErrorHandler.getMappable(dve, msgCode, msg, param, msgArgs);
}
} }
@@ -37,13 +37,14 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.entityaccess.domain.FineractEntityAccessType; import org.apache.fineract.infrastructure.entityaccess.domain.FineractEntityAccessType;
import org.apache.fineract.infrastructure.entityaccess.service.FineractEntityAccessUtil; import org.apache.fineract.infrastructure.entityaccess.service.FineractEntityAccessUtil;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.charge.domain.Charge; import org.apache.fineract.portfolio.charge.domain.Charge;
import org.apache.fineract.portfolio.savings.DepositAccountType; import org.apache.fineract.portfolio.savings.DepositAccountType;
import org.apache.fineract.portfolio.savings.SavingsApiConstants;
import org.apache.fineract.portfolio.savings.data.SavingsProductDataValidator; import org.apache.fineract.portfolio.savings.data.SavingsProductDataValidator;
import org.apache.fineract.portfolio.savings.domain.SavingsProduct; import org.apache.fineract.portfolio.savings.domain.SavingsProduct;
import org.apache.fineract.portfolio.savings.domain.SavingsProductAssembler; import org.apache.fineract.portfolio.savings.domain.SavingsProductAssembler;
@@ -68,26 +69,29 @@ public class SavingsProductWritePlatformServiceJpaRepositoryImpl implements Savi
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) {
String msgCode = "error.msg." + SavingsApiConstants.SAVINGS_PRODUCT_RESOURCE_NAME;
if (realCause.getMessage().contains("sp_unq_name")) { String msg = "Unknown data integrity issue with savings product.";
String param = null;
Object[] msgArgs;
Throwable checkEx = realCause == null ? dae : realCause;
if (checkEx.getMessage().contains("sp_unq_name")) {
final String name = command.stringValueOfParameterNamed("name"); final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException("error.msg.product.savings.duplicate.name", msgCode += ".duplicate.name";
"Savings product with name `" + name + "` already exists", "name", name); msg = "Savings product with name `" + name + "` already exists";
} else if (realCause.getMessage().contains("sp_unq_short_name")) { param = "name";
msgArgs = new Object[] { name, dae };
} else if (checkEx.getMessage().contains("sp_unq_short_name")) {
final String shortName = command.stringValueOfParameterNamed("shortName"); final String shortName = command.stringValueOfParameterNamed("shortName");
throw new PlatformDataIntegrityException("error.msg.product.savings.duplicate.short.name", msgCode += ".duplicate.short.name";
"Savings product with short name `" + shortName + "` already exists", "shortName", shortName); msg = "Savings product with short name `" + shortName + "` already exists";
param = "shortName";
msgArgs = new Object[] { shortName, dae };
} else {
msgCode += ".unknown.data.integrity.issue";
msgArgs = new Object[] { dae };
} }
logAsErrorUnexpectedDataIntegrityException(dae);
throw new PlatformDataIntegrityException("error.msg.savingsproduct.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
private void logAsErrorUnexpectedDataIntegrityException(final Exception dae) {
log.error("Error occured.", dae); log.error("Error occured.", dae);
throw ErrorHandler.getMappable(dae, msgCode, msg, param, msgArgs);
} }
@Transactional @Transactional
@@ -118,8 +122,7 @@ public class SavingsProductWritePlatformServiceJpaRepositoryImpl implements Savi
handleDataIntegrityIssues(command, e.getMostSpecificCause(), e); handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} catch (final PersistenceException dve) { } catch (final PersistenceException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, ExceptionUtils.getRootCause(dve.getCause()), dve);
handleDataIntegrityIssues(command, throwable, dve);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} }
} }
@@ -177,8 +180,7 @@ public class SavingsProductWritePlatformServiceJpaRepositoryImpl implements Savi
handleDataIntegrityIssues(command, e.getMostSpecificCause(), e); handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} catch (final PersistenceException dve) { } catch (final PersistenceException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, ExceptionUtils.getRootCause(dve.getCause()), dve);
handleDataIntegrityIssues(command, throwable, dve);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} }
} }
@@ -20,12 +20,12 @@ package org.apache.fineract.portfolio.savings.starter;
import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService; import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
import org.apache.fineract.accounting.producttoaccountmapping.service.ProductToGLAccountMappingWritePlatformService; import org.apache.fineract.accounting.producttoaccountmapping.service.ProductToGLAccountMappingWritePlatformService;
import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.commands.service.CommandProcessingService; import org.apache.fineract.commands.service.CommandProcessingService;
import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatRepositoryWrapper; import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatRepositoryWrapper;
import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.core.data.PaginationParametersDataValidator; import org.apache.fineract.infrastructure.core.data.PaginationParametersDataValidator;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.service.PaginationHelper; import org.apache.fineract.infrastructure.core.service.PaginationHelper;
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
@@ -31,6 +31,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.account.PortfolioAccountType; import org.apache.fineract.portfolio.account.PortfolioAccountType;
@@ -155,7 +156,6 @@ public class SelfBeneficiariesTPTWritePlatformServiceImpl implements SelfBenefic
} }
private void handleDataIntegrityIssues(final JsonCommand command, final DataAccessException dae) { private void handleDataIntegrityIssues(final JsonCommand command, final DataAccessException dae) {
final Throwable realCause = dae.getMostSpecificCause(); final Throwable realCause = dae.getMostSpecificCause();
if (realCause.getMessage().contains("name")) { if (realCause.getMessage().contains("name")) {
@@ -165,7 +165,7 @@ public class SelfBeneficiariesTPTWritePlatformServiceImpl implements SelfBenefic
} }
log.error("Error occured.", dae); log.error("Error occured.", dae);
throw new PlatformDataIntegrityException("error.msg.beneficiary.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dae, "error.msg.beneficiary.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
} }
@@ -40,6 +40,7 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.domain.EmailDetail; import org.apache.fineract.infrastructure.core.domain.EmailDetail;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
@@ -284,7 +285,7 @@ public class SelfServiceRegistrationWritePlatformServiceImpl implements SelfServ
throw new PlatformDataIntegrityException("error.msg.user.duplicate.username", defaultMessageBuilder.toString(), "username", throw new PlatformDataIntegrityException("error.msg.user.duplicate.username", defaultMessageBuilder.toString(), "username",
username); username);
} }
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); throw ErrorHandler.getMappable(dve, "error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
} }
} }
@@ -37,7 +37,7 @@ import org.apache.fineract.infrastructure.accountnumberformat.domain.EntityAccou
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.event.business.domain.share.ShareAccountApproveBusinessEvent; import org.apache.fineract.infrastructure.event.business.domain.share.ShareAccountApproveBusinessEvent;
import org.apache.fineract.infrastructure.event.business.domain.share.ShareAccountCreateBusinessEvent; import org.apache.fineract.infrastructure.event.business.domain.share.ShareAccountCreateBusinessEvent;
@@ -500,7 +500,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
} }
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
throw new PlatformDataIntegrityException("error.msg.shareaccount.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.shareaccount.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
} }
@@ -30,6 +30,7 @@ import org.apache.fineract.accounting.producttoaccountmapping.service.ProductToG
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.event.business.domain.share.ShareProductDividentsCreateBusinessEvent; import org.apache.fineract.infrastructure.event.business.domain.share.ShareProductDividentsCreateBusinessEvent;
@@ -181,20 +182,16 @@ public class ShareProductWritePlatformServiceJpaRepositoryImpl implements ShareP
private void handleDataIntegrityIssues(final Exception e) { private void handleDataIntegrityIssues(final Exception e) {
log.error("Unknown data integrity issue with resource", e); log.error("Unknown data integrity issue with resource", e);
throw new PlatformDataIntegrityException("error.msg.shareproduct.unknown.data.integrity.issue", throw ErrorHandler.getMappable(e, "error.msg.shareproduct.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("'name'")) { if (realCause.getMessage().contains("'name'")) {
final String name = command.stringValueOfParameterNamed(ShareProductApiConstants.name_paramname); final String name = command.stringValueOfParameterNamed(ShareProductApiConstants.name_paramname);
throw new PlatformDataIntegrityException("error.msg.shareproduct.duplicate.name", throw new PlatformDataIntegrityException("error.msg.shareproduct.duplicate.name",
"Share Product with name `" + name + "` already exists", "name", name); "Share Product with name `" + name + "` already exists", "name", name);
} }
handleDataIntegrityIssues(dve);
log.error("Unknown data integrity issue with resource", dve);
throw new PlatformDataIntegrityException("error.msg.shareproduct.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
} }
} }
@@ -23,6 +23,7 @@ import jakarta.persistence.PersistenceException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -125,17 +126,14 @@ public class SpmService {
} }
private void handleDataIntegrityIssues(final Throwable realCause, final Exception dve, String key) { private void handleDataIntegrityIssues(final Throwable realCause, final Exception dve, String key) {
if (realCause.getMessage().contains("m_survey_scorecards")) { if (realCause.getMessage().contains("m_survey_scorecards")) {
throw new PlatformDataIntegrityException("error.msg.survey.cannot.be.modified.as.used.in.client.survey", throw new PlatformDataIntegrityException("error.msg.survey.cannot.be.modified.as.used.in.client.survey",
"Survey can not be edited as it is already used in client survey", "name", key); "Survey can not be edited as it is already used in client survey", "name", key);
} }
if (realCause.getMessage().contains("key")) { if (realCause.getMessage().contains("key")) {
throw new PlatformDataIntegrityException("error.msg.survey.duplicate.key", "Survey with key already exists", "name", key); throw new PlatformDataIntegrityException("error.msg.survey.duplicate.key", "Survey with key already exists", "name", key);
} }
throw ErrorHandler.getMappable(dve, "error.msg.survey.unknown.data.integrity.issue",
throw new PlatformDataIntegrityException("error.msg.survey.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage()); "Unknown data integrity issue with resource: " + realCause.getMessage());
} }
} }
@@ -34,6 +34,7 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.PlatformEmailSendException; import org.apache.fineract.infrastructure.core.service.PlatformEmailSendException;
@@ -283,28 +284,22 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
/* /*
* Return an exception to throw, no matter what the data integrity issue is. * Return an exception to throw, no matter what the data integrity issue is.
*/ */
private PlatformDataIntegrityException handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, private RuntimeException handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
final Exception dve) {
// TODO: this needs to be fixed. The error condition should be independent from the underlying message and // TODO: this needs to be fixed. The error condition should be independent from the underlying message and
// naming // naming of the constraint
// of the constraint
if (realCause.getMessage().contains("username_org")) { if (realCause.getMessage().contains("username_org")) {
final String username = command.stringValueOfParameterNamed("username"); final String username = command.stringValueOfParameterNamed("username");
final StringBuilder defaultMessageBuilder = new StringBuilder("User with username ").append(username) final String defaultMessage = "User with username " + username + " already exists.";
.append(" already exists."); return new PlatformDataIntegrityException("error.msg.user.duplicate.username", defaultMessage, "username", username);
return new PlatformDataIntegrityException("error.msg.user.duplicate.username", defaultMessageBuilder.toString(), "username",
username);
} }
// TODO: this needs to be fixed. The error condition should be independent from the underlying message and // TODO: this needs to be fixed. The error condition should be independent from the underlying message and
// naming // naming of the constraint
// of the constraint
if (realCause.getMessage().contains("unique_self_client")) { if (realCause.getMessage().contains("unique_self_client")) {
return new PlatformDataIntegrityException("error.msg.user.self.service.user.already.exist", return new PlatformDataIntegrityException("error.msg.user.self.service.user.already.exist",
"Self Service User Id is already created. Go to Admin->Users to edit or delete the self-service user."); "Self Service User Id is already created. Go to Admin->Users to edit or delete the self-service user.");
} }
log.error("handleDataIntegrityIssues: Neither duplicate username nor existing user; unknown error occured", dve); log.error("handleDataIntegrityIssues: Neither duplicate username nor existing user; unknown error occured", dve);
return new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); return ErrorHandler.getMappable(dve, "error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
} }
} }
@@ -26,7 +26,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.useradministration.api.PasswordPreferencesApiConstants; import org.apache.fineract.useradministration.api.PasswordPreferencesApiConstants;
import org.apache.fineract.useradministration.data.PasswordPreferencesDataValidator; import org.apache.fineract.useradministration.data.PasswordPreferencesDataValidator;
import org.apache.fineract.useradministration.domain.PasswordValidationPolicy; import org.apache.fineract.useradministration.domain.PasswordValidationPolicy;
@@ -82,8 +82,8 @@ public class PasswordPreferencesWritePlatformServiceJpaRepositoryImpl implements
.build(); .build();
} catch (final JpaSystemException | DataIntegrityViolationException dve) { } catch (final JpaSystemException | DataIntegrityViolationException dve) {
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.password.validation.policy.unknown.data.integrity.issue", throw ErrorHandler.getMappable(dve, "error.msg.password.validation.policy.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", dve); "Unknown data integrity issue with resource.");
} }
} }
} }
@@ -28,6 +28,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.useradministration.command.PermissionsCommand; import org.apache.fineract.useradministration.command.PermissionsCommand;
@@ -86,21 +87,14 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
* Guaranteed to throw an exception no matter what the data integrity issue is. * Guaranteed to throw an exception no matter what the data integrity issue is.
*/ */
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
if (realCause.getMessage().contains("unq_name")) { if (realCause.getMessage().contains("unq_name")) {
final String name = command.stringValueOfParameterNamed("name"); final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException("error.msg.role.duplicate.name", "Role with name `" + name + "` already exists", throw new PlatformDataIntegrityException("error.msg.role.duplicate.name", "Role with name `" + name + "` already exists",
"name", name); "name", name);
} }
logAsErrorUnexpectedDataIntegrityException(dve);
throw new PlatformDataIntegrityException("error.msg.role.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
private void logAsErrorUnexpectedDataIntegrityException(final Exception dve) {
log.error("Error occured.", dve); log.error("Error occured.", dve);
throw ErrorHandler.getMappable(dve, "error.msg.role.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
} }
@Caching(evict = { @CacheEvict(value = "users", allEntries = true), @CacheEvict(value = "usersByUsername", allEntries = true) }) @Caching(evict = { @CacheEvict(value = "users", allEntries = true), @CacheEvict(value = "usersByUsername", allEntries = true) })
@@ -212,8 +206,8 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
this.roleRepository.delete(role); this.roleRepository.delete(role);
return new CommandProcessingResultBuilder().withEntityId(roleId).build(); return new CommandProcessingResultBuilder().withEntityId(roleId).build();
} catch (final JpaSystemException | DataIntegrityViolationException e) { } catch (final JpaSystemException | DataIntegrityViolationException e) {
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", throw ErrorHandler.getMappable(e, "error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); "Unknown data integrity issue with resource: " + e.getMostSpecificCause());
} }
} }
@@ -246,8 +240,8 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
return new CommandProcessingResultBuilder().withEntityId(roleId).build(); return new CommandProcessingResultBuilder().withEntityId(roleId).build();
} catch (final JpaSystemException | DataIntegrityViolationException e) { } catch (final JpaSystemException | DataIntegrityViolationException e) {
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", throw ErrorHandler.getMappable(e, "error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); "Unknown data integrity issue with resource: " + e.getMostSpecificCause());
} }
} }
@@ -269,8 +263,8 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
return new CommandProcessingResultBuilder().withEntityId(roleId).build(); return new CommandProcessingResultBuilder().withEntityId(roleId).build();
} catch (final JpaSystemException | DataIntegrityViolationException e) { } catch (final JpaSystemException | DataIntegrityViolationException e) {
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", throw ErrorHandler.getMappable(e, "error.msg.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); "Unknown data integrity issue with resource: " + e.getMostSpecificCause());
} }
} }
} }
@@ -23,7 +23,6 @@ import static org.mockito.ArgumentMatchers.any;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.Optional; import java.util.Optional;
import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.commands.domain.CommandSource; import org.apache.fineract.commands.domain.CommandSource;
import org.apache.fineract.commands.domain.CommandSourceRepository; import org.apache.fineract.commands.domain.CommandSourceRepository;
@@ -31,6 +30,7 @@ import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.infrastructure.codes.exception.CodeNotFoundException; import org.apache.fineract.infrastructure.codes.exception.CodeNotFoundException;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUser;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@@ -40,6 +40,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -108,7 +109,9 @@ public class CommandSourceServiceTest {
@Test @Test
public void testGenerateErrorException() { public void testGenerateErrorException() {
Mockito.when(errorHandler.getMappable(any())).thenAnswer(i -> i.getArguments()[0]); try (MockedStatic<ErrorHandler> mockedStatic = Mockito.mockStatic(ErrorHandler.class)) {
mockedStatic.when(() -> ErrorHandler.getMappable(any(CodeNotFoundException.class))).thenAnswer(i -> i.getArguments()[0]);
}
Mockito.when(errorHandler.handle(any(CodeNotFoundException.class))) Mockito.when(errorHandler.handle(any(CodeNotFoundException.class)))
.thenReturn(new ErrorInfo(404, 1001, "Code with name `foo` does not exist", null)); .thenReturn(new ErrorInfo(404, 1001, "Code with name `foo` does not exist", null));
ErrorInfo result = underTest.generateErrorInfo(new CodeNotFoundException("foo")); ErrorInfo result = underTest.generateErrorInfo(new CodeNotFoundException("foo"));