Skip to content

Commit e547969

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

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,5 @@
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_postgresql_client_trends_reports.xml" relativeToChangelogFile="true" />
236237
</databaseChangeLog>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
<!-- ClientTrendsByWeek -->
27+
<changeSet author="fineract" id="postgresql-client-trends-week" context="postgresql">
28+
<update tableName="stretchy_report">
29+
<column name="report_sql" value="SELECT COUNT(cl.id) AS count, EXTRACT(WEEK FROM cl.activation_date) AS Weeks
30+
FROM m_office o LEFT JOIN m_client cl on o.id = cl.office_id
31+
WHERE o.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),'%' )
32+
AND (cl.activation_date BETWEEN (CURRENT_DATE - INTERVAL '12 weeks') AND CURRENT_DATE)
33+
GROUP BY Weeks"/>
34+
<where>report_name = 'ClientTrendsByWeek'</where>
35+
</update>
36+
</changeSet>
37+
38+
<!-- ClientTrendsByMonth -->
39+
<changeSet author="fineract" id="postgresql-client-trends-month" context="postgresql">
40+
<update tableName="stretchy_report">
41+
<column name="report_sql" value="SELECT COUNT(cl.id) AS count, TO_CHAR(cl.activation_date, 'Month') AS Months
42+
FROM m_office o LEFT JOIN m_client cl on o.id = cl.office_id
43+
WHERE o.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),'%' )
44+
AND (cl.activation_date BETWEEN (CURRENT_DATE - INTERVAL '12 months') AND CURRENT_DATE)
45+
GROUP BY Months"/>
46+
<where>report_name = 'ClientTrendsByMonth'</where>
47+
</update>
48+
</changeSet>
49+
50+
</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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
27+
import org.apache.fineract.integrationtests.common.FineractClientHelper;
28+
import org.apache.fineract.integrationtests.common.Utils;
29+
import org.apache.fineract.integrationtests.common.report.ReportHelper;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
32+
33+
public class ClientTrendsPostgresTest {
34+
35+
private ReportHelper reportHelper;
36+
37+
@BeforeEach
38+
public void setup() {
39+
Utils.initializeRESTAssured();
40+
this.reportHelper = new ReportHelper(Utils.getRequestSpecification(), Utils.getResponseSpecification());
41+
}
42+
43+
@Test
44+
public void testClientTrendsReportsPostgresSyntax() throws IOException {
45+
Map<String, String> reportParameters = new HashMap<>();
46+
reportParameters.put("officeId", "1");
47+
48+
var reportsRunApi = FineractClientHelper.getFineractClient().reportsRun;
49+
50+
assertTrue(reportsRunApi.runReportGetFile("ClientTrendsByWeek", reportParameters, false).execute().isSuccessful(),
51+
"Postgres Weekly Report SQL syntax is invalid!");
52+
53+
assertTrue(reportsRunApi.runReportGetFile("ClientTrendsByMonth", reportParameters, false).execute().isSuccessful(),
54+
"Postgres Monthly Report SQL syntax is invalid!");
55+
}
56+
}

0 commit comments

Comments
 (0)