use of uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method tweakRecipeSnapshotName.
private void tweakRecipeSnapshotName(final String recipeId, final String newRecipeName) throws AggregateChangeDetectedException {
final AggregateSnapshot<Recipe> recipeAggregateSnapshot = recipeAggregateSnapshotOf(recipeId).get();
final Recipe recipe = recipeAggregateSnapshot.getAggregate(new DefaultObjectInputStreamStrategy());
setField(recipe, "name", newRecipeName);
SNAPSHOT_REPOSITORY.removeAllSnapshots(recipeAggregateSnapshot.getStreamId(), Recipe.class);
SNAPSHOT_REPOSITORY.storeSnapshot(new AggregateSnapshot(recipeAggregateSnapshot.getStreamId(), recipeAggregateSnapshot.getVersionId(), recipe));
}
use of uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe 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.example.cakeshop.domain.aggregate.Recipe 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.example.cakeshop.domain.aggregate.Recipe 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.example.cakeshop.domain.aggregate.Recipe 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)));
}
Aggregations