Search in sources :

Example 6 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationManagerTest method shouldGetOrganizationByName.

@Test
public void shouldGetOrganizationByName() throws Exception {
    final OrganizationImpl toFetch = new OrganizationImpl("org123", "toFetchOrg", "org321");
    when(organizationDao.getByName(eq("org123"))).thenReturn(toFetch);
    final Organization fetched = manager.getByName("org123");
    assertEquals(fetched, toFetch);
    verify(organizationDao).getByName("org123");
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 7 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationManagerTest method shouldCreateSuborganization.

@Test
public void shouldCreateSuborganization() throws Exception {
    final OrganizationImpl parentOrganization = new OrganizationImpl("org123", "parentOrg", null);
    when(organizationDao.getById(anyString())).thenReturn(parentOrganization);
    final Organization toCreate = new OrganizationImpl(null, "orgName", parentOrganization.getId());
    manager.create(toCreate);
    verify(organizationDao).create(organizationCaptor.capture());
    final OrganizationImpl createdOrganization = organizationCaptor.getValue();
    assertEquals(createdOrganization.getName(), toCreate.getName());
    assertEquals(createdOrganization.getQualifiedName(), parentOrganization.getQualifiedName() + "/" + toCreate.getName());
    assertEquals(createdOrganization.getParent(), toCreate.getParent());
    verify(eventService).publish(persistEventCaptor.capture());
    assertEquals(persistEventCaptor.getValue().getOrganization(), createdOrganization);
    verify(memberDao).store(new MemberImpl(USER_ID, createdOrganization.getId(), OrganizationDomain.getActions()));
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 8 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationManagerTest method shouldCreateOrganization.

@Test
public void shouldCreateOrganization() throws Exception {
    final Organization toCreate = DtoFactory.newDto(OrganizationDto.class).withName("newOrg");
    manager.create(toCreate);
    verify(organizationDao).create(organizationCaptor.capture());
    final OrganizationImpl createdOrganization = organizationCaptor.getValue();
    assertEquals(createdOrganization.getName(), toCreate.getName());
    assertEquals(createdOrganization.getQualifiedName(), toCreate.getName());
    assertEquals(createdOrganization.getParent(), toCreate.getParent());
    verify(eventService).publish(persistEventCaptor.capture());
    assertEquals(persistEventCaptor.getValue().getOrganization(), createdOrganization);
    verify(memberDao).store(new MemberImpl(USER_ID, createdOrganization.getId(), OrganizationDomain.getActions()));
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 9 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationManager method create.

/**
 * Creates new organization.
 *
 * @param newOrganization organization to create
 * @return created organization
 * @throws NullPointerException when {@code organization} is null
 * @throws NotFoundException when parent organization was not found
 * @throws ConflictException when organization with such id/name already exists
 * @throws ConflictException when specified organization name is reserved
 * @throws ServerException when any other error occurs during organization creation
 */
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
public Organization create(Organization newOrganization) throws NotFoundException, ConflictException, ServerException {
    requireNonNull(newOrganization, "Required non-null organization");
    requireNonNull(newOrganization.getName(), "Required non-null organization name");
    String qualifiedName;
    if (newOrganization.getParent() != null) {
        final Organization parent = getById(newOrganization.getParent());
        qualifiedName = parent.getQualifiedName() + "/" + newOrganization.getName();
    } else {
        qualifiedName = newOrganization.getName();
    }
    checkNameReservation(qualifiedName);
    final OrganizationImpl organization = new OrganizationImpl(NameGenerator.generate("organization", 16), qualifiedName, newOrganization.getParent());
    organizationDao.create(organization);
    addFirstMember(organization);
    eventService.publish(new OrganizationPersistedEvent(organization)).propagateException();
    return organization;
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationPersistedEvent(org.eclipse.che.multiuser.organization.api.event.OrganizationPersistedEvent) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Example 10 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationResourceLockKeyProvider method getLockKey.

@Override
public String getLockKey(String accountId) throws ServerException {
    String currentOrganizationId = accountId;
    try {
        Organization organization = organizationManager.getById(currentOrganizationId);
        while (organization.getParent() != null) {
            currentOrganizationId = organization.getParent();
            organization = organizationManager.getById(currentOrganizationId);
        }
        return organization.getId();
    } catch (NotFoundException e) {
        // should not happen
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Aggregations

Organization (org.eclipse.che.multiuser.organization.shared.model.Organization)28 Test (org.testng.annotations.Test)18 OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)16 OrganizationDto (org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto)8 Response (io.restassured.response.Response)4 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)4 Subject (org.eclipse.che.commons.subject.Subject)4 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Transactional (com.google.inject.persist.Transactional)2 ArrayList (java.util.ArrayList)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 OrganizationPersistedEvent (org.eclipse.che.multiuser.organization.api.event.OrganizationPersistedEvent)2 ResourceManager (org.eclipse.che.multiuser.resource.api.usage.ResourceManager)2 Resource (org.eclipse.che.multiuser.resource.model.Resource)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2