use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.
the class UserDevfileDaoTest method shouldThrowConflictExceptionWhenCreatingUserDevfileWithExistingId.
@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionWhenCreatingUserDevfileWithExistingId() throws Exception {
// given
final UserDevfileImpl devfile = createUserDevfile(accounts[0]);
final UserDevfileImpl existing = devfiles[0];
devfile.setId(existing.getId());
// when
userDevfileDaoDao.create(devfile);
// then
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.
the class UserDevfileDaoTest method shouldBeAbleToGetAvailableToUserDevfilesWithFilterAndLimit.
@Test
public void shouldBeAbleToGetAvailableToUserDevfilesWithFilterAndLimit() throws ServerException, NotFoundException, ConflictException {
// given
final UserDevfileImpl update = devfiles[0];
update.setName("New345Name");
userDevfileDaoDao.update(update);
// when
final Page<UserDevfile> result = userDevfileDaoDao.getDevfiles(12, 0, ImmutableList.of(new Pair<>("name", "like:devfileName%")), Collections.emptyList());
// then
assertEquals(result.getItems().size(), 9);
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.
the class UserDevfileDaoTest method shouldCreateUserDevfile.
@Test(dependsOnMethods = "shouldGetUserDevfileById")
public void shouldCreateUserDevfile() throws Exception {
// given
final UserDevfileImpl devfile = createUserDevfile(accounts[0]);
// when
userDevfileDaoDao.create(devfile);
assertEquals(userDevfileDaoDao.getById(devfile.getId()), Optional.of(new UserDevfileImpl(devfile)));
}
use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project devspaces-images by redhat-developer.
the class JpaUserDevfileDao method doGetDevfiles.
@Transactional(rollbackOn = { ServerException.class })
protected Page<UserDevfile> doGetDevfiles(int maxItems, int skipCount, List<Pair<String, String>> filter, List<Pair<String, String>> order, Supplier<UserDevfileSearchQueryBuilder> queryBuilderSupplier) throws ServerException {
if (filter != null && !filter.isEmpty()) {
List<Pair<String, String>> invalidFilter = filter.stream().filter(p -> !VALID_SEARCH_FIELDS.contains(p.first.toLowerCase())).collect(toList());
if (!invalidFilter.isEmpty()) {
throw new IllegalArgumentException("Filtering allowed only by " + VALID_SEARCH_FIELDS + " but got: " + invalidFilter);
}
}
List<Pair<String, String>> effectiveOrder = DEFAULT_ORDER;
if (order != null && !order.isEmpty()) {
List<Pair<String, String>> invalidOrder = order.stream().filter(p -> !VALID_ORDER_FIELDS.contains(p.first.toLowerCase())).collect(toList());
if (!invalidOrder.isEmpty()) {
throw new IllegalArgumentException("Order allowed only by " + VALID_ORDER_FIELDS + "¬ but got: " + invalidOrder);
}
List<Pair<String, String>> invalidSortOrder = order.stream().filter(p -> !p.second.equalsIgnoreCase("asc") && !p.second.equalsIgnoreCase("desc")).collect(Collectors.toList());
if (!invalidSortOrder.isEmpty()) {
throw new IllegalArgumentException("Invalid sort order direction. Possible values are 'asc' or 'desc' but got: " + invalidSortOrder);
}
effectiveOrder = order;
}
try {
final long count = queryBuilderSupplier.get().withFilter(filter).buildCountQuery().getSingleResult();
if (count == 0) {
return new Page<>(emptyList(), skipCount, maxItems, count);
}
List<UserDevfileImpl> result = queryBuilderSupplier.get().withFilter(filter).withOrder(effectiveOrder).withMaxItems(maxItems).withSkipCount(skipCount).buildSelectItemsQuery().getResultList().stream().map(UserDevfileImpl::new).collect(toList());
return new Page<>(result, 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 devspaces-images by redhat-developer.
the class JpaUserDevfileDao method create.
@Override
public UserDevfile create(UserDevfile userDevfile) throws ConflictException, ServerException {
requireNonNull(userDevfile);
try {
Account account = accountDao.getByName(userDevfile.getNamespace());
UserDevfileImpl userDevfileImpl = new UserDevfileImpl(userDevfile, account);
doCreate(userDevfileImpl);
return userDevfileImpl;
} catch (DuplicateKeyException ex) {
throw new ConflictException(format("Devfile with name '%s' already exists in the specified account '%s'", userDevfile.getName(), userDevfile.getNamespace()));
} catch (IntegrityConstraintViolationException ex) {
throw new ConflictException("Could not create devfile with creator that refers to a non-existent user");
} catch (RuntimeException ex) {
throw new ServerException(ex.getMessage(), ex);
} catch (NotFoundException e) {
throw new ConflictException(format("Not able to create devfile in requested namespace %s bacause it is not found", userDevfile.getNamespace()));
}
}
Aggregations