-
Notifications
You must be signed in to change notification settings - Fork 3
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
santhosh
committed
Jan 24, 2024
1 parent
fd94116
commit 438fd85
Showing
14 changed files
with
438 additions
and
74 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
39 changes: 36 additions & 3 deletions
39
...rc/main/java/uk/gov/justice/services/cakeshop/event/processor/CakeMadeEventProcessor.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,22 +1,55 @@ | ||
package uk.gov.justice.services.cakeshop.event.processor; | ||
|
||
import static uk.gov.justice.services.core.annotation.Component.EVENT_PROCESSOR; | ||
|
||
import javax.inject.Inject; | ||
import javax.json.JsonObject; | ||
import org.slf4j.Logger; | ||
import uk.gov.justice.services.cakeshop.jobstore.CakeMadeJobData; | ||
import uk.gov.justice.services.common.converter.ObjectToJsonObjectConverter; | ||
import uk.gov.justice.services.common.util.UtcClock; | ||
import uk.gov.justice.services.core.annotation.Handles; | ||
import uk.gov.justice.services.core.annotation.ServiceComponent; | ||
import uk.gov.justice.services.core.sender.Sender; | ||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
import uk.gov.moj.cpp.jobstore.api.ExecutionService; | ||
import uk.gov.moj.cpp.jobstore.api.task.ExecutionInfo; | ||
|
||
import javax.inject.Inject; | ||
import static uk.gov.justice.services.cakeshop.jobstore.CakeMadeNotificationTask.CAKE_MADE_NOTIFICATION_TASK; | ||
import static uk.gov.justice.services.core.annotation.Component.EVENT_PROCESSOR; | ||
import static uk.gov.moj.cpp.jobstore.api.task.ExecutionStatus.STARTED; | ||
|
||
@ServiceComponent(EVENT_PROCESSOR) | ||
public class CakeMadeEventProcessor { | ||
|
||
@Inject | ||
Sender sender; | ||
|
||
@Inject | ||
private ObjectToJsonObjectConverter objectToJsonObjectConverter; | ||
|
||
@Inject | ||
private UtcClock clock; | ||
|
||
@Inject | ||
private ExecutionService executionService; | ||
|
||
@SuppressWarnings({"squid:S1312"}) | ||
@Inject | ||
private Logger logger; | ||
|
||
@Handles("cakeshop.events.cake-made") | ||
public void handle(final JsonEnvelope event) { | ||
final JsonObject cakeMadeEventPayload = event.payloadAsJsonObject(); | ||
final String cakeId = cakeMadeEventPayload.getString("cakeId"); | ||
final ExecutionInfo executionInfo = new ExecutionInfo( | ||
objectToJsonObjectConverter.convert(new CakeMadeJobData(cakeId)), | ||
CAKE_MADE_NOTIFICATION_TASK, | ||
clock.now(), | ||
STARTED); | ||
|
||
executionService.executeWith(executionInfo); | ||
|
||
logger.info("Cake made notification task submitted to job store"); | ||
|
||
sender.send(event); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...nt-processor/src/main/java/uk/gov/justice/services/cakeshop/jobstore/CakeMadeJobData.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,34 @@ | ||
package uk.gov.justice.services.cakeshop.jobstore; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
|
||
import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals; | ||
|
||
@SuppressWarnings("squid:S2384") | ||
public class CakeMadeJobData { | ||
|
||
private final String cakeId; | ||
|
||
public CakeMadeJobData(@JsonProperty("cakeId") final String cakeId) { | ||
this.cakeId = cakeId; | ||
} | ||
|
||
public String getCakeId() { | ||
return cakeId; | ||
} | ||
|
||
public String toString() { | ||
return "CakeMadeJobData(cakeId=" + this.getCakeId() + ")"; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
return reflectionEquals(this, o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder(17, 37).append(cakeId).toHashCode(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...sor/src/main/java/uk/gov/justice/services/cakeshop/jobstore/CakeMadeNotificationTask.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,57 @@ | ||
package uk.gov.justice.services.cakeshop.jobstore; | ||
|
||
import java.util.UUID; | ||
import javax.inject.Inject; | ||
import org.slf4j.Logger; | ||
import uk.gov.justice.services.common.util.UtcClock; | ||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
import uk.gov.justice.services.messaging.jms.JmsSender; | ||
import uk.gov.justice.services.messaging.spi.DefaultJsonEnvelopeProvider; | ||
import uk.gov.justice.services.messaging.spi.DefaultJsonMetadata; | ||
import uk.gov.moj.cpp.jobstore.api.annotation.Task; | ||
import uk.gov.moj.cpp.jobstore.api.task.ExecutableTask; | ||
import uk.gov.moj.cpp.jobstore.api.task.ExecutionInfo; | ||
import uk.gov.moj.cpp.jobstore.api.task.ExecutionStatus; | ||
|
||
import static uk.gov.justice.services.cakeshop.jobstore.CakeMadeNotificationTask.CAKE_MADE_NOTIFICATION_TASK; | ||
|
||
@Task(CAKE_MADE_NOTIFICATION_TASK) | ||
public class CakeMadeNotificationTask implements ExecutableTask { | ||
|
||
public static final String CAKE_MADE_NOTIFICATION_TASK = "cake-made-notification-task"; | ||
|
||
@Inject | ||
private JmsSender jmsSender; | ||
|
||
@SuppressWarnings({"squid:S1312"}) | ||
@Inject | ||
private Logger logger; | ||
|
||
@Inject | ||
private UtcClock clock; | ||
|
||
@Override | ||
public ExecutionInfo execute(final ExecutionInfo executionInfo) { | ||
try{ | ||
final JsonEnvelope jsonEnvelope = new DefaultJsonEnvelopeProvider().envelopeFrom(DefaultJsonMetadata.metadataBuilder() | ||
.withId(UUID.randomUUID()) | ||
.createdAt(clock.now()) | ||
.withName("jobstore.task.notification.cake-made").build(), | ||
executionInfo.getJobData()); | ||
|
||
jmsSender.send(jsonEnvelope, "public.event"); | ||
|
||
logger.info("Cake made notification sent successfully to public.event topic"); | ||
|
||
return ExecutionInfo.executionInfo() | ||
.withExecutionStatus(ExecutionStatus.COMPLETED) | ||
.build(); | ||
|
||
} catch (Exception e) { | ||
logger.error("Error while sending cake made notification to public.event topic", e); | ||
return ExecutionInfo.executionInfo() | ||
.withExecutionStatus(ExecutionStatus.COMPLETED) | ||
.build(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.