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