FINERACT-2096: Fix duplicate key value exception
This commit is contained in:
committed by
Adam Saghy
parent
3b603f5e80
commit
edc7fff86f
+12
-2
@@ -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)
|
||||
|
||||
+5
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user