Search in sources :

Example 11 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl 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 12 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl 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
    }
}
Also used : OrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.OrganizationRemovedEvent) BeforeOrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent) BeforeOrganizationRemovedEvent(org.eclipse.che.multiuser.organization.api.event.BeforeOrganizationRemovedEvent) NotFoundException(org.eclipse.che.api.core.NotFoundException) BeforeAccountRemovedEvent(org.eclipse.che.account.event.BeforeAccountRemovedEvent) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Example 13 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class OrganizationManager method update.

/**
 * Updates organization with new entity.
 *
 * @param organizationId id of organization to update
 * @param update organization update
 * @throws NullPointerException when {@code organizationId} or {@code update} is null
 * @throws NotFoundException when organization with given id doesn't exist
 * @throws ConflictException when name updated with a value which is reserved or is not unique
 * @throws ServerException when any other error occurs organization updating
 */
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
public Organization update(String organizationId, Organization update) throws NotFoundException, ConflictException, ServerException {
    requireNonNull(organizationId, "Required non-null organization id");
    requireNonNull(update, "Required non-null organization");
    requireNonNull(update.getName(), "Required non-null organization name");
    final OrganizationImpl organization = organizationDao.getById(organizationId);
    final String oldQualifiedName = organization.getQualifiedName();
    final String oldName = organization.getName();
    final String newName = update.getName();
    final String newQualifiedName = buildQualifiedName(oldQualifiedName, update.getName());
    checkNameReservation(newQualifiedName);
    organization.setQualifiedName(newQualifiedName);
    organizationDao.update(organization);
    if (!newName.equals(oldName)) {
        updateSuborganizationsQualifiedNames(oldQualifiedName, organization.getQualifiedName());
        final String performerName = EnvironmentContext.getCurrent().getSubject().getUserName();
        // should be DTO as it sent via json rpc
        eventService.publish(asDto(new OrganizationRenamedEvent(performerName, oldName, newName, organization)));
    }
    return organization;
}
Also used : OrganizationRenamedEvent(org.eclipse.che.multiuser.organization.api.event.OrganizationRenamedEvent) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Example 14 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl 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 15 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class JpaMemberDao method getOrganizations.

@Override
@Transactional
public Page<OrganizationImpl> getOrganizations(String userId, int maxItems, long skipCount) throws ServerException {
    requireNonNull(userId, "Required non-null user id");
    checkArgument(skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE);
    try {
        final EntityManager manager = managerProvider.get();
        final List<OrganizationImpl> result = manager.createNamedQuery("Member.getOrganizations", OrganizationImpl.class).setParameter("userId", userId).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList();
        final Long organizationsCount = manager.createNamedQuery("Member.getOrganizationsCount", Long.class).setParameter("userId", userId).getSingleResult();
        return new Page<>(result, skipCount, maxItems, organizationsCount);
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) Page(org.eclipse.che.api.core.Page) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Aggregations

OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)100 Test (org.testng.annotations.Test)56 Transactional (com.google.inject.persist.Transactional)18 BeforeMethod (org.testng.annotations.BeforeMethod)16 EntityManager (javax.persistence.EntityManager)14 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)14 Organization (org.eclipse.che.multiuser.organization.shared.model.Organization)13 Response (io.restassured.response.Response)12 Page (org.eclipse.che.api.core.Page)10 ServerException (org.eclipse.che.api.core.ServerException)8 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)8 OrganizationDao (org.eclipse.che.multiuser.organization.spi.OrganizationDao)8 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)7 TypeLiteral (com.google.inject.TypeLiteral)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)6 NotFoundException (org.eclipse.che.api.core.NotFoundException)6 OrganizationDto (org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto)6 UserDevfilePermissionImpl (org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)5 DBInitializer (org.eclipse.che.core.db.DBInitializer)5