Search in sources :

Example 56 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.

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;
}
Also used : UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) DevfileCreatedEvent(org.eclipse.che.api.devfile.shared.event.DevfileCreatedEvent)

Example 57 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.

the class JpaUserDevfileDao method doRemove.

@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected void doRemove(String id) throws ServerException {
    final EntityManager manager = managerProvider.get();
    final UserDevfileImpl devfile = manager.find(UserDevfileImpl.class, id);
    if (devfile != null) {
        eventService.publish(new BeforeDevfileRemovedEvent(new UserDevfileImpl(devfile))).propagateException();
        manager.remove(devfile);
        manager.flush();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) BeforeDevfileRemovedEvent(org.eclipse.che.api.devfile.server.event.BeforeDevfileRemovedEvent) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) Transactional(com.google.inject.persist.Transactional)

Example 58 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.

the class JpaUserDevfileDao method doUpdate.

@Transactional
protected Optional<UserDevfileImpl> doUpdate(UserDevfileImpl update) {
    final EntityManager manager = managerProvider.get();
    if (manager.find(UserDevfileImpl.class, update.getId()) == null) {
        return Optional.empty();
    }
    UserDevfileImpl merged = manager.merge(update);
    manager.flush();
    return Optional.of(merged);
}
Also used : EntityManager(javax.persistence.EntityManager) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) Transactional(com.google.inject.persist.Transactional)

Example 59 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.

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);
}
Also used : 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) Test(org.testng.annotations.Test)

Example 60 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.

the class DevfileServiceTest method shouldOverrideIdOnUpdateUserDevfile.

@Test
public void shouldOverrideIdOnUpdateUserDevfile() throws Exception {
    // given
    final UserDevfileDto devfileDto = TestObjectGenerator.createUserDevfileDto();
    final UserDevfileImpl userDevfileImpl = new UserDevfileImpl(devfileDto, TEST_ACCOUNT);
    final String newID = NameGenerator.generate("id", 24);
    final UserDevfileImpl expectedUserDevfileImpl = new UserDevfileImpl(newID, TEST_ACCOUNT, userDevfileImpl);
    final UserDevfileDto expectedDto = org.eclipse.che.api.devfile.server.DtoConverter.asDto(expectedUserDevfileImpl);
    when(userDevfileManager.updateUserDevfile(any(UserDevfile.class))).thenReturn(expectedUserDevfileImpl);
    // when
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(DtoFactory.getInstance().toJson(devfileDto)).when().put(SECURE_PATH + "/devfile/" + newID);
    // then
    assertEquals(response.getStatusCode(), 200);
    assertEquals(new UserDevfileImpl(unwrapDto(response, UserDevfileDto.class), TEST_ACCOUNT), expectedUserDevfileImpl);
    verify(userDevfileManager).updateUserDevfile(expectedDto);
    verify(linksInjector).injectLinks(any(), any());
}
Also used : Response(io.restassured.response.Response) UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserDevfileDto(org.eclipse.che.api.devfile.shared.dto.UserDevfileDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Aggregations

UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)74 Test (org.testng.annotations.Test)46 UserDevfile (org.eclipse.che.api.core.model.workspace.devfile.UserDevfile)28 TestObjectGenerator.createUserDevfile (org.eclipse.che.api.devfile.server.TestObjectGenerator.createUserDevfile)18 AccountImpl (org.eclipse.che.account.spi.AccountImpl)16 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)16 TypeLiteral (com.google.inject.TypeLiteral)14 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)14 DBInitializer (org.eclipse.che.core.db.DBInitializer)14 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)14 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)14 AccountDao (org.eclipse.che.account.spi.AccountDao)12 Response (io.restassured.response.Response)10 JpaAccountDao (org.eclipse.che.account.spi.jpa.JpaAccountDao)10 Pair (org.eclipse.che.commons.lang.Pair)10 PersistTestModuleBuilder (org.eclipse.che.commons.test.db.PersistTestModuleBuilder)10 Transactional (com.google.inject.persist.Transactional)8 EntityManager (javax.persistence.EntityManager)8 UserDevfileDto (org.eclipse.che.api.devfile.shared.dto.UserDevfileDto)8 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)8