This is an automated email from the ASF dual-hosted git repository.
adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new edc7fff86 FINERACT-2096: Fix duplicate key value exception
edc7fff86 is described below
commit edc7fff86fc4935be0e9064210d5f45d2f7a7ae7
Author: Jose Alberto Hernandez <[email protected]>
AuthorDate: Thu Jun 13 08:27:07 2024 -0600
FINERACT-2096: Fix duplicate key value exception
---
.../fineract/commands/service/CommandSourceService.java | 14 ++++++++++++--
.../IdempotentCommandProcessUnderProcessingException.java | 5 +++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git
a/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandSourceService.java
b/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandSourceService.java
index cb5dfaca0..46432d613 100644
---
a/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandSourceService.java
+++
b/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandSourceService.java
@@ -31,8 +31,10 @@ import
org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
+import
org.apache.fineract.infrastructure.core.exception.IdempotentCommandProcessUnderProcessingException;
import org.apache.fineract.useradministration.domain.AppUser;
import org.jetbrains.annotations.NotNull;
+import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
@@ -64,8 +66,16 @@ public class CommandSourceService {
@NotNull
private CommandSource saveInitial(CommandWrapper wrapper, JsonCommand
jsonCommand, AppUser maker, String idempotencyKey) {
- CommandSource initialCommandSource = getInitialCommandSource(wrapper,
jsonCommand, maker, idempotencyKey);
- return commandSourceRepository.saveAndFlush(initialCommandSource);
+ try {
+ CommandSource initialCommandSource =
getInitialCommandSource(wrapper, jsonCommand, maker, idempotencyKey);
+ return commandSourceRepository.saveAndFlush(initialCommandSource);
+ } catch (JpaSystemException jse) {
+ final String message = (jse.getRootCause() != null) ?
jse.getRootCause().getMessage() : null;
+ if (message != null &&
message.toUpperCase().contains("UNIQUE_PORTFOLIO_COMMAND_SOURCE")) {
+ throw new
IdempotentCommandProcessUnderProcessingException(wrapper, idempotencyKey, jse);
+ }
+ throw jse;
+ }
}
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation =
Isolation.REPEATABLE_READ)
diff --git
a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exception/IdempotentCommandProcessUnderProcessingException.java
b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exception/IdempotentCommandProcessUnderProcessingException.java
index 7e608e4be..ba01dedac 100644
---
a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exception/IdempotentCommandProcessUnderProcessingException.java
+++
b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exception/IdempotentCommandProcessUnderProcessingException.java
@@ -28,4 +28,9 @@ public class IdempotentCommandProcessUnderProcessingException
extends AbstractId
public IdempotentCommandProcessUnderProcessingException(CommandWrapper
wrapper, String idempotencyKey) {
super(wrapper.actionName(), wrapper.entityName(), idempotencyKey,
wrapper.getJson());
}
+
+ public IdempotentCommandProcessUnderProcessingException(CommandWrapper
wrapper, String idempotencyKey, Exception e) {
+ super(wrapper.actionName(), wrapper.entityName(), idempotencyKey,
wrapper.getJson());
+ }
+
}