FINERACT-1932: Fineract modularization - fineract-loan

This commit is contained in:
Jose Alberto Hernandez
2024-06-10 20:06:21 +02:00
committed by Adam Saghy
parent 655466785c
commit 6f62699cb3
366 changed files with 86 additions and 10 deletions
@@ -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;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DataIntegrityErrorHandler {
public void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve, final String msgType,
final String msgDescription) {
if (realCause.getMessage().contains("external_id")) {
final String externalId = command.stringValueOfParameterNamed("externalId");
throw new PlatformDataIntegrityException("error.msg." + msgType + ".duplicate.externalId",
msgDescription + ": externalId `" + externalId + "` already exists", "externalId", externalId);
}
log.error("Error occured.", dve);
throw ErrorHandler.getMappable(dve, "error.msg." + msgType + ".unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + msgDescription);
}
}
@@ -0,0 +1,51 @@
/**
* 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.validator;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.InvalidJsonException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
@Slf4j
public class ParseAndValidator {
protected JsonObject extractJsonObject(final FromJsonHelper jsonHelper, final JsonCommand command) {
String json = command.json();
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
final JsonElement element = jsonHelper.parse(json);
return element.getAsJsonObject();
}
protected void throwExceptionIfValidationWarningsExist(DataValidatorBuilder dataValidator) {
if (dataValidator.hasError()) {
log.error("Validation errors: {}", dataValidator.getDataValidationErrors());
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.",
dataValidator.getDataValidationErrors());
}
}
}
@@ -0,0 +1,31 @@
/**
* 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.portfolio.calendar.exception;
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
/**
* A {@link RuntimeException} thrown when Calendar resources are not found.
*/
public class NotValidRecurringDateException extends AbstractPlatformDomainRuleException {
public NotValidRecurringDateException(final String postFix, final String defaultUserMessage, final Object... defaultUserMessageArgs) {
super("error.msg.calendar." + postFix + ".not.valid.recurring.date", defaultUserMessage, defaultUserMessageArgs);
}
}
@@ -0,0 +1,51 @@
/**
* 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.portfolio.collectionsheet.command;
import java.time.LocalDate;
/**
* Immutable command for loan bulk disburse.
*/
public class CollectionSheetBulkDisbursalCommand {
private final String note;
private final LocalDate transactionDate;
private final SingleDisbursalCommand[] disburseTransactions;
public CollectionSheetBulkDisbursalCommand(final String note, final LocalDate transactionDate,
final SingleDisbursalCommand[] disburseTransactions) {
this.note = note;
this.transactionDate = transactionDate;
this.disburseTransactions = disburseTransactions;
}
public String getNote() {
return this.note;
}
public SingleDisbursalCommand[] getDisburseTransactions() {
return this.disburseTransactions;
}
public LocalDate getTransactionDate() {
return this.transactionDate;
}
}
@@ -0,0 +1,51 @@
/**
* 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.portfolio.collectionsheet.command;
import java.time.LocalDate;
/**
* Immutable command for loan bulk repayment.
*/
public class CollectionSheetBulkRepaymentCommand {
private final String note;
private final LocalDate transactionDate;
private final SingleRepaymentCommand[] repaymentTransactions;
public CollectionSheetBulkRepaymentCommand(final String note, final LocalDate transactionDate,
final SingleRepaymentCommand[] repaymentTransactions) {
this.note = note;
this.transactionDate = transactionDate;
this.repaymentTransactions = repaymentTransactions;
}
public String getNote() {
return this.note;
}
public SingleRepaymentCommand[] getLoanTransactions() {
return this.repaymentTransactions;
}
public LocalDate getTransactionDate() {
return this.transactionDate;
}
}
@@ -0,0 +1,51 @@
/**
* 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.portfolio.collectionsheet.command;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* Immutable command for Single loan repayment.
*/
public class SingleDisbursalCommand {
private final Long loanId;
private final BigDecimal transactionAmount;
private final LocalDate transactionDate;
public SingleDisbursalCommand(final Long loanId, final BigDecimal transactionAmount, final LocalDate transactionDate) {
this.loanId = loanId;
this.transactionAmount = transactionAmount;
this.transactionDate = transactionDate;
}
public Long getLoanId() {
return this.loanId;
}
public BigDecimal getTransactionAmount() {
return this.transactionAmount;
}
public LocalDate getTransactionDate() {
return this.transactionDate;
}
}
@@ -0,0 +1,40 @@
/**
* 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.portfolio.collectionsheet.command;
import java.math.BigDecimal;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
/**
* Immutable command for Single loan repayment.
*/
@Getter
@AllArgsConstructor
public class SingleRepaymentCommand {
private final Long loanId;
private final ExternalId externalId;
private final BigDecimal transactionAmount;
private final LocalDate transactionDate;
private final PaymentDetail paymentDetail;
}
@@ -0,0 +1,52 @@
/**
* 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.portfolio.fund.data;
import java.io.Serializable;
/**
* Immutable data object to represent fund data.
*/
public final class FundData implements Serializable {
@SuppressWarnings("unused")
private final Long id;
@SuppressWarnings("unused")
private final String name;
@SuppressWarnings("unused")
private final String externalId;
public static FundData instance(final Long id, final String name, final String externalId) {
return new FundData(id, name, externalId);
}
private FundData(final Long id, final String name, final String externalId) {
this.id = id;
this.name = name;
this.externalId = externalId;
}
public String getName() {
return name;
}
public Long getId() {
return id;
}
}
@@ -0,0 +1,56 @@
/**
* 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.portfolio.rate.data;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.Getter;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
/**
* Bowpi GT Created by Jose on 19/07/2017.
*/
@Getter
public final class RateData implements Serializable {
private Long id;
private String name;
private BigDecimal percentage;
private EnumOptionData productApply;
private boolean active;
public static RateData instance(final Long id, final String name, final BigDecimal percentage, final EnumOptionData productApply,
final boolean active) {
return new RateData(id, name, percentage, productApply, active);
}
private RateData(final Long id, final String name, final BigDecimal percentage, final EnumOptionData productApply,
final boolean active) {
this.id = id;
this.name = name;
this.percentage = percentage;
this.productApply = productApply;
this.active = active;
}
}