Search in sources :

Example 1 with StackPersistedEvent

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

the class JpaStackDao method doCreate.

@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
protected void doCreate(StackImpl stack) throws ConflictException, ServerException {
    if (stack.getWorkspaceConfig() != null) {
        stack.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
    }
    EntityManager manager = managerProvider.get();
    manager.persist(stack);
    manager.flush();
    eventService.publish(new StackPersistedEvent(stack)).propagateException();
}
Also used : StackPersistedEvent(org.eclipse.che.api.workspace.server.event.StackPersistedEvent) EntityManager(javax.persistence.EntityManager) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Transactional(com.google.inject.persist.Transactional)

Example 2 with StackPersistedEvent

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

the class StackDaoTest method shouldNotCreateStackWhenSubscriberThrowsExceptionOnStackStoring.

@Test(dependsOnMethods = "shouldThrowNotFoundExceptionWhenGettingNonExistingStack", expectedExceptions = NotFoundException.class)
public void shouldNotCreateStackWhenSubscriberThrowsExceptionOnStackStoring() throws Exception {
    final StackImpl stack = createStack("new-stack", "new-stack-name");
    CascadeEventSubscriber<StackPersistedEvent> subscriber = mockCascadeEventSubscriber();
    doThrow(new ConflictException("error")).when(subscriber).onCascadeEvent(any());
    eventService.subscribe(subscriber, StackPersistedEvent.class);
    try {
        stackDao.create(stack);
        fail("StackDao#create had to throw conflict exception");
    } catch (ConflictException ignored) {
    }
    eventService.unsubscribe(subscriber, StackPersistedEvent.class);
    stackDao.getById(stack.getId());
}
Also used : StackPersistedEvent(org.eclipse.che.api.workspace.server.event.StackPersistedEvent) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) ConflictException(org.eclipse.che.api.core.ConflictException) Test(org.testng.annotations.Test)

Aggregations

StackPersistedEvent (org.eclipse.che.api.workspace.server.event.StackPersistedEvent)2 Transactional (com.google.inject.persist.Transactional)1 EntityManager (javax.persistence.EntityManager)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)1 StackImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl)1 Test (org.testng.annotations.Test)1