-
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.
MODTLR-13 Handle request update event from data tenant to update ECS TLR
- Loading branch information
1 parent
d0cb1c0
commit 37db0fd
Showing
7 changed files
with
78 additions
and
6 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package org.folio.service; | ||
|
||
public interface KafkaEventHandler { | ||
void handle(String event); | ||
void handleRequestEvent(String event); | ||
} |
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
16 changes: 14 additions & 2 deletions
16
src/main/java/org/folio/service/impl/KafkaEventHandlerImpl.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 |
---|---|---|
@@ -1,16 +1,28 @@ | ||
package org.folio.service.impl; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.folio.service.EcsTlrService; | ||
import org.folio.service.KafkaEventHandler; | ||
import org.folio.support.KafkaEvent; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.extern.log4j.Log4j2; | ||
|
||
import java.util.UUID; | ||
|
||
@AllArgsConstructor | ||
@Service | ||
@Log4j2 | ||
public class KafkaEventHandlerImpl implements KafkaEventHandler { | ||
|
||
private final EcsTlrService ecsTlrService; | ||
@Override | ||
public void handle(String event) { | ||
log.info("handle:: event consumed: {}", event); | ||
public void handleRequestEvent(String event) { | ||
log.info("handle:: request event consumed: {}", event); | ||
KafkaEvent kafkaEvent = new KafkaEvent(event); | ||
if(kafkaEvent.getEventType() == KafkaEvent.EventType.UPDATED) { | ||
ecsTlrService.updateRequestItem(UUID.fromString(kafkaEvent.getNewNode().get("id").asText()), | ||
UUID.fromString(kafkaEvent.getNewNode().get("itemId").asText())); | ||
} | ||
} | ||
} |
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 org.folio.support; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.Getter; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Log4j2 | ||
@Getter | ||
public class KafkaEvent { | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
public static final String STATUS = "status"; | ||
private EventType eventType; | ||
private JsonNode newNode; | ||
private JsonNode oldNode; | ||
|
||
public KafkaEvent(String eventPayload) { | ||
try { | ||
JsonNode jsonNode = objectMapper.readTree(eventPayload); | ||
setEventType(jsonNode.get("type").asText()); | ||
setNewNode(jsonNode.get("data")); | ||
setOldNode(jsonNode.get("data")); | ||
} catch (Exception e) { | ||
log.error("Could not parse input payload for processing event", e); | ||
} | ||
} | ||
|
||
private void setEventType(String eventType) { | ||
this.eventType = EventType.valueOf(eventType); | ||
} | ||
private void setNewNode(JsonNode dataNode) { | ||
if(dataNode != null) { | ||
this.newNode = dataNode.get("new"); | ||
} | ||
} | ||
private void setOldNode(JsonNode dataNode) { | ||
if(dataNode != null) { | ||
this.oldNode = dataNode.get("old"); | ||
} | ||
} | ||
public enum EventType { | ||
UPDATED, CREATED | ||
} | ||
} |