refactor: add lombok to holiday module
This commit is contained in:
committed by
Arnold Gálovics
parent
ba765f9b7a
commit
b45baa12b0
+15
-22
@@ -19,38 +19,31 @@
|
||||
package org.apache.fineract.organisation.holiday.data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class HolidayData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Long id;
|
||||
private Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String name;
|
||||
private String name;
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
private String description;
|
||||
@SuppressWarnings("unused")
|
||||
private final LocalDate fromDate;
|
||||
private LocalDate fromDate;
|
||||
@SuppressWarnings("unused")
|
||||
private final LocalDate toDate;
|
||||
private LocalDate toDate;
|
||||
@SuppressWarnings("unused")
|
||||
private final LocalDate repaymentsRescheduledTo;
|
||||
private LocalDate repaymentsRescheduledTo;
|
||||
@SuppressWarnings("unused")
|
||||
private final Long officeId;
|
||||
private Long officeId;
|
||||
@SuppressWarnings("unused")
|
||||
private final EnumOptionData status;
|
||||
private final Integer reschedulingType;
|
||||
|
||||
public HolidayData(final Long id, final String name, final String description, final LocalDate fromDate, final LocalDate toDate,
|
||||
final LocalDate repaymentsRescheduledTo, final EnumOptionData status, final Integer reschedulingType) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.fromDate = fromDate;
|
||||
this.toDate = toDate;
|
||||
this.repaymentsRescheduledTo = repaymentsRescheduledTo;
|
||||
this.officeId = null;
|
||||
this.status = status;
|
||||
this.reschedulingType = reschedulingType;
|
||||
}
|
||||
private EnumOptionData status;
|
||||
private Integer reschedulingType;
|
||||
}
|
||||
|
||||
+17
-67
@@ -43,6 +43,10 @@ import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
|
||||
@@ -54,6 +58,10 @@ import org.apache.fineract.organisation.office.domain.Office;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_holiday", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "holiday_name") })
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class Holiday extends AbstractPersistableCustom {
|
||||
|
||||
@Column(name = "name", unique = true, nullable = false, length = 100)
|
||||
@@ -101,7 +109,9 @@ public class Holiday extends AbstractPersistableCustom {
|
||||
// should update this field.
|
||||
final String description = command.stringValueOfParameterNamed(HolidayApiConstants.descriptionParamName);
|
||||
|
||||
return new Holiday(name, fromDate, toDate, repaymentsRescheduledTo, status, processed, description, offices, reschedulingType);
|
||||
return new Holiday().setName(StringUtils.trim(name)).setFromDate(fromDate).setToDate(toDate)
|
||||
.setRepaymentsRescheduledTo(repaymentsRescheduledTo).setStatus(status).setProcessed(processed)
|
||||
.setDescription(StringUtils.trim(description)).setOffices(offices).setReschedulingType(reschedulingType);
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
@@ -137,7 +147,7 @@ public class Holiday extends AbstractPersistableCustom {
|
||||
}
|
||||
|
||||
if (currentStatus.isPendingActivation()) {
|
||||
if (command.isChangeInLocalDateParameterNamed(fromDateParamName, getFromDateLocalDate())) {
|
||||
if (command.isChangeInLocalDateParameterNamed(fromDateParamName, getFromDate())) {
|
||||
final String valueAsInput = command.stringValueOfParameterNamed(fromDateParamName);
|
||||
actualChanges.put(fromDateParamName, valueAsInput);
|
||||
actualChanges.put(dateFormatParamName, dateFormatAsInput);
|
||||
@@ -145,7 +155,7 @@ public class Holiday extends AbstractPersistableCustom {
|
||||
this.fromDate = command.localDateValueOfParameterNamed(fromDateParamName);
|
||||
}
|
||||
|
||||
if (command.isChangeInLocalDateParameterNamed(toDateParamName, getToDateLocalDate())) {
|
||||
if (command.isChangeInLocalDateParameterNamed(toDateParamName, getToDate())) {
|
||||
final String valueAsInput = command.stringValueOfParameterNamed(toDateParamName);
|
||||
actualChanges.put(toDateParamName, valueAsInput);
|
||||
actualChanges.put(dateFormatParamName, dateFormatAsInput);
|
||||
@@ -154,7 +164,7 @@ public class Holiday extends AbstractPersistableCustom {
|
||||
this.toDate = command.localDateValueOfParameterNamed(toDateParamName);
|
||||
}
|
||||
|
||||
if (command.isChangeInLocalDateParameterNamed(repaymentsRescheduledToParamName, getRepaymentsRescheduledToLocalDate())) {
|
||||
if (command.isChangeInLocalDateParameterNamed(repaymentsRescheduledToParamName, getRepaymentsRescheduledTo())) {
|
||||
final String valueAsInput = command.stringValueOfParameterNamed(repaymentsRescheduledToParamName);
|
||||
actualChanges.put(repaymentsRescheduledToParamName, valueAsInput);
|
||||
actualChanges.put(dateFormatParamName, dateFormatAsInput);
|
||||
@@ -170,15 +180,15 @@ public class Holiday extends AbstractPersistableCustom {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (command.isChangeInLocalDateParameterNamed(fromDateParamName, getFromDateLocalDate())) {
|
||||
if (command.isChangeInLocalDateParameterNamed(fromDateParamName, getFromDate())) {
|
||||
baseDataValidator.reset().parameter(fromDateParamName).failWithCode("cannot.edit.holiday.in.active.state");
|
||||
}
|
||||
|
||||
if (command.isChangeInLocalDateParameterNamed(toDateParamName, getToDateLocalDate())) {
|
||||
if (command.isChangeInLocalDateParameterNamed(toDateParamName, getToDate())) {
|
||||
baseDataValidator.reset().parameter(toDateParamName).failWithCode("cannot.edit.holiday.in.active.state");
|
||||
}
|
||||
|
||||
if (command.isChangeInLocalDateParameterNamed(repaymentsRescheduledToParamName, getRepaymentsRescheduledToLocalDate())) {
|
||||
if (command.isChangeInLocalDateParameterNamed(repaymentsRescheduledToParamName, getRepaymentsRescheduledTo())) {
|
||||
baseDataValidator.reset().parameter(repaymentsRescheduledToParamName).failWithCode("cannot.edit.holiday.in.active.state");
|
||||
}
|
||||
|
||||
@@ -215,66 +225,6 @@ public class Holiday extends AbstractPersistableCustom {
|
||||
return updated;
|
||||
}
|
||||
|
||||
private Holiday(final String name, final LocalDate fromDate, final LocalDate toDate, final LocalDate repaymentsRescheduledTo,
|
||||
final Integer status, final boolean processed, final String description, final Set<Office> offices,
|
||||
final int reschedulingType) {
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
this.name = name.trim();
|
||||
}
|
||||
|
||||
if (fromDate != null) {
|
||||
this.fromDate = fromDate;
|
||||
}
|
||||
|
||||
if (toDate != null) {
|
||||
this.toDate = toDate;
|
||||
}
|
||||
|
||||
if (repaymentsRescheduledTo != null) {
|
||||
this.repaymentsRescheduledTo = repaymentsRescheduledTo;
|
||||
}
|
||||
|
||||
this.status = status;
|
||||
this.processed = processed;
|
||||
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
this.description = description.trim();
|
||||
} else {
|
||||
this.description = null;
|
||||
}
|
||||
|
||||
if (offices != null) {
|
||||
this.offices = offices;
|
||||
}
|
||||
this.reschedulingType = reschedulingType;
|
||||
}
|
||||
|
||||
protected Holiday() {}
|
||||
|
||||
public LocalDate getRepaymentsRescheduledToLocalDate() {
|
||||
return this.repaymentsRescheduledTo;
|
||||
}
|
||||
|
||||
public boolean isProcessed() {
|
||||
return this.processed;
|
||||
}
|
||||
|
||||
public Set<Office> getOffices() {
|
||||
return this.offices;
|
||||
}
|
||||
|
||||
public LocalDate getFromDateLocalDate() {
|
||||
return this.fromDate;
|
||||
}
|
||||
|
||||
public LocalDate getToDateLocalDate() {
|
||||
return this.toDate;
|
||||
}
|
||||
|
||||
public void processed() {
|
||||
this.processed = true;
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("holiday" + ".activate");
|
||||
|
||||
+2
-1
@@ -79,7 +79,8 @@ public class HolidayReadPlatformServiceImpl implements HolidayReadPlatformServic
|
||||
final Integer reschedulingType = JdbcSupport.getInteger(rs, "reschedulingType");
|
||||
final EnumOptionData status = HolidayEnumerations.holidayStatusType(statusEnum);
|
||||
|
||||
return new HolidayData(id, name, description, fromDate, toDate, repaymentsScheduleTO, status, reschedulingType);
|
||||
return new HolidayData().setId(id).setName(name).setDescription(description).setFromDate(fromDate).setToDate(toDate)
|
||||
.setRepaymentsRescheduledTo(repaymentsScheduleTO).setStatus(status).setReschedulingType(reschedulingType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-9
@@ -32,8 +32,8 @@ public final class HolidayUtil {
|
||||
public static LocalDate getRepaymentRescheduleDateToIfHoliday(LocalDate repaymentDate, final List<Holiday> holidays) {
|
||||
|
||||
for (final Holiday holiday : holidays) {
|
||||
if (repaymentDate.equals(holiday.getFromDateLocalDate()) || repaymentDate.equals(holiday.getToDateLocalDate())
|
||||
|| (repaymentDate.isAfter(holiday.getFromDateLocalDate()) && repaymentDate.isBefore(holiday.getToDateLocalDate()))) {
|
||||
if (repaymentDate.equals(holiday.getFromDate()) || repaymentDate.equals(holiday.getToDate())
|
||||
|| (repaymentDate.isAfter(holiday.getFromDate()) && repaymentDate.isBefore(holiday.getToDate()))) {
|
||||
repaymentDate = getRepaymentRescheduleDateIfHoliday(repaymentDate, holidays);
|
||||
}
|
||||
}
|
||||
@@ -43,10 +43,10 @@ public final class HolidayUtil {
|
||||
private static LocalDate getRepaymentRescheduleDateIfHoliday(final LocalDate repaymentDate, final List<Holiday> holidays) {
|
||||
|
||||
for (final Holiday holiday : holidays) {
|
||||
if (repaymentDate.equals(holiday.getFromDateLocalDate()) || repaymentDate.equals(holiday.getToDateLocalDate())
|
||||
|| (repaymentDate.isAfter(holiday.getFromDateLocalDate()) && repaymentDate.isBefore(holiday.getToDateLocalDate()))) {
|
||||
if (repaymentDate.equals(holiday.getFromDate()) || repaymentDate.equals(holiday.getToDate())
|
||||
|| (repaymentDate.isAfter(holiday.getFromDate()) && repaymentDate.isBefore(holiday.getToDate()))) {
|
||||
// should be take from holiday
|
||||
return holiday.getRepaymentsRescheduledToLocalDate();
|
||||
return holiday.getRepaymentsRescheduledTo();
|
||||
}
|
||||
}
|
||||
return repaymentDate;
|
||||
@@ -54,8 +54,8 @@ public final class HolidayUtil {
|
||||
|
||||
public static boolean isHoliday(final LocalDate date, final List<Holiday> holidays) {
|
||||
for (final Holiday holiday : holidays) {
|
||||
if (date.isEqual(holiday.getFromDateLocalDate()) || date.isEqual(holiday.getToDateLocalDate())
|
||||
|| (date.isAfter(holiday.getFromDateLocalDate()) && date.isBefore(holiday.getToDateLocalDate()))) {
|
||||
if (date.isEqual(holiday.getFromDate()) || date.isEqual(holiday.getToDate())
|
||||
|| (date.isAfter(holiday.getFromDate()) && date.isBefore(holiday.getToDate()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public final class HolidayUtil {
|
||||
public static Holiday getApplicableHoliday(final LocalDate repaymentDate, final List<Holiday> holidays) {
|
||||
Holiday referedHoliday = null;
|
||||
for (final Holiday holiday : holidays) {
|
||||
if (!repaymentDate.isBefore(holiday.getFromDateLocalDate()) && !repaymentDate.isAfter(holiday.getToDateLocalDate())) {
|
||||
if (!repaymentDate.isBefore(holiday.getFromDate()) && !repaymentDate.isAfter(holiday.getToDate())) {
|
||||
referedHoliday = holiday;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public final class HolidayUtil {
|
||||
public static void updateRepaymentRescheduleDateToWorkingDayIfItIsHoliday(final AdjustedDateDetailsDTO adjustedDateDetailsDTO,
|
||||
final Holiday holiday) {
|
||||
if (holiday.getReScheduleType().isRescheduleToSpecificDate()) {
|
||||
adjustedDateDetailsDTO.setChangedScheduleDate(holiday.getRepaymentsRescheduledToLocalDate());
|
||||
adjustedDateDetailsDTO.setChangedScheduleDate(holiday.getRepaymentsRescheduledTo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit
|
||||
final Holiday holiday = this.holidayRepository.findOneWithNotFoundDetection(command.entityId());
|
||||
Map<String, Object> changes = holiday.update(command);
|
||||
|
||||
validateInputDates(holiday.getFromDateLocalDate(), holiday.getToDateLocalDate(), holiday.getRepaymentsRescheduledToLocalDate());
|
||||
validateInputDates(holiday.getFromDate(), holiday.getToDate(), holiday.getRepaymentsRescheduledTo());
|
||||
|
||||
if (changes.containsKey(officesParamName)) {
|
||||
final Set<Office> offices = getSelectedOffices(command);
|
||||
|
||||
+5
-5
@@ -85,7 +85,7 @@ public class ApplyHolidaysToLoansTasklet implements Tasklet {
|
||||
applyHolidayToRepaymentScheduleDates(loan, holiday);
|
||||
}
|
||||
loanRepositoryWrapper.save(loans);
|
||||
holiday.processed();
|
||||
holiday.isProcessed();
|
||||
}
|
||||
holidayRepository.save(holidays);
|
||||
return RepeatStatus.FINISHED;
|
||||
@@ -96,7 +96,7 @@ public class ApplyHolidaysToLoansTasklet implements Tasklet {
|
||||
if (holiday.getReScheduleType().isResheduleToNextRepaymentDate()) {
|
||||
adjustedRescheduleToDate = getNextRepaymentDate(loan, holiday);
|
||||
} else {
|
||||
adjustedRescheduleToDate = holiday.getRepaymentsRescheduledToLocalDate();
|
||||
adjustedRescheduleToDate = holiday.getRepaymentsRescheduledTo();
|
||||
}
|
||||
|
||||
if (isRepaymentScheduleAdjustmentNeeded(adjustedRescheduleToDate)) {
|
||||
@@ -111,7 +111,7 @@ public class ApplyHolidaysToLoansTasklet implements Tasklet {
|
||||
|
||||
private void adjustRepaymentSchedules(Loan loan, Holiday holiday, LocalDate adjustedRescheduleToDate) {
|
||||
final DefaultScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator();
|
||||
ScheduleGeneratorDTO scheduleGeneratorDTO = loanUtilService.buildScheduleGeneratorDTO(loan, holiday.getFromDateLocalDate());
|
||||
ScheduleGeneratorDTO scheduleGeneratorDTO = loanUtilService.buildScheduleGeneratorDTO(loan, holiday.getFromDate());
|
||||
final LoanApplicationTerms loanApplicationTerms = loan.constructLoanApplicationTerms(scheduleGeneratorDTO);
|
||||
|
||||
// first repayment's from date is same as disbursement date.
|
||||
@@ -129,7 +129,7 @@ public class ApplyHolidaysToLoansTasklet implements Tasklet {
|
||||
loanRepaymentScheduleInstallment.updateFromDate(tmpFromDate);
|
||||
}
|
||||
|
||||
if (oldDueDate.equals(holiday.getFromDateLocalDate()) || oldDueDate.isAfter(holiday.getFromDateLocalDate())) {
|
||||
if (oldDueDate.equals(holiday.getFromDate()) || oldDueDate.isAfter(holiday.getFromDate())) {
|
||||
// FIXME: AA do we need to apply non-working days.
|
||||
// Assuming holiday's repayment reschedule to date cannot be
|
||||
// created on a non-working day.
|
||||
@@ -144,7 +144,7 @@ public class ApplyHolidaysToLoansTasklet implements Tasklet {
|
||||
|
||||
private LocalDate getNextRepaymentDate(Loan loan, Holiday holiday) {
|
||||
LocalDate adjustedRescheduleToDate = null;
|
||||
final LocalDate rescheduleToDate = holiday.getToDateLocalDate();
|
||||
final LocalDate rescheduleToDate = holiday.getToDate();
|
||||
for (final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment : loan.getRepaymentScheduleInstallments()) {
|
||||
if (rescheduleToDate.isEqual(loanRepaymentScheduleInstallment.getDueDate())) {
|
||||
adjustedRescheduleToDate = rescheduleToDate;
|
||||
|
||||
Reference in New Issue
Block a user