Skip to content

Commit

Permalink
FINERACT-2152: Loan term variations audit fields
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaghy committed Jan 9, 2025
1 parent 095b1a8 commit 9fc4e2f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleType.PROGRESSIVE;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
Expand All @@ -41,13 +40,11 @@
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTermVariations;
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanTermVariationsRepository;
import org.apache.fineract.useradministration.domain.AppUser;
import org.springframework.transaction.annotation.Transactional;

@AllArgsConstructor
Expand Down Expand Up @@ -110,10 +107,6 @@ public CommandProcessingResult updateInterestPause(Long loanId, Long variationId
variation.setTermApplicableFrom(startDate);
variation.setDateValue(endDate);

AppUser currentUser = context.authenticatedUser();
variation.setUpdatedBy(currentUser != null ? currentUser.getId() : null);
variation.setUpdatedOnDate(LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant()));

LoanTermVariations updatedVariation = loanTermVariationsRepository.save(variation);

return new CommandProcessingResultBuilder().withEntityId(updatedVariation.getId())
Expand All @@ -128,10 +121,6 @@ private CommandProcessingResult processInterestPause(Supplier<Loan> loanSupplier

LoanTermVariations variation = new LoanTermVariations(INTEREST_PAUSE.getValue(), startDate, null, endDate, false, loan);

AppUser currentUser = context.authenticatedUser();
variation.setCreatedBy(currentUser != null ? currentUser.getId() : null);
variation.setCreatedOnDate(LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant()));

LoanTermVariations savedVariation = loanTermVariationsRepository.saveAndFlush(variation);

return new CommandProcessingResultBuilder().withEntityId(savedVariation.getId()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@
import jakarta.persistence.Table;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDateTimeCustom;
import org.apache.fineract.portfolio.loanaccount.data.LoanTermVariationsData;
import org.apache.fineract.portfolio.loanproduct.service.LoanEnumerations;

@Entity
@Table(name = "m_loan_term_variations")
public class LoanTermVariations extends AbstractPersistableCustom<Long> {
public class LoanTermVariations extends AbstractAuditableWithUTCDateTimeCustom<Long> {

@ManyToOne(optional = false)
@JoinColumn(name = "loan_id", nullable = false)
Expand All @@ -62,18 +61,6 @@ public class LoanTermVariations extends AbstractPersistableCustom<Long> {
@Column(name = "is_active", nullable = false)
private Boolean isActive;

@Column(name = "created_by")
private Long createdBy;

@Column(name = "created_on_date")
private LocalDateTime createdOnDate;

@Column(name = "updated_by")
private Long updatedBy;

@Column(name = "updated_on_date")
private LocalDateTime updatedOnDate;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private LoanTermVariations parent;
Expand Down Expand Up @@ -183,36 +170,4 @@ public void updateIsActive(final Boolean isActive) {
public void markAsInactive() {
this.isActive = false;
}

public Long getCreatedBy() {
return createdBy;
}

public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}

public LocalDateTime getCreatedOnDate() {
return createdOnDate;
}

public void setCreatedOnDate(LocalDateTime createdOnDate) {
this.createdOnDate = createdOnDate;
}

public Long getUpdatedBy() {
return updatedBy;
}

public void setUpdatedBy(Long updatedBy) {
this.updatedBy = updatedBy;
}

public LocalDateTime getUpdatedOnDate() {
return updatedOnDate;
}

public void setUpdatedOnDate(LocalDateTime updatedOnDate) {
this.updatedOnDate = updatedOnDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,37 @@
</column>
</addColumn>
</changeSet>
<!-- Columns were created with wrong data type, this below fix them! -->
<changeSet id="2" author="fineract" failOnError="false">
<dropColumn tableName="m_loan_term_variations" columnName="created_by"/>
<dropColumn tableName="m_loan_term_variations" columnName="created_on_date"/>
<dropColumn tableName="m_loan_term_variations" columnName="updated_by"/>
<dropColumn tableName="m_loan_term_variations" columnName="updated_on_date"/>
</changeSet>
<changeSet author="fineract" id="3" context="mysql">
<addColumn tableName="m_loan_term_variations">
<column name="created_on_utc" type="DATETIME"/>
<column name="created_by" type="BIGINT"/>
<column name="last_modified_by" type="BIGINT"/>
<column name="last_modified_on_utc" type="DATETIME"/>
</addColumn>
</changeSet>
<changeSet author="fineract" id="4" context="postgresql">
<addColumn tableName="m_loan_term_variations">
<column name="created_on_utc" type="TIMESTAMP WITH TIME ZONE"/>
<column name="created_by" type="BIGINT"/>
<column name="last_modified_by" type="BIGINT"/>
<column name="last_modified_on_utc" type="TIMESTAMP WITH TIME ZONE"/>
</addColumn>
</changeSet>
<changeSet author="fineract" id="5">
<addForeignKeyConstraint baseColumnNames="created_by" baseTableName="m_loan_term_variations"
constraintName="FK_loan_term_variations_created_by" deferrable="false" initiallyDeferred="false"
onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="id"
referencedTableName="m_appuser" validate="true"/>
<addForeignKeyConstraint baseColumnNames="last_modified_by" baseTableName="m_loan_term_variations"
constraintName="FK_loan_term_variations_last_modified_by" deferrable="false" initiallyDeferred="false"
onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="id"
referencedTableName="m_appuser" validate="true"/>
</changeSet>
</databaseChangeLog>

0 comments on commit 9fc4e2f

Please sign in to comment.