-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new audit tables to track changes in DPA and DSAs
- Loading branch information
1 parent
83e20cd
commit ef6ee66
Showing
6 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/org/endeavourhealth/core/database/dal/audit/ServicePublisherAuditDalI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.endeavourhealth.core.database.dal.audit; | ||
|
||
import java.util.UUID; | ||
|
||
public interface ServicePublisherAuditDalI { | ||
|
||
Boolean getLatestDpaState(UUID serviceId) throws Exception; | ||
void saveDpaState(UUID serviceId, boolean hasDpa) throws Exception; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/endeavourhealth/core/database/dal/audit/ServiceSubscriberAuditDalI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.endeavourhealth.core.database.dal.audit; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public interface ServiceSubscriberAuditDalI { | ||
|
||
List<String> getLatestSubscribers(UUID serviceId) throws Exception; | ||
void saveSubscribers(UUID serviceId, List<String> subscriberConfigNames) throws Exception; | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/org/endeavourhealth/core/database/rdbms/audit/RdbmsPublisherAuditDal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.endeavourhealth.core.database.rdbms.audit; | ||
|
||
import org.endeavourhealth.core.database.dal.audit.ServicePublisherAuditDalI; | ||
import org.endeavourhealth.core.database.rdbms.ConnectionManager; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.util.Date; | ||
import java.util.UUID; | ||
|
||
public class RdbmsPublisherAuditDal implements ServicePublisherAuditDalI { | ||
|
||
@Override | ||
public Boolean getLatestDpaState(UUID serviceId) throws Exception { | ||
Connection conn = ConnectionManager.getAuditConnection(); | ||
PreparedStatement ps = null; | ||
try { | ||
String sql = "SELECT has_dpa" | ||
+ " FROM service_publisher_audit" | ||
+ " WHERE service_id = ?" | ||
+ " ORDER BY dt_changed DESC" | ||
+ " LIMIT 1"; | ||
ps = conn.prepareStatement(sql); | ||
|
||
ps.setString(1, serviceId.toString()); | ||
|
||
ResultSet rs = ps.executeQuery(); | ||
if (rs.next()) { | ||
boolean hasDpa = rs.getBoolean(1); | ||
if (rs.wasNull()) { | ||
return null; | ||
} else { | ||
return new Boolean(hasDpa); | ||
} | ||
|
||
} else { | ||
return null; | ||
} | ||
|
||
} finally { | ||
if (ps != null) { | ||
ps.close(); | ||
} | ||
conn.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public void saveDpaState(UUID serviceId, boolean hasDpa) throws Exception { | ||
|
||
Connection conn = ConnectionManager.getAuditConnection(); | ||
PreparedStatement ps = null; | ||
try { | ||
String sql = "INSERT INTO service_publisher_audit" | ||
+ " (service_id, dt_changed, has_dpa)" | ||
+ " VALUES" | ||
+ " (?, ?, ?)"; | ||
ps = conn.prepareStatement(sql); | ||
|
||
ps.setString(1, serviceId.toString()); | ||
ps.setTimestamp(2, new java.sql.Timestamp(new Date().getTime())); | ||
ps.setBoolean(3, hasDpa); | ||
|
||
ps.executeUpdate(); | ||
conn.commit(); | ||
} catch (Exception ex) { | ||
conn.rollback(); | ||
|
||
} finally { | ||
if (ps != null) { | ||
ps.close(); | ||
} | ||
conn.close(); | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...in/java/org/endeavourhealth/core/database/rdbms/audit/RdbmsServiceSubscriberAuditDal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.endeavourhealth.core.database.rdbms.audit; | ||
|
||
import org.endeavourhealth.core.database.dal.audit.ServiceSubscriberAuditDalI; | ||
import org.endeavourhealth.core.database.rdbms.ConnectionManager; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.util.*; | ||
import java.util.regex.Pattern; | ||
|
||
public class RdbmsServiceSubscriberAuditDal implements ServiceSubscriberAuditDalI { | ||
|
||
private static final String DELIM = "|"; | ||
|
||
@Override | ||
public List<String> getLatestSubscribers(UUID serviceId) throws Exception { | ||
Connection conn = ConnectionManager.getAuditConnection(); | ||
PreparedStatement ps = null; | ||
try { | ||
String sql = "SELECT subscriber_config_names" | ||
+ " FROM service_subscriber_audit" | ||
+ " WHERE service_id = ?" | ||
+ " ORDER BY dt_changed DESC" | ||
+ " LIMIT 1"; | ||
ps = conn.prepareStatement(sql); | ||
|
||
ps.setString(1, serviceId.toString()); | ||
|
||
ResultSet rs = ps.executeQuery(); | ||
if (rs.next()) { | ||
String subscriberConfigNames = rs.getString(1); | ||
String[] toks = subscriberConfigNames.split(Pattern.quote(DELIM)); //use the Pattern.quote fn to make it NOT use regex | ||
return Arrays.asList(toks); | ||
|
||
} else { | ||
return null; | ||
} | ||
|
||
} finally { | ||
if (ps != null) { | ||
ps.close(); | ||
} | ||
conn.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public void saveSubscribers(UUID serviceId, List<String> subscriberConfigNames) throws Exception { | ||
|
||
List<String> l = new ArrayList<>(subscriberConfigNames); | ||
//always re-sort so the table is consistent | ||
l.sort((a, b) -> a.compareToIgnoreCase(b)); | ||
String subscriberConfigStr = String.join(DELIM, l); | ||
|
||
Connection conn = ConnectionManager.getAuditConnection(); | ||
PreparedStatement ps = null; | ||
try { | ||
String sql = "INSERT INTO service_subscriber_audit" | ||
+ " (service_id, dt_changed, subscriber_config_names)" | ||
+ " VALUES" | ||
+ " (?, ?, ?)"; | ||
ps = conn.prepareStatement(sql); | ||
|
||
ps.setString(1, serviceId.toString()); | ||
ps.setTimestamp(2, new java.sql.Timestamp(new Date().getTime())); | ||
ps.setString(3, subscriberConfigStr); | ||
|
||
ps.executeUpdate(); | ||
conn.commit(); | ||
} catch (Exception ex) { | ||
conn.rollback(); | ||
|
||
} finally { | ||
if (ps != null) { | ||
ps.close(); | ||
} | ||
conn.close(); | ||
} | ||
} | ||
} |