FINERACT-1968: Advanced payment allocation - Default allocation

This commit is contained in:
Adam Saghy
2023-09-05 17:14:32 +02:00
parent 26eca0fccd
commit 6d938995a0
14 changed files with 2163 additions and 47 deletions
@@ -25,6 +25,7 @@ import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -40,7 +41,8 @@ public class DefaultExceptionMapper implements FineractExceptionMapper, Exceptio
@Override
public Response toResponse(RuntimeException runtimeException) {
return Response.status(SC_INTERNAL_SERVER_ERROR).entity(Map.of("Exception", runtimeException.getMessage()))
return Response.status(SC_INTERNAL_SERVER_ERROR)
.entity(Map.of("Exception", ObjectUtils.defaultIfNull(runtimeException.getMessage(), "No error message available")))
.type(MediaType.APPLICATION_JSON).build();
}
}
@@ -433,6 +433,14 @@ public final class MathUtil {
return min(min(first, second, notNull), third, notNull);
}
/**
* Calculate percentage of a value
*
* @param value
* @param percentage
* @param precision
* @return
*/
public static BigDecimal percentageOf(final BigDecimal value, final BigDecimal percentage, final int precision) {
BigDecimal percentageOf = BigDecimal.ZERO;
if (isGreaterThanZero(value)) {