use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.
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();
}
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.
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 DevfileServiceTest method shouldGetUserDevfileById.
@Test
public void shouldGetUserDevfileById() throws Exception {
final UserDevfileImpl userDevfile = TestObjectGenerator.createUserDevfile();
when(userDevfileManager.getById(eq("id-22323"))).thenReturn(userDevfile);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/devfile/id-22323").then().extract().response();
assertEquals(response.getStatusCode(), 200);
assertEquals(new UserDevfileImpl(unwrapDto(response, UserDevfileDto.class), TEST_ACCOUNT), userDevfile);
verify(userDevfileManager).getById(eq("id-22323"));
verify(linksInjector).injectLinks(any(), any());
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.
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());
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.
the class DevfileServiceTest method shouldGetUserDevfilesAvailableToUser.
@Test
public void shouldGetUserDevfilesAvailableToUser() throws Exception {
// given
final UserDevfileDto devfileDto = TestObjectGenerator.createUserDevfileDto();
final UserDevfileImpl userDevfileImpl = new UserDevfileImpl(devfileDto, TEST_ACCOUNT);
doReturn(new Page<>(ImmutableList.of(userDevfileImpl), 0, 1, 1)).when(userDevfileManager).getUserDevfiles(anyInt(), anyInt(), anyList(), anyList());
// when
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/devfile/search").then().extract().response();
// then
assertEquals(response.getStatusCode(), 200);
final List<UserDevfileDto> res = unwrapDtoList(response, UserDevfileDto.class);
assertEquals(res.size(), 1);
assertEquals(res.get(0).withLinks(emptyList()), devfileDto);
verify(userDevfileManager).getUserDevfiles(eq(30), eq(0), anyList(), anyList());
}
Aggregations