Search in sources :

Example 31 with MemberImpl

use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project devspaces-images by redhat-developer.

the class MemberDaoTest method shouldGetMember.

@Test
public void shouldGetMember() throws Exception {
    final MemberImpl existedMember = members[0];
    final MemberImpl fetchedMember = memberDao.getMember(existedMember.getOrganizationId(), existedMember.getUserId());
    assertEquals(existedMember, fetchedMember);
}
Also used : MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl) Test(org.testng.annotations.Test)

Example 32 with MemberImpl

use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project devspaces-images by redhat-developer.

the class JpaMemberDao method doRemove.

@Override
@Transactional
protected void doRemove(String organizationId, String userId) {
    final EntityManager manager = managerProvider.get();
    List<MemberImpl> members = manager.createNamedQuery("Member.getMember", MemberImpl.class).setParameter("userId", userId).setParameter("organizationId", organizationId).getResultList();
    if (!members.isEmpty()) {
        manager.remove(members.get(0));
        manager.flush();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl) Transactional(com.google.inject.persist.Transactional)

Example 33 with MemberImpl

use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project devspaces-images by redhat-developer.

the class JpaMemberDao method getMembers.

@Override
@Transactional
public Page<MemberImpl> getMembers(String organizationId, int maxItems, long skipCount) throws ServerException {
    requireNonNull(organizationId, "Required non-null organization 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<MemberImpl> members = manager.createNamedQuery("Member.getByOrganization", MemberImpl.class).setParameter("organizationId", organizationId).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList().stream().map(MemberImpl::new).collect(toList());
        final Long membersCount = manager.createNamedQuery("Member.getCountByOrganizationId", Long.class).setParameter("organizationId", organizationId).getSingleResult();
        return new Page<>(members, skipCount, maxItems, membersCount);
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl) Page(org.eclipse.che.api.core.Page) Transactional(com.google.inject.persist.Transactional)

Example 34 with MemberImpl

use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project devspaces-images by redhat-developer.

the class JpaMemberDao method getMember.

@Override
public MemberImpl getMember(String organizationId, String userId) throws NotFoundException, ServerException {
    requireNonNull(organizationId, "Required non-null organization id");
    requireNonNull(userId, "Required non-null user id");
    try {
        return new MemberImpl(getEntity(wildcardToNull(userId), organizationId));
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)

Example 35 with MemberImpl

use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project devspaces-images by redhat-developer.

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)

Aggregations

MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)36 Test (org.testng.annotations.Test)18 OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)14 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)8 TypeLiteral (com.google.inject.TypeLiteral)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)6 DBInitializer (org.eclipse.che.core.db.DBInitializer)6 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)6 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)6 MemberDao (org.eclipse.che.multiuser.organization.spi.MemberDao)6 OrganizationDao (org.eclipse.che.multiuser.organization.spi.OrganizationDao)6 OrganizationDistributedResourcesDao (org.eclipse.che.multiuser.organization.spi.OrganizationDistributedResourcesDao)6 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)6 JpaMemberDao (org.eclipse.che.multiuser.organization.spi.jpa.JpaMemberDao)6 JpaOrganizationDao (org.eclipse.che.multiuser.organization.spi.jpa.JpaOrganizationDao)6 JpaOrganizationDistributedResourcesDao (org.eclipse.che.multiuser.organization.spi.jpa.JpaOrganizationDistributedResourcesDao)6 UserDevfilePermissionImpl (org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl)6 Transactional (com.google.inject.persist.Transactional)4 HashMap (java.util.HashMap)4