diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/domain/GLClosure.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/domain/GLClosure.java index f1626ef40..1ed254214 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/domain/GLClosure.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/domain/GLClosure.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.accounting.closure.domain; -import java.util.Date; +import java.time.LocalDate; import java.util.LinkedHashMap; import java.util.Map; import javax.persistence.Column; @@ -26,8 +26,6 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.accounting.closure.api.GLClosureJsonInputParams; @@ -48,8 +46,7 @@ public class GLClosure extends AbstractAuditableCustom { private boolean deleted = true; @Column(name = "closing_date") - @Temporal(TemporalType.DATE) - private Date closingDate; + private LocalDate closingDate; @Column(name = "comments", nullable = true, length = 500) private String comments; @@ -58,7 +55,7 @@ public class GLClosure extends AbstractAuditableCustom { // } - public GLClosure(final Office office, final Date closingDate, final String comments) { + public GLClosure(final Office office, final LocalDate closingDate, final String comments) { this.office = office; this.deleted = false; this.closingDate = closingDate; @@ -69,7 +66,7 @@ public class GLClosure extends AbstractAuditableCustom { } public static GLClosure fromJson(final Office office, final JsonCommand command) { - final Date closingDate = command.dateValueOfParameterNamed(GLClosureJsonInputParams.CLOSING_DATE.getValue()); + final LocalDate closingDate = command.localDateValueOfParameterNamed(GLClosureJsonInputParams.CLOSING_DATE.getValue()); final String comments = command.stringValueOfParameterNamed(GLClosureJsonInputParams.COMMENTS.getValue()); return new GLClosure(office, closingDate, comments); } @@ -92,7 +89,7 @@ public class GLClosure extends AbstractAuditableCustom { } } - public Date getClosingDate() { + public LocalDate getClosingDate() { return this.closingDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/exception/GLClosureInvalidDeleteException.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/exception/GLClosureInvalidDeleteException.java index 53671463d..3ead13eb4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/exception/GLClosureInvalidDeleteException.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/exception/GLClosureInvalidDeleteException.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.accounting.closure.exception; -import java.util.Date; +import java.time.LocalDate; import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; /** @@ -26,7 +26,7 @@ import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainR */ public class GLClosureInvalidDeleteException extends AbstractPlatformDomainRuleException { - public GLClosureInvalidDeleteException(final Long officeId, final String officeName, final Date latestclosureDate) { + public GLClosureInvalidDeleteException(final Long officeId, final String officeName, final LocalDate latestclosureDate) { super("error.msg.glclosure.invalid.delete", "The latest closure for office with Id " + officeId + " and name " + officeName + " is on " + latestclosureDate.toString() + ", please delete this closure first", latestclosureDate); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/exception/GLClosureInvalidException.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/exception/GLClosureInvalidException.java index 4d6c4dd2b..e581c3e3d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/exception/GLClosureInvalidException.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/exception/GLClosureInvalidException.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.accounting.closure.exception; -import java.util.Date; +import java.time.LocalDate; import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; /** @@ -50,7 +50,7 @@ public class GLClosureInvalidException extends AbstractPlatformDomainRuleExcepti } } - public GLClosureInvalidException(final GlClosureInvalidReason reason, final Date date) { + public GLClosureInvalidException(final GlClosureInvalidReason reason, final LocalDate date) { super(reason.errorCode(), reason.errorMessage(), date); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java index ee85dde8e..44541cc4c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java @@ -19,7 +19,6 @@ package org.apache.fineract.accounting.closure.service; import java.time.LocalDate; -import java.util.Date; import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -67,15 +66,15 @@ public class GLClosureWritePlatformServiceJpaRepositoryImpl implements GLClosure final Office office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId); // TODO: Get Tenant specific date // ensure closure date is not in the future - final Date todaysDate = DateUtils.getBusinessDate(); - final Date closureDate = command.dateValueOfParameterNamed(GLClosureJsonInputParams.CLOSING_DATE.getValue()); - if (closureDate.after(todaysDate)) { + final LocalDate todaysDate = DateUtils.getBusinessLocalDate(); + final LocalDate closureDate = command.localDateValueOfParameterNamed(GLClosureJsonInputParams.CLOSING_DATE.getValue()); + if (closureDate.isAfter(todaysDate)) { throw new GLClosureInvalidException(GlClosureInvalidReason.FUTURE_DATE, closureDate); } // shouldn't be before an existing accounting closure final GLClosure latestGLClosure = this.glClosureRepository.getLatestGLClosureByBranch(officeId); if (latestGLClosure != null) { - if (latestGLClosure.getClosingDate().after(closureDate)) { + if (latestGLClosure.getClosingDate().isAfter(closureDate)) { throw new GLClosureInvalidException(GlClosureInvalidReason.ACCOUNTING_CLOSED, latestGLClosure.getClosingDate()); } } @@ -121,9 +120,9 @@ public class GLClosureWritePlatformServiceJpaRepositoryImpl implements GLClosure /** * check if any closures are present for this branch at a later date than this closure date **/ - final Date closureDate = glClosure.getClosingDate(); + final LocalDate closureDate = glClosure.getClosingDate(); final GLClosure latestGLClosure = this.glClosureRepository.getLatestGLClosureByBranch(glClosure.getOffice().getId()); - if (latestGLClosure.getClosingDate().after(closureDate)) { + if (latestGLClosure.getClosingDate().isAfter(closureDate)) { throw new GLClosureInvalidDeleteException(latestGLClosure.getOffice().getId(), latestGLClosure.getOffice().getName(), latestGLClosure.getClosingDate()); } @@ -141,8 +140,7 @@ public class GLClosureWritePlatformServiceJpaRepositoryImpl implements GLClosure private void handleGLClosureIntegrityIssues(final JsonCommand command, final Throwable realCause, NonTransientDataAccessException dve) { if (realCause.getMessage().contains("office_id_closing_date")) { throw new GLClosureDuplicateException(command.longValueOfParameterNamed(GLClosureJsonInputParams.OFFICE_ID.getValue()), - LocalDate.ofInstant(command.dateValueOfParameterNamed(GLClosureJsonInputParams.CLOSING_DATE.getValue()).toInstant(), - DateUtils.getDateTimeZoneOfTenant())); + command.localDateValueOfParameterNamed(GLClosureJsonInputParams.CLOSING_DATE.getValue())); } log.error("Error occured.", dve); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/TrialBalance.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/TrialBalance.java index f74f35e9a..ba2f2ca10 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/TrialBalance.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/TrialBalance.java @@ -20,13 +20,11 @@ package org.apache.fineract.accounting.glaccount.domain; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @Entity @@ -43,23 +41,21 @@ public class TrialBalance extends AbstractPersistableCustom { private BigDecimal amount; @Column(name = "entry_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date entryDate; + private LocalDate entryDate; @Column(name = "created_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date transactionDate; + private LocalDate transactionDate; @Column(name = "closing_balance", nullable = false) private BigDecimal closingBalance; - public static TrialBalance getInstance(final Long officeId, final Long glAccountId, final BigDecimal amount, final Date entryDate, - final Date transactionDate) { + public static TrialBalance getInstance(final Long officeId, final Long glAccountId, final BigDecimal amount, final LocalDate entryDate, + final LocalDate transactionDate) { return new TrialBalance(officeId, glAccountId, amount, entryDate, transactionDate); } - private TrialBalance(final Long officeId, final Long glAccountId, final BigDecimal amount, final Date entryDate, - final Date transactionDate) { + private TrialBalance(final Long officeId, final Long glAccountId, final BigDecimal amount, final LocalDate entryDate, + final LocalDate transactionDate) { this.officeId = officeId; this.glAccountId = glAccountId; this.amount = amount; @@ -73,7 +69,7 @@ public class TrialBalance extends AbstractPersistableCustom { return officeId; } - public Date getTransactionDate() { + public LocalDate getTransactionDate() { return transactionDate; } @@ -85,7 +81,7 @@ public class TrialBalance extends AbstractPersistableCustom { this.closingBalance = closingBalance; } - public Date getEntryDate() { + public LocalDate getEntryDate() { return entryDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/DateParam.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/DateParam.java index e9c8373cd..d249f26d7 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/DateParam.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/DateParam.java @@ -19,8 +19,6 @@ package org.apache.fineract.accounting.journalentry.api; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import java.util.Locale; import javax.ws.rs.WebApplicationException; import org.apache.fineract.infrastructure.core.serialization.JsonParserHelper; @@ -38,9 +36,8 @@ public class DateParam { this.dateAsString = dateStr; } - public Date getDate(final String parameterName, final String dateFormat, final String localeAsString) { + public LocalDate getDate(final String parameterName, final String dateFormat, final String localeAsString) { final Locale locale = JsonParserHelper.localeFromString(localeAsString); - final LocalDate localDate = JsonParserHelper.convertFrom(this.dateAsString, parameterName, dateFormat, locale); - return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + return JsonParserHelper.convertFrom(this.dateAsString, parameterName, dateFormat, locale); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntriesApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntriesApiResource.java index 3991e84f3..bb3aeee7b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntriesApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntriesApiResource.java @@ -28,8 +28,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import java.io.InputStream; +import java.time.LocalDate; import java.util.Arrays; -import java.util.Date; import java.util.HashSet; import java.util.Set; import javax.ws.rs.Consumes; @@ -126,11 +126,11 @@ public class JournalEntriesApiResource { this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission); - Date fromDate = null; + LocalDate fromDate = null; if (fromDateParam != null) { fromDate = fromDateParam.getDate("fromDate", dateFormat, locale); } - Date toDate = null; + LocalDate toDate = null; if (toDateParam != null) { toDate = toDateParam.getDate("toDate", dateFormat, locale); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/ClientTransactionDTO.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/ClientTransactionDTO.java index 263d142a4..d80ca2d11 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/ClientTransactionDTO.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/ClientTransactionDTO.java @@ -19,7 +19,7 @@ package org.apache.fineract.accounting.journalentry.data; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -35,7 +35,7 @@ public class ClientTransactionDTO { private final Long paymentTypeId; private final Long transactionId; - private final Date transactionDate; + private final LocalDate transactionDate; private final EnumOptionData transactionType; private final String currencyCode; diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/LoanTransactionDTO.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/LoanTransactionDTO.java index 4d07de2df..5cfc02b21 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/LoanTransactionDTO.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/LoanTransactionDTO.java @@ -19,7 +19,7 @@ package org.apache.fineract.accounting.journalentry.data; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -33,7 +33,7 @@ public class LoanTransactionDTO { private final Long officeId; private final Long paymentTypeId; private final String transactionId; - private final Date transactionDate; + private final LocalDate transactionDate; private final LoanTransactionEnumData transactionType; private final BigDecimal amount; diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/SavingsTransactionDTO.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/SavingsTransactionDTO.java index 95042852d..acbcb164c 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/SavingsTransactionDTO.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/SavingsTransactionDTO.java @@ -19,7 +19,7 @@ package org.apache.fineract.accounting.journalentry.data; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -32,7 +32,7 @@ public class SavingsTransactionDTO { private final Long officeId; private final Long paymentTypeId; private final String transactionId; - private final Date transactionDate; + private final LocalDate transactionDate; private final SavingsAccountTransactionEnumData transactionType; private final BigDecimal amount; diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/SharesTransactionDTO.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/SharesTransactionDTO.java index 06aac0311..fa571a3b8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/SharesTransactionDTO.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/SharesTransactionDTO.java @@ -19,7 +19,7 @@ package org.apache.fineract.accounting.journalentry.data; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -32,7 +32,7 @@ public class SharesTransactionDTO { private final Long officeId; private final Long paymentTypeId; private final String transactionId; - private final Date transactionDate; + private final LocalDate transactionDate; private final ShareAccountTransactionEnumData transactionType; private final ShareAccountTransactionEnumData transactionStatus; diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntry.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntry.java index 78f82ce14..b207954ad 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntry.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntry.java @@ -19,15 +19,13 @@ package org.apache.fineract.accounting.journalentry.domain; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.accounting.glaccount.domain.GLAccount; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; @@ -85,8 +83,7 @@ public class JournalEntry extends AbstractAuditableCustom { private boolean manualEntry = false; @Column(name = "entry_date") - @Temporal(TemporalType.DATE) - private Date transactionDate; + private LocalDate transactionDate; @Column(name = "type_enum", nullable = false) private Integer type; @@ -107,7 +104,7 @@ public class JournalEntry extends AbstractAuditableCustom { private String referenceNumber; public static JournalEntry createNew(final Office office, final PaymentDetail paymentDetail, final GLAccount glAccount, - final String currencyCode, final String transactionId, final boolean manualEntry, final Date transactionDate, + final String currencyCode, final String transactionId, final boolean manualEntry, final LocalDate transactionDate, final JournalEntryType journalEntryType, final BigDecimal amount, final String description, final Integer entityType, final Long entityId, final String referenceNumber, final LoanTransaction loanTransaction, final SavingsAccountTransaction savingsTransaction, final ClientTransaction clientTransaction, Long shareTransactionId) { @@ -121,8 +118,8 @@ public class JournalEntry extends AbstractAuditableCustom { } public JournalEntry(final Office office, final PaymentDetail paymentDetail, final GLAccount glAccount, final String currencyCode, - final String transactionId, final boolean manualEntry, final Date transactionDate, final Integer type, final BigDecimal amount, - final String description, final Integer entityType, final Long entityId, final String referenceNumber, + final String transactionId, final boolean manualEntry, final LocalDate transactionDate, final Integer type, + final BigDecimal amount, final String description, final Integer entityType, final Long entityId, final String referenceNumber, final LoanTransaction loanTransaction, final SavingsAccountTransaction savingsTransaction, final ClientTransaction clientTransaction, final Long shareTransactionId) { this.office = office; @@ -162,7 +159,7 @@ public class JournalEntry extends AbstractAuditableCustom { return this.glAccount; } - public Date getTransactionDate() { + public LocalDate getTransactionDate() { return this.transactionDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/exception/JournalEntryInvalidException.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/exception/JournalEntryInvalidException.java index 325b304fc..7543bde54 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/exception/JournalEntryInvalidException.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/exception/JournalEntryInvalidException.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.accounting.journalentry.exception; -import java.util.Date; +import java.time.LocalDate; import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; /** @@ -76,7 +76,7 @@ public class JournalEntryInvalidException extends AbstractPlatformDomainRuleExce } } - public JournalEntryInvalidException(final GlJournalEntryInvalidReason reason, final Date date, final String accountName, + public JournalEntryInvalidException(final GlJournalEntryInvalidReason reason, final LocalDate date, final String accountName, final String accountGLCode) { super(reason.errorCode(), reason.errorMessage(), date, accountName, accountGLCode); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccountingProcessorHelper.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccountingProcessorHelper.java index b56c49095..45e3a3a4f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccountingProcessorHelper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccountingProcessorHelper.java @@ -20,9 +20,7 @@ package org.apache.fineract.accounting.journalentry.service; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; -import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -116,7 +114,7 @@ public class AccountingProcessorHelper { for (final Map map : newTransactionsMap) { final Long transactionOfficeId = (Long) map.get("officeId"); final String transactionId = ((Long) map.get("id")).toString(); - final Date transactionDate = Date.from(((LocalDate) map.get("date")).atStartOfDay(ZoneId.systemDefault()).toInstant()); + final LocalDate transactionDate = ((LocalDate) map.get("date")); final LoanTransactionEnumData transactionType = (LoanTransactionEnumData) map.get("type"); final BigDecimal amount = (BigDecimal) map.get("amount"); final BigDecimal principal = (BigDecimal) map.get("principalPortion"); @@ -183,7 +181,7 @@ public class AccountingProcessorHelper { for (final Map map : newTransactionsMap) { final Long transactionOfficeId = (Long) map.get("officeId"); final String transactionId = ((Long) map.get("id")).toString(); - final Date transactionDate = Date.from(((LocalDate) map.get("date")).atStartOfDay(ZoneId.systemDefault()).toInstant()); + final LocalDate transactionDate = ((LocalDate) map.get("date")); final SavingsAccountTransactionEnumData transactionType = (SavingsAccountTransactionEnumData) map.get("type"); final BigDecimal amount = (BigDecimal) map.get("amount"); final boolean reversed = (Boolean) map.get("reversed"); @@ -252,7 +250,7 @@ public class AccountingProcessorHelper { for (final Map map : newTransactionsMap) { final Long transactionOfficeId = (Long) map.get("officeId"); final String transactionId = ((Long) map.get("id")).toString(); - final Date transactionDate = Date.from(((LocalDate) map.get("date")).atStartOfDay(ZoneId.systemDefault()).toInstant()); + final LocalDate transactionDate = ((LocalDate) map.get("date")); final ShareAccountTransactionEnumData transactionType = (ShareAccountTransactionEnumData) map.get("type"); final ShareAccountTransactionEnumData transactionStatus = (ShareAccountTransactionEnumData) map.get("status"); final BigDecimal amount = (BigDecimal) map.get("amount"); @@ -288,8 +286,7 @@ public class AccountingProcessorHelper { final Long transactionOfficeId = (Long) accountingBridgeData.get("officeId"); final Long clientId = (Long) accountingBridgeData.get("clientId"); final Long transactionId = (Long) accountingBridgeData.get("id"); - final Date transactionDate = Date - .from(((LocalDate) accountingBridgeData.get("date")).atStartOfDay(ZoneId.systemDefault()).toInstant()); + final LocalDate transactionDate = ((LocalDate) accountingBridgeData.get("date")); final EnumOptionData transactionType = (EnumOptionData) accountingBridgeData.get("type"); final BigDecimal amount = (BigDecimal) accountingBridgeData.get("amount"); final boolean reversed = (Boolean) accountingBridgeData.get("reversed"); @@ -343,7 +340,8 @@ public class AccountingProcessorHelper { */ public void createAccrualBasedJournalEntriesAndReversalsForLoan(final Office office, final String currencyCode, final Integer accountTypeToBeDebited, final Integer accountTypeToBeCredited, final Long loanProductId, final Long paymentTypeId, - final Long loanId, final String transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal) { + final Long loanId, final String transactionId, final LocalDate transactionDate, final BigDecimal amount, + final Boolean isReversal) { int accountTypeToDebitId = accountTypeToBeDebited; int accountTypeToCreditId = accountTypeToBeCredited; // reverse debits and credits for reversals @@ -385,7 +383,7 @@ public class AccountingProcessorHelper { */ public void createAccrualBasedJournalEntriesAndReversalsForLoanCharges(final Office office, final String currencyCode, final Integer accountTypeToBeDebited, final Integer accountTypeToBeCredited, final Long loanProductId, final Long loanId, - final String transactionId, final Date transactionDate, final BigDecimal totalAmount, final Boolean isReversal, + final String transactionId, final LocalDate transactionDate, final BigDecimal totalAmount, final Boolean isReversal, final List chargePaymentDTOs) { GLAccount receivableAccount = getLinkedGLAccountForLoanCharges(loanProductId, accountTypeToBeDebited, null); @@ -446,8 +444,8 @@ public class AccountingProcessorHelper { */ public void createCashBasedJournalEntriesAndReversalsForSavings(final Office office, final String currencyCode, final Integer accountTypeToBeDebited, final Integer accountTypeToBeCredited, final Long savingsProductId, - final Long paymentTypeId, final Long loanId, final String transactionId, final Date transactionDate, final BigDecimal amount, - final Boolean isReversal) { + final Long paymentTypeId, final Long loanId, final String transactionId, final LocalDate transactionDate, + final BigDecimal amount, final Boolean isReversal) { int accountTypeToDebitId = accountTypeToBeDebited; int accountTypeToCreditId = accountTypeToBeCredited; // reverse debits and credits for reversals @@ -479,7 +477,8 @@ public class AccountingProcessorHelper { */ public void createCashBasedJournalEntriesAndReversalsForLoan(final Office office, final String currencyCode, final Integer accountTypeToBeDebited, final Integer accountTypeToBeCredited, final Long loanProductId, final Long paymentTypeId, - final Long loanId, final String transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal) { + final Long loanId, final String transactionId, final LocalDate transactionDate, final BigDecimal amount, + final Boolean isReversal) { int accountTypeToDebitId = accountTypeToBeDebited; int accountTypeToCreditId = accountTypeToBeCredited; // reverse debits and credits for reversals @@ -493,7 +492,7 @@ public class AccountingProcessorHelper { public void createCreditJournalEntryOrReversalForLoan(final Office office, final String currencyCode, final CashAccountsForLoan accountMappingType, final Long loanProductId, final Long paymentTypeId, final Long loanId, - final String transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal) { + final String transactionId, final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) { final int accountMappingTypeId = accountMappingType.getValue(); createCreditJournalEntryOrReversalForLoan(office, currencyCode, accountMappingTypeId, loanProductId, paymentTypeId, loanId, transactionId, transactionDate, amount, isReversal); @@ -501,7 +500,7 @@ public class AccountingProcessorHelper { public void createCreditJournalEntryOrReversalForLoan(final Office office, final String currencyCode, final AccrualAccountsForLoan accountMappingType, final Long loanProductId, final Long paymentTypeId, final Long loanId, - final String transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal) { + final String transactionId, final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) { final int accountMappingTypeId = accountMappingType.getValue(); createCreditJournalEntryOrReversalForLoan(office, currencyCode, accountMappingTypeId, loanProductId, paymentTypeId, loanId, transactionId, transactionDate, amount, isReversal); @@ -511,14 +510,13 @@ public class AccountingProcessorHelper { * @param latestGLClosure * @param transactionDate */ - public void checkForBranchClosures(final GLClosure latestGLClosure, final Date transactionDate) { + public void checkForBranchClosures(final GLClosure latestGLClosure, final LocalDate transactionDate) { /** * check if an accounting closure has happened for this branch after the transaction Date **/ if (latestGLClosure != null) { - if (latestGLClosure.getClosingDate().after(transactionDate) || latestGLClosure.getClosingDate().compareTo(transactionDate) == 0 - ? Boolean.TRUE - : Boolean.FALSE) { + if (latestGLClosure.getClosingDate().isAfter(transactionDate) + || latestGLClosure.getClosingDate().compareTo(transactionDate) == 0 ? Boolean.TRUE : Boolean.FALSE) { throw new JournalEntryInvalidException(GlJournalEntryInvalidReason.ACCOUNTING_CLOSED, latestGLClosure.getClosingDate(), null, null); } @@ -535,7 +533,7 @@ public class AccountingProcessorHelper { private void createJournalEntriesForLoan(final Office office, final String currencyCode, final int accountTypeToDebitId, final int accountTypeToCreditId, final Long loanProductId, final Long paymentTypeId, final Long loanId, - final String transactionId, final Date transactionDate, final BigDecimal amount) { + final String transactionId, final LocalDate transactionDate, final BigDecimal amount) { final GLAccount debitAccount = getLinkedGLAccountForLoanProduct(loanProductId, accountTypeToDebitId, paymentTypeId); final GLAccount creditAccount = getLinkedGLAccountForLoanProduct(loanProductId, accountTypeToCreditId, paymentTypeId); createDebitJournalEntryForLoan(office, currencyCode, debitAccount, loanId, transactionId, transactionDate, amount); @@ -544,7 +542,7 @@ public class AccountingProcessorHelper { private void createJournalEntriesForSavings(final Office office, final String currencyCode, final int accountTypeToDebitId, final int accountTypeToCreditId, final Long savingsProductId, final Long paymentTypeId, final Long savingsId, - final String transactionId, final Date transactionDate, final BigDecimal amount) { + final String transactionId, final LocalDate transactionDate, final BigDecimal amount) { final GLAccount debitAccount = getLinkedGLAccountForSavingsProduct(savingsProductId, accountTypeToDebitId, paymentTypeId); final GLAccount creditAccount = getLinkedGLAccountForSavingsProduct(savingsProductId, accountTypeToCreditId, paymentTypeId); createDebitJournalEntryForSavings(office, currencyCode, debitAccount, savingsId, transactionId, transactionDate, amount); @@ -574,7 +572,7 @@ public class AccountingProcessorHelper { public void createCashBasedJournalEntriesAndReversalsForSavingsTax(final Office office, final String currencyCode, final CashAccountsForSavings accountTypeToBeDebited, final CashAccountsForSavings accountTypeToBeCredited, final Long savingsProductId, final Long paymentTypeId, final Long savingsId, final String transactionId, - final Date transactionDate, final BigDecimal amount, final Boolean isReversal, final List taxDetails) { + final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal, final List taxDetails) { for (TaxPaymentDTO taxPaymentDTO : taxDetails) { if (taxPaymentDTO.getAmount() != null) { @@ -594,7 +592,7 @@ public class AccountingProcessorHelper { public void createCashBasedDebitJournalEntriesAndReversalsForSavings(final Office office, final String currencyCode, final Integer accountTypeToBeDebited, final Long savingsProductId, final Long paymentTypeId, final Long savingsId, - final String transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal) { + final String transactionId, final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) { // reverse debits and credits for reversals if (isReversal) { createCreditJournalEntriesForSavings(office, currencyCode, accountTypeToBeDebited, savingsProductId, paymentTypeId, savingsId, @@ -607,7 +605,7 @@ public class AccountingProcessorHelper { public void createCashBasedCreditJournalEntriesAndReversalsForSavings(final Office office, final String currencyCode, final Integer accountTypeToBeCredited, final Long savingsProductId, final Long paymentTypeId, final Long savingsId, - final String transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal) { + final String transactionId, final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) { // reverse debits and credits for reversals if (isReversal) { createDebitJournalEntriesForSavings(office, currencyCode, accountTypeToBeCredited, savingsProductId, paymentTypeId, savingsId, @@ -619,7 +617,7 @@ public class AccountingProcessorHelper { } public void createCashBasedDebitJournalEntriesAndReversalsForSavings(final Office office, final String currencyCode, - final Long debitAccountId, final Long savingsId, final String transactionId, final Date transactionDate, + final Long debitAccountId, final Long savingsId, final String transactionId, final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) { // reverse debits and credits for reversals final GLAccount debitAccount = getGLAccountById(debitAccountId); @@ -631,7 +629,7 @@ public class AccountingProcessorHelper { } public void createCashBasedCreditJournalEntriesAndReversalsForSavings(final Office office, final String currencyCode, - final Long creditAccountId, final Long savingsId, final String transactionId, final Date transactionDate, + final Long creditAccountId, final Long savingsId, final String transactionId, final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) { // reverse debits and credits for reversals final GLAccount creditAccount = getGLAccountById(creditAccountId); @@ -644,21 +642,21 @@ public class AccountingProcessorHelper { private void createDebitJournalEntriesForSavings(final Office office, final String currencyCode, final int accountTypeToDebitId, final Long savingsProductId, final Long paymentTypeId, final Long savingsId, final String transactionId, - final Date transactionDate, final BigDecimal amount) { + final LocalDate transactionDate, final BigDecimal amount) { final GLAccount debitAccount = getLinkedGLAccountForSavingsProduct(savingsProductId, accountTypeToDebitId, paymentTypeId); createDebitJournalEntryForSavings(office, currencyCode, debitAccount, savingsId, transactionId, transactionDate, amount); } private void createCreditJournalEntriesForSavings(final Office office, final String currencyCode, final int accountTypeToCreditId, final Long savingsProductId, final Long paymentTypeId, final Long savingsId, final String transactionId, - final Date transactionDate, final BigDecimal amount) { + final LocalDate transactionDate, final BigDecimal amount) { final GLAccount creditAccount = getLinkedGLAccountForSavingsProduct(savingsProductId, accountTypeToCreditId, paymentTypeId); createCreditJournalEntryForSavings(office, currencyCode, creditAccount, savingsId, transactionId, transactionDate, amount); } public void createDebitJournalEntryOrReversalForLoan(final Office office, final String currencyCode, final int accountMappingTypeId, - final Long loanProductId, final Long paymentTypeId, final Long loanId, final String transactionId, final Date transactionDate, - final BigDecimal amount, final Boolean isReversal) { + final Long loanProductId, final Long paymentTypeId, final Long loanId, final String transactionId, + final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) { final GLAccount account = getLinkedGLAccountForLoanProduct(loanProductId, accountMappingTypeId, paymentTypeId); if (isReversal) { createCreditJournalEntryForLoan(office, currencyCode, account, loanId, transactionId, transactionDate, amount); @@ -669,7 +667,7 @@ public class AccountingProcessorHelper { public void createCreditJournalEntryOrReversalForLoanCharges(final Office office, final String currencyCode, final int accountMappingTypeId, final Long loanProductId, final Long loanId, final String transactionId, - final Date transactionDate, final BigDecimal totalAmount, final Boolean isReversal, + final LocalDate transactionDate, final BigDecimal totalAmount, final Boolean isReversal, final List chargePaymentDTOs) { /*** * Map to track each account and the net credit to be made for a particular account @@ -744,7 +742,7 @@ public class AccountingProcessorHelper { public void createCashBasedJournalEntriesAndReversalsForSavingsCharges(final Office office, final String currencyCode, final CashAccountsForSavings accountTypeToBeDebited, CashAccountsForSavings accountTypeToBeCredited, final Long savingsProductId, final Long paymentTypeId, final Long loanId, final String transactionId, - final Date transactionDate, final BigDecimal totalAmount, final Boolean isReversal, + final LocalDate transactionDate, final BigDecimal totalAmount, final Boolean isReversal, final List chargePaymentDTOs) { // TODO Vishwas: Remove this validation, as and when appropriate Junit // tests are written for accounting @@ -785,15 +783,15 @@ public class AccountingProcessorHelper { } private void createCreditJournalEntryOrReversalForLoan(final Office office, final String currencyCode, final int accountMappingTypeId, - final Long loanProductId, final Long paymentTypeId, final Long loanId, final String transactionId, final Date transactionDate, - final BigDecimal amount, final Boolean isReversal) { + final Long loanProductId, final Long paymentTypeId, final Long loanId, final String transactionId, + final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) { final GLAccount account = getLinkedGLAccountForLoanProduct(loanProductId, accountMappingTypeId, paymentTypeId); createCreditJournalEntryOrReversalForLoan(office, currencyCode, loanId, transactionId, transactionDate, amount, isReversal, account); } public void createCreditJournalEntryOrReversalForLoan(final Office office, final String currencyCode, final Long loanId, - final String transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal, + final String transactionId, final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal, final GLAccount account) { if (isReversal) { createDebitJournalEntryForLoan(office, currencyCode, account, loanId, transactionId, transactionDate, amount); @@ -803,7 +801,7 @@ public class AccountingProcessorHelper { } private void createCreditJournalEntryForClientPayments(final Office office, final String currencyCode, final GLAccount account, - final Long clientId, final Long transactionId, final Date transactionDate, final BigDecimal amount) { + final Long clientId, final Long transactionId, final LocalDate transactionDate, final BigDecimal amount) { final boolean manualEntry = false; LoanTransaction loanTransaction = null; SavingsAccountTransaction savingsAccountTransaction = null; @@ -822,7 +820,7 @@ public class AccountingProcessorHelper { } private void createCreditJournalEntryForSavings(final Office office, final String currencyCode, final GLAccount account, - final Long savingsId, final String transactionId, final Date transactionDate, final BigDecimal amount) + final Long savingsId, final String transactionId, final LocalDate transactionDate, final BigDecimal amount) throws DataAccessException { final boolean manualEntry = false; LoanTransaction loanTransaction = null; @@ -844,7 +842,7 @@ public class AccountingProcessorHelper { } private void createCreditJournalEntryForLoan(final Office office, final String currencyCode, final GLAccount account, final Long loanId, - final String transactionId, final Date transactionDate, final BigDecimal amount) { + final String transactionId, final LocalDate transactionDate, final BigDecimal amount) { final boolean manualEntry = false; LoanTransaction loanTransaction = null; SavingsAccountTransaction savingsAccountTransaction = null; @@ -863,7 +861,7 @@ public class AccountingProcessorHelper { this.glJournalEntryRepository.saveAndFlush(journalEntry); } - public void createProvisioningDebitJournalEntry(Date transactionDate, Long provisioningentryId, Office office, String currencyCode, + public void createProvisioningDebitJournalEntry(LocalDate transactionDate, Long provisioningentryId, Office office, String currencyCode, GLAccount account, BigDecimal amount) { LoanTransaction loanTransaction = null; SavingsAccountTransaction savingsAccountTransaction = null; @@ -878,8 +876,8 @@ public class AccountingProcessorHelper { this.glJournalEntryRepository.saveAndFlush(journalEntry); } - public void createProvisioningCreditJournalEntry(Date transactionDate, Long provisioningentryId, Office office, String currencyCode, - GLAccount account, BigDecimal amount) { + public void createProvisioningCreditJournalEntry(LocalDate transactionDate, Long provisioningentryId, Office office, + String currencyCode, GLAccount account, BigDecimal amount) { LoanTransaction loanTransaction = null; SavingsAccountTransaction savingsAccountTransaction = null; ClientTransaction clientTransaction = null; @@ -894,7 +892,7 @@ public class AccountingProcessorHelper { } private void createDebitJournalEntryForLoan(final Office office, final String currencyCode, final GLAccount account, final Long loanId, - final String transactionId, final Date transactionDate, final BigDecimal amount) { + final String transactionId, final LocalDate transactionDate, final BigDecimal amount) { final boolean manualEntry = false; LoanTransaction loanTransaction = null; SavingsAccountTransaction savingsAccountTransaction = null; @@ -914,7 +912,7 @@ public class AccountingProcessorHelper { } private void createDebitJournalEntryForSavings(final Office office, final String currencyCode, final GLAccount account, - final Long savingsId, final String transactionId, final Date transactionDate, final BigDecimal amount) { + final Long savingsId, final String transactionId, final LocalDate transactionDate, final BigDecimal amount) { final boolean manualEntry = false; LoanTransaction loanTransaction = null; SavingsAccountTransaction savingsAccountTransaction = null; @@ -935,7 +933,7 @@ public class AccountingProcessorHelper { } private void createDebitJournalEntryForClientPayments(final Office office, final String currencyCode, final GLAccount account, - final Long clientId, final Long transactionId, final Date transactionDate, final BigDecimal amount) { + final Long clientId, final Long transactionId, final LocalDate transactionDate, final BigDecimal amount) { final boolean manualEntry = false; ClientTransaction clientTransaction = null; LoanTransaction loanTransaction = null; @@ -955,7 +953,7 @@ public class AccountingProcessorHelper { public void createJournalEntriesForShares(final Office office, final String currencyCode, final int accountTypeToDebitId, final int accountTypeToCreditId, final Long shareProductId, final Long paymentTypeId, final Long shareAccountId, - final String transactionId, final Date transactionDate, final BigDecimal amount) { + final String transactionId, final LocalDate transactionDate, final BigDecimal amount) { createDebitJournalEntryForShares(office, currencyCode, accountTypeToDebitId, shareProductId, paymentTypeId, shareAccountId, transactionId, transactionDate, amount); createCreditJournalEntryForShares(office, currencyCode, accountTypeToCreditId, shareProductId, paymentTypeId, shareAccountId, @@ -964,14 +962,14 @@ public class AccountingProcessorHelper { public void createDebitJournalEntryForShares(final Office office, final String currencyCode, final int accountTypeToDebitId, final Long shareProductId, final Long paymentTypeId, final Long shareAccountId, final String transactionId, - final Date transactionDate, final BigDecimal amount) { + final LocalDate transactionDate, final BigDecimal amount) { final GLAccount debitAccount = getLinkedGLAccountForShareProduct(shareProductId, accountTypeToDebitId, paymentTypeId); createDebitJournalEntryForShares(office, currencyCode, debitAccount, shareAccountId, transactionId, transactionDate, amount); } public void createCreditJournalEntryForShares(final Office office, final String currencyCode, final int accountTypeToCreditId, final Long shareProductId, final Long paymentTypeId, final Long shareAccountId, final String transactionId, - final Date transactionDate, final BigDecimal amount) { + final LocalDate transactionDate, final BigDecimal amount) { final GLAccount creditAccount = getLinkedGLAccountForShareProduct(shareProductId, accountTypeToCreditId, paymentTypeId); createCreditJournalEntryForShares(office, currencyCode, creditAccount, shareAccountId, transactionId, transactionDate, amount); } @@ -979,7 +977,7 @@ public class AccountingProcessorHelper { public void createCashBasedJournalEntriesForSharesCharges(final Office office, final String currencyCode, final CashAccountsForShares accountTypeToBeDebited, final CashAccountsForShares accountTypeToBeCredited, final Long shareProductId, final Long paymentTypeId, final Long shareAccountId, final String transactionId, - final Date transactionDate, final BigDecimal totalAmount, final List chargePaymentDTOs) { + final LocalDate transactionDate, final BigDecimal totalAmount, final List chargePaymentDTOs) { createDebitJournalEntryForShares(office, currencyCode, accountTypeToBeDebited.getValue(), shareProductId, paymentTypeId, shareAccountId, transactionId, transactionDate, totalAmount); @@ -989,7 +987,7 @@ public class AccountingProcessorHelper { public void createCashBasedJournalEntryForSharesCharges(final Office office, final String currencyCode, final CashAccountsForShares accountTypeToBeCredited, final Long shareProductId, final Long shareAccountId, - final String transactionId, final Date transactionDate, final BigDecimal totalAmount, + final String transactionId, final LocalDate transactionDate, final BigDecimal totalAmount, final List chargePaymentDTOs) { final Map creditDetailsMap = new LinkedHashMap<>(); for (final ChargePaymentDTO chargePaymentDTO : chargePaymentDTOs) { @@ -1021,7 +1019,7 @@ public class AccountingProcessorHelper { public void revertCashBasedJournalEntryForSharesCharges(final Office office, final String currencyCode, final CashAccountsForShares accountTypeToBeCredited, final Long shareProductId, final Long shareAccountId, - final String transactionId, final Date transactionDate, final BigDecimal totalAmount, + final String transactionId, final LocalDate transactionDate, final BigDecimal totalAmount, final List chargePaymentDTOs) { final Map creditDetailsMap = new LinkedHashMap<>(); for (final ChargePaymentDTO chargePaymentDTO : chargePaymentDTOs) { @@ -1052,7 +1050,7 @@ public class AccountingProcessorHelper { } private void createDebitJournalEntryForShares(final Office office, final String currencyCode, final GLAccount account, - final Long shareAccountId, final String transactionId, final Date transactionDate, final BigDecimal amount) { + final Long shareAccountId, final String transactionId, final LocalDate transactionDate, final BigDecimal amount) { final boolean manualEntry = false; LoanTransaction loanTransaction = null; SavingsAccountTransaction savingsAccountTransaction = null; @@ -1071,7 +1069,7 @@ public class AccountingProcessorHelper { } private void createCreditJournalEntryForShares(final Office office, final String currencyCode, final GLAccount account, - final Long shareAccountId, final String transactionId, final Date transactionDate, final BigDecimal amount) { + final Long shareAccountId, final String transactionId, final LocalDate transactionDate, final BigDecimal amount) { final boolean manualEntry = false; LoanTransaction loanTransaction = null; SavingsAccountTransaction savingsAccountTransaction = null; @@ -1253,7 +1251,7 @@ public class AccountingProcessorHelper { } public BigDecimal createCreditJournalEntryOrReversalForClientPayments(final Office office, final String currencyCode, - final Long clientId, final Long transactionId, final Date transactionDate, final Boolean isReversal, + final Long clientId, final Long transactionId, final LocalDate transactionDate, final Boolean isReversal, final List clientChargePaymentDTOs) { /*** * Map to track each account affected and the net credit to be made for a particular account @@ -1289,7 +1287,8 @@ public class AccountingProcessorHelper { } public void createDebitJournalEntryOrReversalForClientChargePayments(final Office office, final String currencyCode, - final Long clientId, final Long transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal) { + final Long clientId, final Long transactionId, final LocalDate transactionDate, final BigDecimal amount, + final Boolean isReversal) { final GLAccount account = financialActivityAccountRepository .findByFinancialActivityTypeWithNotFoundDetection(FinancialActivity.ASSET_FUND_SOURCE.getValue()).getGlAccount(); if (isReversal) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java index ca45de6a7..8b2380297 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java @@ -19,8 +19,8 @@ package org.apache.fineract.accounting.journalentry.service; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -47,7 +47,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess final GLClosure latestGLClosure = this.helper.getLatestClosureByBranch(loanDTO.getOfficeId()); final Office office = this.helper.getOfficeById(loanDTO.getOfficeId()); for (final LoanTransactionDTO loanTransactionDTO : loanDTO.getNewLoanTransactions()) { - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); this.helper.checkForBranchClosures(latestGLClosure, transactionDate); /** Handle Disbursements **/ @@ -116,7 +116,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal disbursalAmount = loanTransactionDTO.getAmount(); final boolean isReversed = loanTransactionDTO.isReversed(); final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -181,7 +181,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal principalAmount = loanTransactionDTO.getPrincipal(); final BigDecimal interestAmount = loanTransactionDTO.getInterest(); final BigDecimal feesAmount = loanTransactionDTO.getFees(); @@ -323,7 +323,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal amount = loanTransactionDTO.getAmount(); final boolean isReversal = loanTransactionDTO.isReversed(); final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -357,7 +357,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal interestAmount = loanTransactionDTO.getInterest(); final BigDecimal feesAmount = loanTransactionDTO.getFees(); final BigDecimal penaltiesAmount = loanTransactionDTO.getPenalties(); @@ -394,7 +394,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal refundAmount = loanTransactionDTO.getAmount(); final boolean isReversal = loanTransactionDTO.isReversed(); final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -419,7 +419,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal refundAmount = loanTransactionDTO.getAmount(); final boolean isReversal = loanTransactionDTO.isReversed(); final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -438,7 +438,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal principalAmount = loanTransactionDTO.getPrincipal(); final BigDecimal interestAmount = loanTransactionDTO.getInterest(); final BigDecimal feesAmount = loanTransactionDTO.getFees(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForClientTransactions.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForClientTransactions.java index b588faad4..0fd47aa49 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForClientTransactions.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForClientTransactions.java @@ -19,7 +19,7 @@ package org.apache.fineract.accounting.journalentry.service; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import lombok.RequiredArgsConstructor; import org.apache.fineract.accounting.closure.domain.GLClosure; import org.apache.fineract.accounting.journalentry.data.ClientTransactionDTO; @@ -36,7 +36,7 @@ public class CashBasedAccountingProcessorForClientTransactions implements Accoun public void createJournalEntriesForClientTransaction(ClientTransactionDTO clientTransactionDTO) { if (clientTransactionDTO.isAccountingEnabled()) { final GLClosure latestGLClosure = this.helper.getLatestClosureByBranch(clientTransactionDTO.getOfficeId()); - final Date transactionDate = clientTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = clientTransactionDTO.getTransactionDate(); final Office office = this.helper.getOfficeById(clientTransactionDTO.getOfficeId()); this.helper.checkForBranchClosures(latestGLClosure, transactionDate); @@ -60,7 +60,7 @@ public class CashBasedAccountingProcessorForClientTransactions implements Accoun // transaction properties final String currencyCode = clientTransactionDTO.getCurrencyCode(); final Long transactionId = clientTransactionDTO.getTransactionId(); - final Date transactionDate = clientTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = clientTransactionDTO.getTransactionDate(); final BigDecimal amount = clientTransactionDTO.getAmount(); final boolean isReversal = clientTransactionDTO.isReversed(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java index a49e80e51..692698abe 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java @@ -19,8 +19,8 @@ package org.apache.fineract.accounting.journalentry.service; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.List; import lombok.RequiredArgsConstructor; import org.apache.fineract.accounting.closure.domain.GLClosure; @@ -46,7 +46,7 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF final Long loanProductId = loanDTO.getLoanProductId(); final String currencyCode = loanDTO.getCurrencyCode(); for (final LoanTransactionDTO loanTransactionDTO : loanDTO.getNewLoanTransactions()) { - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final String transactionId = loanTransactionDTO.getTransactionId(); final Office office = this.helper.getOfficeById(loanTransactionDTO.getOfficeId()); final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -126,7 +126,7 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal disbursalAmount = loanTransactionDTO.getAmount(); final boolean isReversal = loanTransactionDTO.isReversed(); final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -164,7 +164,7 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal refundAmount = loanTransactionDTO.getAmount(); final boolean isReversal = loanTransactionDTO.isReversed(); final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -196,7 +196,7 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal principalAmount = loanTransactionDTO.getPrincipal(); final BigDecimal interestAmount = loanTransactionDTO.getInterest(); final BigDecimal feesAmount = loanTransactionDTO.getFees(); @@ -272,7 +272,7 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal amount = loanTransactionDTO.getAmount(); final boolean isReversal = loanTransactionDTO.isReversed(); final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -302,7 +302,7 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal principalAmount = loanTransactionDTO.getPrincipal(); final boolean isReversal = loanTransactionDTO.isReversed(); // final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -328,7 +328,7 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal refundAmount = loanTransactionDTO.getAmount(); final boolean isReversal = loanTransactionDTO.isReversed(); final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); @@ -346,7 +346,7 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF // transaction properties final String transactionId = loanTransactionDTO.getTransactionId(); - final Date transactionDate = loanTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = loanTransactionDTO.getTransactionDate(); final BigDecimal principalAmount = loanTransactionDTO.getPrincipal(); final BigDecimal interestAmount = loanTransactionDTO.getInterest(); final BigDecimal feesAmount = loanTransactionDTO.getFees(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForSavings.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForSavings.java index 67b409def..89aa71a9c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForSavings.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForSavings.java @@ -19,7 +19,7 @@ package org.apache.fineract.accounting.journalentry.service; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import lombok.RequiredArgsConstructor; import org.apache.fineract.accounting.closure.domain.GLClosure; @@ -44,7 +44,7 @@ public class CashBasedAccountingProcessorForSavings implements AccountingProcess final Long savingsId = savingsDTO.getSavingsId(); final String currencyCode = savingsDTO.getCurrencyCode(); for (final SavingsTransactionDTO savingsTransactionDTO : savingsDTO.getNewSavingsTransactions()) { - final Date transactionDate = savingsTransactionDTO.getTransactionDate(); + final LocalDate transactionDate = savingsTransactionDTO.getTransactionDate(); final String transactionId = savingsTransactionDTO.getTransactionId(); final Office office = this.helper.getOfficeById(savingsTransactionDTO.getOfficeId()); final Long paymentTypeId = savingsTransactionDTO.getPaymentTypeId(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForShares.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForShares.java index dea3e9989..c521b5e50 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForShares.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForShares.java @@ -19,7 +19,7 @@ package org.apache.fineract.accounting.journalentry.service; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import lombok.RequiredArgsConstructor; import org.apache.fineract.accounting.closure.domain.GLClosure; @@ -43,7 +43,7 @@ public class CashBasedAccountingProcessorForShares implements AccountingProcesso final Long shareProductId = sharesDTO.getShareProductId(); final String currencyCode = sharesDTO.getCurrencyCode(); for (SharesTransactionDTO transactionDTO : sharesDTO.getNewTransactions()) { - final Date transactionDate = transactionDTO.getTransactionDate(); + final LocalDate transactionDate = transactionDTO.getTransactionDate(); final String transactionId = transactionDTO.getTransactionId(); final Office office = this.helper.getOfficeById(transactionDTO.getOfficeId()); final Long paymentTypeId = transactionDTO.getPaymentTypeId(); @@ -70,8 +70,8 @@ public class CashBasedAccountingProcessorForShares implements AccountingProcesso } public void createJournalEntriesForRedeem(final Long shareAccountId, final Long shareProductId, final String currencyCode, - final Date transactionDate, final String transactionId, final Office office, final Long paymentTypeId, final BigDecimal amount, - final BigDecimal chargeAmount, final List feePayments) { + final LocalDate transactionDate, final String transactionId, final Office office, final Long paymentTypeId, + final BigDecimal amount, final BigDecimal chargeAmount, final List feePayments) { if (chargeAmount == null || chargeAmount.compareTo(BigDecimal.ZERO) <= 0) { this.helper.createJournalEntriesForShares(office, currencyCode, CashAccountsForShares.SHARES_EQUITY.getValue(), CashAccountsForShares.SHARES_REFERENCE.getValue(), shareProductId, paymentTypeId, shareAccountId, transactionId, @@ -87,7 +87,7 @@ public class CashBasedAccountingProcessorForShares implements AccountingProcesso } public void createJournalEntriesForPurchase(final Long shareAccountId, final Long shareProductId, final String currencyCode, - SharesTransactionDTO transactionDTO, final Date transactionDate, final String transactionId, final Office office, + SharesTransactionDTO transactionDTO, final LocalDate transactionDate, final String transactionId, final Office office, final Long paymentTypeId, final BigDecimal amount, final BigDecimal chargeAmount, final List feePayments) { if (transactionDTO.getTransactionStatus().isApplied()) { if (chargeAmount == null || chargeAmount.compareTo(BigDecimal.ZERO) <= 0) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformService.java index 94a4afb9d..cb867c8c4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformService.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.accounting.journalentry.service; -import java.util.Date; +import java.time.LocalDate; import org.apache.fineract.accounting.journalentry.data.JournalEntryAssociationParametersData; import org.apache.fineract.accounting.journalentry.data.JournalEntryData; import org.apache.fineract.accounting.journalentry.data.OfficeOpeningBalancesData; @@ -29,8 +29,8 @@ public interface JournalEntryReadPlatformService { JournalEntryData retrieveGLJournalEntryById(long glJournalEntryId, JournalEntryAssociationParametersData associationParametersData); - Page retrieveAll(SearchParameters searchParameters, Long glAccountId, Boolean onlyManualEntries, Date fromDate, - Date toDate, String transactionId, Integer entityType, JournalEntryAssociationParametersData associationParametersData); + Page retrieveAll(SearchParameters searchParameters, Long glAccountId, Boolean onlyManualEntries, LocalDate fromDate, + LocalDate toDate, String transactionId, Integer entityType, JournalEntryAssociationParametersData associationParametersData); OfficeOpeningBalancesData retrieveOfficeOpeningBalances(Long officeId, String currencyCode); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java index 8f416831d..d21c14b5e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java @@ -21,12 +21,11 @@ package org.apache.fineract.accounting.journalentry.service; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.List; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; @@ -235,8 +234,8 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat @Override public Page retrieveAll(final SearchParameters searchParameters, final Long glAccountId, - final Boolean onlyManualEntries, final Date fromDate, final Date toDate, final String transactionId, final Integer entityType, - final JournalEntryAssociationParametersData associationParametersData) { + final Boolean onlyManualEntries, final LocalDate fromDate, final LocalDate toDate, final String transactionId, + final Integer entityType, final JournalEntryAssociationParametersData associationParametersData) { GLJournalEntryMapper rm = new GLJournalEntryMapper(associationParametersData); final StringBuilder sqlBuilder = new StringBuilder(200); @@ -290,7 +289,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat } if (fromDate != null || toDate != null) { - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + final DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd").toFormatter(); String fromDateString = null; String toDateString = null; if (fromDate != null && toDate != null) { @@ -492,8 +491,8 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat final String sortOrder = "ASC"; final Integer entityType = null; final Boolean onlyManualEntries = null; - final Date fromDate = null; - final Date toDate = null; + final LocalDate fromDate = null; + final LocalDate toDate = null; final JournalEntryAssociationParametersData associationParametersData = null; final Long loanId = null; final Long savingsId = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java index 5261e89f4..353333e8d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java @@ -21,8 +21,8 @@ package org.apache.fineract.accounting.journalentry.service; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -71,7 +71,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry String dateFinder = "select MIN(je.entry_date) as entityDate from acc_gl_journal_entry je " + "where je.is_running_balance_calculated=false "; try { - Date entityDate = this.jdbcTemplate.queryForObject(dateFinder, Date.class); + LocalDate entityDate = this.jdbcTemplate.queryForObject(dateFinder, LocalDate.class); updateOrganizationRunningBalance(entityDate); } catch (EmptyResultDataAccessException e) { log.debug("No results found for updation of running balance "); @@ -92,7 +92,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry String dateFinder = "select MIN(je.entry_date) as entityDate " + "from acc_gl_journal_entry je " + "where je.is_running_balance_calculated=false and je.office_id=?"; try { - Date entityDate = this.jdbcTemplate.queryForObject(dateFinder, Date.class, officeId); + LocalDate entityDate = this.jdbcTemplate.queryForObject(dateFinder, LocalDate.class, officeId); updateRunningBalance(officeId, entityDate); } catch (EmptyResultDataAccessException e) { log.debug("No results found for updation of office running balance with office id: {}", officeId); @@ -102,7 +102,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry return commandProcessingResultBuilder.build(); } - private void updateOrganizationRunningBalance(Date entityDate) { + private void updateOrganizationRunningBalance(LocalDate entityDate) { Map runningBalanceMap = new HashMap<>(5); Map> officesRunningBalance = new HashMap<>(); @@ -112,7 +112,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry + "group by je.id order by je.entry_date DESC " + sqlGenerator.limit(10000, 0); List> list = jdbcTemplate.queryForList(organizationRunningBalanceQuery, // NOSONAR - new Object[] { entityDate, entityDate }); + entityDate, entityDate); for (Map entries : list) { Long accountId = Long.parseLong(entries.get("accountId").toString()); // Drizzle @@ -137,7 +137,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry + "group by je.id order by je.entry_date DESC " + sqlGenerator.limit(10000, 0); List> officesRunningBalanceList = jdbcTemplate.queryForList(offlineRunningBalanceQuery, // NOSONAR - new Object[] { entityDate, entityDate }); + entityDate, entityDate); for (Map entries : officesRunningBalanceList) { Long accountId = Long.parseLong(entries.get("accountId").toString()); Long officeId = Long.parseLong(entries.get("officeId").toString()); @@ -153,8 +153,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry } } - List entryDatas = jdbcTemplate.query(entryMapper.organizationRunningBalanceSchema(), entryMapper, - new Object[] { entityDate }); + List entryDatas = jdbcTemplate.query(entryMapper.organizationRunningBalanceSchema(), entryMapper, entityDate); if (entryDatas.size() > 0) { // run a batch update of 1000 SQL statements at a time final Integer batchUpdateSize = 1000; @@ -189,7 +188,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry } - private void updateRunningBalance(Long officeId, Date entityDate) { + private void updateRunningBalance(Long officeId, LocalDate entityDate) { Map runningBalanceMap = new HashMap<>(5); final String offlineRunningBalanceQuery = "select je.office_running_balance as runningBalance,je.account_id as accountId from acc_gl_journal_entry je " @@ -198,15 +197,14 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry + "group by je.id order by je.entry_date DESC " + sqlGenerator.limit(10000, 0); List> list = jdbcTemplate.queryForList(offlineRunningBalanceQuery, // NOSONAR - new Object[] { officeId, entityDate, officeId, entityDate }); + officeId, entityDate, officeId, entityDate); for (Map entries : list) { Long accountId = (Long) entries.get("accountId"); if (!runningBalanceMap.containsKey(accountId)) { runningBalanceMap.put(accountId, (BigDecimal) entries.get("runningBalance")); } } - List entryDatas = jdbcTemplate.query(entryMapper.officeRunningBalanceSchema(), entryMapper, - new Object[] { officeId, entityDate }); + List entryDatas = jdbcTemplate.query(entryMapper.officeRunningBalanceSchema(), entryMapper, officeId, entityDate); String[] updateSql = new String[entryDatas.size()]; int i = 0; for (JournalEntryData entryData : entryDatas) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformService.java index bafdcbdcf..0ea9eceb6 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformService.java @@ -18,8 +18,8 @@ */ package org.apache.fineract.accounting.journalentry.service; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.Map; import org.apache.fineract.accounting.provisioning.domain.ProvisioningEntry; import org.apache.fineract.infrastructure.core.api.JsonCommand; @@ -39,12 +39,12 @@ public interface JournalEntryWritePlatformService { CommandProcessingResult defineOpeningBalance(JsonCommand command); - String revertProvisioningJournalEntries(Date reversalTransactionDate, Long entityId, Integer entityType); + String revertProvisioningJournalEntries(LocalDate reversalTransactionDate, Long entityId, Integer entityType); String createProvisioningJournalEntries(ProvisioningEntry entry); void createJournalEntriesForShares(Map accountingBridgeData); - void revertShareAccountJournalEntries(ArrayList transactionId, Date transactionDate); + void revertShareAccountJournalEntries(ArrayList transactionId, LocalDate transactionDate); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java index fdebe070d..66c89e8f5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java @@ -20,10 +20,8 @@ package org.apache.fineract.accounting.journalentry.service; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -130,7 +128,8 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes); /** Set a transaction Id and save these Journal entries **/ - final Date transactionDate = command.dateValueOfParameterNamed(JournalEntryJsonInputParams.TRANSACTION_DATE.getValue()); + final LocalDate transactionDate = command + .localDateValueOfParameterNamed(JournalEntryJsonInputParams.TRANSACTION_DATE.getValue()); final String transactionId = generateTransactionId(officeId); final String referenceNumber = command.stringValueOfParameterNamed(JournalEntryJsonInputParams.REFERENCE_NUMBER.getValue()); @@ -315,10 +314,10 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa // Before reversal validate accounting closure is done for that branch // or not. - final Date journalEntriesTransactionDate = journalEntries.get(0).getTransactionDate(); + final LocalDate journalEntriesTransactionDate = journalEntries.get(0).getTransactionDate(); final GLClosure latestGLClosureByBranch = this.glClosureRepository.getLatestGLClosureByBranch(officeId); if (latestGLClosureByBranch != null) { - if (latestGLClosureByBranch.getClosingDate().after(journalEntriesTransactionDate) + if (latestGLClosureByBranch.getClosingDate().isAfter(journalEntriesTransactionDate) || latestGLClosureByBranch.getClosingDate().compareTo(journalEntriesTransactionDate) == 0 ? Boolean.TRUE : Boolean.FALSE) { final String accountName = null; @@ -358,7 +357,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa } @Override - public String revertProvisioningJournalEntries(final Date reversalTransactionDate, final Long entityId, final Integer entityType) { + public String revertProvisioningJournalEntries(final LocalDate reversalTransactionDate, final Long entityId, final Integer entityType) { List journalEntries = this.glJournalEntryRepository.findProvisioningJournalEntriesByEntityId(entityId, entityType); final String reversalTransactionId = journalEntries.get(0).getTransactionId(); for (final JournalEntry journalEntry : journalEntries) { @@ -435,13 +434,13 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa expenseMap.put(entry.getExpenseAccount(), amount); } } - createJournalEnry(provisioningEntry.getCreatedDate(), provisioningEntry.getId(), key.office, key.currency, liabilityMap, + createJournalEntry(provisioningEntry.getCreatedDate(), provisioningEntry.getId(), key.office, key.currency, liabilityMap, expenseMap); } return "P" + provisioningEntry.getId(); } - private void createJournalEnry(Date transactionDate, Long entryId, Office office, String currencyCode, + private void createJournalEntry(LocalDate transactionDate, Long entryId, Office office, String currencyCode, Map liabilityMap, Map expenseMap) { Set liabilityAccounts = liabilityMap.keySet(); for (GLAccount account : liabilityAccounts) { @@ -519,7 +518,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa } @Override - public void revertShareAccountJournalEntries(final ArrayList transactionIds, final Date transactionDate) { + public void revertShareAccountJournalEntries(final ArrayList transactionIds, final LocalDate transactionDate) { for (Long shareTransactionId : transactionIds) { String transactionId = AccountingProcessorHelper.SHARE_TRANSACTION_IDENTIFIER + shareTransactionId.longValue(); List journalEntries = this.glJournalEntryRepository.findJournalEntries(transactionId, @@ -561,18 +560,17 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa private void validateBusinessRulesForJournalEntries(final JournalEntryCommand command) { /** check if date of Journal entry is valid ***/ final LocalDate entryLocalDate = command.getTransactionDate(); - final Date transactionDate = Date.from(entryLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + final LocalDate transactionDate = entryLocalDate; // shouldn't be in the future - final Date todaysDate = DateUtils.getBusinessDate(); - if (transactionDate.after(todaysDate)) { + final LocalDate todaysDate = DateUtils.getBusinessLocalDate(); + if (transactionDate.isAfter(todaysDate)) { throw new JournalEntryInvalidException(GlJournalEntryInvalidReason.FUTURE_DATE, transactionDate, null, null); } // shouldn't be before an accounting closure final GLClosure latestGLClosure = this.glClosureRepository.getLatestGLClosureByBranch(command.getOfficeId()); if (latestGLClosure != null) { - if (latestGLClosure.getClosingDate().after(transactionDate) || latestGLClosure.getClosingDate().compareTo(transactionDate) == 0 - ? Boolean.TRUE - : Boolean.FALSE) { + if (latestGLClosure.getClosingDate().isAfter(transactionDate) + || latestGLClosure.getClosingDate().compareTo(transactionDate) == 0 ? Boolean.TRUE : Boolean.FALSE) { throw new JournalEntryInvalidException(GlJournalEntryInvalidReason.ACCOUNTING_CLOSED, latestGLClosure.getClosingDate(), null, null); } @@ -591,8 +589,9 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa } private void saveAllDebitOrCreditEntries(final JournalEntryCommand command, final Office office, final PaymentDetail paymentDetail, - final String currencyCode, final Date transactionDate, final SingleDebitOrCreditEntryCommand[] singleDebitOrCreditEntryCommands, - final String transactionId, final JournalEntryType type, final String referenceNumber) { + final String currencyCode, final LocalDate transactionDate, + final SingleDebitOrCreditEntryCommand[] singleDebitOrCreditEntryCommands, final String transactionId, + final JournalEntryType type, final String referenceNumber) { final boolean manualEntry = true; for (final SingleDebitOrCreditEntryCommand singleDebitOrCreditEntryCommand : singleDebitOrCreditEntryCommands) { final GLAccount glAccount = this.glAccountRepository.findById(singleDebitOrCreditEntryCommand.getGlAccountId()) @@ -673,7 +672,8 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa } /** Set a transaction Id and save these Journal entries **/ - final Date transactionDate = command.dateValueOfParameterNamed(JournalEntryJsonInputParams.TRANSACTION_DATE.getValue()); + final LocalDate transactionDate = command + .localDateValueOfParameterNamed(JournalEntryJsonInputParams.TRANSACTION_DATE.getValue()); final String transactionId = generateTransactionId(officeId); saveAllDebitOrCreditOpeningBalanceEntries(journalEntryCommand, office, currencyCode, transactionDate, @@ -691,8 +691,9 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa } private void saveAllDebitOrCreditOpeningBalanceEntries(final JournalEntryCommand command, final Office office, - final String currencyCode, final Date transactionDate, final SingleDebitOrCreditEntryCommand[] singleDebitOrCreditEntryCommands, - final String transactionId, final JournalEntryType type, final Long contraAccountId) { + final String currencyCode, final LocalDate transactionDate, + final SingleDebitOrCreditEntryCommand[] singleDebitOrCreditEntryCommands, final String transactionId, + final JournalEntryType type, final Long contraAccountId) { final boolean manualEntry = true; final GLAccount contraAccount = this.glAccountRepository.findById(contraAccountId) diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/data/ProvisioningEntryData.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/data/ProvisioningEntryData.java index f03628af2..a07f7fbfd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/data/ProvisioningEntryData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/data/ProvisioningEntryData.java @@ -19,8 +19,8 @@ package org.apache.fineract.accounting.provisioning.data; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; @SuppressWarnings("unused") public class ProvisioningEntryData { @@ -33,7 +33,7 @@ public class ProvisioningEntryData { private String createdUser; - Date createdDate; + LocalDate createdDate; Long modifiedById; @@ -48,8 +48,8 @@ public class ProvisioningEntryData { this.id = id; } - public ProvisioningEntryData(Long id, Boolean journalEntry, Long createdById, String createdUser, Date createdDate, Long modifiedById, - String modifiedUser, BigDecimal totalReservedAmount) { + public ProvisioningEntryData(Long id, Boolean journalEntry, Long createdById, String createdUser, LocalDate createdDate, + Long modifiedById, String modifiedUser, BigDecimal totalReservedAmount) { this.id = id; this.journalEntry = journalEntry; this.createdById = createdById; @@ -68,7 +68,7 @@ public class ProvisioningEntryData { return this.id; } - public Date getCreatedDate() { + public LocalDate getCreatedDate() { return this.createdDate; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntry.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntry.java index c981cbb4c..4c8cf0555 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntry.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntry.java @@ -18,8 +18,8 @@ */ package org.apache.fineract.accounting.provisioning.domain; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; @@ -30,8 +30,6 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.useradministration.domain.AppUser; @@ -50,22 +48,20 @@ public class ProvisioningEntry extends AbstractPersistableCustom { private AppUser createdBy; @Column(name = "created_date") - @Temporal(TemporalType.DATE) - private Date createdDate; + private LocalDate createdDate; @OneToOne @JoinColumn(name = "lastmodifiedby_id") private AppUser lastModifiedBy; @Column(name = "lastmodified_date") - @Temporal(TemporalType.DATE) - private Date lastModifiedDate; + private LocalDate lastModifiedDate; protected ProvisioningEntry() { } - public ProvisioningEntry(AppUser createdBy, Date createdDate, AppUser lastModifiedBy, Date lastModifiedDate, + public ProvisioningEntry(AppUser createdBy, LocalDate createdDate, AppUser lastModifiedBy, LocalDate lastModifiedDate, Set provisioningEntries) { this.provisioningEntries = provisioningEntries; this.createdBy = createdBy; @@ -89,7 +85,7 @@ public class ProvisioningEntry extends AbstractPersistableCustom { this.isJournalEntryCreated = bool; } - public Date getCreatedDate() { + public LocalDate getCreatedDate() { return this.createdDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntryRepository.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntryRepository.java index c76eb07e7..760b93f58 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntryRepository.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntryRepository.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.accounting.provisioning.domain; -import java.util.Date; +import java.time.LocalDate; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; @@ -28,7 +28,7 @@ public interface ProvisioningEntryRepository extends JpaRepository retrieveLoanProductsProvisioningData(Date date); + Collection retrieveLoanProductsProvisioningData(LocalDate date); ProvisioningEntryData retrieveProvisioningEntryData(Long entryId); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesReadPlatformServiceImpl.java index 1383fcad3..eac0c64cd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesReadPlatformServiceImpl.java @@ -19,17 +19,18 @@ package org.apache.fineract.accounting.provisioning.service; import java.math.BigDecimal; +import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; -import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.accounting.provisioning.data.LoanProductProvisioningEntryData; import org.apache.fineract.accounting.provisioning.data.ProvisioningEntryData; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.PaginationHelper; import org.apache.fineract.infrastructure.core.service.SearchParameters; @@ -51,11 +52,11 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE private final DatabaseSpecificSQLGenerator sqlGenerator; @Override - public Collection retrieveLoanProductsProvisioningData(Date date) { - String formattedDate = new SimpleDateFormat("yyyy-MM-dd").format(date); + public Collection retrieveLoanProductsProvisioningData(LocalDate date) { + String formattedDate = DateUtils.DEFAULT_DATE_FORMATER.format(date); LoanProductProvisioningEntryMapper mapper = new LoanProductProvisioningEntryMapper(sqlGenerator); final String sql = mapper.schema(); - return this.jdbcTemplate.query(sql, mapper, new Object[] { formattedDate, formattedDate, formattedDate }); + return this.jdbcTemplate.query(sql, mapper, formattedDate, formattedDate, formattedDate); } private static final class LoanProductProvisioningEntryMapper implements RowMapper { @@ -107,8 +108,7 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE public ProvisioningEntryData retrieveProvisioningEntryData(Long entryId) { ProvisioningEntryDataMapperWithSumReserved mapper1 = new ProvisioningEntryDataMapperWithSumReserved(); final String sql = "select" + mapper1.getSchema() + " where entry.id = ? group by entry.id, created.username, modified.username"; - ProvisioningEntryData data = this.jdbcTemplate.queryForObject(sql, mapper1, new Object[] { entryId }); // NOSONAR - return data; + return this.jdbcTemplate.queryForObject(sql, mapper1, entryId); } private static final class ProvisioningEntryDataMapper implements RowMapper { @@ -130,7 +130,8 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE Long modifiedById = rs.getLong("lastmodifiedby_id"); String modifieUser = rs.getString("modifieduser"); BigDecimal totalReservedAmount = null; - return new ProvisioningEntryData(id, journalEntry, createdById, createdUser, createdDate, modifiedById, modifieUser, + LocalDate createdLocalDate = createdDate != null ? createdDate.toLocalDate() : null; + return new ProvisioningEntryData(id, journalEntry, createdById, createdUser, createdLocalDate, modifiedById, modifieUser, totalReservedAmount); } @@ -203,7 +204,8 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE Long modifiedById = rs.getLong("lastmodifiedby_id"); String modifieUser = rs.getString("modifieduser"); BigDecimal totalReservedAmount = rs.getBigDecimal("totalreserved"); - return new ProvisioningEntryData(id, journalEntry, createdById, createdUser, createdDate, modifiedById, modifieUser, + LocalDate createdLocalDate = createdDate != null ? createdDate.toLocalDate() : null; + return new ProvisioningEntryData(id, journalEntry, createdById, createdUser, createdLocalDate, modifiedById, modifieUser, totalReservedAmount); } @@ -239,7 +241,7 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE final String sql1 = "select " + mapper1.getSchema() + " where entry.created_date like ? "; ProvisioningEntryData data = null; try { - data = this.jdbcTemplate.queryForObject(sql1, mapper1, new Object[] { date }); // NOSONAR + data = this.jdbcTemplate.queryForObject(sql1, mapper1, date); // NOSONAR } catch (EmptyResultDataAccessException e) { log.error("Problem occurred in retrieveProvisioningEntryData function", e); } @@ -252,12 +254,12 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE ProvisioningEntryData data = null; LoanProductProvisioningEntryRowMapper mapper = new LoanProductProvisioningEntryRowMapper(); final String sql = "select " + mapper.getSchema() + " where entry.criteria_id = ?"; - Collection entries = this.jdbcTemplate.query(sql, mapper, new Object[] { criteriaId }); // NOSONAR + Collection entries = this.jdbcTemplate.query(sql, mapper, criteriaId); // NOSONAR if (entries != null && entries.size() > 0) { Long entryId = ((LoanProductProvisioningEntryData) entries.toArray()[0]).getHistoryId(); ProvisioningEntryDataMapper mapper1 = new ProvisioningEntryDataMapper(); final String sql1 = "select " + mapper1.getSchema() + " where entry.id = ?"; - data = this.jdbcTemplate.queryForObject(sql1, mapper1, new Object[] { entryId }); // NOSONAR + data = this.jdbcTemplate.queryForObject(sql1, mapper1, entryId); // NOSONAR data.setEntries(entries); } return data; @@ -290,7 +292,8 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE Long modifiedBy = null; String modifiedName = null; BigDecimal totalReservedAmount = null; - return new ProvisioningEntryData(id, Boolean.TRUE, createdBy, createdName, createdDate, modifiedBy, modifiedName, + LocalDate createdLocalDate = createdDate != null ? createdDate.toLocalDate() : null; + return new ProvisioningEntryData(id, Boolean.TRUE, createdBy, createdName, createdLocalDate, modifiedBy, modifiedName, totalReservedAmount); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java index a54e80892..9c01e0ccd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java @@ -20,9 +20,7 @@ package org.apache.fineract.accounting.provisioning.service; import com.google.gson.JsonObject; import java.time.LocalDate; -import java.time.ZoneId; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -111,9 +109,9 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements } private void validateForCreateJournalEntry(ProvisioningEntryData existingEntry, ProvisioningEntry requested) { - Date existingDate = existingEntry.getCreatedDate(); - Date requestedDate = requested.getCreatedDate(); - if (existingDate.after(requestedDate) || existingDate.compareTo(requestedDate) == 0 ? Boolean.TRUE : Boolean.FALSE) { + LocalDate existingDate = existingEntry.getCreatedDate(); + LocalDate requestedDate = requested.getCreatedDate(); + if (existingDate.isAfter(requestedDate) || existingDate.compareTo(requestedDate) == 0 ? Boolean.TRUE : Boolean.FALSE) { throw new ProvisioningJournalEntriesCannotbeCreatedException(existingEntry.getCreatedDate(), requestedDate); } } @@ -127,15 +125,14 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements return bool; } - private Date parseDate(JsonCommand command) { - LocalDate localDate = this.fromApiJsonHelper.extractLocalDateNamed("date", command.parsedJson()); - return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + private LocalDate parseDate(JsonCommand command) { + return this.fromApiJsonHelper.extractLocalDateNamed("date", command.parsedJson()); } @Override @CronTarget(jobName = JobName.GENERATE_LOANLOSS_PROVISIONING) public void generateLoanLossProvisioningAmount() { - Date currentDate = DateUtils.getBusinessDate(); + LocalDate currentDate = DateUtils.getBusinessLocalDate(); boolean addJournalEntries = true; try { Collection criteriaCollection = this.provisioningCriteriaReadPlatformService @@ -156,7 +153,7 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements @Override public CommandProcessingResult createProvisioningEntries(JsonCommand command) { this.fromApiJsonDeserializer.validateForCreate(command.json()); - Date createdDate = parseDate(command); + LocalDate createdDate = parseDate(command); boolean addJournalEntries = isJournalEntriesRequired(command); try { Collection criteriaCollection = this.provisioningCriteriaReadPlatformService @@ -171,14 +168,14 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements } } - private ProvisioningEntry createProvsioningEntry(Date date, boolean addJournalEntries) { + private ProvisioningEntry createProvsioningEntry(LocalDate date, boolean addJournalEntries) { ProvisioningEntry existingEntry = this.provisioningEntryRepository.findByProvisioningEntryDate(date); if (existingEntry != null) { throw new ProvisioningEntryAlreadyCreatedException(existingEntry.getId(), existingEntry.getCreatedDate()); } AppUser currentUser = this.platformSecurityContext.authenticatedUser(); AppUser lastModifiedBy = null; - Date lastModifiedDate = null; + LocalDate lastModifiedDate = null; Set nullEntries = null; ProvisioningEntry requestedEntry = new ProvisioningEntry(currentUser, date, lastModifiedBy, lastModifiedDate, nullEntries); Collection entries = generateLoanProvisioningEntry(requestedEntry, date); @@ -205,7 +202,7 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(requestedEntry.getId()).build(); } - private Collection generateLoanProvisioningEntry(ProvisioningEntry parent, Date date) { + private Collection generateLoanProvisioningEntry(ProvisioningEntry parent, LocalDate date) { Collection entries = this.provisioningEntriesReadPlatformService .retrieveLoanProductsProvisioningData(date); Map provisioningEntries = new HashMap<>(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/exception/AccountingRuleInvalidDeleteException.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/exception/AccountingRuleInvalidDeleteException.java index 4c64dd034..ad649a658 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/exception/AccountingRuleInvalidDeleteException.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/exception/AccountingRuleInvalidDeleteException.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.accounting.rule.exception; -import java.util.Date; +import java.time.LocalDate; import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; /** @@ -26,7 +26,7 @@ import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainR */ public class AccountingRuleInvalidDeleteException extends AbstractPlatformDomainRuleException { - public AccountingRuleInvalidDeleteException(final Long officeId, final String officeName, final Date latestclosureDate) { + public AccountingRuleInvalidDeleteException(final Long officeId, final String officeName, final LocalDate latestclosureDate) { super("error.msg.glclosure.invalid.delete", "The latest closure for office with Id " + officeId + " and name " + officeName + " is on " + latestclosureDate.toString() + ", please delete this closure first", latestclosureDate); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/exception/AccountingRuleInvalidException.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/exception/AccountingRuleInvalidException.java index 5a6d7ef60..8743881bd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/exception/AccountingRuleInvalidException.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/exception/AccountingRuleInvalidException.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.accounting.rule.exception; -import java.util.Date; +import java.time.LocalDate; import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; /** @@ -50,7 +50,7 @@ public class AccountingRuleInvalidException extends AbstractPlatformDomainRuleEx } } - public AccountingRuleInvalidException(final GlClosureInvalidReason reason, final Date date) { + public AccountingRuleInvalidException(final GlClosureInvalidReason reason, final LocalDate date) { super(reason.errorCode(), reason.errorMessage(), date); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBBusinessStep.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBBusinessStep.java index 5513b5a42..9f2494045 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBBusinessStep.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBBusinessStep.java @@ -21,4 +21,6 @@ package org.apache.fineract.cob.loan; import org.apache.fineract.cob.COBBusinessStep; import org.apache.fineract.portfolio.loanaccount.domain.Loan; -public interface LoanCOBBusinessStep extends COBBusinessStep {} +public interface LoanCOBBusinessStep extends COBBusinessStep { + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java b/fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java index 5fe77beae..75a368eb8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java @@ -18,15 +18,13 @@ */ package org.apache.fineract.commands.domain; +import java.time.LocalDateTime; import java.time.ZonedDateTime; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @@ -75,16 +73,14 @@ public class CommandSource extends AbstractPersistableCustom { private AppUser maker; @Column(name = "made_on_date", nullable = false) - @Temporal(TemporalType.TIMESTAMP) - private Date madeOnDate; + private LocalDateTime madeOnDate; @ManyToOne @JoinColumn(name = "checker_id", nullable = true) private AppUser checker; @Column(name = "checked_on_date", nullable = true) - @Temporal(TemporalType.TIMESTAMP) - private Date checkedOnDate; + private LocalDateTime checkedOnDate; @Column(name = "processing_result_enum", nullable = false) private Integer processingResult; @@ -119,7 +115,7 @@ public class CommandSource extends AbstractPersistableCustom { this.subresourceId = subresourceId; this.commandAsJson = commandSerializedAsJson; this.maker = maker; - this.madeOnDate = Date.from(madeOnDateTime.toInstant()); + this.madeOnDate = madeOnDateTime != null ? madeOnDateTime.toLocalDateTime() : null; this.processingResult = CommandProcessingResultType.PROCESSED.getValue(); } @@ -141,13 +137,13 @@ public class CommandSource extends AbstractPersistableCustom { public void markAsChecked(final AppUser checker, final ZonedDateTime checkedOnDate) { this.checker = checker; - this.checkedOnDate = Date.from(checkedOnDate.toInstant()); + this.checkedOnDate = checkedOnDate != null ? checkedOnDate.toLocalDateTime() : null; this.processingResult = CommandProcessingResultType.PROCESSED.getValue(); } public void markAsRejected(final AppUser checker, final ZonedDateTime checkedOnDate) { this.checker = checker; - this.checkedOnDate = Date.from(checkedOnDate.toInstant()); + this.checkedOnDate = checkedOnDate != null ? checkedOnDate.toLocalDateTime() : null; this.processingResult = CommandProcessingResultType.REJECTED.getValue(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocument.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocument.java index a9a83bfd4..7b89b8a53 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocument.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocument.java @@ -19,15 +19,12 @@ package org.apache.fineract.infrastructure.bulkimport.domain; import java.time.LocalDateTime; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.documentmanagement.domain.Document; @@ -41,13 +38,11 @@ public class ImportDocument extends AbstractPersistableCustom { @JoinColumn(name = "document_id") private Document document; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "import_time") - private Date importTime; + private LocalDateTime importTime; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "end_time") - private Date endTime; + private LocalDateTime endTime; @Column(name = "completed", nullable = false) private Boolean completed; @@ -88,8 +83,8 @@ public class ImportDocument extends AbstractPersistableCustom { final Integer entityType, final AppUser createdBy, final Integer totalRecords, final Integer successCount, final Integer failureCount) { this.document = document; - this.importTime = Date.from(importTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); - this.endTime = Date.from(endTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.importTime = importTime; + this.endTime = endTime; this.completed = completed; this.entityType = entityType; this.createdBy = createdBy; @@ -100,7 +95,7 @@ public class ImportDocument extends AbstractPersistableCustom { } public void update(final LocalDateTime endTime, final Integer successCount, final Integer errorCount) { - this.endTime = Date.from(endTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.endTime = endTime; this.completed = Boolean.TRUE; this.successCount = successCount; this.failureCount = errorCount; diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/AbstractWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/AbstractWorkbookPopulator.java index 8a9bfe7f3..0361b88dc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/AbstractWorkbookPopulator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/AbstractWorkbookPopulator.java @@ -19,10 +19,10 @@ package org.apache.fineract.infrastructure.bulkimport.populator; import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; import java.util.List; import java.util.regex.Pattern; import org.apache.fineract.organisation.office.data.OfficeData; @@ -67,27 +67,21 @@ public abstract class AbstractWorkbookPopulator implements WorkbookPopulator { protected void writeDate(int colIndex, Row row, String value, CellStyle dateCellStyle, String dateFormat) { try { - SimpleDateFormat formatinDB = null; + DateTimeFormatter formatinDB; if (value.matches("\\d{4}-\\d{1,2}-\\d{1,2}")) { - formatinDB = new SimpleDateFormat("yyyy-MM-dd"); + formatinDB = new DateTimeFormatterBuilder().appendPattern("yyyy-M-d").toFormatter(); } else if (value.matches("\\d{1,2}/\\d{1,2}/\\d{4}")) { - formatinDB = new SimpleDateFormat("dd/MM/yyyy"); + formatinDB = new DateTimeFormatterBuilder().appendPattern("d/M/yyyy").toFormatter(); } else if (value.matches("\\d{1,2} \\w{3,12} \\d{4}")) { - formatinDB = new SimpleDateFormat("dd MMMM yyyy"); + formatinDB = new DateTimeFormatterBuilder().appendPattern("d MMMM yyyy").toFormatter(); + } else { + throw new IllegalArgumentException("Unrecognised format of date value: " + value); } - Date date1 = formatinDB.parse(value); - SimpleDateFormat expectedFormat = new SimpleDateFormat(dateFormat); - Date date2 = expectedFormat.parse(expectedFormat.format(date1)); - Calendar cal = Calendar.getInstance(); - cal.setTime(date2); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); - Date dateWithoutTime = cal.getTime(); - row.createCell(colIndex).setCellValue(dateWithoutTime); + LocalDate date1 = LocalDate.parse(value, formatinDB); + DateTimeFormatter expectedFormat = new DateTimeFormatterBuilder().appendPattern(dateFormat).toFormatter(); + row.createCell(colIndex).setCellValue(expectedFormat.format(date1)); row.getCell(colIndex).setCellStyle(dateCellStyle); - } catch (ParseException pe) { + } catch (DateTimeParseException pe) { throw new IllegalArgumentException(pe); } } @@ -121,9 +115,7 @@ public abstract class AbstractWorkbookPopulator implements WorkbookPopulator { short df = workbook.createDataFormat().getFormat(dateFormat); dateCellStyle.setDataFormat(df); int rowIndex = 0; - SimpleDateFormat outputFormat = new SimpleDateFormat(dateFormat); - SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date date = null; + DateTimeFormatter outputFormat = new DateTimeFormatterBuilder().appendPattern(dateFormat).toFormatter(); try { if (clients != null) { for (ClientData client : clients) { @@ -134,8 +126,7 @@ public abstract class AbstractWorkbookPopulator implements WorkbookPopulator { writeString(nameCol, row, client.displayName().replaceAll("[ )(] ", "_") + "(" + client.id() + ")"); if (client.getActivationDate() != null) { - date = inputFormat.parse(client.getActivationDate().toString()); - writeDate(activationDateCol, row, outputFormat.format(date), dateCellStyle, dateFormat); + writeDate(activationDateCol, row, outputFormat.format(client.getActivationDate()), dateCellStyle, dateFormat); } if (containsClientExtId) { if (client.getExternalId() != null) { @@ -154,13 +145,12 @@ public abstract class AbstractWorkbookPopulator implements WorkbookPopulator { writeString(nameCol, row, group.getName().replaceAll("[ )(] ", "_")); if (group.getActivationDate() != null) { - date = inputFormat.parse(group.getActivationDate().toString()); - writeDate(activationDateCol, row, outputFormat.format(date), dateCellStyle, dateFormat); + writeDate(activationDateCol, row, outputFormat.format(group.getActivationDate()), dateCellStyle, dateFormat); } } } - } catch (ParseException e) { + } catch (DateTimeParseException e) { LOG.error("Problem occurred in setClientAndGroupDateLookupTable function", e); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SharedProductsSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SharedProductsSheetPopulator.java index dd53d6298..7936f4cbc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SharedProductsSheetPopulator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SharedProductsSheetPopulator.java @@ -19,8 +19,8 @@ package org.apache.fineract.infrastructure.bulkimport.populator; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -99,10 +99,10 @@ public class SharedProductsSheetPopulator extends AbstractWorkbookPopulator { BigDecimal marketValue = shareProductData.getUnitPrice(); Collection marketDataSet = shareProductData.getMarketPrice(); if (marketDataSet != null && !marketDataSet.isEmpty()) { - Date currentDate = DateUtils.getBusinessDate(); + LocalDate currentDate = DateUtils.getBusinessLocalDate(); for (ShareProductMarketPriceData data : marketDataSet) { - Date futureDate = data.getStartDate(); - if (currentDate.after(futureDate)) { + LocalDate futureDate = data.getStartDate(); + if (currentDate.isAfter(futureDate)) { marketValue = data.getShareValue(); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java index 0d9997f63..84f5ea855 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java @@ -18,11 +18,10 @@ */ package org.apache.fineract.infrastructure.bulkimport.populator.loanrepayment; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -229,9 +228,7 @@ public class LoanRepaymentWorkbookPopulator extends AbstractWorkbookPopulator { CellStyle dateCellStyle = workbook.createCellStyle(); short df = workbook.createDataFormat().getFormat(dateFormat); dateCellStyle.setDataFormat(df); - SimpleDateFormat outputFormat = new SimpleDateFormat(dateFormat); - SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date date = null; + DateTimeFormatter outputFormat = new DateTimeFormatterBuilder().appendPattern(dateFormat).toFormatter(); Collections.sort(allloans, new LoanComparatorByStatusActive()); for (LoanAccountData loan : allloans) { row = loanRepaymentSheet.createRow(rowIndex++); @@ -244,13 +241,8 @@ public class LoanRepaymentWorkbookPopulator extends AbstractWorkbookPopulator { writeBigDecimal(LoanRepaymentConstants.LOOKUP_TOTAL_OUTSTANDING_AMOUNT_COL, row, loan.getTotalOutstandingAmount()); } if (loan.getDisbursementDate() != null) { - try { - date = inputFormat.parse(loan.getDisbursementDate().toString()); - } catch (ParseException e) { - LOG.error("Problem occurred in populateLoansTable function", e); - } - writeDate(LoanRepaymentConstants.LOOKUP_LOAN_DISBURSEMENT_DATE_COL, row, outputFormat.format(date), dateCellStyle, - dateFormat); + writeDate(LoanRepaymentConstants.LOOKUP_LOAN_DISBURSEMENT_DATE_COL, row, outputFormat.format(loan.getDisbursementDate()), + dateCellStyle, dateFormat); } } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/api/EmailApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/api/EmailApiResource.java index 5a4909604..56a73bf2c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/api/EmailApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/api/EmailApiResource.java @@ -18,8 +18,8 @@ */ package org.apache.fineract.infrastructure.campaigns.email.api; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -119,11 +119,11 @@ public class EmailApiResource { @QueryParam("locale") final String locale, @QueryParam("dateFormat") final String dateFormat, @Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions); - Date fromDate = null; + LocalDate fromDate = null; if (fromDateParam != null) { fromDate = fromDateParam.getDate("fromDate", dateFormat, locale); } - Date toDate = null; + LocalDate toDate = null; if (toDateParam != null) { toDate = toDateParam.getDate("toDate", dateFormat, locale); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/domain/EmailCampaign.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/domain/EmailCampaign.java index 495e317ca..bd61c8638 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/domain/EmailCampaign.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/domain/EmailCampaign.java @@ -20,11 +20,8 @@ package org.apache.fineract.infrastructure.campaigns.email.domain; import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; -import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -34,9 +31,6 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.campaigns.email.ScheduledEmailConstants; import org.apache.fineract.infrastructure.campaigns.email.data.EmailCampaignValidator; @@ -86,24 +80,21 @@ public class EmailCampaign extends AbstractPersistableCustom { private String stretchyReportParamMap; @Column(name = "closedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date closureDate; + private LocalDate closureDate; @ManyToOne(optional = true) @JoinColumn(name = "closedon_userid", nullable = true) private AppUser closedBy; @Column(name = "submittedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date submittedOnDate; + private LocalDate submittedOnDate; @ManyToOne(optional = true) @JoinColumn(name = "submittedon_userid", nullable = true) private AppUser submittedBy; @Column(name = "approvedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date approvedOnDate; + private LocalDate approvedOnDate; @ManyToOne(optional = true) @JoinColumn(name = "approvedon_userid", nullable = true) @@ -113,16 +104,13 @@ public class EmailCampaign extends AbstractPersistableCustom { private String recurrence; @Column(name = "next_trigger_date") - @Temporal(TemporalType.TIMESTAMP) - private Date nextTriggerDate; + private LocalDateTime nextTriggerDate; @Column(name = "last_trigger_date") - @Temporal(TemporalType.TIMESTAMP) - private Date lastTriggerDate; + private LocalDateTime lastTriggerDate; @Column(name = "recurrence_start_date") - @Temporal(TemporalType.TIMESTAMP) - private Date recurrenceStartDate; + private LocalDateTime recurrenceStartDate; @Column(name = "is_visible", nullable = true) private boolean isVisible; @@ -153,15 +141,15 @@ public class EmailCampaign extends AbstractPersistableCustom { this.emailAttachmentFileFormat = emailAttachmentFileFormat.getValue(); this.stretchyReport = stretchyReport; this.stretchyReportParamMap = stretchyReportParamMap; - this.submittedOnDate = Date.from(submittedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.submittedOnDate = submittedOnDate; this.submittedBy = submittedBy; this.recurrence = recurrence; LocalDateTime recurrenceStartDate = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant()); this.isVisible = true; if (localDateTime != null) { - this.recurrenceStartDate = Date.from(localDateTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.recurrenceStartDate = localDateTime; } else { - this.recurrenceStartDate = Date.from(recurrenceStartDate.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.recurrenceStartDate = recurrenceStartDate; } } @@ -248,15 +236,13 @@ public class EmailCampaign extends AbstractPersistableCustom { final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale); - if (command.isChangeInLocalDateParameterNamed(EmailCampaignValidator.recurrenceStartDate, getRecurrenceStartDate())) { + if (command.isChangeInLocalDateTimeParameterNamed(EmailCampaignValidator.recurrenceStartDate, getRecurrenceStartDateTime())) { final String valueAsInput = command.stringValueOfParameterNamed(EmailCampaignValidator.recurrenceStartDate); actualChanges.put(EmailCampaignValidator.recurrenceStartDate, valueAsInput); actualChanges.put(ClientApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(ClientApiConstants.localeParamName, localeAsInput); - final LocalDateTime newValue = LocalDateTime.parse(valueAsInput, fmt); - - this.recurrenceStartDate = Date.from(newValue.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.recurrenceStartDate = LocalDateTime.parse(valueAsInput, fmt); } return actualChanges; @@ -275,7 +261,7 @@ public class EmailCampaign extends AbstractPersistableCustom { throw new PlatformApiDataValidationException(dataValidationErrors); } - this.approvedOnDate = Date.from(activationLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.approvedOnDate = activationLocalDate; this.approvedBy = currentUser; this.status = EmailCampaignStatus.ACTIVE.getValue(); @@ -299,7 +285,7 @@ public class EmailCampaign extends AbstractPersistableCustom { this.lastTriggerDate = null; } this.closedBy = currentUser; - this.closureDate = Date.from(closureLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closureDate = closureLocalDate; this.status = EmailCampaignStatus.CLOSED.getValue(); validateClosureDate(); } @@ -318,7 +304,7 @@ public class EmailCampaign extends AbstractPersistableCustom { throw new PlatformApiDataValidationException(dataValidationErrors); } - this.approvedOnDate = Date.from(reactivateLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.approvedOnDate = reactivateLocalDate; this.status = EmailCampaignStatus.ACTIVE.getValue(); this.approvedBy = currentUser; this.closureDate = null; @@ -457,20 +443,16 @@ public class EmailCampaign extends AbstractPersistableCustom { } public LocalDate getSubmittedOnDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.submittedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), null); + return this.submittedOnDate; } public LocalDate getClosureDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.closureDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), null); + return this.closureDate; } public LocalDate getActivationLocalDate() { - LocalDate activationLocalDate = null; - if (this.approvedOnDate != null) { - activationLocalDate = LocalDate.ofInstant(this.approvedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return activationLocalDate; + return this.approvedOnDate; } private boolean isDateInTheFuture(final LocalDate localDate) { @@ -501,36 +483,28 @@ public class EmailCampaign extends AbstractPersistableCustom { return this.recurrence; } - public LocalDate getRecurrenceStartDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.recurrenceStartDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), - null); - } - public LocalDateTime getRecurrenceStartDateTime() { - return ObjectUtils.defaultIfNull( - ZonedDateTime.ofInstant(this.recurrenceStartDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDateTime(), null); + return this.recurrenceStartDate; } - public void setLastTriggerDate(Date lastTriggerDate) { + public void setLastTriggerDate(LocalDateTime lastTriggerDate) { this.lastTriggerDate = lastTriggerDate; } - public void setNextTriggerDate(Date nextTriggerDate) { + public void setNextTriggerDate(LocalDateTime nextTriggerDate) { this.nextTriggerDate = nextTriggerDate; } public LocalDateTime getNextTriggerDate() { - return ObjectUtils.defaultIfNull( - ZonedDateTime.ofInstant(this.nextTriggerDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDateTime(), null); - - } - - public Date getNextTriggerDateInDate() { return this.nextTriggerDate; } - public LocalDate getLastTriggerDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.lastTriggerDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), null); + public LocalDateTime getNextTriggerDateInDate() { + return this.nextTriggerDate; + } + + public LocalDateTime getLastTriggerDate() { + return this.lastTriggerDate; } public void updateIsVisible(boolean isVisible) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/domain/EmailMessage.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/domain/EmailMessage.java index 7a611876e..cc732c4a7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/domain/EmailMessage.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/domain/EmailMessage.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.infrastructure.campaigns.email.domain; -import java.util.Date; +import java.time.LocalDate; import java.util.LinkedHashMap; import java.util.Map; import javax.persistence.Column; @@ -26,8 +26,6 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.campaigns.email.EmailApiConstants; import org.apache.fineract.infrastructure.core.api.JsonCommand; @@ -73,8 +71,7 @@ public class EmailMessage extends AbstractPersistableCustom { private String campaignName; @Column(name = "submittedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date submittedOnDate; + private LocalDate submittedOnDate; @Column(name = "error_message") private String errorMessage; @@ -107,7 +104,7 @@ public class EmailMessage extends AbstractPersistableCustom { this.emailSubject = emailSubject; this.message = message; this.campaignName = campaignName; - this.submittedOnDate = DateUtils.getBusinessDate(); + this.submittedOnDate = DateUtils.getBusinessLocalDate(); } public Map update(final JsonCommand command) { @@ -159,7 +156,7 @@ public class EmailMessage extends AbstractPersistableCustom { return this.campaignName; } - public Date getSubmittedOnDate() { + public LocalDate getSubmittedOnDate() { return this.submittedOnDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailCampaignWritePlatformCommandHandlerImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailCampaignWritePlatformCommandHandlerImpl.java index df542106e..d1cef8882 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailCampaignWritePlatformCommandHandlerImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailCampaignWritePlatformCommandHandlerImpl.java @@ -38,7 +38,6 @@ import java.time.format.DateTimeFormatterBuilder; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -344,33 +343,29 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai final EmailCampaign emailCampaign = this.emailCampaignRepository.findById(campaignId) .orElseThrow(() -> new EmailCampaignNotFound(campaignId)); LocalDateTime nextTriggerDate = emailCampaign.getNextTriggerDate(); - emailCampaign.setLastTriggerDate(Date.from(nextTriggerDate.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + emailCampaign.setLastTriggerDate(nextTriggerDate); // calculate new trigger date and insert into next trigger date /** * next run time has to be in the future if not calculate a new future date */ - LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), - emailCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate()); - if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means - // next - // run - // time is - // in the - // past - // calculate - // a new - // future - // date - nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), - emailCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant()); + LocalDateTime newTriggerDateWithTime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), + emailCampaign.getNextTriggerDate(), nextTriggerDate); + if (newTriggerDateWithTime.isBefore(DateUtils.getLocalDateTimeOfTenant())) { // means + // next + // run + // time is + // in the + // past + // calculate + // a new + // future + // date + newTriggerDateWithTime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), emailCampaign.getNextTriggerDate(), + DateUtils.getLocalDateTimeOfTenant()); } - final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime(); - final String dateString = nextRuntime.toString() + " " + getTime.getHour() + ":" + getTime.getMinute() + ":" + getTime.getSecond(); - final DateTimeFormatter simpleDateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat); - emailCampaign.setNextTriggerDate(Date.from(newTriggerDateWithTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + emailCampaign.setNextTriggerDate(newTriggerDateWithTime); this.emailCampaignRepository.saveAndFlush(emailCampaign); } @@ -402,24 +397,15 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai * if recurrence start date is in the future calculate next trigger date if not use recurrence start * date us next trigger date when activating */ - LocalDate nextTriggerDate = null; + LocalDateTime nextTriggerDateWithTime; if (emailCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) { - nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), - emailCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant()); + nextTriggerDateWithTime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), + emailCampaign.getRecurrenceStartDateTime(), DateUtils.getLocalDateTimeOfTenant()); } else { - nextTriggerDate = emailCampaign.getRecurrenceStartDate(); + nextTriggerDateWithTime = emailCampaign.getRecurrenceStartDateTime(); } - // to get time of tenant - final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime(); - final String dateString = nextTriggerDate.toString() + " " + getTime.getHour() + ":" + getTime.getMinute() + ":" - + getTime.getSecond(); - final DateTimeFormatter simpleDateFormat = new DateTimeFormatterBuilder().parseCaseInsensitive().parseLenient() - .appendPattern("yyyy-MM-dd HH:mm:ss").toFormatter(); - final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat); - - emailCampaign - .setNextTriggerDate(Date.from(nextTriggerDateWithTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + emailCampaign.setNextTriggerDate(nextTriggerDateWithTime); this.emailCampaignRepository.saveAndFlush(emailCampaign); } } @@ -554,12 +540,12 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai * if recurrence start date is in the future calculate next trigger date if not use recurrence start date us * next trigger date when activating */ - LocalDate nextTriggerDate = null; + LocalDateTime nextTriggerDate = null; if (emailCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) { - nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), emailCampaign.getRecurrenceStartDate(), - DateUtils.getLocalDateOfTenant()); + nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), + emailCampaign.getRecurrenceStartDateTime(), DateUtils.getLocalDateTimeOfTenant()); } else { - nextTriggerDate = emailCampaign.getRecurrenceStartDate(); + nextTriggerDate = emailCampaign.getRecurrenceStartDateTime(); } // to get time of tenant final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime(); @@ -570,7 +556,7 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai .appendPattern("yyyy-MM-dd HH:mm:ss").toFormatter(); final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat); - emailCampaign.setNextTriggerDate(Date.from(nextTriggerDateWithTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + emailCampaign.setNextTriggerDate(nextTriggerDateWithTime); this.emailCampaignRepository.saveAndFlush(emailCampaign); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailReadPlatformService.java index 99f105c49..945ad49ee 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailReadPlatformService.java @@ -18,8 +18,8 @@ */ package org.apache.fineract.infrastructure.campaigns.email.service; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.campaigns.email.data.EmailData; import org.apache.fineract.infrastructure.core.service.Page; @@ -39,7 +39,7 @@ public interface EmailReadPlatformService { Collection retrieveAllFailed(SearchParameters searchParameters); - Page retrieveEmailByStatus(Integer limit, Integer status, Date dateFrom, Date dateTo); + Page retrieveEmailByStatus(Integer limit, Integer status, LocalDate dateFrom, LocalDate dateTo); List retrieveExternalIdsOfAllSent(Integer limit); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailReadPlatformServiceImpl.java index 1175fb9ed..b57528d5e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailReadPlatformServiceImpl.java @@ -20,11 +20,8 @@ package org.apache.fineract.infrastructure.campaigns.email.service; import java.sql.ResultSet; import java.sql.SQLException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.campaigns.email.data.EmailData; import org.apache.fineract.infrastructure.campaigns.email.domain.EmailMessageEnumerations; @@ -32,6 +29,7 @@ import org.apache.fineract.infrastructure.campaigns.email.domain.EmailMessageSta import org.apache.fineract.infrastructure.campaigns.email.exception.EmailNotFoundException; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.PaginationHelper; import org.apache.fineract.infrastructure.core.service.SearchParameters; @@ -172,7 +170,8 @@ public class EmailReadPlatformServiceImpl implements EmailReadPlatformService { } @Override - public Page retrieveEmailByStatus(final Integer limit, final Integer status, final Date dateFrom, final Date dateTo) { + public Page retrieveEmailByStatus(final Integer limit, final Integer status, final LocalDate dateFrom, + final LocalDate dateTo) { final StringBuilder sqlBuilder = new StringBuilder(200); sqlBuilder.append("select " + sqlGenerator.calcFoundRows() + " "); sqlBuilder.append(this.emailRowMapper.schema()); @@ -182,9 +181,8 @@ public class EmailReadPlatformServiceImpl implements EmailReadPlatformService { String fromDateString = null; String toDateString = null; if (dateFrom != null && dateTo != null) { - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - fromDateString = df.format(dateFrom); - toDateString = df.format(dateTo); + fromDateString = DateUtils.DEFAULT_DATE_FORMATER.format(dateFrom); + toDateString = DateUtils.DEFAULT_DATE_FORMATER.format(dateTo); sqlBuilder.append(" and emo.submittedon_date >= ? and emo.submittedon_date <= ? "); } final String sqlPlusLimit = (limit > 0) ? " " + sqlGenerator.limit(limit) : ""; diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/domain/SmsCampaign.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/domain/SmsCampaign.java index b2261e4e5..44e19433f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/domain/SmsCampaign.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/domain/SmsCampaign.java @@ -20,11 +20,8 @@ package org.apache.fineract.infrastructure.campaigns.sms.domain; import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; -import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -34,10 +31,7 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.campaigns.constants.CampaignType; import org.apache.fineract.infrastructure.campaigns.sms.constants.SmsCampaignStatus; @@ -83,24 +77,21 @@ public class SmsCampaign extends AbstractPersistableCustom { private String message; @Column(name = "closedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date closureDate; + private LocalDate closureDate; @ManyToOne(optional = true) @JoinColumn(name = "closedon_userid", nullable = true) private AppUser closedBy; @Column(name = "submittedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date submittedOnDate; + private LocalDate submittedOnDate; @ManyToOne(optional = true) @JoinColumn(name = "submittedon_userid", nullable = true) private AppUser submittedBy; @Column(name = "approvedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date approvedOnDate; + private LocalDate approvedOnDate; @ManyToOne(optional = true) @JoinColumn(name = "approvedon_userid", nullable = true) @@ -110,16 +101,13 @@ public class SmsCampaign extends AbstractPersistableCustom { private String recurrence; @Column(name = "next_trigger_date", nullable = true) - @Temporal(TemporalType.TIMESTAMP) - private Date nextTriggerDate; + private LocalDateTime nextTriggerDate; @Column(name = "last_trigger_date", nullable = true) - @Temporal(TemporalType.TIMESTAMP) - private Date lastTriggerDate; + private LocalDateTime lastTriggerDate; @Column(name = "recurrence_start_date", nullable = true) - @Temporal(TemporalType.TIMESTAMP) - private Date recurrenceStartDate; + private LocalDateTime recurrenceStartDate; @Column(name = "is_visible", nullable = true) private boolean isVisible; @@ -140,15 +128,15 @@ public class SmsCampaign extends AbstractPersistableCustom { this.paramValue = paramValue; this.status = SmsCampaignStatus.PENDING.getValue(); this.message = message; - this.submittedOnDate = Date.from(submittedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.submittedOnDate = submittedOnDate; this.submittedBy = submittedBy; this.recurrence = recurrence; LocalDateTime recurrenceStartDate = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant()); this.isVisible = true; if (localDateTime != null) { - this.recurrenceStartDate = Date.from(localDateTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.recurrenceStartDate = localDateTime; } else { - this.recurrenceStartDate = Date.from(recurrenceStartDate.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.recurrenceStartDate = recurrenceStartDate; } this.isNotification = isNotification; } @@ -260,9 +248,7 @@ public class SmsCampaign extends AbstractPersistableCustom { actualChanges.put(SmsCampaignValidator.dateTimeFormat, dateTimeFormatAsInput); actualChanges.put(SmsCampaignValidator.localeParamName, localeAsInput); - final LocalDateTime newValue = LocalDateTime.parse(valueAsInput, fmt); - - this.recurrenceStartDate = Date.from(newValue.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.recurrenceStartDate = LocalDateTime.parse(valueAsInput, fmt); } return actualChanges; @@ -281,7 +267,7 @@ public class SmsCampaign extends AbstractPersistableCustom { throw new PlatformApiDataValidationException(dataValidationErrors); } - this.approvedOnDate = Date.from(activationLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.approvedOnDate = activationLocalDate; this.approvedBy = currentUser; this.status = SmsCampaignStatus.ACTIVE.getValue(); @@ -305,7 +291,7 @@ public class SmsCampaign extends AbstractPersistableCustom { this.lastTriggerDate = null; } this.closedBy = currentUser; - this.closureDate = Date.from(closureLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closureDate = closureLocalDate; this.status = SmsCampaignStatus.CLOSED.getValue(); validateClosureDate(); } @@ -324,7 +310,7 @@ public class SmsCampaign extends AbstractPersistableCustom { throw new PlatformApiDataValidationException(dataValidationErrors); } - this.approvedOnDate = Date.from(reactivateLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.approvedOnDate = reactivateLocalDate; this.status = SmsCampaignStatus.ACTIVE.getValue(); this.approvedBy = currentUser; this.closureDate = null; @@ -467,20 +453,16 @@ public class SmsCampaign extends AbstractPersistableCustom { } public LocalDate getSubmittedOnDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.submittedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), null); + return this.submittedOnDate; } public LocalDate getClosureDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.closureDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), null); + return this.closureDate; } public LocalDate getActivationLocalDate() { - LocalDate activationLocalDate = null; - if (this.approvedOnDate != null) { - activationLocalDate = LocalDate.ofInstant(this.approvedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return activationLocalDate; + return this.approvedOnDate; } private boolean isDateInTheFuture(final LocalDate localDate) { @@ -507,36 +489,28 @@ public class SmsCampaign extends AbstractPersistableCustom { return this.recurrence; } - public LocalDate getRecurrenceStartDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.recurrenceStartDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), - null); + public LocalDateTime getRecurrenceStartDate() { + return this.recurrenceStartDate; } public LocalDateTime getRecurrenceStartDateTime() { - return ObjectUtils.defaultIfNull( - ZonedDateTime.ofInstant(this.recurrenceStartDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDateTime(), null); + return this.recurrenceStartDate; } - public void setLastTriggerDate(Date lastTriggerDate) { + public void setLastTriggerDate(LocalDateTime lastTriggerDate) { this.lastTriggerDate = lastTriggerDate; } - public void setNextTriggerDate(Date nextTriggerDate) { + public void setNextTriggerDate(LocalDateTime nextTriggerDate) { this.nextTriggerDate = nextTriggerDate; } public LocalDateTime getNextTriggerDate() { - return ObjectUtils.defaultIfNull( - ZonedDateTime.ofInstant(this.nextTriggerDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDateTime(), null); - - } - - public Date getNextTriggerDateInDate() { return this.nextTriggerDate; } - public LocalDate getLastTriggerDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.lastTriggerDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), null); + public LocalDateTime getLastTriggerDate() { + return this.lastTriggerDate; } public void updateIsVisible(boolean isVisible) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/service/SmsCampaignWritePlatformServiceJpaImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/service/SmsCampaignWritePlatformServiceJpaImpl.java index 77f209693..323aa3bd9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/service/SmsCampaignWritePlatformServiceJpaImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/service/SmsCampaignWritePlatformServiceJpaImpl.java @@ -32,10 +32,8 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeFormatterBuilder; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -146,7 +144,7 @@ public class SmsCampaignWritePlatformServiceJpaImpl implements SmsCampaignWriteP Report report = this.reportRepository.findById(runReportId).orElseThrow(() -> new ReportNotFoundException(runReportId)); SmsCampaign smsCampaign = SmsCampaign.instance(currentUser, report, command); if (smsCampaign.getRecurrenceStartDate() != null - && smsCampaign.getRecurrenceStartDate().isBefore(DateUtils.getLocalDateOfTenant())) { + && smsCampaign.getRecurrenceStartDate().isBefore(DateUtils.getLocalDateTimeOfTenant())) { throw new GeneralPlatformDomainRuleException("error.msg.campaign.recurrenceStartDate.in.the.past", "Recurrence start date cannot be the past date.", smsCampaign.getRecurrenceStartDate()); } @@ -409,34 +407,29 @@ public class SmsCampaignWritePlatformServiceJpaImpl implements SmsCampaignWriteP final SmsCampaign smsCampaign = this.smsCampaignRepository.findById(campaignId) .orElseThrow(() -> new SmsCampaignNotFound(campaignId)); LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate(); - smsCampaign.setLastTriggerDate(Date.from(nextTriggerDate.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + smsCampaign.setLastTriggerDate(nextTriggerDate); // calculate new trigger date and insert into next trigger date /** * next run time has to be in the future if not calculate a new future date */ - LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(), - smsCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate()); - if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means - // next - // run - // time is - // in the - // past - // calculate - // a new - // future - // date - nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(), smsCampaign.getNextTriggerDate().toLocalDate(), - DateUtils.getLocalDateOfTenant()); + LocalDateTime nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(), smsCampaign.getNextTriggerDate(), + nextTriggerDate); + if (nextRuntime.isBefore(DateUtils.getLocalDateTimeOfTenant())) { // means + // next + // run + // time is + // in the + // past + // calculate + // a new + // future + // date + nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(), smsCampaign.getNextTriggerDate(), + DateUtils.getLocalDateTimeOfTenant()); } - final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime(); - final String dateString = nextRuntime.toString() + " " + getTime.getHour() + ":" + getTime.getMinute() + ":" + getTime.getSecond(); - final DateTimeFormatter simpleDateFormat = new DateTimeFormatterBuilder().parseCaseInsensitive().parseLenient() - .appendPattern("yyyy-MM-dd HH:mm:ss").toFormatter(); - final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat); - smsCampaign.setNextTriggerDate(Date.from(newTriggerDateWithTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + smsCampaign.setNextTriggerDate(nextRuntime); this.smsCampaignRepository.saveAndFlush(smsCampaign); } @@ -466,23 +459,15 @@ public class SmsCampaignWritePlatformServiceJpaImpl implements SmsCampaignWriteP * if recurrence start date is in the future calculate next trigger date if not use recurrence start date us * next trigger date when activating */ - LocalDate nextTriggerDate = null; + LocalDateTime nextTriggerDate = null; if (smsCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) { nextTriggerDate = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(), smsCampaign.getRecurrenceStartDate(), - DateUtils.getLocalDateOfTenant()); + DateUtils.getLocalDateTimeOfTenant()); } else { nextTriggerDate = smsCampaign.getRecurrenceStartDate(); } - // to get time of tenant - final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime(); - final String dateString = nextTriggerDate.toString() + " " + getTime.getHour() + ":" + getTime.getMinute() + ":" - + getTime.getSecond(); - final DateTimeFormatter simpleDateFormat = new DateTimeFormatterBuilder().parseCaseInsensitive().parseLenient() - .appendPattern("yyyy-MM-dd HH:mm:ss").toFormatter(); - final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat); - - smsCampaign.setNextTriggerDate(Date.from(nextTriggerDateWithTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + smsCampaign.setNextTriggerDate(nextTriggerDate); this.smsCampaignRepository.saveAndFlush(smsCampaign); } @@ -629,23 +614,17 @@ public class SmsCampaignWritePlatformServiceJpaImpl implements SmsCampaignWriteP * if recurrence start date is in the future calculate next trigger date if not use recurrence start date us * next trigger date when activating */ - LocalDate nextTriggerDate = null; + LocalDateTime nextTriggerDate = null; if (smsCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) { nextTriggerDate = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(), smsCampaign.getRecurrenceStartDate(), - DateUtils.getLocalDateOfTenant()); + DateUtils.getLocalDateTimeOfTenant()); } else { nextTriggerDate = smsCampaign.getRecurrenceStartDate(); } // to get time of tenant final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime(); - final String dateString = nextTriggerDate.toString() + " " + getTime.getHour() + ":" + getTime.getMinute() + ":" - + getTime.getSecond(); - final DateTimeFormatter simpleDateFormat = new DateTimeFormatterBuilder().parseCaseInsensitive().parseLenient() - .appendPattern("yyyy-MM-dd HH:mm:ss").toFormatter(); - final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat); - - smsCampaign.setNextTriggerDate(Date.from(nextTriggerDateWithTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + smsCampaign.setNextTriggerDate(nextTriggerDate); } this.smsCampaignRepository.saveAndFlush(smsCampaign); @@ -665,8 +644,8 @@ public class SmsCampaignWritePlatformServiceJpaImpl implements SmsCampaignWriteP LocalDateTime tenantDateNow = tenantDateTime(); LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate(); - LOG.info("tenant time {} trigger time {} {}", - new Object[] { tenantDateNow, nextTriggerDate, JobName.UPDATE_SMS_OUTBOUND_WITH_CAMPAIGN_MESSAGE.name() }); + LOG.info("tenant time {} trigger time {} {}", tenantDateNow, nextTriggerDate, + JobName.UPDATE_SMS_OUTBOUND_WITH_CAMPAIGN_MESSAGE.name()); if (nextTriggerDate.isBefore(tenantDateNow)) { insertDirectCampaignIntoSmsOutboundTable(smsCampaign); this.updateTriggerDates(smsCampaign.getId()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java index d4efbbb95..6c23663fa 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java @@ -25,11 +25,11 @@ import java.lang.reflect.Type; import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.MonthDay; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; import java.util.Arrays; -import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -255,19 +255,7 @@ public final class JsonCommand { return this.productId; } - private boolean differenceExistsTime(final LocalDateTime baseValue, final LocalDateTime workingCopyValue) { - boolean differenceExists = false; - - if (baseValue != null) { - differenceExists = !baseValue.equals(workingCopyValue); - } else { - differenceExists = workingCopyValue != null; - } - - return differenceExists; - } - - private boolean differenceExists(final LocalDate baseValue, final LocalDate workingCopyValue) { + private boolean differenceExists(final TemporalAccessor baseValue, final TemporalAccessor workingCopyValue) { boolean differenceExists = false; if (baseValue != null) { @@ -374,20 +362,29 @@ public final class JsonCommand { return isChangeInLocalDateParameterNamed(parameterName, existingValue); } - public boolean isChangeInTimeParameterNamed(final String parameterName, final Date existingValue, final String timeFormat) { - LocalDateTime time = null; + public boolean isChangeInTimeParameterNamed(final String parameterName, final LocalTime existingValue, final String timeFormat) { + LocalTime time = null; if (existingValue != null) { DateTimeFormatter timeFormtter = DateTimeFormatter.ofPattern(timeFormat); - time = LocalDateTime.parse(existingValue.toString(), timeFormtter); + time = LocalTime.parse(existingValue.toString(), timeFormtter); } return isChangeInLocalTimeParameterNamed(parameterName, time); } - public boolean isChangeInLocalTimeParameterNamed(final String parameterName, final LocalDateTime existingValue) { + public boolean isChangeInLocalTimeParameterNamed(final String parameterName, final LocalTime existingValue) { boolean isChanged = false; if (parameterExists(parameterName)) { - final LocalDateTime workingValue = localTimeValueOfParameterNamed(parameterName); - isChanged = differenceExistsTime(existingValue, workingValue); + final LocalTime workingValue = localTimeValueOfParameterNamed(parameterName); + isChanged = differenceExists(existingValue, workingValue); + } + return isChanged; + } + + public boolean isChangeInLocalDateTimeParameterNamed(final String parameterName, final LocalDateTime existingValue) { + boolean isChanged = false; + if (parameterExists(parameterName)) { + final LocalTime workingValue = localTimeValueOfParameterNamed(parameterName); + isChanged = differenceExists(existingValue, workingValue); } return isChanged; } @@ -405,20 +402,20 @@ public final class JsonCommand { return this.fromApiJsonHelper.extractLocalDateNamed(parameterName, this.parsedCommand); } - public LocalDateTime localTimeValueOfParameterNamed(final String parameterName) { + public LocalTime localTimeValueOfParameterNamed(final String parameterName) { return this.fromApiJsonHelper.extractLocalTimeNamed(parameterName, this.parsedCommand); } + public LocalDateTime localDateTimeValueOfParameterNamed(final String parameterName) { + return this.fromApiJsonHelper.extractLocalDateTimeNamed(parameterName, this.parsedCommand); + } + public MonthDay extractMonthDayNamed(final String parameterName) { return this.fromApiJsonHelper.extractMonthDayNamed(parameterName, this.parsedCommand); } - public Date dateValueOfParameterNamed(final String parameterName) { - final LocalDate localDate = this.fromApiJsonHelper.extractLocalDateNamed(parameterName, this.parsedCommand); - if (localDate == null) { - return null; - } - return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + public LocalDate dateValueOfParameterNamed(final String parameterName) { + return this.fromApiJsonHelper.extractLocalDateNamed(parameterName, this.parsedCommand); } public boolean isChangeInStringParameterNamed(final String parameterName, final String existingValue) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/ApiParameterError.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/ApiParameterError.java index b88e84da8..fa140d1ee 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/ApiParameterError.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/ApiParameterError.java @@ -18,9 +18,10 @@ */ package org.apache.fineract.infrastructure.core.data; -import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.util.ArrayList; -import java.util.Date; import java.util.List; public final class ApiParameterError { @@ -91,9 +92,9 @@ public final class ApiParameterError { final List messageArgs = new ArrayList<>(); if (defaultUserMessageArgs != null) { for (final Object object : defaultUserMessageArgs) { - if (object instanceof Date) { - final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); - final String formattedDate = dateFormatter.format(object); + 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)); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java index b8e7f8d61..01a229849 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java @@ -18,13 +18,10 @@ */ package org.apache.fineract.infrastructure.core.domain; -import java.time.Instant; -import java.util.Date; +import java.time.LocalDateTime; import java.util.Optional; import javax.persistence.Column; import javax.persistence.MappedSuperclass; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.springframework.data.domain.Auditable; import org.springframework.data.jpa.domain.AbstractAuditable; @@ -40,7 +37,7 @@ import org.springframework.data.jpa.domain.AbstractAuditable; * the type of the auditing type's identifier */ @MappedSuperclass -public abstract class AbstractAuditableCustom extends AbstractPersistableCustom implements Auditable { +public abstract class AbstractAuditableCustom extends AbstractPersistableCustom implements Auditable { private static final long serialVersionUID = 141481953116476081L; @@ -48,15 +45,13 @@ public abstract class AbstractAuditableCustom extends AbstractPersistableCustom private Long createdBy; @Column(name = "created_date") - @Temporal(TemporalType.TIMESTAMP) - private Date createdDate; + private LocalDateTime createdDate; @Column(name = "lastmodifiedby_id") private Long lastModifiedBy; @Column(name = "lastmodified_date") - @Temporal(TemporalType.TIMESTAMP) - private Date lastModifiedDate; + private LocalDateTime lastModifiedDate; @Override public Optional getCreatedBy() { @@ -69,13 +64,13 @@ public abstract class AbstractAuditableCustom extends AbstractPersistableCustom } @Override - public Optional getCreatedDate() { - return null == this.createdDate ? Optional.empty() : Optional.of(this.createdDate.toInstant()); + public Optional getCreatedDate() { + return null == this.createdDate ? Optional.empty() : Optional.of(this.createdDate); } @Override - public void setCreatedDate(final Instant createdDate) { - this.createdDate = null == createdDate ? null : Date.from(createdDate); + public void setCreatedDate(final LocalDateTime createdDate) { + this.createdDate = createdDate; } @Override @@ -89,12 +84,12 @@ public abstract class AbstractAuditableCustom extends AbstractPersistableCustom } @Override - public Optional getLastModifiedDate() { - return null == this.lastModifiedDate ? Optional.empty() : Optional.of(this.lastModifiedDate.toInstant()); + public Optional getLastModifiedDate() { + return null == this.lastModifiedDate ? Optional.empty() : Optional.of(this.lastModifiedDate); } @Override - public void setLastModifiedDate(final Instant lastModifiedDate) { - this.lastModifiedDate = null == lastModifiedDate ? null : Date.from(lastModifiedDate); + public void setLastModifiedDate(final LocalDateTime lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/serialization/FromJsonHelper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/serialization/FromJsonHelper.java index 7af14591e..68949c896 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/serialization/FromJsonHelper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/serialization/FromJsonHelper.java @@ -28,6 +28,7 @@ import java.math.BigDecimal; import java.security.InvalidParameterException; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.MonthDay; import java.util.ArrayList; import java.util.Collection; @@ -203,19 +204,32 @@ public class FromJsonHelper { return this.helperDelegator.extractLocalDateNamed(parameterName, element, new HashSet<>()); } - public LocalDateTime extractLocalTimeNamed(final String parameterName, final JsonElement element) { + public LocalTime extractLocalTimeNamed(final String parameterName, final JsonElement element) { return this.helperDelegator.extractLocalTimeNamed(parameterName, element, new HashSet<>()); } - public LocalDateTime extractLocalTimeNamed(final String parameterName, final JsonElement element, final String dateFormat, + public LocalDateTime extractLocalDateTimeNamed(final String parameterName, final JsonElement element) { + return this.helperDelegator.extractLocalDateTimeNamed(parameterName, element, new HashSet<>()); + } + + public LocalTime extractLocalTimeNamed(final String parameterName, final JsonElement element, final String dateFormat, final Locale locale) { return this.helperDelegator.extractLocalTimeNamed(parameterName, element, dateFormat, locale, new HashSet<>()); } - public LocalDateTime extractLocalTimeNamed(final String parameterName, final JsonElement element, String timeFormat) { + public LocalTime extractLocalTimeNamed(final String parameterName, final JsonElement element, String timeFormat) { return this.helperDelegator.extractLocalTimeNamed(parameterName, element, timeFormat, new HashSet<>()); } + public LocalDateTime extractLocalDateTimeNamed(final String parameterName, final JsonElement element, final String dateFormat, + final Locale locale) { + return this.helperDelegator.extractLocalDateTimeNamed(parameterName, element, dateFormat, locale, new HashSet<>()); + } + + public LocalDateTime extractLocalDateTimeNamed(final String parameterName, final JsonElement element, String timeFormat) { + return this.helperDelegator.extractLocalDateTimeNamed(parameterName, element, timeFormat, new HashSet<>()); + } + public LocalDate extractLocalDateNamed(final String parameterName, final JsonElement element, final String dateFormat, final Locale locale) { return this.helperDelegator.extractLocalDateNamed(parameterName, element.getAsJsonObject(), dateFormat, locale, new HashSet<>()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/serialization/JsonParserHelper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/serialization/JsonParserHelper.java index f939b6aa3..7ad675592 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/serialization/JsonParserHelper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/serialization/JsonParserHelper.java @@ -29,6 +29,7 @@ import java.text.NumberFormat; import java.text.ParseException; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.MonthDay; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; @@ -370,10 +371,10 @@ public class JsonParserHelper { return value; } - public LocalDateTime extractLocalTimeNamed(final String parameterName, final JsonElement element, + public LocalTime extractLocalTimeNamed(final String parameterName, final JsonElement element, final Set parametersPassedInCommand) { - LocalDateTime value = null; + LocalTime value = null; if (element.isJsonObject()) { final JsonObject object = element.getAsJsonObject(); @@ -382,11 +383,23 @@ public class JsonParserHelper { return value; } - public LocalDateTime extractLocalTimeNamed(final String parameterName, final JsonElement element, String timeFormat, + public LocalDateTime extractLocalDateTimeNamed(final String parameterName, final JsonElement element, final Set parametersPassedInCommand) { LocalDateTime value = null; + if (element.isJsonObject()) { + final JsonObject object = element.getAsJsonObject(); + value = extractLocalDateTimeNamed(parameterName, element, extractTimeFormatParameter(object), parametersPassedInCommand); + } + return value; + } + + public LocalTime extractLocalTimeNamed(final String parameterName, final JsonElement element, String timeFormat, + final Set parametersPassedInCommand) { + + LocalTime value = null; + if (element.isJsonObject()) { final JsonObject object = element.getAsJsonObject(); final Locale clientApplicationLocale = extractLocaleParameter(object); @@ -395,7 +408,52 @@ public class JsonParserHelper { return value; } - public LocalDateTime extractLocalTimeNamed(final String parameterName, final JsonElement element, final String timeFormat, + public LocalDateTime extractLocalDateTimeNamed(final String parameterName, final JsonElement element, String timeFormat, + final Set parametersPassedInCommand) { + + LocalDateTime value = null; + + if (element.isJsonObject()) { + final JsonObject object = element.getAsJsonObject(); + final Locale clientApplicationLocale = extractLocaleParameter(object); + value = extractLocalDateTimeNamed(parameterName, object, timeFormat, clientApplicationLocale, parametersPassedInCommand); + } + return value; + } + + public LocalTime extractLocalTimeNamed(final String parameterName, final JsonElement element, final String timeFormat, + final Locale clientApplicationLocale, final Set parametersPassedInCommand) { + LocalTime value = null; + String timeValueAsString = null; + if (element.isJsonObject()) { + final JsonObject object = element.getAsJsonObject(); + if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) { + parametersPassedInCommand.add(parameterName); + + try { + DateTimeFormatter timeFormtter = DateTimeFormatter.ofPattern(timeFormat); + final JsonPrimitive primitive = object.get(parameterName).getAsJsonPrimitive(); + timeValueAsString = primitive.getAsString(); + if (StringUtils.isNotBlank(timeValueAsString)) { + value = LocalTime.parse(timeValueAsString, timeFormtter); + } + } catch (IllegalArgumentException e) { + final List dataValidationErrors = new ArrayList<>(); + final String defaultMessage = new StringBuilder("The parameter `" + timeValueAsString + "` is not in correct format.") + .toString(); + final ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.TimeFormat", defaultMessage, + parameterName); + dataValidationErrors.add(error); + throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", + dataValidationErrors, e); + } + + } + } + return value; + } + + public LocalDateTime extractLocalDateTimeNamed(final String parameterName, final JsonElement element, final String timeFormat, final Locale clientApplicationLocale, final Set parametersPassedInCommand) { LocalDateTime value = null; String timeValueAsString = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java index ae7c28687..833662da1 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java @@ -18,9 +18,6 @@ */ package org.apache.fineract.infrastructure.core.service; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; @@ -29,8 +26,6 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.temporal.ChronoUnit; import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; import java.util.List; import java.util.TimeZone; import org.apache.fineract.infrastructure.core.data.ApiParameterError; @@ -68,26 +63,6 @@ public final class DateUtils { return zone; } - public static Date getDateOfTenant() { - return convertLocalDateToDate(getLocalDateOfTenant()); - } - - private static Date convertLocalDateToDate(LocalDate localDate) { - return createDate(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth()); - } - - public static LocalDate convertToLocalDate(final Date dateToConvert, final ZoneId zoneId) { - return dateToConvert.toInstant().atZone(zoneId).toLocalDate(); - } - - public static Date createDate(int year, int month, int day) { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, year); - cal.set(Calendar.MONTH, month - 1); - cal.set(Calendar.DAY_OF_MONTH, day); - return cal.getTime(); - } - public static LocalDate getLocalDateOfTenant() { final ZoneId zone = getDateTimeZoneOfTenant(); return LocalDate.now(zone); @@ -98,17 +73,8 @@ public final class DateUtils { return LocalDateTime.now(zone).truncatedTo(ChronoUnit.SECONDS); } - public static Date parseDate(final String stringDate, final String pattern, final ZoneId zoneId) { - try { - return new SimpleDateFormat(pattern).parse(stringDate); - } catch (final ParseException e) { - final List dataValidationErrors = new ArrayList<>(); - final ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.date.pattern", - "The parameter date (" + stringDate + ") is invalid w.r.t. pattern " + pattern, "date", stringDate, pattern); - dataValidationErrors.add(error); - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", - dataValidationErrors, e); - } + public static LocalDateTime getLocalDateTimeOfSystem() { + return LocalDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.SECONDS); } public static LocalDate parseLocalDate(final String stringDate, final String pattern, final ZoneId zoneId) { @@ -136,12 +102,6 @@ public final class DateUtils { return parseLocalDate(stringDate, pattern, getDateTimeZoneOfTenant()); } - public static String formatToSqlDate(final Date date) { - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - df.setTimeZone(getTimeZoneOfTenant()); - return df.format(date); - } - public static boolean isDateInTheFuture(final LocalDate localDate) { return localDate.isAfter(getLocalDateOfTenant()); } @@ -150,8 +110,4 @@ public final class DateUtils { return ThreadLocalContextUtil.getBusinessDate(); } - public static Date getBusinessDate() { - return Date.from(ThreadLocalContextUtil.getBusinessDate().atStartOfDay(ZoneId.systemDefault()).toInstant()); - } - } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/domain/CreditBureauToken.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/domain/CreditBureauToken.java index 3734dff92..c93807f1a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/domain/CreditBureauToken.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/domain/CreditBureauToken.java @@ -19,10 +19,9 @@ package org.apache.fineract.infrastructure.creditbureau.domain; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; @@ -53,7 +52,7 @@ public class CreditBureauToken extends AbstractPersistableCustom { private String issued; @Column(name = "expiry_date") - private Date expires; + private LocalDate expires; public static CreditBureauToken fromJson(final JsonCommand command) { final String userName = command.stringValueOfParameterNamed("userName"); @@ -63,19 +62,14 @@ public class CreditBureauToken extends AbstractPersistableCustom { final String issued = command.stringValueOfParameterNamed(".issued"); final String expiry = command.stringValueOfParameterNamed(".expires"); - SimpleDateFormat dateformat = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss zzz", Locale.ENGLISH); + DateTimeFormatter dateformat = new DateTimeFormatterBuilder().appendPattern("EEE, dd MMM yyyy kk:mm:ss zzz").toFormatter(); - Date expires = null; - try { - expires = dateformat.parse(expiry); - } catch (ParseException Ex) { - LOG.error("Error occured while converting Date(String) to SimpleDateFormat", Ex); - } + LocalDate expires = LocalDate.parse(expiry, dateformat); return new CreditBureauToken(userName, accessToken, tokenType, expiresIn, issued, expires); } - public CreditBureauToken(String userName, String accessToken, String tokenType, String expiresIn, String issued, Date expires) { + public CreditBureauToken(String userName, String accessToken, String tokenType, String expiresIn, String issued, LocalDate expires) { this.userName = userName; this.accessToken = accessToken; this.tokenType = tokenType; @@ -109,7 +103,7 @@ public class CreditBureauToken extends AbstractPersistableCustom { this.accessToken = tokens; } - public Date getTokenExpiryDate() { + public LocalDate getTokenExpiryDate() { return this.expires; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl.java index 926b4bbc9..c6819772a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl.java @@ -27,8 +27,8 @@ import com.google.gson.JsonParser; import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.List; import okhttp3.HttpUrl; import okhttp3.MediaType; @@ -45,6 +45,7 @@ import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauConfigurations; import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauReportData; import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauConfiguration; @@ -412,10 +413,10 @@ public class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl implemen // check the expiry date of the previous token. if (creditBureauToken != null) { - Date current = new Date(); - Date getExpiryDate = creditBureauToken.getTokenExpiryDate(); + LocalDate current = DateUtils.getLocalDateOfTenant(); + LocalDate getExpiryDate = creditBureauToken.getTokenExpiryDate(); - if (getExpiryDate.before(current)) { + if (getExpiryDate.isBefore(current)) { this.tokenRepositoryWrapper.delete(creditBureauToken); creditBureauToken = null; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/data/FineractEntityToEntityMappingData.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/data/FineractEntityToEntityMappingData.java index 56d7f1cad..47332297e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/data/FineractEntityToEntityMappingData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/data/FineractEntityToEntityMappingData.java @@ -19,7 +19,7 @@ package org.apache.fineract.infrastructure.entityaccess.data; import java.io.Serializable; -import java.util.Date; +import java.time.LocalDate; public final class FineractEntityToEntityMappingData implements Serializable { @@ -36,10 +36,10 @@ public final class FineractEntityToEntityMappingData implements Serializable { private Long toId; @SuppressWarnings("unused") - private Date startDate; + private LocalDate startDate; @SuppressWarnings("unused") - private Date endDate; + private LocalDate endDate; @SuppressWarnings("unused") private final String fromEntity; @@ -48,7 +48,7 @@ public final class FineractEntityToEntityMappingData implements Serializable { private final String toEntity; private FineractEntityToEntityMappingData(final Long mapId, final Long relationId, final Long fromId, final Long toId, - final Date startDate, final Date endDate, final String fromEntity, final String toEntity) { + final LocalDate startDate, final LocalDate endDate, final String fromEntity, final String toEntity) { this.mapId = mapId; this.relationId = relationId; this.fromId = fromId; @@ -60,14 +60,14 @@ public final class FineractEntityToEntityMappingData implements Serializable { } public static FineractEntityToEntityMappingData getRelatedEntities(final Long mapId, final Long relationId, final Long fromId, - final Long toId, final Date startDate, final Date endDate, final String fromEntity, final String toEntity) { + final Long toId, final LocalDate startDate, final LocalDate endDate, final String fromEntity, final String toEntity) { return new FineractEntityToEntityMappingData(mapId, relationId, fromId, toId, startDate, endDate, fromEntity, toEntity); } public static FineractEntityToEntityMappingData getRelatedEntities(final Long relationId, final Long fromId, final Long toId, - final Date startDate, final Date endDate) { + final LocalDate startDate, final LocalDate endDate) { final Long mapId = null; final String fromEntity = null; final String toEntity = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessReadServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessReadServiceImpl.java index 9b896fa3f..54dcced13 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessReadServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessReadServiceImpl.java @@ -18,10 +18,11 @@ */ package org.apache.fineract.infrastructure.entityaccess.service; +import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import org.apache.fineract.infrastructure.entityaccess.data.FineractEntityRelationData; import org.apache.fineract.infrastructure.entityaccess.data.FineractEntityToEntityMappingData; import org.apache.fineract.infrastructure.entityaccess.domain.FineractEntityAccessType; @@ -242,7 +243,9 @@ public class FineractEntityAccessReadServiceImpl implements FineractEntityAccess final Long toId = rs.getLong("toId"); final Date startDate = rs.getDate("startDate"); final Date endDate = rs.getDate("endDate"); - return FineractEntityToEntityMappingData.getRelatedEntities(relId, fromId, toId, startDate, endDate); + final LocalDate startLocalDate = startDate != null ? startDate.toLocalDate() : null; + final LocalDate endLocalDate = endDate != null ? endDate.toLocalDate() : null; + return FineractEntityToEntityMappingData.getRelatedEntities(relId, fromId, toId, startLocalDate, endLocalDate); } } @@ -314,8 +317,10 @@ public class FineractEntityAccessReadServiceImpl implements FineractEntityAccess final String toEntity = rs.getString("to_name"); final Date startDate = rs.getDate("startDate"); final Date endDate = rs.getDate("endDate"); - return FineractEntityToEntityMappingData.getRelatedEntities(mapId, relId, fromId, toId, startDate, endDate, fromEntity, - toEntity); + final LocalDate startLocalDate = startDate != null ? startDate.toLocalDate() : null; + final LocalDate endLocalDate = endDate != null ? endDate.toLocalDate() : null; + return FineractEntityToEntityMappingData.getRelatedEntities(mapId, relId, fromId, toId, startLocalDate, endLocalDate, + fromEntity, toEntity); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/domain/DeviceRegistration.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/domain/DeviceRegistration.java index 46512f7fb..4db4c7efd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/domain/DeviceRegistration.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/domain/DeviceRegistration.java @@ -18,14 +18,12 @@ */ package org.apache.fineract.infrastructure.gcm.domain; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.portfolio.client.domain.Client; @@ -42,15 +40,14 @@ public final class DeviceRegistration extends AbstractPersistableCustom { private String registrationId; @Column(name = "updatedon_date", nullable = false) - @Temporal(TemporalType.TIMESTAMP) - private Date updatedOnDate; + private LocalDateTime updatedOnDate; private DeviceRegistration() {} private DeviceRegistration(final Client client, final String registrationId) { this.client = client; this.registrationId = registrationId; - this.updatedOnDate = Date.from(DateUtils.getLocalDateTimeOfTenant().atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.updatedOnDate = DateUtils.getLocalDateTimeOfTenant(); } public static DeviceRegistration instance(final Client client, final String registrationId) { @@ -73,11 +70,11 @@ public final class DeviceRegistration extends AbstractPersistableCustom { this.registrationId = registrationId; } - public Date getUpdatedOnDate() { + public LocalDateTime getUpdatedOnDate() { return this.updatedOnDate; } - public void setUpdatedOnDate(Date updatedOnDate) { + public void setUpdatedOnDate(LocalDateTime updatedOnDate) { this.updatedOnDate = updatedOnDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/domain/DeviceRegistrationData.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/domain/DeviceRegistrationData.java index 9de71ba3a..7498c1a1e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/domain/DeviceRegistrationData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/domain/DeviceRegistrationData.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.infrastructure.gcm.domain; -import java.util.Date; +import java.time.LocalDateTime; import org.apache.fineract.portfolio.client.data.ClientData; public final class DeviceRegistrationData { @@ -26,9 +26,10 @@ public final class DeviceRegistrationData { public Long id; public ClientData clientData; public String registrationId; - public Date updatedOnDate; + public LocalDateTime updatedOnDate; - private DeviceRegistrationData(final Long id, final ClientData clientData, final String registrationId, final Date updatedOnDate) { + private DeviceRegistrationData(final Long id, final ClientData clientData, final String registrationId, + final LocalDateTime updatedOnDate) { this.id = id; this.clientData = clientData; this.registrationId = registrationId; @@ -36,7 +37,7 @@ public final class DeviceRegistrationData { } public static DeviceRegistrationData instance(final Long id, final ClientData clientData, final String registrationId, - final Date updatedOnDate) { + final LocalDateTime updatedOnDate) { return new DeviceRegistrationData(id, clientData, registrationId, updatedOnDate); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationReadPlatformServiceImpl.java index 77716e049..f1a980ccb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationReadPlatformServiceImpl.java @@ -20,10 +20,8 @@ package org.apache.fineract.infrastructure.gcm.service; import java.sql.ResultSet; import java.sql.SQLException; -import java.time.LocalDate; -import java.time.ZoneId; +import java.time.LocalDateTime; import java.util.Collection; -import java.util.Date; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; import org.apache.fineract.infrastructure.gcm.domain.DeviceRegistrationData; import org.apache.fineract.infrastructure.gcm.exception.DeviceRegistrationNotFoundException; @@ -68,13 +66,12 @@ public class DeviceRegistrationReadPlatformServiceImpl implements DeviceRegistra public DeviceRegistrationData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { final Long id = JdbcSupport.getLong(rs, "id"); - final LocalDate updatedOnDate = JdbcSupport.getLocalDate(rs, "updatedOnDate"); + final LocalDateTime updatedOnDate = JdbcSupport.getLocalDateTime(rs, "updatedOnDate"); final String registrationId = rs.getString("registrationId"); final Long clientId = rs.getLong("clientId"); final String clientName = rs.getString("clientName"); ClientData clientData = ClientData.instance(clientId, clientName); - return DeviceRegistrationData.instance(id, clientData, registrationId, - Date.from(updatedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); + return DeviceRegistrationData.instance(id, clientData, registrationId, updatedOnDate); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationWritePlatformServiceImpl.java index 704c6e0bd..1c71642c1 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationWritePlatformServiceImpl.java @@ -18,7 +18,6 @@ */ package org.apache.fineract.infrastructure.gcm.service; -import java.util.Date; import javax.persistence.EntityExistsException; import javax.persistence.PersistenceException; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -94,8 +93,7 @@ public class DeviceRegistrationWritePlatformServiceImpl implements DeviceRegistr Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId); deviceRegistration.setClient(client); deviceRegistration.setRegistrationId(registrationId); - deviceRegistration - .setUpdatedOnDate(Date.from(DateUtils.getLocalDateTimeOfTenant().atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + deviceRegistration.setUpdatedOnDate(DateUtils.getLocalDateTimeOfTenant()); return deviceRegistration; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/NotificationSenderService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/NotificationSenderService.java index 3de6c6382..6b0c1cfab 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/NotificationSenderService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/NotificationSenderService.java @@ -19,10 +19,8 @@ package org.apache.fineract.infrastructure.gcm.service; import java.io.IOException; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -109,8 +107,7 @@ public class NotificationSenderService { res = s.send(msg, registrationId, 3); if (res.getSuccess() != null && res.getSuccess() > 0) { smsMessage.setStatusType(SmsMessageStatusType.SENT.getValue()); - smsMessage.setDeliveredOnDate( - Date.from(DateUtils.getLocalDateOfTenant().atStartOfDay(ZoneId.systemDefault()).toInstant())); + smsMessage.setDeliveredOnDate(DateUtils.getLocalDateTimeOfTenant()); } else if (res.getFailure() != null && res.getFailure() > 0) { smsMessage.setStatusType(SmsMessageStatusType.FAILED.getValue()); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJob.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJob.java index 1035c0d0e..2ab21a1ae 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJob.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJob.java @@ -19,9 +19,7 @@ package org.apache.fineract.infrastructure.reportmailingjob.domain; import java.time.LocalDateTime; -import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; -import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; import javax.persistence.Column; @@ -29,8 +27,6 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.core.api.JsonCommand; @@ -55,8 +51,7 @@ public class ReportMailingJob extends AbstractAuditableCustom { private String description; @Column(name = "start_datetime", nullable = false) - @Temporal(TemporalType.TIMESTAMP) - private Date startDateTime; + private LocalDateTime startDateTime; @Column(name = "recurrence", nullable = true) private String recurrence; @@ -81,12 +76,10 @@ public class ReportMailingJob extends AbstractAuditableCustom { private String stretchyReportParamMap; @Column(name = "previous_run_datetime", nullable = true) - @Temporal(TemporalType.TIMESTAMP) - private Date previousRunDateTime; + private LocalDateTime previousRunDateTime; @Column(name = "next_run_datetime", nullable = true) - @Temporal(TemporalType.TIMESTAMP) - private Date nextRunDateTime; + private LocalDateTime nextRunDateTime; @Column(name = "previous_run_status", nullable = true) private String previousRunStatus; @@ -129,7 +122,7 @@ public class ReportMailingJob extends AbstractAuditableCustom { this.startDateTime = null; if (startDateTime != null) { - this.startDateTime = Date.from(startDateTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.startDateTime = startDateTime; } this.recurrence = recurrence; @@ -142,13 +135,13 @@ public class ReportMailingJob extends AbstractAuditableCustom { this.previousRunDateTime = null; if (previousRunDateTime != null) { - this.previousRunDateTime = Date.from(previousRunDateTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.previousRunDateTime = previousRunDateTime; } this.nextRunDateTime = null; if (nextRunDateTime != null) { - this.nextRunDateTime = Date.from(nextRunDateTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.nextRunDateTime = nextRunDateTime; } this.previousRunStatus = null; @@ -307,14 +300,12 @@ public class ReportMailingJob extends AbstractAuditableCustom { final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(jsonCommand.dateFormat()) .withLocale(jsonCommand.extractLocale()); final LocalDateTime newStartDateTime = LocalDateTime.parse(newStartDateTimeString, dateTimeFormatter); - final LocalDateTime oldStartDateTime = (this.startDateTime != null) - ? ZonedDateTime.ofInstant(this.startDateTime.toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDateTime() - : null; + final LocalDateTime oldStartDateTime = this.startDateTime; if ((oldStartDateTime != null) && !newStartDateTime.equals(oldStartDateTime)) { actualChanges.put(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME, newStartDateTimeString); - this.startDateTime = Date.from(newStartDateTime.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.startDateTime = newStartDateTime; } } @@ -374,9 +365,8 @@ public class ReportMailingJob extends AbstractAuditableCustom { /** * @return the value of the startDateTime property **/ - public ZonedDateTime getStartDateTime() { - return (this.startDateTime != null) ? ZonedDateTime.ofInstant(this.startDateTime.toInstant(), DateUtils.getDateTimeZoneOfTenant()) - : null; + public LocalDateTime getStartDateTime() { + return this.startDateTime; } /** @@ -459,19 +449,15 @@ public class ReportMailingJob extends AbstractAuditableCustom { /** * @return the previousRunDateTime */ - public ZonedDateTime getPreviousRunDateTime() { - return (this.previousRunDateTime != null) - ? ZonedDateTime.ofInstant(this.previousRunDateTime.toInstant(), DateUtils.getDateTimeZoneOfTenant()) - : null; + public LocalDateTime getPreviousRunDateTime() { + return this.previousRunDateTime; } /** * @return the nextRunDateTime */ - public ZonedDateTime getNextRunDateTime() { - return (this.nextRunDateTime != null) - ? ZonedDateTime.ofInstant(this.nextRunDateTime.toInstant(), DateUtils.getDateTimeZoneOfTenant()) - : null; + public LocalDateTime getNextRunDateTime() { + return this.nextRunDateTime; } /** @@ -538,9 +524,9 @@ public class ReportMailingJob extends AbstractAuditableCustom { * -- previous run date * **/ - public void updatePreviousRunDateTime(final ZonedDateTime previousRunDateTime) { + public void updatePreviousRunDateTime(final LocalDateTime previousRunDateTime) { if (previousRunDateTime != null) { - this.previousRunDateTime = Date.from(previousRunDateTime.toInstant()); + this.previousRunDateTime = previousRunDateTime; } } @@ -551,9 +537,9 @@ public class ReportMailingJob extends AbstractAuditableCustom { * -- the next run DateTime * **/ - public void updateNextRunDateTime(final ZonedDateTime nextRunDateTime) { + public void updateNextRunDateTime(final LocalDateTime nextRunDateTime) { if (nextRunDateTime != null) { - this.nextRunDateTime = Date.from(nextRunDateTime.toInstant()); + this.nextRunDateTime = nextRunDateTime; } else { diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRunHistory.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRunHistory.java index a05284e20..50162da4a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRunHistory.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRunHistory.java @@ -18,17 +18,13 @@ */ package org.apache.fineract.infrastructure.reportmailingjob.domain; -import java.time.ZonedDateTime; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; @Entity @Table(name = "m_report_mailing_job_run_history") @@ -41,12 +37,10 @@ public class ReportMailingJobRunHistory extends AbstractPersistableCustom { private ReportMailingJob reportMailingJob; @Column(name = "start_datetime", nullable = false) - @Temporal(TemporalType.TIMESTAMP) - private Date startDateTime; + private LocalDateTime startDateTime; @Column(name = "end_datetime", nullable = false) - @Temporal(TemporalType.TIMESTAMP) - private Date endDateTime; + private LocalDateTime endDateTime; @Column(name = "status", nullable = false) private String status; @@ -65,19 +59,19 @@ public class ReportMailingJobRunHistory extends AbstractPersistableCustom { /** * ReportMailingJobRunHistory private constructor **/ - private ReportMailingJobRunHistory(final ReportMailingJob reportMailingJob, final ZonedDateTime startDateTime, - final ZonedDateTime endDateTime, final String status, final String errorMessage, final String errorLog) { + private ReportMailingJobRunHistory(final ReportMailingJob reportMailingJob, final LocalDateTime startDateTime, + final LocalDateTime endDateTime, final String status, final String errorMessage, final String errorLog) { this.reportMailingJob = reportMailingJob; this.startDateTime = null; if (startDateTime != null) { - this.startDateTime = Date.from(startDateTime.toInstant()); + this.startDateTime = startDateTime; } this.endDateTime = null; if (endDateTime != null) { - this.endDateTime = Date.from(endDateTime.toInstant()); + this.endDateTime = endDateTime; } this.status = status; @@ -90,8 +84,8 @@ public class ReportMailingJobRunHistory extends AbstractPersistableCustom { * * @return ReportMailingJobRunHistory object **/ - public static ReportMailingJobRunHistory newInstance(final ReportMailingJob reportMailingJob, final ZonedDateTime startDateTime, - final ZonedDateTime endDateTime, final String status, final String errorMessage, final String errorLog) { + public static ReportMailingJobRunHistory newInstance(final ReportMailingJob reportMailingJob, final LocalDateTime startDateTime, + final LocalDateTime endDateTime, final String status, final String errorMessage, final String errorLog) { return new ReportMailingJobRunHistory(reportMailingJob, startDateTime, endDateTime, status, errorMessage, errorLog); } @@ -105,17 +99,15 @@ public class ReportMailingJobRunHistory extends AbstractPersistableCustom { /** * @return the startDateTime */ - public ZonedDateTime getStartDateTime() { - return (this.startDateTime != null) ? ZonedDateTime.ofInstant(this.startDateTime.toInstant(), DateUtils.getDateTimeZoneOfTenant()) - : null; + public LocalDateTime getStartDateTime() { + return this.startDateTime; } /** * @return the endDateTime */ - public ZonedDateTime getEndDateTime() { - return (this.endDateTime != null) ? ZonedDateTime.ofInstant(this.endDateTime.toInstant(), DateUtils.getDateTimeZoneOfTenant()) - : null; + public LocalDateTime getEndDateTime() { + return this.endDateTime; } /** diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/service/ReportMailingJobWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/service/ReportMailingJobWritePlatformServiceImpl.java index dc7725baf..d65368adb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/service/ReportMailingJobWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/service/ReportMailingJobWritePlatformServiceImpl.java @@ -23,9 +23,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.time.Duration; -import java.time.LocalDate; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; +import java.time.LocalDateTime; import java.util.Collection; import java.util.Iterator; import java.util.Map; @@ -152,8 +150,8 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo // get the recurrence rule string final String recurrence = reportMailingJob.getRecurrence(); - // get the next run ZonedDateTime from the ReportMailingJob entity - ZonedDateTime nextRunDateTime = reportMailingJob.getNextRunDateTime(); + // get the next run LocalDateTime from the ReportMailingJob entity + LocalDateTime nextRunDateTime = reportMailingJob.getNextRunDateTime(); // check if the stretchy report id was updated if (changes.containsKey(ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME)) { @@ -169,10 +167,10 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo // go ahead if the recurrence is not null if (StringUtils.isNotBlank(recurrence)) { - // set the start ZonedDateTime to the current tenant date time - ZonedDateTime startDateTime = DateUtils.getLocalDateTimeOfTenant().atZone(DateUtils.getDateTimeZoneOfTenant()); + // set the start LocalDateTime to the current tenant date time + LocalDateTime startDateTime = DateUtils.getLocalDateTimeOfTenant(); - // check if the start ZonedDateTime was updated + // check if the start LocalDateTime was updated if (changes.containsKey(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME)) { // get the updated start DateTime startDateTime = reportMailingJob.getStartDateTime(); @@ -181,25 +179,25 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo startDateTime = reportMailingJob.getStartDateTime(); // get the next recurring DateTime - final ZonedDateTime nextRecurringDateTime = this.createNextRecurringDateTime(recurrence, startDateTime); + final LocalDateTime nextRecurringDateTime = this.createNextRecurringDateTime(recurrence, startDateTime); // update the next run time property reportMailingJob.updateNextRunDateTime(nextRecurringDateTime); - // check if the next run ZonedDateTime is not empty and the + // check if the next run LocalDateTime is not empty and the // recurrence is empty } else if (StringUtils.isBlank(recurrence) && (nextRunDateTime != null)) { - // the next run ZonedDateTime should be set to null + // the next run LocalDateTime should be set to null reportMailingJob.updateNextRunDateTime(null); } } if (changes.containsKey(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME)) { - final ZonedDateTime startDateTime = reportMailingJob.getStartDateTime(); + final LocalDateTime startDateTime = reportMailingJob.getStartDateTime(); // initially set the next recurring date time to the new start // date time - ZonedDateTime nextRecurringDateTime = startDateTime; + LocalDateTime nextRecurringDateTime = startDateTime; // ensure that the recurrence pattern string is not empty if (StringUtils.isNotBlank(recurrence)) { @@ -251,9 +249,8 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo .findByIsActiveTrueAndIsDeletedFalse(); for (ReportMailingJob reportMailingJob : reportMailingJobCollection) { - // get the tenant's date as a ZonedDateTime object - final ZonedDateTime localDateTimeOftenant = DateUtils.getLocalDateTimeOfTenant().atZone(DateUtils.getDateTimeZoneOfTenant()); - final ZonedDateTime nextRunDateTime = reportMailingJob.getNextRunDateTime(); + final LocalDateTime localDateTimeOftenant = DateUtils.getLocalDateTimeOfTenant(); + final LocalDateTime nextRunDateTime = reportMailingJob.getNextRunDateTime(); if (nextRunDateTime != null && nextRunDateTime.isBefore(localDateTimeOftenant)) { // get the emailAttachmentFileFormat enum object @@ -310,13 +307,13 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo * @param errorLog * -- StringBuilder object containing the error log if any * @param jobStartDateTime - * -- the start ZonedDateTime of the job + * -- the start LocalDateTime of the job * **/ private void updateReportMailingJobAfterJobExecution(final ReportMailingJob reportMailingJob, final StringBuilder errorLog, - final ZonedDateTime jobStartDateTime) { + final LocalDateTime jobStartDateTime) { final String recurrence = reportMailingJob.getRecurrence(); - final ZonedDateTime nextRunDateTime = reportMailingJob.getNextRunDateTime(); + final LocalDateTime nextRunDateTime = reportMailingJob.getNextRunDateTime(); ReportMailingJobPreviousRunStatus reportMailingJobPreviousRunStatus = ReportMailingJobPreviousRunStatus.SUCCESS; reportMailingJob.updatePreviousRunErrorLog(null); @@ -339,7 +336,7 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo // job will only run once, no next run time reportMailingJob.updateNextRunDateTime(null); } else if (nextRunDateTime != null) { - final ZonedDateTime nextRecurringDateTime = this.createNextRecurringDateTime(recurrence, nextRunDateTime); + final LocalDateTime nextRecurringDateTime = this.createNextRecurringDateTime(recurrence, nextRunDateTime); // finally update the next run date time property reportMailingJob.updateNextRunDateTime(nextRecurringDateTime); @@ -354,25 +351,19 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo } /** - * create the next recurring ZonedDateTime from recurrence pattern, start ZonedDateTime and current DateTime + * create the next recurring LocalDateTime from recurrence pattern, start LocalDateTime and current DateTime * * @param recurrencePattern * @param startDateTime - * @return ZonedDateTime object + * @return LocalDateTime object */ - private ZonedDateTime createNextRecurringDateTime(final String recurrencePattern, final ZonedDateTime startDateTime) { - ZonedDateTime nextRecurringDateTime = null; + private LocalDateTime createNextRecurringDateTime(final String recurrencePattern, final LocalDateTime startDateTime) { + LocalDateTime nextRecurringDateTime = null; // the recurrence pattern/rule cannot be empty if (StringUtils.isNotBlank(recurrencePattern) && startDateTime != null) { - final LocalDate nextDayLocalDate = startDateTime.plus(Duration.ofDays(1)).toLocalDate(); - final LocalDate nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern, startDateTime.toLocalDate(), - nextDayLocalDate); - final String nextDateTimeString = nextRecurringLocalDate + " " + startDateTime.getHour() + ":" + startDateTime.getMinute() + ":" - + startDateTime.getSecond(); - final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATETIME_FORMAT); - - nextRecurringDateTime = ZonedDateTime.parse(nextDateTimeString, dateTimeFormatter); + final LocalDateTime nextDayLocalDate = startDateTime.plus(Duration.ofDays(1)); + nextRecurringDateTime = CalendarUtils.getNextRecurringDate(recurrencePattern, startDateTime, nextDayLocalDate); } return nextRecurringDateTime; @@ -386,14 +377,14 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo * @param errorLog * -- StringBuilder object containing the error log if any * @param jobStartDateTime - * -- the start ZonedDateTime of the job + * -- the start LocalDateTime of the job * @param jobRunStatus * -- the status of the job (success/error) * **/ private void createReportMailingJobRunHistroryAfterJobExecution(final ReportMailingJob reportMailingJob, final StringBuilder errorLog, - final ZonedDateTime jobStartDateTime, final String jobRunStatus) { - final ZonedDateTime jobEndDateTime = DateUtils.getLocalDateTimeOfTenant().atZone(DateUtils.getDateTimeZoneOfTenant()); + final LocalDateTime jobStartDateTime, final String jobRunStatus) { + final LocalDateTime jobEndDateTime = DateUtils.getLocalDateTimeOfTenant(); final String errorLogToString = (errorLog != null) ? errorLog.toString() : null; final ReportMailingJobRunHistory reportMailingJobRunHistory = ReportMailingJobRunHistory.newInstance(reportMailingJob, jobStartDateTime, jobEndDateTime, jobRunStatus, null, errorLogToString); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/util/ReportMailingJobDateUtil.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/util/ReportMailingJobDateUtil.java index 78faba058..553fee900 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/util/ReportMailingJobDateUtil.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/util/ReportMailingJobDateUtil.java @@ -18,9 +18,7 @@ */ package org.apache.fineract.infrastructure.reportmailingjob.util; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobStretchyReportParamDateOption; public final class ReportMailingJobDateUtil { @@ -35,60 +33,21 @@ public final class ReportMailingJobDateUtil { * get the current date as string using the mysql date format yyyy-MM-dd **/ public static String getTodayDateAsString() { - // get a calendar instance, which defaults to "now" - Calendar calendar = Calendar.getInstance(); - - // get a date to represent "today" - Date today = calendar.getTime(); - - // get a SimpleDateFormat instance, passing the mysql date format as - // parameter - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(MYSQL_DATE_FORMAT); - - // return date as string - return simpleDateFormat.format(today); + return DateUtils.getLocalDateOfTenant().format(DateUtils.DEFAULT_DATE_FORMATER); } /** * get the yesterday's date as string using the mysql date format yyyy-MM-dd **/ public static String getYesterdayDateAsString() { - // get a calendar instance, which defaults to "now" - Calendar calendar = Calendar.getInstance(); - - // add one day to the date/calendar - calendar.add(Calendar.DAY_OF_YEAR, -1); - - // now get "yesterday" - Date yesterday = calendar.getTime(); - - // get a SimpleDateFormat instance, passing the mysql date format as - // parameter - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(MYSQL_DATE_FORMAT); - - // return date as string - return simpleDateFormat.format(yesterday); + return DateUtils.getLocalDateOfTenant().minusDays(1).format(DateUtils.DEFAULT_DATE_FORMATER); } /** * get the tomorrow's date as string using the mysql date format yyyy-MM-dd **/ public static String getTomorrowDateAsString() { - // get a calendar instance, which defaults to "now" - Calendar calendar = Calendar.getInstance(); - - // add one day to the date/calendar - calendar.add(Calendar.DAY_OF_YEAR, 1); - - // now get "tomorrow" - Date tomorrow = calendar.getTime(); - - // get a SimpleDateFormat instance, passing the mysql date format as - // parameter - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(MYSQL_DATE_FORMAT); - - // return date as string - return simpleDateFormat.format(tomorrow); + return DateUtils.getLocalDateOfTenant().plusDays(1).format(DateUtils.DEFAULT_DATE_FORMATER); } /** diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/domain/TFAccessToken.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/domain/TFAccessToken.java index 55934757e..9975cd495 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/domain/TFAccessToken.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/domain/TFAccessToken.java @@ -19,15 +19,11 @@ package org.apache.fineract.infrastructure.security.domain; import java.time.LocalDateTime; -import java.time.ZonedDateTime; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.service.DateUtils; @@ -46,13 +42,11 @@ public class TFAccessToken extends AbstractPersistableCustom { @JoinColumn(name = "appuser_id", nullable = false) private AppUser user; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "valid_from", nullable = false) - private Date validFrom; + private LocalDateTime validFrom; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "valid_to", nullable = false) - private Date validTo; + private LocalDateTime validTo; @Column(name = "enabled", nullable = false) private boolean enabled; @@ -60,13 +54,13 @@ public class TFAccessToken extends AbstractPersistableCustom { public TFAccessToken() {} public static TFAccessToken create(String token, AppUser user, int tokenLiveTimeInSec) { - ZonedDateTime validFrom = DateUtils.getLocalDateTimeOfTenant().atZone(DateUtils.getDateTimeZoneOfTenant()); - ZonedDateTime validTo = validFrom.plusSeconds(tokenLiveTimeInSec); + LocalDateTime validFrom = DateUtils.getLocalDateTimeOfTenant(); + LocalDateTime validTo = validFrom.plusSeconds(tokenLiveTimeInSec); - return new TFAccessToken(token, user, Date.from(validFrom.toInstant()), Date.from(validTo.toInstant()), true); + return new TFAccessToken(token, user, validFrom, validTo, true); } - public TFAccessToken(String token, AppUser user, Date validFrom, Date validTo, boolean enabled) { + public TFAccessToken(String token, AppUser user, LocalDateTime validFrom, LocalDateTime validTo, boolean enabled) { this.token = token; this.user = user; this.validFrom = validFrom; @@ -96,11 +90,11 @@ public class TFAccessToken extends AbstractPersistableCustom { } public LocalDateTime getValidFromDate() { - return ZonedDateTime.ofInstant(validFrom.toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDateTime(); + return validFrom; } public LocalDateTime getValidToDate() { - return ZonedDateTime.ofInstant(validTo.toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDateTime(); + return validTo; } public void setToken(String token) { @@ -111,11 +105,11 @@ public class TFAccessToken extends AbstractPersistableCustom { this.user = user; } - public void setValidFrom(Date validFrom) { + public void setValidFrom(LocalDateTime validFrom) { this.validFrom = validFrom; } - public void setValidTo(Date validTo) { + public void setValidTo(LocalDateTime validTo) { this.validTo = validTo; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/service/SpringSecurityPlatformSecurityContext.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/service/SpringSecurityPlatformSecurityContext.java index c48490fd8..3052ca416 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/service/SpringSecurityPlatformSecurityContext.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/service/SpringSecurityPlatformSecurityContext.java @@ -18,9 +18,8 @@ */ package org.apache.fineract.infrastructure.security.service; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; import java.util.List; import org.apache.fineract.commands.domain.CommandWrapper; import org.apache.fineract.commands.service.CommandWrapperBuilder; @@ -149,15 +148,11 @@ public class SpringSecurityPlatformSecurityContext implements PlatformSecurityCo if (this.configurationDomainService.isPasswordForcedResetEnable() && !currentUser.getPasswordNeverExpires()) { Long passwordDurationDays = this.configurationDomainService.retrievePasswordLiveTime(); - final Date passWordLastUpdateDate = currentUser.getLastTimePasswordUpdated(); + final LocalDate passWordLastUpdateDate = currentUser.getLastTimePasswordUpdated(); - Calendar c = Calendar.getInstance(); - c.setTime(passWordLastUpdateDate); - c.add(Calendar.DATE, passwordDurationDays.intValue()); + final LocalDate passwordExpirationDate = passWordLastUpdateDate.plusDays(passwordDurationDays); - final Date passwordExpirationDate = c.getTime(); - - if (DateUtils.getDateOfTenant().after(passwordExpirationDate)) { + if (DateUtils.getLocalDateOfTenant().isAfter(passwordExpirationDate)) { return true; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/api/SmsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/api/SmsApiResource.java index f8bf7c964..8b9f56b83 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/api/SmsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/api/SmsApiResource.java @@ -19,8 +19,8 @@ package org.apache.fineract.infrastructure.sms.api; import io.swagger.v3.oas.annotations.tags.Tag; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -121,11 +121,11 @@ public class SmsApiResource { final SearchParameters searchParameters = SearchParameters.forSMSCampaign(sqlSearch, offset, limit, orderBy, sortOrder); - Date fromDate = null; + LocalDate fromDate = null; if (fromDateParam != null) { fromDate = fromDateParam.getDate("fromDate", dateFormat, locale); } - Date toDate = null; + LocalDate toDate = null; if (toDateParam != null) { toDate = toDateParam.getDate("toDate", dateFormat, locale); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/domain/SmsMessage.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/domain/SmsMessage.java index 34a811164..8b2590c7b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/domain/SmsMessage.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/domain/SmsMessage.java @@ -18,7 +18,8 @@ */ package org.apache.fineract.infrastructure.sms.domain; -import java.util.Date; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.LinkedHashMap; import java.util.Map; import javax.persistence.Column; @@ -26,8 +27,6 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.campaigns.sms.domain.SmsCampaign; import org.apache.fineract.infrastructure.core.api.JsonCommand; @@ -77,12 +76,10 @@ public class SmsMessage extends AbstractPersistableCustom { // private String campaignName; @Column(name = "submittedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date submittedOnDate; + private LocalDate submittedOnDate; @Column(name = "delivered_on_date", nullable = true) - @Temporal(TemporalType.TIMESTAMP) - private Date deliveredOnDate; + private LocalDateTime deliveredOnDate; @Column(name = "is_notification", nullable = true) private boolean isNotification; @@ -120,7 +117,7 @@ public class SmsMessage extends AbstractPersistableCustom { this.mobileNo = mobileNo; this.message = message; this.smsCampaign = smsCampaign; - this.submittedOnDate = DateUtils.getBusinessDate(); + this.submittedOnDate = DateUtils.getBusinessLocalDate(); this.isNotification = isNotification; } @@ -177,15 +174,15 @@ public class SmsMessage extends AbstractPersistableCustom { this.statusType = statusType; } - public Date getSubmittedOnDate() { + public LocalDate getSubmittedOnDate() { return this.submittedOnDate; } - public Date getDeliveredOnDate() { + public LocalDateTime getDeliveredOnDate() { return this.deliveredOnDate; } - public void setDeliveredOnDate(final Date deliveredOnDate) { + public void setDeliveredOnDate(final LocalDateTime deliveredOnDate) { this.deliveredOnDate = deliveredOnDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsReadPlatformService.java index ab1241933..48634eed6 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsReadPlatformService.java @@ -18,8 +18,8 @@ */ package org.apache.fineract.infrastructure.sms.service; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.SearchParameters; @@ -39,7 +39,8 @@ public interface SmsReadPlatformService { Collection retrieveAllFailed(Integer limit); - Page retrieveSmsByStatus(Long campaignId, SearchParameters searchParameters, Integer status, Date dateFrom, Date dateTo); + Page retrieveSmsByStatus(Long campaignId, SearchParameters searchParameters, Integer status, LocalDate dateFrom, + LocalDate dateTo); List retrieveExternalIdsOfAllSent(Integer limit); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsReadPlatformServiceImpl.java index 2a32c2c23..57911176c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsReadPlatformServiceImpl.java @@ -20,14 +20,13 @@ package org.apache.fineract.infrastructure.sms.service; import java.sql.ResultSet; import java.sql.SQLException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.PaginationHelper; import org.apache.fineract.infrastructure.core.service.SearchParameters; @@ -203,7 +202,7 @@ public class SmsReadPlatformServiceImpl implements SmsReadPlatformService { @Override public Page retrieveSmsByStatus(final Long campaignId, final SearchParameters searchParameters, final Integer status, - final Date dateFrom, final Date dateTo) { + final LocalDate dateFrom, final LocalDate dateTo) { final StringBuilder sqlBuilder = new StringBuilder(200); final Object[] objectArray = new Object[10]; int arrayPos = 0; @@ -219,9 +218,8 @@ public class SmsReadPlatformServiceImpl implements SmsReadPlatformService { String fromDateString = null; String toDateString = null; if (dateFrom != null && dateTo != null) { - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - fromDateString = df.format(dateFrom); - toDateString = df.format(dateTo); + fromDateString = DateUtils.DEFAULT_DATE_FORMATER.format(dateFrom); + toDateString = DateUtils.DEFAULT_DATE_FORMATER.format(dateTo); sqlBuilder.append(" and smo.submittedon_date >= ? and smo.submittedon_date <= ? "); objectArray[arrayPos] = fromDateString; arrayPos = arrayPos + 1; diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/service/ReadSurveyServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/service/ReadSurveyServiceImpl.java index 60fc109c7..10d886927 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/service/ReadSurveyServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/service/ReadSurveyServiceImpl.java @@ -18,11 +18,8 @@ */ package org.apache.fineract.infrastructure.survey.service; -import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.dataqueries.api.DataTableApiConstant; import org.apache.fineract.infrastructure.dataqueries.data.DatatableData; import org.apache.fineract.infrastructure.dataqueries.data.GenericResultsetData; @@ -137,9 +134,7 @@ public class ReadSurveyServiceImpl implements ReadSurveyService { while (rs.next()) { scoresOverviews.add(new ClientScoresOverview(rs.getString("code"), rs.getString("name"), rs.getLong("score"), - rs.getDouble("poverty_line"), - LocalDate.ofInstant(new Date(rs.getTimestamp("date").getTime()).toInstant(), DateUtils.getDateTimeZoneOfTenant()), - rs.getLong("id"), surveyName)); + rs.getDouble("poverty_line"), rs.getDate("date").toLocalDate(), rs.getLong("id"), surveyName)); } return scoresOverviews; @@ -168,9 +163,7 @@ public class ReadSurveyServiceImpl implements ReadSurveyService { while (rs.next()) { scoresOverviews.add(new ClientScoresOverview(rs.getString("code"), rs.getString("name"), rs.getLong("score"), - rs.getDouble("poverty_line"), - LocalDate.ofInstant(new Date(rs.getTimestamp("date").getTime()).toInstant(), DateUtils.getDateTimeZoneOfTenant()), - rs.getLong("id"), rs.getString("surveyName"))); + rs.getDouble("poverty_line"), rs.getDate("date").toLocalDate(), rs.getLong("id"), rs.getString("surveyName"))); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/interoperation/data/InteropRequestData.java b/fineract-provider/src/main/java/org/apache/fineract/interoperation/data/InteropRequestData.java index f7c1ff474..7e5bc1065 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/interoperation/data/InteropRequestData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/interoperation/data/InteropRequestData.java @@ -193,12 +193,12 @@ public class InteropRequestData { String locale = jsonHelper.extractStringNamed(PARAM_LOCALE, element); LocalDateTime expiration = locale == null - ? jsonHelper.extractLocalTimeNamed(PARAM_EXPIRATION, element, ISO8601_DATE_TIME_FORMAT, DEFAULT_LOCALE) - : jsonHelper.extractLocalTimeNamed(PARAM_EXPIRATION, element); // PARAM_DATE_FORMAT - // also - // must - // be - // set + ? jsonHelper.extractLocalDateTimeNamed(PARAM_EXPIRATION, element, ISO8601_DATE_TIME_FORMAT, DEFAULT_LOCALE) + : jsonHelper.extractLocalDateTimeNamed(PARAM_EXPIRATION, element); // PARAM_DATE_FORMAT + // also + // must + // be + // set JsonArray extensionArray = jsonHelper.extractJsonArrayNamed(PARAM_EXTENSION_LIST, element); ArrayList extensionList = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/interoperation/domain/InteropIdentifier.java b/fineract-provider/src/main/java/org/apache/fineract/interoperation/domain/InteropIdentifier.java index a4103461e..3b8eb4f32 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/interoperation/domain/InteropIdentifier.java +++ b/fineract-provider/src/main/java/org/apache/fineract/interoperation/domain/InteropIdentifier.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.interoperation.domain; -import java.util.Date; +import java.time.LocalDateTime; import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; @@ -27,8 +27,6 @@ import javax.persistence.Enumerated; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @@ -57,21 +55,19 @@ public class InteropIdentifier extends AbstractPersistableCustom { @Column(name = "created_by", nullable = false, length = 32) private String createdBy; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_on", nullable = false) - private Date createdOn; + private LocalDateTime createdOn; @Column(name = "modified_by", length = 32) private String modifiedBy; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "modified_on") - private Date modifiedOn; + private LocalDateTime modifiedOn; protected InteropIdentifier() {} public InteropIdentifier(@NotNull SavingsAccount account, @NotNull InteropIdentifierType type, @NotNull String value, String subType, - @NotNull String createdBy, @NotNull Date createdOn) { + @NotNull String createdBy, @NotNull LocalDateTime createdOn) { this.account = account; this.type = type; this.value = value; @@ -81,7 +77,7 @@ public class InteropIdentifier extends AbstractPersistableCustom { } public InteropIdentifier(@NotNull SavingsAccount account, @NotNull InteropIdentifierType type, @NotNull String createdBy, - @NotNull Date createdOn) { + @NotNull LocalDateTime createdOn) { this(account, type, null, null, createdBy, createdOn); } @@ -113,7 +109,7 @@ public class InteropIdentifier extends AbstractPersistableCustom { return createdBy; } - public Date getCreatedOn() { + public LocalDateTime getCreatedOn() { return createdOn; } @@ -125,11 +121,11 @@ public class InteropIdentifier extends AbstractPersistableCustom { this.modifiedBy = modifiedBy; } - public Date getModifiedOn() { + public LocalDateTime getModifiedOn() { return modifiedOn; } - public void setModifiedOn(Date modifiedOn) { + public void setModifiedOn(LocalDateTime modifiedOn) { this.modifiedOn = modifiedOn; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/interoperation/service/InteropServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/interoperation/service/InteropServiceImpl.java index d2533e905..81691513c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/interoperation/service/InteropServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/interoperation/service/InteropServiceImpl.java @@ -33,7 +33,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.Date; import java.util.List; import java.util.Locale; import java.util.function.Predicate; @@ -285,7 +284,7 @@ public class InteropServiceImpl implements InteropService { AppUser createdBy = getLoginUser(); InteropIdentifier identifier = new InteropIdentifier(savingsAccount, request.getIdType(), request.getIdValue(), - request.getSubIdOrType(), createdBy.getUsername(), DateUtils.getDateOfTenant()); + request.getSubIdOrType(), createdBy.getUsername(), DateUtils.getLocalDateTimeOfTenant()); identifierRepository.saveAndFlush(identifier); @@ -401,7 +400,8 @@ public class InteropServiceImpl implements InteropService { PaymentDetail paymentDetail = instance(findPaymentType(), savingsAccount.getExternalId(), null, getRoutingCode(), transferCode, null); SavingsAccountTransaction holdTransaction = SavingsAccountTransaction.holdAmount(savingsAccount, savingsAccount.office(), - paymentDetail, transactionDate, Money.of(savingsAccount.getCurrency(), total), new Date(), getLoginUser(), false); + paymentDetail, transactionDate, Money.of(savingsAccount.getCurrency(), total), DateUtils.getLocalDateTimeOfTenant(), + getLoginUser(), false); MonetaryCurrency accountCurrency = savingsAccount.getCurrency().copy(); holdTransaction.updateRunningBalance( Money.of(accountCurrency, savingsAccount.getWithdrawableBalance().subtract(holdTransaction.getAmount()))); @@ -453,8 +453,8 @@ public class InteropServiceImpl implements InteropService { } if (holdTransaction.getReleaseIdOfHoldAmountTransaction() == null) { - SavingsAccountTransaction releaseTransaction = savingsAccountTransactionRepository - .saveAndFlush(releaseAmount(holdTransaction, transactionDate, new Date(), getLoginUser())); + SavingsAccountTransaction releaseTransaction = savingsAccountTransactionRepository.saveAndFlush( + releaseAmount(holdTransaction, transactionDate, DateUtils.getLocalDateTimeOfSystem(), getLoginUser())); holdTransaction.updateReleaseId(releaseTransaction.getId()); savingsAccount.releaseOnHoldAmount(holdTransaction.getAmount()); savingsAccount.addTransaction(releaseTransaction); @@ -492,7 +492,8 @@ public class InteropServiceImpl implements InteropService { SavingsAccountTransaction holdTransaction = findTransaction(savingsAccount, request.getTransferCode(), AMOUNT_HOLD.getValue()); if (holdTransaction != null && holdTransaction.getReleaseIdOfHoldAmountTransaction() == null) { - SavingsAccountTransaction releaseTransaction = releaseAmount(holdTransaction, transactionDate, new Date(), getLoginUser()); + SavingsAccountTransaction releaseTransaction = releaseAmount(holdTransaction, transactionDate, + DateUtils.getLocalDateTimeOfSystem(), getLoginUser()); MonetaryCurrency accountCurrency = savingsAccount.getCurrency().copy(); releaseTransaction.updateRunningBalance( Money.of(accountCurrency, savingsAccount.getWithdrawableBalance().add(holdTransaction.getAmount()))); diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/domain/Notification.java b/fineract-provider/src/main/java/org/apache/fineract/notification/domain/Notification.java index 66e3c052f..a7fa46ef2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/domain/Notification.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/domain/Notification.java @@ -18,12 +18,10 @@ */ package org.apache.fineract.notification.domain; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @Entity @@ -49,13 +47,12 @@ public class Notification extends AbstractPersistableCustom { private String notificationContent; @Column(name = "created_at") - @Temporal(TemporalType.TIMESTAMP) - private Date createdAt; + private LocalDateTime createdAt; public Notification() {} public Notification(String objectType, Long objectIdentifier, String action, Long actorId, boolean isSystemGenerated, - String notificationContent, Date createdAt) { + String notificationContent, LocalDateTime createdAt) { this.objectType = objectType; this.objectIdentifier = objectIdentifier; this.action = action; diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/domain/NotificationMapper.java b/fineract-provider/src/main/java/org/apache/fineract/notification/domain/NotificationMapper.java index a75b8d1a8..4ed11829c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/domain/NotificationMapper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/domain/NotificationMapper.java @@ -18,14 +18,12 @@ */ package org.apache.fineract.notification.domain; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.useradministration.domain.AppUser; @@ -45,12 +43,11 @@ public class NotificationMapper extends AbstractPersistableCustom { private boolean isRead; @Column(name = "created_at") - @Temporal(TemporalType.TIMESTAMP) - private Date createdAt; + private LocalDateTime createdAt; public NotificationMapper() {} - public NotificationMapper(Notification notification, AppUser userId, boolean isRead, Date createdAt) { + public NotificationMapper(Notification notification, AppUser userId, boolean isRead, LocalDateTime createdAt) { this.notification = notification; this.userId = userId; this.isRead = isRead; diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationWritePlatformServiceImpl.java index e41386f69..92297c37f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationWritePlatformServiceImpl.java @@ -54,7 +54,7 @@ public class NotificationWritePlatformServiceImpl implements NotificationWritePl AppUser appUser = this.appUserRepository.findById(userId).orElse(null); NotificationMapper notificationMapper = new NotificationMapper( this.notificationGeneratorReadRepositoryWrapper.findById(generatedNotificationId), appUser, false, - DateUtils.getDateOfTenant()); + DateUtils.getLocalDateTimeOfSystem()); this.notificationMapperWritePlatformService.create(notificationMapper); return notificationMapper.getId(); @@ -64,7 +64,7 @@ public class NotificationWritePlatformServiceImpl implements NotificationWritePl String notificationContent, boolean isSystemGenerated) { Notification notification = new Notification(objectType, objectIdentifier, action, actorId, isSystemGenerated, notificationContent, - DateUtils.getDateOfTenant()); + DateUtils.getLocalDateTimeOfSystem()); return this.notificationGeneratorWritePlatformService.create(notification); } @@ -86,7 +86,7 @@ public class NotificationWritePlatformServiceImpl implements NotificationWritePl AppUser appUser = this.appUserRepository.findById(userId).orElseThrow(); NotificationMapper notificationMapper = new NotificationMapper( this.notificationGeneratorReadRepositoryWrapper.findById(generatedNotificationId), appUser, false, - DateUtils.getDateOfTenant()); + DateUtils.getLocalDateTimeOfSystem()); this.notificationMapperWritePlatformService.create(notificationMapper); mappedIds.add(notificationMapper.getId()); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/api/HolidaysApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/api/HolidaysApiResource.java index 4a28dc072..41bbddf6b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/api/HolidaysApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/api/HolidaysApiResource.java @@ -30,8 +30,8 @@ import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -208,11 +208,11 @@ public class HolidaysApiResource { this.context.authenticatedUser().validateHasReadPermission(HOLIDAY_RESOURCE_NAME); - Date fromDate = null; + LocalDate fromDate = null; if (fromDateParam != null) { fromDate = fromDateParam.getDate("fromDate", dateFormat, locale); } - Date toDate = null; + LocalDate toDate = null; if (toDateParam != null) { toDate = toDateParam.getDate("toDate", dateFormat, locale); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayReadPlatformService.java index 911ec146f..356b6b1bc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayReadPlatformService.java @@ -18,15 +18,15 @@ */ package org.apache.fineract.organisation.holiday.service; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.organisation.holiday.data.HolidayData; public interface HolidayReadPlatformService { - Collection retrieveAllHolidaysBySearchParamerters(Long officeId, Date fromDate, Date toDate); + Collection retrieveAllHolidaysBySearchParamerters(Long officeId, LocalDate fromDate, LocalDate toDate); HolidayData retrieveHoliday(Long holidayId); diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayReadPlatformServiceImpl.java index 61993bd11..bb604527a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayReadPlatformServiceImpl.java @@ -20,15 +20,14 @@ package org.apache.fineract.organisation.holiday.service; import java.sql.ResultSet; import java.sql.SQLException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.organisation.holiday.data.HolidayData; import org.apache.fineract.organisation.holiday.domain.RescheduleType; @@ -86,10 +85,11 @@ public class HolidayReadPlatformServiceImpl implements HolidayReadPlatformServic } @Override - public Collection retrieveAllHolidaysBySearchParamerters(final Long officeId, final Date fromDate, final Date toDate) { + public Collection retrieveAllHolidaysBySearchParamerters(final Long officeId, final LocalDate fromDate, + final LocalDate toDate) { this.context.authenticatedUser(); - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + final DateTimeFormatter df = DateUtils.DEFAULT_DATE_FORMATER; final Object[] objectArray = new Object[3]; int arrayPos = 0; diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/Office.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/Office.java index a0b614f0d..6da5a1936 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/Office.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/Office.java @@ -20,9 +20,7 @@ package org.apache.fineract.organisation.office.domain; import java.io.Serializable; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; -import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -33,13 +31,10 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.office.exception.CannotUpdateOfficeWithParentOfficeSameAsSelf; import org.apache.fineract.organisation.office.exception.RootOfficeParentCannotBeUpdated; @@ -63,8 +58,7 @@ public class Office extends AbstractPersistableCustom implements Serializable { private String hierarchy; @Column(name = "opening_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date openingDate; + private LocalDate openingDate; @Column(name = "external_id", length = 100) private String externalId; @@ -90,7 +84,7 @@ public class Office extends AbstractPersistableCustom implements Serializable { private Office(final Office parent, final String name, final LocalDate openingDate, final String externalId) { this.parent = parent; - this.openingDate = Date.from(openingDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.openingDate = openingDate; if (parent != null) { this.parent.addChild(this); } @@ -136,8 +130,7 @@ public class Office extends AbstractPersistableCustom implements Serializable { actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(openingDateParamName); - this.openingDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.openingDate = command.localDateValueOfParameterNamed(openingDateParamName); } final String nameParamName = "name"; @@ -166,11 +159,7 @@ public class Office extends AbstractPersistableCustom implements Serializable { } public LocalDate getOpeningLocalDate() { - LocalDate openingLocalDate = null; - if (this.openingDate != null) { - openingLocalDate = LocalDate.ofInstant(this.openingDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return openingLocalDate; + return this.openingDate; } public void update(final Office newParent) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeTransaction.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeTransaction.java index bf0ade674..4a22e3581 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeTransaction.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeTransaction.java @@ -20,8 +20,6 @@ package org.apache.fineract.organisation.office.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Embedded; import javax.persistence.Entity; @@ -29,8 +27,6 @@ import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; @@ -49,8 +45,7 @@ public class OfficeTransaction extends AbstractPersistableCustom { private Office to; @Column(name = "transaction_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date transactionDate; + private LocalDate transactionDate; @Embedded private MonetaryCurrency currency; @@ -79,7 +74,7 @@ public class OfficeTransaction extends AbstractPersistableCustom { this.from = fromOffice; this.to = toOffice; if (transactionLocalDate != null) { - this.transactionDate = Date.from(transactionLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.transactionDate = transactionLocalDate; } this.currency = amount.getCurrency(); this.transactionAmount = amount.getAmount(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/domain/ProvisioningCriteria.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/domain/ProvisioningCriteria.java index 21db079b3..3bc99e5fc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/domain/ProvisioningCriteria.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/domain/ProvisioningCriteria.java @@ -18,8 +18,7 @@ */ package org.apache.fineract.organisation.provisioning.domain; -import java.time.Instant; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -66,13 +65,13 @@ public class ProvisioningCriteria extends AbstractAuditableCustom { } - public ProvisioningCriteria(String criteriaName, AppUser createdBy, ZonedDateTime createdDate, AppUser lastModifiedBy, - ZonedDateTime lastModifiedDate) { + public ProvisioningCriteria(String criteriaName, AppUser createdBy, LocalDateTime createdDate, AppUser lastModifiedBy, + LocalDateTime lastModifiedDate) { this.criteriaName = criteriaName; setCreatedBy(createdBy.getId()); - setCreatedDate(Instant.ofEpochMilli(createdDate.toInstant().toEpochMilli())); + setCreatedDate(createdDate); setLastModifiedBy(lastModifiedBy.getId()); - setLastModifiedDate(Instant.ofEpochMilli(lastModifiedDate.toInstant().toEpochMilli())); + setLastModifiedDate(lastModifiedDate); } public void setProvisioningCriteriaDefinitions(Set provisioningCriteriaDefinition) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCriteriaAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCriteriaAssembler.java index 1916c3a0f..252b3475b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCriteriaAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCriteriaAssembler.java @@ -22,7 +22,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.math.BigDecimal; -import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -122,8 +121,7 @@ public class ProvisioningCriteriaAssembler { jsonElement); ProvisioningCriteria criteria = new ProvisioningCriteria(criteriaName, platformSecurityContext.authenticatedUser(), - ZonedDateTime.now(DateUtils.getDateTimeZoneOfTenant()), platformSecurityContext.authenticatedUser(), - ZonedDateTime.now(DateUtils.getDateTimeZoneOfTenant())); + DateUtils.getLocalDateTimeOfSystem(), platformSecurityContext.authenticatedUser(), DateUtils.getLocalDateTimeOfSystem()); return criteria; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/CashierApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/CashierApiResource.java index 0b0e8d76d..d55b5e114 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/CashierApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/CashierApiResource.java @@ -19,10 +19,9 @@ package org.apache.fineract.organisation.teller.api; import io.swagger.v3.oas.annotations.tags.Tag; -import java.time.ZonedDateTime; +import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Collection; -import java.util.Date; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -30,6 +29,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.teller.data.CashierData; import org.apache.fineract.organisation.teller.service.TellerManagementReadPlatformService; import org.springframework.beans.factory.annotation.Autowired; @@ -60,7 +60,7 @@ public class CashierApiResource { @QueryParam("staffId") final Long staffId, @QueryParam("date") final String date) { final DateTimeFormatter dateFormatter = DateTimeFormatter.BASIC_ISO_DATE; - final Date dateRestriction = (date != null ? Date.from(ZonedDateTime.parse(date, dateFormatter).toInstant()) : new Date()); + final LocalDate dateRestriction = (date != null ? LocalDate.parse(date, dateFormatter) : DateUtils.getBusinessLocalDate()); final Collection allCashiers = this.readPlatformService.getCashierData(officeId, tellerId, staffId, dateRestriction); diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/TellerApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/TellerApiResource.java index eac2faa1a..e480a196a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/TellerApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/TellerApiResource.java @@ -27,10 +27,9 @@ import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import java.time.ZonedDateTime; +import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Collection; -import java.util.Date; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -46,6 +45,7 @@ import org.apache.fineract.commands.service.CommandWrapperBuilder; import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.SearchParameters; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; @@ -166,8 +166,8 @@ public class TellerApiResource { @QueryParam("todate") @Parameter(description = "todate") final String toDateStr) { final DateTimeFormatter dateFormatter = DateTimeFormatter.BASIC_ISO_DATE; - final Date fromDate = fromDateStr != null ? Date.from(ZonedDateTime.parse(fromDateStr, dateFormatter).toInstant()) : new Date(); - final Date toDate = toDateStr != null ? Date.from(ZonedDateTime.parse(toDateStr, dateFormatter).toInstant()) : new Date(); + final LocalDate fromDate = fromDateStr != null ? LocalDate.parse(fromDateStr, dateFormatter) : DateUtils.getBusinessLocalDate(); + final LocalDate toDate = toDateStr != null ? LocalDate.parse(toDateStr, dateFormatter) : DateUtils.getBusinessLocalDate(); final TellerData teller = this.readPlatformService.findTeller(tellerId); final Collection cashiers = this.readPlatformService.getCashiersForTeller(tellerId, fromDate, toDate); @@ -324,8 +324,8 @@ public class TellerApiResource { final TellerData teller = this.readPlatformService.findTeller(tellerId); final CashierData cashier = this.readPlatformService.findCashier(cashierId); - final Date fromDate = null; - final Date toDate = null; + final LocalDate fromDate = null; + final LocalDate toDate = null; final SearchParameters searchParameters = SearchParameters.forPagination(offset, limit, orderBy, sortOrder); final Page cashierTxns = this.readPlatformService.retrieveCashierTransactions(cashierId, false, fromDate, toDate, currencyCode, searchParameters); @@ -350,8 +350,8 @@ public class TellerApiResource { final TellerData teller = this.readPlatformService.findTeller(tellerId); final CashierData cashier = this.readPlatformService.findCashier(cashierId); - final Date fromDate = null; - final Date toDate = null; + final LocalDate fromDate = null; + final LocalDate toDate = null; final SearchParameters searchParameters = SearchParameters.forPagination(offset, limit, orderBy, sortOrder); diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/TellerApiResourceSwagger.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/TellerApiResourceSwagger.java index 85c73df43..89a0589d0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/TellerApiResourceSwagger.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/api/TellerApiResourceSwagger.java @@ -21,8 +21,8 @@ package org.apache.fineract.organisation.teller.api; import io.swagger.v3.oas.annotations.media.Schema; import java.math.BigDecimal; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.Collection; -import java.util.Date; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.organisation.staff.data.StaffData; @@ -343,16 +343,16 @@ final class TellerApiResourceSwagger { public CashierTxnType txnType; @Schema(example = "1000") public BigDecimal txnAmount; - @Schema(example = "Feb 25, 2015 12:00:00 AM") - public Date txnDate; + @Schema(example = "[2015, 02, 25]") + public LocalDate txnDate; @Schema(example = "2") public Long entityId; @Schema(example = "loans") public String entityType; @Schema(example = "Disbursement, Loan:2-000000002,Client:1-Test 1") public String txnNote; - @Schema(example = "Feb 25, 2015 12:00:00 AM") - public Date createdDate; + @Schema(example = "[2015, 02, 25, 12, 00, 00]") + public LocalDateTime createdDate; @Schema(example = "1") public Long officeId; @Schema(example = "Head Office") @@ -380,8 +380,8 @@ final class TellerApiResourceSwagger { public String locale; @Schema(example = "dd-MM-yyyy") public String dateFormat; - @Schema(example = "01 February 2015") - public Date txnDate; + @Schema(example = "[2015, 02, 01]") + public LocalDate txnDate; } @Schema(description = "PostTellersTellerIdCashiersCashierIdAllocateResponse") @@ -414,8 +414,8 @@ final class TellerApiResourceSwagger { public String locale; @Schema(example = "dd-MM-yyyy") public String dateFormat; - @Schema(example = "20 February 2015") - public Date txnDate; + @Schema(example = "[2015, 02, 20]") + public LocalDate txnDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierData.java index c9913d44f..85a75703e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierData.java @@ -19,8 +19,8 @@ package org.apache.fineract.organisation.teller.data; import java.io.Serializable; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import org.apache.fineract.organisation.staff.data.StaffData; /** @@ -39,8 +39,8 @@ public final class CashierData implements Serializable { private final Long officeId; private final Long staffId; private final String description; - private final Date startDate; - private final Date endDate; + private final LocalDate startDate; + private final LocalDate endDate; private final Boolean isFullDay; private final String startTime; private final String endTime; @@ -55,7 +55,7 @@ public final class CashierData implements Serializable { * Creates a new cashier. */ private CashierData(final Long id, final Long officeId, String officeName, final Long staffId, final String staffName, - final Long tellerId, final String tellerName, final String description, final Date startDate, final Date endDate, + final Long tellerId, final String tellerName, final String description, final LocalDate startDate, final LocalDate endDate, final Boolean isFullDay, final String startTime, final String endTime, Collection staffOptions) { this.id = id; this.officeId = officeId; @@ -113,7 +113,7 @@ public final class CashierData implements Serializable { * @return */ public static CashierData instance(final Long id, final Long officeId, String officeName, final Long staffId, final String staffName, - final Long tellerId, final String tellerName, final String description, final Date startDate, final Date endDate, + final Long tellerId, final String tellerName, final String description, final LocalDate startDate, final LocalDate endDate, final Boolean isFullDay, final String startTime, final String endTime) { return new CashierData(id, officeId, officeName, staffId, staffName, tellerId, tellerName, description, startDate, endDate, isFullDay, startTime, endTime, null); @@ -182,7 +182,7 @@ public final class CashierData implements Serializable { * * @return the valid from date of this cashier */ - public Date getStartDate() { + public LocalDate getStartDate() { return startDate; } @@ -195,7 +195,7 @@ public final class CashierData implements Serializable { * * @return the valid to date of this cashier */ - public Date getEndDate() { + public LocalDate getEndDate() { return endDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierTransactionData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierTransactionData.java index c15af97f7..b1720ef64 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierTransactionData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierTransactionData.java @@ -20,8 +20,9 @@ package org.apache.fineract.organisation.teller.data; import java.io.Serializable; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.Collection; -import java.util.Date; import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.organisation.teller.domain.CashierTxnType; @@ -31,11 +32,11 @@ public final class CashierTransactionData implements Serializable { private final Long cashierId; private final CashierTxnType txnType; private final BigDecimal txnAmount; - private final Date txnDate; + private final LocalDate txnDate; private final Long entityId; private final String entityType; private final String txnNote; - private final Date createdDate; + private final LocalDateTime createdDate; // Template fields private final Long officeId; @@ -45,8 +46,8 @@ public final class CashierTransactionData implements Serializable { private final String cashierName; private final CashierData cashierData; - private final Date startDate; - private final Date endDate; + private final LocalDate startDate; + private final LocalDate endDate; private final Collection currencyOptions; @@ -54,9 +55,9 @@ public final class CashierTransactionData implements Serializable { * Creates a new cashier. */ private CashierTransactionData(final Long id, final Long cashierId, CashierTxnType txnType, final BigDecimal txnAmount, - final Date txnDate, String txnNote, String entityType, Long entityId, Date createdDate, Long officeId, String officeName, - Long tellerId, String tellerName, String cashierName, CashierData cashierData, Date startDate, Date endDate, - final Collection currencyOptions) { + final LocalDate txnDate, String txnNote, String entityType, Long entityId, LocalDateTime createdDate, Long officeId, + String officeName, Long tellerId, String tellerName, String cashierName, CashierData cashierData, LocalDate startDate, + LocalDate endDate, final Collection currencyOptions) { this.id = id; this.cashierId = cashierId; this.txnType = txnType; @@ -81,15 +82,15 @@ public final class CashierTransactionData implements Serializable { } public static CashierTransactionData instance(final Long id, final Long cashierId, CashierTxnType txnType, final BigDecimal txnAmount, - final Date txnDate, final String txnNote, final String entityType, final Long entityId, final Date createdDate, + final LocalDate txnDate, final String txnNote, final String entityType, final Long entityId, final LocalDateTime createdDate, final Long officeId, final String officeName, final Long tellerId, final String tellerName, final String cashierName, - final CashierData cashierData, Date startDate, Date endDate) { + final CashierData cashierData, LocalDate startDate, LocalDate endDate) { return new CashierTransactionData(id, cashierId, txnType, txnAmount, txnDate, txnNote, entityType, entityId, createdDate, officeId, officeName, tellerId, tellerName, cashierName, cashierData, startDate, endDate, null); } public static CashierTransactionData template(final Long cashierId, final Long tellerId, final String tellerName, final Long officeId, - final String officeName, final String cashierName, final CashierData cashierData, Date startDate, Date endDate, + final String officeName, final String cashierName, final CashierData cashierData, LocalDate startDate, LocalDate endDate, final Collection currencyOptions) { return new CashierTransactionData(null, cashierId, null, null, null, null, null, null, null, officeId, officeName, tellerId, tellerName, cashierName, cashierData, startDate, endDate, currencyOptions); @@ -111,7 +112,7 @@ public final class CashierTransactionData implements Serializable { return txnAmount; } - public Date getTxnDate() { + public LocalDate getTxnDate() { return txnDate; } @@ -127,7 +128,7 @@ public final class CashierTransactionData implements Serializable { return entityId; } - public Date getCreatedDate() { + public LocalDateTime getCreatedDate() { return createdDate; } @@ -151,11 +152,11 @@ public final class CashierTransactionData implements Serializable { return cashierName; } - public Date getStartDate() { + public LocalDate getStartDate() { return startDate; } - public Date getEndDate() { + public LocalDate getEndDate() { return endDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierTransactionDataValidator.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierTransactionDataValidator.java index 9fe7c0ffe..4d7d36b4f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierTransactionDataValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/CashierTransactionDataValidator.java @@ -22,7 +22,6 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZonedDateTime; -import java.util.Date; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.SearchParameters; @@ -60,8 +59,8 @@ public class CashierTransactionDataValidator { final Integer limit = null; final String orderBy = null; final String sortOrder = null; - final Date fromDate = null; - final Date toDate = null; + final LocalDate fromDate = null; + final LocalDate toDate = null; final SearchParameters searchParameters = SearchParameters.forPagination(offset, limit, orderBy, sortOrder); final CashierTransactionsWithSummaryData cashierTxnWithSummary = this.tellerManagementReadPlatformService .retrieveCashierTransactionsWithSummary(cashierId, false, fromDate, toDate, currencyCode, searchParameters); @@ -78,8 +77,8 @@ public class CashierTransactionDataValidator { public void validateCashierAllowedDateAndTime(final Cashier cashier, final Teller teller) { Long staffId = cashier.getStaff().getId(); - final LocalDate fromDate = LocalDate.ofInstant(cashier.getStartDate().toInstant(), DateUtils.getDateTimeZoneOfTenant()); - final LocalDate endDate = LocalDate.ofInstant(cashier.getEndDate().toInstant(), DateUtils.getDateTimeZoneOfTenant()); + final LocalDate fromDate = cashier.getStartDate(); + final LocalDate endDate = cashier.getEndDate(); final LocalDate tellerFromDate = teller.getStartLocalDate(); final LocalDate tellerEndDate = teller.getEndLocalDate(); /** diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/TellerJournalData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/TellerJournalData.java index cb5754574..0629af11a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/TellerJournalData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/TellerJournalData.java @@ -19,7 +19,7 @@ package org.apache.fineract.organisation.teller.data; import java.io.Serializable; -import java.util.Date; +import java.time.LocalDate; /** * {@code TellerJournalData} represents an immutable journal data object. @@ -34,7 +34,7 @@ public final class TellerJournalData implements Serializable { private final Long officeId; private final Long tellerId; - private final Date day; + private final LocalDate day; private final Double openingBalance; private final Double settledBalance; private final Double closingBalance; @@ -44,7 +44,7 @@ public final class TellerJournalData implements Serializable { /* * Sole private CTOR to create a new instance. */ - private TellerJournalData(final Long officeId, final Long tellerId, final Date day, final Double openingBalance, + private TellerJournalData(final Long officeId, final Long tellerId, final LocalDate day, final Double openingBalance, final Double settledBalance, final Double closingBalance, final Double sumReceipts, final Double sumPayments) { this.officeId = officeId; this.tellerId = tellerId; @@ -77,7 +77,7 @@ public final class TellerJournalData implements Serializable { * - sum of all posted payments * @return the new created {@code TellerJournalData} */ - public static TellerJournalData instance(final Long officeId, final Long tellerId, final Date day, final Double openingBalance, + public static TellerJournalData instance(final Long officeId, final Long tellerId, final LocalDate day, final Double openingBalance, final Double settledBalance, final Double closingBalance, final Double sumReceipts, final Double sumPayments) { return new TellerJournalData(officeId, tellerId, day, openingBalance, settledBalance, closingBalance, sumReceipts, sumPayments); } @@ -90,7 +90,7 @@ public final class TellerJournalData implements Serializable { return tellerId; } - public Date getDay() { + public LocalDate getDay() { return day; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/TellerTransactionData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/TellerTransactionData.java index 834b288e8..62ab13bf7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/TellerTransactionData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/data/TellerTransactionData.java @@ -19,7 +19,7 @@ package org.apache.fineract.organisation.teller.data; import java.io.Serializable; -import java.util.Date; +import java.time.LocalDate; import org.apache.fineract.infrastructure.core.data.EnumOptionData; /** @@ -40,13 +40,13 @@ public final class TellerTransactionData implements Serializable { private final Long clientId; private final EnumOptionData type; private final Double amount; - private final Date postingDate; + private final LocalDate postingDate; /* * Sole private CTOR to create a new instance */ private TellerTransactionData(final Long id, final Long officeId, final Long tellerId, final Long cashierId, final Long clientId, - final EnumOptionData type, final Double amount, final Date postingDate) { + final EnumOptionData type, final Double amount, final LocalDate postingDate) { this.id = id; this.officeId = officeId; this.tellerId = tellerId; @@ -79,7 +79,7 @@ public final class TellerTransactionData implements Serializable { * @return the new created {@code TellerTransactionData} */ public static TellerTransactionData instance(final Long id, final Long officeId, final Long tellerId, final Long cashierId, - final Long clientId, final EnumOptionData type, final Double amount, final Date postingDate) { + final Long clientId, final EnumOptionData type, final Double amount, final LocalDate postingDate) { return new TellerTransactionData(id, officeId, tellerId, cashierId, clientId, type, amount, postingDate); } @@ -111,7 +111,7 @@ public final class TellerTransactionData implements Serializable { return amount; } - public Date getPostingDate() { + public LocalDate getPostingDate() { return postingDate; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/Cashier.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/Cashier.java index a1a51a133..9a39d2800 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/Cashier.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/Cashier.java @@ -20,8 +20,6 @@ package org.apache.fineract.organisation.teller.domain; import com.google.common.base.Splitter; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -31,13 +29,10 @@ import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.Transient; import javax.persistence.UniqueConstraint; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.office.domain.Office; import org.apache.fineract.organisation.staff.domain.Staff; @@ -69,13 +64,11 @@ public class Cashier extends AbstractPersistableCustom { @Column(name = "description", nullable = true, length = 500) private String description; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "start_date", nullable = false) - private Date startDate; + private LocalDate startDate; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "end_date", nullable = false) - private Date endDate; + private LocalDate endDate; @Column(name = "full_day", nullable = true) private Boolean isFullDay; @@ -115,8 +108,8 @@ public class Cashier extends AbstractPersistableCustom { this.teller = teller; this.staff = staff; this.description = description; - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - this.endDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = startDate; + this.endDate = endDate; this.isFullDay = isFullDay; this.startTime = startTime; this.endTime = endTime; @@ -137,25 +130,23 @@ public class Cashier extends AbstractPersistableCustom { } final String startDateParamName = "startDate"; - if (command.isChangeInLocalDateParameterNamed(startDateParamName, getStartLocalDate())) { + if (command.isChangeInLocalDateParameterNamed(startDateParamName, getStartDate())) { final String valueAsInput = command.stringValueOfParameterNamed(startDateParamName); actualChanges.put(startDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(startDateParamName); - this.startDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = command.localDateValueOfParameterNamed(startDateParamName); } final String endDateParamName = "endDate"; - if (command.isChangeInLocalDateParameterNamed(endDateParamName, getEndLocalDate())) { + if (command.isChangeInLocalDateParameterNamed(endDateParamName, getEndDate())) { final String valueAsInput = command.stringValueOfParameterNamed(endDateParamName); actualChanges.put(endDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(endDateParamName); - this.endDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.endDate = command.localDateValueOfParameterNamed(endDateParamName); } final Boolean isFullDay = command.booleanObjectValueOfParameterNamed("isFullDay"); @@ -341,18 +332,10 @@ public class Cashier extends AbstractPersistableCustom { * * @return the valid from date of this cashier */ - public Date getStartDate() { + public LocalDate getStartDate() { return startDate; } - public LocalDate getStartLocalDate() { - LocalDate startLocalDate = null; - if (this.startDate != null) { - startLocalDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return startLocalDate; - } - /** * Sets the valid from date of this cashier. * @@ -363,7 +346,7 @@ public class Cashier extends AbstractPersistableCustom { * @param startDate * validFrom the valid from date of this cashier */ - public void setStartDate(Date startDate) { + public void setStartDate(LocalDate startDate) { this.startDate = startDate; } @@ -376,18 +359,10 @@ public class Cashier extends AbstractPersistableCustom { * * @return the valid to date of this cashier */ - public Date getEndDate() { + public LocalDate getEndDate() { return endDate; } - public LocalDate getEndLocalDate() { - LocalDate endLocalDate = null; - if (this.endDate != null) { - endLocalDate = LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return endLocalDate; - } - /** * Sets the valid to date of this cashier. * @@ -398,7 +373,7 @@ public class Cashier extends AbstractPersistableCustom { * @param endDate * validTo the valid to date of this cashier */ - public void setEndDate(Date endDate) { + public void setEndDate(LocalDate endDate) { this.endDate = endDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/CashierTransaction.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/CashierTransaction.java index c63047458..a033d663c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/CashierTransaction.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/CashierTransaction.java @@ -20,8 +20,7 @@ package org.apache.fineract.organisation.teller.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; +import java.time.LocalDateTime; import java.util.LinkedHashMap; import java.util.Map; import javax.persistence.Column; @@ -30,8 +29,6 @@ import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.Transient; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @@ -55,9 +52,8 @@ public class CashierTransaction extends AbstractPersistableCustom { @Column(name = "txn_type", nullable = false) private Integer txnType; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "txn_date", nullable = false) - private Date txnDate; + private LocalDate txnDate; @Column(name = "txn_amount", scale = 6, precision = 19, nullable = false) private BigDecimal txnAmount; @@ -71,9 +67,8 @@ public class CashierTransaction extends AbstractPersistableCustom { @Column(name = "entity_id", nullable = true) private Long entityId; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_date", nullable = false) - private Date createdDate; + private LocalDateTime createdDate; @Column(name = "currency_code", nullable = true) private String currencyCode; @@ -104,13 +99,13 @@ public class CashierTransaction extends AbstractPersistableCustom { this.cashier = cashier; this.txnType = txnType; if (txnDate != null) { - this.txnDate = Date.from(txnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.txnDate = txnDate; } this.txnAmount = txnAmount; this.entityType = entityType; this.entityId = entityId; this.txnNote = txnNote; - this.createdDate = new Date(); + this.createdDate = DateUtils.getLocalDateTimeOfSystem(); this.currencyCode = currencyCode; } @@ -135,8 +130,7 @@ public class CashierTransaction extends AbstractPersistableCustom { actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(txnDateParamName); - this.txnDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.txnDate = command.localDateValueOfParameterNamed(txnDateParamName); } final String txnAmountParamName = "txnAmount"; @@ -229,16 +223,12 @@ public class CashierTransaction extends AbstractPersistableCustom { * * @return the transaction date of this cashier transaction */ - public Date getTxnDate() { + public LocalDate getTxnDate() { return txnDate; } public LocalDate getTxnLocalDate() { - LocalDate txnLocalDate = null; - if (this.txnDate != null) { - txnLocalDate = LocalDate.ofInstant(this.txnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return txnLocalDate; + return this.txnDate; } /** @@ -247,7 +237,7 @@ public class CashierTransaction extends AbstractPersistableCustom { * @param txnDate * transaction date of this cashier transaction */ - public void setTxnDate(Date txnDate) { + public void setTxnDate(LocalDate txnDate) { this.txnDate = txnDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/Teller.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/Teller.java index e1baf666b..443492192 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/Teller.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/Teller.java @@ -19,8 +19,6 @@ package org.apache.fineract.organisation.teller.domain; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -31,14 +29,10 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; -import org.apache.commons.lang3.StringUtils; import org.apache.fineract.accounting.glaccount.domain.GLAccount; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.office.domain.Office; @Entity @@ -63,13 +57,11 @@ public class Teller extends AbstractPersistableCustom { @Column(name = "description", nullable = true, length = 500) private String description; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "valid_from", nullable = true) - private Date startDate; + private LocalDate startDate; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "valid_to", nullable = true) - private Date endDate; + private LocalDate endDate; @Column(name = "state", nullable = false) private Integer status; @@ -84,14 +76,11 @@ public class Teller extends AbstractPersistableCustom { private Teller(final Office staffOffice, final String name, final String description, final LocalDate startDate, final LocalDate endDate, final TellerStatus status) { - this.name = StringUtils.defaultIfEmpty(name, null); - this.description = StringUtils.defaultIfEmpty(description, null); - if (startDate != null) { - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } - if (endDate != null) { - this.endDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } + this.name = name; + this.description = description; + this.startDate = startDate; + this.endDate = endDate; + if (status != null) { this.status = status.getValue(); } @@ -152,8 +141,7 @@ public class Teller extends AbstractPersistableCustom { actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(startDateParamName); - this.startDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = command.localDateValueOfParameterNamed(startDateParamName); } final String endDateParamName = "endDate"; @@ -163,8 +151,7 @@ public class Teller extends AbstractPersistableCustom { actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(endDateParamName); - this.endDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.endDate = command.localDateValueOfParameterNamed(endDateParamName); } final String statusParamName = "status"; @@ -221,35 +208,27 @@ public class Teller extends AbstractPersistableCustom { this.description = description; } - public Date getStartDate() { + public LocalDate getStartDate() { return startDate; } public LocalDate getStartLocalDate() { - LocalDate startLocalDate = null; - if (this.startDate != null) { - startLocalDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return startLocalDate; + return this.startDate; } - public void setStartDate(Date startDate) { + public void setStartDate(LocalDate startDate) { this.startDate = startDate; } - public Date getEndDate() { + public LocalDate getEndDate() { return endDate; } public LocalDate getEndLocalDate() { - LocalDate endLocalDate = null; - if (this.endDate != null) { - endLocalDate = LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return endLocalDate; + return this.endDate; } - public void setEndDate(Date endDate) { + public void setEndDate(LocalDate endDate) { this.endDate = endDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/TellerTransaction.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/TellerTransaction.java index 92c8eac1c..503a258f0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/TellerTransaction.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/domain/TellerTransaction.java @@ -18,15 +18,13 @@ */ package org.apache.fineract.organisation.teller.domain; -import java.util.Date; +import java.time.LocalDate; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.organisation.office.domain.Office; import org.apache.fineract.portfolio.client.domain.Client; @@ -57,9 +55,8 @@ public class TellerTransaction extends AbstractPersistableCustom { @Column(name = "amount", nullable = false) private Double amount; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "posting_date", nullable = false) - private Date postingDate; + private LocalDate postingDate; public TellerTransaction() { @@ -113,11 +110,11 @@ public class TellerTransaction extends AbstractPersistableCustom { this.amount = amount; } - public Date getPostingDate() { + public LocalDate getPostingDate() { return postingDate; } - public void setPostingDate(Date postingDate) { + public void setPostingDate(LocalDate postingDate) { this.postingDate = postingDate; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerManagementReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerManagementReadPlatformService.java index 3c75b7c41..1e48bfe4e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerManagementReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerManagementReadPlatformService.java @@ -18,8 +18,8 @@ */ package org.apache.fineract.organisation.teller.service; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.SearchParameters; import org.apache.fineract.organisation.teller.data.CashierData; @@ -37,9 +37,9 @@ public interface TellerManagementReadPlatformService { CashierData findCashier(Long cashierId); - Collection getCashierData(Long officeId, Long tellerId, Long staffId, Date date); + Collection getCashierData(Long officeId, Long tellerId, Long staffId, LocalDate date); - Collection getTellerCashiers(Long tellerId, Date date); + Collection getTellerCashiers(Long tellerId, LocalDate date); CashierData retrieveCashierTemplate(Long officeId, Long tellerId, boolean staffInSelectedOfficeOnly); @@ -47,24 +47,24 @@ public interface TellerManagementReadPlatformService { TellerTransactionData findTellerTransaction(Long transactionId); - Collection fetchTellerTransactionsByTellerId(Long tellerId, Date fromDate, Date toDate); + Collection fetchTellerTransactionsByTellerId(Long tellerId, LocalDate fromDate, LocalDate toDate); - Collection getJournals(Long officeId, Long tellerId, Long cashierId, Date dateFrom, Date dateTo); + Collection getJournals(Long officeId, Long tellerId, Long cashierId, LocalDate dateFrom, LocalDate dateTo); - Collection fetchTellerJournals(Long tellerId, Long cashierId, Date fromDate, Date toDate); + Collection fetchTellerJournals(Long tellerId, Long cashierId, LocalDate fromDate, LocalDate toDate); Collection retrieveAllTellersForDropdown(Long officeId); Collection retrieveAllTellers(String sqlSearch, Long officeId, String status); - Collection getCashiersForTeller(Long tellerId, Date fromDate, Date toDate); + Collection getCashiersForTeller(Long tellerId, LocalDate fromDate, LocalDate toDate); Collection retrieveCashiersForTellers(String sqlSearch, Long tellerId); - Page retrieveCashierTransactions(Long cashierId, boolean includeAllTellers, Date fromDate, Date toDate, - String currencyCode, SearchParameters searchParameters); + Page retrieveCashierTransactions(Long cashierId, boolean includeAllTellers, LocalDate fromDate, + LocalDate toDate, String currencyCode, SearchParameters searchParameters); - CashierTransactionsWithSummaryData retrieveCashierTransactionsWithSummary(Long cashierId, boolean includeAllTellers, Date fromDate, - Date toDate, String currencyCode, SearchParameters searchParameters); + CashierTransactionsWithSummaryData retrieveCashierTransactionsWithSummary(Long cashierId, boolean includeAllTellers, LocalDate fromDate, + LocalDate toDate, String currencyCode, SearchParameters searchParameters); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerManagementReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerManagementReadPlatformServiceImpl.java index fec043215..72de36aed 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerManagementReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerManagementReadPlatformServiceImpl.java @@ -22,9 +22,8 @@ import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDate; -import java.time.ZoneId; +import java.time.LocalDateTime; import java.util.Collection; -import java.util.Date; import java.util.Iterator; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; @@ -256,7 +255,7 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement } @Override - public Collection getCashiersForTeller(Long tellerId, Date fromDate, Date toDate) { + public Collection getCashiersForTeller(Long tellerId, LocalDate fromDate, LocalDate toDate) { return retrieveCashiersForTellers(null, tellerId); } @@ -312,13 +311,13 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement } @Override - public Collection getCashierData(Long officeId, Long tellerId, Long staffId, Date date) { + public Collection getCashierData(Long officeId, Long tellerId, Long staffId, LocalDate date) { // TODO Auto-generated method stub return null; } @Override - public Collection getTellerCashiers(Long tellerId, Date date) { + public Collection getTellerCashiers(Long tellerId, LocalDate date) { // TODO Auto-generated method stub return null; } @@ -330,19 +329,19 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement } @Override - public Collection fetchTellerTransactionsByTellerId(Long tellerId, Date fromDate, Date toDate) { + public Collection fetchTellerTransactionsByTellerId(Long tellerId, LocalDate fromDate, LocalDate toDate) { // TODO Auto-generated method stub return null; } @Override - public Collection getJournals(Long officeId, Long tellerId, Long cashierId, Date dateFrom, Date dateTo) { + public Collection getJournals(Long officeId, Long tellerId, Long cashierId, LocalDate dateFrom, LocalDate dateTo) { // TODO Auto-generated method stub return null; } @Override - public Collection fetchTellerJournals(Long tellerId, Long cashierId, Date fromDate, Date toDate) { + public Collection fetchTellerJournals(Long tellerId, Long cashierId, LocalDate fromDate, LocalDate toDate) { // TODO Auto-generated method stub return null; } @@ -404,8 +403,8 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement String cashierName = ""; Long officeId = null; Long tellerId = null; - Date startDate = null; - Date endDate = null; + LocalDate startDate = null; + LocalDate endDate = null; CashierData cashierData = findCashier(cashierId); if (cashierData != null) { @@ -430,7 +429,7 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement @Override public CashierTransactionsWithSummaryData retrieveCashierTransactionsWithSummary(final Long cashierId, final boolean includeAllTellers, - final Date fromDate, final Date toDate, final String currencyCode, final SearchParameters searchParameters) { + final LocalDate fromDate, final LocalDate toDate, final String currencyCode, final SearchParameters searchParameters) { CashierData cashierData = findCashier(cashierId); Long staffId = cashierData.getStaffId(); StaffData staffData = staffReadPlatformService.retrieveStaff(staffId); @@ -483,7 +482,7 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement @Override public Page retrieveCashierTransactions(final Long cashierId, final boolean includeAllTellers, - final Date fromDate, final Date toDate, final String currencyCode, final SearchParameters searchParameters) { + final LocalDate fromDate, final LocalDate toDate, final String currencyCode, final SearchParameters searchParameters) { CashierData cashierData = findCashier(cashierId); Long staffId = cashierData.getStaffId(); StaffData staffData = staffReadPlatformService.retrieveStaff(staffId); @@ -573,9 +572,8 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement final String startTime = rs.getString("start_time"); final String endTime = rs.getString("end_time"); - return CashierData.instance(id, null, null, staffId, staffName, tellerId, tellerName, description, - Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), - Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), fullDay, startTime, endTime); + return CashierData.instance(id, null, null, staffId, staffName, tellerId, tellerName, description, startDate, endDate, fullDay, + startTime, endTime); } } @@ -721,15 +719,15 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement final String txnNote = rs.getString("txn_note"); final String entityType = rs.getString("entity_type"); final Long entityId = rs.getLong("entity_id"); - final LocalDate createdLocalDate = JdbcSupport.getLocalDate(rs, "created_date"); + final LocalDateTime createdLocalDate = JdbcSupport.getLocalDateTime(rs, "created_date"); - Date txnDate = null; + LocalDate txnDate = null; if (txnLocalDate != null) { - txnDate = Date.from(txnLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + txnDate = txnLocalDate; } - Date createdDate = null; + LocalDateTime createdDate = null; if (createdLocalDate != null) { - createdDate = Date.from(createdLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + createdDate = createdLocalDate; } final Long officeId = rs.getLong("office_id"); diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/util/DateRange.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/util/DateRange.java index e22d67670..d6d0d8c53 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/util/DateRange.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/util/DateRange.java @@ -18,11 +18,10 @@ */ package org.apache.fineract.organisation.teller.util; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; +import java.time.LocalDate; +import java.time.format.DateTimeParseException; import java.util.StringTokenizer; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,38 +31,36 @@ public class DateRange { private static final String ISO_8601_DATE_PATTERN = "yyy-MM-dd"; private static final String RANGE_DELIMITER = ".."; - private Date startDate; - private Date endDate; + private LocalDate startDate; + private LocalDate endDate; public DateRange() { } - public Date getStartDate() { + public LocalDate getStartDate() { return startDate; } - public void setStartDate(Date startDate) { + public void setStartDate(LocalDate startDate) { this.startDate = startDate; } - public Date getEndDate() { + public LocalDate getEndDate() { return endDate; } - public void setEndDate(Date endDate) { + public void setEndDate(LocalDate endDate) { this.endDate = endDate; } public static DateRange fromString(final String dateToParse) { final DateRange dateRange = new DateRange(); - final SimpleDateFormat sdf = new SimpleDateFormat(DateRange.ISO_8601_DATE_PATTERN); - final Calendar cal = Calendar.getInstance(); final String testee; if (dateToParse == null) { - testee = sdf.format(cal.getTime()); + testee = DateUtils.DEFAULT_DATE_FORMATER.format(DateUtils.getBusinessLocalDate()); } else { testee = dateToParse; } @@ -71,31 +68,18 @@ public class DateRange { final StringTokenizer tokenizer = new StringTokenizer(testee, DateRange.RANGE_DELIMITER); try { - cal.setTime(sdf.parse(tokenizer.nextToken())); - } catch (ParseException ex) { + dateRange.setStartDate(LocalDate.parse(tokenizer.nextToken(), DateUtils.DEFAULT_DATE_FORMATER)); + } catch (DateTimeParseException ex) { LOG.error("Problem occurred in DateRange function Could not parse the date recieved.", ex); } - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); - - dateRange.setStartDate(cal.getTime()); if (tokenizer.hasMoreTokens()) { try { - cal.setTime(sdf.parse(tokenizer.nextToken())); - } catch (ParseException ex) { + dateRange.setEndDate(LocalDate.parse(tokenizer.nextToken(), DateUtils.DEFAULT_DATE_FORMATER)); + } catch (DateTimeParseException ex) { LOG.error("Problem occurred in DateRange function Could not parse the date recieved.", ex); } } - cal.set(Calendar.HOUR_OF_DAY, 23); - cal.set(Calendar.MINUTE, 59); - cal.set(Calendar.SECOND, 59); - cal.set(Calendar.MILLISECOND, 999); - - dateRange.setEndDate(cal.getTime()); - return dateRange; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionApiResource.java index b55972a1d..5a32190f5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionApiResource.java @@ -26,8 +26,8 @@ import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import java.time.LocalDate; import java.util.Arrays; -import java.util.Date; import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -202,8 +202,8 @@ public class StandingInstructionApiResource { final SearchParameters searchParameters = SearchParameters.forAccountTransfer(sqlSearch, externalId, offset, limit, orderBy, sortOrder); - final Date startDateRange = null; - final Date endDateRange = null; + final LocalDate startDateRange = null; + final LocalDate endDateRange = null; StandingInstructionDTO standingInstructionDTO = new StandingInstructionDTO(searchParameters, transferType, clientName, clientId, fromAccount, fromAccountType, startDateRange, endDateRange); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionHistoryApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionHistoryApiResource.java index a2ee50e19..067135930 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionHistoryApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionHistoryApiResource.java @@ -25,7 +25,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import java.util.Date; +import java.time.LocalDate; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -99,8 +99,8 @@ public class StandingInstructionHistoryApiResource { final SearchParameters searchParameters = SearchParameters.forAccountTransfer(sqlSearch, externalId, offset, limit, orderBy, sortOrder); - Date startDateRange = null; - Date endDateRange = null; + LocalDate startDateRange = null; + LocalDate endDateRange = null; if (fromDateParam != null) { startDateRange = fromDateParam.getDate("fromDate", dateFormat, locale); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/data/StandingInstructionDTO.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/data/StandingInstructionDTO.java index 6e05df16c..53317e621 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/data/StandingInstructionDTO.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/data/StandingInstructionDTO.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.portfolio.account.data; -import java.util.Date; +import java.time.LocalDate; import org.apache.fineract.infrastructure.core.service.SearchParameters; public class StandingInstructionDTO { @@ -29,12 +29,12 @@ public class StandingInstructionDTO { final Integer transferType; final Integer fromAccountType; final Long fromAccount; - final Date startDateRange; - final Date endDateRange; + final LocalDate startDateRange; + final LocalDate endDateRange; public StandingInstructionDTO(final SearchParameters searchParameters, final Integer transferType, final String clientName, - final Long clientId, final Long fromAccount, final Integer fromAccountType, final Date startDateRange, - final Date endDateRange) { + final Long clientId, final Long fromAccount, final Integer fromAccountType, final LocalDate startDateRange, + final LocalDate endDateRange) { this.searchParameters = searchParameters; this.transferType = transferType; this.clientName = clientName; @@ -73,11 +73,11 @@ public class StandingInstructionDTO { return this.transferType; } - public Date startDateRange() { + public LocalDate startDateRange() { return this.startDateRange; } - public Date endDateRange() { + public LocalDate endDateRange() { return this.endDateRange; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/domain/AccountTransferTransaction.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/domain/AccountTransferTransaction.java index a4c34bfbd..a66b195c9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/domain/AccountTransferTransaction.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/domain/AccountTransferTransaction.java @@ -20,16 +20,12 @@ package org.apache.fineract.portfolio.account.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.Money; @@ -63,9 +59,8 @@ public class AccountTransferTransaction extends AbstractPersistableCustom { @Column(name = "is_reversed", nullable = false) private boolean reversed = false; - @Temporal(TemporalType.DATE) @Column(name = "transaction_date") - private Date date; + private LocalDate date; @Embedded private MonetaryCurrency currency; @@ -111,7 +106,7 @@ public class AccountTransferTransaction extends AbstractPersistableCustom { this.fromSavingsTransaction = withdrawal; this.toSavingsTransaction = deposit; this.toLoanTransaction = loanRepaymentTransaction; - this.date = Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.date = transactionDate; this.currency = transactionAmount.getCurrency(); this.amount = transactionAmount.getAmountDefaultedToNullIfZero(); this.description = description; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersReadPlatformService.java index 3d7d8821b..c6d22051d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersReadPlatformService.java @@ -21,7 +21,6 @@ package org.apache.fineract.portfolio.account.service; import java.math.BigDecimal; import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.SearchParameters; import org.apache.fineract.portfolio.account.PortfolioAccountType; @@ -42,7 +41,7 @@ public interface AccountTransfersReadPlatformService { Collection fetchPostInterestTransactionIds(Long accountId); - Collection fetchPostInterestTransactionIdsWithPivotDate(Long accountId, Date pivotDate); + Collection fetchPostInterestTransactionIdsWithPivotDate(Long accountId, LocalDate pivotDate); AccountTransferData retrieveRefundByTransferTemplate(Long fromOfficeId, Long fromClientId, Long fromAccountId, Integer fromAccountType, Long toOfficeId, Long toClientId, Long toAccountId, Integer toAccountType); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersReadPlatformServiceImpl.java index 92d52f874..a4703c66f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersReadPlatformServiceImpl.java @@ -26,7 +26,6 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; @@ -268,7 +267,7 @@ public class AccountTransfersReadPlatformServiceImpl implements AccountTransfers } @Override - public Collection fetchPostInterestTransactionIdsWithPivotDate(final Long accountId, final Date pivotDate) { + public Collection fetchPostInterestTransactionIdsWithPivotDate(final Long accountId, final LocalDate pivotDate) { final String sql = "select att.from_savings_transaction_id from m_account_transfer_transaction att inner join m_account_transfer_details atd on atd.id = att.account_transfer_details_id where atd.from_savings_account_id=? and att.is_reversed = false and atd.transfer_type = ? and att.transaction_date >= ?"; final List transactionIds = this.jdbcTemplate.queryForList(sql, Long.class, accountId, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionHistoryReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionHistoryReadPlatformServiceImpl.java index 7c2e8c591..0d2981a4b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionHistoryReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionHistoryReadPlatformServiceImpl.java @@ -23,13 +23,12 @@ import static org.apache.fineract.portfolio.account.service.AccountTransferEnume import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.PaginationHelper; import org.apache.fineract.infrastructure.core.service.SearchParameters; @@ -126,9 +125,8 @@ public class StandingInstructionHistoryReadPlatformServiceImpl implements Standi if (addAndCaluse) { sqlBuilder.append(" and "); } - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); sqlBuilder.append(" atsih.execution_time >= ? "); - paramObj.add(df.format(standingInstructionDTO.startDateRange())); + paramObj.add(DateUtils.DEFAULT_DATE_FORMATER.format(standingInstructionDTO.startDateRange())); addAndCaluse = true; } @@ -136,9 +134,8 @@ public class StandingInstructionHistoryReadPlatformServiceImpl implements Standi if (addAndCaluse) { sqlBuilder.append(" and "); } - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); sqlBuilder.append(" atsih.execution_time < ? "); - paramObj.add(df.format(standingInstructionDTO.endDateRange())); + paramObj.add(DateUtils.DEFAULT_DATE_FORMATER.format(standingInstructionDTO.endDateRange())); addAndCaluse = true; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java index aef3885dd..367339e3a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java @@ -25,10 +25,8 @@ import static org.apache.fineract.portfolio.account.api.StandingInstructionApiCo import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -249,8 +247,7 @@ public class StandingInstructionWritePlatformServiceImpl implements StandingInst if (transferCompleted) { final String updateQuery = "UPDATE m_account_transfer_standing_instructions SET last_run_date = ? where id = ?"; - this.jdbcTemplate.update(updateQuery, Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), - data.getId()); + this.jdbcTemplate.update(updateQuery, transactionDate, data.getId()); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java index bf632f9ee..4742b5608 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java @@ -20,8 +20,8 @@ package org.apache.fineract.portfolio.address.data; import java.io.Serializable; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import org.apache.fineract.infrastructure.codes.data.CodeValueData; @SuppressWarnings("unused") @@ -67,11 +67,11 @@ public class AddressData implements Serializable { private final String createdBy; - private final Date createdOn; + private final LocalDate createdOn; private final String updatedBy; - private final Date updatedOn; + private final LocalDate updatedOn; // template holder private final Collection countryIdOptions; @@ -113,9 +113,9 @@ public class AddressData implements Serializable { final Boolean is_active, final String street, final String addressLine1, final String addressLine2, final String addressLine3, final String townVillage, final String city, final String countyDistrict, final Long stateProvinceId, final Long countryId, final String stateName, final String countryName, final String postalCode, final BigDecimal latitude, - final BigDecimal longitude, final String createdBy, final Date createdOn, final String updatedBy, final Date updatedOn, - final Collection countryIdOptions, final Collection stateProvinceIdOptions, - final Collection addressTypeIdOptions) { + final BigDecimal longitude, final String createdBy, final LocalDate createdOn, final String updatedBy, + final LocalDate updatedOn, final Collection countryIdOptions, + final Collection stateProvinceIdOptions, final Collection addressTypeIdOptions) { this.addressType = addressType; this.clientID = clientID; this.addressId = addressId; @@ -148,7 +148,8 @@ public class AddressData implements Serializable { final Boolean is_active, final String street, final String addressLine1, final String addressLine2, final String addressLine3, final String townVillage, final String city, final String countyDistrict, final Long stateProvinceId, final Long countryId, final String stateName, final String countryName, final String postalCode, final BigDecimal latitude, - final BigDecimal longitude, final String createdBy, final Date createdOn, final String updatedBy, final Date updatedOn) { + final BigDecimal longitude, final String createdBy, final LocalDate createdOn, final String updatedBy, + final LocalDate updatedOn) { return new AddressData(addressType, clientID, addressId, addressTypeId, is_active, street, addressLine1, addressLine2, addressLine3, townVillage, city, countyDistrict, stateProvinceId, countryId, stateName, countryName, postalCode, latitude, longitude, @@ -158,7 +159,7 @@ public class AddressData implements Serializable { public static AddressData instance1(final Long addressId, final String street, final String addressLine1, final String addressLine2, final String addressLine3, final String townVillage, final String city, final String countyDistrict, final Long stateProvinceId, final Long countryId, final String postalCode, final BigDecimal latitude, final BigDecimal longitude, final String createdBy, - final Date createdOn, final String updatedBy, final Date updatedOn) { + final LocalDate createdOn, final String updatedBy, final LocalDate updatedOn) { return new AddressData(null, null, addressId, null, false, street, addressLine1, addressLine2, addressLine3, townVillage, city, countyDistrict, stateProvinceId, countryId, null, null, postalCode, latitude, longitude, createdBy, createdOn, updatedBy, updatedOn, null, null, null); @@ -200,11 +201,11 @@ public class AddressData implements Serializable { final String createdBytemp = null; - final Date createdOntemp = null; + final LocalDate createdOntemp = null; final String updatedBytemp = null; - final Date updatedOntemp = null; + final LocalDate updatedOntemp = null; return new AddressData(null, client_idtemp, addressIdtemp, addressTypeIdtemp, is_activetemp, streettemp, addressLine1temp, addressLine2temp, addressLine3temp, townVillagetemp, citytemp, countyDistricttemp, stateProvinceIdtemp, countryIdtemp, null, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/domain/Address.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/domain/Address.java index bfb897523..a5ff23d51 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/domain/Address.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/domain/Address.java @@ -21,9 +21,7 @@ package org.apache.fineract.portfolio.address.domain; import com.google.gson.JsonObject; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.Date; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -91,13 +89,13 @@ public class Address extends AbstractPersistableCustom { private String createdBy; @Column(name = "created_on") - private Date createdOn; + private LocalDate createdOn; @Column(name = "updated_by") private String updatedBy; @Column(name = "updated_on") - private Date updatedOn; + private LocalDate updatedOn; private Address(final String street, final String addressLine1, final String addressLine2, final String addressLine3, final String townVillage, final String city, final String countyDistrict, final CodeValue stateProvince, @@ -121,12 +119,12 @@ public class Address extends AbstractPersistableCustom { // this.updatedOn = updatedOn; if (createdOn != null) { - this.createdOn = Date.from(createdOn.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.createdOn = createdOn; } if (updatedOn != null) { - this.updatedOn = Date.from(updatedOn.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.updatedOn = updatedOn; } } @@ -355,12 +353,12 @@ public class Address extends AbstractPersistableCustom { this.createdBy = createdBy; } - public Date getCreatedOn() { + public LocalDate getCreatedOn() { return this.createdOn; } public void setCreatedOn(LocalDate createdOn) { - this.createdOn = Date.from(createdOn.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.createdOn = createdOn; } public String getUpdatedBy() { @@ -371,12 +369,12 @@ public class Address extends AbstractPersistableCustom { this.updatedBy = updatedBy; } - public Date getUpdatedOn() { + public LocalDate getUpdatedOn() { return this.updatedOn; } public void setUpdatedOn(LocalDate updatedOn) { - this.updatedOn = Date.from(updatedOn.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.updatedOn = updatedOn; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformServiceImpl.java index 3e0ca6026..ebe5660dd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformServiceImpl.java @@ -19,11 +19,12 @@ package org.apache.fineract.portfolio.address.service; import java.math.BigDecimal; +import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; @@ -93,14 +94,15 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic final String created_by = rs.getString("created_by"); final Date created_on = rs.getDate("created_on"); - + final LocalDate created_on_local_date = created_on != null ? created_on.toLocalDate() : null; final String updated_by = rs.getString("updated_by"); final Date updated_on = rs.getDate("updated_on"); + final LocalDate update_on_local_date = updated_on != null ? updated_on.toLocalDate() : null; return AddressData.instance1(addressId, street, address_line_1, address_line_2, address_line_3, town_village, city, - county_district, state_province_id, country_id, postal_code, latitude, longitude, created_by, created_on, updated_by, - updated_on); + county_district, state_province_id, country_id, postal_code, latitude, longitude, created_by, created_on_local_date, + updated_by, update_on_local_date); } } @@ -162,13 +164,17 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic final Date created_on = rs.getDate("created_on"); + final LocalDate created_on_local_date = created_on != null ? created_on.toLocalDate() : null; + final String updated_by = rs.getString("updated_by"); final Date updated_on = rs.getDate("updated_on"); + final LocalDate update_on_local_date = updated_on != null ? updated_on.toLocalDate() : null; + return AddressData.instance(addressType, client_id, addressId, address_type_id, is_active, street, address_line_1, address_line_2, address_line_3, town_village, city, county_district, state_province_id, country_id, state_name, - country_name, postal_code, latitude, longitude, created_by, created_on, updated_by, updated_on); + country_name, postal_code, latitude, longitude, created_by, created_on_local_date, updated_by, update_on_local_date); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/domain/Calendar.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/domain/Calendar.java index 8115ad644..75fa4406c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/domain/Calendar.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/domain/Calendar.java @@ -21,11 +21,9 @@ package org.apache.fineract.portfolio.calendar.domain; import static org.apache.fineract.portfolio.calendar.CalendarConstants.CALENDAR_RESOURCE_NAME; import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; +import java.time.LocalTime; import java.time.temporal.ChronoField; import java.util.ArrayList; -import java.util.Date; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -37,8 +35,6 @@ import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.ApiParameterError; @@ -66,12 +62,10 @@ public class Calendar extends AbstractAuditableCustom { private String location; @Column(name = "start_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date startDate; + private LocalDate startDate; @Column(name = "end_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date endDate; + private LocalDate endDate; @Column(name = "duration", nullable = true) private Integer duration; @@ -95,8 +89,7 @@ public class Calendar extends AbstractAuditableCustom { private Integer secondReminder; @Column(name = "meeting_time", nullable = true) - @Temporal(TemporalType.TIME) - private Date meetingtime; + private LocalTime meetingtime; @OneToMany(mappedBy = "calendar", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) private Set calendarHistory = new HashSet<>(); @@ -107,7 +100,7 @@ public class Calendar extends AbstractAuditableCustom { public Calendar(final String title, final String description, final String location, final LocalDate startDate, final LocalDate endDate, final Integer duration, final Integer typeId, final boolean repeating, final String recurrence, final Integer remindById, - final Integer firstReminder, final Integer secondReminder, final Date meetingtime) { + final Integer firstReminder, final Integer secondReminder, final LocalTime meetingtime) { final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource(CALENDAR_RESOURCE_NAME); @@ -124,19 +117,8 @@ public class Calendar extends AbstractAuditableCustom { this.title = StringUtils.defaultIfEmpty(title, null); this.description = StringUtils.defaultIfEmpty(description, null); this.location = StringUtils.defaultIfEmpty(location, null); - - if (null != startDate) { - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } else { - this.startDate = null; - } - - if (null != endDate) { - this.endDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } else { - this.endDate = null; - } - + this.startDate = startDate; + this.endDate = endDate; this.duration = duration; this.typeId = typeId; this.repeating = repeating; @@ -164,7 +146,7 @@ public class Calendar extends AbstractAuditableCustom { final Integer remindById = null; final Integer firstReminder = null; final Integer secondReminder = null; - final Date meetingtime = null; + final LocalTime meetingtime = null; return new Calendar(title, description, location, startDate, endDate, duration, typeId, repeating, recurrence, remindById, firstReminder, secondReminder, meetingtime); } @@ -174,7 +156,7 @@ public class Calendar extends AbstractAuditableCustom { // final Long entityId = command.getSupportedEntityId(); // final Integer entityTypeId = // CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase()).getValue(); - Date meetingtime = null; + LocalTime meetingtime = null; final String title = command.stringValueOfParameterNamed(CalendarSupportedParameters.TITLE.getValue()); final String description = command.stringValueOfParameterNamed(CalendarSupportedParameters.DESCRIPTION.getValue()); final String location = command.stringValueOfParameterNamed(CalendarSupportedParameters.LOCATION.getValue()); @@ -187,10 +169,8 @@ public class Calendar extends AbstractAuditableCustom { final Integer firstReminder = command.integerValueSansLocaleOfParameterNamed(CalendarSupportedParameters.FIRST_REMINDER.getValue()); final Integer secondReminder = command .integerValueSansLocaleOfParameterNamed(CalendarSupportedParameters.SECOND_REMINDER.getValue()); - final LocalDateTime time = command.localTimeValueOfParameterNamed(CalendarSupportedParameters.MEETING_TIME.getValue()); - if (time != null) { - meetingtime = Date.from(time.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); - } + meetingtime = command.localTimeValueOfParameterNamed(CalendarSupportedParameters.MEETING_TIME.getValue()); + final String recurrence = Calendar.constructRecurrence(command, null); return new Calendar(title, description, location, startDate, endDate, duration, typeId, repeating, recurrence, remindById, @@ -216,7 +196,7 @@ public class Calendar extends AbstractAuditableCustom { } else { actualChanges.put(CalendarSupportedParameters.START_DATE.getValue(), newMeetingStartDate.toString()); - this.startDate = Date.from(newMeetingStartDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = newMeetingStartDate; /* * If meeting start date is changed then there is possibilities of recurring day may change, so derive the @@ -292,7 +272,7 @@ public class Calendar extends AbstractAuditableCustom { actualChanges.put(startDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); - this.startDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = newValue; } } @@ -303,8 +283,7 @@ public class Calendar extends AbstractAuditableCustom { actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(endDateParamName); - this.endDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.endDate = command.localDateValueOfParameterNamed(endDateParamName); } final String durationParamName = CalendarSupportedParameters.DURATION.getValue(); @@ -407,9 +386,9 @@ public class Calendar extends AbstractAuditableCustom { if (command.isChangeInTimeParameterNamed(CalendarSupportedParameters.MEETING_TIME.getValue(), this.meetingtime, timeFormat)) { final String newValue = command.stringValueOfParameterNamed(CalendarSupportedParameters.MEETING_TIME.getValue()); actualChanges.put(CalendarSupportedParameters.MEETING_TIME.getValue(), newValue); - LocalDateTime timeInLocalDateTimeFormat = command.localTimeValueOfParameterNamed(time); + LocalTime timeInLocalDateTimeFormat = command.localTimeValueOfParameterNamed(time); if (timeInLocalDateTimeFormat != null) { - this.meetingtime = Date.from(timeInLocalDateTimeFormat.atZone(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + this.meetingtime = timeInLocalDateTimeFormat; } } @@ -425,7 +404,7 @@ public class Calendar extends AbstractAuditableCustom { if (calendarStartDate != null && this.startDate != null) { if (!calendarStartDate.equals(this.getStartDateLocalDate())) { actualChanges.put("startDate", calendarStartDate); - this.startDate = Date.from(calendarStartDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = calendarStartDate; } } @@ -449,11 +428,11 @@ public class Calendar extends AbstractAuditableCustom { return this.location; } - public Date getStartDate() { + public LocalDate getStartDate() { return this.startDate; } - public Date getEndDate() { + public LocalDate getEndDate() { return this.endDate; } @@ -485,24 +464,16 @@ public class Calendar extends AbstractAuditableCustom { return this.secondReminder; } - public Date getMeetingTime() { + public LocalTime getMeetingTime() { return this.meetingtime; } public LocalDate getStartDateLocalDate() { - LocalDate startDateLocalDate = null; - if (this.startDate != null) { - startDateLocalDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return startDateLocalDate; + return this.startDate; } public LocalDate getEndDateLocalDate() { - LocalDate endDateLocalDate = null; - if (this.endDate != null) { - endDateLocalDate = LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return endDateLocalDate; + return this.endDate; } public Set history() { @@ -663,8 +634,8 @@ public class Calendar extends AbstractAuditableCustom { final String newRecurrence = Calendar.constructRecurrence(frequencyType, interval, startDate.get(ChronoField.DAY_OF_WEEK), null); this.recurrence = newRecurrence; - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - this.endDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = startDate; + this.endDate = endDate; } public Set getCalendarHistory() { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/domain/CalendarHistory.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/domain/CalendarHistory.java index fbd4112c0..73603b8b3 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/domain/CalendarHistory.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/domain/CalendarHistory.java @@ -19,16 +19,12 @@ package org.apache.fineract.portfolio.calendar.domain; import java.time.LocalDate; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; @Entity @Table(name = "m_calendar_history") @@ -48,12 +44,10 @@ public class CalendarHistory extends AbstractPersistableCustom { private String location; @Column(name = "start_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date startDate; + private LocalDate startDate; @Column(name = "end_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date endDate; + private LocalDate endDate; @Column(name = "duration", nullable = true) private Integer duration; @@ -80,7 +74,7 @@ public class CalendarHistory extends AbstractPersistableCustom { } - public CalendarHistory(Calendar calendar, Date startDate) { + public CalendarHistory(Calendar calendar, LocalDate startDate) { this.calendar = calendar; this.title = calendar.getTitle(); this.description = calendar.getDescription(); @@ -102,19 +96,11 @@ public class CalendarHistory extends AbstractPersistableCustom { } public LocalDate getStartDateLocalDate() { - LocalDate startDateLocalDate = null; - if (this.startDate != null) { - startDateLocalDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return startDateLocalDate; + return this.startDate; } public LocalDate getEndDateLocalDate() { - LocalDate endDateLocalDate = null; - if (this.endDate != null) { - endDateLocalDate = LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return endDateLocalDate; + return this.endDate; } public boolean isEndDateAfterOrEqual(final LocalDate compareDate) { @@ -144,7 +130,7 @@ public class CalendarHistory extends AbstractPersistableCustom { return false; } - public void updateEndDate(Date historyCalEndDate) { + public void updateEndDate(LocalDate historyCalEndDate) { this.endDate = historyCalEndDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/serialization/CalendarCommandFromApiJsonDeserializer.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/serialization/CalendarCommandFromApiJsonDeserializer.java index d3a2554ba..0792193ed 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/serialization/CalendarCommandFromApiJsonDeserializer.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/serialization/CalendarCommandFromApiJsonDeserializer.java @@ -22,7 +22,7 @@ import com.google.gson.JsonElement; import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.time.LocalDate; -import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -203,8 +203,8 @@ public class CalendarCommandFromApiJsonDeserializer extends AbstractFromApiJsonD .integerGreaterThanZero(); } if (this.fromApiJsonHelper.parameterExists(CalendarSupportedParameters.MEETING_TIME.getValue(), element)) { - final LocalDateTime meetingTime = this.fromApiJsonHelper - .extractLocalTimeNamed(CalendarSupportedParameters.MEETING_TIME.getValue(), element); + final LocalTime meetingTime = this.fromApiJsonHelper.extractLocalTimeNamed(CalendarSupportedParameters.MEETING_TIME.getValue(), + element); baseDataValidator.reset().parameter(CalendarSupportedParameters.MEETING_TIME.getValue()).value(meetingTime).ignoreIfNull(); } @@ -347,9 +347,9 @@ public class CalendarCommandFromApiJsonDeserializer extends AbstractFromApiJsonD .ignoreIfNull(); } if (this.fromApiJsonHelper.parameterExists(CalendarSupportedParameters.MEETING_TIME.getValue(), element)) { - final LocalDateTime startDate = this.fromApiJsonHelper - .extractLocalTimeNamed(CalendarSupportedParameters.MEETING_TIME.getValue(), element); - baseDataValidator.reset().parameter(CalendarSupportedParameters.MEETING_TIME.getValue()).value(startDate).ignoreIfNull(); + final LocalTime meetingTime = this.fromApiJsonHelper.extractLocalTimeNamed(CalendarSupportedParameters.MEETING_TIME.getValue(), + element); + baseDataValidator.reset().parameter(CalendarSupportedParameters.MEETING_TIME.getValue()).value(meetingTime).ignoreIfNull(); } if (!dataValidationErrors.isEmpty()) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java index 2de3a2d3a..85f964463 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java @@ -22,10 +22,8 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDate; import java.time.LocalTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import lombok.RequiredArgsConstructor; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; @@ -427,7 +425,7 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ final String sql = rm.schema() + " where c.calendar_id = ? and date(?) between c.start_date and c.end_date limit 1"; return this.jdbcTemplate.queryForObject(sql, rm, // NOSONAR - new Object[] { calendarId, Date.from(compareDate.atStartOfDay(ZoneId.systemDefault()).toInstant()) }); + calendarId, compareDate); } catch (final EmptyResultDataAccessException e) { return null; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarUtils.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarUtils.java index 0c5c0fc06..d6c3f6578 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarUtils.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarUtils.java @@ -19,13 +19,14 @@ package org.apache.fineract.portfolio.calendar.service; import com.google.gson.JsonElement; -import java.text.DateFormat; import java.text.ParseException; -import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.ZoneId; -import java.time.ZonedDateTime; +import java.time.chrono.IsoChronology; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoField; +import java.time.temporal.Temporal; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -67,33 +68,44 @@ public final class CalendarUtils { System.setProperty("net.fortuna.ical4j.timezone.date.floating", "true"); } + public static LocalDateTime getNextRecurringDate(final String recurringRule, final LocalDateTime seedDate, + final LocalDateTime startDate) { + final Recur recur = CalendarUtils.getICalRecur(recurringRule); + if (recur == null) { + return null; + } + LocalDateTime nextDate = getNextRecurringDate(recur, seedDate, startDate); + nextDate = (LocalDateTime) adjustDate(nextDate, seedDate, getMeetingPeriodFrequencyType(recurringRule)); + return nextDate; + } + public static LocalDate getNextRecurringDate(final String recurringRule, final LocalDate seedDate, final LocalDate startDate) { final Recur recur = CalendarUtils.getICalRecur(recurringRule); if (recur == null) { return null; } LocalDate nextDate = getNextRecurringDate(recur, seedDate, startDate); - nextDate = adjustDate(nextDate, seedDate, getMeetingPeriodFrequencyType(recurringRule)); + nextDate = (LocalDate) adjustDate(nextDate, seedDate, getMeetingPeriodFrequencyType(recurringRule)); return nextDate; } - public static LocalDate adjustDate(final LocalDate date, final LocalDate seedDate, final PeriodFrequencyType frequencyType) { - LocalDate adjustedVal = date; - if (frequencyType.isMonthly() && seedDate.getDayOfMonth() > 28 && date.getDayOfMonth() > 28) { - switch (date.getMonthValue()) { + public static Temporal adjustDate(final Temporal date, final Temporal seedDate, final PeriodFrequencyType frequencyType) { + Temporal adjustedVal = date; + if (frequencyType.isMonthly() && seedDate.get(ChronoField.DAY_OF_MONTH) > 28 && date.get(ChronoField.DAY_OF_MONTH) > 28) { + switch (date.get(ChronoField.MONTH_OF_YEAR)) { case 2: - if (date.isLeapYear()) { - adjustedVal = date.withDayOfMonth(29); + if (IsoChronology.INSTANCE.isLeapYear(date.get(ChronoField.YEAR))) { + adjustedVal = date.with(ChronoField.DAY_OF_MONTH, 29); } break; case 4: case 6: case 9: case 11: - if (seedDate.getDayOfMonth() > 30) { - adjustedVal = date.withDayOfMonth(30); + if (seedDate.get(ChronoField.DAY_OF_MONTH) > 30) { + adjustedVal = date.with(ChronoField.DAY_OF_MONTH, 30); } else { - adjustedVal = date.withDayOfMonth(seedDate.getDayOfMonth()); + adjustedVal = date.with(ChronoField.DAY_OF_MONTH, seedDate.get(ChronoField.DAY_OF_MONTH)); } break; case 1: @@ -103,28 +115,32 @@ public final class CalendarUtils { case 8: case 10: case 12: - adjustedVal = date.withDayOfMonth(seedDate.getDayOfMonth()); + adjustedVal = date.with(ChronoField.DAY_OF_MONTH, seedDate.get(ChronoField.DAY_OF_MONTH)); break; } } return adjustedVal; } - private static LocalDate getNextRecurringDate(final Recur recur, final LocalDate seedDate, final LocalDate startDate) { - final DateTime periodStart = new DateTime(java.util.Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); + private static LocalDateTime getNextRecurringDate(final Recur recur, final LocalDateTime seedDate, final LocalDateTime startDate) { + final DateTime periodStart = new DateTime(java.util.Date.from(startDate.atZone(ZoneId.systemDefault()).toInstant())); final Date seed = convertToiCal4JCompatibleDate(seedDate); final Date nextRecDate = recur.getNextDate(seed, periodStart); - return nextRecDate == null ? null - : ZonedDateTime.ofInstant(nextRecDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDate(); + return nextRecDate == null ? null : LocalDateTime.ofInstant(nextRecDate.toInstant(), DateUtils.getSystemZoneId()); } - private static Date convertToiCal4JCompatibleDate(final LocalDate inputDate) { - // Date format in iCal4J is hard coded + private static LocalDate getNextRecurringDate(final Recur recur, final LocalDate seedDate, final LocalDate startDate) { + final DateTime periodStart = new DateTime(java.util.Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); + final Date seed = convertToiCal4JCompatibleDate(seedDate.atStartOfDay()); + final Date nextRecDate = recur.getNextDate(seed, periodStart); + return nextRecDate == null ? null : LocalDate.ofInstant(nextRecDate.toInstant(), DateUtils.getSystemZoneId()); + } + + private static Date convertToiCal4JCompatibleDate(final LocalDateTime inputDate) { Date formattedDate = null; - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - final String seedDateStr = df.format(java.util.Date.from(inputDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); + final String seedDateStr = DateUtils.DEFAULT_DATETIME_FORMATER.format(inputDate); try { - formattedDate = new Date(seedDateStr, "yyyy-MM-dd"); + formattedDate = new Date(seedDateStr, DateUtils.DEFAULT_DATETIME_FORMAT); } catch (final ParseException e) { LOG.error("Invalid date: {}", seedDateStr, e); } @@ -168,7 +184,7 @@ public final class CalendarUtils { if (recur == null) { return null; } - final Date seed = convertToiCal4JCompatibleDate(seedDate); + final Date seed = convertToiCal4JCompatibleDate(seedDate.atStartOfDay()); final DateTime periodStart = new DateTime(java.util.Date.from(periodStartDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); final DateTime periodEnd = new DateTime(java.util.Date.from(periodEndDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); @@ -186,8 +202,8 @@ public final class CalendarUtils { for (@SuppressWarnings("rawtypes") final Iterator iterator = dates.iterator(); iterator.hasNext();) { final Date date = (Date) iterator.next(); - recurringDates - .add(adjustDate(LocalDate.ofInstant(date.toInstant(), DateUtils.getDateTimeZoneOfTenant()), seedDate, frequencyType)); + recurringDates.add((LocalDate) adjustDate(LocalDate.ofInstant(date.toInstant(), DateUtils.getDateTimeZoneOfTenant()), seedDate, + frequencyType)); } if (isSkippMeetingOnFirstDay) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java index cceee59b1..26901c0b6 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java @@ -19,12 +19,10 @@ package org.apache.fineract.portfolio.calendar.service; import java.time.LocalDate; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; @@ -232,7 +230,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr final Calendar calendarForUpdate = this.calendarRepository.findById(calendarId) .orElseThrow(() -> new CalendarNotFoundException(calendarId)); - final Date oldStartDate = calendarForUpdate.getStartDate(); + final LocalDate oldStartDate = calendarForUpdate.getStartDate(); // create calendar history before updating calendar final CalendarHistory calendarHistory = new CalendarHistory(calendarForUpdate, oldStartDate); @@ -281,7 +279,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr presentMeetingDate = command.localDateValueOfParameterNamed(CalendarSupportedParameters.START_DATE.getValue()); } if (null != newMeetingDate) { - final Date endDate = Date.from(presentMeetingDate.minusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant()); + final LocalDate endDate = presentMeetingDate.minusDays(1); calendarHistory.updateEndDate(endDate); } this.calendarHistoryRepository.save(calendarHistory); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java index 5d6f5a924..dacdff318 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java @@ -26,13 +26,9 @@ import static org.apache.fineract.portfolio.collectionsheet.CollectionSheetConst import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -41,6 +37,7 @@ import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDoma import org.apache.fineract.infrastructure.core.api.JsonQuery; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.organisation.monetary.data.CurrencyData; @@ -330,8 +327,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe final Long calendarId = query.longValueOfParameterNamed(calendarIdParamName); final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName); - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - final String transactionDateStr = df.format(Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); + final String transactionDateStr = DateUtils.DEFAULT_DATE_FORMATER.format(transactionDate); final Calendar calendar = this.calendarRepositoryWrapper.findOneWithNotFoundDetection(calendarId); // check if transaction against calendar effective from date @@ -466,8 +462,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe final CenterData center = this.centerReadPlatformService.retrieveOne(centerId); final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName); - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - final String dueDateStr = df.format(Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); + final String dueDateStr = DateUtils.DEFAULT_DATE_FORMATER.format(transactionDate); final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper(sqlGenerator); @@ -684,8 +679,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe this.collectionSheetGenerateCommandFromApiJsonDeserializer.validateForGenerateCollectionSheetOfIndividuals(query.json()); final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName); - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - final String transactionDateStr = df.format(Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); + final String transactionDateStr = DateUtils.DEFAULT_DATE_FORMATER.format(transactionDate); final AppUser currentUser = this.context.authenticatedUser(); final String hierarchy = currentUser.getOffice().getHierarchy(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/data/FloatingRatePeriodData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/data/FloatingRatePeriodData.java index 5a10b4670..fd2c14d78 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/data/FloatingRatePeriodData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/data/FloatingRatePeriodData.java @@ -21,6 +21,7 @@ package org.apache.fineract.portfolio.floatingrates.data; import java.io.Serializable; import java.math.BigDecimal; import java.time.LocalDate; +import java.time.LocalDateTime; import org.apache.commons.lang3.builder.CompareToBuilder; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -33,12 +34,12 @@ public class FloatingRatePeriodData implements Comparable floatingRatePeriods, - AppUser createdBy, AppUser modifiedBy, Date createdOn, Date modifiedOn) { + AppUser createdBy, AppUser modifiedBy, LocalDateTime createdOn, LocalDateTime modifiedOn) { this.name = name; this.isBaseLendingRate = isBaseLendingRate; this.isActive = isActive; @@ -110,7 +109,7 @@ public class FloatingRate extends AbstractPersistableCustom { : false; final boolean isActive = command.parameterExists("isActive") ? command.booleanPrimitiveValueOfParameterNamed("isActive") : true; final List floatingRatePeriods = getRatePeriods(currentUser, command); - final Date currentDate = DateUtils.getBusinessDate(); + final LocalDateTime currentDate = DateUtils.getLocalDateTimeOfSystem(); return new FloatingRate(name, isBaseLendingRate, isActive, floatingRatePeriods, currentUser, currentUser, currentDate, currentDate); } @@ -124,14 +123,13 @@ public class FloatingRate extends AbstractPersistableCustom { for (final JsonElement ratePeriod : arrayOfParameterNamed) { final JsonObject ratePeriodObject = ratePeriod.getAsJsonObject(); final JsonParserHelper helper = new JsonParserHelper(); - final Date fromDate = Date.from(helper.extractLocalDateNamed("fromDate", ratePeriod, new HashSet()) - .atStartOfDay(ZoneId.systemDefault()).toInstant()); + final LocalDate fromDate = helper.extractLocalDateNamed("fromDate", ratePeriod, new HashSet()); final BigDecimal interestRate = ratePeriodObject.get("interestRate").getAsBigDecimal(); final boolean isDifferentialToBaseLendingRate = helper.parameterExists("isDifferentialToBaseLendingRate", ratePeriod) ? ratePeriodObject.get("isDifferentialToBaseLendingRate").getAsBoolean() : false; final boolean isActive = true; - final Date currentDate = DateUtils.getBusinessDate(); + final LocalDateTime currentDate = DateUtils.getLocalDateTimeOfSystem(); ratePeriods.add(new FloatingRatePeriod(fromDate, interestRate, isDifferentialToBaseLendingRate, isActive, currentUser, currentUser, currentDate, currentDate)); } @@ -163,11 +161,11 @@ public class FloatingRate extends AbstractPersistableCustom { return this.modifiedBy; } - public Date getCreatedOn() { + public LocalDateTime getCreatedOn() { return this.createdOn; } - public Date getModifiedOn() { + public LocalDateTime getModifiedOn() { return this.modifiedOn; } @@ -206,11 +204,11 @@ public class FloatingRate extends AbstractPersistableCustom { final LocalDate today = DateUtils.getBusinessLocalDate(); if (this.floatingRatePeriods != null) { for (FloatingRatePeriod ratePeriod : this.floatingRatePeriods) { - LocalDate fromDate = LocalDate.ofInstant(ratePeriod.getFromDate().toInstant(), DateUtils.getDateTimeZoneOfTenant()); + LocalDate fromDate = ratePeriod.getFromDate(); if (fromDate.isAfter(today)) { ratePeriod.setActive(false); ratePeriod.setModifiedBy(appUser); - ratePeriod.setModifiedOn(Date.from(today.atStartOfDay(ZoneId.systemDefault()).toInstant())); + ratePeriod.setModifiedOn(DateUtils.getLocalDateTimeOfSystem()); } } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/domain/FloatingRatePeriod.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/domain/FloatingRatePeriod.java index bba429b3c..f85bd8be5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/domain/FloatingRatePeriod.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/domain/FloatingRatePeriod.java @@ -20,8 +20,7 @@ package org.apache.fineract.portfolio.floatingrates.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZonedDateTime; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -29,7 +28,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.portfolio.floatingrates.data.FloatingRateDTO; import org.apache.fineract.portfolio.floatingrates.data.FloatingRatePeriodData; import org.apache.fineract.useradministration.domain.AppUser; @@ -44,7 +42,7 @@ public class FloatingRatePeriod extends AbstractPersistableCustom { private FloatingRate floatingRate; @Column(name = "from_date", nullable = false) - private Date fromDate; + private LocalDate fromDate; @Column(name = "interest_rate", scale = 6, precision = 19, nullable = false) private BigDecimal interestRate; @@ -64,17 +62,17 @@ public class FloatingRatePeriod extends AbstractPersistableCustom { private AppUser modifiedBy; @Column(name = "created_date", nullable = false) - private Date createdOn; + private LocalDateTime createdOn; @Column(name = "lastmodified_date", nullable = false) - private Date modifiedOn; + private LocalDateTime modifiedOn; public FloatingRatePeriod() { } - public FloatingRatePeriod(Date fromDate, BigDecimal interestRate, boolean isDifferentialToBaseLendingRate, boolean isActive, - AppUser createdBy, AppUser modifiedBy, Date createdOn, Date modifiedOn) { + public FloatingRatePeriod(LocalDate fromDate, BigDecimal interestRate, boolean isDifferentialToBaseLendingRate, boolean isActive, + AppUser createdBy, AppUser modifiedBy, LocalDateTime createdOn, LocalDateTime modifiedOn) { this.fromDate = fromDate; this.interestRate = interestRate; this.isDifferentialToBaseLendingRate = isDifferentialToBaseLendingRate; @@ -93,7 +91,7 @@ public class FloatingRatePeriod extends AbstractPersistableCustom { return this.floatingRate; } - public Date getFromDate() { + public LocalDate getFromDate() { return this.fromDate; } @@ -117,11 +115,11 @@ public class FloatingRatePeriod extends AbstractPersistableCustom { return this.modifiedBy; } - public Date getCreatedOn() { + public LocalDateTime getCreatedOn() { return this.createdOn; } - public Date getModifiedOn() { + public LocalDateTime getModifiedOn() { return this.modifiedOn; } @@ -129,7 +127,7 @@ public class FloatingRatePeriod extends AbstractPersistableCustom { this.modifiedBy = modifiedBy; } - public void setModifiedOn(Date modifiedOn) { + public void setModifiedOn(LocalDateTime modifiedOn) { this.modifiedOn = modifiedOn; } @@ -138,7 +136,7 @@ public class FloatingRatePeriod extends AbstractPersistableCustom { } public LocalDate fetchFromDate() { - return LocalDate.ofInstant(this.fromDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return fromDate; } public FloatingRatePeriodData toData(final FloatingRateDTO floatingRateDTO) { @@ -148,10 +146,9 @@ public class FloatingRatePeriod extends AbstractPersistableCustom { interest = interest.add(floatingRateDTO.fetchBaseRate(fetchFromDate())); } - final LocalDate fromDate = ZonedDateTime.ofInstant(getFromDate().toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDate(); - final LocalDate createdOn = ZonedDateTime.ofInstant(getCreatedOn().toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDate(); - final LocalDate modifiedOn = ZonedDateTime.ofInstant(getModifiedOn().toInstant(), DateUtils.getDateTimeZoneOfTenant()) - .toLocalDate(); + final LocalDate fromDate = getFromDate(); + final LocalDateTime createdOn = getCreatedOn(); + final LocalDateTime modifiedOn = getModifiedOn(); String createdBy = getCreatedBy() != null ? getCreatedBy().getUsername() : null; String modifiedBy = getModifiedBy() != null ? getModifiedBy().getUsername() : null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/service/FloatingRatesReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/service/FloatingRatesReadPlatformServiceImpl.java index ea55d7300..7439a93c0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/service/FloatingRatesReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/service/FloatingRatesReadPlatformServiceImpl.java @@ -23,6 +23,7 @@ import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; import org.apache.fineract.portfolio.floatingrates.data.FloatingRateData; @@ -158,9 +159,9 @@ public class FloatingRatesReadPlatformServiceImpl implements FloatingRatesReadPl final boolean isDifferentialToBaseLendingRate = rs.getBoolean("isDifferentialToBaseLendingRate"); final boolean isActive = rs.getBoolean("isActive"); final String createdBy = rs.getString("createdBy"); - final LocalDate createdOn = JdbcSupport.getLocalDate(rs, "createdOn"); + final LocalDateTime createdOn = JdbcSupport.getLocalDateTime(rs, "createdOn"); final String modifiedBy = rs.getString("modifiedBy"); - final LocalDate modifiedOn = JdbcSupport.getLocalDate(rs, "modifiedOn"); + final LocalDateTime modifiedOn = JdbcSupport.getLocalDateTime(rs, "modifiedOn"); return new FloatingRatePeriodData(id, fromDate, interestRate, isDifferentialToBaseLendingRate, isActive, createdBy, createdOn, modifiedBy, modifiedOn); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/CentersApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/CentersApiResource.java index 08a55b1f5..653e8614c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/CentersApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/CentersApiResource.java @@ -31,7 +31,6 @@ import java.io.InputStream; import java.time.LocalDate; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -201,7 +200,7 @@ public class CentersApiResource { this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.CENTER_RESOURCE_NAME); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); if (meetingDateParam != null && officeId != null) { - Date meetingDate = meetingDateParam.getDate("meetingDate", dateFormat, locale); + LocalDate meetingDate = meetingDateParam.getDate("meetingDate", dateFormat, locale); Collection staffCenterDataArray = this.centerReadPlatformService.retriveAllCentersByMeetingDate(officeId, meetingDate, staffId); return this.toApiJsonSerializer.serialize(settings, staffCenterDataArray, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/Group.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/Group.java index fca2814f4..991ce4ba7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/Group.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/Group.java @@ -19,9 +19,7 @@ package org.apache.fineract.portfolio.group.domain; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; -import java.util.Date; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -37,10 +35,7 @@ import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.Transient; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.codes.domain.CodeValue; import org.apache.fineract.infrastructure.core.api.JsonCommand; @@ -76,8 +71,7 @@ public final class Group extends AbstractPersistableCustom { private Integer status; @Column(name = "activation_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date activationDate; + private LocalDate activationDate; @ManyToOne(optional = true) @JoinColumn(name = "activatedon_userid", nullable = true) @@ -118,16 +112,14 @@ public final class Group extends AbstractPersistableCustom { private CodeValue closureReason; @Column(name = "closedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date closureDate; + private LocalDate closureDate; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "closedon_userid", nullable = true) private AppUser closedBy; @Column(name = "submittedon_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date submittedOnDate; + private LocalDate submittedOnDate; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "submittedon_userid", nullable = true) @@ -209,7 +201,7 @@ public final class Group extends AbstractPersistableCustom { this.groupMembers.addAll(groupMembers); } - this.submittedOnDate = Date.from(submittedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.submittedOnDate = submittedOnDate; this.submittedBy = currentUser; this.staffHistory = null; @@ -241,8 +233,7 @@ public final class Group extends AbstractPersistableCustom { validateStatusNotEqualToActiveAndLogError(dataValidationErrors); if (dataValidationErrors.isEmpty()) { this.status = GroupingTypeStatus.ACTIVE.getValue(); - setActivationDate(Date.from(activationLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), currentUser, - dataValidationErrors); + setActivationDate(activationLocalDate, currentUser, dataValidationErrors); } } @@ -259,7 +250,8 @@ public final class Group extends AbstractPersistableCustom { } - private void setActivationDate(final Date activationDate, final AppUser loginUser, final List dataValidationErrors) { + private void setActivationDate(final LocalDate activationDate, final AppUser loginUser, + final List dataValidationErrors) { if (activationDate != null) { this.activationDate = activationDate; @@ -334,10 +326,7 @@ public final class Group extends AbstractPersistableCustom { actualChanges.put(GroupingTypesApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(GroupingTypesApiConstants.localeParamName, localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName); - if (newValue != null) { - this.activationDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } + this.activationDate = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName); } if (command.isChangeInStringParameterNamed(GroupingTypesApiConstants.accountNoParamName, this.accountNumber)) { @@ -352,25 +341,18 @@ public final class Group extends AbstractPersistableCustom { actualChanges.put(GroupingTypesApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(GroupingTypesApiConstants.localeParamName, localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.submittedOnDateParamName); - if (newValue != null) { - this.submittedOnDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } + this.submittedOnDate = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.submittedOnDateParamName); } return actualChanges; } public LocalDate getSubmittedOnDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.submittedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), null); + return this.submittedOnDate; } public LocalDate getActivationLocalDate() { - LocalDate activationLocalDate = null; - if (this.activationDate != null) { - activationLocalDate = LocalDate.ofInstant(this.activationDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return activationLocalDate; + return this.activationDate; } public List associateClients(final Set clientMembersSet) { @@ -540,7 +522,7 @@ public final class Group extends AbstractPersistableCustom { } this.closureReason = closureReason; - this.closureDate = Date.from(closureDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closureDate = closureDate; this.status = GroupingTypeStatus.CLOSED.getValue(); this.closedBy = currentUser; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/GroupRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/GroupRepository.java index 710a8dd9a..fdf6c5a63 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/GroupRepository.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/GroupRepository.java @@ -18,8 +18,8 @@ */ package org.apache.fineract.portfolio.group.domain; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; @@ -32,6 +32,6 @@ public interface GroupRepository extends JpaRepository, JpaSpecific String RETRIEVE_SUBMITTED_ON_DATE = "select g.submittedOnDate from Group g where g.id = :groupId"; @Query(RETRIEVE_SUBMITTED_ON_DATE) - Date retrieveGroupTypeSubmitteOndDate(@Param("groupId") Long groupId); + LocalDate retrieveGroupTypeSubmitteOndDate(@Param("groupId") Long groupId); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/GroupRepositoryWrapper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/GroupRepositoryWrapper.java index e101a80e6..e06899f17 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/GroupRepositoryWrapper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/GroupRepositoryWrapper.java @@ -19,8 +19,6 @@ package org.apache.fineract.portfolio.group.domain; import java.time.LocalDate; -import java.util.Date; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.office.domain.Office; import org.apache.fineract.portfolio.group.exception.GroupNotFoundException; import org.springframework.beans.factory.annotation.Autowired; @@ -70,10 +68,6 @@ public class GroupRepositoryWrapper { } public LocalDate retrieveSubmittedOndate(final Long groupId) { - Date submittedOnDate = this.repository.retrieveGroupTypeSubmitteOndDate(groupId); - if (submittedOnDate != null) { - return LocalDate.ofInstant(submittedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return null; + return this.repository.retrieveGroupTypeSubmitteOndDate(groupId); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/StaffAssignmentHistory.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/StaffAssignmentHistory.java index bf0c92ab4..a3a915370 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/StaffAssignmentHistory.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/StaffAssignmentHistory.java @@ -19,17 +19,12 @@ package org.apache.fineract.portfolio.group.domain; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.staff.domain.Staff; @Entity @@ -44,23 +39,21 @@ public class StaffAssignmentHistory extends AbstractAuditableCustom { @JoinColumn(name = "staff_id", nullable = true) private Staff staff; - @Temporal(TemporalType.DATE) @Column(name = "start_date") - private Date startDate; + private LocalDate startDate; - @Temporal(TemporalType.DATE) @Column(name = "end_date") - private Date endDate; + private LocalDate endDate; public static StaffAssignmentHistory createNew(final Group center, final Staff staff, final LocalDate startDate) { - return new StaffAssignmentHistory(center, staff, Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), null); + return new StaffAssignmentHistory(center, staff, startDate, null); } protected StaffAssignmentHistory() { // } - private StaffAssignmentHistory(final Group center, final Staff staff, final Date startDate, final Date endDate) { + private StaffAssignmentHistory(final Group center, final Staff staff, final LocalDate startDate, final LocalDate endDate) { this.center = center; this.staff = staff; this.startDate = startDate; @@ -72,11 +65,11 @@ public class StaffAssignmentHistory extends AbstractAuditableCustom { } public void updateStartDate(final LocalDate startDate) { - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = startDate; } public void updateEndDate(final LocalDate endDate) { - this.endDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.endDate = endDate; } public boolean matchesStartDateOf(final LocalDate matchingDate) { @@ -84,7 +77,7 @@ public class StaffAssignmentHistory extends AbstractAuditableCustom { } public LocalDate getStartDate() { - return LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return this.startDate; } public boolean isCurrentRecord() { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformService.java index 535f57ffd..2f0e9ce40 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformService.java @@ -18,8 +18,8 @@ */ package org.apache.fineract.portfolio.group.service; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import org.apache.fineract.infrastructure.core.data.PaginationParameters; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.SearchParameters; @@ -45,5 +45,5 @@ public interface CenterReadPlatformService { CenterData retrieveCenterWithClosureReasons(); - Collection retriveAllCentersByMeetingDate(Long officeId, Date meetingDate, Long staffId); + Collection retriveAllCentersByMeetingDate(Long officeId, LocalDate meetingDate, Long staffId); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java index 9b0fb8fc4..5c459f828 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java @@ -27,7 +27,6 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -495,22 +494,21 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService } @Override - public Collection retriveAllCentersByMeetingDate(final Long officeId, final Date meetingDate, final Long staffId) { + public Collection retriveAllCentersByMeetingDate(final Long officeId, final LocalDate meetingDate, + final Long staffId) { validateForGenerateCollectionSheet(staffId); - LocalDate localDate = LocalDate.ofInstant(meetingDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); final CenterCalendarDataMapper centerCalendarMapper = new CenterCalendarDataMapper(); - String passeddate = formatter.format(localDate); String sql = centerCalendarMapper.schema(); Collection centerDataArray; if (staffId != null) { sql += " and g.staff_id=? "; - sql += "and lrs.duedate<='" + passeddate + "' and l.loan_type_enum=3"; + sql += "and lrs.duedate<=? and l.loan_type_enum=3"; sql += " group by c.id, ci.id, g.account_no, g.external_id, g.status_enum, g.activation_date, g.hierarchy"; centerDataArray = this.jdbcTemplate.query(sql, centerCalendarMapper, // NOSONAR - new Object[] { passeddate, passeddate, passeddate, passeddate, passeddate, passeddate, officeId, staffId }); + meetingDate, meetingDate, meetingDate, meetingDate, meetingDate, meetingDate, officeId, staffId, meetingDate); } else { centerDataArray = this.jdbcTemplate.query(sql, centerCalendarMapper, // NOSONAR - new Object[] { passeddate, passeddate, passeddate, passeddate, passeddate, passeddate, officeId }); + meetingDate, meetingDate, meetingDate, meetingDate, meetingDate, meetingDate, officeId); } Collection staffCenterDataArray = new ArrayList<>(); @@ -521,8 +519,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService numberOfDays = this.configurationDomainService.retreivePeroidInNumberOfDaysForSkipMeetingDate().intValue(); } for (CenterData centerData : centerDataArray) { - if (centerData.getCollectionMeetingCalendar().isValidRecurringDate( - LocalDate.ofInstant(meetingDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), isSkipRepaymentOnFirstMonthEnabled, + if (centerData.getCollectionMeetingCalendar().isValidRecurringDate(meetingDate, isSkipRepaymentOnFirstMonthEnabled, numberOfDays)) { if (staffCenterDataArray.size() <= 0) { Collection meetingFallCenter = new ArrayList<>(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartFields.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartFields.java index c60b0a5cd..7e4c2499d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartFields.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartFields.java @@ -27,13 +27,9 @@ import static org.apache.fineract.portfolio.interestratechart.InterestRateChartA import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.nameParamName; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import java.util.Map; import javax.persistence.Column; import javax.persistence.Embeddable; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.domain.LocalDateInterval; @@ -48,13 +44,11 @@ public class InterestRateChartFields { @Column(name = "description", nullable = true) private String description; - @Temporal(TemporalType.DATE) @Column(name = "from_date", nullable = false) - private Date fromDate; + private LocalDate fromDate; - @Temporal(TemporalType.DATE) @Column(name = "end_date", nullable = true) - private Date endDate; + private LocalDate endDate; @Column(name = "is_primary_grouping_by_amount", nullable = false) private boolean isPrimaryGroupingByAmount; @@ -72,8 +66,8 @@ public class InterestRateChartFields { boolean isPrimaryGroupingByAmount) { this.name = name; this.description = description; - this.fromDate = Date.from(fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - this.endDate = (toDate == null) ? null : Date.from(toDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.fromDate = fromDate; + this.endDate = toDate; this.isPrimaryGroupingByAmount = isPrimaryGroupingByAmount; } @@ -95,21 +89,19 @@ public class InterestRateChartFields { final String dateFormat = command.dateFormat(); if (command.isChangeInLocalDateParameterNamed(fromDateParamName, getFromDateAsLocalDate())) { - final LocalDate newValue = command.localDateValueOfParameterNamed(fromDateParamName); final String newValueAsString = command.stringValueOfParameterNamed(fromDateParamName); actualChanges.put(fromDateParamName, newValueAsString); actualChanges.put(localeParamName, localeAsInput); actualChanges.put(dateFormatParamName, dateFormat); - this.fromDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.fromDate = command.localDateValueOfParameterNamed(fromDateParamName); } if (command.isChangeInLocalDateParameterNamed(endDateParamName, getEndDateAsLocalDate())) { - final LocalDate newValue = command.localDateValueOfParameterNamed(endDateParamName); final String newValueAsString = command.stringValueOfParameterNamed(endDateParamName); actualChanges.put(endDateParamName, newValueAsString); actualChanges.put(localeParamName, localeAsInput); actualChanges.put(dateFormatParamName, dateFormat); - this.endDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.endDate = command.localDateValueOfParameterNamed(endDateParamName); } if (command.isChangeInBooleanParameterNamed(isPrimaryGroupingByAmountParamName, this.isPrimaryGroupingByAmount)) { @@ -136,19 +128,11 @@ public class InterestRateChartFields { } public LocalDate getFromDateAsLocalDate() { - LocalDate fromDate = null; - if (this.fromDate != null) { - fromDate = LocalDate.ofInstant(this.fromDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return fromDate; + return this.fromDate; } public LocalDate getEndDateAsLocalDate() { - LocalDate endDate = null; - if (this.endDate != null) { - endDate = LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return endDate; + return this.endDate; } public boolean isOverlapping(InterestRateChartFields that) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResource.java index 4eed49599..77dc0fdf3 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResource.java @@ -169,8 +169,7 @@ public class LoanTransactionsApiResource { if (transactionDateParam == null) { transactionDate = DateUtils.getBusinessLocalDate(); } else { - transactionDate = LocalDate.ofInstant(transactionDateParam.getDate("transactionDate", dateFormat, locale).toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + transactionDate = transactionDateParam.getDate("transactionDate", dateFormat, locale); } transactionData = this.loanReadPlatformService.retrieveLoanPrePaymentTemplate(LoanTransactionType.REPAYMENT, loanId, transactionDate); @@ -183,8 +182,7 @@ public class LoanTransactionsApiResource { if (transactionDateParam == null) { transactionDate = DateUtils.getBusinessLocalDate(); } else { - transactionDate = LocalDate.ofInstant(transactionDateParam.getDate("transactionDate", dateFormat, locale).toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + transactionDate = transactionDateParam.getDate("transactionDate", dateFormat, locale); } transactionData = this.loanReadPlatformService.retrieveLoanForeclosureTemplate(loanId, transactionDate); } else if (is(commandParam, "creditBalanceRefund")) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java index 2bc2c881f..d2699df24 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java @@ -727,9 +727,7 @@ public class LoanTransaction extends AbstractAuditableCustom { } public LocalDateTime getCreatedDateTime() { - return (this.getCreatedDate().isPresent() - ? LocalDateTime.ofInstant(this.getCreatedDate().get(), DateUtils.getDateTimeZoneOfTenant()) - : DateUtils.getLocalDateTimeOfTenant()); + return (this.getCreatedDate().isPresent() ? this.getCreatedDate().get() : DateUtils.getLocalDateTimeOfTenant()); } public boolean isLastTransaction(final LoanTransaction loanTransaction) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGenerator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGenerator.java index b2221bc14..154856a4c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGenerator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGenerator.java @@ -66,7 +66,7 @@ public class DefaultScheduledDateGenerator implements ScheduledDateGenerator { Calendar currentCalendar = loanApplicationTerms.getLoanCalendar(); dueRepaymentPeriodDate = getRepaymentPeriodDate(loanApplicationTerms.getRepaymentPeriodFrequencyType(), loanApplicationTerms.getRepaymentEvery(), lastRepaymentDate); - dueRepaymentPeriodDate = CalendarUtils.adjustDate(dueRepaymentPeriodDate, loanApplicationTerms.getSeedDate(), + dueRepaymentPeriodDate = (LocalDate) CalendarUtils.adjustDate(dueRepaymentPeriodDate, loanApplicationTerms.getSeedDate(), loanApplicationTerms.getRepaymentPeriodFrequencyType()); if (currentCalendar != null) { // If we have currentCalendar object, this means there is a diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java index 03cef56c4..0e8bb7c33 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java @@ -839,10 +839,10 @@ public final class LoanApplicationTerms { int diffDays = 0; if (this.loanCalendar == null) { startDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths); - startDateAfterConsideringMonths = CalendarUtils.adjustDate(startDateAfterConsideringMonths, getSeedDate(), + startDateAfterConsideringMonths = (LocalDate) CalendarUtils.adjustDate(startDateAfterConsideringMonths, getSeedDate(), this.repaymentPeriodFrequencyType); endDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths + 1); - endDateAfterConsideringMonths = CalendarUtils.adjustDate(endDateAfterConsideringMonths, getSeedDate(), + endDateAfterConsideringMonths = (LocalDate) CalendarUtils.adjustDate(endDateAfterConsideringMonths, getSeedDate(), this.repaymentPeriodFrequencyType); } else { LocalDate expectedStartDate = startDate; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanRepaymentScheduleHistory.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanRepaymentScheduleHistory.java index 77e754549..7b2acca54 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanRepaymentScheduleHistory.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanRepaymentScheduleHistory.java @@ -20,6 +20,7 @@ package org.apache.fineract.portfolio.loanaccount.loanschedule.domain; import java.math.BigDecimal; import java.time.LocalDate; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; @@ -64,7 +65,7 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom { private BigDecimal penaltyCharges; @Column(name = "created_date") - private LocalDate createdOnDate; + private LocalDateTime createdOnDate; @Column(name = "createdby_id") private Long createdByUser; @@ -73,7 +74,7 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom { private Long lastModifiedByUser; @Column(name = "lastmodified_date") - private LocalDate lastModifiedOnDate; + private LocalDateTime lastModifiedOnDate; @Column(name = "version") private Integer version; @@ -89,8 +90,8 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom { private LoanRepaymentScheduleHistory(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest, final Integer installmentNumber, final LocalDate fromDate, final LocalDate dueDate, final BigDecimal principal, final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges, - final LocalDate createdOnDate, final Long createdByUser, final Long lastModifiedByUser, final LocalDate lastModifiedOnDate, - final Integer version) { + final LocalDateTime createdOnDate, final Long createdByUser, final Long lastModifiedByUser, + final LocalDateTime lastModifiedOnDate, final Integer version) { this.loan = loan; this.loanRescheduleRequest = loanRescheduleRequest; @@ -114,8 +115,8 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom { public static LoanRepaymentScheduleHistory instance(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest, final Integer installmentNumber, final LocalDate fromDate, final LocalDate dueDate, final BigDecimal principal, final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges, - final LocalDate createdOnDate, final Long createdByUser, final Long lastModifiedByUser, final LocalDate lastModifiedOnDate, - final Integer version) { + final LocalDateTime createdOnDate, final Long createdByUser, final Long lastModifiedByUser, + final LocalDateTime lastModifiedOnDate, final Integer version) { return new LoanRepaymentScheduleHistory(loan, loanRescheduleRequest, installmentNumber, fromDate, dueDate, principal, interestCharged, feeChargesCharged, penaltyCharges, createdOnDate, createdByUser, lastModifiedByUser, lastModifiedOnDate, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleHistoryWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleHistoryWritePlatformServiceImpl.java index a84f67798..12f5d2f78 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleHistoryWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleHistoryWritePlatformServiceImpl.java @@ -20,9 +20,9 @@ package org.apache.fineract.portfolio.loanaccount.loanschedule.service; import java.math.BigDecimal; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.portfolio.loanaccount.domain.Loan; import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment; @@ -73,20 +73,18 @@ public class LoanScheduleHistoryWritePlatformServiceImpl implements LoanSchedule final BigDecimal feeChargesCharged = repaymentScheduleInstallment.getFeeChargesCharged(currency).getAmount(); final BigDecimal penaltyCharges = repaymentScheduleInstallment.getPenaltyChargesCharged(currency).getAmount(); - LocalDate createdOnDate = null; + LocalDateTime createdOnDate = null; if (repaymentScheduleInstallment.getCreatedDate().isPresent()) { - createdOnDate = LocalDate.ofInstant(repaymentScheduleInstallment.getCreatedDate().get(), - DateUtils.getDateTimeZoneOfTenant()); // NOSONAR + createdOnDate = repaymentScheduleInstallment.getCreatedDate().get(); // NOSONAR } final Long createdByUser = repaymentScheduleInstallment.getCreatedBy().orElse(null); final Long lastModifiedByUser = repaymentScheduleInstallment.getLastModifiedBy().orElse(null); - LocalDate lastModifiedOnDate = null; + LocalDateTime lastModifiedOnDate = null; if (repaymentScheduleInstallment.getLastModifiedDate().isPresent()) { - lastModifiedOnDate = LocalDate.ofInstant(repaymentScheduleInstallment.getLastModifiedDate().get(), - DateUtils.getDateTimeZoneOfTenant()); // NOSONAR + lastModifiedOnDate = repaymentScheduleInstallment.getLastModifiedDate().get(); // NOSONAR } LoanRepaymentScheduleHistory loanRepaymentScheduleHistory = LoanRepaymentScheduleHistory.instance(loan, loanRescheduleRequest, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java index 408555669..a5af8b816 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java @@ -270,7 +270,7 @@ public class LoanAccrualWritePlatformServiceImpl implements LoanAccrualWritePlat + "fee_charges_portion_derived,penalty_charges_portion_derived, submitted_on_date) VALUES (?, ?, false, ?, ?, ?, ?, ?, ?, ?)"; this.jdbcTemplate.update(transactionSql, scheduleAccrualData.getLoanId(), scheduleAccrualData.getOfficeId(), LoanTransactionType.ACCRUAL.getValue(), accruedTill, amount, interestportion, feeportion, penaltyportion, - DateUtils.getBusinessDate()); + DateUtils.getBusinessLocalDate()); @SuppressWarnings("deprecation") final Long transactonId = this.jdbcTemplate.queryForObject("SELECT " + sqlGenerator.lastInsertId(), Long.class); // NOSONAR diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index a9cfa8787..116c48415 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -22,7 +22,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.math.BigDecimal; -import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -1759,7 +1758,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf chargePerInstallment.getInstallment().setFeeChargesWaived(feeChargesWaivedAmount.subtract(amountWaived)); // Set the last modification date. - chargePerInstallment.getInstallment().setLastModifiedDate(Instant.now()); + chargePerInstallment.getInstallment().setLastModifiedDate(DateUtils.getLocalDateTimeOfSystem()); // Update loan charge. loanCharge.setInstallmentLoanCharge(chargePerInstallment, chargePerInstallment.getInstallment().getInstallmentNumber()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProduct.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProduct.java index 4413a4ff1..d9a1ada88 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProduct.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProduct.java @@ -22,11 +22,9 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -45,14 +43,11 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.accounting.common.AccountingRuleType; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.Money; import org.apache.fineract.portfolio.charge.domain.Charge; @@ -126,12 +121,10 @@ public class LoanProduct extends AbstractPersistableCustom { private LoanProductTrancheDetails loanProducTrancheDetails; @Column(name = "start_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date startDate; + private LocalDate startDate; @Column(name = "close_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date closeDate; + private LocalDate closeDate; @Column(name = "external_id", length = 100, nullable = true, unique = true) private String externalId; @@ -676,13 +669,8 @@ public class LoanProduct extends AbstractPersistableCustom { this.includeInBorrowerCycle = includeInBorrowerCycle; this.useBorrowerCycle = useBorrowerCycle; - if (startDate != null) { - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } - - if (closeDate != null) { - this.closeDate = Date.from(closeDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } + this.startDate = startDate; + this.closeDate = closeDate; this.externalId = externalId; this.borrowerCycleVariations = loanProductBorrowerCycleVariations; @@ -970,12 +958,7 @@ public class LoanProduct extends AbstractPersistableCustom { actualChanges.put(dateFormatParamName, dateFormatAsInput); actualChanges.put(localeParamName, localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(startDateParamName); - if (newValue != null) { - this.startDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } else { - this.startDate = null; - } + this.startDate = command.localDateValueOfParameterNamed(startDateParamName); } final String closeDateParamName = "closeDate"; @@ -985,12 +968,7 @@ public class LoanProduct extends AbstractPersistableCustom { actualChanges.put(dateFormatParamName, dateFormatAsInput); actualChanges.put(localeParamName, localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(closeDateParamName); - if (newValue != null) { - this.closeDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } else { - this.closeDate = null; - } + this.closeDate = command.localDateValueOfParameterNamed(closeDateParamName); } final String externalIdTypeParamName = "externalId"; @@ -1312,19 +1290,11 @@ public class LoanProduct extends AbstractPersistableCustom { } public LocalDate getStartDate() { - LocalDate startLocalDate = null; - if (this.startDate != null) { - startLocalDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return startLocalDate; + return this.startDate; } public LocalDate getCloseDate() { - LocalDate closeLocalDate = null; - if (this.closeDate != null) { - closeLocalDate = LocalDate.ofInstant(this.closeDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return closeLocalDate; + return this.closeDate; } public String productName() { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/domain/Meeting.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/domain/Meeting.java index d334b918a..17e28e3ec 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/domain/Meeting.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/domain/Meeting.java @@ -24,9 +24,7 @@ import static org.apache.fineract.portfolio.meeting.MeetingApiConstants.clientsA import static org.apache.fineract.portfolio.meeting.MeetingApiConstants.meetingDateParamName; import java.time.LocalDate; -import java.time.ZoneId; import java.util.Collection; -import java.util.Date; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; @@ -39,8 +37,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @@ -62,8 +58,7 @@ public class Meeting extends AbstractPersistableCustom { private CalendarInstance calendarInstance; @Column(name = "meeting_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date meetingDate; + private LocalDate meetingDate; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "meeting", orphanRemoval = true) private Set clientsAttendance; @@ -72,12 +67,12 @@ public class Meeting extends AbstractPersistableCustom { // } - private Meeting(final CalendarInstance calendarInstance, final Date meetingDate) { + private Meeting(final CalendarInstance calendarInstance, final LocalDate meetingDate) { this.calendarInstance = calendarInstance; this.meetingDate = meetingDate; } - public static Meeting createNew(final CalendarInstance calendarInstance, final Date meetingDate, + public static Meeting createNew(final CalendarInstance calendarInstance, final LocalDate meetingDate, Boolean isTransactionDateOnNonMeetingDate, final boolean isSkipRepaymentOnFirstMonth, final int numberOfDays) { if (!isTransactionDateOnNonMeetingDate @@ -102,12 +97,10 @@ public class Meeting extends AbstractPersistableCustom { final String localeAsInput = command.locale(); if (command.isChangeInLocalDateParameterNamed(meetingDateParamName, getMeetingDateLocalDate())) { - final String valueAsInput = command.stringValueOfParameterNamed(meetingDateParamName); - final LocalDate newValue = command.localDateValueOfParameterNamed(meetingDateParamName); - actualChanges.put(meetingDateParamName, valueAsInput); + actualChanges.put(meetingDateParamName, command.stringValueOfParameterNamed(meetingDateParamName)); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); - this.meetingDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.meetingDate = command.localDateValueOfParameterNamed(meetingDateParamName); if (!isValidMeetingDate(this.calendarInstance, this.meetingDate, isSkipRepaymentOnFirstMonth, numberOfDays)) { throw new NotValidRecurringDateException("meeting", "Not a valid meeting date", this.meetingDate); @@ -166,14 +159,10 @@ public class Meeting extends AbstractPersistableCustom { } public LocalDate getMeetingDateLocalDate() { - LocalDate meetingDateLocalDate = null; - if (this.meetingDate != null) { - meetingDateLocalDate = LocalDate.ofInstant(this.meetingDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return meetingDateLocalDate; + return this.meetingDate; } - public Date getMeetingDate() { + public LocalDate getMeetingDate() { return this.meetingDate; } @@ -181,16 +170,11 @@ public class Meeting extends AbstractPersistableCustom { return this.meetingDate != null && newStartDate != null && getMeetingDateLocalDate().isBefore(newStartDate) ? true : false; } - private static boolean isValidMeetingDate(final CalendarInstance calendarInstance, final Date meetingDate, + private static boolean isValidMeetingDate(final CalendarInstance calendarInstance, final LocalDate meetingDate, final boolean isSkipRepaymentOnFirstMonth, final int numberOfDays) { final Calendar calendar = calendarInstance.getCalendar(); - LocalDate meetingDateLocalDate = null; - if (meetingDate != null) { - meetingDateLocalDate = LocalDate.ofInstant(meetingDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - if (meetingDateLocalDate == null - || !calendar.isValidRecurringDate(meetingDateLocalDate, isSkipRepaymentOnFirstMonth, numberOfDays)) { + if (meetingDate == null || !calendar.isValidRecurringDate(meetingDate, isSkipRepaymentOnFirstMonth, numberOfDays)) { return false; } return true; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/domain/MeetingRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/domain/MeetingRepository.java index 52b8bfaf3..d547e45a9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/domain/MeetingRepository.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/domain/MeetingRepository.java @@ -18,11 +18,11 @@ */ package org.apache.fineract.portfolio.meeting.domain; -import java.util.Date; +import java.time.LocalDate; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; public interface MeetingRepository extends JpaRepository, JpaSpecificationExecutor { - Meeting findByCalendarInstanceIdAndMeetingDate(Long calendarInstanceId, Date meetingDate); + Meeting findByCalendarInstanceIdAndMeetingDate(Long calendarInstanceId, LocalDate meetingDate); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java index bcf7be91c..9a5ae03b4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java @@ -32,7 +32,6 @@ import com.google.gson.JsonObject; import java.time.LocalDate; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.Map; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.apache.fineract.infrastructure.core.api.JsonCommand; @@ -40,7 +39,6 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.portfolio.calendar.domain.Calendar; import org.apache.fineract.portfolio.calendar.domain.CalendarEntityType; import org.apache.fineract.portfolio.calendar.domain.CalendarInstance; @@ -98,7 +96,7 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit this.meetingDataValidator.validateForCreate(command); - final Date meetingDate = command.dateValueOfParameterNamed(meetingDateParamName); + final LocalDate meetingDate = command.dateValueOfParameterNamed(meetingDateParamName); final Boolean isTransactionDateOnNonMeetingDate = false; /* * Boolean isSkipRepaymentOnFirstMonth = false; Integer numberOfDays = 0; boolean @@ -298,11 +296,10 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit .build(); } - private void handleMeetingDataIntegrityIssues(final Date meetingDate, final Throwable realCause, final Exception dve) { + private void handleMeetingDataIntegrityIssues(final LocalDate meetingDate, final Throwable realCause, final Exception dve) { if (realCause.getMessage().contains("unique_calendar_instance_id_meeting_date")) { - final LocalDate meetingDateLocal = LocalDate.ofInstant(meetingDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); throw new PlatformDataIntegrityException("error.msg.meeting.duplicate", - "A meeting with date '" + meetingDateLocal + "' already exists", meetingDateParamName, meetingDateLocal); + "A meeting with date '" + meetingDate + "' already exists", meetingDateParamName, meetingDate); } throw new PlatformDataIntegrityException("error.msg.meeting.unknown.data.integrity.issue", @@ -311,7 +308,7 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit @Override public void updateCollectionSheetAttendance(final JsonCommand command) { - final Date meetingDate = command.dateValueOfParameterNamed(transactionDateParamName); + final LocalDate meetingDate = command.dateValueOfParameterNamed(transactionDateParamName); final Boolean isTransactionDateOnNonMeetingDate = command .booleanPrimitiveValueOfParameterNamed(isTransactionDateOnNonMeetingDateParamName); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/repaymentwithpostdatedchecks/domain/PostDatedChecks.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/repaymentwithpostdatedchecks/domain/PostDatedChecks.java index b4cc449ba..ba681b01a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/repaymentwithpostdatedchecks/domain/PostDatedChecks.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/repaymentwithpostdatedchecks/domain/PostDatedChecks.java @@ -19,7 +19,7 @@ package org.apache.fineract.portfolio.repaymentwithpostdatedchecks.domain; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.HashMap; import java.util.Map; import javax.persistence.Column; @@ -30,7 +30,6 @@ import javax.persistence.OneToOne; import javax.persistence.Table; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.portfolio.loanaccount.domain.Loan; import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment; @@ -51,7 +50,7 @@ public class PostDatedChecks extends AbstractPersistableCustom { @Column(name = "amount", scale = 6, precision = 19) private BigDecimal amount; @Column(name = "repayment_date", nullable = false) - private Date repaymentDate; + private LocalDate repaymentDate; @Column(name = "status", columnDefinition = "0") private Integer status; @Column(name = "check_no", nullable = false, unique = true) @@ -60,7 +59,8 @@ public class PostDatedChecks extends AbstractPersistableCustom { public PostDatedChecks() {} private PostDatedChecks(final Long accountNo, final String bankName, final BigDecimal amount, - final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment, final Date date, final Loan loan, final Long checkNo) { + final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment, final LocalDate date, final Loan loan, + final Long checkNo) { this.bankName = bankName; this.accountNo = accountNo; this.amount = amount; @@ -73,8 +73,7 @@ public class PostDatedChecks extends AbstractPersistableCustom { public static PostDatedChecks instanceOf(final Long accountNo, final String bankName, final BigDecimal amount, final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment, final Loan loan, final Long checkNo) { return new PostDatedChecks(accountNo, bankName, amount, loanRepaymentScheduleInstallment, - Date.from(loanRepaymentScheduleInstallment.getDueDate().atStartOfDay(DateUtils.getDateTimeZoneOfTenant()).toInstant()), - loan, checkNo); + loanRepaymentScheduleInstallment.getDueDate(), loan, checkNo); } public void setLoan(Loan loan) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountData.java index 83617b084..ee89ea6d7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountData.java @@ -24,7 +24,6 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -33,7 +32,6 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.fineract.infrastructure.core.data.EnumOptionData; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.dataqueries.data.DatatableData; import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.organisation.staff.data.StaffData; @@ -125,13 +123,13 @@ public final class SavingsAccountData implements Serializable { private String locale; private String dateFormat; private transient Integer rowIndex; - private transient Date startInterestCalculationDate; + private transient LocalDate startInterestCalculationDate; private LocalDate submittedOnDate; private transient SavingsAccountTransactionSummaryWrapper savingsAccountTransactionSummaryWrapper; private transient SavingsHelper savingsHelper; private transient SavingsAccountSummaryData savingsAccountSummaryData; - private transient Date activatedOnDate; + private transient LocalDate activatedOnDate; private transient LocalDate lockedInUntilDate; private transient ClientData clientData; private transient SavingsProductData savingsProductData; @@ -267,7 +265,7 @@ public final class SavingsAccountData implements Serializable { this.lockedInUntilDate = lockedInUntilDate; } - public void setStartInterestCalculationDate(final Date startInterestCalculationDate) { + public void setStartInterestCalculationDate(final LocalDate startInterestCalculationDate) { this.startInterestCalculationDate = startInterestCalculationDate; } @@ -435,8 +433,7 @@ public final class SavingsAccountData implements Serializable { public LocalDate getStartInterestCalculationDate() { LocalDate startInterestCalculationLocalDate = null; if (this.startInterestCalculationDate != null) { - startInterestCalculationLocalDate = LocalDate.ofInstant(this.startInterestCalculationDate.toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + startInterestCalculationLocalDate = this.startInterestCalculationDate; } else { startInterestCalculationLocalDate = getActivationLocalDate(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionDTO.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionDTO.java index 14e0b7142..37b38a896 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionDTO.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionDTO.java @@ -20,8 +20,8 @@ package org.apache.fineract.portfolio.savings.data; import java.math.BigDecimal; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.Date; import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail; import org.apache.fineract.useradministration.domain.AppUser; @@ -31,13 +31,13 @@ public class SavingsAccountTransactionDTO { private final LocalDate transactionDate; private final BigDecimal transactionAmount; private final PaymentDetail paymentDetail; - private final Date createdDate; + private final LocalDateTime createdDate; private final Long savingsAccountId; private final AppUser appUser; private final Integer depositAccountType; public SavingsAccountTransactionDTO(final DateTimeFormatter formatter, final LocalDate transactionDate, - final BigDecimal transactionAmount, final PaymentDetail paymentDetail, final Date createdDate, final AppUser appUser, + final BigDecimal transactionAmount, final PaymentDetail paymentDetail, final LocalDateTime createdDate, final AppUser appUser, final Integer depositAccountType) { this.formatter = formatter; this.transactionDate = transactionDate; @@ -60,7 +60,8 @@ public class SavingsAccountTransactionDTO { * @param savingsAccountId */ public SavingsAccountTransactionDTO(DateTimeFormatter formatter, LocalDate transactionDate, BigDecimal transactionAmount, - PaymentDetail paymentDetail, Date createdDate, Long savingsAccountId, AppUser appUser, final Integer depositAccountType) { + PaymentDetail paymentDetail, LocalDateTime createdDate, Long savingsAccountId, AppUser appUser, + final Integer depositAccountType) { this.formatter = formatter; this.transactionDate = transactionDate; this.transactionAmount = transactionAmount; @@ -87,7 +88,7 @@ public class SavingsAccountTransactionDTO { return this.paymentDetail; } - public Date getCreatedDate() { + public LocalDateTime getCreatedDate() { return this.createdDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionData.java index a4946477f..92cd095be 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionData.java @@ -21,10 +21,8 @@ package org.apache.fineract.portfolio.savings.data; import java.io.Serializable; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -66,7 +64,7 @@ public final class SavingsAccountTransactionData implements Serializable { private BigDecimal runningBalance; private boolean reversed; private final AccountTransferData transfer; - private Date submittedOnDate; + private LocalDate submittedOnDate; private final boolean interestedPostedAsOn; private final String submittedByUsername; private final String note; @@ -322,9 +320,9 @@ public final class SavingsAccountTransactionData implements Serializable { } private SavingsAccountTransactionData(final Long savingsId, final Long officeId, final PaymentDetailData paymentDetailData, - final SavingsAccountTransactionEnumData savingsAccountTransactionType, final LocalDate transactionDate, final Date createdDate, - final BigDecimal amount, final boolean isReversed, final Long userId, final boolean isManualTransaction, - final Boolean lienTransaction) { + final SavingsAccountTransactionEnumData savingsAccountTransactionType, final LocalDate transactionDate, + final LocalDate createdDate, final BigDecimal amount, final boolean isReversed, final Long userId, + final boolean isManualTransaction, final Boolean lienTransaction) { this.savingsAccountId = savingsId; this.paymentDetailData = paymentDetailData; this.transactionType = savingsAccountTransactionType; @@ -539,7 +537,7 @@ public final class SavingsAccountTransactionData implements Serializable { this.runningBalance = null; this.reversed = isReversed; this.transfer = null; - this.submittedOnDate = Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.submittedOnDate = transactionDate; this.interestedPostedAsOn = false; this.rowIndex = null; this.savingsAccountId = savingsAccountId; @@ -707,7 +705,7 @@ public final class SavingsAccountTransactionData implements Serializable { return this.balanceEndDate; } - public Date getSubmittedOnDate() { + public LocalDate getSubmittedOnDate() { return this.submittedOnDate; } @@ -770,7 +768,7 @@ public final class SavingsAccountTransactionData implements Serializable { this.runningBalance = runningBalance; this.reversed = reversed; this.paymentTypeOptions = paymentTypeOptions; - this.submittedOnDate = Date.from(submittedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.submittedOnDate = submittedOnDate; this.interestedPostedAsOn = interestedPostedAsOn; this.cumulativeBalance = cumulativeBalance; this.transfer = null; @@ -877,11 +875,7 @@ public final class SavingsAccountTransactionData implements Serializable { this.reversed = reversed; this.transfer = transfer; this.paymentTypeOptions = paymentTypeOptions; - if (submittedOnDate != null) { - this.submittedOnDate = Date.from(submittedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } else { - this.submittedOnDate = null; - } + this.submittedOnDate = submittedOnDate; this.interestedPostedAsOn = interestedPostedAsOn; this.submittedByUsername = submittedByUsername; @@ -913,11 +907,7 @@ public final class SavingsAccountTransactionData implements Serializable { this.reversed = reversed; this.transfer = transfer; this.paymentTypeOptions = paymentTypeOptions; - if (submittedOnDate != null) { - this.submittedOnDate = Date.from(submittedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } else { - this.submittedOnDate = null; - } + this.submittedOnDate = submittedOnDate; this.interestedPostedAsOn = interestedPostedAsOn; this.submittedByUsername = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionDataValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionDataValidator.java index 2a0047ef3..802e4c41d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionDataValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionDataValidator.java @@ -37,9 +37,9 @@ import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.math.BigDecimal; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -87,10 +87,10 @@ public class SavingsAccountTransactionDataValidator { final boolean backdatedTxnsAllowedTill = this.configurationDomainService.retrievePivotDateConfig(); final boolean isRelaxingDaysConfigOn = this.configurationDomainService.isRelaxingDaysConfigForPivotDateEnabled(); - final Date lastInterestPostingDate = savingsAccount.getSummary().getInterestPostedTillDate(); + final LocalDate lastInterestPostingDate = savingsAccount.getSummary().getInterestPostedTillDate(); if (backdatedTxnsAllowedTill && lastInterestPostingDate != null) { - LocalDate pivotDate = LocalDate.ofInstant(lastInterestPostingDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + LocalDate pivotDate = lastInterestPostingDate; if (isRelaxingDaysConfigOn) { pivotDate = pivotDate.minusDays(this.configurationDomainService.retrieveRelaxingDaysConfigForPivotDate()); } @@ -326,7 +326,7 @@ public class SavingsAccountTransactionDataValidator { } throwExceptionIfValidationWarningsExist(dataValidationErrors); - Date createdDate = new Date(); + LocalDateTime createdDate = DateUtils.getLocalDateTimeOfSystem(); LocalDate transactionDate = DateUtils.getBusinessLocalDate(); SavingsAccountTransaction transaction = SavingsAccountTransaction.releaseAmount(holdTransaction, transactionDate, createdDate, createdUser); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountAssembler.java index 0a6fafd96..abf8051de 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountAssembler.java @@ -62,7 +62,6 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.Locale; import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -475,7 +474,7 @@ public class DepositAccountAssembler { detail = this.paymentDetailAssembler.fetchPaymentDetail(savingsTransactionElement); } final SavingsAccountTransactionDTO savingsAccountTransactionDTO = new SavingsAccountTransactionDTO(formatter, - transactionDate, dueAmount, detail, new Date(), savingsId, user, depositAccountType); + transactionDate, dueAmount, detail, DateUtils.getLocalDateTimeOfSystem(), savingsId, user, depositAccountType); savingsAccountTransactions.add(savingsAccountTransactionDTO); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountDomainServiceJpa.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountDomainServiceJpa.java index 44fe44212..85f49ef40 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountDomainServiceJpa.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountDomainServiceJpa.java @@ -25,9 +25,7 @@ import static org.apache.fineract.portfolio.savings.DepositsApiConstants.transfe import java.math.BigDecimal; import java.math.MathContext; import java.time.LocalDate; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -311,7 +309,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi account.updateOnAccountClosureStatus(onClosureType); } changes.put("reinvestedDepositId", reinvestedDeposit.getId()); - reinvestedDeposit.approveAndActivateApplication(Date.from(closedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), user); + reinvestedDeposit.approveAndActivateApplication(closedDate, user); this.savingsAccountRepository.save(reinvestedDeposit); } else if (onClosureType.isTransferToSavings()) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountOnHoldTransaction.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountOnHoldTransaction.java index 0a0eea2e5..0bf3922c8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountOnHoldTransaction.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountOnHoldTransaction.java @@ -20,8 +20,7 @@ package org.apache.fineract.portfolio.savings.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -29,8 +28,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; @@ -52,16 +49,14 @@ public class DepositAccountOnHoldTransaction extends AbstractPersistableCustom { @Column(name = "transaction_type_enum", nullable = false) private Integer transactionType; - @Temporal(TemporalType.DATE) @Column(name = "transaction_date", nullable = false) - private Date transactionDate; + private LocalDate transactionDate; @Column(name = "is_reversed", nullable = false) private boolean reversed; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_date", nullable = false) - private Date createdDate; + private LocalDateTime createdDate; @OneToOne(cascade = CascadeType.ALL, mappedBy = "depositAccountOnHoldTransaction", optional = true, orphanRemoval = true) private GuarantorFundingTransaction guarantorFundingTransaction; @@ -73,8 +68,8 @@ public class DepositAccountOnHoldTransaction extends AbstractPersistableCustom { this.savingsAccount = savingsAccount; this.amount = amount; this.transactionType = transactionType.getValue(); - this.transactionDate = Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - this.createdDate = new Date(); + this.transactionDate = transactionDate; + this.createdDate = DateUtils.getLocalDateTimeOfSystem(); this.reversed = reversed; } @@ -114,11 +109,7 @@ public class DepositAccountOnHoldTransaction extends AbstractPersistableCustom { } public LocalDate getTransactionDate() { - LocalDate transactionDate = null; - if (this.transactionDate != null) { - transactionDate = LocalDate.ofInstant(this.transactionDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return transactionDate; + return this.transactionDate; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountTermAndPreClosure.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountTermAndPreClosure.java index cad363de9..2377203fc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountTermAndPreClosure.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountTermAndPreClosure.java @@ -30,9 +30,7 @@ import static org.apache.fineract.portfolio.savings.DepositsApiConstants.transfe import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.time.temporal.ChronoUnit; -import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; import javax.persistence.Column; @@ -41,12 +39,9 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.portfolio.savings.DepositAccountOnClosureType; import org.apache.fineract.portfolio.savings.SavingsPeriodFrequencyType; import org.apache.fineract.portfolio.savings.service.SavingsEnumerations; @@ -61,13 +56,11 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistableCustom { @Column(name = "maturity_amount", scale = 6, precision = 19, nullable = true) private BigDecimal maturityAmount; - @Temporal(TemporalType.DATE) @Column(name = "maturity_date", nullable = true) - private Date maturityDate; + private LocalDate maturityDate; - @Temporal(TemporalType.DATE) @Column(name = "expected_firstdepositon_date") - private Date expectedFirstDepositOnDate; + private LocalDate expectedFirstDepositOnDate; @Column(name = "deposit_period", nullable = true) private Integer depositPeriod; @@ -114,14 +107,13 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistableCustom { final DepositAccountOnClosureType accountOnClosureType, Boolean transferInterest, Long transferToSavingsId) { this.depositAmount = depositAmount; this.maturityAmount = maturityAmount; - this.maturityDate = (maturityDate == null) ? null : Date.from(maturityDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.maturityDate = maturityDate; this.depositPeriod = depositPeriod; this.depositPeriodFrequency = (depositPeriodFrequency == null) ? null : depositPeriodFrequency.getValue(); this.preClosureDetail = preClosureDetail; this.depositTermDetail = depositTermDetail; this.account = account; - this.expectedFirstDepositOnDate = expectedFirstDepositOnDate == null ? null - : Date.from(expectedFirstDepositOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.expectedFirstDepositOnDate = expectedFirstDepositOnDate; this.onAccountClosureType = (accountOnClosureType == null) ? null : accountOnClosureType.getValue(); this.transferInterestToLinkedAccount = transferInterest; this.transferToSavingsAccountId = transferToSavingsId; @@ -151,12 +143,11 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistableCustom { final String localeAsInput = command.locale(); final String dateFormat = command.dateFormat(); if (command.isChangeInLocalDateParameterNamed(expectedFirstDepositOnDateParamName, this.getExpectedFirstDepositOnDate())) { - final LocalDate newValue = command.localDateValueOfParameterNamed(expectedFirstDepositOnDateParamName); final String newValueAsString = command.stringValueOfParameterNamed(expectedFirstDepositOnDateParamName); actualChanges.put(expectedFirstDepositOnDateParamName, newValueAsString); actualChanges.put(localeParamName, localeAsInput); actualChanges.put(dateFormatParamName, dateFormat); - this.expectedFirstDepositOnDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.expectedFirstDepositOnDate = command.localDateValueOfParameterNamed(expectedFirstDepositOnDateParamName); } if (command.isChangeInBooleanParameterNamed(transferInterestToSavingsParamName, this.transferInterestToLinkedAccount)) { @@ -219,13 +210,13 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistableCustom { public void updateMaturityDetails(final BigDecimal maturityAmount, final LocalDate maturityDate) { this.maturityAmount = maturityAmount; - this.maturityDate = Date.from(maturityDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.maturityDate = maturityDate; } public void updateMaturityDetails(final BigDecimal depositAmount, final BigDecimal interestPayable, final LocalDate maturityDate) { this.depositAmount = depositAmount; this.maturityAmount = this.depositAmount.add(interestPayable); - this.maturityDate = Date.from(maturityDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.maturityDate = maturityDate; } public void updateDepositAmount(final BigDecimal depositAmount) { @@ -233,20 +224,11 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistableCustom { } public LocalDate getMaturityLocalDate() { - LocalDate maturityLocalDate = null; - if (this.maturityDate != null) { - maturityLocalDate = LocalDate.ofInstant(this.maturityDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return maturityLocalDate; + return this.maturityDate; } public LocalDate getExpectedFirstDepositOnDate() { - LocalDate expectedFirstDepositOnLocalDate = null; - if (this.expectedFirstDepositOnDate != null) { - expectedFirstDepositOnLocalDate = LocalDate.ofInstant(this.expectedFirstDepositOnDate.toInstant(), - DateUtils.getDateTimeZoneOfTenant()); - } - return expectedFirstDepositOnLocalDate; + return this.expectedFirstDepositOnDate; } public boolean isPreClosurePenalApplicable() { @@ -325,7 +307,7 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistableCustom { } public void updateExpectedFirstDepositDate(final LocalDate expectedFirstDepositOnDate) { - this.expectedFirstDepositOnDate = Date.from(expectedFirstDepositOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.expectedFirstDepositOnDate = expectedFirstDepositOnDate; } public boolean isTransferInterestToLinkedAccount() { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/FixedDepositAccount.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/FixedDepositAccount.java index c03c8f957..a306b3a9b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/FixedDepositAccount.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/FixedDepositAccount.java @@ -26,11 +26,9 @@ import static org.apache.fineract.portfolio.savings.DepositsApiConstants.onAccou import java.math.BigDecimal; import java.math.MathContext; import java.time.LocalDate; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; @@ -194,7 +192,7 @@ public class FixedDepositAccount extends SavingsAccount { String refNo = null; final Money transactionAmountMoney = Money.of(getCurrency(), this.accountTermAndPreClosure.depositAmount()); final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(null, office(), null, - this.accountSubmittedOrActivationDate(), transactionAmountMoney, new Date(), null, refNo); // TODO: + this.accountSubmittedOrActivationDate(), transactionAmountMoney, DateUtils.getLocalDateTimeOfSystem(), null, refNo); // TODO: // verify // if // it @@ -421,7 +419,7 @@ public class FixedDepositAccount extends SavingsAccount { this.rejectedBy = null; this.withdrawnOnDate = null; this.withdrawnBy = null; - this.closedOnDate = Date.from(closedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closedOnDate = closedDate; this.closedBy = currentUser; this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); } @@ -509,7 +507,7 @@ public class FixedDepositAccount extends SavingsAccount { this.rejectedBy = null; this.withdrawnOnDate = null; this.withdrawnBy = null; - this.closedOnDate = Date.from(closedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closedOnDate = closedDate; this.closedBy = currentUser; // this.summary.updateSummary(this.currency, // this.savingsAccountTransactionSummaryWrapper, this.transactions); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/RecurringDepositAccount.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/RecurringDepositAccount.java index cd28932d4..5a6027829 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/RecurringDepositAccount.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/RecurringDepositAccount.java @@ -26,13 +26,11 @@ import static org.apache.fineract.portfolio.savings.DepositsApiConstants.onAccou import java.math.BigDecimal; import java.math.MathContext; import java.time.LocalDate; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; @@ -391,8 +389,7 @@ public class RecurringDepositAccount extends SavingsAccount { dueDate = latestTransactionDate; } final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(null, office(), null, dueDate, - installment.getDepositAmountOutstanding(getCurrency()), - Date.from(installment.dueDate().atStartOfDay(ZoneId.systemDefault()).toInstant()), null, refNo); + installment.getDepositAmountOutstanding(getCurrency()), DateUtils.getLocalDateTimeOfSystem(), null, refNo); allTransactions.add(transaction); } } @@ -529,7 +526,7 @@ public class RecurringDepositAccount extends SavingsAccount { this.rejectedBy = null; this.withdrawnOnDate = null; this.withdrawnBy = null; - this.closedOnDate = Date.from(closedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closedOnDate = closedDate; this.closedBy = currentUser; this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); @@ -546,7 +543,7 @@ public class RecurringDepositAccount extends SavingsAccount { String refNo = null; if (minRequiredOpeningBalance.isGreaterThanZero()) { final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, getActivationLocalDate(), - minRequiredOpeningBalance.getAmount(), null, new Date(), user, accountType); + minRequiredOpeningBalance.getAmount(), null, DateUtils.getLocalDateTimeOfSystem(), user, accountType); deposit(transactionDTO, backdatedTxnsAllowedTill, refNo); // update existing transactions so derived balance fields are @@ -631,7 +628,7 @@ public class RecurringDepositAccount extends SavingsAccount { this.rejectedBy = null; this.withdrawnOnDate = null; this.withdrawnBy = null; - this.closedOnDate = Date.from(closedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closedOnDate = closedDate; this.closedBy = currentUser; this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); } @@ -1168,11 +1165,11 @@ public class RecurringDepositAccount extends SavingsAccount { this.activatedBy = null; this.lockedInUntilDate = null; - this.activatedOnDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.activatedOnDate = now; } public void setClosedOnDate(final LocalDate closedOnDate) { - this.closedOnDate = Date.from(closedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closedOnDate = closedOnDate; } @Override @@ -1194,7 +1191,7 @@ public class RecurringDepositAccount extends SavingsAccount { final BigDecimal depositAmount = this.recurringDetail.mandatoryRecommendedDepositAmount(); while (maturityDate.isAfter(installmentDate)) { final RecurringDepositScheduleInstallment installment = RecurringDepositScheduleInstallment.installment(this, installmentNumber, - Date.from(installmentDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), depositAmount); + installmentDate, depositAmount); addDepositScheduleInstallment(installment); installmentDate = DepositAccountUtils.calculateNextDepositDate(installmentDate, frequency, recurringEvery); installmentNumber += 1; @@ -1264,8 +1261,7 @@ public class RecurringDepositAccount extends SavingsAccount { @Override public int compare(final RecurringDepositScheduleInstallment o1, final RecurringDepositScheduleInstallment o2) { - final int comparsion = o1.installmentNumber().compareTo(o2.installmentNumber()); - return comparsion; + return o1.installmentNumber().compareTo(o2.installmentNumber()); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/RecurringDepositScheduleInstallment.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/RecurringDepositScheduleInstallment.java index d5f1e3e7b..e980bb16b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/RecurringDepositScheduleInstallment.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/RecurringDepositScheduleInstallment.java @@ -20,17 +20,12 @@ package org.apache.fineract.portfolio.savings.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.Money; @@ -45,13 +40,11 @@ public class RecurringDepositScheduleInstallment extends AbstractAuditableCustom @Column(name = "installment", nullable = false) private Integer installmentNumber; - @Temporal(TemporalType.DATE) @Column(name = "fromdate", nullable = true) - private Date fromDate; + private LocalDate fromDate; - @Temporal(TemporalType.DATE) @Column(name = "duedate", nullable = false) - private Date dueDate; + private LocalDate dueDate; @Column(name = "deposit_amount", scale = 6, precision = 19, nullable = true) private BigDecimal depositAmount; @@ -68,9 +61,8 @@ public class RecurringDepositScheduleInstallment extends AbstractAuditableCustom @Column(name = "completed_derived", nullable = false) private boolean obligationsMet; - @Temporal(TemporalType.DATE) @Column(name = "obligations_met_on_date") - private Date obligationsMetOnDate; + private LocalDate obligationsMetOnDate; /** * @@ -94,10 +86,10 @@ public class RecurringDepositScheduleInstallment extends AbstractAuditableCustom * @param obligationsMet * @param obligationsMetOnDate */ - private RecurringDepositScheduleInstallment(final RecurringDepositAccount account, final Integer installmentNumber, final Date fromDate, - final Date dueDate, final BigDecimal depositAmount, final BigDecimal depositAmountCompleted, + private RecurringDepositScheduleInstallment(final RecurringDepositAccount account, final Integer installmentNumber, + final LocalDate fromDate, final LocalDate dueDate, final BigDecimal depositAmount, final BigDecimal depositAmountCompleted, final BigDecimal totalPaidInAdvance, final BigDecimal totalPaidLate, final boolean obligationsMet, - final Date obligationsMetOnDate) { + final LocalDate obligationsMetOnDate) { this.account = account; this.installmentNumber = installmentNumber; this.fromDate = fromDate; @@ -111,22 +103,22 @@ public class RecurringDepositScheduleInstallment extends AbstractAuditableCustom } public static RecurringDepositScheduleInstallment from(final RecurringDepositAccount account, final Integer installmentNumber, - final Date fromDate, final Date dueDate, final BigDecimal depositAmount, final BigDecimal depositAmountCompleted, + final LocalDate fromDate, final LocalDate dueDate, final BigDecimal depositAmount, final BigDecimal depositAmountCompleted, final BigDecimal totalPaidInAdvance, final BigDecimal totalPaidLate, final boolean obligationsMet, - final Date obligationsMetOnDate) { + final LocalDate obligationsMetOnDate) { return new RecurringDepositScheduleInstallment(account, installmentNumber, fromDate, dueDate, depositAmount, depositAmountCompleted, totalPaidInAdvance, totalPaidLate, obligationsMet, obligationsMetOnDate); } public static RecurringDepositScheduleInstallment installment(final RecurringDepositAccount account, final Integer installmentNumber, - final Date dueDate, final BigDecimal depositAmount) { + final LocalDate dueDate, final BigDecimal depositAmount) { - final Date fromDate = null; + final LocalDate fromDate = null; final BigDecimal depositAmountCompleted = null; final BigDecimal totalPaidInAdvance = null; final BigDecimal totalPaidLate = null; final boolean obligationsMet = false; - final Date obligationsMetOnDate = null; + final LocalDate obligationsMetOnDate = null; return new RecurringDepositScheduleInstallment(account, installmentNumber, fromDate, dueDate, depositAmount, depositAmountCompleted, totalPaidInAdvance, totalPaidLate, obligationsMet, obligationsMetOnDate); @@ -170,7 +162,7 @@ public class RecurringDepositScheduleInstallment extends AbstractAuditableCustom } public LocalDate dueDate() { - return (this.dueDate == null) ? null : LocalDate.ofInstant(this.dueDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return this.dueDate; } public Money payInstallment(final LocalDate transactionDate, final Money transactionAmountRemaining) { @@ -199,7 +191,7 @@ public class RecurringDepositScheduleInstallment extends AbstractAuditableCustom private void checkIfInstallmentObligationsAreMet(final LocalDate transactionDate, final MonetaryCurrency currency) { this.obligationsMet = getTotalOutstanding(currency).isZero(); if (this.obligationsMet) { - this.obligationsMetOnDate = Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.obligationsMetOnDate = transactionDate; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java index 864840876..928531625 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.savings.domain; +import static java.time.temporal.ChronoUnit.DAYS; import static org.apache.fineract.portfolio.savings.SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME; import static org.apache.fineract.portfolio.savings.SavingsApiConstants.allowOverdraftParamName; import static org.apache.fineract.portfolio.savings.SavingsApiConstants.dueAsOfDateParamName; @@ -39,13 +40,11 @@ import java.math.BigDecimal; import java.math.MathContext; import java.time.LocalDate; import java.time.YearMonth; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -54,7 +53,6 @@ import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.concurrent.TimeUnit; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.DiscriminatorColumn; @@ -70,8 +68,6 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.Transient; import javax.persistence.UniqueConstraint; import javax.persistence.Version; @@ -175,49 +171,43 @@ public class SavingsAccount extends AbstractPersistableCustom { @Column(name = "account_type_enum", nullable = false) protected Integer accountType; - @Temporal(TemporalType.DATE) @Column(name = "submittedon_date", nullable = true) - protected Date submittedOnDate; + protected LocalDate submittedOnDate; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "submittedon_userid", nullable = true) protected AppUser submittedBy; - @Temporal(TemporalType.DATE) @Column(name = "rejectedon_date") - protected Date rejectedOnDate; + protected LocalDate rejectedOnDate; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "rejectedon_userid", nullable = true) protected AppUser rejectedBy; - @Temporal(TemporalType.DATE) @Column(name = "withdrawnon_date") - protected Date withdrawnOnDate; + protected LocalDate withdrawnOnDate; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "withdrawnon_userid", nullable = true) protected AppUser withdrawnBy; - @Temporal(TemporalType.DATE) @Column(name = "approvedon_date") - protected Date approvedOnDate; + protected LocalDate approvedOnDate; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "approvedon_userid", nullable = true) protected AppUser approvedBy; - @Temporal(TemporalType.DATE) @Column(name = "activatedon_date", nullable = true) - protected Date activatedOnDate; + protected LocalDate activatedOnDate; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "activatedon_userid", nullable = true) protected AppUser activatedBy; - @Temporal(TemporalType.DATE) @Column(name = "closedon_date") - protected Date closedOnDate; + protected LocalDate closedOnDate; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "closedon_userid", nullable = true) @@ -271,9 +261,8 @@ public class SavingsAccount extends AbstractPersistableCustom { * When account becomes active this field is derived if lockinPeriodFrequency and * lockinPeriodFrequencyType details are present. */ - @Temporal(TemporalType.DATE) @Column(name = "lockedin_until_date_derived", nullable = true) - protected Date lockedInUntilDate; + protected LocalDate lockedInUntilDate; @Column(name = "withdrawal_fee_for_transfer", nullable = true) protected boolean withdrawalFeeApplicableForTransfer; @@ -305,9 +294,8 @@ public class SavingsAccount extends AbstractPersistableCustom { @Column(name = "on_hold_funds_derived", scale = 6, precision = 19, nullable = true) private BigDecimal onHoldFunds; - @Temporal(TemporalType.DATE) @Column(name = "start_interest_calculation_date") - protected Date startInterestCalculationDate; + protected LocalDate startInterestCalculationDate; @Embedded protected SavingsAccountSummary summary; @@ -417,7 +405,7 @@ public class SavingsAccount extends AbstractPersistableCustom { this.externalId = externalId; this.status = status.getValue(); this.accountType = accountType.getValue(); - this.submittedOnDate = Date.from(submittedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.submittedOnDate = submittedOnDate; this.submittedBy = submittedBy; this.nominalAnnualInterestRate = nominalAnnualInterestRate; this.interestCompoundingPeriodType = interestCompoundingPeriodType.getValue(); @@ -853,8 +841,7 @@ public class SavingsAccount extends AbstractPersistableCustom { Money periodStartingBalance; if (this.startInterestCalculationDate != null) { - LocalDate startInterestCalculationDate = LocalDate.ofInstant(this.startInterestCalculationDate.toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + LocalDate startInterestCalculationDate = this.startInterestCalculationDate; final SavingsAccountTransaction transaction = findLastTransaction(startInterestCalculationDate); if (transaction == null) { @@ -1158,11 +1145,7 @@ public class SavingsAccount extends AbstractPersistableCustom { } public LocalDate getActivationLocalDate() { - LocalDate activationLocalDate = null; - if (this.activatedOnDate != null) { - activationLocalDate = LocalDate.ofInstant(this.activatedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return activationLocalDate; + return this.activatedOnDate; } public AppUser getActivatedBy() { @@ -1170,7 +1153,7 @@ public class SavingsAccount extends AbstractPersistableCustom { } public LocalDate getWithdrawnOnDate() { - return withdrawnOnDate == null ? null : LocalDate.ofInstant(withdrawnOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return this.withdrawnOnDate; } public AppUser getWithdrawnBy() { @@ -1182,8 +1165,7 @@ public class SavingsAccount extends AbstractPersistableCustom { public LocalDate getStartInterestCalculationDate() { LocalDate startInterestCalculationLocalDate = null; if (this.startInterestCalculationDate != null) { - startInterestCalculationLocalDate = LocalDate.ofInstant(this.startInterestCalculationDate.toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + startInterestCalculationLocalDate = this.startInterestCalculationDate; } else { startInterestCalculationLocalDate = getActivationLocalDate(); } @@ -1323,7 +1305,7 @@ public class SavingsAccount extends AbstractPersistableCustom { private void resetFreeChargeDaysCount(SavingsAccountCharge charge, final BigDecimal transactionAmount, final LocalDate transactionDate, final AppUser user, final String refNo) { - Date resetDate = charge.getResetChargeDate(); + LocalDate resetDate = charge.getResetChargeDate(); Integer restartPeriod = charge.getRestartFrequency(); if (charge.getRestartFrequencyEnum() == 2) { // calculation for months @@ -1331,9 +1313,9 @@ public class SavingsAccount extends AbstractPersistableCustom { LocalDate resetLocalDate; if (resetDate == null) { - resetLocalDate = this.activatedOnDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + resetLocalDate = this.activatedOnDate; } else { - resetLocalDate = resetDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + resetLocalDate = resetDate; } LocalDate gapIntervalMonth = resetLocalDate.plusMonths(restartPeriod); @@ -1347,17 +1329,15 @@ public class SavingsAccount extends AbstractPersistableCustom { } } else { // calculation for days Long completedDays; - Long days; if (resetDate == null) { - completedDays = DateUtils.getBusinessDate().getTime() - this.activatedOnDate.getTime(); - days = TimeUnit.DAYS.convert(completedDays, TimeUnit.MILLISECONDS); + completedDays = DAYS.between(DateUtils.getBusinessLocalDate(), this.activatedOnDate); + } else { - completedDays = DateUtils.getBusinessDate().getTime() - resetDate.getTime(); - days = TimeUnit.DAYS.convert(completedDays, TimeUnit.MILLISECONDS); + completedDays = DAYS.between(DateUtils.getBusinessLocalDate(), resetDate); } - int totalDays = days.intValue(); + int totalDays = completedDays.intValue(); if (totalDays < restartPeriod) { countValidation(charge, transactionAmount, transactionDate, user, refNo); @@ -1382,7 +1362,7 @@ public class SavingsAccount extends AbstractPersistableCustom { private void discountCharge(Integer freeWithdrawalCount, SavingsAccountCharge charge) { charge.setFreeWithdrawalCount(freeWithdrawalCount); - charge.setDiscountDueDate(DateUtils.getBusinessDate()); + charge.setDiscountDueDate(DateUtils.getBusinessLocalDate()); charge.updateNoWithdrawalFee(); } @@ -1403,9 +1383,7 @@ public class SavingsAccount extends AbstractPersistableCustom { return false; } - transactionBeforeLastInterestPosting = LocalDate - .ofInstant(this.summary.getInterestPostedTillDate().toInstant(), DateUtils.getDateTimeZoneOfTenant()) - .isAfter(transactionDate) ? true : false; + transactionBeforeLastInterestPosting = this.summary.getInterestPostedTillDate().isAfter(transactionDate); } return transactionBeforeLastInterestPosting; @@ -1575,11 +1553,7 @@ public class SavingsAccount extends AbstractPersistableCustom { } protected LocalDate getLockedInUntilLocalDate() { - LocalDate lockedInUntilLocalDate = null; - if (this.lockedInUntilDate != null) { - lockedInUntilLocalDate = LocalDate.ofInstant(this.lockedInUntilDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return lockedInUntilLocalDate; + return this.lockedInUntilDate; } private boolean isDateInTheFuture(final LocalDate transactionDate) { @@ -1614,12 +1588,11 @@ public class SavingsAccount extends AbstractPersistableCustom { final String dateFormat = command.dateFormat(); if (command.isChangeInLocalDateParameterNamed(SavingsApiConstants.submittedOnDateParamName, getSubmittedOnLocalDate())) { - final LocalDate newValue = command.localDateValueOfParameterNamed(SavingsApiConstants.submittedOnDateParamName); final String newValueAsString = command.stringValueOfParameterNamed(SavingsApiConstants.submittedOnDateParamName); actualChanges.put(SavingsApiConstants.submittedOnDateParamName, newValueAsString); actualChanges.put(SavingsApiConstants.localeParamName, localeAsInput); actualChanges.put(SavingsApiConstants.dateFormatParamName, dateFormat); - this.submittedOnDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.submittedOnDate = command.localDateValueOfParameterNamed(SavingsApiConstants.submittedOnDateParamName); } if (command.isChangeInStringParameterNamed(SavingsApiConstants.accountNoParamName, this.accountNumber)) { @@ -2130,20 +2103,19 @@ public class SavingsAccount extends AbstractPersistableCustom { } public boolean isSubmittedOnDateAfter(final LocalDate compareDate) { - return this.submittedOnDate == null ? false - : LocalDate.ofInstant(this.submittedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()).isAfter(compareDate); + return this.submittedOnDate == null ? false : this.submittedOnDate.isAfter(compareDate); } public LocalDate getSubmittedOnDate() { - return submittedOnDate == null ? null : LocalDate.ofInstant(submittedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return submittedOnDate; } public LocalDate getApprovedOnDate() { - return approvedOnDate == null ? null : LocalDate.ofInstant(approvedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return approvedOnDate; } public LocalDate getRejectedOnDate() { - return rejectedOnDate == null ? null : LocalDate.ofInstant(rejectedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return rejectedOnDate; } public AppUser getRejectedBy() { @@ -2233,19 +2205,11 @@ public class SavingsAccount extends AbstractPersistableCustom { } protected LocalDate getSubmittedOnLocalDate() { - LocalDate submittedOn = null; - if (this.submittedOnDate != null) { - submittedOn = LocalDate.ofInstant(this.submittedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return submittedOn; + return this.submittedOnDate; } private LocalDate getApprovedOnLocalDate() { - LocalDate approvedOnLocalDate = null; - if (this.approvedOnDate != null) { - approvedOnLocalDate = LocalDate.ofInstant(this.approvedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return approvedOnLocalDate; + return this.approvedOnDate; } public Client getClient() { @@ -2297,7 +2261,7 @@ public class SavingsAccount extends AbstractPersistableCustom { final LocalDate approvedOn = command.localDateValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName); final String approvedOnDateChange = command.stringValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName); - this.approvedOnDate = Date.from(approvedOn.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.approvedOnDate = approvedOn; this.approvedBy = currentUser; actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat()); @@ -2463,21 +2427,21 @@ public class SavingsAccount extends AbstractPersistableCustom { } } - private Date findLatestAnnualFeeTransactionDueDate() { + private LocalDate findLatestAnnualFeeTransactionDueDate() { - Date nextDueDate = null; + LocalDate nextDueDate = null; LocalDate lastAnnualFeeTransactionDate = null; for (final SavingsAccountTransaction transaction : retreiveOrderedNonInterestPostingTransactions()) { if (transaction.isAnnualFeeAndNotReversed()) { if (lastAnnualFeeTransactionDate == null) { lastAnnualFeeTransactionDate = transaction.transactionLocalDate(); - nextDueDate = Date.from(lastAnnualFeeTransactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + nextDueDate = lastAnnualFeeTransactionDate; } if (transaction.transactionLocalDate().isAfter(lastAnnualFeeTransactionDate)) { lastAnnualFeeTransactionDate = transaction.transactionLocalDate(); - nextDueDate = Date.from(lastAnnualFeeTransactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + nextDueDate = lastAnnualFeeTransactionDate; } } } @@ -2534,11 +2498,11 @@ public class SavingsAccount extends AbstractPersistableCustom { final LocalDate rejectedOn = command.localDateValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName); final String rejectedOnAsString = command.stringValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName); - this.rejectedOnDate = Date.from(rejectedOn.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.rejectedOnDate = rejectedOn; this.rejectedBy = currentUser; this.withdrawnOnDate = null; this.withdrawnBy = null; - this.closedOnDate = Date.from(rejectedOn.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closedOnDate = rejectedOn; this.closedBy = currentUser; actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); @@ -2602,9 +2566,9 @@ public class SavingsAccount extends AbstractPersistableCustom { this.rejectedOnDate = null; this.rejectedBy = null; - this.withdrawnOnDate = Date.from(withdrawnOn.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.withdrawnOnDate = withdrawnOn; this.withdrawnBy = currentUser; - this.closedOnDate = Date.from(withdrawnOn.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closedOnDate = withdrawnOn; this.closedBy = currentUser; actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); @@ -2675,7 +2639,7 @@ public class SavingsAccount extends AbstractPersistableCustom { this.withdrawnBy = null; this.closedOnDate = null; this.closedBy = null; - this.activatedOnDate = Date.from(activationDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.activatedOnDate = activationDate; this.activatedBy = currentUser; this.lockedInUntilDate = calculateDateAccountIsLockedUntil(getActivationLocalDate()); @@ -2747,7 +2711,7 @@ public class SavingsAccount extends AbstractPersistableCustom { return Money.of(this.currency, this.minRequiredOpeningBalance); } - public void approveAndActivateApplication(final Date appliedonDate, final AppUser appliedBy) { + public void approveAndActivateApplication(final LocalDate appliedonDate, final AppUser appliedBy) { this.status = SavingsAccountStatusType.ACTIVE.getValue(); this.approvedOnDate = appliedonDate; this.approvedBy = appliedBy; @@ -2853,7 +2817,7 @@ public class SavingsAccount extends AbstractPersistableCustom { this.rejectedBy = null; this.withdrawnOnDate = null; this.withdrawnBy = null; - this.closedOnDate = Date.from(closedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.closedOnDate = closedDate; this.closedBy = currentUser; return actualChanges; @@ -2874,28 +2838,24 @@ public class SavingsAccount extends AbstractPersistableCustom { } } - private Date calculateDateAccountIsLockedUntil(final LocalDate activationLocalDate) { + private LocalDate calculateDateAccountIsLockedUntil(final LocalDate activationLocalDate) { - Date lockedInUntilLocalDate = null; + LocalDate lockedInUntilLocalDate = null; final PeriodFrequencyType lockinPeriodFrequencyType = PeriodFrequencyType.fromInt(this.lockinPeriodFrequencyType); switch (lockinPeriodFrequencyType) { case INVALID: break; case DAYS: - lockedInUntilLocalDate = Date - .from(activationLocalDate.plusDays(this.lockinPeriodFrequency).atStartOfDay(ZoneId.systemDefault()).toInstant()); + lockedInUntilLocalDate = activationLocalDate.plusDays(this.lockinPeriodFrequency); break; case WEEKS: - lockedInUntilLocalDate = Date - .from(activationLocalDate.plusWeeks(this.lockinPeriodFrequency).atStartOfDay(ZoneId.systemDefault()).toInstant()); + lockedInUntilLocalDate = activationLocalDate.plusWeeks(this.lockinPeriodFrequency); break; case MONTHS: - lockedInUntilLocalDate = Date - .from(activationLocalDate.plusMonths(this.lockinPeriodFrequency).atStartOfDay(ZoneId.systemDefault()).toInstant()); + lockedInUntilLocalDate = activationLocalDate.plusMonths(this.lockinPeriodFrequency); break; case YEARS: - lockedInUntilLocalDate = Date - .from(activationLocalDate.plusYears(this.lockinPeriodFrequency).atStartOfDay(ZoneId.systemDefault()).toInstant()); + lockedInUntilLocalDate = activationLocalDate.plusYears(this.lockinPeriodFrequency); break; case WHOLE_TERM: LOG.error("TODO Implement calculateDateAccountIsLockedUntil for WHOLE_TERM"); @@ -2920,7 +2880,7 @@ public class SavingsAccount extends AbstractPersistableCustom { } public LocalDate getClosedOnDate() { - return this.closedOnDate == null ? null : LocalDate.ofInstant(this.closedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return this.closedOnDate; } public AppUser getClosedBy() { @@ -3188,9 +3148,8 @@ public class SavingsAccount extends AbstractPersistableCustom { throw new PlatformApiDataValidationException(dataValidationErrors); } - Date currentAnnualFeeNextDueDate = findLatestAnnualFeeTransactionDueDate(); - if (currentAnnualFeeNextDueDate != null && LocalDate - .ofInstant(currentAnnualFeeNextDueDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()).isEqual(transactionDate)) { + LocalDate currentAnnualFeeNextDueDate = findLatestAnnualFeeTransactionDueDate(); + if (currentAnnualFeeNextDueDate != null && currentAnnualFeeNextDueDate.isEqual(transactionDate)) { baseDataValidator.reset().parameter("dueDate").value(transactionDate.format(formatter)) .failWithCodeNoParameterAddedToErrorCode("transaction.exists.on.date"); @@ -3543,7 +3502,7 @@ public class SavingsAccount extends AbstractPersistableCustom { public void escheat(AppUser appUser) { this.status = SavingsAccountStatusType.CLOSED.getValue(); this.sub_status = SavingsAccountSubStatusEnum.ESCHEAT.getValue(); - this.closedOnDate = DateUtils.getBusinessDate(); + this.closedOnDate = DateUtils.getBusinessLocalDate(); this.closedBy = appUser; boolean postInterestAsOnDate = false; LocalDate transactionDate = DateUtils.getBusinessLocalDate(); @@ -3879,7 +3838,7 @@ public class SavingsAccount extends AbstractPersistableCustom { return this.minOverdraftForInterestCalculation; } - public Date getLockedInUntilDate() { + public LocalDate getLockedInUntilDate() { return this.lockedInUntilDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java index f5418f3a9..d3e34cbbb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java @@ -49,7 +49,6 @@ import com.google.gson.JsonElement; import java.math.BigDecimal; import java.time.LocalDate; import java.util.Arrays; -import java.util.Date; import java.util.List; import java.util.Set; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; @@ -341,17 +340,15 @@ public class SavingsAccountAssembler { public SavingsAccount loadTransactionsToSavingsAccount(final SavingsAccount account, final boolean backdatedTxnsAllowedTill) { List savingsAccountTransactions = null; if (backdatedTxnsAllowedTill) { - Date pivotDate = account.getSummary().getInterestPostedTillDate(); + LocalDate pivotDate = account.getSummary().getInterestPostedTillDate(); boolean isNotPresent = pivotDate == null ? true : false; if (!isNotPresent) { // Get savings account transactions if (isRelaxingDaysConfigForPivotDateEnabled()) { final Long relaxingDaysForPivotDate = this.configurationDomainService.retrieveRelaxingDaysConfigForPivotDate(); - LocalDate interestPostedTillDate = LocalDate.ofInstant(account.getSummary().getInterestPostedTillDate().toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + LocalDate interestPostedTillDate = account.getSummary().getInterestPostedTillDate(); savingsAccountTransactions = this.savingsAccountRepository.findTransactionsAfterPivotDate(account, - Date.from(interestPostedTillDate.minusDays(relaxingDaysForPivotDate) - .atStartOfDay(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + interestPostedTillDate.minusDays(relaxingDaysForPivotDate)); } else { savingsAccountTransactions = this.savingsAccountRepository.findTransactionsAfterPivotDate(account, account.getSummary().getInterestPostedTillDate()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountCharge.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountCharge.java index 4e35d0b1d..0233f1391 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountCharge.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountCharge.java @@ -30,9 +30,7 @@ import java.math.BigDecimal; import java.math.MathContext; import java.time.LocalDate; import java.time.MonthDay; -import java.time.ZoneId; import java.time.temporal.ChronoField; -import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; @@ -41,12 +39,9 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.Money; import org.apache.fineract.organisation.monetary.domain.MoneyHelper; @@ -78,9 +73,8 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { @Column(name = "charge_time_enum", nullable = false) private Integer chargeTime; - @Temporal(TemporalType.DATE) @Column(name = "charge_due_date") - private Date dueDate; + private LocalDate dueDate; @Column(name = "fee_on_month", nullable = true) private Integer feeOnMonth; @@ -97,9 +91,8 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { @Column(name = "free_withdrawal_count", nullable = true) private Integer freeWithdrawalCount; - @Temporal(TemporalType.DATE) @Column(name = "charge_reset_date", nullable = true) - private Date chargeResetDate; + private LocalDate chargeResetDate; @Column(name = "calculation_percentage", scale = 6, precision = 19, nullable = true) private BigDecimal percentage; @@ -135,9 +128,8 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { @Column(name = "is_active", nullable = false) private boolean status = true; - @Temporal(TemporalType.DATE) @Column(name = "inactivated_on_date") - private Date inactivationDate; + private LocalDate inactivationDate; public static SavingsAccountCharge createNewFromJson(final SavingsAccount savingsAccount, final Charge chargeDefinition, final JsonCommand command) { @@ -220,7 +212,7 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval; } - this.dueDate = (dueDate == null) ? null : Date.from(dueDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.dueDate = dueDate; this.chargeCalculation = chargeDefinition.getChargeCalculation(); if (chargeCalculation != null) { @@ -401,7 +393,7 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { public void update(final BigDecimal amount, final LocalDate dueDate, final MonthDay feeOnMonthDay, final Integer feeInterval) { final BigDecimal transactionAmount = BigDecimal.ZERO; if (dueDate != null) { - this.dueDate = Date.from(dueDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.dueDate = dueDate; if (isWeeklyFee()) { this.feeOnDay = dueDate.get(ChronoField.DAY_OF_WEEK); } @@ -462,10 +454,9 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { actualChanges.put(dateFormatParamName, dateFormatAsInput); actualChanges.put(localeParamName, localeAsInput); - final LocalDate newValue = command.localDateValueOfParameterNamed(dueAsOfDateParamName); - this.dueDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.dueDate = command.localDateValueOfParameterNamed(dueAsOfDateParamName); if (this.isWeeklyFee()) { - this.feeOnDay = newValue.get(ChronoField.DAY_OF_WEEK); + this.feeOnDay = this.dueDate.get(ChronoField.DAY_OF_WEEK); } } @@ -531,11 +522,7 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { } public LocalDate getDueLocalDate() { - LocalDate dueDate = null; - if (this.dueDate != null) { - dueDate = LocalDate.ofInstant(this.dueDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return dueDate; + return this.dueDate; } private boolean determineIfFullyPaid() { @@ -701,11 +688,11 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { this.freeWithdrawalCount = freeWithdrawalCount; } - public Date getResetChargeDate() { + public LocalDate getResetChargeDate() { return chargeResetDate; } - public void setDiscountDueDate(final Date date) { + public void setDiscountDueDate(final LocalDate date) { this.chargeResetDate = date; } @@ -807,7 +794,7 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { public void updateToNextDueDateFrom(final LocalDate startingDate) { if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) { - this.dueDate = Date.from(getNextDueDateFrom(startingDate).atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.dueDate = getNextDueDateFrom(startingDate); } } @@ -861,15 +848,13 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { public void updateNextDueDateForRecurringFees() { if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) { - LocalDate nextDueLocalDate = LocalDate.ofInstant(dueDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - nextDueLocalDate = calculateNextDueDate(nextDueLocalDate); - this.dueDate = Date.from(nextDueLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.dueDate = calculateNextDueDate(this.dueDate); } } public void updateToPreviousDueDate() { if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) { - LocalDate nextDueLocalDate = LocalDate.ofInstant(dueDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + LocalDate nextDueLocalDate = dueDate; if (isAnnualFee()) { nextDueLocalDate = nextDueLocalDate.withMonth(this.feeOnMonth).minusYears(1); nextDueLocalDate = setDayOfMonth(nextDueLocalDate); @@ -881,7 +866,7 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { nextDueLocalDate = setDayOfWeek(nextDueLocalDate); } - this.dueDate = Date.from(nextDueLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.dueDate = nextDueLocalDate; } } @@ -911,7 +896,7 @@ public class SavingsAccountCharge extends AbstractPersistableCustom { } public void inactiavateCharge(final LocalDate inactivationOnDate) { - this.inactivationDate = Date.from(inactivationOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.inactivationDate = inactivationOnDate; this.status = false; this.amountOutstanding = BigDecimal.ZERO; this.paid = true; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountChargeRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountChargeRepository.java index 3b0c5dbef..173d1dd89 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountChargeRepository.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountChargeRepository.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.portfolio.savings.domain; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -31,6 +31,6 @@ public interface SavingsAccountChargeRepository @Query("select sac from SavingsAccountCharge sac where sac.id =:id and sac.savingsAccount.id = :savingsAccountId") SavingsAccountCharge findByIdAndSavingsAccountId(@Param("id") Long id, @Param("savingsAccountId") Long savingsAccountId); - @Query("select sac from SavingsAccountCharge sac where sac.dueDate <=:transactionDate and sac.waived = 0 and sac.paid=0 order by sac.dueDate") - List findPendingCharges(@Param("transactionDate") Date transactionDate); + @Query("select sac from SavingsAccountCharge sac where sac.dueDate <=:transactionDate and sac.waived = false and sac.paid=false order by sac.dueDate") + List findPendingCharges(@Param("transactionDate") LocalDate transactionDate); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountChargeRepositoryWrapper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountChargeRepositoryWrapper.java index 88af69c4c..8ced30000 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountChargeRepositoryWrapper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountChargeRepositoryWrapper.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.portfolio.savings.domain; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import org.apache.fineract.portfolio.charge.exception.SavingsAccountChargeNotFoundException; import org.springframework.beans.factory.annotation.Autowired; @@ -51,7 +51,7 @@ public class SavingsAccountChargeRepositoryWrapper { return savingsAccountCharge; } - public List findPendingCharges(final Date transactionDate) { + public List findPendingCharges(final LocalDate transactionDate) { return this.repository.findPendingCharges(transactionDate); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java index 142605ee1..4806d5e91 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java @@ -23,7 +23,6 @@ import java.math.MathContext; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -108,7 +107,7 @@ public class SavingsAccountDomainServiceJpa implements SavingsAccountDomainServi Integer accountType = null; final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, - paymentDetail, new Date(), user, accountType); + paymentDetail, DateUtils.getLocalDateTimeOfSystem(), user, accountType); UUID refNo = UUID.randomUUID(); final SavingsAccountTransaction withdrawal = account.withdraw(transactionDTO, transactionBooleanValues.isApplyWithdrawFee(), backdatedTxnsAllowedTill, refNo.toString()); @@ -191,7 +190,7 @@ public class SavingsAccountDomainServiceJpa implements SavingsAccountDomainServi Integer accountType = null; final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, - paymentDetail, new Date(), user, accountType); + paymentDetail, DateUtils.getLocalDateTimeOfSystem(), user, accountType); UUID refNo = UUID.randomUUID(); final SavingsAccountTransaction deposit = account.deposit(transactionDTO, savingsAccountTransactionType, backdatedTxnsAllowedTill, refNo.toString()); @@ -227,10 +226,9 @@ public class SavingsAccountDomainServiceJpa implements SavingsAccountDomainServi public SavingsAccountTransaction handleHold(final SavingsAccount account, final AppUser createdUser, BigDecimal amount, LocalDate transactionDate, Boolean lienAllowed) { final PaymentDetail paymentDetails = null; - Date createdDate = new Date(); SavingsAccountTransaction transaction = SavingsAccountTransaction.holdAmount(account, account.office(), paymentDetails, - transactionDate, Money.of(account.getCurrency(), amount), createdDate, createdUser, lienAllowed); + transactionDate, Money.of(account.getCurrency(), amount), DateUtils.getLocalDateTimeOfSystem(), createdUser, lienAllowed); return transaction; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java index 4a988dde3..0746b5ea7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.portfolio.savings.domain; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import org.apache.fineract.portfolio.savings.DepositAccountType; import org.apache.fineract.portfolio.savings.exception.SavingsAccountNotFoundException; @@ -130,8 +130,8 @@ public class SavingsAccountRepositoryWrapper { @Transactional public List findTransactionsAfterPivotDate(@Param("savingsAccount") SavingsAccount savingsAccount, - @Param("date") Date date) { - return this.savingsAccountTransactionRepository.findTransactionsAfterPivotDate(savingsAccount, date); + @Param("date") LocalDate transactionDate) { + return this.savingsAccountTransactionRepository.findTransactionsAfterPivotDate(savingsAccount, transactionDate); } @Transactional diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountSummary.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountSummary.java index a234186b6..a44dbcf03 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountSummary.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountSummary.java @@ -20,14 +20,10 @@ package org.apache.fineract.portfolio.savings.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import java.util.HashMap; import java.util.List; import javax.persistence.Column; import javax.persistence.Embeddable; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.Transient; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; @@ -81,14 +77,12 @@ public final class SavingsAccountSummary { @Column(name = "total_withhold_tax_derived", scale = 6, precision = 19) private BigDecimal totalWithholdTax; - @Temporal(TemporalType.DATE) @Column(name = "last_interest_calculation_date") - private Date lastInterestCalculationDate; + private LocalDate lastInterestCalculationDate; // Currently this represents the last interest posting date - @Temporal(TemporalType.DATE) @Column(name = "interest_posted_till_date") - private Date interestPostedTillDate; + private LocalDate interestPostedTillDate; @Transient private BigDecimal runningBalanceOnInterestPostingTillDate = BigDecimal.ZERO; @@ -265,15 +259,13 @@ public final class SavingsAccountSummary { } public void updateFromInterestPeriodSummaries(final MonetaryCurrency currency, final List allPostingPeriods) { - Money totalEarned = Money.zero(currency); - LocalDate interestCalculationDate = DateUtils.getBusinessLocalDate(); for (final PostingPeriod period : allPostingPeriods) { Money interestEarned = period.interest(); interestEarned = interestEarned == null ? Money.zero(currency) : interestEarned; totalEarned = totalEarned.plus(interestEarned); } - this.lastInterestCalculationDate = Date.from(interestCalculationDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.lastInterestCalculationDate = DateUtils.getBusinessLocalDate(); this.totalInterestEarned = totalEarned.getAmount(); } @@ -298,15 +290,15 @@ public final class SavingsAccountSummary { return this.totalInterestPosted; } - public Date getLastInterestCalculationDate() { + public LocalDate getLastInterestCalculationDate() { return this.lastInterestCalculationDate; } - public void setInterestPostedTillDate(final Date date) { + public void setInterestPostedTillDate(final LocalDate date) { this.interestPostedTillDate = date; } - public Date getInterestPostedTillDate() { + public LocalDate getInterestPostedTillDate() { return this.interestPostedTillDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransaction.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransaction.java index 861aa465a..8459da909 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransaction.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransaction.java @@ -20,9 +20,8 @@ package org.apache.fineract.portfolio.savings.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; +import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -37,8 +36,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.LocalDateInterval; import org.apache.fineract.infrastructure.core.service.DateUtils; @@ -78,9 +75,8 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { @Column(name = "transaction_type_enum", nullable = false) private Integer typeOf; - @Temporal(TemporalType.DATE) @Column(name = "transaction_date", nullable = false) - private Date dateOf; + private LocalDate dateOf; @Column(name = "amount", scale = 6, precision = 19, nullable = false) private BigDecimal amount; @@ -94,9 +90,8 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { @Column(name = "cumulative_balance_derived", scale = 6, precision = 19, nullable = true) private BigDecimal cumulativeBalance; - @Temporal(TemporalType.DATE) @Column(name = "balance_end_date_derived", nullable = true) - private Date balanceEndDate; + private LocalDate balanceEndDate; @Column(name = "balance_number_of_days_derived", nullable = true) private Integer balanceNumberOfDays; @@ -107,9 +102,8 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { @Column(name = "overdraft_amount_derived", scale = 6, precision = 19, nullable = true) private BigDecimal overdraftAmount; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_date", nullable = false) - private Date createdDate; + private LocalDateTime createdDate; @ManyToOne @JoinColumn(name = "appuser_id", nullable = true) @@ -153,7 +147,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { } public static SavingsAccountTransaction deposit(final SavingsAccount savingsAccount, final Office office, - final PaymentDetail paymentDetail, final LocalDate date, final Money amount, Date createdDate, final AppUser appUser, + final PaymentDetail paymentDetail, final LocalDate date, final Money amount, LocalDateTime createdDate, final AppUser appUser, final String refNo) { final boolean isReversed = false; final boolean isManualTransaction = false; @@ -163,7 +157,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { } public static SavingsAccountTransaction deposit(final SavingsAccount savingsAccount, final Office office, - final PaymentDetail paymentDetail, final LocalDate date, final Money amount, Date createdDate, final AppUser appUser, + final PaymentDetail paymentDetail, final LocalDate date, final Money amount, LocalDateTime createdDate, final AppUser appUser, final SavingsAccountTransactionType savingsAccountTransactionType, final String refNo) { final boolean isReversed = false; final boolean isManualTransaction = false; @@ -173,7 +167,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { } public static SavingsAccountTransaction withdrawal(final SavingsAccount savingsAccount, final Office office, - final PaymentDetail paymentDetail, final LocalDate date, final Money amount, Date createdDate, final AppUser appUser, + final PaymentDetail paymentDetail, final LocalDate date, final Money amount, LocalDateTime createdDate, final AppUser appUser, final String refNo) { final boolean isReversed = false; final boolean isManualTransaction = false; @@ -232,7 +226,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { public static SavingsAccountTransaction from(final Integer transactionTypeEnum, final LocalDate transactionDate, final BigDecimal amount, final boolean isReversed, final BigDecimal runningBalance, final BigDecimal cumulativeBalance, final LocalDate balanceEndDate, final Integer balanceNumberOfDays, final BigDecimal overdraftAmount, - final LocalDate createdDate, final boolean isManualTransaction, final Long releaseIdOfHoldAmountTransaction) { + final LocalDateTime createdDate, final boolean isManualTransaction, final Long releaseIdOfHoldAmountTransaction) { return new SavingsAccountTransaction(transactionTypeEnum, transactionDate, amount, isReversed, runningBalance, cumulativeBalance, balanceEndDate, balanceNumberOfDays, overdraftAmount, createdDate, isManualTransaction, releaseIdOfHoldAmountTransaction); } @@ -255,7 +249,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { final Boolean lienTransaction = false; final String refNo = null; return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, - SavingsAccountTransactionType.INITIATE_TRANSFER.getValue(), date, new Date(), + SavingsAccountTransactionType.INITIATE_TRANSFER.getValue(), date, DateUtils.getLocalDateTimeOfSystem(), savingsAccount.getSummary().getAccountBalance(), isReversed, appUser, isManualTransaction, lienTransaction, refNo); } @@ -267,7 +261,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { final Boolean lienTransaction = false; final String refNo = null; return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, - SavingsAccountTransactionType.APPROVE_TRANSFER.getValue(), date, new Date(), + SavingsAccountTransactionType.APPROVE_TRANSFER.getValue(), date, DateUtils.getLocalDateTimeOfSystem(), savingsAccount.getSummary().getAccountBalance(), isReversed, appUser, isManualTransaction, lienTransaction, refNo); } @@ -279,7 +273,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { final Boolean lienTransaction = false; final String refNo = null; return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, - SavingsAccountTransactionType.WITHDRAW_TRANSFER.getValue(), date, new Date(), + SavingsAccountTransactionType.WITHDRAW_TRANSFER.getValue(), date, DateUtils.getLocalDateTimeOfSystem(), savingsAccount.getSummary().getAccountBalance(), isReversed, appUser, isManualTransaction, lienTransaction, refNo); } @@ -303,8 +297,8 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { final Boolean lienTransaction = false; final String refNo = null; return new SavingsAccountTransaction(savingsAccount, savingsAccount.office(), paymentDetail, - SavingsAccountTransactionType.ESCHEAT.getValue(), date, new Date(), savingsAccount.getSummary().getAccountBalance(), - isReversed, appUser, accountTransaction, lienTransaction, refNo); + SavingsAccountTransactionType.ESCHEAT.getValue(), date, DateUtils.getLocalDateTimeOfSystem(), + savingsAccount.getSummary().getAccountBalance(), isReversed, appUser, accountTransaction, lienTransaction, refNo); } public static void updateTaxDetails(final Map taxDetails, @@ -319,7 +313,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { public static SavingsAccountTransaction copyTransaction(SavingsAccountTransaction accountTransaction) { return new SavingsAccountTransaction(accountTransaction.savingsAccount, accountTransaction.office, accountTransaction.paymentDetail, - accountTransaction.typeOf, accountTransaction.transactionLocalDate(), DateUtils.getDateOfTenant(), + accountTransaction.typeOf, accountTransaction.transactionLocalDate(), DateUtils.getLocalDateTimeOfSystem(), accountTransaction.amount, accountTransaction.reversed, accountTransaction.appUser, accountTransaction.isManualTransaction, accountTransaction.lienTransaction, accountTransaction.refNo); } @@ -327,12 +321,12 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { private SavingsAccountTransaction(final SavingsAccount savingsAccount, final Office office, final Integer typeOf, final LocalDate transactionLocalDate, final Money amount, final boolean isReversed, final AppUser appUser, final boolean isManualTransaction, final Boolean lienTransaction, final String refNo) { - this(savingsAccount, office, null, typeOf, transactionLocalDate, new Date(), amount, isReversed, appUser, isManualTransaction, - lienTransaction, refNo); + this(savingsAccount, office, null, typeOf, transactionLocalDate, DateUtils.getLocalDateTimeOfSystem(), amount, isReversed, appUser, + isManualTransaction, lienTransaction, refNo); } private SavingsAccountTransaction(final SavingsAccount savingsAccount, final Office office, final PaymentDetail paymentDetail, - final Integer typeOf, final LocalDate transactionLocalDate, final Date createdDate, final Money amount, + final Integer typeOf, final LocalDate transactionLocalDate, final LocalDateTime createdDate, final Money amount, final boolean isReversed, final AppUser appUser, final boolean isManualTransaction, final Boolean lienTransaction, final String refNo) { this(savingsAccount, office, paymentDetail, typeOf, transactionLocalDate, createdDate, amount.getAmount(), isReversed, appUser, @@ -340,13 +334,13 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { } private SavingsAccountTransaction(final SavingsAccount savingsAccount, final Office office, final PaymentDetail paymentDetail, - final Integer typeOf, final LocalDate transactionLocalDate, final Date createdDate, final BigDecimal amount, + final Integer typeOf, final LocalDate transactionLocalDate, final LocalDateTime createdDate, final BigDecimal amount, final boolean isReversed, final AppUser appUser, final boolean isManualTransaction, final Boolean lienTransaction, final String refNo) { this.savingsAccount = savingsAccount; this.office = office; this.typeOf = typeOf; - this.dateOf = Date.from(transactionLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.dateOf = transactionLocalDate; this.amount = amount; this.reversed = isReversed; this.paymentDetail = paymentDetail; @@ -359,24 +353,24 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { private SavingsAccountTransaction(final Integer transactionTypeEnum, final LocalDate transactionDate, final BigDecimal amount, final boolean isReversed, final BigDecimal runningBalance, final BigDecimal cumulativeBalance, final LocalDate balanceEndDate, - final Integer balanceNumberOfDays, final BigDecimal overdraftAmount, final LocalDate createdDate, + final Integer balanceNumberOfDays, final BigDecimal overdraftAmount, final LocalDateTime createdDate, final boolean isManualTransaction, final Long releaseIdOfHoldAmountTransaction) { this.typeOf = transactionTypeEnum; - this.dateOf = Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.dateOf = transactionDate; this.amount = amount; this.reversed = isReversed; this.runningBalance = runningBalance; this.cumulativeBalance = cumulativeBalance; - this.balanceEndDate = Date.from(balanceEndDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.balanceEndDate = balanceEndDate; this.balanceNumberOfDays = balanceNumberOfDays; this.overdraftAmount = overdraftAmount; - this.createdDate = Date.from(createdDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.createdDate = createdDate; this.isManualTransaction = isManualTransaction; this.releaseIdOfHoldAmountTransaction = releaseIdOfHoldAmountTransaction; } public static SavingsAccountTransaction holdAmount(final SavingsAccount savingsAccount, final Office office, - final PaymentDetail paymentDetail, final LocalDate date, final Money amount, Date createdDate, final AppUser appUser, + final PaymentDetail paymentDetail, final LocalDate date, final Money amount, LocalDateTime createdDate, final AppUser appUser, final Boolean lienTransaction) { final boolean isReversed = false; final boolean isManualTransaction = false; @@ -386,7 +380,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { } public static SavingsAccountTransaction releaseAmount(SavingsAccountTransaction accountTransaction, LocalDate transactionDate, - Date createdDate, final AppUser appUser) { + LocalDateTime createdDate, final AppUser appUser) { return new SavingsAccountTransaction(accountTransaction.savingsAccount, accountTransaction.office, accountTransaction.paymentDetail, SavingsAccountTransactionType.AMOUNT_RELEASE.getValue(), transactionDate, createdDate, accountTransaction.amount, accountTransaction.reversed, appUser, accountTransaction.isManualTransaction, accountTransaction.lienTransaction, @@ -403,7 +397,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { } public LocalDate transactionLocalDate() { - return LocalDate.ofInstant(this.dateOf.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return this.dateOf; } public void reverse() { @@ -517,26 +511,24 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { public void updateCumulativeBalanceAndDates(final MonetaryCurrency currency, final LocalDate endOfBalanceDate) { // balance end date should not be before transaction date if (endOfBalanceDate != null && endOfBalanceDate.isBefore(this.transactionLocalDate())) { - this.balanceEndDate = Date.from(this.transactionLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant()); - } else if (endOfBalanceDate != null) { - this.balanceEndDate = Date.from(endOfBalanceDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.balanceEndDate = this.transactionLocalDate(); } else { - this.balanceEndDate = null; + this.balanceEndDate = endOfBalanceDate; } this.balanceNumberOfDays = LocalDateInterval.create(getTransactionLocalDate(), endOfBalanceDate).daysInPeriodInclusiveOfEndDate(); this.cumulativeBalance = Money.of(currency, this.runningBalance).multipliedBy(this.balanceNumberOfDays).getAmount(); } public LocalDate getTransactionLocalDate() { - return LocalDate.ofInstant(this.dateOf.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return this.dateOf; } - public Date getLastTransactionDate() { + public LocalDate getLastTransactionDate() { return this.dateOf; } public LocalDate getEndOfBalanceLocalDate() { - return balanceEndDate == null ? null : LocalDate.ofInstant(balanceEndDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return balanceEndDate; } public boolean isAcceptableForDailyBalance(final LocalDateInterval interestPeriodInterval) { @@ -829,10 +821,6 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { return Money.of(currency, this.overdraftAmount); } - public Date createdDate() { - return this.createdDate; - } - public boolean isPaymentForCurrentCharge(final SavingsAccountCharge savingsAccountCharge) { final SavingsAccountChargePaidBy chargePaidBy = getSavingsAccountChargePaidBy(); @@ -876,7 +864,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { this.savingsAccount = savingsAccount; } - public Date getDateOf() { + public LocalDate getDateOf() { return this.dateOf; } @@ -908,7 +896,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { return this.office.getId(); } - public Date getBalanceEndDate() { + public LocalDate getBalanceEndDate() { return this.balanceEndDate; } @@ -924,7 +912,7 @@ public final class SavingsAccountTransaction extends AbstractPersistableCustom { return this.appUser.getId(); } - public Date getCreatedDate() { + public LocalDateTime getCreatedDate() { return this.createdDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransactionComparator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransactionComparator.java index e72028d99..3527db7fe 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransactionComparator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransactionComparator.java @@ -30,7 +30,7 @@ public class SavingsAccountTransactionComparator implements Comparator= :date order by st.dateOf,st.createdDate,st.id") + @Query("select st from SavingsAccountTransaction st where st.savingsAccount = :savingsAccount and st.dateOf >= :transactionDate order by st.dateOf,st.createdDate,st.id") List findTransactionsAfterPivotDate(@Param("savingsAccount") SavingsAccount savingsAccount, - @Param("date") Date date); + @Param("transactionDate") LocalDate transactionDate); @Lock(LockModeType.PESSIMISTIC_WRITE) List findBySavingsAccount(@Param("savingsAccount") SavingsAccount savingsAccount); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsHelper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsHelper.java index 48c83d7a4..7d3858918 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsHelper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsHelper.java @@ -23,7 +23,6 @@ import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.core.domain.LocalDateInterval; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; @@ -178,7 +177,7 @@ public final class SavingsHelper { return this.accountTransfersReadPlatformService.fetchPostInterestTransactionIds(accountId); } - public Collection fetchPostInterestTransactionIds(Long accountId, Date pivotDate) { + public Collection fetchPostInterestTransactionIds(Long accountId, LocalDate pivotDate) { return this.accountTransfersReadPlatformService.fetchPostInterestTransactionIdsWithPivotDate(accountId, pivotDate); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsOfficerAssignmentHistory.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsOfficerAssignmentHistory.java index 8bbdc6c92..bd8f439e1 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsOfficerAssignmentHistory.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsOfficerAssignmentHistory.java @@ -19,18 +19,12 @@ package org.apache.fineract.portfolio.savings.domain; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import org.apache.commons.lang3.ObjectUtils; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.staff.domain.Staff; @Entity @@ -45,26 +39,23 @@ public class SavingsOfficerAssignmentHistory extends AbstractAuditableCustom { @JoinColumn(name = "savings_officer_id", nullable = true) private Staff savingsOfficer; - @Temporal(TemporalType.DATE) @Column(name = "start_date") - private Date startDate; + private LocalDate startDate; - @Temporal(TemporalType.DATE) @Column(name = "end_date") - private Date endDate; + private LocalDate endDate; public static SavingsOfficerAssignmentHistory createNew(final SavingsAccount account, final Staff savingsOfficer, final LocalDate assignmentDate) { - return new SavingsOfficerAssignmentHistory(account, savingsOfficer, - Date.from(assignmentDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), null); + return new SavingsOfficerAssignmentHistory(account, savingsOfficer, assignmentDate, null); } protected SavingsOfficerAssignmentHistory() { // } - private SavingsOfficerAssignmentHistory(final SavingsAccount account, final Staff savingsOfficer, final Date startDate, - final Date endDate) { + private SavingsOfficerAssignmentHistory(final SavingsAccount account, final Staff savingsOfficer, final LocalDate startDate, + final LocalDate endDate) { this.savingsAccount = account; this.savingsOfficer = savingsOfficer; this.startDate = startDate; @@ -80,11 +71,11 @@ public class SavingsOfficerAssignmentHistory extends AbstractAuditableCustom { } public void updateStartDate(final LocalDate startDate) { - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = startDate; } public void updateEndDate(final LocalDate endDate) { - this.endDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.endDate = endDate; } public boolean matchesStartDateOf(final LocalDate matchingDate) { @@ -92,7 +83,7 @@ public class SavingsOfficerAssignmentHistory extends AbstractAuditableCustom { } public LocalDate getStartDate() { - return LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + return this.startDate; } public boolean hasStartDateBefore(final LocalDate matchingDate) { @@ -110,12 +101,11 @@ public class SavingsOfficerAssignmentHistory extends AbstractAuditableCustom { * @return */ public boolean isEndDateAfter(final LocalDate compareDate) { - return this.endDate == null ? false - : LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()).isAfter(compareDate); + return this.endDate != null && this.endDate.isAfter(compareDate); } public LocalDate getEndDate() { - return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), null); + return this.endDate; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java index 353070900..aadea8e85 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java @@ -749,11 +749,11 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo UUID refNo = UUID.randomUUID(); if (savingsAccountTransaction.isDeposit()) { final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, - paymentDetail, savingsAccountTransaction.createdDate(), user, accountType); + paymentDetail, savingsAccountTransaction.getCreatedDate(), user, accountType); transaction = account.deposit(transactionDTO, false, refNo.toString()); } else { final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, - paymentDetail, savingsAccountTransaction.createdDate(), user, accountType); + paymentDetail, savingsAccountTransaction.getCreatedDate(), user, accountType); transaction = account.withdraw(transactionDTO, true, false, refNo.toString()); } final Long newtransactionId = saveTransactionToGenerateTransactionId(transaction); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountInterestPostingServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountInterestPostingServiceImpl.java index eed7393bb..b6e54a073 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountInterestPostingServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountInterestPostingServiceImpl.java @@ -24,7 +24,6 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -33,7 +32,6 @@ import java.util.stream.Collectors; import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.domain.LocalDateInterval; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.Money; import org.apache.fineract.portfolio.savings.DepositAccountType; @@ -73,12 +71,10 @@ public class SavingsAccountInterestPostingServiceImpl implements SavingsAccountI if (backdatedTxnsAllowedTill && savingsAccountData.getSummary().getInterestPostedTillDate() != null) { interestPostedToDate = Money.of(savingsAccountData.currency(), savingsAccountData.getSummary().getTotalInterestPosted()); SavingsAccountTransactionData savingsAccountTransactionData = retrieveLastTransactions(savingsAccountData); - Date lastTransactionDate = Date.from( - savingsAccountTransactionData.getLastTransactionDate().atStartOfDay(DateUtils.getDateTimeZoneOfTenant()).toInstant()); + LocalDate lastTransactionDate = savingsAccountTransactionData.getLastTransactionDate(); savingsAccountData.setStartInterestCalculationDate(lastTransactionDate); } else { - savingsAccountData.setStartInterestCalculationDate( - Date.from(startInterestDate.atStartOfDay(DateUtils.getDateTimeZoneOfTenant()).toInstant())); + savingsAccountData.setStartInterestCalculationDate(startInterestDate); } final List postingPeriods = calculateInterestUsing(mc, interestPostingUpToDate, isInterestTransfer, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index d22c85534..35f567556 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -34,12 +34,10 @@ import com.google.gson.JsonElement; import java.math.BigDecimal; import java.math.MathContext; import java.time.LocalDate; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -566,7 +564,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi } for (SavingsAccountTransaction savingTransaction : savingTransactions) { - if (Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()).before(savingTransaction.getDateOf())) { + if (transactionDate.isBefore(savingTransaction.getDateOf())) { throw new PostInterestAsOnDateException(PostInterestAsOnExceptionType.LAST_TRANSACTION_DATE); } } @@ -881,7 +879,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi boolean isInterestTransfer = false; Integer accountType = null; final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, - paymentDetail, savingsAccountTransaction.createdDate(), user, accountType); + paymentDetail, savingsAccountTransaction.getCreatedDate(), user, accountType); UUID refNo = UUID.randomUUID(); if (savingsAccountTransaction.isDeposit()) { transaction = account.deposit(transactionDTO, false, refNo.toString()); @@ -1989,8 +1987,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi if ((transaction.getTransactionLocalDate().isEqual(transferDate) && transaction.getTransactionLocalDate().isAfter(transferDate)) || transaction.getTransactionLocalDate().isAfter(transferDate)) { throw new GeneralPlatformDomainRuleException(TransferApiConstants.transferClientSavingsException, - TransferApiConstants.transferClientSavingsException, - LocalDate.ofInstant(transaction.createdDate().toInstant(), DateUtils.getDateTimeZoneOfTenant()), transferDate); + TransferApiConstants.transferClientSavingsException, transaction.getCreatedDate(), transferDate); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java index 66a2ae21b..b5a0932ff 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java @@ -23,9 +23,7 @@ import static org.apache.fineract.portfolio.savings.SavingsApiConstants.SAVINGS_ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import java.math.BigDecimal; -import java.time.ZoneId; import java.util.ArrayList; -import java.util.Date; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -692,9 +690,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsAccountDataDTO.getClient(), savingsAccountDataDTO.getGroup(), savingsAccountDataDTO.getSavingsProduct(), savingsAccountDataDTO.getApplicationDate(), savingsAccountDataDTO.getAppliedBy()); - account.approveAndActivateApplication( - Date.from(savingsAccountDataDTO.getApplicationDate().atStartOfDay(ZoneId.systemDefault()).toInstant()), - savingsAccountDataDTO.getAppliedBy()); + account.approveAndActivateApplication(savingsAccountDataDTO.getApplicationDate(), savingsAccountDataDTO.getAppliedBy()); Money amountForDeposit = account.activateWithBalance(); final Set existingTransactionIds = new HashSet<>(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/search/service/SearchReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/search/service/SearchReadPlatformServiceImpl.java index 1a7896c6b..af7cfb98a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/search/service/SearchReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/search/service/SearchReadPlatformServiceImpl.java @@ -22,9 +22,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.ResultSet; import java.sql.SQLException; -import java.time.ZoneId; import java.util.Collection; -import java.util.Date; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; @@ -247,24 +245,18 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService if (StringUtils.isNotBlank(searchConditions.getLoanDateOption())) { if (searchConditions.getLoanDateOption().equals(SearchConstants.SearchLoanDate.APPROVAL_DATE.getValue())) { checkAndUpdateWhereClause(sql); - params.addValue("loanFromDate", - Date.from(searchConditions.getLoanFromDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); - params.addValue("loanToDate", - Date.from(searchConditions.getLoanToDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); + params.addValue("loanFromDate", searchConditions.getLoanFromDate()); + params.addValue("loanToDate", searchConditions.getLoanToDate()); sql.append(" ( ml.approvedon_date between :loanFromDate and :loanToDate ) "); } else if (searchConditions.getLoanDateOption().equals(SearchConstants.SearchLoanDate.CREATED_DATE.getValue())) { checkAndUpdateWhereClause(sql); - params.addValue("loanFromDate", - Date.from(searchConditions.getLoanFromDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); - params.addValue("loanToDate", - Date.from(searchConditions.getLoanToDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); + params.addValue("loanFromDate", searchConditions.getLoanFromDate()); + params.addValue("loanToDate", searchConditions.getLoanToDate()); sql.append(" ( ml.submittedon_date between :loanFromDate and :loanToDate ) "); } else if (searchConditions.getLoanDateOption().equals(SearchConstants.SearchLoanDate.DISBURSAL_DATE.getValue())) { checkAndUpdateWhereClause(sql); - params.addValue("loanFromDate", - Date.from(searchConditions.getLoanFromDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); - params.addValue("loanToDate", - Date.from(searchConditions.getLoanToDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); + params.addValue("loanFromDate", searchConditions.getLoanFromDate()); + params.addValue("loanToDate", searchConditions.getLoanToDate()); sql.append(" ( ml.disbursedon_date between :loanFromDate and :loanToDate ) "); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/domain/SelfServiceRegistration.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/domain/SelfServiceRegistration.java index 5be0538a8..f62301e69 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/domain/SelfServiceRegistration.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/domain/SelfServiceRegistration.java @@ -18,15 +18,14 @@ */ package org.apache.fineract.portfolio.self.registration.domain; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.portfolio.client.domain.Client; @Entity @@ -62,8 +61,7 @@ public class SelfServiceRegistration extends AbstractPersistableCustom { private String password; @Column(name = "created_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date createdDate; + private LocalDateTime createdDate; public SelfServiceRegistration() {} @@ -78,7 +76,7 @@ public class SelfServiceRegistration extends AbstractPersistableCustom { this.authenticationToken = authenticationToken; this.username = username; this.password = password; - this.createdDate = new Date(); + this.createdDate = DateUtils.getLocalDateTimeOfSystem(); } public static SelfServiceRegistration instance(final Client client, final String accountNumber, final String firstName, @@ -112,7 +110,7 @@ public class SelfServiceRegistration extends AbstractPersistableCustom { return this.authenticationToken; } - public Date getCreatedDate() { + public LocalDateTime getCreatedDate() { return this.createdDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountDividendData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountDividendData.java index 4f455df68..97241dccc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountDividendData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountDividendData.java @@ -20,14 +20,14 @@ package org.apache.fineract.portfolio.shareaccounts.data; import java.io.Serializable; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import org.apache.fineract.infrastructure.core.data.EnumOptionData; @SuppressWarnings("unused") public class ShareAccountDividendData implements Serializable { private final Long id; - private final Date postedDate; + private final LocalDate postedDate; private final ShareAccountData accountData; private final BigDecimal amount; private final EnumOptionData status; @@ -52,7 +52,7 @@ public class ShareAccountDividendData implements Serializable { this.postedDate = null; } - public ShareAccountDividendData(final Long id, final Date postedDate, final ShareAccountData accountData, final BigDecimal amount, + public ShareAccountDividendData(final Long id, final LocalDate postedDate, final ShareAccountData accountData, final BigDecimal amount, final EnumOptionData status, final Long savingsTransactionId) { this.id = id; this.accountData = accountData; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccount.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccount.java index f85dcd2fd..28932aeb9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccount.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccount.java @@ -18,7 +18,8 @@ */ package org.apache.fineract.portfolio.shareaccounts.domain; -import java.util.Date; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; @@ -32,8 +33,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.Transient; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @@ -61,48 +60,42 @@ public class ShareAccount extends AbstractPersistableCustom { protected Integer status; @Column(name = "submitted_date") - @Temporal(TemporalType.DATE) - private Date submittedDate; + private LocalDate submittedDate; @ManyToOne(optional = true) @JoinColumn(name = "submitted_userid", nullable = true) protected AppUser submittedBy; - @Temporal(TemporalType.DATE) @Column(name = "approved_date") - protected Date approvedDate; + protected LocalDate approvedDate; @ManyToOne(optional = true) @JoinColumn(name = "approved_userid", nullable = true) protected AppUser approvedBy; - @Temporal(TemporalType.DATE) @Column(name = "rejected_date") - protected Date rejectedDate; + protected LocalDate rejectedDate; @ManyToOne(optional = true) @JoinColumn(name = "rejected_userid", nullable = true) protected AppUser rejectedBy; - @Temporal(TemporalType.DATE) @Column(name = "activated_date", nullable = true) - protected Date activatedDate; + protected LocalDate activatedDate; @ManyToOne(optional = true) @JoinColumn(name = "activated_userid", nullable = true) protected AppUser activatedBy; - @Temporal(TemporalType.DATE) @Column(name = "closed_date") - protected Date closedDate; + protected LocalDate closedDate; @ManyToOne(optional = true) @JoinColumn(name = "closed_userid", nullable = true) protected AppUser closedBy; - @Temporal(TemporalType.DATE) @Column(name = "lastmodified_date") - protected Date modifiedDate; + protected LocalDateTime modifiedDate; @ManyToOne(optional = true) @JoinColumn(name = "lastmodifiedby_id", nullable = true) @@ -162,8 +155,9 @@ public class ShareAccount extends AbstractPersistableCustom { final Set purchasedShares, final Boolean allowDividendCalculationForInactiveClients, final Integer lockinPeriodFrequency, final PeriodFrequencyType lockPeriodType, final Integer minimumActivePeriodFrequency, final PeriodFrequencyType minimumActivePeriodType, Set charges, AppUser submittedBy, - final Date submittedDate, AppUser approvedBy, Date approvedDate, AppUser rejectedBy, Date rejectedDate, AppUser activatedBy, - Date activatedDate, AppUser closedBy, Date closedDate, AppUser modifiedBy, Date modifiedDate) { + final LocalDate submittedDate, AppUser approvedBy, LocalDate approvedDate, AppUser rejectedBy, LocalDate rejectedDate, + AppUser activatedBy, LocalDate activatedDate, AppUser closedBy, LocalDate closedDate, AppUser modifiedBy, + LocalDateTime modifiedDate) { this.client = client; this.shareProduct = shareProduct; @@ -213,7 +207,7 @@ public class ShareAccount extends AbstractPersistableCustom { return this.shareProduct; } - public boolean setSubmittedDate(final Date submittedDate) { + public boolean setSubmittedDate(final LocalDate submittedDate) { boolean toReturn = false; if (this.submittedDate.compareTo(submittedDate) == 0 ? Boolean.FALSE : Boolean.TRUE) { this.submittedDate = submittedDate; @@ -222,7 +216,7 @@ public class ShareAccount extends AbstractPersistableCustom { return toReturn; } - public boolean setApprovedDate(final Date approvedDate) { + public boolean setApprovedDate(final LocalDate approvedDate) { boolean toReturn = false; if (this.approvedDate.compareTo(approvedDate) == 0 ? Boolean.FALSE : Boolean.TRUE) { this.approvedDate = approvedDate; @@ -397,7 +391,7 @@ public class ShareAccount extends AbstractPersistableCustom { this.charges.add(charge); } - public void approve(final Date approvedDate, final AppUser approvedUser) { + public void approve(final LocalDate approvedDate, final AppUser approvedUser) { this.approvedDate = approvedDate; this.approvedBy = approvedUser; for (ShareAccountTransaction transaction : this.shareAccountTransactions) { @@ -408,7 +402,7 @@ public class ShareAccount extends AbstractPersistableCustom { this.totalSharesPending = null; } - public void activate(final Date approvedDate, final AppUser approvedUser) { + public void activate(final LocalDate approvedDate, final AppUser approvedUser) { this.activatedDate = approvedDate; this.activatedBy = approvedUser; this.status = ShareAccountStatusType.ACTIVE.getValue(); @@ -433,7 +427,7 @@ public class ShareAccount extends AbstractPersistableCustom { this.totalSharesPending = tempTotalShares; } - public void reject(final Date rejectedDate, final AppUser rejectedUser) { + public void reject(final LocalDate rejectedDate, final AppUser rejectedUser) { this.rejectedDate = rejectedDate; this.rejectedBy = rejectedUser; this.status = ShareAccountStatusType.REJECTED.getValue(); @@ -446,7 +440,7 @@ public class ShareAccount extends AbstractPersistableCustom { } } - public void close(final Date closedDate, final AppUser closedBy) { + public void close(final LocalDate closedDate, final AppUser closedBy) { this.closedDate = closedDate; this.closedBy = closedBy; this.status = ShareAccountStatusType.CLOSED.getValue(); @@ -532,11 +526,11 @@ public class ShareAccount extends AbstractPersistableCustom { return returnTrans; } - public Date getSubmittedDate() { + public LocalDate getSubmittedDate() { return this.submittedDate; } - public Date getApprovedDate() { + public LocalDate getApprovedDate() { return this.approvedDate; } @@ -566,7 +560,7 @@ public class ShareAccount extends AbstractPersistableCustom { return this.lockinPeriodFrequencyType; } - public Date getActivatedDate() { + public LocalDate getActivatedDate() { return this.activatedDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccountTransaction.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccountTransaction.java index 9943f803b..2453ffc02 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccountTransaction.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccountTransaction.java @@ -19,7 +19,7 @@ package org.apache.fineract.portfolio.shareaccounts.domain; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; @@ -30,8 +30,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @Entity @@ -43,8 +41,7 @@ public class ShareAccountTransaction extends AbstractPersistableCustom { private ShareAccount shareAccount; @Column(name = "transaction_date") - @Temporal(TemporalType.DATE) - private Date transactionDate; + private LocalDate transactionDate; @Column(name = "total_shares") private Long totalShares; @@ -81,7 +78,7 @@ public class ShareAccountTransaction extends AbstractPersistableCustom { this.shareAccount = shareAccount; } - public ShareAccountTransaction(final Date transactionDate, final Long totalShares, final BigDecimal shareValue) { + public ShareAccountTransaction(final LocalDate transactionDate, final Long totalShares, final BigDecimal shareValue) { this.transactionDate = transactionDate; this.totalShares = totalShares; this.shareValue = shareValue; @@ -91,8 +88,8 @@ public class ShareAccountTransaction extends AbstractPersistableCustom { this.amountPaid = new BigDecimal(this.amount.doubleValue()); } - private ShareAccountTransaction(final Date transactionDate, final Long totalShares, final BigDecimal shareValue, final Integer status, - final Integer type, final BigDecimal amount, final BigDecimal chargeAmount, final BigDecimal amountPaid) { + private ShareAccountTransaction(final LocalDate transactionDate, final Long totalShares, final BigDecimal shareValue, + final Integer status, final Integer type, final BigDecimal amount, final BigDecimal chargeAmount, final BigDecimal amountPaid) { this.transactionDate = transactionDate; this.totalShares = totalShares; this.shareValue = shareValue; @@ -103,7 +100,7 @@ public class ShareAccountTransaction extends AbstractPersistableCustom { this.amountPaid = amountPaid; } - public static ShareAccountTransaction createRedeemTransaction(final Date transactionDate, final Long totalShares, + public static ShareAccountTransaction createRedeemTransaction(final LocalDate transactionDate, final Long totalShares, final BigDecimal shareValue) { final Integer status = PurchasedSharesStatusType.APPROVED.getValue(); final Integer type = PurchasedSharesStatusType.REDEEMED.getValue(); @@ -112,7 +109,7 @@ public class ShareAccountTransaction extends AbstractPersistableCustom { return new ShareAccountTransaction(transactionDate, totalShares, shareValue, status, type, amount, null, amountPaid); } - public static ShareAccountTransaction createChargeTransaction(final Date transactionDate, final ShareAccountCharge charge) { + public static ShareAccountTransaction createChargeTransaction(final LocalDate transactionDate, final ShareAccountCharge charge) { final Long totalShares = null; final BigDecimal unitPrice = null; final Integer status = PurchasedSharesStatusType.APPROVED.getValue(); @@ -123,7 +120,7 @@ public class ShareAccountTransaction extends AbstractPersistableCustom { return new ShareAccountTransaction(transactionDate, totalShares, unitPrice, status, type, amount, chargeAmount, amountPaid); } - public Date getPurchasedDate() { + public LocalDate getPurchasedDate() { return this.transactionDate; } @@ -135,7 +132,7 @@ public class ShareAccountTransaction extends AbstractPersistableCustom { return this.shareValue; } - public void update(final Date purchasedDate, final Long totalShares, final BigDecimal shareValue) { + public void update(final LocalDate purchasedDate, final Long totalShares, final BigDecimal shareValue) { this.transactionDate = purchasedDate; this.totalShares = totalShares; this.shareValue = shareValue; @@ -243,7 +240,7 @@ public class ShareAccountTransaction extends AbstractPersistableCustom { } } - public void updateTransactionDate(final Date transactionDate) { + public void updateTransactionDate(final LocalDate transactionDate) { this.transactionDate = transactionDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/serialization/ShareAccountDataSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/serialization/ShareAccountDataSerializer.java index 5925b1ca6..a7c16bfce 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/serialization/ShareAccountDataSerializer.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/serialization/ShareAccountDataSerializer.java @@ -25,11 +25,10 @@ import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -199,29 +198,27 @@ public class ShareAccountDataSerializer { AppUser submittedBy = platformSecurityContext.authenticatedUser(); AppUser approvedBy = null; - Date approvedDate = null; + LocalDate approvedDate = null; AppUser rejectedBy = null; - Date rejectedDate = null; + LocalDate rejectedDate = null; AppUser activatedBy = null; - Date activatedDate = null; + LocalDate activatedDate = null; AppUser closedBy = null; - Date closedDate = null; + LocalDate closedDate = null; AppUser modifiedBy = null; - Date modifiedDate = null; + LocalDateTime modifiedDate = null; String accountNo = null; Long approvedShares = null; Long pendingShares = requestedShares; - BigDecimal unitPrice = shareProduct.deriveMarketPrice(Date.from(applicationDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); - ShareAccountTransaction transaction = new ShareAccountTransaction( - Date.from(applicationDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), requestedShares, unitPrice); + BigDecimal unitPrice = shareProduct.deriveMarketPrice(applicationDate); + ShareAccountTransaction transaction = new ShareAccountTransaction(applicationDate, requestedShares, unitPrice); Set sharesPurchased = new HashSet<>(); sharesPurchased.add(transaction); ShareAccount account = new ShareAccount(client, shareProduct, externalId, currency, savingsAccount, accountNo, approvedShares, pendingShares, sharesPurchased, allowdividendsForInactiveClients, lockinPeriod, lockPeriodEnum, minimumActivePeriod, - minimumActivePeriodEnum, charges, submittedBy, Date.from(submittedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), - approvedBy, approvedDate, rejectedBy, rejectedDate, activatedBy, activatedDate, closedBy, closedDate, modifiedBy, - modifiedDate); + minimumActivePeriodEnum, charges, submittedBy, submittedDate, approvedBy, approvedDate, rejectedBy, rejectedDate, + activatedBy, activatedDate, closedBy, closedDate, modifiedBy, modifiedDate); for (ShareAccountTransaction pur : sharesPurchased) { pur.setShareAccount(account); @@ -239,7 +236,7 @@ public class ShareAccountDataSerializer { private void createChargeTransaction(ShareAccount account) { BigDecimal totalChargeAmount = BigDecimal.ZERO; Set charges = account.getCharges(); - Date currentDate = Date.from(DateUtils.getBusinessLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant()); + LocalDate currentDate = DateUtils.getBusinessLocalDate(); for (ShareAccountCharge charge : charges) { if (charge.isActive() && charge.isShareAccountActivation()) { charge.deriveChargeAmount(totalChargeAmount, account.getCurrency()); @@ -286,9 +283,8 @@ public class ShareAccountDataSerializer { } if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.submitteddate_paramname, element)) { - final Date submittedDate = Date - .from(this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.submitteddate_paramname, element) - .atStartOfDay(ZoneId.systemDefault()).toInstant()); + final LocalDate submittedDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.submitteddate_paramname, + element); baseDataValidator.reset().parameter(ShareAccountApiConstants.submitteddate_paramname).value(submittedDate).notNull(); if (account.setSubmittedDate(submittedDate)) { actualChanges.put(ShareAccountApiConstants.submitteddate_paramname, submittedDate); @@ -319,7 +315,7 @@ public class ShareAccountDataSerializer { } } - Date existingApplicationDate = null; + LocalDate existingApplicationDate = null; List purchaseTransactionsList = new ArrayList<>(); Set chargesList = new HashSet<>(); @@ -358,12 +354,10 @@ public class ShareAccountDataSerializer { if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.requestedshares_paramname, element)) { Long requestedShares = this.fromApiJsonHelper.extractLongNamed(ShareAccountApiConstants.requestedshares_paramname, element); baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname).value(requestedShares).notNull(); - Date applicationDate = null; + LocalDate applicationDate = null; purchaseTransactionsList.clear(); if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.applicationdate_param, element)) { - applicationDate = Date - .from(this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.applicationdate_param, element) - .atStartOfDay(ZoneId.systemDefault()).toInstant()); + applicationDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.applicationdate_param, element); baseDataValidator.reset().parameter(ShareAccountApiConstants.applicationdate_param).value(applicationDate).notNull(); } else { applicationDate = existingApplicationDate; @@ -474,7 +468,7 @@ public class ShareAccountDataSerializer { baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.pending.for.approval"); } LocalDate approvedDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.approveddate_paramname, element); - final LocalDate submittalDate = LocalDate.ofInstant(account.getSubmittedDate().toInstant(), DateUtils.getDateTimeZoneOfTenant()); + final LocalDate submittalDate = account.getSubmittedDate(); if (approvedDate != null && approvedDate.isBefore(submittalDate)) { final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(jsonCommand.dateFormat()) .withLocale(jsonCommand.extractLocale()); @@ -495,7 +489,7 @@ public class ShareAccountDataSerializer { } AppUser approvedUser = this.platformSecurityContext.authenticatedUser(); - account.approve(Date.from(approvedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), approvedUser); + account.approve(approvedDate, approvedUser); actualChanges.put(ShareAccountApiConstants.id_paramname, account.getId()); updateTotalChargeDerived(account); return actualChanges; @@ -593,7 +587,7 @@ public class ShareAccountDataSerializer { public Map validateAndReject(JsonCommand jsonCommand, ShareAccount account) { Map actualChanges = new HashMap<>(); AppUser rejectedUser = this.platformSecurityContext.authenticatedUser(); - Date rejectedDate = DateUtils.getBusinessDate(); + LocalDate rejectedDate = DateUtils.getBusinessLocalDate(); account.reject(rejectedDate, rejectedUser); actualChanges.put(ShareAccountApiConstants.charges_paramname, Boolean.TRUE); return actualChanges; @@ -615,7 +609,7 @@ public class ShareAccountDataSerializer { } LocalDate activatedDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.activatedate_paramname, element); baseDataValidator.reset().parameter(ShareAccountApiConstants.activatedate_paramname).value(activatedDate).notNull(); - final LocalDate approvedDate = LocalDate.ofInstant(account.getApprovedDate().toInstant(), DateUtils.getDateTimeZoneOfTenant()); + final LocalDate approvedDate = account.getApprovedDate(); if (activatedDate != null && activatedDate.isBefore(approvedDate)) { final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(jsonCommand.dateFormat()) .withLocale(jsonCommand.extractLocale()); @@ -627,10 +621,9 @@ public class ShareAccountDataSerializer { throw new PlatformApiDataValidationException(dataValidationErrors); } AppUser approvedUser = this.platformSecurityContext.authenticatedUser(); - account.activate(Date.from(activatedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), approvedUser); + account.activate(activatedDate, approvedUser); handlechargesOnActivation(account); - actualChanges.put(ShareAccountApiConstants.charges_paramname, - Date.from(activatedDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); + actualChanges.put(ShareAccountApiConstants.charges_paramname, activatedDate); return actualChanges; } @@ -716,8 +709,7 @@ public class ShareAccountDataSerializer { Set transactions = account.getShareAccountTransactions(); for (ShareAccountTransaction transaction : transactions) { if (!transaction.isChargeTransaction()) { - LocalDate transactionDate = LocalDate.ofInstant(transaction.getPurchasedDate().toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + LocalDate transactionDate = transaction.getPurchasedDate(); if (requestedDate.isBefore(transactionDate)) { isTransactionBeforeExistingTransactions = true; break; @@ -732,10 +724,8 @@ public class ShareAccountDataSerializer { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } - final BigDecimal unitPrice = shareProduct - .deriveMarketPrice(Date.from(requestedDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); - ShareAccountTransaction purchaseTransaction = new ShareAccountTransaction( - Date.from(requestedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), sharesRequested, unitPrice); + final BigDecimal unitPrice = shareProduct.deriveMarketPrice(requestedDate); + ShareAccountTransaction purchaseTransaction = new ShareAccountTransaction(requestedDate, sharesRequested, unitPrice); account.addAdditionalPurchasedShares(purchaseTransaction); handleAdditionalSharesChargeTransactions(account, purchaseTransaction); actualChanges.put(ShareAccountApiConstants.additionalshares_paramname, purchaseTransaction); @@ -876,8 +866,7 @@ public class ShareAccountDataSerializer { Set transactions = account.getShareAccountTransactions(); for (ShareAccountTransaction transaction : transactions) { if (!transaction.isChargeTransaction() && transaction.isActive()) { - LocalDate transactionDate = LocalDate.ofInstant(transaction.getPurchasedDate().toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + LocalDate transactionDate = transaction.getPurchasedDate(); if (requestedDate.isBefore(transactionDate)) { isTransactionBeforeExistingTransactions = true; break; @@ -891,10 +880,8 @@ public class ShareAccountDataSerializer { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } - BigDecimal unitPrice = account.getShareProduct() - .deriveMarketPrice(Date.from(requestedDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); - ShareAccountTransaction transaction = ShareAccountTransaction.createRedeemTransaction( - Date.from(requestedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), sharesRequested, unitPrice); + BigDecimal unitPrice = account.getShareProduct().deriveMarketPrice(requestedDate); + ShareAccountTransaction transaction = ShareAccountTransaction.createRedeemTransaction(requestedDate, sharesRequested, unitPrice); validateRedeemRequest(account, transaction, baseDataValidator, dataValidationErrors); account.addAdditionalPurchasedShares(transaction); actualChanges.put(ShareAccountApiConstants.requestedshares_paramname, transaction); @@ -915,7 +902,7 @@ public class ShareAccountDataSerializer { throw new PlatformApiDataValidationException(dataValidationErrors); } - LocalDate redeemDate = LocalDate.ofInstant(redeemTransaction.getPurchasedDate().toInstant(), DateUtils.getDateTimeZoneOfTenant()); + LocalDate redeemDate = redeemTransaction.getPurchasedDate(); final Integer lockinPeriod = account.getLockinPeriodFrequency(); final PeriodFrequencyType periodType = account.getLockinPeriodFrequencyType(); if (lockinPeriod == null && periodType == null) { @@ -928,8 +915,7 @@ public class ShareAccountDataSerializer { Set transactions = account.getShareAccountTransactions(); for (ShareAccountTransaction transaction : transactions) { if (transaction.isActive() && !transaction.isChargeTransaction()) { - LocalDate purchaseDate = LocalDate.ofInstant(transaction.getPurchasedDate().toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + LocalDate purchaseDate = transaction.getPurchasedDate(); LocalDate lockinDate = deriveLockinPeriodDuration(lockinPeriod, periodType, purchaseDate); if (!lockinDate.isAfter(redeemDate)) { if (transaction.isPurchasTransaction()) { @@ -1035,8 +1021,7 @@ public class ShareAccountDataSerializer { Set transactions = account.getShareAccountTransactions(); for (ShareAccountTransaction transaction : transactions) { if (!transaction.isChargeTransaction()) { - LocalDate transactionDate = LocalDate.ofInstant(transaction.getPurchasedDate().toInstant(), - DateUtils.getDateTimeZoneOfTenant()); + LocalDate transactionDate = transaction.getPurchasedDate(); if (closedDate.isBefore(transactionDate)) { isTransactionBeforeExistingTransactions = true; break; @@ -1053,11 +1038,11 @@ public class ShareAccountDataSerializer { } AppUser approvedUser = this.platformSecurityContext.authenticatedUser(); - final BigDecimal unitPrice = account.getShareProduct().deriveMarketPrice(DateUtils.getBusinessDate()); - ShareAccountTransaction transaction = ShareAccountTransaction.createRedeemTransaction( - Date.from(closedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), account.getTotalApprovedShares(), unitPrice); + final BigDecimal unitPrice = account.getShareProduct().deriveMarketPrice(DateUtils.getBusinessLocalDate()); + ShareAccountTransaction transaction = ShareAccountTransaction.createRedeemTransaction(closedDate, account.getTotalApprovedShares(), + unitPrice); account.addAdditionalPurchasedShares(transaction); - account.close(Date.from(closedDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), approvedUser); + account.close(closedDate, approvedUser); handleRedeemSharesChargeTransactions(account, transaction); actualChanges.put(ShareAccountApiConstants.requestedshares_paramname, transaction); return actualChanges; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountReadPlatformServiceImpl.java index e9e528ed3..2bb840d54 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountReadPlatformServiceImpl.java @@ -23,11 +23,9 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDate; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Set; import org.apache.fineract.infrastructure.core.data.EnumOptionData; @@ -139,10 +137,10 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat BigDecimal marketValue = shareProductData.getUnitPrice(); Collection marketDataSet = shareProductData.getMarketPrice(); if (marketDataSet != null && !marketDataSet.isEmpty()) { - Date currentDate = DateUtils.getBusinessDate(); + LocalDate currentDate = DateUtils.getBusinessLocalDate(); for (ShareProductMarketPriceData data : marketDataSet) { - Date futureDate = data.getStartDate(); - if (currentDate.after(futureDate)) { + LocalDate futureDate = data.getStartDate(); + if (currentDate.isAfter(futureDate)) { marketValue = data.getShareValue(); } } @@ -501,8 +499,7 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat @Override public ShareAccountDividendData mapRow(ResultSet rs, int rowNum) throws SQLException { final Long id = rs.getLong("id"); - final Date postedDate = Date - .from(JdbcSupport.getLocalDate(rs, "created_date").atStartOfDay(ZoneId.systemDefault()).toInstant()); + final LocalDate postedDate = JdbcSupport.getLocalDate(rs, "created_date"); final BigDecimal postedAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "amount"); final Long savingTransactionId = rs.getLong("savings_transaction_id"); final Integer status = rs.getInt("status"); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java index 1a0bb317b..7b18c37a1 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java @@ -21,7 +21,6 @@ package org.apache.fineract.portfolio.shareaccounts.service; import java.math.BigDecimal; import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -148,8 +147,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA final Map transactionDto = new HashMap<>(); transactionDto.put("officeId", account.getOfficeId()); transactionDto.put("id", transaction.getId()); - transactionDto.put("date", - LocalDate.ofInstant(transaction.getPurchasedDate().toInstant(), DateUtils.getDateTimeZoneOfTenant())); + transactionDto.put("date", transaction.getPurchasedDate()); final Integer status = transaction.getTransactionStatus(); final ShareAccountTransactionEnumData statusEnum = new ShareAccountTransactionEnumData(status.longValue(), null, null); final Integer type = transaction.getTransactionType(); @@ -190,7 +188,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA @Override public CommandProcessingResult updateShareAccount(Long accountId, JsonCommand jsonCommand) { try { - Date transactionDate = DateUtils.getBusinessDate(); + LocalDate transactionDate = DateUtils.getBusinessLocalDate(); ShareAccount account = this.shareAccountRepository.findOneWithNotFoundDetection(accountId); Map changes = this.accountDataSerializer.validateAndUpdate(jsonCommand, account); if (!changes.isEmpty()) { @@ -350,7 +348,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA journalEntryTransactions.add(transaction.getId()); } } - Date transactionDate = DateUtils.getBusinessDate(); + LocalDate transactionDate = DateUtils.getBusinessLocalDate(); this.journalEntryWritePlatformService.revertShareAccountJournalEntries(journalEntryTransactions, transactionDate); journalEntryWritePlatformService.createJournalEntriesForShares( populateJournalEntries(account, account.getPendingForApprovalSharePurchaseTransactions())); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/data/ShareProductMarketPriceData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/data/ShareProductMarketPriceData.java index 0668a5651..7c941a94b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/data/ShareProductMarketPriceData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/data/ShareProductMarketPriceData.java @@ -19,17 +19,17 @@ package org.apache.fineract.portfolio.shareproducts.data; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; public class ShareProductMarketPriceData { private final Long id; - private final Date fromDate; + private final LocalDate fromDate; private final BigDecimal shareValue; - public ShareProductMarketPriceData(final Long id, final Date fromDate, final BigDecimal shareValue) { + public ShareProductMarketPriceData(final Long id, final LocalDate fromDate, final BigDecimal shareValue) { this.id = id; this.fromDate = fromDate; this.shareValue = shareValue; @@ -39,7 +39,7 @@ public class ShareProductMarketPriceData { return this.id; } - public Date getStartDate() { + public LocalDate getStartDate() { return this.fromDate; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProduct.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProduct.java index 629817898..c728fae46 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProduct.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProduct.java @@ -19,7 +19,7 @@ package org.apache.fineract.portfolio.shareproducts.domain; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; @@ -35,8 +35,6 @@ import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.accounting.common.AccountingRuleType; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; import org.apache.fineract.infrastructure.core.service.DateUtils; @@ -60,12 +58,10 @@ public class ShareProduct extends AbstractAuditableCustom { private String description; @Column(name = "start_date") - @Temporal(TemporalType.DATE) - private Date startDate; + private LocalDate startDate; @Column(name = "end_date") - @Temporal(TemporalType.DATE) - private Date endDate; + private LocalDate endDate; @Column(name = "external_id", length = 100, nullable = true, unique = true) private String externalId; @@ -156,8 +152,8 @@ public class ShareProduct extends AbstractAuditableCustom { this.minimumActivePeriod = minimumActivePeriod; this.minimumActivePeriodType = minimumActivePeriodForDividendsType; // TODO: is this used at all? - this.startDate = DateUtils.getBusinessDate(); - this.endDate = DateUtils.getBusinessDate(); + this.startDate = DateUtils.getBusinessLocalDate(); + this.endDate = DateUtils.getBusinessLocalDate(); if (accountingRuleType != null) { this.accountingRule = accountingRuleType.getValue(); } @@ -395,12 +391,12 @@ public class ShareProduct extends AbstractAuditableCustom { return allowed; } - public BigDecimal deriveMarketPrice(final Date currentDate) { + public BigDecimal deriveMarketPrice(final LocalDate currentDate) { BigDecimal marketValue = this.unitPrice; if (this.marketPrice != null && !this.marketPrice.isEmpty()) { for (ShareProductMarketPrice data : this.marketPrice) { - Date futureDate = data.getStartDate(); - if (currentDate.compareTo(futureDate) == 0 ? Boolean.TRUE : Boolean.FALSE || currentDate.after(futureDate)) { + LocalDate futureDate = data.getStartDate(); + if (currentDate.compareTo(futureDate) == 0 ? Boolean.TRUE : Boolean.FALSE || currentDate.isAfter(futureDate)) { marketValue = data.getPrice(); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProductDividendPayOutDetails.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProductDividendPayOutDetails.java index dc87dfd73..ca139b190 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProductDividendPayOutDetails.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProductDividendPayOutDetails.java @@ -21,7 +21,6 @@ package org.apache.fineract.portfolio.shareproducts.domain; import java.math.BigDecimal; import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -29,10 +28,7 @@ import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountDividendDetails; @Entity @@ -46,12 +42,10 @@ public class ShareProductDividendPayOutDetails extends AbstractAuditableCustom { private BigDecimal amount; @Column(name = "dividend_period_start_date") - @Temporal(TemporalType.DATE) - private Date dividendPeriodStartDate; + private LocalDate dividendPeriodStartDate; @Column(name = "dividend_period_end_date") - @Temporal(TemporalType.DATE) - private Date dividendPeriodEndDate; + private LocalDate dividendPeriodEndDate; @Column(name = "status", nullable = false) private Integer status; @@ -63,8 +57,8 @@ public class ShareProductDividendPayOutDetails extends AbstractAuditableCustom { } - public ShareProductDividendPayOutDetails(final Long shareProductId, final BigDecimal amount, final Date dividendPeriodStartDate, - final Date dividendPeriodEndDate) { + public ShareProductDividendPayOutDetails(final Long shareProductId, final BigDecimal amount, final LocalDate dividendPeriodStartDate, + final LocalDate dividendPeriodEndDate) { this.shareProductId = shareProductId; this.amount = amount; this.dividendPeriodStartDate = dividendPeriodStartDate; @@ -73,11 +67,7 @@ public class ShareProductDividendPayOutDetails extends AbstractAuditableCustom { } public LocalDate getDividendPeriodEndDateAsLocalDate() { - LocalDate dividendPeriodEndDate = null; - if (this.dividendPeriodEndDate != null) { - dividendPeriodEndDate = LocalDate.ofInstant(this.dividendPeriodEndDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return dividendPeriodEndDate; + return this.dividendPeriodEndDate; } public List getAccountDividendDetails() { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProductMarketPrice.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProductMarketPrice.java index 4be38768a..4aab45eb9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProductMarketPrice.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProductMarketPrice.java @@ -19,14 +19,12 @@ package org.apache.fineract.portfolio.shareproducts.domain; import java.math.BigDecimal; -import java.util.Date; +import java.time.LocalDate; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @Entity @@ -38,8 +36,7 @@ public class ShareProductMarketPrice extends AbstractPersistableCustom { private ShareProduct product; @Column(name = "from_date") - @Temporal(TemporalType.DATE) - private Date fromDate; + private LocalDate fromDate; @Column(name = "share_value", nullable = false) private BigDecimal shareValue; @@ -48,7 +45,7 @@ public class ShareProductMarketPrice extends AbstractPersistableCustom { } - public ShareProductMarketPrice(final Date fromDate, final BigDecimal shareValue) { + public ShareProductMarketPrice(final LocalDate fromDate, final BigDecimal shareValue) { this.fromDate = fromDate; this.shareValue = shareValue; } @@ -57,7 +54,7 @@ public class ShareProductMarketPrice extends AbstractPersistableCustom { this.product = product; } - public Date getStartDate() { + public LocalDate getStartDate() { return this.fromDate; } @@ -65,7 +62,7 @@ public class ShareProductMarketPrice extends AbstractPersistableCustom { return this.shareValue; } - public void setStartDate(Date date) { + public void setStartDate(LocalDate date) { this.fromDate = date; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/serialization/ShareProductDataSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/serialization/ShareProductDataSerializer.java index 69c93a40f..64e2b6c7e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/serialization/ShareProductDataSerializer.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/serialization/ShareProductDataSerializer.java @@ -25,10 +25,8 @@ import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -214,8 +212,7 @@ public class ShareProductDataSerializer { arrayElement); final BigDecimal shareValue = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(ShareProductApiConstants.sharevalue_paramname, arrayElement); - ShareProductMarketPriceData obj = new ShareProductMarketPriceData(id, - Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), shareValue); + ShareProductMarketPriceData obj = new ShareProductMarketPriceData(id, localDate, shareValue); set.add(obj); } } @@ -232,8 +229,7 @@ public class ShareProductDataSerializer { arrayElement); final BigDecimal shareValue = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(ShareProductApiConstants.sharevalue_paramname, arrayElement); - ShareProductMarketPrice obj = new ShareProductMarketPrice( - Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), shareValue); + ShareProductMarketPrice obj = new ShareProductMarketPrice(localDate, shareValue); set.add(obj); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java index 74e548a9b..3dc5b1f22 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java @@ -20,10 +20,8 @@ package org.apache.fineract.portfolio.shareproducts.service; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.time.temporal.ChronoUnit; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.Map; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; @@ -78,8 +76,7 @@ public class ShareProductDividendAssembler { if (numberOfShareDays > 0) { double amountPerShareDay = amount.doubleValue() / numberOfShareDays; productDividendPayOutDetails = new ShareProductDividendPayOutDetails(productId, Money.of(currency, amount).getAmount(), - Date.from(dividendPeriodStartDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), - Date.from(dividendPeriodEndDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); + dividendPeriodStartDate, dividendPeriodEndDate); for (ShareAccountData accountData : shareAccountDatas) { long numberOfShareDaysPerAccount = numberOfSharesdaysPerAccount.get(accountData.getId()); double amountForAccount = numberOfShareDaysPerAccount * amountPerShareDay; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java index d5615f9a2..4261a384f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java @@ -19,10 +19,11 @@ package org.apache.fineract.portfolio.shareproducts.service; import java.math.BigDecimal; +import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; @@ -178,7 +179,8 @@ public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformS final Long id = rs.getLong("id"); final Date fromDate = rs.getDate("from_date"); final BigDecimal shareValue = rs.getBigDecimal("share_value"); - return new ShareProductMarketPriceData(id, fromDate, shareValue); + final LocalDate fromLocalDate = fromDate != null ? fromDate.toLocalDate() : null; + return new ShareProductMarketPriceData(id, fromLocalDate, shareValue); } public String schema() { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxComponent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxComponent.java index 8b79ee3f3..f3419079a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxComponent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxComponent.java @@ -20,10 +20,8 @@ package org.apache.fineract.portfolio.tax.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -37,8 +35,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.accounting.glaccount.domain.GLAccount; import org.apache.fineract.accounting.glaccount.domain.GLAccountType; @@ -72,8 +68,7 @@ public class TaxComponent extends AbstractAuditableCustom { private GLAccount creditAcount; @Column(name = "start_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date startDate; + private LocalDate startDate; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) @JoinColumn(name = "tax_component_id", referencedColumnName = "id", nullable = false) @@ -98,7 +93,7 @@ public class TaxComponent extends AbstractAuditableCustom { this.creditAccountType = creditAccountType.getValue(); } this.creditAcount = creditAcount; - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = startDate; } public static TaxComponent createTaxComponent(final String name, final BigDecimal percentage, final GLAccountType debitAccountType, @@ -119,9 +114,9 @@ public class TaxComponent extends AbstractAuditableCustom { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(TaxApiConstants.percentageParamName); changes.put(TaxApiConstants.percentageParamName, newValue); - LocalDate oldStartDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + LocalDate oldStartDate = this.startDate; updateStartDate(command, changes, true); - LocalDate newStartDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + LocalDate newStartDate = this.startDate; TaxComponentHistory history = TaxComponentHistory.createTaxComponentHistory(this.percentage, oldStartDate, newStartDate); this.taxComponentHistories.add(history); @@ -139,11 +134,11 @@ public class TaxComponent extends AbstractAuditableCustom { if (startDateFromUI != null) { startDate = startDateFromUI; } - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = startDate; changes.put(TaxApiConstants.startDateParamName, startDate); } else if (setAsCurrentDate) { changes.put(TaxApiConstants.startDateParamName, startDate); - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = startDate; } } @@ -153,11 +148,7 @@ public class TaxComponent extends AbstractAuditableCustom { } public LocalDate startDate() { - LocalDate startDate = null; - if (this.startDate != null) { - startDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return startDate; + return this.startDate; } public BigDecimal getApplicablePercentage(final LocalDate date) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxComponentHistory.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxComponentHistory.java index 87514f157..2341058bc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxComponentHistory.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxComponentHistory.java @@ -20,15 +20,10 @@ package org.apache.fineract.portfolio.tax.domain; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; @Entity @Table(name = "m_tax_component_history") @@ -38,12 +33,10 @@ public class TaxComponentHistory extends AbstractAuditableCustom { private BigDecimal percentage; @Column(name = "start_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date startDate; + private LocalDate startDate; @Column(name = "end_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date endDate; + private LocalDate endDate; protected TaxComponentHistory() { @@ -51,8 +44,8 @@ public class TaxComponentHistory extends AbstractAuditableCustom { private TaxComponentHistory(final BigDecimal percentage, final LocalDate startDate, final LocalDate endDate) { this.percentage = percentage; - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - this.endDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + this.startDate = startDate; + this.endDate = endDate; } public static TaxComponentHistory createTaxComponentHistory(final BigDecimal percentage, final LocalDate startDate, @@ -61,19 +54,11 @@ public class TaxComponentHistory extends AbstractAuditableCustom { } public LocalDate startDate() { - LocalDate startDate = null; - if (this.startDate != null) { - startDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return startDate; + return this.startDate; } public LocalDate endDate() { - LocalDate endDate = null; - if (this.endDate != null) { - endDate = LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return endDate; + return this.endDate; } public boolean occursOnDayFromAndUpToAndIncluding(final LocalDate target) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxGroupMappings.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxGroupMappings.java index 608841c35..d5ed7afac 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxGroupMappings.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/domain/TaxGroupMappings.java @@ -19,8 +19,6 @@ package org.apache.fineract.portfolio.tax.domain; import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -29,10 +27,7 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.portfolio.tax.api.TaxApiConstants; @Entity @@ -48,24 +43,17 @@ public class TaxGroupMappings extends AbstractAuditableCustom { private TaxComponent taxComponent; @Column(name = "start_date", nullable = false) - @Temporal(TemporalType.DATE) - private Date startDate; + private LocalDate startDate; @Column(name = "end_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date endDate; + private LocalDate endDate; protected TaxGroupMappings() {} private TaxGroupMappings(final TaxComponent taxComponent, final LocalDate startDate, final LocalDate endDate) { - this.taxComponent = taxComponent; - if (startDate != null) { - this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } - if (endDate != null) { - this.endDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - } + this.startDate = startDate; + this.endDate = endDate; } public static TaxGroupMappings createTaxGroupMappings(final TaxComponent taxComponent, final LocalDate startDate) { @@ -82,7 +70,7 @@ public class TaxGroupMappings extends AbstractAuditableCustom { } - public void update(final Date endDate, final List> changes) { + public void update(final LocalDate endDate, final List> changes) { if (endDate != null && this.endDate == null) { this.endDate = endDate; Map map = new HashMap<>(2); @@ -103,31 +91,23 @@ public class TaxGroupMappings extends AbstractAuditableCustom { return this.taxComponent; } - public Date getEndDate() { + public LocalDate getEndDate() { return this.endDate; } public LocalDate startDate() { - LocalDate startDate = null; - if (this.startDate != null) { - startDate = LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return startDate; + return this.startDate; } public LocalDate endDate() { - LocalDate endDate = null; - if (this.endDate != null) { - endDate = LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); - } - return endDate; - } - - public void setTaxGroup(TaxGroup taxGroup) { - this.taxGroup = taxGroup; + return this.endDate; } public TaxGroup getTaxGroup() { return taxGroup; } + + public void setTaxGroup(TaxGroup taxGroup) { + this.taxGroup = taxGroup; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java index d063483dd..8249c4b6b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java @@ -21,11 +21,9 @@ package org.apache.fineract.scheduledjobs.service; import java.math.BigDecimal; import java.math.BigInteger; import java.time.LocalDate; -import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Map; import org.apache.fineract.accounting.glaccount.domain.TrialBalance; @@ -247,8 +245,7 @@ public class ScheduledJobRunnerServiceImpl implements ScheduledJobRunnerService final Long savingsId = (Long) details.get("savingsId"); final BigDecimal amount = (BigDecimal) details.get("amount"); final String recurrence = (String) details.get("recurrence"); - Date date = (Date) details.get("dueDate"); - LocalDate lastDepositDate = LocalDate.ofInstant(date.toInstant(), DateUtils.getDateTimeZoneOfTenant()); + LocalDate lastDepositDate = (LocalDate) details.get("dueDate"); Integer installmentNumber = (Integer) details.get("installment"); while (count < DepositAccountUtils.GENERATE_MINIMUM_NUMBER_OF_FUTURE_INSTALMENTS) { count++; @@ -331,11 +328,10 @@ public class ScheduledJobRunnerServiceImpl implements ScheduledJobRunnerService tbGapSqlBuilder.append("select distinct(je.transaction_date) ").append("from acc_gl_journal_entry je ") .append("where je.transaction_date > (select coalesce(MAX(created_date),'2010-01-01') from m_trial_balance)"); - final List tbGaps = jdbcTemplate.queryForList(tbGapSqlBuilder.toString(), Date.class); + final List tbGaps = jdbcTemplate.queryForList(tbGapSqlBuilder.toString(), LocalDate.class); - for (Date tbGap : tbGaps) { - LocalDate convDate = ZonedDateTime.ofInstant(tbGap.toInstant(), DateUtils.getDateTimeZoneOfTenant()).toLocalDate(); - int days = Math.toIntExact(ChronoUnit.DAYS.between(convDate, DateUtils.getBusinessLocalDate())); + for (LocalDate tbGap : tbGaps) { + int days = Math.toIntExact(ChronoUnit.DAYS.between(tbGap, DateUtils.getBusinessLocalDate())); if (days < 1) { continue; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/data/ScorecardValue.java b/fineract-provider/src/main/java/org/apache/fineract/spm/data/ScorecardValue.java index e89504ff9..33ec7c767 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/data/ScorecardValue.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/data/ScorecardValue.java @@ -18,27 +18,28 @@ */ package org.apache.fineract.spm.data; -import java.util.Date; +import java.time.LocalDateTime; public class ScorecardValue { private Long questionId; private Long responseId; private Integer value; - private Date createdOn; + private LocalDateTime createdOn; public ScorecardValue() { } - private ScorecardValue(final Long questionId, final Long responseId, final Integer value, final Date createdOn) { + private ScorecardValue(final Long questionId, final Long responseId, final Integer value, final LocalDateTime createdOn) { this.questionId = questionId; this.responseId = responseId; this.value = value; this.createdOn = createdOn; } - public static ScorecardValue instance(final Long questionId, final Long responseId, final Integer value, final Date createdOn) { + public static ScorecardValue instance(final Long questionId, final Long responseId, final Integer value, + final LocalDateTime createdOn) { return new ScorecardValue(questionId, responseId, value, createdOn); } @@ -66,11 +67,11 @@ public class ScorecardValue { this.value = value; } - public Date getCreatedOn() { + public LocalDateTime getCreatedOn() { return this.createdOn; } - public void setCreatedOn(Date createdOn) { + public void setCreatedOn(LocalDateTime createdOn) { this.createdOn = createdOn; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/data/SurveyData.java b/fineract-provider/src/main/java/org/apache/fineract/spm/data/SurveyData.java index 10ee05f09..aaf56b3cb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/data/SurveyData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/data/SurveyData.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.spm.data; -import java.util.Date; +import java.time.LocalDate; import java.util.List; public class SurveyData { @@ -30,15 +30,15 @@ public class SurveyData { private String name; private String description; private String countryCode; - private Date validFrom; - private Date validTo; + private LocalDate validFrom; + private LocalDate validTo; public SurveyData() { } public SurveyData(final Long id, final List componentDatas, final List questionDatas, final String key, - final String name, final String description, final String countryCode, final Date validFrom, final Date validTo) { + final String name, final String description, final String countryCode, final LocalDate validFrom, final LocalDate validTo) { this.id = id; this.componentDatas = componentDatas; @@ -107,19 +107,19 @@ public class SurveyData { this.countryCode = countryCode; } - public Date getValidFrom() { + public LocalDate getValidFrom() { return validFrom; } - public void setValidFrom(Date validFrom) { + public void setValidFrom(LocalDate validFrom) { this.validFrom = validFrom; } - public Date getValidTo() { + public LocalDate getValidTo() { return validTo; } - public void setValidTo(Date validTo) { + public void setValidTo(LocalDate validTo) { this.validTo = validTo; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/domain/Scorecard.java b/fineract-provider/src/main/java/org/apache/fineract/spm/domain/Scorecard.java index 08a9a141f..ec70d73f2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/domain/Scorecard.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/domain/Scorecard.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.spm.domain; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -26,8 +26,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OrderBy; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.portfolio.client.domain.Client; import org.apache.fineract.useradministration.domain.AppUser; @@ -57,9 +55,8 @@ public class Scorecard extends AbstractPersistableCustom { private Client client; @Column(name = "created_on") - @Temporal(value = TemporalType.TIMESTAMP) @OrderBy("createdOn DESC") - private Date createdOn; + private LocalDateTime createdOn; @Column(name = "a_value", precision = 4) private Integer value; @@ -108,11 +105,11 @@ public class Scorecard extends AbstractPersistableCustom { this.client = client; } - public Date getCreatedOn() { + public LocalDateTime getCreatedOn() { return createdOn; } - public void setCreatedOn(Date createdOn) { + public void setCreatedOn(LocalDateTime createdOn) { this.createdOn = createdOn; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/domain/Survey.java b/fineract-provider/src/main/java/org/apache/fineract/spm/domain/Survey.java index db750b5d0..8f08bb0e2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/domain/Survey.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/domain/Survey.java @@ -18,8 +18,8 @@ */ package org.apache.fineract.spm.domain; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -28,8 +28,6 @@ import javax.persistence.FetchType; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @Entity @@ -57,12 +55,10 @@ public class Survey extends AbstractPersistableCustom { private String countryCode; @Column(name = "valid_from") - @Temporal(value = TemporalType.TIMESTAMP) - private Date validFrom; + private LocalDate validFrom; @Column(name = "valid_to") - @Temporal(value = TemporalType.TIMESTAMP) - private Date validTo; + private LocalDate validTo; public Survey() { @@ -122,19 +118,19 @@ public class Survey extends AbstractPersistableCustom { this.countryCode = countryCode; } - public Date getValidFrom() { + public LocalDate getValidFrom() { return validFrom; } - public void setValidFrom(Date validFrom) { + public void setValidFrom(LocalDate validFrom) { this.validFrom = validFrom; } - public Date getValidTo() { + public LocalDate getValidTo() { return validTo; } - public void setValidTo(Date validTo) { + public void setValidTo(LocalDate validTo) { this.validTo = validTo; } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/domain/SurveyRepository.java b/fineract-provider/src/main/java/org/apache/fineract/spm/domain/SurveyRepository.java index e834d1821..75e145d5a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/domain/SurveyRepository.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/domain/SurveyRepository.java @@ -18,7 +18,7 @@ */ package org.apache.fineract.spm.domain; -import java.util.Date; +import java.time.LocalDateTime; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -27,11 +27,11 @@ import org.springframework.data.repository.query.Param; public interface SurveyRepository extends JpaRepository { @Query("select s from Survey s where :pointInTime between s.validFrom and s.validTo") - List fetchActiveSurveys(@Param("pointInTime") Date pointInTime); + List fetchActiveSurveys(@Param("pointInTime") LocalDateTime pointInTime); @Query("select s from Survey s ") List fetchAllSurveys(); @Query("select s from Survey s where s.key = :key and :pointInTime between s.validFrom and s.validTo") - Survey findByKey(@Param("key") String key, @Param("pointInTime") Date pointInTime); + Survey findByKey(@Param("key") String key, @Param("pointInTime") LocalDateTime pointInTime); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardReadPlatformServiceImpl.java index 5589f0c86..7c498717f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardReadPlatformServiceImpl.java @@ -20,10 +20,8 @@ package org.apache.fineract.spm.service; import java.sql.ResultSet; import java.sql.SQLException; -import java.time.LocalDate; -import java.time.ZoneId; +import java.time.LocalDateTime; import java.util.Collection; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; @@ -91,11 +89,10 @@ public class ScorecardReadPlatformServiceImpl implements ScorecardReadPlatformSe final Long questionId = rs.getLong("questionId"); final Long responseId = rs.getLong("responseId"); - final LocalDate createdOn = JdbcSupport.getLocalDate(rs, "createdOn"); + final LocalDateTime createdOn = JdbcSupport.getLocalDateTime(rs, "createdOn"); final Integer value = rs.getInt("value"); - return ScorecardValue.instance(questionId, responseId, value, - Date.from(createdOn.atStartOfDay(ZoneId.systemDefault()).toInstant())); + return ScorecardValue.instance(questionId, responseId, value, createdOn); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java b/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java index 1402b10cd..8fe2a5d05 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java @@ -19,12 +19,6 @@ package org.apache.fineract.spm.service; import java.time.LocalDate; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.temporal.ChronoField; -import java.time.temporal.ChronoUnit; -import java.util.Calendar; -import java.util.Date; import java.util.List; import javax.persistence.EntityExistsException; import javax.persistence.PersistenceException; @@ -59,7 +53,7 @@ public class SpmService { public List fetchValidSurveys() { this.securityContext.authenticatedUser(); - return this.surveyRepository.fetchActiveSurveys(new Date()); + return this.surveyRepository.fetchActiveSurveys(DateUtils.getLocalDateTimeOfSystem()); } public List fetchAllSurveys() { @@ -76,19 +70,15 @@ public class SpmService { public Survey createSurvey(final Survey survey) { this.securityContext.authenticatedUser(); this.surveyValidator.validate(survey); - final Survey previousSurvey = this.surveyRepository.findByKey(survey.getKey(), new Date()); + final Survey previousSurvey = this.surveyRepository.findByKey(survey.getKey(), DateUtils.getLocalDateTimeOfSystem()); if (previousSurvey != null) { this.deactivateSurvey(previousSurvey.getId()); } // set valid from to start of today - LocalDate validFrom = DateUtils.getBusinessLocalDate(); - // set valid to for 100 years - Calendar cal = Calendar.getInstance(); - cal.setTime(Date.from(validFrom.atStartOfDay(ZoneId.systemDefault()).toInstant())); - cal.add(Calendar.YEAR, 100); - survey.setValidFrom(Date.from(validFrom.atStartOfDay(ZoneId.systemDefault()).toInstant())); - survey.setValidTo(cal.getTime()); + LocalDate validFrom = getStartOfToday(); + survey.setValidFrom(validFrom); + survey.setValidTo(validFrom.plusYears(100)); try { this.surveyRepository.saveAndFlush(survey); } catch (final EntityExistsException dve) { @@ -123,8 +113,8 @@ public class SpmService { this.securityContext.authenticatedUser(); final Survey survey = findById(id); - final ZonedDateTime dateTime = getStartOfToday().minus(1, ChronoUnit.MILLIS); - survey.setValidTo(Date.from(dateTime.toInstant())); + final LocalDate dateTime = getStartOfToday().minusDays(1); + survey.setValidTo(dateTime); this.surveyRepository.saveAndFlush(survey); } @@ -133,19 +123,15 @@ public class SpmService { this.securityContext.authenticatedUser(); final Survey survey = findById(id); - LocalDate validFrom = DateUtils.getBusinessLocalDate(); - Calendar cal = Calendar.getInstance(); - cal.setTime(Date.from(validFrom.atStartOfDay(ZoneId.systemDefault()).toInstant())); - cal.add(Calendar.YEAR, 100); - survey.setValidFrom(Date.from(validFrom.atStartOfDay(ZoneId.systemDefault()).toInstant())); - survey.setValidTo(cal.getTime()); + LocalDate validFrom = getStartOfToday(); + survey.setValidFrom(validFrom); + survey.setValidTo(validFrom.plusYears(100)); this.surveyRepository.saveAndFlush(survey); } - public static ZonedDateTime getStartOfToday() { - return ZonedDateTime.now(DateUtils.getDateTimeZoneOfTenant()).withHour(0).withMinute(0).withSecond(0) - .with(ChronoField.MILLI_OF_SECOND, 0); + public static LocalDate getStartOfToday() { + return DateUtils.getLocalDateOfTenant(); } private void handleDataIntegrityIssues(final Throwable realCause, final Exception dve, String key) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/util/ScorecardMapper.java b/fineract-provider/src/main/java/org/apache/fineract/spm/util/ScorecardMapper.java index 111a5ddb2..2e229c77d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/util/ScorecardMapper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/util/ScorecardMapper.java @@ -18,9 +18,7 @@ */ package org.apache.fineract.spm.util; -import java.time.ZoneId; import java.util.ArrayList; -import java.util.Date; import java.util.List; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.portfolio.client.domain.Client; @@ -52,7 +50,7 @@ public final class ScorecardMapper { ScorecardMapper.setQuestionAndResponse(scorecardValue, scorecard, survey); scorecard.setAppUser(appUser); scorecard.setClient(client); - scorecard.setCreatedOn(Date.from(DateUtils.getBusinessLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); + scorecard.setCreatedOn(DateUtils.getLocalDateTimeOfTenant()); scorecard.setValue(scorecardValue.getValue()); } } else { diff --git a/fineract-provider/src/main/java/org/apache/fineract/template/domain/TemplateFunctions.java b/fineract-provider/src/main/java/org/apache/fineract/template/domain/TemplateFunctions.java index 5a37bac4c..0c5ebf65d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/template/domain/TemplateFunctions.java +++ b/fineract-provider/src/main/java/org/apache/fineract/template/domain/TemplateFunctions.java @@ -18,16 +18,17 @@ */ package org.apache.fineract.template.domain; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import org.apache.fineract.infrastructure.core.service.DateUtils; @SuppressWarnings({ "HideUtilityClassConstructor" }) public class TemplateFunctions { public static String now() { - final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm"); - final Date date = new Date(); + final DateTimeFormatter dateFormat = new DateTimeFormatterBuilder().appendPattern("yyyy/MM/dd HH:mm").toFormatter(); + final LocalDateTime date = DateUtils.getLocalDateTimeOfSystem(); return dateFormat.format(date); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/AppUser.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/AppUser.java index 7f31e9ca2..9f298f5cd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/AppUser.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/AppUser.java @@ -18,10 +18,10 @@ */ package org.apache.fineract.useradministration.domain; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -37,8 +37,6 @@ import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -110,8 +108,7 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser { private Set roles; @Column(name = "last_time_password_updated") - @Temporal(TemporalType.DATE) - private Date lastTimePasswordUpdated; + private LocalDate lastTimePasswordUpdated; @Column(name = "password_never_expires", nullable = false) private boolean passwordNeverExpires; @@ -185,7 +182,7 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser { this.enabled = user.isEnabled(); this.roles = roles; this.firstTimeLoginRemaining = true; - this.lastTimePasswordUpdated = DateUtils.getDateOfTenant(); + this.lastTimePasswordUpdated = DateUtils.getLocalDateOfTenant(); this.staff = staff; this.passwordNeverExpires = passwordNeverExpire; this.isSelfServiceUser = isSelfServiceUser; @@ -208,7 +205,7 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser { this.password = encodePassword; this.firstTimeLoginRemaining = false; - this.lastTimePasswordUpdated = DateUtils.getDateOfTenant(); + this.lastTimePasswordUpdated = DateUtils.getBusinessLocalDate(); } @@ -468,7 +465,7 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser { return this.passwordNeverExpires; } - public Date getLastTimePasswordUpdated() { + public LocalDate getLastTimePasswordUpdated() { return this.lastTimePasswordUpdated; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/AppUserPreviousPassword.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/AppUserPreviousPassword.java index 661cbe9c2..3b96c6155 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/AppUserPreviousPassword.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/AppUserPreviousPassword.java @@ -18,12 +18,10 @@ */ package org.apache.fineract.useradministration.domain; -import java.util.Date; +import java.time.LocalDate; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.service.DateUtils; @@ -35,8 +33,7 @@ public class AppUserPreviousPassword extends AbstractPersistableCustom { private Long userId; @Column(name = "removal_date") - @Temporal(TemporalType.DATE) - private Date removalDate; + private LocalDate removalDate; @Column(name = "password", nullable = false) private String password; @@ -48,7 +45,7 @@ public class AppUserPreviousPassword extends AbstractPersistableCustom { public AppUserPreviousPassword(final AppUser user) { this.userId = user.getId(); this.password = user.getPassword().trim(); - this.removalDate = DateUtils.getDateOfTenant(); + this.removalDate = DateUtils.getLocalDateOfTenant(); } public String getPassword() { diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0019_refactor_loan_transaction.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0019_refactor_loan_transaction.xml index 0d6bb0992..c19c3e2b8 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0019_refactor_loan_transaction.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0019_refactor_loan_transaction.xml @@ -22,11 +22,11 @@ - + - - + + diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/AccountingScenarioIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/AccountingScenarioIntegrationTest.java index 62927af04..a0ae3bf2d 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/AccountingScenarioIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/AccountingScenarioIntegrationTest.java @@ -39,12 +39,10 @@ import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Calendar; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.TimeZone; -import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.CollateralManagementHelper; import org.apache.fineract.integrationtests.common.CommonConstants; @@ -1118,9 +1116,8 @@ public class AccountingScenarioIntegrationTest { return this.loanTransactionHelper.getLoanProductId(loanProductJSON); } - private LocalDate getDateAsLocalDate(String dateAsString) throws ParseException { - final Date dateParsed = DateUtils.parseDate(dateAsString, "dd MMMM yyyy", null); - return DateUtils.convertToLocalDate(dateParsed, this.systemTimeZone.toZoneId()); + private LocalDate getDateAsLocalDate(String dateAsString) { + return LocalDate.parse(dateAsString, Utils.dateFormatter); } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTest.java index c2022024f..e10527716 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTest.java @@ -44,10 +44,10 @@ import org.junit.jupiter.api.Test; @Order(1) public class SchedulerJobsTest { + private final Map originalJobStatus = new HashMap<>(); private RequestSpecification requestSpec; private SchedulerJobHelper schedulerJobHelper; private Boolean originalSchedulerStatus; - private final Map originalJobStatus = new HashMap<>(); @BeforeEach public void setup() { @@ -138,10 +138,13 @@ public class SchedulerJobsTest { @Test public void testTriggeringManualExecutionOfAllSchedulerJobs() { ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); - GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE); - for (String jobName : schedulerJobHelper.getAllSchedulerJobNames()) { - schedulerJobHelper.executeAndAwaitJob(jobName); + try { + GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE); + for (String jobName : schedulerJobHelper.getAllSchedulerJobNames()) { + schedulerJobHelper.executeAndAwaitJob(jobName); + } + } finally { + GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE); } - GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE); } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java index c90d3f803..0003d1d76 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java @@ -26,14 +26,11 @@ import io.restassured.path.json.JsonPath; import io.restassured.specification.RequestSpecification; import io.restassured.specification.ResponseSpecification; import java.math.BigDecimal; -import java.text.DateFormat; import java.text.ParseException; -import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; import org.apache.fineract.integrationtests.common.accounting.Account; import org.apache.fineract.integrationtests.common.accounting.AccountHelper; @@ -256,14 +253,10 @@ public class ProvisioningIntegrationTest { boolean provisioningetryAlreadyCreated = false; if (pageItems != null) { for (Map item : pageItems) { - String date = (String) item.get("createdDate"); - DateFormat formatter = new SimpleDateFormat("MMM dd, yyyy"); - Date date1 = formatter.parse(date); - DateFormat simple = new SimpleDateFormat("dd MMMM yyyy", Locale.US); - String formattedString = simple - .format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(Utils.getZoneIdOfTenant()).toInstant())); - Date currentDate = simple.parse(formattedString); - if (date1.getTime() == currentDate.getTime()) { + List date = (ArrayList) item.get("createdDate"); + LocalDate localDate = LocalDate.of(date.get(0), date.get(1), date.get(2)); + + if (localDate.equals(Utils.getLocalDateOfTenant())) { provisioningetryAlreadyCreated = true; break; }