Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Battlestad committed Oct 1, 2024
1 parent 67b5ee7 commit c8eeb12
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.fintlabs;

public class EventTopicNames {
public class EventNames {

private EventTopicNames() {
private EventNames() {
}

public static String INSTANCE_RECEIVED = "instance-received";
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/no/fintlabs/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static no.fintlabs.EventNames.INSTANCE_DELETED;

@Service
@AllArgsConstructor
public class EventService {
Expand Down Expand Up @@ -71,12 +73,12 @@ private PageImpl<EventDto> getEventDtos(Pageable pageable, List<Event> latestNon
List<EventDto> mergedEvents = new ArrayList<>();

for (Event latestEvent : latestEvents) {
if ("instance-deleted".equals(latestEvent.getName())) {
if (INSTANCE_DELETED.equals(latestEvent.getName())) {
Event nonDeletedEvent = nonDeletedEventMap
.get(latestEvent.getInstanceFlowHeaders().getSourceApplicationInstanceId());
if (nonDeletedEvent != null) {
EventDto updatedEventDto = EventToEventDto(nonDeletedEvent);
updatedEventDto.setStatus("deleted");
updatedEventDto.setStatus(INSTANCE_DELETED);
mergedEvents.add(updatedEventDto);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.Collection;
import java.util.stream.Collectors;

import static no.fintlabs.EventTopicNames.*;
import static no.fintlabs.EventNames.*;

@Configuration
public class ErrorEventConsumerConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.time.Instant;
import java.time.ZoneOffset;

import static no.fintlabs.EventTopicNames.*;
import static no.fintlabs.EventNames.*;

@Configuration
public class InfoEventConsumerConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;

import static no.fintlabs.EventTopicNames.INSTANCE_REGISTERED;
import static no.fintlabs.EventNames.INSTANCE_REGISTERED;

@Configuration
public class InstanceFlowHeadersForRegisteredInstanceRequestConsumerConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;
import java.util.Optional;

import static no.fintlabs.EventTopicNames.INSTANCE_DISPATCHED;
import static no.fintlabs.EventNames.INSTANCE_DISPATCHED;

@Repository
public interface EventRepository extends JpaRepository<Event, Long> {
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/no/fintlabs/repositories/EventRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.time.ZoneOffset;
import java.util.*;

import static no.fintlabs.EventTopicNames.*;
import static no.fintlabs.EventNames.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -54,16 +54,16 @@ public void setup() {
@Test
public void shouldReturnOnlyLatestEventForEachSourceApplicationInstanceId() {
Event event1 = createUnnamedTimestampEvent("1", "1", EventType.INFO, LocalDateTime.of(2001, 1, 1, 13, 30));
event1.setName("instance-received");
event1.setName(INSTANCE_RECEIVED);

Event event2 = createUnnamedTimestampEvent("1", "1", EventType.INFO, LocalDateTime.of(2001, 1, 1, 13, 32));
event2.setName("instance-received");
event2.setName(INSTANCE_RECEIVED);

Event event3 = createUnnamedTimestampEvent("1", "1", EventType.ERROR, LocalDateTime.of(2001, 1, 1, 13, 31));
event3.setName("instance-deleted");
event3.setName(INSTANCE_DELETED);

Event event4 = createUnnamedTimestampEvent("1", "2", EventType.ERROR, LocalDateTime.of(2001, 1, 1, 13, 29));
event4.setName("instance-received");
event4.setName(INSTANCE_RECEIVED);

eventRepository.saveAll(List.of(event1, event2, event3, event4));

Expand Down

0 comments on commit c8eeb12

Please sign in to comment.