Search in sources :

Example 1 with UserDevfilePermissionImpl

use of org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl in project che-server by eclipse-che.

the class JpaUserDevfilePermissionDao method getByInstance.

@Override
@Transactional
public Page<UserDevfilePermissionImpl> getByInstance(String instanceId, int maxItems, long skipCount) throws ServerException {
    requireNonNull(instanceId, "User devfile identifier required");
    checkArgument(skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE);
    try {
        final EntityManager entityManager = managerProvider.get();
        final List<UserDevfilePermissionImpl> permissions = entityManager.createNamedQuery("UserDevfilePermission.getByUserDevfileId", UserDevfilePermissionImpl.class).setParameter("userDevfileId", instanceId).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList().stream().map(UserDevfilePermissionImpl::new).collect(toList());
        final Long permissionsCount = entityManager.createNamedQuery("UserDevfilePermission.getCountByUserDevfileId", Long.class).setParameter("userDevfileId", instanceId).getSingleResult();
        return new Page<>(permissions, skipCount, maxItems, permissionsCount);
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) Page(org.eclipse.che.api.core.Page) Transactional(com.google.inject.persist.Transactional)

Example 2 with UserDevfilePermissionImpl

use of org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl in project che-server by eclipse-che.

the class UserDevfilePermissionDaoTest method setUp.

@BeforeMethod
public void setUp() throws TckRepositoryException {
    accountRepository.createAll(ImmutableList.of(TestObjectGenerator.TEST_ACCOUNT));
    permissions = new UserDevfilePermissionImpl[] { new UserDevfilePermissionImpl("devfile_id1", "user1", Arrays.asList(READ, DELETE, UPDATE)), new UserDevfilePermissionImpl("devfile_id1", "user2", Arrays.asList(READ, DELETE)), new UserDevfilePermissionImpl("devfile_id2", "user1", Arrays.asList(READ, UPDATE)), new UserDevfilePermissionImpl("devfile_id2", "user2", Arrays.asList(READ, DELETE, UPDATE)), new UserDevfilePermissionImpl("devfile_id2", "user0", Arrays.asList(READ, DELETE, UPDATE)) };
    final UserImpl[] users = new UserImpl[] { new UserImpl("user0", "user0@com.com", "usr0"), new UserImpl("user1", "user1@com.com", "usr1"), new UserImpl("user2", "user2@com.com", "usr2") };
    userRepository.createAll(Arrays.asList(users));
    devfileRepository.createAll(ImmutableList.of(createUserDevfile("devfile_id1", generate("name", 6)), createUserDevfile("devfile_id2", generate("name", 6)), createUserDevfile("devfile_id3", generate("name", 6)), createUserDevfile("devfile_id4", generate("name", 6)), createUserDevfile("devfile_id5", generate("name", 6))));
    permissionTckRepository.createAll(Stream.of(permissions).map(UserDevfilePermissionImpl::new).collect(Collectors.toList()));
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with UserDevfilePermissionImpl

use of org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl in project che-server by eclipse-che.

the class MultiuserJpaUserDevfileDaoTest method setupEntities.

@BeforeClass
public void setupEntities() throws Exception {
    permissions = ImmutableList.of(new UserDevfilePermissionImpl("devfile_id1", "user1", Arrays.asList(READ, DELETE, UPDATE)), new UserDevfilePermissionImpl("devfile_id2", "user1", Arrays.asList(READ, UPDATE)), new UserDevfilePermissionImpl("devfile_id3", "user1", Arrays.asList(DELETE, UPDATE)), new UserDevfilePermissionImpl("devfile_id1", "user2", Arrays.asList(READ, DELETE, UPDATE)));
    users = ImmutableList.of(new UserImpl("user1", "user1@com.com", "usr1"), new UserImpl("user2", "user2@com.com", "usr2"));
    accounts = ImmutableList.of(new AccountImpl("acc-1", NameGenerator.generate("account", 6), "user"), new AccountImpl("acc-2", NameGenerator.generate("account", 6), "user"));
    userDevfiles = ImmutableList.of(createUserDevfile("devfile_id1", accounts.get(0), generate("name", 6)), createUserDevfile("devfile_id2", accounts.get(0), generate("name", 6)), createUserDevfile("devfile_id3", accounts.get(0), generate("name", 6)));
    Injector injector = Guice.createInjector(new UserDevfileTckModule());
    manager = injector.getInstance(EntityManager.class);
    dao = injector.getInstance(MultiuserJpaUserDevfileDao.class);
    tckResourcesCleaner = injector.getInstance(TckResourcesCleaner.class);
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) EntityManager(javax.persistence.EntityManager) Injector(com.google.inject.Injector) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) MultiuserJpaUserDevfileDao(org.eclipse.che.multiuser.permission.devfile.server.spi.jpa.MultiuserJpaUserDevfileDao) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with UserDevfilePermissionImpl

use of org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl in project devspaces-images by redhat-developer.

the class UserDevfileTckModule method configure.

@Override
protected void configure() {
    H2DBTestServer server = H2DBTestServer.startDefault();
    install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(AccountImpl.class, UserImpl.class, WorkspaceImpl.class, WorkspaceConfigImpl.class, ProjectConfigImpl.class, EnvironmentImpl.class, MachineConfigImpl.class, SourceStorageImpl.class, ServerConfigImpl.class, CommandImpl.class, RecipeImpl.class, VolumeImpl.class, // devfile
    UserDevfileImpl.class, UserDevfilePermissionImpl.class, ActionImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class, ComponentImpl.class, DevfileImpl.class, EndpointImpl.class, EntrypointImpl.class, EnvImpl.class, ProjectImpl.class, SourceImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class).addEntityClass("org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute").addClass(SerializableConverter.class).setExceptionHandler(H2ExceptionHandler.class).build());
    bind(DBInitializer.class).asEagerSingleton();
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
    bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
    bind(new TypeLiteral<TckRepository<UserDevfileImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserDevfileImpl.class));
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserImpl.class));
    bind(new TypeLiteral<TckRepository<UserDevfilePermissionImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserDevfilePermissionImpl.class));
    bind(new TypeLiteral<AbstractPermissionsDomain<UserDevfilePermissionImpl>>() {
    }).to(UserDevfilePermissionDaoTest.TestDomain.class);
    bind(UserDevfilePermissionDao.class).to(JpaUserDevfilePermissionDao.class);
    bind(AccountDao.class).to(JpaAccountDao.class);
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) JpaUserDevfilePermissionDao(org.eclipse.che.multiuser.permission.devfile.server.spi.jpa.JpaUserDevfilePermissionDao) UserDevfilePermissionDao(org.eclipse.che.multiuser.permission.devfile.server.spi.UserDevfilePermissionDao) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(org.h2.Driver) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) UserDevfilePermissionDaoTest(org.eclipse.che.multiuser.permission.devfile.server.spi.tck.UserDevfilePermissionDaoTest) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) ProjectImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) AccountDao(org.eclipse.che.account.spi.AccountDao) JpaAccountDao(org.eclipse.che.account.spi.jpa.JpaAccountDao) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SerializableConverter(org.eclipse.che.api.workspace.server.devfile.SerializableConverter) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) SourceImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.SourceImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 5 with UserDevfilePermissionImpl

