FINERACT-1161: Fixing update and delete note operations

This commit is contained in:
Petri Tuomola
2020-09-28 19:24:33 +02:00
committed by Michael Vorburger ⛑️
parent f3d25d1320
commit d9ff0f1317
9 changed files with 496 additions and 22 deletions
@@ -0,0 +1,324 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.HashMap;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.GroupHelper;
import org.apache.fineract.integrationtests.common.NotesHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@SuppressWarnings({ "rawtypes" })
public class NotesTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
private ResponseSpecification responseSpec404;
private LoanTransactionHelper loanTransactionHelper;
@BeforeEach
public void setup() {
Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.responseSpec404 = new ResponseSpecBuilder().expectStatusCode(404).build();
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
}
@Test
public void testCreateClientNote() {
String noteText = "this is a test note";
Integer clientId = ClientHelper.createClient(requestSpec, responseSpec);
Assertions.assertNotNull(clientId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createClientNote(requestSpec, responseSpec, clientId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getClientNote(requestSpec, responseSpec, clientId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
}
@Test
public void testUpdateClientNote() {
String noteText = "this is a test note";
Integer clientId = ClientHelper.createClient(requestSpec, responseSpec);
Assertions.assertNotNull(clientId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createClientNote(requestSpec, responseSpec, clientId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getClientNote(requestSpec, responseSpec, clientId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
String updatedNoteText = "this is an updated test note";
String updateRequest = "{\"note\": \"" + updatedNoteText + "\"}";
NotesHelper.updateClientNote(requestSpec, responseSpec, clientId, noteId, updateRequest);
receivedNoteText = NotesHelper.getClientNote(requestSpec, responseSpec, clientId, noteId);
Assertions.assertEquals(updatedNoteText, receivedNoteText);
}
@Test
public void testDeleteClientNote() {
String noteText = "this is a test note";
Integer clientId = ClientHelper.createClient(requestSpec, responseSpec);
Assertions.assertNotNull(clientId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createClientNote(requestSpec, responseSpec, clientId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getClientNote(requestSpec, responseSpec, clientId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
NotesHelper.deleteClientNote(requestSpec, responseSpec, clientId, noteId);
NotesHelper.getClientNote(requestSpec, responseSpec404, clientId, noteId);
}
@Test
public void testCreateGroupNote() {
String noteText = "this is a test group note";
Integer groupId = GroupHelper.createGroup(requestSpec, responseSpec);
Assertions.assertNotNull(groupId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createGroupNote(requestSpec, responseSpec, groupId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getGroupNote(requestSpec, responseSpec, groupId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
}
@Test
public void testUpdateGroupNote() {
String noteText = "this is a test group note";
Integer groupId = GroupHelper.createGroup(requestSpec, responseSpec);
Assertions.assertNotNull(groupId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createGroupNote(requestSpec, responseSpec, groupId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getGroupNote(requestSpec, responseSpec, groupId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
String updatedNoteText = "this is an updated test group note";
String updateRequest = "{\"note\": \"" + updatedNoteText + "\"}";
NotesHelper.updateGroupNote(requestSpec, responseSpec, groupId, noteId, updateRequest);
receivedNoteText = NotesHelper.getGroupNote(requestSpec, responseSpec, groupId, noteId);
Assertions.assertEquals(updatedNoteText, receivedNoteText);
}
@Test
public void testDeleteGroupNote() {
String noteText = "this is a test group note";
Integer groupId = GroupHelper.createGroup(requestSpec, responseSpec);
Assertions.assertNotNull(groupId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createGroupNote(requestSpec, responseSpec, groupId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getGroupNote(requestSpec, responseSpec, groupId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
NotesHelper.deleteGroupNote(requestSpec, responseSpec, groupId, noteId);
NotesHelper.getGroupNote(requestSpec, responseSpec404, groupId, noteId);
}
@Test
public void testCreateLoanNote() {
String noteText = "this is a test loan note";
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
final Integer loanId = applyForLoanApplication(clientID, loanProductID);
Assertions.assertNotNull(loanId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createLoanNote(requestSpec, responseSpec, loanId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getLoanNote(requestSpec, responseSpec, loanId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
}
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) {
final String loanApplication = new LoanApplicationTestBuilder().withPrincipal("5000").withLoanTermFrequency("5")
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("5").withRepaymentEveryAfter("1")
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("2").withExpectedDisbursementDate("04 April 2012")
.withSubmittedOnDate("02 April 2012").build(clientID.toString(), loanProductID.toString(), null);
return this.loanTransactionHelper.getLoanId(loanApplication);
}
@Test
public void testUpdateLoanNote() {
String noteText = "this is a test loan note";
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
final Integer loanId = applyForLoanApplication(clientID, loanProductID);
Assertions.assertNotNull(loanId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createLoanNote(requestSpec, responseSpec, loanId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getLoanNote(requestSpec, responseSpec, loanId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
String updatedNoteText = "this is an updated test loan note";
String updateRequest = "{\"note\": \"" + updatedNoteText + "\"}";
NotesHelper.updateLoanNote(requestSpec, responseSpec, loanId, noteId, updateRequest);
receivedNoteText = NotesHelper.getLoanNote(requestSpec, responseSpec, loanId, noteId);
Assertions.assertEquals(updatedNoteText, receivedNoteText);
}
@Test
public void testDeleteLoanNote() {
String noteText = "this is a test loan note";
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
final Integer loanId = applyForLoanApplication(clientID, loanProductID);
Assertions.assertNotNull(loanId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createLoanNote(requestSpec, responseSpec, loanId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getLoanNote(requestSpec, responseSpec, loanId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
NotesHelper.deleteLoanNote(requestSpec, responseSpec, loanId, noteId);
NotesHelper.getLoanNote(requestSpec, responseSpec404, loanId, noteId);
}
@Test
public void testCreateLoanTransactionNote() {
String noteText = "this is a test loan transaction note";
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
final Integer loanId = applyForLoanApplication(clientID, loanProductID);
Assertions.assertNotNull(loanId);
this.loanTransactionHelper.approveLoan("02 April 2012", loanId);
this.loanTransactionHelper.disburseLoan("02 April 2012", loanId);
HashMap repayment = this.loanTransactionHelper.makeRepayment("02 April 2012", 100.0f, loanId);
Integer loanTransactionId = (Integer) repayment.get("resourceId");
Assertions.assertNotNull(loanTransactionId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
}
@Test
public void testUpdateLoanTransactionNote() {
String noteText = "this is a test loan transaction note";
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
final Integer loanId = applyForLoanApplication(clientID, loanProductID);
Assertions.assertNotNull(loanId);
this.loanTransactionHelper.approveLoan("02 April 2012", loanId);
this.loanTransactionHelper.disburseLoan("02 April 2012", loanId);
HashMap repayment = this.loanTransactionHelper.makeRepayment("02 April 2012", 100.0f, loanId);
Integer loanTransactionId = (Integer) repayment.get("resourceId");
Assertions.assertNotNull(loanTransactionId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
String updatedNoteText = "this is an updated test loan transaction note";
String updateRequest = "{\"note\": \"" + updatedNoteText + "\"}";
NotesHelper.updateLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId, updateRequest);
receivedNoteText = NotesHelper.getLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
Assertions.assertEquals(updatedNoteText, receivedNoteText);
}
@Test
public void testDeleteLoanTransactionNote() {
String noteText = "this is a test loan transaction note";
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
final Integer loanId = applyForLoanApplication(clientID, loanProductID);
Assertions.assertNotNull(loanId);
this.loanTransactionHelper.approveLoan("02 April 2012", loanId);
this.loanTransactionHelper.disburseLoan("02 April 2012", loanId);
HashMap repayment = this.loanTransactionHelper.makeRepayment("02 April 2012", 100.0f, loanId);
Integer loanTransactionId = (Integer) repayment.get("resourceId");
Assertions.assertNotNull(loanTransactionId);
String request = "{\"note\": \"" + noteText + "\"}";
Integer noteId = NotesHelper.createLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, request);
Assertions.assertNotNull(noteId);
String receivedNoteText = NotesHelper.getLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
Assertions.assertEquals(noteText, receivedNoteText);
NotesHelper.deleteLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
NotesHelper.getLoanTransactionNote(requestSpec, responseSpec404, loanTransactionId, noteId);
}
}
@@ -0,0 +1,137 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.common;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
@SuppressWarnings({ "rawtypes", "unchecked" })
public final class NotesHelper {
private NotesHelper() {
}
private static final String CLIENT_URL = "/fineract-provider/api/v1/clients";
public static Integer createClientNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer clientId,
String request) {
String createClientNoteURL = CLIENT_URL + "/" + clientId + "/notes?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, createClientNoteURL, request, "resourceId");
}
public static String getClientNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer clientId,
Integer noteId) {
String getClientNoteURL = CLIENT_URL + "/" + clientId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, getClientNoteURL, "note");
}
public static Integer updateClientNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer clientId,
Integer noteId, String request) {
String updateClientNoteURL = CLIENT_URL + "/" + clientId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPut(requestSpec, responseSpec, updateClientNoteURL, request, "resourceId");
}
public static void deleteClientNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer clientId,
Integer noteId) {
String deleteClientNoteURL = CLIENT_URL + "/" + clientId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
Utils.performServerDelete(requestSpec, responseSpec, deleteClientNoteURL, "");
}
private static final String GROUP_URL = "/fineract-provider/api/v1/groups";
public static Integer createGroupNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer groupId,
String request) {
String createGroupNoteURL = GROUP_URL + "/" + groupId + "/notes?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, createGroupNoteURL, request, "resourceId");
}
public static String getGroupNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer groupId,
Integer noteId) {
String getGroupNoteURL = GROUP_URL + "/" + groupId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, getGroupNoteURL, "note");
}
public static Integer updateGroupNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer groupId,
Integer noteId, String request) {
String updateGroupNoteURL = GROUP_URL + "/" + groupId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPut(requestSpec, responseSpec, updateGroupNoteURL, request, "resourceId");
}
public static void deleteGroupNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer groupId,
Integer noteId) {
String deleteGroupNoteURL = GROUP_URL + "/" + groupId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
Utils.performServerDelete(requestSpec, responseSpec, deleteGroupNoteURL, "");
}
private static final String LOAN_URL = "/fineract-provider/api/v1/loans";
public static Integer createLoanNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanId,
String request) {
String createLoanNoteURL = LOAN_URL + "/" + loanId + "/notes?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, createLoanNoteURL, request, "resourceId");
}
public static String getLoanNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanId, Integer noteId) {
String getLoanNoteURL = LOAN_URL + "/" + loanId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, getLoanNoteURL, "note");
}
public static Integer updateLoanNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanId,
Integer noteId, String updateRequest) {
String updateLoanNoteURL = LOAN_URL + "/" + loanId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPut(requestSpec, responseSpec, updateLoanNoteURL, updateRequest, "resourceId");
}
public static void deleteLoanNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanId,
Integer noteId) {
String deleteLoanNoteURL = LOAN_URL + "/" + loanId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
Utils.performServerDelete(requestSpec, responseSpec, deleteLoanNoteURL, "");
}
private static final String LOAN_TRANSACTION_URL = "/fineract-provider/api/v1/loanTransactions";
public static Integer createLoanTransactionNote(RequestSpecification requestSpec, ResponseSpecification responseSpec,
Integer loanTransactionId, String request) {
String createLoanTransactionNoteURL = LOAN_TRANSACTION_URL + "/" + loanTransactionId + "/notes?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, createLoanTransactionNoteURL, request, "resourceId");
}
public static String getLoanTransactionNote(RequestSpecification requestSpec, ResponseSpecification responseSpec,
Integer loanTransactionId, Integer noteId) {
String getLoanTransactionNoteURL = LOAN_TRANSACTION_URL + "/" + loanTransactionId + "/notes/" + noteId + "?"
+ Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, getLoanTransactionNoteURL, "note");
}
public static Integer updateLoanTransactionNote(RequestSpecification requestSpec, ResponseSpecification responseSpec,
Integer loanTransactionId, Integer noteId, String updateRequest) {
String updateLoanTransactionNoteURL = LOAN_TRANSACTION_URL + "/" + loanTransactionId + "/notes/" + noteId + "?"
+ Utils.TENANT_IDENTIFIER;
return Utils.performServerPut(requestSpec, responseSpec, updateLoanTransactionNoteURL, updateRequest, "resourceId");
}
public static void deleteLoanTransactionNote(RequestSpecification requestSpec, ResponseSpecification responseSpec,
Integer loanTransactionId, Integer noteId) {
String deleteLoanTransactionNoteURL = LOAN_TRANSACTION_URL + "/" + loanTransactionId + "/notes/" + noteId + "?"
+ Utils.TENANT_IDENTIFIER;
Utils.performServerDelete(requestSpec, responseSpec, deleteLoanTransactionNoteURL, "");
}
}
@@ -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);
@@ -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);
@@ -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);
}
@@ -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;
@@ -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: {
@@ -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);
@@ -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);