package authoringtool.persistence.changelog.java; import authoringtool.common.helpers.ValidationHelper; import authoringtool.persistence.encryption.StringEncryptor; import persistence.dao.EntityManagerHolder; import javax.persistence.EntityManager; import javax.persistence.Query; import java.util.List; public class EncryptAuditTrails extends CustomLiquibaseTask { public static final String SELECT_QUERY = "SELECT uuid, " + "email, " + "new_value as newValue, " + "old_value as oldValue, " + "table_changed as table, " + "column_changed as column, " + "browser_name as browser, " + "computer_name as computer, " + "patient_name as patient, " + "systemip as systemIp, " + "user_id as username " + "FROM audit_trails"; public static final String UPDATE_QUERY = "UPDATE audit_trails SET " + "email = :email, " + "new_value = :newValue, " + "old_value = :oldValue, " + "table_changed = :table, " + "column_changed = :column, " + "browser_name = :browser, " + "computer_name = :computer, " + "patient_name = :patient, " + "systemip = :systemIp, " + "user_id = :username " + "WHERE uuid = CAST(:uuid AS uuid)"; @Override protected void executeInternal() { EntityManager em = EntityManagerHolder.getCurrentEntityManager(); List results = em.createNativeQuery(SELECT_QUERY, "AuditTrailsTuple").getResultList(); Query updateQuery = em.createNativeQuery(UPDATE_QUERY); if (!ValidationHelper.isNullOrEmpty(results)) { for (AuditTrailsTuple tuple : results) { updateQuery.setParameter("uuid", tuple.getUuid()); updateQuery.setParameter("email", StringEncryptor.getInstance().encrypt(tuple.getEmail())); updateQuery.setParameter("newValue", StringEncryptor.getInstance().encrypt(tuple.getNewValue())); updateQuery.setParameter("oldValue", StringEncryptor.getInstance().encrypt(tuple.getOldValue())); updateQuery.setParameter("table", StringEncryptor.getInstance().encrypt(tuple.getTable())); updateQuery.setParameter("column", StringEncryptor.getInstance().encrypt(tuple.getColumn())); updateQuery.setParameter("browser", StringEncryptor.getInstance().encrypt(tuple.getBrowser())); updateQuery.setParameter("computer", StringEncryptor.getInstance().encrypt(tuple.getComputer())); updateQuery.setParameter("patient", StringEncryptor.getInstance().encrypt(tuple.getPatient())); updateQuery.setParameter("systemIp", StringEncryptor.getInstance().encrypt(tuple.getSystemIp())); updateQuery.setParameter("username", StringEncryptor.getInstance().encrypt(tuple.getUsername())); updateQuery.executeUpdate(); } } } }