Skip to content

Commit

Permalink
feature: Create dw_event_stats view and remove dw_even and dw_event_p…
Browse files Browse the repository at this point in the history
…ublic
  • Loading branch information
DanielPalafox committed Jan 4, 2024
1 parent a6db989 commit bd56da8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public void createEventStats() {
"INSERT INTO event_stats (event_type, client_id, count, date, date_created, last_modified) " +
"SELECT event_type, client_id, COUNT(id), CAST(e.date_created as date), now(), now() " +
"FROM event as e " +
"WHERE event_type != 'Public-Page' " +
"AND CAST(e.date_created as date) = CAST(now() - (CAST('1' AS INTERVAL DAY) * 1) as date) " +
"WHERE CAST(e.date_created as date) = CAST(now() - (CAST('1' AS INTERVAL DAY) * 1) as date) " +
"GROUP BY event_type, client_id, CAST(e.date_created as date) " +
"ORDER BY CAST(e.date_created as date) DESC;";
Query insertQuery = entityManager.createNativeQuery(query);
Expand Down
1 change: 1 addition & 0 deletions orcid-persistence/src/main/resources/db-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,5 @@
<include file="/db/updates/grant_select_to_dw_user_on_dw_event.xml" />
<include file="/db/updates/identifier-types/update-ol-to-be-case-sensitive.xml" />
<include file="/db/updates/create_event_stats_table.xml" />
<include file="/db/updates/dw_event_stats.xml" />
</databaseChangeLog>
27 changes: 27 additions & 0 deletions orcid-persistence/src/main/resources/db/updates/dw_event_stats.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

<changeSet id="DROP-VIEW-FOR-EVENT" author="Daniel Palafox" dbms="postgresql">
<dropView viewName="dw_event"/>
</changeSet>

<changeSet id="CREATE-DW-EVENT-STATS-VIEW-GROUP-BY-DAY-CLIENT_ID-AND-EVENT_TYPE" author="Daniel Palafox" dbms="postgresql">
<preConditions onFail="MARK_RAN">
<not><viewExists viewName="dw_event_stats"/></not>
</preConditions>
<createView viewName="dw_event_stats">
SELECT event_type, client_id, count, DATE_TRUNC('day', date), DATE_TRUNC('day', date) as last_modified
FROM event_stats
ORDER BY DATE_TRUNC('day', date_created) DESC;
</createView>
</changeSet>

<changeSet id="GRANT-READ-TO-DW_USER-TO-DW_EVENT-STATS-VIEW" author="Daniel Palafox" dbms="postgresql">
<preConditions>
<sqlCheck expectedResult="1">SELECT 1 FROM pg_roles WHERE rolname='dw_user'</sqlCheck>
</preConditions>
<sql>GRANT SELECT ON TABLE dw_event_stats to dw_user;</sql>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.orcid.persistence.dao;

import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.orcid.persistence.jpa.entities.EventEntity;
Expand Down Expand Up @@ -38,6 +37,7 @@ public void createEventStats() {

assertNotNull(eventStatsEntityList);
assertEquals(1, eventStatsEntityList.size());
assertEquals(20, java.util.Optional.ofNullable(eventStatsEntityList.get(0).getCount()));

Check failure on line 40 in orcid-persistence/src/test/java/org/orcid/persistence/dao/EventStatsDaoTest.java

View workflow job for this annotation

GitHub Actions / orcid-persistence Unit Tests

org.orcid.persistence.dao.EventStatsDaoTest ► createEventStats

Failed test found in: TEST-org.orcid.persistence.dao.EventStatsDaoTest.xml Error: java.lang.AssertionError: expected:<20> but was:<Optional[20]>
Raw output
java.lang.AssertionError: expected:<20> but was:<Optional[20]>
	at org.orcid.persistence.dao.EventStatsDaoTest.createEventStats(EventStatsDaoTest.java:40)
}

private void createEvents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<task:scheduled ref="emailMessageSender" method="addWorksToRecordSecondReminder" cron="${org.orcid.scheduler.web.addWorksToRecord.secondReminder:0 20 * * * *}"/>
<task:scheduled ref="emailMessageSender" method="addWorksToRecordThirdReminder" cron="${org.orcid.scheduler.web.addWorksToRecord.thirdReminder:0 30 * * * *}"/>
<task:scheduled ref="eventStats" method="deleteEvents" cron="${org.orcid.scheduler.web.deleteEventsOlderDays:0 10 * * * *}"/>
<task:scheduled ref="eventStats" method="saveEventStats" cron="${org.orcid.scheduler.web.saveEventStats:0 10 * * * *}"/>
<task:scheduled ref="eventStats" method="saveEventStats" cron="${org.orcid.scheduler.web.saveEventStats:30 * * * * *}"/>
</task:scheduled-tasks>

<task:scheduler id="scheduler" pool-size="${org.orcid.scheduler.tasks.pool_size:30}"/>
Expand Down
2 changes: 1 addition & 1 deletion orcid-test/src/main/resources/data/EventEntityData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/>

<event id="3"
event_type="Sign-In"
event_type="Public-Page"
label="Website"
date_created="2023-01-01 15:31:00.00"
/>
Expand Down

0 comments on commit bd56da8

Please sign in to comment.