Search in sources :

Example 1 with Recipe

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));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe) DefaultObjectInputStreamStrategy(uk.gov.justice.domain.snapshot.DefaultObjectInputStreamStrategy) AggregateSnapshot(uk.gov.justice.domain.snapshot.AggregateSnapshot)

Example 2 with 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);
}
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 3 with Recipe

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);
}
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 4 with Recipe

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);
}
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 5 with Recipe

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

Aggregations

Recipe (uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe)9 UUID (java.util.UUID)6 Handles (uk.gov.justice.services.core.annotation.Handles)5 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)5 JsonObjects.getUUID (uk.gov.justice.services.messaging.JsonObjects.getUUID)5 Test (org.junit.Test)2 RecipeAdded (uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded)2 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)2 JsonObjects.getString (uk.gov.justice.services.messaging.JsonObjects.getString)2 UUID.randomUUID (java.util.UUID.randomUUID)1 AggregateSnapshot (uk.gov.justice.domain.snapshot.AggregateSnapshot)1 DefaultObjectInputStreamStrategy (uk.gov.justice.domain.snapshot.DefaultObjectInputStreamStrategy)1 Ingredient (uk.gov.justice.services.example.cakeshop.domain.Ingredient)1 JsonObjects.getBoolean (uk.gov.justice.services.messaging.JsonObjects.getBoolean)1