-
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.
[DUOS-2196][risk=low] Initial Acknowledgement Service implementation. (…
…#1813) * Initial Acknowledgement Service implementation.
- Loading branch information
1 parent
c25b633
commit cca5793
Showing
21 changed files
with
816 additions
and
120 deletions.
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
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
34 changes: 34 additions & 0 deletions
34
src/main/java/org/broadinstitute/consent/http/db/AcknowledgementDAO.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,34 @@ | ||
package org.broadinstitute.consent.http.db; | ||
|
||
import org.broadinstitute.consent.http.db.mapper.AcknowledgementMapper; | ||
import org.broadinstitute.consent.http.models.Acknowledgement; | ||
import org.jdbi.v3.sqlobject.config.RegisterRowMapper; | ||
import org.jdbi.v3.sqlobject.customizer.Bind; | ||
import org.jdbi.v3.sqlobject.customizer.BindList; | ||
import org.jdbi.v3.sqlobject.statement.SqlQuery; | ||
import org.jdbi.v3.sqlobject.statement.SqlUpdate; | ||
import org.jdbi.v3.sqlobject.transaction.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@RegisterRowMapper(AcknowledgementMapper.class) | ||
public interface AcknowledgementDAO extends Transactional<AcknowledgementDAO> { | ||
|
||
@SqlUpdate("INSERT INTO acknowledgement (ack_key, user_id, first_acknowledged, last_acknowledged) " | ||
+ " VALUES (:key, :userId, current_timestamp, current_timestamp) " | ||
+ " ON CONFLICT (ack_key, user_id) DO UPDATE SET last_acknowledged = current_timestamp ") | ||
void upsertAcknowledgement(@Bind("key") String key, @Bind("userId") Integer userId); | ||
|
||
@SqlQuery("SELECT ack_key, user_id, first_acknowledged, last_acknowledged " | ||
+ " FROM acknowledgement WHERE ack_key = :key and user_id = :userId") | ||
Acknowledgement findAcknowledgementsByKeyForUser(@Bind("key") String key, @Bind("userId") Integer userId); | ||
|
||
@SqlQuery("SELECT ack_key, user_id, first_acknowledged, last_acknowledged " | ||
+ " FROM acknowledgement WHERE user_id = :userId") | ||
List<Acknowledgement> findAcknowledgementsForUser(@Bind("userId") Integer userId); | ||
|
||
@SqlQuery("SELECT ack_key, user_id, first_acknowledged, last_acknowledged " | ||
+ " FROM acknowledgement WHERE user_id = :userId and ack_key IN (<key_list>)") | ||
List<Acknowledgement> findAcknowledgementsForUser(@BindList("key_list") List<String> keys, @Bind("userId") Integer userId); | ||
|
||
} |
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
20 changes: 20 additions & 0 deletions
20
src/main/java/org/broadinstitute/consent/http/db/mapper/AcknowledgementMapper.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,20 @@ | ||
package org.broadinstitute.consent.http.db.mapper; | ||
|
||
import org.broadinstitute.consent.http.models.Acknowledgement; | ||
import org.jdbi.v3.core.mapper.RowMapper; | ||
import org.jdbi.v3.core.statement.StatementContext; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class AcknowledgementMapper implements RowMapper<Acknowledgement> { | ||
@Override | ||
public Acknowledgement map(ResultSet rs, StatementContext ctx) throws SQLException { | ||
Acknowledgement ack = new Acknowledgement(); | ||
ack.setAckKey(rs.getString("ack_key")); | ||
ack.setUserId(rs.getInt("user_id")); | ||
ack.setFirstAcknowledged(rs.getTimestamp("first_acknowledged")); | ||
ack.setLastAcknowledged(rs.getTimestamp("last_acknowledged")); | ||
return ack; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/org/broadinstitute/consent/http/models/Acknowledgement.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,54 @@ | ||
package org.broadinstitute.consent.http.models; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.Date; | ||
import java.util.Objects; | ||
|
||
public class Acknowledgement { | ||
|
||
private String ackKey; | ||
private Integer userId; | ||
private Timestamp firstAcknowledged; | ||
private Timestamp lastAcknowledged; | ||
|
||
public Integer getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(Integer userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public Date getFirstAcknowledged() { return firstAcknowledged; } | ||
|
||
public void setFirstAcknowledged(Timestamp firstAcknowledged) { | ||
this.firstAcknowledged = firstAcknowledged; | ||
} | ||
|
||
public Date getLastAcknowledged() { | ||
return lastAcknowledged; | ||
} | ||
|
||
public void setLastAcknowledged(Timestamp lastAcknowledged) { | ||
this.lastAcknowledged = lastAcknowledged; | ||
} | ||
|
||
public String getAckKey() { | ||
return ackKey; | ||
} | ||
|
||
public void setAckKey(String ackKey) { | ||
this.ackKey = ackKey; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Acknowledgement ack = (Acknowledgement) o; | ||
return (Objects.equals(this.getAckKey(), ack.getAckKey()) && | ||
Objects.equals(this.getUserId(), ack.getUserId()) && | ||
this.getLastAcknowledged().getTime() == (ack.getLastAcknowledged().getTime()) && | ||
this.getFirstAcknowledged().getTime() == (ack.getFirstAcknowledged()).getTime()); | ||
} | ||
} |
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
Oops, something went wrong.