Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
import org.apache.fineract.client.feign.services.WorkingCapitalLoanProductsApi;
import org.apache.fineract.client.feign.services.WorkingCapitalLoanTransactionsApi;
import org.apache.fineract.client.feign.services.WorkingCapitalLoansApi;
import org.apache.fineract.client.feign.services.WorkingCapitalNearBreachApi;
import org.apache.fineract.client.feign.services.WorkingDaysApi;

/**
Expand Down Expand Up @@ -787,6 +788,10 @@ public WorkingCapitalBreachApi workingCapitalBreaches() {
return create(WorkingCapitalBreachApi.class);
}

public WorkingCapitalNearBreachApi workingCapitalNearBreaches() {
return create(WorkingCapitalNearBreachApi.class);
}

public WorkingDaysApi workingDays() {
return create(WorkingDaysApi.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,30 @@ public CommandWrapperBuilder deleteWorkingCapitalBreach(final Long breachId) {
return this;
}

public CommandWrapperBuilder createWorkingCapitalNearBreach() {
this.actionName = "CREATE";
this.entityName = "WORKINGCAPITALNEARBREACH";
this.entityId = null;
this.href = "/working-capital/near-breach";
return this;
}

public CommandWrapperBuilder updateWorkingCapitalNearBreach(final Long breachId) {
this.actionName = "UPDATE";
this.entityName = "WORKINGCAPITALNEARBREACH";
this.entityId = breachId;
this.href = "/working-capital/near-breach/" + breachId;
return this;
}

public CommandWrapperBuilder deleteWorkingCapitalNearBreach(final Long breachId) {
this.actionName = "DELETE";
this.entityName = "WORKINGCAPITALNEARBREACH";
this.entityId = breachId;
this.href = "/working-capital/near-breach/" + breachId;
return this;
}

public CommandWrapperBuilder createWorkingCapitalLoanApplication() {
this.actionName = ACTION_CREATE;
this.entityName = ENTITY_WORKINGCAPITALLOAN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ public static ApiGlobalErrorResponse notImplemented(final String globalisationMe
public static ApiGlobalErrorResponse dataIntegrityError(final String globalisationMessageCode, final String defaultUserMessage,
final String parameterName, final Object... defaultUserMessageArgs) {
final List<ApiParameterError> errors = new ArrayList<>();
errors.add(ApiParameterError.parameterError(globalisationMessageCode, defaultUserMessage, parameterName, defaultUserMessageArgs));
final String developerMessage = "The request caused a data integrity issue to be fired by the database.";
Comment thread
adamsaghy marked this conversation as resolved.
Resolved
errors.add(ApiParameterError.parameterError(globalisationMessageCode, developerMessage, defaultUserMessage, parameterName,
defaultUserMessageArgs));

return create(SC_FORBIDDEN, globalisationMessageCode, "The request caused a data integrity issue to be fired by the database.",
defaultUserMessage, errors);
return create(SC_FORBIDDEN, globalisationMessageCode, developerMessage, defaultUserMessage, errors);
}

public static ApiGlobalErrorResponse notFound(final String globalisationMessageCode, final String defaultUserMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public static ApiParameterError resourceIdentifierNotFound(final String globalis
return new ApiParameterError(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs, "id", null);
}

public static ApiParameterError parameterError(final String globalisationMessageCode, final String developerMessage,
final String defaultUserMessage, final String parameterName, final Object... defaultUserMessageArgs) {
return new ApiParameterError(globalisationMessageCode, developerMessage, defaultUserMessage, defaultUserMessageArgs, parameterName,
null);
}

public static ApiParameterError parameterError(final String globalisationMessageCode, final String defaultUserMessage,
final String parameterName, final Object... defaultUserMessageArgs) {
return new ApiParameterError(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs, parameterName, null);
Expand All @@ -77,6 +83,29 @@ public static ApiParameterError parameterErrorWithValue(final String globalisati
return new ApiParameterError(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs, parameterName, value);
}

private ApiParameterError(final String globalisationMessageCode, final String developerMessage, final String defaultUserMessage,
final Object[] defaultUserMessageArgs, String parameterName, String value) {
this.userMessageGlobalisationCode = globalisationMessageCode;
this.developerMessage = developerMessage;
this.defaultUserMessage = defaultUserMessage;
this.parameterName = parameterName;
this.value = value;

final List<ApiErrorMessageArg> messageArgs = new ArrayList<>();
if (defaultUserMessageArgs != null) {
for (final Object object : defaultUserMessageArgs) {
if (object instanceof LocalDate) {
final DateTimeFormatter dateFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd").toFormatter();
final String formattedDate = dateFormatter.format((LocalDate) object);
messageArgs.add(ApiErrorMessageArg.from(formattedDate));
} else {
messageArgs.add(ApiErrorMessageArg.from(object));
}
}
}
this.args = messageArgs;
}

private ApiParameterError(final String globalisationMessageCode, final String defaultUserMessage, final Object[] defaultUserMessageArgs,
String parameterName, String value) {
this.userMessageGlobalisationCode = globalisationMessageCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,31 @@ public DataValidatorBuilder positiveAmount() {
return this;
}

public DataValidatorBuilder percentage() {
if (this.value == null && this.ignoreNullValue) {
return this;
}

if (this.value != null) {
final BigDecimal number = new BigDecimal(this.value.toString());
if (number.compareTo(BigDecimal.ZERO) <= 0) {
String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".not.greater.than.zero";
String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than 0.";
final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter,
number, 0);
this.dataValidationErrors.add(error);
}
if (number.compareTo(BigDecimal.valueOf(100.0)) > 0) {
String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".greater.than.one.hundred";
String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be not greater than 100.";
final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter,
number, 0);
this.dataValidationErrors.add(error);
}
}
return this;
}

/*
* should be used with .notNull() before it
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 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.infrastructure.core.service;

public final class FrequencyTypeUtil {

private FrequencyTypeUtil() {}

public static int compareFrequencies(final Integer frequency1, final String frequencyType1, final Integer frequency2,
final String frequencyType2) {
if (frequencyType1.equals(frequencyType2)) {
return frequency1.compareTo(frequency2);
}
return frequencyToDays(frequency1, frequencyType1).compareTo(frequencyToDays(frequency2, frequencyType2));
}

private static Integer frequencyToDays(final Integer frequency, final String frequencyType) {
return switch (frequencyType) {
case "DAYS" -> frequency;
case "WEEKS" -> frequency * 7;
case "MONTHS" -> frequency * 30;
case "YEARS" -> frequency * 365;
default -> 0;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.fineract.portfolio.common.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
Expand Down Expand Up @@ -55,4 +56,21 @@ private static List<ApiParameterError> getApiParameterErrors(String resource, Co
baseDataValidator.accept(dataValidatorBuilder);
return dataValidationErrors;
}

public static boolean isChanged(final Object newValue, final Object currentValue) {
if (newValue == null) {
return currentValue != null;
}
return !newValue.equals(currentValue);
}

public static boolean isBigDecimalChanged(final BigDecimal newValue, final BigDecimal currentValue) {
if (newValue == null) {
return currentValue != null;
}
if (currentValue == null) {
return true;
}
return newValue.compareTo(currentValue) != 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void validDateTimeFormatPatternShouldRejectInvalidPatterns(final String pattern)
final List<ApiParameterError> errors = new ArrayList<>();
new DataValidatorBuilder(errors).resource(RESOURCE).parameter(PARAMETER).value(pattern).validDateTimeFormatPattern();
assertThat(errors).hasSize(1);
assertThat(errors.get(0).getParameterName()).isEqualTo(PARAMETER);
assertThat(errors.get(0).getParameterName()).isEqualTo(pattern);
assertThat(errors.get(0).getDeveloperMessage()).contains("invalid date/time pattern");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public enum DefaultWorkingCapitalLoanProduct implements WorkingCapitalLoanProduc
WCLP_DISCOUNT, //
WCLP_DISALLOW_ATTRIBUTES_OVERRIDE, //
WCLP_DISCOUNT_DISALLOW_ATTRIBUTES_OVERRIDE, //
WCLP_FOR_UPDATE; //
WCLP_FOR_UPDATE, //
WCLP_DELINQUENCY_RESCHEDULE, //
WCLP_BREACH, //
WCLP_BREACH_NEAR_BREACH, //
WCLP_BREACH_DISALLOW_ATTRIBUTES_OVERRIDE, //
WCLP_BREACH_NEAR_BREACH_DISALLOW_ATTRIBUTES_OVERRIDE; //

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* 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.test.data.workingcapitalproduct;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum WorkingCapitalBreachCalculationType {

FLAT(0L, "FLAT", "Flat"), //
PERCENTAGE(1L, "PERCENTAGE", "Percentage"); //

private final Long id;
private final String code;
private final String value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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.test.data.workingcapitalproduct;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum WorkingCapitalBreachFrequencyType {

DAYS(0L, "DAYS", "Days"), //
MONTHS(1L, "MONTHS", "Months"), //
YEARS(2L, "YEARS", "Years");

private final Long id;
private final String code;
private final String value;
}
Loading
Loading