Search in sources :

Example 1 with BeforeRecipeRemovedEvent

use of org.eclipse.che.api.machine.server.event.BeforeRecipeRemovedEvent in project che by eclipse.

the class JpaRecipeDao method doRemove.

@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected void doRemove(String id) throws ServerException {
    final EntityManager manager = managerProvider.get();
    final RecipeImpl recipe = manager.find(RecipeImpl.class, id);
    if (recipe != null) {
        eventService.publish(new BeforeRecipeRemovedEvent(new RecipeImpl(recipe))).propagateException();
        manager.remove(recipe);
        manager.flush();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) BeforeRecipeRemovedEvent(org.eclipse.che.api.machine.server.event.BeforeRecipeRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Example 2 with BeforeRecipeRemovedEvent

use of org.eclipse.che.api.machine.server.event.BeforeRecipeRemovedEvent in project che by eclipse.

the class RecipeDaoTest method shouldNotRemoveRecipeWhenSubscriberThrowsExceptionOnRecipeRemoving.

@Test(dependsOnMethods = "shouldGetRecipeById")
public void shouldNotRemoveRecipeWhenSubscriberThrowsExceptionOnRecipeRemoving() throws Exception {
    final RecipeImpl recipe = recipes.get(0);
    CascadeEventSubscriber<BeforeRecipeRemovedEvent> subscriber = mockCascadeEventSubscriber();
    doThrow(new ServerException("error")).when(subscriber).onCascadeEvent(any());
    eventService.subscribe(subscriber, BeforeRecipeRemovedEvent.class);
    try {
        recipeDao.remove(recipe.getId());
        fail("RecipeDao#remove had to throw server exception");
    } catch (ServerException ignored) {
    }
    assertEquals(recipeDao.getById(recipe.getId()), recipe);
    eventService.unsubscribe(subscriber, BeforeRecipeRemovedEvent.class);
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) BeforeRecipeRemovedEvent(org.eclipse.che.api.machine.server.event.BeforeRecipeRemovedEvent) Test(org.testng.annotations.Test)

Aggregations

BeforeRecipeRemovedEvent (org.eclipse.che.api.machine.server.event.BeforeRecipeRemovedEvent)2 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)2 Transactional (com.google.inject.persist.Transactional)1 EntityManager (javax.persistence.EntityManager)1 ServerException (org.eclipse.che.api.core.ServerException)1 Test (org.testng.annotations.Test)1