Search in sources :

Example 26 with UserDevfilePermissionImpl

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

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)

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