[ 
https://issues.apache.org/jira/browse/FINERACT-723?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Vishwas Babu A J updated FINERACT-723:
--------------------------------------
    Description: 
Each tenant in Fineract has its timezone configured in the `tenants` table 
under the `fineractplatform-tenants` schema and the application should consider 
the same while carrying out any date/time related operations. This does not 
seem to be done consistently in the application and intermittent errors can be 
seen when the Application (tomcat) and database servers (MySQL) are run on 
systems with different timezones than that of the tenant.

Ex: Set the System timezone to "PDT". The default demo tenant is set to 
"Asia/Kolkata" and integration tests run on the same would fail intermittently.

Fixing the same would involve
 * Ensuring that all dates created in the API / service layers are done in a 
tenant sensitive fashion by utilizing the methods present in the class 
org.apache.fineract.infrastructure.core.service.DateUtils.
 * Ensure database operations do not use MySQL date functions. Ex:

{code:java}
@Override

    public Collection<SavingsAccountAnnualFeeData> 
retrieveChargesWithAnnualFeeDue() {

        final String sql = "select " + this.chargeDueMapper.schema() + " where 
sac.charge_due_date is not null and sac.charge_time_enum = ? "

                + " and sac.charge_due_date <= NOW() and sa.status_enum = ? ";




        return this.jdbcTemplate.query(sql, this.chargeDueMapper, new Object[] 
{ChargeTimeType.ANNUAL_FEE.getValue(), 
SavingsAccountStatusType.ACTIVE.getValue()});

    }{code}
 in
org.apache.fineract.portfolio.savings.service.SavingsAccountChargeReadPlatformServiceImpl
 would cause issues with Timezones. We should be using something along the 
lines of
{code:java}
@Override
        public Collection<SavingsAccountAnnualFeeData> 
retrieveChargesWithAnnualFeeDue() {
        String currentdate = formatter.print(DateUtils.getLocalDateOfTenant());
        final String sql = "select " + this.chargeDueMapper.schema() + " where 
sac.charge_due_date is not null and sac.charge_time_enum = ? and 
sac.charge_due_date <= ? and sa.status_enum ? ";
        
        return this.jdbcTemplate.query(sql, this.chargeDueMapper, new Object[] 
{currentdate, ChargeTimeType.ANNUAL_FEE.getValue(), 
SavingsAccountStatusType.ACTIVE.getValue()});
        }{code}
 

 

 

  was:
Each tenant in Fineract has its timezone configured in the `tenants` table 
under the `fineractplatform-tenants` schema and the application should consider 
the same while carrying out any date/time related operations. This does not 
seem to be done consistently in the application and intermittent errors can be 
seen when the Application (tomcat) and database servers (MySQL) are run on 
systems with different timezones than that of the tenant.

Ex: Set the System timezone to "PDT". The default demo tenant is set to 
"Asia/Kolkata" and integration tests run on the same would fail intermittently.

Fixing the same would involve
 * Ensuring that all dates created in the API / service layers are done in a 
tenant sensitive fashion by utilizing the methods present in the class 
org.apache.fineract.infrastructure.core.service.DateUtils.
 * Ensure database operations do not use MySQL date functions. Ex:

{code:java}
@Override

    public Collection<SavingsAccountAnnualFeeData> 
retrieveChargesWithAnnualFeeDue() {

        final String sql = "select " + this.chargeDueMapper.schema() + " where 
sac.charge_due_date is not null and sac.charge_time_enum = ? "

                + " and sac.charge_due_date <= NOW() and sa.status_enum = ? ";




        return this.jdbcTemplate.query(sql, this.chargeDueMapper, new Object[] 
{ChargeTimeType.ANNUAL_FEE.getValue(), 
SavingsAccountStatusType.ACTIVE.getValue()});

    }{code}
 in
org.apache.fineract.portfolio.savings.service.SavingsAccountChargeReadPlatformServiceImpl
 would cause issues with Timezones. We should be using something along the 
lines of
{code:java}
@Override
        public Collection<SavingsAccountAnnualFeeData> 
retrieveChargesWithAnnualFeeDue() {
        String currentdate = formatter.print(DateUtils.getLocalDateOfTenant());
        final String sql = "select " + this.chargeDueMapper.schema() + " where 
sac.charge_due_date is not null and sac.charge_time_enum = "
        + ChargeTimeType.ANNUAL_FEE.getValue() + " and sac.charge_due_date <= ? 
and sa.status_enum = "
        + SavingsAccountStatusType.ACTIVE.getValue();
        
        return this.jdbcTemplate.query(sql, this.chargeDueMapper, new Object[] 
{currentdate});
        }{code}
 

 

 


> Integration tests fail when the default tenant has a different time-zone than 
> the system(s) running the application and database servers
> ----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: FINERACT-723
>                 URL: https://issues.apache.org/jira/browse/FINERACT-723
>             Project: Apache Fineract
>          Issue Type: Bug
>    Affects Versions: 1.1.0, 1.2.0, 1.3.0
>            Reporter: Vishwas Babu A J
>            Priority: Major
>              Labels: gsoc2019
>
> Each tenant in Fineract has its timezone configured in the `tenants` table 
> under the `fineractplatform-tenants` schema and the application should 
> consider the same while carrying out any date/time related operations. This 
> does not seem to be done consistently in the application and intermittent 
> errors can be seen when the Application (tomcat) and database servers (MySQL) 
> are run on systems with different timezones than that of the tenant.
> Ex: Set the System timezone to "PDT". The default demo tenant is set to 
> "Asia/Kolkata" and integration tests run on the same would fail 
> intermittently.
> Fixing the same would involve
>  * Ensuring that all dates created in the API / service layers are done in a 
> tenant sensitive fashion by utilizing the methods present in the class 
> org.apache.fineract.infrastructure.core.service.DateUtils.
>  * Ensure database operations do not use MySQL date functions. Ex:
> {code:java}
> @Override
>     public Collection<SavingsAccountAnnualFeeData> 
> retrieveChargesWithAnnualFeeDue() {
>         final String sql = "select " + this.chargeDueMapper.schema() + " 
> where sac.charge_due_date is not null and sac.charge_time_enum = ? "
>                 + " and sac.charge_due_date <= NOW() and sa.status_enum = ? ";
>         return this.jdbcTemplate.query(sql, this.chargeDueMapper, new 
> Object[] {ChargeTimeType.ANNUAL_FEE.getValue(), 
> SavingsAccountStatusType.ACTIVE.getValue()});
>     }{code}
>  in
> org.apache.fineract.portfolio.savings.service.SavingsAccountChargeReadPlatformServiceImpl
>  would cause issues with Timezones. We should be using something along the 
> lines of
> {code:java}
> @Override
>       public Collection<SavingsAccountAnnualFeeData> 
> retrieveChargesWithAnnualFeeDue() {
>       String currentdate = formatter.print(DateUtils.getLocalDateOfTenant());
>       final String sql = "select " + this.chargeDueMapper.schema() + " where 
> sac.charge_due_date is not null and sac.charge_time_enum = ? and 
> sac.charge_due_date <= ? and sa.status_enum ? ";
>       
>       return this.jdbcTemplate.query(sql, this.chargeDueMapper, new Object[] 
> {currentdate, ChargeTimeType.ANNUAL_FEE.getValue(), 
> SavingsAccountStatusType.ACTIVE.getValue()});
>       }{code}
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to