Search in sources :

Example 1 with Ingredient

use of uk.gov.justice.services.example.cakeshop.domain.Ingredient 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 2 with Ingredient

use of uk.gov.justice.services.example.cakeshop.domain.Ingredient in project microservice_framework by CJSCommonPlatform.

the class RecipeAddedToRecipeConverterTest method shouldConvertRecipeAddedEvent.

@Test
public void shouldConvertRecipeAddedEvent() {
    final String name = "someName123";
    final UUID recipeId = UUID.randomUUID();
    final boolean glutenFree = true;
    final List<Ingredient> ingredients = Collections.singletonList(new Ingredient("sugar", 2));
    Recipe recipe = converter.convert(new RecipeAdded(recipeId, name, glutenFree, ingredients));
    assertThat(recipe.getName(), equalTo(name));
    assertThat(recipe.getId(), equalTo(recipeId));
    assertThat(recipe.isGlutenFree(), equalTo(glutenFree));
}
Also used : RecipeAdded(uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded) Ingredient(uk.gov.justice.services.example.cakeshop.domain.Ingredient) Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

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