use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.
the class JpaUserDevfileDao method getByNamespace.
@Transactional(rollbackOn = { ServerException.class, RuntimeException.class })
@Override
public Page<UserDevfile> getByNamespace(String namespace, int maxItems, long skipCount) throws ServerException {
requireNonNull(namespace, "Required non-null namespace");
try {
final EntityManager manager = managerProvider.get();
final List<UserDevfileImpl> list = manager.createNamedQuery("UserDevfile.getByNamespace", UserDevfileImpl.class).setParameter("namespace", namespace).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList().stream().map(UserDevfileImpl::new).collect(Collectors.toList());
final long count = manager.createNamedQuery("UserDevfile.getByNamespaceCount", Long.class).setParameter("namespace", namespace).getSingleResult();
return new Page<>(list, skipCount, maxItems, count);
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.
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));
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl 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, 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));
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.
the class JpaUserDevfilePermissionDaoTest method shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Database exception")
public void shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod() throws Exception {
// Persist the account
manager.getTransaction().begin();
manager.persist(TestObjectGenerator.TEST_ACCOUNT);
manager.getTransaction().commit();
manager.clear();
final UserDevfileImpl userDevfile = TestObjectGenerator.createUserDevfile();
// Persist the userdevfile
manager.getTransaction().begin();
manager.persist(userDevfile);
manager.getTransaction().commit();
manager.clear();
final UserImpl user = new UserImpl(generate("user", 6), "user0@com.com", "usr0");
// Persist the user
manager.getTransaction().begin();
manager.persist(user);
manager.getTransaction().commit();
manager.clear();
// Persist the worker
UserDevfilePermissionImpl worker = new UserDevfilePermissionImpl(userDevfile.getId(), user.getId(), Collections.singletonList(SET_PERMISSIONS));
manager.getTransaction().begin();
manager.persist(worker);
manager.getTransaction().commit();
manager.clear();
userDevfilePermissionsDao.exists(user.getId(), userDevfile.getId(), SET_PERMISSIONS);
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.
the class UserDevfileManager method createDevfile.
/**
* Stores {@link Devfile} instance
*
* @param userDevfile instance of user devfile which would be stored
* @return new persisted devfile instance
* @throws ConflictException when any conflict occurs (e.g Devfile with such name already exists
* for {@code owner})
* @throws NullPointerException when {@code devfile} is null
* @throws ServerException when any other error occurs
*/
public UserDevfile createDevfile(UserDevfile userDevfile) throws ServerException, NotFoundException, ConflictException {
requireNonNull(userDevfile, "Required non-null userdevfile");
requireNonNull(userDevfile.getDevfile(), "Required non-null devfile");
String name = userDevfile.getName() != null ? userDevfile.getName() : NameGenerator.generate("devfile-", 5);
UserDevfile result = userDevfileDao.create(new UserDevfileImpl(NameGenerator.generate("id-", 16), accountManager.getByName(EnvironmentContext.getCurrent().getSubject().getUserName()), name, userDevfile.getDescription(), userDevfile.getDevfile()));
LOG.debug("UserDevfile '{}' with id '{}' created by user '{}'", result.getName(), result.getId(), EnvironmentContext.getCurrent().getSubject().getUserName());
eventService.publish(new DevfileCreatedEvent(result));
return result;
}
Aggregations