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);
}
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);
}
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);
}
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)));
}
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);
}
Aggregations