Removed vavr related code
This commit is contained in:
committed by
Arnold Gálovics
parent
797ba293c0
commit
7a9e696ac8
+7
-6
@@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.infrastructure.core.filters;
|
package org.apache.fineract.infrastructure.core.filters;
|
||||||
|
|
||||||
import io.vavr.collection.List;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -115,11 +114,13 @@ public class IdempotencyStoreFilter extends OncePerRequestFilter implements Batc
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Optional<String> extractIdempotentKeyFromBatchRequest(BatchRequest request) {
|
private Optional<String> extractIdempotentKeyFromBatchRequest(BatchRequest request) {
|
||||||
return Optional.ofNullable(request.getHeaders()) //
|
if (request.getHeaders() == null) {
|
||||||
.map(List::ofAll) //
|
return Optional.empty();
|
||||||
.flatMap(headers -> headers.find(header -> header.getName().equals(fineractProperties.getIdempotencyKeyHeaderName()))
|
}
|
||||||
.toJavaOptional()) //
|
return request.getHeaders() //
|
||||||
.map(Header::getValue); //
|
.stream().filter(header -> header.getName().equals(fineractProperties.getIdempotencyKeyHeaderName())) //
|
||||||
|
.map(Header::getValue) //
|
||||||
|
.findAny(); //
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+43
-39
@@ -19,7 +19,6 @@
|
|||||||
package org.apache.fineract.infrastructure.jobs.filter;
|
package org.apache.fineract.infrastructure.jobs.filter;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import io.vavr.control.Either;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -34,6 +33,7 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.fineract.batch.domain.BatchRequest;
|
import org.apache.fineract.batch.domain.BatchRequest;
|
||||||
@@ -74,6 +74,13 @@ public class LoanCOBApiFilter extends OncePerRequestFilter implements BatchFilte
|
|||||||
private static final Integer GLIM_STRING_INDEX_IN_URL = 2;
|
private static final Integer GLIM_STRING_INDEX_IN_URL = 2;
|
||||||
private static final String JOB_NAME = "INLINE_LOAN_COB";
|
private static final String JOB_NAME = "INLINE_LOAN_COB";
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
private static class LoanIdsHardLockedException extends RuntimeException {
|
||||||
|
|
||||||
|
private final Long loanIdFromRequest;
|
||||||
|
}
|
||||||
|
|
||||||
private static class Reject {
|
private static class Reject {
|
||||||
|
|
||||||
private final String message;
|
private final String message;
|
||||||
@@ -109,35 +116,37 @@ public class LoanCOBApiFilter extends OncePerRequestFilter implements BatchFilte
|
|||||||
if (!isOnApiList(request.getPathInfo(), request.getMethod())) {
|
if (!isOnApiList(request.getPathInfo(), request.getMethod())) {
|
||||||
proceed(filterChain, request, response);
|
proceed(filterChain, request, response);
|
||||||
} else {
|
} else {
|
||||||
Either<Reject, Boolean> bypassUser = isBypassUser();
|
try {
|
||||||
if (bypassUser.isRight() && Boolean.TRUE.equals(bypassUser.get())) {
|
boolean bypassUser = isBypassUser();
|
||||||
proceed(filterChain, request, response);
|
if (bypassUser) {
|
||||||
} else if (bypassUser.isLeft()) {
|
|
||||||
bypassUser.getLeft().toServletResponse(response);
|
|
||||||
} else {
|
|
||||||
Either<Reject, List<Long>> result = loanIdCalculation(request.getPathInfo());
|
|
||||||
if (result.isLeft()) {
|
|
||||||
result.getLeft().toServletResponse(response);
|
|
||||||
} else {
|
|
||||||
if (isLoanSoftLocked(result.get())) {
|
|
||||||
executeInlineCob(result.get());
|
|
||||||
}
|
|
||||||
proceed(filterChain, request, response);
|
proceed(filterChain, request, response);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
List<Long> result = calculateRelevantLoanIds(request.getPathInfo());
|
||||||
|
if (isLoanSoftLocked(result)) {
|
||||||
|
executeInlineCob(result);
|
||||||
|
}
|
||||||
|
proceed(filterChain, request, response);
|
||||||
|
} catch (LoanIdsHardLockedException e) {
|
||||||
|
Reject.reject(e.getLoanIdFromRequest(), HttpStatus.SC_CONFLICT).toServletResponse(response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (UnAuthenticatedUserException e) {
|
||||||
|
Reject.reject(null, HttpStatus.SC_UNAUTHORIZED).toServletResponse(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Either<Reject, List<Long>> loanIdCalculation(String pathInfo) {
|
private List<Long> calculateRelevantLoanIds(String pathInfo) {
|
||||||
Iterable<String> split = Splitter.on('/').split(pathInfo);
|
Iterable<String> split = Splitter.on('/').split(pathInfo);
|
||||||
Supplier<Stream<String>> streamSupplier = () -> StreamSupport.stream(split.spliterator(), false);
|
Supplier<Stream<String>> streamSupplier = () -> StreamSupport.stream(split.spliterator(), false);
|
||||||
boolean isGlim = isGlim(streamSupplier);
|
boolean isGlim = isGlim(streamSupplier);
|
||||||
Long loanIdFromRequest = getLoanId(isGlim, streamSupplier);
|
Long loanIdFromRequest = getLoanId(isGlim, streamSupplier);
|
||||||
List<Long> loanIds = isGlim ? getGlimChildLoanIds(loanIdFromRequest) : Collections.singletonList(loanIdFromRequest);
|
List<Long> loanIds = isGlim ? getGlimChildLoanIds(loanIdFromRequest) : Collections.singletonList(loanIdFromRequest);
|
||||||
if (isLoanHardLocked(loanIds)) {
|
if (isLoanHardLocked(loanIds)) {
|
||||||
return Either.left(Reject.reject(loanIdFromRequest, HttpStatus.SC_CONFLICT));
|
throw new LoanIdsHardLockedException(loanIdFromRequest);
|
||||||
} else {
|
} else {
|
||||||
return Either.right(loanIds);
|
return loanIds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,12 +154,8 @@ public class LoanCOBApiFilter extends OncePerRequestFilter implements BatchFilte
|
|||||||
inlineLoanCOBExecutorService.execute(loanIds, JOB_NAME);
|
inlineLoanCOBExecutorService.execute(loanIds, JOB_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Either<Reject, Boolean> isBypassUser() {
|
private boolean isBypassUser() {
|
||||||
try {
|
return context.authenticatedUser().isBypassUser();
|
||||||
return Either.right(context.authenticatedUser().isBypassUser());
|
|
||||||
} catch (UnAuthenticatedUserException e) {
|
|
||||||
return Either.left(Reject.reject(null, HttpStatus.SC_UNAUTHORIZED));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Long> getGlimChildLoanIds(Long loanIdFromRequest) {
|
private List<Long> getGlimChildLoanIds(Long loanIdFromRequest) {
|
||||||
@@ -205,25 +210,24 @@ public class LoanCOBApiFilter extends OncePerRequestFilter implements BatchFilte
|
|||||||
if (!isOnApiList("/" + batchRequest.getRelativeUrl(), batchRequest.getMethod())) {
|
if (!isOnApiList("/" + batchRequest.getRelativeUrl(), batchRequest.getMethod())) {
|
||||||
return chain.serviceCall(batchRequest, uriInfo);
|
return chain.serviceCall(batchRequest, uriInfo);
|
||||||
} else {
|
} else {
|
||||||
Either<Reject, Boolean> bypassUser = isBypassUser();
|
try {
|
||||||
if (bypassUser.isRight() && Boolean.TRUE.equals(bypassUser.get())) {
|
boolean bypassUser = isBypassUser();
|
||||||
return chain.serviceCall(batchRequest, uriInfo);
|
if (bypassUser) {
|
||||||
} else if (bypassUser.isLeft()) {
|
|
||||||
return bypassUser.getLeft().toBatchResponse(batchRequest);
|
|
||||||
} else {
|
|
||||||
Either<Reject, List<Long>> result = loanIdCalculation("/" + batchRequest.getRelativeUrl());
|
|
||||||
if (result.isLeft()) {
|
|
||||||
return result.getLeft().toBatchResponse(batchRequest);
|
|
||||||
} else {
|
|
||||||
if (!isLoanSoftLocked(result.get())) {
|
|
||||||
executeInlineCob(result.get());
|
|
||||||
}
|
|
||||||
return chain.serviceCall(batchRequest, uriInfo);
|
return chain.serviceCall(batchRequest, uriInfo);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
List<Long> result = calculateRelevantLoanIds("/" + batchRequest.getRelativeUrl());
|
||||||
|
if (!isLoanSoftLocked(result)) {
|
||||||
|
executeInlineCob(result);
|
||||||
|
}
|
||||||
|
return chain.serviceCall(batchRequest, uriInfo);
|
||||||
|
} catch (LoanIdsHardLockedException e) {
|
||||||
|
return Reject.reject(e.getLoanIdFromRequest(), HttpStatus.SC_CONFLICT).toBatchResponse(batchRequest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (UnAuthenticatedUserException e) {
|
||||||
|
return Reject.reject(null, HttpStatus.SC_UNAUTHORIZED).toBatchResponse(batchRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -32,7 +32,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import io.vavr.CheckedFunction1;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -135,7 +134,7 @@ public class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImplTest {
|
|||||||
return mapper.writeValueAsString(jsonResponse);
|
return mapper.writeValueAsString(jsonResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mockOkHttpCall(CheckedFunction1<Request, Response> responseGenerator) throws IOException {
|
public void mockOkHttpCall(CheckedFunction<Request, Response> responseGenerator) throws IOException {
|
||||||
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
|
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
|
||||||
Call callMock = mock(Call.class);
|
Call callMock = mock(Call.class);
|
||||||
when(okHttpClient.newCall(requestCaptor.capture())).thenReturn(callMock);
|
when(okHttpClient.newCall(requestCaptor.capture())).thenReturn(callMock);
|
||||||
@@ -592,4 +591,8 @@ public class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImplTest {
|
|||||||
assertNull(result.getClosedAccounts());
|
assertNull(result.getClosedAccounts());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private interface CheckedFunction<T, R> {
|
||||||
|
|
||||||
|
R apply(T t) throws Exception;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-19
@@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.infrastructure.event.external.service.serialization.serializer.loan;
|
package org.apache.fineract.infrastructure.event.external.service.serialization.serializer.loan;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -60,7 +62,6 @@ import org.apache.fineract.portfolio.loanaccount.domain.LoanCharge;
|
|||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanInstallmentCharge;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanInstallmentCharge;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||||
import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService;
|
import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService;
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
@@ -119,24 +120,21 @@ public class LoanAccountDelinquencyRangeEventSerializerTest {
|
|||||||
LoanAccountDelinquencyRangeDataV1 data = (LoanAccountDelinquencyRangeDataV1) serializer.toAvroDTO(event);
|
LoanAccountDelinquencyRangeDataV1 data = (LoanAccountDelinquencyRangeDataV1) serializer.toAvroDTO(event);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Assertions.assertEquals(1L, data.getLoanId());
|
assertEquals(1L, data.getLoanId());
|
||||||
Assertions.assertEquals("0001", data.getLoanAccountNo());
|
assertEquals("0001", data.getLoanAccountNo());
|
||||||
Assertions.assertEquals("externalId", data.getLoanExternalId());
|
assertEquals("externalId", data.getLoanExternalId());
|
||||||
Assertions.assertEquals(1L, data.getDelinquencyRange().getId());
|
assertEquals(1L, data.getDelinquencyRange().getId());
|
||||||
Assertions.assertEquals("classification", data.getDelinquencyRange().getClassification());
|
assertEquals("classification", data.getDelinquencyRange().getClassification());
|
||||||
Assertions.assertEquals(1, data.getDelinquencyRange().getMinimumAgeDays());
|
assertEquals(1, data.getDelinquencyRange().getMinimumAgeDays());
|
||||||
Assertions.assertEquals(10, data.getDelinquencyRange().getMaximumAgeDays());
|
assertEquals(10, data.getDelinquencyRange().getMaximumAgeDays());
|
||||||
Assertions.assertEquals(2, data.getCharges().size());
|
assertEquals(2, data.getCharges().size());
|
||||||
Assertions.assertTrue(io.vavr.collection.List.ofAll(data.getCharges())
|
assertTrue(data.getCharges().stream().anyMatch(a -> a.getAmount().compareTo(new BigDecimal("100.5")) == 0));
|
||||||
.find(a -> a.getAmount().compareTo(new BigDecimal("100.5")) == 0).isDefined());
|
assertTrue(data.getCharges().stream().anyMatch(a -> a.getAmount().compareTo(new BigDecimal("200.3")) == 0));
|
||||||
Assertions.assertTrue(io.vavr.collection.List.ofAll(data.getCharges())
|
assertEquals(0, data.getAmount().getTotalAmount().compareTo(new BigDecimal("185.0")));
|
||||||
.find(a -> a.getAmount().compareTo(new BigDecimal("200.3")) == 0).isDefined());
|
assertEquals(0, data.getAmount().getPrincipalAmount().compareTo(new BigDecimal("100.0")));
|
||||||
|
assertEquals(0, data.getAmount().getInterestAmount().compareTo(new BigDecimal("30.0")));
|
||||||
Assertions.assertEquals(0, data.getAmount().getTotalAmount().compareTo(new BigDecimal("185.0")));
|
assertEquals(0, data.getAmount().getFeeAmount().compareTo(new BigDecimal("5.0")));
|
||||||
Assertions.assertEquals(0, data.getAmount().getPrincipalAmount().compareTo(new BigDecimal("100.0")));
|
assertEquals(0, data.getAmount().getPenaltyAmount().compareTo(new BigDecimal("50.0")));
|
||||||
Assertions.assertEquals(0, data.getAmount().getInterestAmount().compareTo(new BigDecimal("30.0")));
|
|
||||||
Assertions.assertEquals(0, data.getAmount().getFeeAmount().compareTo(new BigDecimal("5.0")));
|
|
||||||
Assertions.assertEquals(0, data.getAmount().getPenaltyAmount().compareTo(new BigDecimal("50.0")));
|
|
||||||
|
|
||||||
// assertEquals(data, expectedSerializedData);
|
// assertEquals(data, expectedSerializedData);
|
||||||
moneyHelper.close();
|
moneyHelper.close();
|
||||||
|
|||||||
+6
-5
@@ -220,8 +220,9 @@ public class BatchRequestsIntegrationTest {
|
|||||||
|
|
||||||
// Verify that each loan has been applied successfully
|
// Verify that each loan has been applied successfully
|
||||||
for (BatchResponse res : response) {
|
for (BatchResponse res : response) {
|
||||||
Assertions.assertFalse(io.vavr.collection.List.ofAll(res.getHeaders())
|
Assertions.assertFalse(
|
||||||
.find(header -> header.getName().equals(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER)).isDefined(),
|
res.getHeaders().stream()
|
||||||
|
.anyMatch(header -> header.getName().equals(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER)),
|
||||||
"First can not be cached!");
|
"First can not be cached!");
|
||||||
Assertions.assertEquals(200L, (long) res.getStatusCode(), "Verify Status Code 200");
|
Assertions.assertEquals(200L, (long) res.getStatusCode(), "Verify Status Code 200");
|
||||||
}
|
}
|
||||||
@@ -232,9 +233,9 @@ public class BatchRequestsIntegrationTest {
|
|||||||
// Verify that each loan has been applied successfully
|
// Verify that each loan has been applied successfully
|
||||||
for (BatchResponse res : secondResponse) {
|
for (BatchResponse res : secondResponse) {
|
||||||
Assertions.assertEquals("true",
|
Assertions.assertEquals("true",
|
||||||
io.vavr.collection.List.ofAll(res.getHeaders())
|
res.getHeaders().stream()
|
||||||
.find(header -> header.getName().equals(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER))
|
.filter(header -> header.getName().equals(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER))
|
||||||
.map(Header::getValue).get(),
|
.map(Header::getValue).findAny().get(),
|
||||||
"Not cached by idempotency key!");
|
"Not cached by idempotency key!");
|
||||||
Assertions.assertEquals(200L, (long) res.getStatusCode(), "Verify Status Code 200");
|
Assertions.assertEquals(200L, (long) res.getStatusCode(), "Verify Status Code 200");
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -37,6 +37,7 @@ import java.time.ZonedDateTime;
|
|||||||
import java.time.format.DateTimeFormatterBuilder;
|
import java.time.format.DateTimeFormatterBuilder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauReportData;
|
import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauReportData;
|
||||||
import org.apache.fineract.integrationtests.common.CreditBureauConfigurationHelper;
|
import org.apache.fineract.integrationtests.common.CreditBureauConfigurationHelper;
|
||||||
import org.apache.fineract.integrationtests.common.CreditBureauIntegrationHelper;
|
import org.apache.fineract.integrationtests.common.CreditBureauIntegrationHelper;
|
||||||
@@ -80,9 +81,8 @@ public class CreditBureauTest {
|
|||||||
List<Map<String, Object>> configurations = CreditBureauConfigurationHelper.getCreditBureauConfiguration(requestSpec, responseSpec,
|
List<Map<String, Object>> configurations = CreditBureauConfigurationHelper.getCreditBureauConfiguration(requestSpec, responseSpec,
|
||||||
"1");
|
"1");
|
||||||
Assertions.assertNotNull(configurations);
|
Assertions.assertNotNull(configurations);
|
||||||
Map<String, Integer> currentConfiguration = io.vavr.collection.List.ofAll(configurations)
|
Map<String, Integer> currentConfiguration = configurations.stream().collect(Collectors
|
||||||
.toMap(k -> String.valueOf(k.get("configurationKey")).toUpperCase(), v -> (int) v.get("creditBureauConfigurationId"))
|
.toMap(k -> String.valueOf(k.get("configurationKey")).toUpperCase(), v -> (int) v.get("creditBureauConfigurationId")));
|
||||||
.toJavaMap();
|
|
||||||
final Object usernameConfigurationId = CreditBureauConfigurationHelper.updateCreditBureauConfiguration(this.requestSpec,
|
final Object usernameConfigurationId = CreditBureauConfigurationHelper.updateCreditBureauConfiguration(this.requestSpec,
|
||||||
this.responseSpec, currentConfiguration.get("USERNAME").intValue(), "USERNAME", "testUser");
|
this.responseSpec, currentConfiguration.get("USERNAME").intValue(), "USERNAME", "testUser");
|
||||||
Assertions.assertNotNull(usernameConfigurationId);
|
Assertions.assertNotNull(usernameConfigurationId);
|
||||||
|
|||||||
Reference in New Issue
Block a user