Search in sources :

Example 11 with Handles

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

the class RecipeEventListener method recipePhotographAdded.

@Handles("example.recipe-photograph-added")
public void recipePhotographAdded(final JsonEnvelope event) {
    final String recipeId = event.payloadAsJsonObject().getString(FIELD_RECIPE_ID);
    final String photoId = event.payloadAsJsonObject().getString(FIELD_PHOTO_ID);
    LOGGER.trace("=============> Inside recipe-photograph-added Event Listener. RecipeId: " + recipeId);
    final Recipe recipe = recipeRepository.findBy(UUID.fromString(recipeId));
    recipe.setPhotoId(UUID.fromString(photoId));
    recipeRepository.save(recipe);
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 12 with Handles

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

the class RecipeEventListener method recipeAdded.

@Handles("example.recipe-added")
public void recipeAdded(final JsonEnvelope event) {
    final String recipeId = event.payloadAsJsonObject().getString(FIELD_RECIPE_ID);
    LOGGER.trace("=============> Inside add-recipe Event Listener. RecipeId: " + recipeId);
    final RecipeAdded recipeAdded = jsonObjectConverter.convert(event.payloadAsJsonObject(), RecipeAdded.class);
    recipeRepository.save(recipeAddedToRecipeConverter.convert(recipeAdded));
    LOGGER.trace("=====================================================> Recipe saved, RecipeId: " + recipeId);
    for (final Ingredient ingredient : recipeAddedToIngredientsConverter.convert(recipeAdded)) {
        if (ingredientRepository.findByNameIgnoreCase(ingredient.getName()).isEmpty()) {
            LOGGER.trace("=============> Inside add-recipe Event Listener about to save Ingredient Id: " + ingredient.getId());
            ingredientRepository.save(ingredient);
            LOGGER.trace("=====================================================> Ingredient saved, Ingredient Id: " + ingredient.getId());
        } else {
            LOGGER.trace("=====================================================> Skipped adding ingredient as it already exists, Ingredient Name: " + ingredient.getName());
        }
    }
}
Also used : RecipeAdded(uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded) Ingredient(uk.gov.justice.services.example.cakeshop.persistence.entity.Ingredient) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 13 with Handles

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

the class RecipeEventListener method recipeRenamed.

@Handles("example.recipe-renamed")
public void recipeRenamed(final JsonEnvelope event) {
    final String recipeId = event.payloadAsJsonObject().getString(FIELD_RECIPE_ID);
    final String recipeName = event.payloadAsJsonObject().getString("name");
    LOGGER.trace("=============> Inside rename-recipe Event Listener. RecipeId: " + recipeId);
    final Recipe recipe = recipeRepository.findBy(UUID.fromString(recipeId));
    recipe.setName(recipeName);
    recipeRepository.save(recipe);
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 14 with Handles

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

the class OrderCakeCommandHandler method handle.

@Handles("example.command.order-cake")
public void handle(final JsonEnvelope command) throws EventStreamException {
    LOGGER.info("=============> Inside order-cake Command Handler");
    final UUID streamId = UUID.fromString(command.payloadAsJsonObject().getString(FIELD_STREAM_ID));
    final Stream<Object> events = streamOf(eventFactory.cakeOrderedEventFrom(command));
    eventSource.getStreamById(streamId).append(events.map(toEnvelopeWithMetadataFrom(command)));
}
Also used : UUID(java.util.UUID) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 15 with Handles

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

the class RestClientGenerator_CodeStructureTest method shouldGenerateMethodAnnotatedWithHandlesAnnotationForGET.

@Test
public void shouldGenerateMethodAnnotatedWithHandlesAnnotationForGET() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path/{recipeId}").with(httpAction(GET).withResponseTypes("application/vnd.cakeshop.query.recipe+json").withDescription(GET_MAPPING_ANNOTATION))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withServiceComponentOf("CUSTOM_COMPONENT")));
    final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "RemoteCustomComponent2ServiceCommandApi");
    final List<Method> methods = methodsOf(clazz);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    assertThat(method.getName(), equalTo("getSomePathRecipeIdCakeshopQueryRecipe"));
    final Handles handlesAnnotation = method.getAnnotation(Handles.class);
    assertThat(handlesAnnotation, not(nullValue()));
    assertThat(handlesAnnotation.value(), is("cakeshop.get-recipe"));
}
Also used : Handles(uk.gov.justice.services.core.annotation.Handles) Method(java.lang.reflect.Method) Test(org.junit.Test)

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