-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0033a3b
commit e056de3
Showing
12 changed files
with
288 additions
and
33 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
11 changes: 11 additions & 0 deletions
11
domain/src/main/java/br/com/ifsp/tickets/domain/shared/DomainEventType.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,11 @@ | ||
package br.com.ifsp.tickets.domain.shared; | ||
|
||
public enum DomainEventType { | ||
|
||
INFO, | ||
WARNING, | ||
ERROR, | ||
DEBUG, | ||
FATAL | ||
|
||
} |
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
53 changes: 53 additions & 0 deletions
53
domain/src/main/java/br/com/ifsp/tickets/domain/shared/event/ConsumeTicketError.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,53 @@ | ||
package br.com.ifsp.tickets.domain.shared.event; | ||
|
||
import br.com.ifsp.tickets.domain.shared.DomainEventType; | ||
import br.com.ifsp.tickets.domain.shared.IDomainEvent; | ||
import br.com.ifsp.tickets.domain.ticket.Ticket; | ||
|
||
import java.time.Instant; | ||
|
||
public class ConsumeTicketError implements IDomainEvent { | ||
|
||
private final String id; | ||
private final String reason; | ||
|
||
public ConsumeTicketError(Ticket ticket, String reason) { | ||
this.id = ticket.getId().getValue().toString(); | ||
this.reason = reason; | ||
} | ||
|
||
@Override | ||
public Instant occurredOn() { | ||
return Instant.now(); | ||
} | ||
|
||
@Override | ||
public String subject() { | ||
return "ConsumeTicket"; | ||
} | ||
|
||
@Override | ||
public String message() { | ||
return "Ticket could not be consumed"; | ||
} | ||
|
||
@Override | ||
public String source() { | ||
return Ticket.class.getName(); | ||
} | ||
|
||
@Override | ||
public DomainEventType type() { | ||
return DomainEventType.ERROR; | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return this.id; | ||
} | ||
|
||
@Override | ||
public String reason() { | ||
return this.reason; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
domain/src/main/java/br/com/ifsp/tickets/domain/shared/event/ConsumeTicketSuccess.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,51 @@ | ||
package br.com.ifsp.tickets.domain.shared.event; | ||
|
||
import br.com.ifsp.tickets.domain.shared.DomainEventType; | ||
import br.com.ifsp.tickets.domain.shared.IDomainEvent; | ||
import br.com.ifsp.tickets.domain.ticket.Ticket; | ||
|
||
import java.time.Instant; | ||
|
||
public class ConsumeTicketSuccess implements IDomainEvent { | ||
|
||
private final String id; | ||
|
||
public ConsumeTicketSuccess(Ticket ticket) { | ||
this.id = ticket.getId().getValue().toString(); | ||
} | ||
|
||
@Override | ||
public Instant occurredOn() { | ||
return Instant.now(); | ||
} | ||
|
||
@Override | ||
public String subject() { | ||
return "ConsumeTicket"; | ||
} | ||
|
||
@Override | ||
public String message() { | ||
return "Ticket has been consumed"; | ||
} | ||
|
||
@Override | ||
public String reason() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String source() { | ||
return Ticket.class.getName(); | ||
} | ||
|
||
@Override | ||
public DomainEventType type() { | ||
return DomainEventType.INFO; | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return this.id; | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
infrastructure/src/main/java/br/com/ifsp/tickets/infra/shared/event/DomainEventListener.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,36 @@ | ||
package br.com.ifsp.tickets.infra.shared.event; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor(onConstructor_ = @__(@Autowired)) | ||
public class DomainEventListener implements ApplicationListener<InfraAppEvent> { | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
@Override | ||
public void onApplicationEvent(@NotNull InfraAppEvent event) { | ||
final String eventJson; | ||
try { | ||
eventJson = this.objectMapper.writeValueAsString(event); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
final String message = "domain event received: " + eventJson; | ||
switch (event.type()) { | ||
case INFO -> log.info(message); | ||
case WARNING -> log.warn(message); | ||
case ERROR, FATAL -> log.error(message); | ||
case DEBUG -> log.debug(message); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...astructure/src/main/java/br/com/ifsp/tickets/infra/shared/event/DomainEventPublisher.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 br.com.ifsp.tickets.infra.shared.event; | ||
|
||
import br.com.ifsp.tickets.domain.shared.IDomainEvent; | ||
import br.com.ifsp.tickets.domain.shared.IDomainEventPublisher; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor(onConstructor_ = @__(@Autowired)) | ||
public class DomainEventPublisher implements IDomainEventPublisher { | ||
|
||
private final ApplicationEventPublisher publisher; | ||
|
||
@Override | ||
public void publishEvent(IDomainEvent event) { | ||
this.publisher.publishEvent(new InfraAppEvent(this, event)); | ||
} | ||
} |
Oops, something went wrong.