-
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.
Browse files
Browse the repository at this point in the history
* DST-16098 : Domain Event when username is changed * Fix for failing tests * DST-16098 Feedback * DST-16098 Feedback * Failing test fix
- Loading branch information
1 parent
e5d33fa
commit 4eca260
Showing
9 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/uk/co/bconline/ndelius/model/entity/DomainEventEntity.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,44 @@ | ||
package uk.co.bconline.ndelius.model.entity; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Entity | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "DOMAIN_EVENT") | ||
public class DomainEventEntity | ||
{ | ||
@Id | ||
@Column(name = "DOMAIN_EVENT_ID") | ||
@SequenceGenerator(name = "DOMAIN_EVENT_ID_SEQ", sequenceName = "DOMAIN_EVENT_ID_SEQ", allocationSize = 1) | ||
@GeneratedValue(generator = "DOMAIN_EVENT_ID_SEQ") | ||
private Long id; | ||
|
||
@Column(name = "MESSAGE_BODY") | ||
@Lob | ||
private String messageBody; | ||
|
||
@Column(name = "MESSAGE_ATTRIBUTES") | ||
private String messageAttributes; | ||
|
||
@ManyToOne() | ||
@JoinColumn(name = "DOMAIN_EVENT_TYPE_ID", insertable = false, updatable = false) | ||
private ReferenceDataEntity domainEventType; | ||
|
||
@Column(name = "DOMAIN_EVENT_TYPE_ID") | ||
private Long domainEventTypeId; | ||
|
||
@Column(name = "CREATED_DATETIME") | ||
private LocalDateTime createdDateTime; | ||
|
||
@Column(name = "FAILED_PUBLISHING") | ||
private Boolean failedPublishing; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/uk/co/bconline/ndelius/model/notification/HmppsDomainEvent.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,23 @@ | ||
package uk.co.bconline.ndelius.model.notification; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Map; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class HmppsDomainEvent | ||
{ | ||
private String eventType; | ||
private int version; | ||
private String description; | ||
private String occurredAt; | ||
private Map<String, String> additionalInformation; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/uk/co/bconline/ndelius/model/notification/HmppsDomainEventType.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,14 @@ | ||
package uk.co.bconline.ndelius.model.notification; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum HmppsDomainEventType | ||
{ | ||
UMT_USERNAME_CHANGED("probation-user.username.changed", "The username for a probation user has been changed"); | ||
|
||
private final String eventType; | ||
private final String eventDescription; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/uk/co/bconline/ndelius/repository/db/DomainEventRepository.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,8 @@ | ||
package uk.co.bconline.ndelius.repository.db; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import uk.co.bconline.ndelius.model.entity.DomainEventEntity; | ||
|
||
public interface DomainEventRepository extends JpaRepository<DomainEventEntity, Long> | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/uk/co/bconline/ndelius/service/DomainEventService.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 uk.co.bconline.ndelius.service; | ||
|
||
import uk.co.bconline.ndelius.model.notification.HmppsDomainEventType; | ||
|
||
import java.util.Map; | ||
|
||
public interface DomainEventService | ||
{ | ||
void insertDomainEvent(HmppsDomainEventType eventType, Map<String, String> attributes); | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/uk/co/bconline/ndelius/service/impl/DomainEventServiceImpl.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,66 @@ | ||
package uk.co.bconline.ndelius.service.impl; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.SneakyThrows; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import uk.co.bconline.ndelius.model.entity.DomainEventEntity; | ||
import uk.co.bconline.ndelius.model.notification.HmppsDomainEvent; | ||
import uk.co.bconline.ndelius.model.notification.HmppsDomainEventType; | ||
import uk.co.bconline.ndelius.repository.db.DomainEventRepository; | ||
import uk.co.bconline.ndelius.repository.db.ReferenceDataRepository; | ||
import uk.co.bconline.ndelius.service.DomainEventService; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
@Service | ||
public class DomainEventServiceImpl implements DomainEventService | ||
{ | ||
private final ReferenceDataRepository referenceDataRepository; | ||
|
||
private final DomainEventRepository domainEventRepository; | ||
|
||
private final ObjectMapper mapper; | ||
|
||
private static final String DOMAIN_EVENT_TYPE_REF_DATA_CODE_SET = "DOMAIN EVENT TYPE"; | ||
|
||
@Autowired | ||
public DomainEventServiceImpl( | ||
ReferenceDataRepository referenceDataRepository, | ||
DomainEventRepository domainEventRepository, | ||
ObjectMapper mapper) { | ||
this.referenceDataRepository = referenceDataRepository; | ||
this.domainEventRepository = domainEventRepository; | ||
this.mapper = mapper; | ||
} | ||
|
||
@Override | ||
@SneakyThrows | ||
public void insertDomainEvent(HmppsDomainEventType eventType, Map<String, String> additionalInformation) | ||
{ | ||
val type = referenceDataRepository.findByCodeAndReferenceDataMasterCodeSetName(eventType.getEventType(), DOMAIN_EVENT_TYPE_REF_DATA_CODE_SET) | ||
.orElseThrow(() -> new IllegalStateException("Reference data for domain event type " + eventType.getEventType() + " not found")); | ||
val message = HmppsDomainEvent.builder() | ||
.eventType(eventType.getEventType()) | ||
.description(eventType.getEventDescription()) | ||
.occurredAt(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)) | ||
.additionalInformation(additionalInformation) | ||
.version(1) | ||
.build(); | ||
val attributes = Map.of("eventType", Map.of("Type", "String", "Value", eventType.getEventType())); | ||
val entity = DomainEventEntity.builder() | ||
.messageBody(mapper.writeValueAsString(message)) | ||
.messageAttributes(mapper.writeValueAsString(attributes)) | ||
.domainEventTypeId(type.getId()) | ||
.createdDateTime(LocalDateTime.now()) | ||
.build(); | ||
|
||
domainEventRepository.save(entity); | ||
} | ||
} |
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