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;
|
||||
|
||||
import io.vavr.collection.List;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
@@ -115,11 +114,13 @@ public class IdempotencyStoreFilter extends OncePerRequestFilter implements Batc
|
||||
}
|
||||
|
||||
private Optional<String> extractIdempotentKeyFromBatchRequest(BatchRequest request) {
|
||||
return Optional.ofNullable(request.getHeaders()) //
|
||||
.map(List::ofAll) //
|
||||
.flatMap(headers -> headers.find(header -> header.getName().equals(fineractProperties.getIdempotencyKeyHeaderName()))
|
||||
.toJavaOptional()) //
|
||||
.map(Header::getValue); //
|
||||
if (request.getHeaders() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return request.getHeaders() //
|
||||
.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;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import io.vavr.control.Either;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
@@ -34,6 +33,7 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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 String JOB_NAME = "INLINE_LOAN_COB";
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
private static class LoanIdsHardLockedException extends RuntimeException {
|
||||
|
||||
private final Long loanIdFromRequest;
|
||||
}
|
||||
|
||||
private static class Reject {
|
||||
|
||||
private final String message;
|
||||
@@ -109,35 +116,37 @@ public class LoanCOBApiFilter extends OncePerRequestFilter implements BatchFilte
|
||||
if (!isOnApiList(request.getPathInfo(), request.getMethod())) {
|
||||
proceed(filterChain, request, response);
|
||||
} else {
|
||||
Either<Reject, Boolean> bypassUser = isBypassUser();
|
||||
if (bypassUser.isRight() && Boolean.TRUE.equals(bypassUser.get())) {
|
||||
proceed(filterChain, request, response);
|
||||
} 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());
|
||||
}
|
||||
try {
|
||||
boolean bypassUser = isBypassUser();
|
||||
if (bypassUser) {
|
||||
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);
|
||||
Supplier<Stream<String>> streamSupplier = () -> StreamSupport.stream(split.spliterator(), false);
|
||||
boolean isGlim = isGlim(streamSupplier);
|
||||
Long loanIdFromRequest = getLoanId(isGlim, streamSupplier);
|
||||
List<Long> loanIds = isGlim ? getGlimChildLoanIds(loanIdFromRequest) : Collections.singletonList(loanIdFromRequest);
|
||||
if (isLoanHardLocked(loanIds)) {
|
||||
return Either.left(Reject.reject(loanIdFromRequest, HttpStatus.SC_CONFLICT));
|
||||
throw new LoanIdsHardLockedException(loanIdFromRequest);
|
||||
} else {
|
||||
return Either.right(loanIds);
|
||||
return loanIds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,12 +154,8 @@ public class LoanCOBApiFilter extends OncePerRequestFilter implements BatchFilte
|
||||
inlineLoanCOBExecutorService.execute(loanIds, JOB_NAME);
|
||||
}
|
||||
|
||||
private Either<Reject, Boolean> isBypassUser() {
|
||||
try {
|
||||
return Either.right(context.authenticatedUser().isBypassUser());
|
||||
} catch (UnAuthenticatedUserException e) {
|
||||
return Either.left(Reject.reject(null, HttpStatus.SC_UNAUTHORIZED));
|
||||
}
|
||||
private boolean isBypassUser() {
|
||||
return context.authenticatedUser().isBypassUser();
|
||||
}
|
||||
|
||||
private List<Long> getGlimChildLoanIds(Long loanIdFromRequest) {
|
||||
@@ -205,25 +210,24 @@ public class LoanCOBApiFilter extends OncePerRequestFilter implements BatchFilte
|
||||
if (!isOnApiList("/" + batchRequest.getRelativeUrl(), batchRequest.getMethod())) {
|
||||
return chain.serviceCall(batchRequest, uriInfo);
|
||||
} else {
|
||||
Either<Reject, Boolean> bypassUser = isBypassUser();
|
||||
if (bypassUser.isRight() && Boolean.TRUE.equals(bypassUser.get())) {
|
||||
return chain.serviceCall(batchRequest, uriInfo);
|
||||
} 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());
|
||||
}
|
||||
try {
|
||||
boolean bypassUser = isBypassUser();
|
||||
if (bypassUser) {
|
||||
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.ObjectNode;
|
||||
import com.google.gson.JsonParser;
|
||||
import io.vavr.CheckedFunction1;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -135,7 +134,7 @@ public class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImplTest {
|
||||
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);
|
||||
Call callMock = mock(Call.class);
|
||||
when(okHttpClient.newCall(requestCaptor.capture())).thenReturn(callMock);
|
||||
@@ -592,4 +591,8 @@ public class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImplTest {
|
||||
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;
|
||||
|
||||
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.Mockito.mock;
|
||||
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.LoanRepaymentScheduleInstallment;
|
||||
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.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -119,24 +120,21 @@ public class LoanAccountDelinquencyRangeEventSerializerTest {
|
||||
LoanAccountDelinquencyRangeDataV1 data = (LoanAccountDelinquencyRangeDataV1) serializer.toAvroDTO(event);
|
||||
|
||||
// then
|
||||
Assertions.assertEquals(1L, data.getLoanId());
|
||||
Assertions.assertEquals("0001", data.getLoanAccountNo());
|
||||
Assertions.assertEquals("externalId", data.getLoanExternalId());
|
||||
Assertions.assertEquals(1L, data.getDelinquencyRange().getId());
|
||||
Assertions.assertEquals("classification", data.getDelinquencyRange().getClassification());
|
||||
Assertions.assertEquals(1, data.getDelinquencyRange().getMinimumAgeDays());
|
||||
Assertions.assertEquals(10, data.getDelinquencyRange().getMaximumAgeDays());
|
||||
Assertions.assertEquals(2, data.getCharges().size());
|
||||
Assertions.assertTrue(io.vavr.collection.List.ofAll(data.getCharges())
|
||||
.find(a -> a.getAmount().compareTo(new BigDecimal("100.5")) == 0).isDefined());
|
||||
Assertions.assertTrue(io.vavr.collection.List.ofAll(data.getCharges())
|
||||
.find(a -> a.getAmount().compareTo(new BigDecimal("200.3")) == 0).isDefined());
|
||||
|
||||
Assertions.assertEquals(0, data.getAmount().getTotalAmount().compareTo(new BigDecimal("185.0")));
|
||||
Assertions.assertEquals(0, data.getAmount().getPrincipalAmount().compareTo(new BigDecimal("100.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(1L, data.getLoanId());
|
||||
assertEquals("0001", data.getLoanAccountNo());
|
||||
assertEquals("externalId", data.getLoanExternalId());
|
||||
assertEquals(1L, data.getDelinquencyRange().getId());
|
||||
assertEquals("classification", data.getDelinquencyRange().getClassification());
|
||||
assertEquals(1, data.getDelinquencyRange().getMinimumAgeDays());
|
||||
assertEquals(10, data.getDelinquencyRange().getMaximumAgeDays());
|
||||
assertEquals(2, data.getCharges().size());
|
||||
assertTrue(data.getCharges().stream().anyMatch(a -> a.getAmount().compareTo(new BigDecimal("100.5")) == 0));
|
||||
assertTrue(data.getCharges().stream().anyMatch(a -> a.getAmount().compareTo(new BigDecimal("200.3")) == 0));
|
||||
assertEquals(0, data.getAmount().getTotalAmount().compareTo(new BigDecimal("185.0")));
|
||||
assertEquals(0, data.getAmount().getPrincipalAmount().compareTo(new BigDecimal("100.0")));
|
||||
assertEquals(0, data.getAmount().getInterestAmount().compareTo(new BigDecimal("30.0")));
|
||||
assertEquals(0, data.getAmount().getFeeAmount().compareTo(new BigDecimal("5.0")));
|
||||
assertEquals(0, data.getAmount().getPenaltyAmount().compareTo(new BigDecimal("50.0")));
|
||||
|
||||
// assertEquals(data, expectedSerializedData);
|
||||
moneyHelper.close();
|
||||
|
||||
+6
-5
@@ -220,8 +220,9 @@ public class BatchRequestsIntegrationTest {
|
||||
|
||||
// Verify that each loan has been applied successfully
|
||||
for (BatchResponse res : response) {
|
||||
Assertions.assertFalse(io.vavr.collection.List.ofAll(res.getHeaders())
|
||||
.find(header -> header.getName().equals(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER)).isDefined(),
|
||||
Assertions.assertFalse(
|
||||
res.getHeaders().stream()
|
||||
.anyMatch(header -> header.getName().equals(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER)),
|
||||
"First can not be cached!");
|
||||
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
|
||||
for (BatchResponse res : secondResponse) {
|
||||
Assertions.assertEquals("true",
|
||||
io.vavr.collection.List.ofAll(res.getHeaders())
|
||||
.find(header -> header.getName().equals(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER))
|
||||
.map(Header::getValue).get(),
|
||||
res.getHeaders().stream()
|
||||
.filter(header -> header.getName().equals(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER))
|
||||
.map(Header::getValue).findAny().get(),
|
||||
"Not cached by idempotency key!");
|
||||
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.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauReportData;
|
||||
import org.apache.fineract.integrationtests.common.CreditBureauConfigurationHelper;
|
||||
import org.apache.fineract.integrationtests.common.CreditBureauIntegrationHelper;
|
||||
@@ -80,9 +81,8 @@ public class CreditBureauTest {
|
||||
List<Map<String, Object>> configurations = CreditBureauConfigurationHelper.getCreditBureauConfiguration(requestSpec, responseSpec,
|
||||
"1");
|
||||
Assertions.assertNotNull(configurations);
|
||||
Map<String, Integer> currentConfiguration = io.vavr.collection.List.ofAll(configurations)
|
||||
.toMap(k -> String.valueOf(k.get("configurationKey")).toUpperCase(), v -> (int) v.get("creditBureauConfigurationId"))
|
||||
.toJavaMap();
|
||||
Map<String, Integer> currentConfiguration = configurations.stream().collect(Collectors
|
||||
.toMap(k -> String.valueOf(k.get("configurationKey")).toUpperCase(), v -> (int) v.get("creditBureauConfigurationId")));
|
||||
final Object usernameConfigurationId = CreditBureauConfigurationHelper.updateCreditBureauConfiguration(this.requestSpec,
|
||||
this.responseSpec, currentConfiguration.get("USERNAME").intValue(), "USERNAME", "testUser");
|
||||
Assertions.assertNotNull(usernameConfigurationId);
|
||||
|
||||
Reference in New Issue
Block a user