Auditor fix - Detached Auditor entity was not persisted during cascade persisting
This commit is contained in:
committed by
Arnold Gálovics
parent
83dcc4413b
commit
ad4fa563de
+1
-2
@@ -25,7 +25,6 @@ import org.apache.fineract.infrastructure.core.persistence.DatabaseSelectingPers
|
|||||||
import org.apache.fineract.infrastructure.core.persistence.ExtendedJpaTransactionManager;
|
import org.apache.fineract.infrastructure.core.persistence.ExtendedJpaTransactionManager;
|
||||||
import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
|
import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
|
||||||
import org.apache.fineract.infrastructure.core.service.database.DatabaseTypeResolver;
|
import org.apache.fineract.infrastructure.core.service.database.DatabaseTypeResolver;
|
||||||
import org.apache.fineract.useradministration.domain.AppUser;
|
|
||||||
import org.eclipse.persistence.config.PersistenceUnitProperties;
|
import org.eclipse.persistence.config.PersistenceUnitProperties;
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilderCustomizer;
|
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilderCustomizer;
|
||||||
@@ -96,7 +95,7 @@ public class JPAConfig extends JpaBaseConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AuditorAware<AppUser> auditorAware() {
|
public AuditorAware<Long> auditorAware() {
|
||||||
return new AuditorAwareImpl();
|
return new AuditorAwareImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-15
@@ -22,13 +22,9 @@ import java.time.Instant;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import org.apache.fineract.useradministration.domain.AppUser;
|
|
||||||
import org.springframework.data.domain.Auditable;
|
import org.springframework.data.domain.Auditable;
|
||||||
import org.springframework.data.jpa.domain.AbstractAuditable;
|
import org.springframework.data.jpa.domain.AbstractAuditable;
|
||||||
|
|
||||||
@@ -44,33 +40,31 @@ import org.springframework.data.jpa.domain.AbstractAuditable;
|
|||||||
* the type of the auditing type's identifier
|
* the type of the auditing type's identifier
|
||||||
*/
|
*/
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public abstract class AbstractAuditableCustom extends AbstractPersistableCustom implements Auditable<AppUser, Long, Instant> {
|
public abstract class AbstractAuditableCustom extends AbstractPersistableCustom implements Auditable<Long, Long, Instant> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 141481953116476081L;
|
private static final long serialVersionUID = 141481953116476081L;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@Column(name = "createdby_id")
|
||||||
@JoinColumn(name = "createdby_id")
|
private Long createdBy;
|
||||||
private AppUser createdBy;
|
|
||||||
|
|
||||||
@Column(name = "created_date")
|
@Column(name = "created_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
private Date createdDate;
|
private Date createdDate;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@Column(name = "lastmodifiedby_id")
|
||||||
@JoinColumn(name = "lastmodifiedby_id")
|
private Long lastModifiedBy;
|
||||||
private AppUser lastModifiedBy;
|
|
||||||
|
|
||||||
@Column(name = "lastmodified_date")
|
@Column(name = "lastmodified_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
private Date lastModifiedDate;
|
private Date lastModifiedDate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<AppUser> getCreatedBy() {
|
public Optional<Long> getCreatedBy() {
|
||||||
return Optional.ofNullable(this.createdBy);
|
return Optional.ofNullable(this.createdBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCreatedBy(final AppUser createdBy) {
|
public void setCreatedBy(final Long createdBy) {
|
||||||
this.createdBy = createdBy;
|
this.createdBy = createdBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,12 +79,12 @@ public abstract class AbstractAuditableCustom extends AbstractPersistableCustom
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<AppUser> getLastModifiedBy() {
|
public Optional<Long> getLastModifiedBy() {
|
||||||
return Optional.ofNullable(this.lastModifiedBy);
|
return Optional.ofNullable(this.lastModifiedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLastModifiedBy(final AppUser lastModifiedBy) {
|
public void setLastModifiedBy(final Long lastModifiedBy) {
|
||||||
this.lastModifiedBy = lastModifiedBy;
|
this.lastModifiedBy = lastModifiedBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -27,29 +27,29 @@ import org.springframework.security.core.Authentication;
|
|||||||
import org.springframework.security.core.context.SecurityContext;
|
import org.springframework.security.core.context.SecurityContext;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
|
||||||
public class AuditorAwareImpl implements AuditorAware<AppUser> {
|
public class AuditorAwareImpl implements AuditorAware<Long> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AppUserRepository userRepository;
|
private AppUserRepository userRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<AppUser> getCurrentAuditor() {
|
public Optional<Long> getCurrentAuditor() {
|
||||||
Optional<AppUser> currentUser;
|
Optional<Long> currentUserId;
|
||||||
final SecurityContext securityContext = SecurityContextHolder.getContext();
|
final SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||||
if (securityContext != null) {
|
if (securityContext != null) {
|
||||||
final Authentication authentication = securityContext.getAuthentication();
|
final Authentication authentication = securityContext.getAuthentication();
|
||||||
if (authentication != null) {
|
if (authentication != null) {
|
||||||
currentUser = Optional.ofNullable((AppUser) authentication.getPrincipal());
|
currentUserId = Optional.ofNullable(((AppUser) authentication.getPrincipal()).getId());
|
||||||
} else {
|
} else {
|
||||||
currentUser = retrieveSuperUser();
|
currentUserId = retrieveSuperUser();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
currentUser = retrieveSuperUser();
|
currentUserId = retrieveSuperUser();
|
||||||
}
|
}
|
||||||
return currentUser;
|
return currentUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<AppUser> retrieveSuperUser() {
|
private Optional<Long> retrieveSuperUser() {
|
||||||
return this.userRepository.findById(Long.valueOf("1"));
|
return Optional.of(1L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -69,9 +69,9 @@ public class ProvisioningCriteria extends AbstractAuditableCustom {
|
|||||||
public ProvisioningCriteria(String criteriaName, AppUser createdBy, ZonedDateTime createdDate, AppUser lastModifiedBy,
|
public ProvisioningCriteria(String criteriaName, AppUser createdBy, ZonedDateTime createdDate, AppUser lastModifiedBy,
|
||||||
ZonedDateTime lastModifiedDate) {
|
ZonedDateTime lastModifiedDate) {
|
||||||
this.criteriaName = criteriaName;
|
this.criteriaName = criteriaName;
|
||||||
setCreatedBy(createdBy);
|
setCreatedBy(createdBy.getId());
|
||||||
setCreatedDate(Instant.ofEpochMilli(createdDate.toInstant().toEpochMilli()));
|
setCreatedDate(Instant.ofEpochMilli(createdDate.toInstant().toEpochMilli()));
|
||||||
setLastModifiedBy(lastModifiedBy);
|
setLastModifiedBy(lastModifiedBy.getId());
|
||||||
setLastModifiedDate(Instant.ofEpochMilli(lastModifiedDate.toInstant().toEpochMilli()));
|
setLastModifiedDate(Instant.ofEpochMilli(lastModifiedDate.toInstant().toEpochMilli()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-9
@@ -31,7 +31,6 @@ import javax.persistence.TemporalType;
|
|||||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||||
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequest;
|
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequest;
|
||||||
import org.apache.fineract.useradministration.domain.AppUser;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "m_loan_repayment_schedule_history")
|
@Table(name = "m_loan_repayment_schedule_history")
|
||||||
@@ -72,13 +71,11 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom {
|
|||||||
@Column(name = "created_date")
|
@Column(name = "created_date")
|
||||||
private Date createdOnDate;
|
private Date createdOnDate;
|
||||||
|
|
||||||
@ManyToOne
|
@Column(name = "createdby_id")
|
||||||
@JoinColumn(name = "createdby_id")
|
private Long createdByUser;
|
||||||
private AppUser createdByUser;
|
|
||||||
|
|
||||||
@ManyToOne
|
@Column(name = "lastmodifiedby_id")
|
||||||
@JoinColumn(name = "lastmodifiedby_id")
|
private Long lastModifiedByUser;
|
||||||
private AppUser lastModifiedByUser;
|
|
||||||
|
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
@Column(name = "lastmodified_date")
|
@Column(name = "lastmodified_date")
|
||||||
@@ -98,7 +95,7 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom {
|
|||||||
private LoanRepaymentScheduleHistory(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest,
|
private LoanRepaymentScheduleHistory(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest,
|
||||||
final Integer installmentNumber, final Date fromDate, final Date dueDate, final BigDecimal principal,
|
final Integer installmentNumber, final Date fromDate, final Date dueDate, final BigDecimal principal,
|
||||||
final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges, final Date createdOnDate,
|
final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges, final Date createdOnDate,
|
||||||
final AppUser createdByUser, final AppUser lastModifiedByUser, final Date lastModifiedOnDate, final Integer version) {
|
final Long createdByUser, final Long lastModifiedByUser, final Date lastModifiedOnDate, final Integer version) {
|
||||||
|
|
||||||
this.loan = loan;
|
this.loan = loan;
|
||||||
this.loanRescheduleRequest = loanRescheduleRequest;
|
this.loanRescheduleRequest = loanRescheduleRequest;
|
||||||
@@ -122,7 +119,7 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom {
|
|||||||
public static LoanRepaymentScheduleHistory instance(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest,
|
public static LoanRepaymentScheduleHistory instance(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest,
|
||||||
final Integer installmentNumber, final Date fromDate, final Date dueDate, final BigDecimal principal,
|
final Integer installmentNumber, final Date fromDate, final Date dueDate, final BigDecimal principal,
|
||||||
final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges, final Date createdOnDate,
|
final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges, final Date createdOnDate,
|
||||||
final AppUser createdByUser, final AppUser lastModifiedByUser, final Date lastModifiedOnDate, final Integer version) {
|
final Long createdByUser, final Long lastModifiedByUser, final Date lastModifiedOnDate, final Integer version) {
|
||||||
|
|
||||||
return new LoanRepaymentScheduleHistory(loan, loanRescheduleRequest, installmentNumber, fromDate, dueDate, principal,
|
return new LoanRepaymentScheduleHistory(loan, loanRescheduleRequest, installmentNumber, fromDate, dueDate, principal,
|
||||||
interestCharged, feeChargesCharged, penaltyCharges, createdOnDate, createdByUser, lastModifiedByUser, lastModifiedOnDate,
|
interestCharged, feeChargesCharged, penaltyCharges, createdOnDate, createdByUser, lastModifiedByUser, lastModifiedOnDate,
|
||||||
|
|||||||
+2
-3
@@ -29,7 +29,6 @@ import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleIns
|
|||||||
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanRepaymentScheduleHistory;
|
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanRepaymentScheduleHistory;
|
||||||
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanRepaymentScheduleHistoryRepository;
|
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanRepaymentScheduleHistoryRepository;
|
||||||
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequest;
|
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequest;
|
||||||
import org.apache.fineract.useradministration.domain.AppUser;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -79,8 +78,8 @@ public class LoanScheduleHistoryWritePlatformServiceImpl implements LoanSchedule
|
|||||||
createdOnDate = Date.from(repaymentScheduleInstallment.getCreatedDate().get()); // NOSONAR
|
createdOnDate = Date.from(repaymentScheduleInstallment.getCreatedDate().get()); // NOSONAR
|
||||||
}
|
}
|
||||||
|
|
||||||
final AppUser createdByUser = repaymentScheduleInstallment.getCreatedBy().orElse(null);
|
final Long createdByUser = repaymentScheduleInstallment.getCreatedBy().orElse(null);
|
||||||
final AppUser lastModifiedByUser = repaymentScheduleInstallment.getLastModifiedBy().orElse(null);
|
final Long lastModifiedByUser = repaymentScheduleInstallment.getLastModifiedBy().orElse(null);
|
||||||
|
|
||||||
Date lastModifiedOnDate = null;
|
Date lastModifiedOnDate = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user