use of org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent in project che-server by eclipse-che.
the class OrganizationManagerTest method shouldRemoveOrganization.
@Test
public void shouldRemoveOrganization() throws Exception {
doNothing().when(manager).removeSuborganizations(anyString());
final List<Member> members = Collections.singletonList(mock(Member.class));
doReturn(members).when(manager).removeMembers(anyString());
OrganizationImpl toRemove = new OrganizationImpl("org123", "toRemove", null);
when(organizationDao.getById(anyString())).thenReturn(toRemove);
BeforeAccountRemovedEvent beforeAccountRemovedEvent = mock(BeforeAccountRemovedEvent.class);
BeforeOrganizationRemovedEvent beforeOrganizationRemovedEvent = mock(BeforeOrganizationRemovedEvent.class);
doReturn(beforeAccountRemovedEvent).doReturn(beforeOrganizationRemovedEvent).when(eventService).publish(any());
manager.remove(toRemove.getId());
verify(organizationDao).remove(toRemove.getId());
verify(manager).removeMembers(eq(toRemove.getId()));
verify(manager).removeSuborganizations(eq(toRemove.getId()));
verify(eventService, times(3)).publish(anyObject());
verify(beforeAccountRemovedEvent).propagateException();
verify(beforeOrganizationRemovedEvent).propagateException();
}
use of org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent in project che-server by eclipse-che.
the class OrganizationManager method remove.
/**
* Removes organization with given id
*
* @param organizationId organization id
* @throws NullPointerException when {@code organizationId} is null
* @throws ServerException when any other error occurs during organization removing
*/
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
public void remove(String organizationId) throws ServerException {
requireNonNull(organizationId, "Required non-null organization id");
try {
OrganizationImpl organization = organizationDao.getById(organizationId);
eventService.publish(new BeforeAccountRemovedEvent(organization.getAccount())).propagateException();
eventService.publish(new BeforeOrganizationRemovedEvent(organization)).propagateException();
removeSuborganizations(organizationId);
final List<String> members = removeMembers(organizationId);
organizationDao.remove(organizationId);
final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName();
eventService.publish(asDto(new OrganizationRemovedEvent(initiator, organization, members)));
} catch (NotFoundException e) {
// organization is already removed
}
}
use of org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent in project che-server by eclipse-che.
the class RemoveOrganizationDistributedResourcesSubscriberTest method shouldNotResetResourcesDistributionBeforeRootOrganizationRemoving.
@Test
public void shouldNotResetResourcesDistributionBeforeRootOrganizationRemoving() throws Exception {
// given
lenient().when(organization.getId()).thenReturn("org123");
when(organization.getParent()).thenReturn(null);
// when
suborganizationsRemover.onEvent(new BeforeOrganizationRemovedEvent(organization));
// then
verify(organizationDistributedResourcesDao, never()).remove("org123");
}
use of org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent in project che-server by eclipse-che.
the class RemoveOrganizationDistributedResourcesSubscriberTest method shouldResetResourcesDistributionBeforeSuborganizationRemoving.
@Test
public void shouldResetResourcesDistributionBeforeSuborganizationRemoving() throws Exception {
// given
when(organization.getId()).thenReturn("suborg123");
when(organization.getParent()).thenReturn("org123");
// when
suborganizationsRemover.onEvent(new BeforeOrganizationRemovedEvent(organization));
// then
verify(organizationDistributedResourcesDao).remove("suborg123");
}
use of org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent in project devspaces-images by redhat-developer.
the class OrganizationManager method remove.
/**
* Removes organization with given id
*
* @param organizationId organization id
* @throws NullPointerException when {@code organizationId} is null
* @throws ServerException when any other error occurs during organization removing
*/
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
public void remove(String organizationId) throws ServerException {
requireNonNull(organizationId, "Required non-null organization id");
try {
OrganizationImpl organization = organizationDao.getById(organizationId);
eventService.publish(new BeforeAccountRemovedEvent(organization.getAccount())).propagateException();
eventService.publish(new BeforeOrganizationRemovedEvent(organization)).propagateException();
removeSuborganizations(organizationId);
final List<String> members = removeMembers(organizationId);
organizationDao.remove(organizationId);
final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName();
eventService.publish(asDto(new OrganizationRemovedEvent(initiator, organization, members)));
} catch (NotFoundException e) {
// organization is already removed
}
}
Aggregations