FINERACT-1161: Fixing update and delete note operations
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
f3d25d1320
commit
d9ff0f1317
+1
-1
@@ -173,7 +173,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
if (client.isNotPending()) {
|
||||
throw new ClientMustBePendingToBeDeletedException(clientId);
|
||||
}
|
||||
final List<Note> relatedNotes = this.noteRepository.findByClientId(clientId);
|
||||
final List<Note> relatedNotes = this.noteRepository.findByClient(client);
|
||||
this.noteRepository.deleteInBatch(relatedNotes);
|
||||
|
||||
final ClientNonPerson clientNonPerson = this.clientNonPersonRepository.findOneByClientId(clientId);
|
||||
|
||||
+1
-1
@@ -591,7 +591,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
throw new GroupMustBePendingToBeDeletedException(groupId);
|
||||
}
|
||||
|
||||
final List<Note> relatedNotes = this.noteRepository.findByGroupId(groupId);
|
||||
final List<Note> relatedNotes = this.noteRepository.findByGroup(groupForDelete);
|
||||
this.noteRepository.deleteInBatch(relatedNotes);
|
||||
|
||||
this.groupRepository.delete(groupForDelete);
|
||||
|
||||
+12
-7
@@ -19,6 +19,11 @@
|
||||
package org.apache.fineract.portfolio.note.domain;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.fineract.portfolio.client.domain.Client;
|
||||
import org.apache.fineract.portfolio.group.domain.Group;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
|
||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
@@ -26,19 +31,19 @@ public interface NoteRepository extends JpaRepository<Note, Long>, JpaSpecificat
|
||||
|
||||
List<Note> findByLoanId(Long id);
|
||||
|
||||
List<Note> findByClientId(Long id);
|
||||
List<Note> findByClient(Client id);
|
||||
|
||||
List<Note> findByGroupId(Long groupId);
|
||||
List<Note> findByGroup(Group group);
|
||||
|
||||
Note findByLoanIdAndId(Long loanId, Long id);
|
||||
Note findByLoanAndId(Loan loanId, Long id);
|
||||
|
||||
Note findByClientIdAndId(Long clientId, Long id);
|
||||
Note findByClientAndId(Client client, Long id);
|
||||
|
||||
Note findByGroupIdAndId(Long groupId, Long id);
|
||||
Note findByGroupAndId(Group group, Long id);
|
||||
|
||||
Note findByLoanTransactionIdAndId(Long loanTransactionId, Long id);
|
||||
Note findByLoanTransactionAndId(LoanTransaction loanTransaction, Long id);
|
||||
|
||||
List<Note> findBySavingsAccountId(Long savingAccountId);
|
||||
List<Note> findBySavingsAccount(SavingsAccount savingAccount);
|
||||
|
||||
// Note findBySavingsAccountIdAndId(Long savingAccountId, Long id);
|
||||
}
|
||||
|
||||
+3
-2
@@ -27,8 +27,9 @@ public enum NoteType {
|
||||
LOAN(200, "noteType.loan", "loans"), //
|
||||
LOAN_TRANSACTION(300, "noteType.loan.transaction", "loanTransactions"), //
|
||||
SAVING_ACCOUNT(500, "noteType.saving", "savings"), //
|
||||
GROUP(600, "noteType.group", "groups"), SHARE_ACCOUNT(700, "noteType.shares", "accounts/share"), SAVINGS_TRANSACTION(800,
|
||||
"noteType.savings.transaction", "savingsTransactions");
|
||||
GROUP(600, "noteType.group", "groups"), //
|
||||
SHARE_ACCOUNT(700, "noteType.shares", "accounts/share"), //
|
||||
SAVINGS_TRANSACTION(800, "noteType.savings.transaction", "savingsTransactions");
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
|
||||
+16
-9
@@ -238,7 +238,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
|
||||
|
||||
final Client client = this.clientRepository.findOneWithNotFoundDetection(resourceId);
|
||||
|
||||
final Note noteForUpdate = this.noteRepository.findByClientIdAndId(resourceId, noteId);
|
||||
final Note noteForUpdate = this.noteRepository.findByClientAndId(client, noteId);
|
||||
if (noteForUpdate == null) {
|
||||
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase());
|
||||
}
|
||||
@@ -267,7 +267,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
|
||||
|
||||
final Group group = this.groupRepository.findById(resourceId).orElseThrow(() -> new GroupNotFoundException(resourceId));
|
||||
|
||||
final Note noteForUpdate = this.noteRepository.findByGroupIdAndId(resourceId, noteId);
|
||||
final Note noteForUpdate = this.noteRepository.findByGroupAndId(group, noteId);
|
||||
|
||||
if (noteForUpdate == null) {
|
||||
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase());
|
||||
@@ -295,7 +295,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
|
||||
final NoteType type = NoteType.LOAN;
|
||||
|
||||
final Loan loan = this.loanRepository.findOneWithNotFoundDetection(resourceId);
|
||||
final Note noteForUpdate = this.noteRepository.findByLoanIdAndId(resourceId, noteId);
|
||||
final Note noteForUpdate = this.noteRepository.findByLoanAndId(loan, noteId);
|
||||
if (noteForUpdate == null) {
|
||||
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase());
|
||||
}
|
||||
@@ -321,7 +321,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
|
||||
.orElseThrow(() -> new LoanTransactionNotFoundException(resourceId));
|
||||
final Loan loan = loanTransaction.getLoan();
|
||||
|
||||
final Note noteForUpdate = this.noteRepository.findByLoanTransactionIdAndId(resourceId, noteId);
|
||||
final Note noteForUpdate = this.noteRepository.findByLoanTransactionAndId(loanTransaction, noteId);
|
||||
|
||||
if (noteForUpdate == null) {
|
||||
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase());
|
||||
@@ -423,22 +423,29 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
|
||||
switch (type) {
|
||||
case CLIENT: {
|
||||
resourceId = command.getClientId();
|
||||
noteForUpdate = this.noteRepository.findByClientIdAndId(resourceId, noteId);
|
||||
final Client client = this.clientRepository.findOneWithNotFoundDetection(resourceId);
|
||||
noteForUpdate = this.noteRepository.findByClientAndId(client, noteId);
|
||||
}
|
||||
break;
|
||||
case GROUP: {
|
||||
resourceId = command.getGroupId();
|
||||
noteForUpdate = this.noteRepository.findByGroupIdAndId(resourceId, noteId);
|
||||
final Long groupId = command.getGroupId();
|
||||
resourceId = groupId;
|
||||
Group group = this.groupRepository.findById(groupId).orElseThrow(() -> new GroupNotFoundException(groupId));
|
||||
noteForUpdate = this.noteRepository.findByGroupAndId(group, noteId);
|
||||
}
|
||||
break;
|
||||
case LOAN: {
|
||||
resourceId = command.getLoanId();
|
||||
noteForUpdate = this.noteRepository.findByLoanIdAndId(resourceId, noteId);
|
||||
final Loan loan = this.loanRepository.findOneWithNotFoundDetection(resourceId);
|
||||
noteForUpdate = this.noteRepository.findByLoanAndId(loan, noteId);
|
||||
}
|
||||
break;
|
||||
case LOAN_TRANSACTION: {
|
||||
resourceId = command.subentityId();
|
||||
noteForUpdate = this.noteRepository.findByLoanTransactionIdAndId(resourceId, noteId);
|
||||
final Long loanTransactionId = resourceId;
|
||||
final LoanTransaction loanTransaction = this.loanTransactionRepository.findById(loanTransactionId)
|
||||
.orElseThrow(() -> new LoanTransactionNotFoundException(loanTransactionId));
|
||||
noteForUpdate = this.noteRepository.findByLoanTransactionAndId(loanTransaction, noteId);
|
||||
}
|
||||
break;
|
||||
// case SAVING_ACCOUNT: {
|
||||
|
||||
+1
-1
@@ -621,7 +621,7 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
|
||||
}
|
||||
}
|
||||
|
||||
final List<Note> relatedNotes = this.noteRepository.findBySavingsAccountId(savingsId);
|
||||
final List<Note> relatedNotes = this.noteRepository.findBySavingsAccount(account);
|
||||
this.noteRepository.deleteInBatch(relatedNotes);
|
||||
|
||||
this.savingAccountRepository.delete(account);
|
||||
|
||||
+1
-1
@@ -465,7 +465,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
|
||||
}
|
||||
}
|
||||
|
||||
final List<Note> relatedNotes = this.noteRepository.findBySavingsAccountId(savingsId);
|
||||
final List<Note> relatedNotes = this.noteRepository.findBySavingsAccount(account);
|
||||
this.noteRepository.deleteInBatch(relatedNotes);
|
||||
|
||||
this.savingAccountRepository.delete(account);
|
||||
|
||||
Reference in New Issue
Block a user