Skip to content

Commit 5480a97

Browse files
committed
FINERACT-2436: Fix PostgreSQL compatibility for Client Weekly and Monthly Trends Reports with test
1 parent 2047553 commit 5480a97

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,7 @@
233233
<include file="parts/0212_add_force_password_reset_config.xml" relativeToChangelogFile="true" />
234234
<include file="parts/0213_transaction_summary_adding_originators.xml" relativeToChangelogFile="true" />
235235
<include file="parts/0214_trial_balance_summary_adding_originators.xml" relativeToChangelogFile="true" />
236+
<include file="parts/0215_transaction_summary_reports_add_buydown_fee_types.xml" relativeToChangelogFile="true" />
237+
<include file="parts/0216_add_unique_constraint_sms_campaign_name.xml" relativeToChangelogFile="true" />
238+
<include file="parts/0217_postgresql_client_trends_reports.xml" relativeToChangelogFile="true" />
236239
</databaseChangeLog>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">
25+
26+
<changeSet author="fineract" id="postgresql-client-trends-week-fix" context="postgresql">
27+
<update tableName="stretchy_report">
28+
<column name="report_sql" value="SELECT COUNT(cl.id) AS count, EXTRACT(WEEK FROM cl.activation_date) AS Weeks
29+
FROM m_office o LEFT JOIN m_client cl ON o.id = cl.office_id
30+
WHERE o.hierarchy LIKE CONCAT((SELECT ino.hierarchy FROM m_office ino WHERE ino.id = ${officeId}), '%')
31+
AND (cl.activation_date BETWEEN (CURRENT_DATE - INTERVAL '12 weeks') AND CURRENT_DATE)
32+
GROUP BY EXTRACT(WEEK FROM cl.activation_date)
33+
ORDER BY Weeks ASC"/>
34+
<where>report_name = 'ClientTrendsByWeek'</where>
35+
</update>
36+
</changeSet>
37+
38+
<changeSet author="fineract" id="postgresql-client-trends-month-fix" context="postgresql">
39+
<update tableName="stretchy_report">
40+
<column name="report_sql" value="SELECT COUNT(cl.id) AS count, TRIM(TO_CHAR(cl.activation_date, 'Month')) AS Months
41+
FROM m_office o LEFT JOIN m_client cl ON o.id = cl.office_id
42+
WHERE o.hierarchy LIKE CONCAT((SELECT ino.hierarchy FROM m_office ino WHERE ino.id = ${officeId}), '%')
43+
AND (cl.activation_date BETWEEN (CURRENT_DATE - INTERVAL '12 months') AND CURRENT_DATE)
44+
GROUP BY TRIM(TO_CHAR(cl.activation_date, 'Month')), EXTRACT(MONTH FROM cl.activation_date)
45+
ORDER BY EXTRACT(MONTH FROM cl.activation_date) ASC"/>
46+
<where>report_name = 'ClientTrendsByMonth'</where>
47+
</update>
48+
</changeSet>
49+
</databaseChangeLog>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">
25+
26+
<changeSet author="fineract" id="postgresql-client-trends-week-fix" context="postgresql">
27+
<update tableName="stretchy_report">
28+
<column name="report_sql" value="SELECT COUNT(cl.id) AS count, EXTRACT(WEEK FROM cl.activation_date) AS Weeks
29+
FROM m_office o LEFT JOIN m_client cl ON o.id = cl.office_id
30+
WHERE o.hierarchy LIKE CONCAT((SELECT ino.hierarchy FROM m_office ino WHERE ino.id = ${officeId}), '%')
31+
AND (cl.activation_date BETWEEN (CURRENT_DATE - INTERVAL '12 weeks') AND CURRENT_DATE)
32+
GROUP BY EXTRACT(WEEK FROM cl.activation_date)
33+
ORDER BY Weeks ASC"/>
34+
<where>report_name = 'ClientTrendsByWeek'</where>
35+
</update>
36+
</changeSet>
37+
38+
<changeSet author="fineract" id="postgresql-client-trends-month-fix" context="postgresql">
39+
<update tableName="stretchy_report">
40+
<column name="report_sql" value="SELECT COUNT(cl.id) AS count, TRIM(TO_CHAR(cl.activation_date, 'Month')) AS Months
41+
FROM m_office o LEFT JOIN m_client cl ON o.id = cl.office_id
42+
WHERE o.hierarchy LIKE CONCAT((SELECT ino.hierarchy FROM m_office ino WHERE ino.id = ${officeId}), '%')
43+
AND (cl.activation_date BETWEEN (CURRENT_DATE - INTERVAL '12 months') AND CURRENT_DATE)
44+
GROUP BY TRIM(TO_CHAR(cl.activation_date, 'Month')), EXTRACT(MONTH FROM cl.activation_date)
45+
ORDER BY EXTRACT(MONTH FROM cl.activation_date) ASC"/>
46+
<where>report_name = 'ClientTrendsByMonth'</where>
47+
</update>
48+
</changeSet>
49+
</databaseChangeLog>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.integrationtests;
20+
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
23+
import java.io.IOException;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
import org.apache.fineract.integrationtests.common.FineractClientHelper;
27+
import org.apache.fineract.integrationtests.common.Utils;
28+
import org.apache.fineract.integrationtests.common.report.ReportHelper;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
31+
32+
public class ClientTrendsPostgresTest {
33+
34+
private ReportHelper reportHelper;
35+
36+
@BeforeEach
37+
public void setup() {
38+
Utils.initializeRESTAssured();
39+
this.reportHelper = new ReportHelper(Utils.getRequestSpecification(), Utils.getResponseSpecification());
40+
}
41+
42+
@Test
43+
public void testClientTrendsReportsPostgresSyntax() throws IOException {
44+
Map<String, String> reportParameters = new HashMap<>();
45+
reportParameters.put("officeId", "1");
46+
47+
var reportsRunApi = FineractClientHelper.getFineractClient().reportsRun;
48+
49+
assertTrue(reportsRunApi.runReportGetFile("ClientTrendsByWeek", reportParameters, false).execute().isSuccessful(),
50+
"Postgres Weekly Report SQL syntax is invalid!");
51+
52+
assertTrue(reportsRunApi.runReportGetFile("ClientTrendsByMonth", reportParameters, false).execute().isSuccessful(),
53+
"Postgres Monthly Report SQL syntax is invalid!");
54+
}
55+
}

0 commit comments

Comments
 (0)