Search in sources :

Example 6 with Handles

use of uk.gov.justice.services.core.annotation.Handles in project microservice_framework by CJSCommonPlatform.

the class MakeCakeCommandHandler method makeCake.

@Handles("example.command.make-cake")
public void makeCake(final JsonEnvelope command) throws EventStreamException {
    LOGGER.info("=============> Inside make-cake Command Handler");
    final UUID recipeId = getUUID(command.payloadAsJsonObject(), FIELD_RECIPE_ID).get();
    final UUID cakeId = getUUID(command.payloadAsJsonObject(), FIELD_CAKE_ID).get();
    final EventStream eventStream = eventSource.getStreamById(recipeId);
    final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
    eventStream.append(recipe.makeCake(cakeId).map(toEnvelopeWithMetadataFrom(command)), Tolerance.CONSECUTIVE);
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) UUID(java.util.UUID) JsonObjects.getUUID(uk.gov.justice.services.messaging.JsonObjects.getUUID) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 7 with Handles

use of uk.gov.justice.services.core.annotation.Handles in project microservice_framework by CJSCommonPlatform.

the class RecipeCommandHandler method uploadPhotograph.

@Handles("example.command.upload-photograph")
public void uploadPhotograph(final JsonEnvelope command) throws EventStreamException {
    LOGGER.trace("=============> Inside upload-photograph Command Handler. RecipeId: " + command.payloadAsJsonObject().getString(FIELD_RECIPE_ID));
    final UUID recipeId = getUUID(command.payloadAsJsonObject(), FIELD_RECIPE_ID).get();
    final UUID photoId = getUUID(command.payloadAsJsonObject(), FIELD_PHOTO_ID).get();
    final EventStream eventStream = eventSource.getStreamById(recipeId);
    final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
    eventStream.append(recipe.addPhotograph(photoId).map(toEnvelopeWithMetadataFrom(command)), Tolerance.NON_CONSECUTIVE);
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) UUID(java.util.UUID) JsonObjects.getUUID(uk.gov.justice.services.messaging.JsonObjects.getUUID) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 8 with Handles

use of uk.gov.justice.services.core.annotation.Handles in project microservice_framework by CJSCommonPlatform.

the class RecipeCommandHandler method renameRecipe.

@Handles("example.command.rename-recipe")
public void renameRecipe(final Envelope<RenameRecipe> command) throws EventStreamException {
    LOGGER.trace("=============> Inside rename-recipe Command Handler");
    final UUID recipeId = UUID.fromString(command.payload().getRecipeId());
    final String name = command.payload().getName();
    final EventStream eventStream = eventSource.getStreamById(recipeId);
    final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
    eventStream.append(recipe.renameRecipe(name).map(toEnvelopeWithMetadataFrom(command)), Tolerance.NON_CONSECUTIVE);
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) JsonObjects.getString(uk.gov.justice.services.messaging.JsonObjects.getString) UUID(java.util.UUID) JsonObjects.getUUID(uk.gov.justice.services.messaging.JsonObjects.getUUID) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 9 with Handles

use of uk.gov.justice.services.core.annotation.Handles in project microservice_framework by CJSCommonPlatform.

the class RecipeCommandHandler method addRecipe.

@Handles("example.command.add-recipe")
public void addRecipe(final JsonEnvelope command) throws EventStreamException {
    LOGGER.trace("=============> Inside add-recipe Command Handler. RecipeId: " + command.payloadAsJsonObject().getString(FIELD_RECIPE_ID));
    final UUID recipeId = getUUID(command.payloadAsJsonObject(), FIELD_RECIPE_ID).get();
    final String name = getString(command.payloadAsJsonObject(), FIELD_NAME).get();
    final Boolean glutenFree = getBoolean(command.payloadAsJsonObject(), FIELD_GLUTEN_FREE).get();
    final List<Ingredient> ingredients = ingredientsFrom(command.payloadAsJsonObject());
    final EventStream eventStream = eventSource.getStreamById(recipeId);
    final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
    eventStream.append(recipe.addRecipe(recipeId, name, glutenFree, ingredients).map(toEnvelopeWithMetadataFrom(command)));
}
Also used : Ingredient(uk.gov.justice.services.example.cakeshop.domain.Ingredient) Recipe(uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) JsonObjects.getString(uk.gov.justice.services.messaging.JsonObjects.getString) UUID(java.util.UUID) JsonObjects.getUUID(uk.gov.justice.services.messaging.JsonObjects.getUUID) JsonObjects.getBoolean(uk.gov.justice.services.messaging.JsonObjects.getBoolean) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 10 with Handles

use of uk.gov.justice.services.core.annotation.Handles in project microservice_framework by CJSCommonPlatform.

the class RecipeEventListener method recipeRemoved.

@Handles("example.recipe-removed")
public void recipeRemoved(final JsonEnvelope event) {
    final String recipeId = event.payloadAsJsonObject().getString(FIELD_RECIPE_ID);
    LOGGER.trace("=============> Inside remove-recipe Event Listener about to find recipeId: " + recipeId);
    final Recipe recipeFound = recipeRepository.findBy(UUID.fromString(recipeId));
    LOGGER.trace("=============> Found remove-recipe Event Listener. RecipeId: " + recipeFound);
    recipeRepository.remove(recipeFound);
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) Handles(uk.gov.justice.services.core.annotation.Handles)

Aggregations

Handles (uk.gov.justice.services.core.annotation.Handles)20 Method (java.lang.reflect.Method)9 Test (org.junit.Test)9 UUID (java.util.UUID)6 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)5 Recipe (uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe)5 JsonObjects.getUUID (uk.gov.justice.services.messaging.JsonObjects.getUUID)5 Recipe (uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe)3 RecipeAdded (uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded)2 Ingredient (uk.gov.justice.services.example.cakeshop.persistence.entity.Ingredient)2 JsonObjects.getString (uk.gov.justice.services.messaging.JsonObjects.getString)2 Ingredient (uk.gov.justice.services.example.cakeshop.domain.Ingredient)1 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)1 JsonObjects.getBoolean (uk.gov.justice.services.messaging.JsonObjects.getBoolean)1