use of org.eclipse.che.api.machine.server.recipe.RecipeImpl in project che by eclipse.
the class RecipeDaoTest method shouldFindRecipeByType.
@Test(dependsOnMethods = "shouldFindRecipeByUser")
public void shouldFindRecipeByType() throws Exception {
final RecipeImpl recipe = recipes.get(0);
final List<RecipeImpl> result = recipeDao.search(null, null, recipe.getType(), 0, recipes.size());
assertTrue(result.contains(recipe));
}
use of org.eclipse.che.api.machine.server.recipe.RecipeImpl in project che by eclipse.
the class RecipeDownloader method getRecipe.
/**
* Downloads recipe by location from {@link MachineSource#getLocation()}.
*
* @param machineConfig
* config used to get recipe location
* @return recipe with set content and type
* @throws MachineException
* if any error occurs
*/
public RecipeImpl getRecipe(MachineConfig machineConfig) throws MachineException {
URL recipeUrl;
File file = null;
final String location = machineConfig.getSource().getLocation();
try {
UriBuilder targetUriBuilder = UriBuilder.fromUri(location);
// add user token to be able to download user's private recipe
final URI recipeUri = targetUriBuilder.build();
if (!recipeUri.isAbsolute() && recipeUri.getHost() == null) {
targetUriBuilder.scheme(apiEndpoint.getScheme()).host(apiEndpoint.getHost()).port(apiEndpoint.getPort()).replacePath(apiEndpoint.getPath() + location);
if (EnvironmentContext.getCurrent().getSubject().getToken() != null) {
targetUriBuilder.queryParam("token", EnvironmentContext.getCurrent().getSubject().getToken());
}
}
recipeUrl = targetUriBuilder.build().toURL();
file = IoUtil.downloadFileWithRedirect(null, "recipe", null, recipeUrl);
return new RecipeImpl().withType(machineConfig.getSource().getType()).withScript(IoUtil.readAndCloseQuietly(new FileInputStream(file)));
} catch (IOException | IllegalArgumentException e) {
throw new MachineException(format("Failed to download recipe for machine %s. Recipe url %s. Error: %s", machineConfig.getName(), location, e.getLocalizedMessage()));
} finally {
if (file != null && !file.delete()) {
LOG.error(String.format("Removal of recipe file %s failed.", file.getAbsolutePath()));
}
}
}
use of org.eclipse.che.api.machine.server.recipe.RecipeImpl in project che by eclipse.
the class JpaRecipeDao method search.
@Override
@Transactional
public List<RecipeImpl> search(String user, List<String> tags, String type, int skipCount, int maxItems) throws ServerException {
try {
final EntityManager manager = managerProvider.get();
final CriteriaBuilder cb = manager.getCriteriaBuilder();
final CriteriaQuery<RecipeImpl> query = cb.createQuery(RecipeImpl.class);
final Root<RecipeImpl> fromRecipe = query.from(RecipeImpl.class);
final ParameterExpression<String> typeParam = cb.parameter(String.class, "recipeType");
final Predicate checkType = cb.or(cb.isNull(typeParam), cb.equal(fromRecipe.get("type"), typeParam));
final TypedQuery<RecipeImpl> typedQuery;
if (tags != null && !tags.isEmpty()) {
final Join<RecipeImpl, String> tag = fromRecipe.join("tags");
query.select(cb.construct(RecipeImpl.class, tag.getParent())).where(cb.and(checkType, tag.in(tags))).groupBy(fromRecipe.get("id")).having(cb.equal(cb.count(tag), tags.size()));
typedQuery = manager.createQuery(query).setParameter("tags", tags);
} else {
typedQuery = manager.createQuery(query.where(checkType));
}
return typedQuery.setParameter("recipeType", type).setFirstResult(skipCount).setMaxResults(maxItems).getResultList();
} catch (RuntimeException ex) {
throw new ServerException(ex.getLocalizedMessage(), ex);
}
}
use of org.eclipse.che.api.machine.server.recipe.RecipeImpl in project che by eclipse.
the class RecipeDaoTest method shouldFindRecipeByUserTagsAndType.
@Test(dependsOnMethods = { "shouldFindRecipeByUser", "shouldFindingRecipesByTags", "shouldFindRecipeByType" })
public void shouldFindRecipeByUserTagsAndType() throws Exception {
final RecipeImpl recipe = recipes.get(0);
final List<RecipeImpl> result = recipeDao.search(null, recipe.getTags(), recipe.getType(), 0, 1);
assertTrue(result.contains(recipe));
}
use of org.eclipse.che.api.machine.server.recipe.RecipeImpl in project che by eclipse.
the class RecipeDaoTest method shouldUpdateRecipeWithAllRelatedAttributes.
@Test
public void shouldUpdateRecipeWithAllRelatedAttributes() throws Exception {
final RecipeImpl update = recipes.get(0);
update.withName("debian").withCreator("userid_9").withDescription("description").withType("docker").setScript("FROM codenvy/debian_jdk8");
recipeDao.update(update);
assertEquals(recipeDao.getById(update.getId()), update);
}
Aggregations