Search in sources :

Example 1 with BeforeStackRemovedEvent

use of org.eclipse.che.api.workspace.server.event.BeforeStackRemovedEvent in project che by eclipse.

the class JpaStackDao method doRemove.

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

Example 2 with BeforeStackRemovedEvent

use of org.eclipse.che.api.workspace.server.event.BeforeStackRemovedEvent in project che by eclipse.

the class StackDaoTest method shouldNotRemoveStackWhenSubscriberThrowsExceptionOnStackRemoving.

@Test(dependsOnMethods = "shouldGetById")
public void shouldNotRemoveStackWhenSubscriberThrowsExceptionOnStackRemoving() throws Exception {
    final StackImpl stack = stacks[0];
    CascadeEventSubscriber<BeforeStackRemovedEvent> subscriber = mockCascadeEventSubscriber();
    doThrow(new ServerException("error")).when(subscriber).onCascadeEvent(any());
    eventService.subscribe(subscriber, BeforeStackRemovedEvent.class);
    try {
        stackDao.remove(stack.getId());
        fail("StackDao#remove had to throw server exception");
    } catch (ServerException ignored) {
    }
    assertEquals(stackDao.getById(stack.getId()), stack);
    eventService.unsubscribe(subscriber, BeforeStackRemovedEvent.class);
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) ServerException(org.eclipse.che.api.core.ServerException) BeforeStackRemovedEvent(org.eclipse.che.api.workspace.server.event.BeforeStackRemovedEvent) Test(org.testng.annotations.Test)

Aggregations

BeforeStackRemovedEvent (org.eclipse.che.api.workspace.server.event.BeforeStackRemovedEvent)2 StackImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl)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