Search in sources :

Example 16 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project che-server by eclipse-che.

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, WorkspaceImpl.class, WorkspaceConfigImpl.class, ProjectConfigImpl.class, EnvironmentImpl.class, WorkerImpl.class, MachineConfigImpl.class, SourceStorageImpl.class, ServerConfigImpl.class, CommandImpl.class, RecipeImpl.class, VolumeImpl.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, 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(new TypeLiteral<AbstractPermissionsDomain<WorkerImpl>>() {
    }).to(WorkerDaoTest.TestDomain.class);
    bind(WorkerDao.class).to(JpaWorkerDao.class);
    bind(new TypeLiteral<TckRepository<WorkerImpl>>() {
    }).toInstance(new JpaTckRepository<>(WorkerImpl.class));
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserImpl.class));
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {
    }).toInstance(new JpaTckRepository<>(WorkspaceImpl.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) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(org.h2.Driver) WorkerDaoTest(org.eclipse.che.multiuser.permission.workspace.server.spi.tck.WorkerDaoTest) 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) WorkerDao(org.eclipse.che.multiuser.permission.workspace.server.spi.WorkerDao) 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) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) 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) 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) WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 17 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project che-server by eclipse-che.

the class JpaWorkerDao method get.

@Override
public WorkerImpl get(String userId, String instanceId) throws ServerException, NotFoundException {
    requireNonNull(instanceId, "Workspace identifier required");
    requireNonNull(userId, "User identifier required");
    try {
        return new WorkerImpl(getEntity(wildcardToNull(userId), instanceId));
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl)

Example 18 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project che-server by eclipse-che.

the class JpaWorkerDao method getByInstance.

@Override
@Transactional
public Page<WorkerImpl> getByInstance(String instanceId, int maxItems, long skipCount) throws ServerException {
    requireNonNull(instanceId, "Workspace 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<WorkerImpl> workers = entityManager.createNamedQuery("Worker.getByWorkspaceId", WorkerImpl.class).setParameter("workspaceId", instanceId).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList().stream().map(WorkerImpl::new).collect(toList());
        final Long workersCount = entityManager.createNamedQuery("Worker.getCountByWorkspaceId", Long.class).setParameter("workspaceId", instanceId).getSingleResult();
        return new Page<>(workers, skipCount, maxItems, workersCount);
    } 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) WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl) Transactional(com.google.inject.persist.Transactional)

Example 19 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project che-server by eclipse-che.

the class WorkerDaoTest method shouldStoreWorker.

/* WorkerDao.store() tests */
@Test
public void shouldStoreWorker() throws Exception {
    WorkerImpl worker = new WorkerImpl("ws0", "user0", Arrays.asList("read", "use", "run"));
    workerDao.store(worker);
    Assert.assertEquals(workerDao.getWorker("ws0", "user0"), new WorkerImpl(worker));
}
Also used : WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl) Test(org.testng.annotations.Test)

Example 20 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project che-server by eclipse-che.

the class WorkerDaoTest method shouldReplaceExistingWorkerOnStoring.

@Test
public void shouldReplaceExistingWorkerOnStoring() throws Exception {
    WorkerImpl replace = new WorkerImpl("ws1", "user1", Collections.singletonList("read"));
    workerDao.store(replace);
    Assert.assertEquals(workerDao.getWorker("ws1", "user1"), replace);
}
Also used : WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl) Test(org.testng.annotations.Test)

Aggregations

WorkerImpl (org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl)26 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)18 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)18 AccountImpl (org.eclipse.che.account.spi.AccountImpl)16 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)12 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)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 WorkerDao (org.eclipse.che.multiuser.permission.workspace.server.spi.WorkerDao)8 WorkerDaoTest (org.eclipse.che.multiuser.permission.workspace.server.spi.tck.WorkerDaoTest)8 JpaWorkerDao (org.eclipse.che.multiuser.permission.workspace.server.spi.jpa.JpaWorkerDao)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)4 HashMap (java.util.HashMap)4 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)4 SerializableConverter (org.eclipse.che.api.workspace.server.devfile.SerializableConverter)4 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)4 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)4 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)4