use of org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl in project devspaces-images by redhat-developer.

the class JpaTckModule method configure.

@Override
protected void configure() {
    H2DBTestServer server = H2DBTestServer.startDefault();
    install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(AccountImpl.class, UserImpl.class, UserDevfilePermissionImpl.class, // devfile
    ActionImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class, ComponentImpl.class, DevfileImpl.class, EndpointImpl.class, EntrypointImpl.class, EnvImpl.class, ProjectImpl.class, SourceImpl.class, UserDevfileImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class).addClass(SerializableConverter.class).setExceptionHandler(H2ExceptionHandler.class).build());
    bind(new TypeLiteral<AbstractPermissionsDomain<UserDevfilePermissionImpl>>() {
    }).to(UserDevfilePermissionDaoTest.TestDomain.class);
    bind(UserDevfilePermissionDao.class).to(JpaUserDevfilePermissionDao.class);
    bind(AccountDao.class).to(JpaAccountDao.class);
    bind(new TypeLiteral<TckRepository<UserDevfilePermission>>() {
    }).toInstance(new JpaTckRepository<>(UserDevfilePermission.class));
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserImpl.class));
    bind(new TypeLiteral<TckRepository<UserDevfileImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserDevfileImpl.class));
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
    bind(DBInitializer.class).asEagerSingleton();
    bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) UserDevfilePermissionDao(org.eclipse.che.multiuser.permission.devfile.server.spi.UserDevfilePermissionDao) AccountImpl(org.eclipse.che.account.spi.AccountImpl) AccountDao(org.eclipse.che.account.spi.AccountDao) JpaAccountDao(org.eclipse.che.account.spi.jpa.JpaAccountDao) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) UserDevfilePermission(org.eclipse.che.multiuser.permission.devfile.server.model.UserDevfilePermission) UserDevfilePermissionDaoTest(org.eclipse.che.multiuser.permission.devfile.server.spi.tck.UserDevfilePermissionDaoTest) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) SerializableConverter(org.eclipse.che.api.workspace.server.devfile.SerializableConverter) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl)

Aggregations

UserDevfilePermissionImpl (org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl)26 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)16 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)12 AccountImpl (org.eclipse.che.account.spi.AccountImpl)10 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)10 TypeLiteral (com.google.inject.TypeLiteral)8 DBInitializer (org.eclipse.che.core.db.DBInitializer)8 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)8 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)8 UserDevfilePermissionDao (org.eclipse.che.multiuser.permission.devfile.server.spi.UserDevfilePermissionDao)8 EntityManager (javax.persistence.EntityManager)6 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)6 OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)6 Test (org.testng.annotations.Test)6 UserDevfilePermission (org.eclipse.che.multiuser.permission.devfile.server.model.UserDevfilePermission)5 JpaUserDevfilePermissionDao (org.eclipse.che.multiuser.permission.devfile.server.spi.jpa.JpaUserDevfilePermissionDao)5 Injector (com.google.inject.Injector)4 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)4 HashMap (java.util.HashMap)4