Skip to content

Commit

Permalink
feat: Store add timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
hangy committed Mar 24, 2024
1 parent 10c4b02 commit 9377817
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.jboss.logging.Logger;
import org.keycloak.Config;
import org.keycloak.common.util.Time;
import org.keycloak.connections.jpa.JpaConnectionProvider;
import org.keycloak.events.Event;
import org.keycloak.events.EventListenerProvider;
Expand Down Expand Up @@ -74,6 +75,8 @@ private void storeDeletedUser(final UserRemovedEvent userRemovedEvent) {
entity.setUserId(user.getId());
entity.setUsername(user.getUsername());
entity.setEmail(user.getEmail());
entity.setCreatedTimestamp(user.getCreatedTimestamp());
entity.setDeletedTimestamp(Time.currentTimeMillis());
userRemovedEvent.getKeycloakSession()
.getProvider(JpaConnectionProvider.class)
.getEntityManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public class DeletedUserEntity {
@Column(name = "EMAIL")
protected String email;

@Column(name = "CREATED_TIMESTAMP")
private Long createdTimestamp;

@Column(name = "DELETED_TIMESTAMP")
private Long deletedTimestamp;

public String getId() {
return id;
}
Expand Down Expand Up @@ -51,6 +57,22 @@ public void setEmail(String email) {
this.email = email;
}

public Long getCreatedTimestamp() {
return createdTimestamp;
}

public void setCreatedTimestamp(Long createdTimestamp) {
this.createdTimestamp = createdTimestamp;
}

public Long getDeletedTimestamp() {
return deletedTimestamp;
}

public void setDeletedTimestamp(Long deletedTimestamp) {
this.deletedTimestamp = deletedTimestamp;
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/deleted-users-changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<constraints nullable="false"/>
</column>
<column name="EMAIL" type="NVARCHAR(255)"/>
<column name="CREATED_TIMESTAMP" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="DELETED_TIMESTAMP" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey columnNames="ID" constraintName="PK_DELETED_USER_ID" tableName="DELETED_USER"/>
</changeSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ void testDeletedUserEntityGettersAndSetters() {
String userId = "456";
String username = "testuser";
String email = "testuser@example.com";
long createdTimestamp = 42;
long deletedTimestamp = 69;

// Act
entity.setId(id);
entity.setUserId(userId);
entity.setUsername(username);
entity.setEmail(email);
entity.setCreatedTimestamp(createdTimestamp);
entity.setDeletedTimestamp(deletedTimestamp);

// Assert
Assertions.assertEquals(id, entity.getId());
Assertions.assertEquals(userId, entity.getUserId());
Assertions.assertEquals(username, entity.getUsername());
Assertions.assertEquals(email, entity.getEmail());
Assertions.assertEquals(createdTimestamp, entity.getCreatedTimestamp());
Assertions.assertEquals(deletedTimestamp, entity.getDeletedTimestamp());
}

@Test
Expand Down

0 comments on commit 9377817

Please sign in to comment.