Search in sources :

Example 6 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor in project che by eclipse.

the class RecipePartPresenter method onCloneButtonClicked.

/** {@inheritDoc} */
@Override
public void onCloneButtonClicked() {
    RecipeDescriptor selectedRecipeDescriptor = recipes.get(selectedRecipe);
    String recipeName = NameGenerator.generateCopy(selectedRecipeDescriptor.getName(), recipes.keySet());
    NewRecipe newRecipe = dtoFactory.createDto(NewRecipe.class).withType(selectedRecipeDescriptor.getType()).withScript(selectedRecipeDescriptor.getScript()).withName(recipeName).withTags(selectedRecipeDescriptor.getTags());
    createRecipe(newRecipe);
}
Also used : RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe)

Example 7 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor in project che by eclipse.

the class RecipesContainerPresenter method addRecipePanel.

/**
     * Adds new recipe panel to container.
     *
     * @param recipe
     *         current recipe widget
     */
public void addRecipePanel(@NotNull RecipeWidget recipe) {
    if (recipePanels.get(recipe) != null) {
        return;
    }
    RecipeEditorPanel editorPanel = entityFactory.createRecipeEditorPanel(recipe.getDescriptor());
    recipePanels.put(recipe, editorPanel);
    RecipeEditorView editorView = ((RecipeEditorView) editorPanel.getView());
    RecipeDescriptor recipeDescriptor = recipe.getDescriptor();
    editorView.setScriptUrl(recipeDescriptor.getLink("get recipe script").getHref());
    editorView.setTags(recipeDescriptor.getTags());
    editorView.setName(recipeDescriptor.getName());
}
Also used : RecipeEditorPanel(org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.editor.RecipeEditorPanel) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) RecipeEditorView(org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.editor.RecipeEditorView)

Example 8 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor in project che by eclipse.

the class NameGeneratorTest method generateCustomRecipeName3.

@Test
public void generateCustomRecipeName3() throws Exception {
    String newName = "RECIPE-11";
    RecipeWidget environment3 = mock(RecipeWidget.class);
    RecipeWidget environment4 = mock(RecipeWidget.class);
    RecipeWidget environment5 = mock(RecipeWidget.class);
    RecipeWidget environment6 = mock(RecipeWidget.class);
    RecipeWidget environment7 = mock(RecipeWidget.class);
    RecipeWidget environment8 = mock(RecipeWidget.class);
    RecipeWidget environment9 = mock(RecipeWidget.class);
    RecipeWidget environment10 = mock(RecipeWidget.class);
    RecipeDescriptor recipeDescriptor3 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor4 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor5 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor6 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor7 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor8 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor9 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor10 = mock(RecipeDescriptor.class);
    when(recipe1.getDescriptor()).thenReturn(recipeDescriptor1);
    when(recipe2.getDescriptor()).thenReturn(recipeDescriptor2);
    when(environment3.getDescriptor()).thenReturn(recipeDescriptor3);
    when(environment4.getDescriptor()).thenReturn(recipeDescriptor4);
    when(environment5.getDescriptor()).thenReturn(recipeDescriptor5);
    when(environment6.getDescriptor()).thenReturn(recipeDescriptor6);
    when(environment7.getDescriptor()).thenReturn(recipeDescriptor7);
    when(environment8.getDescriptor()).thenReturn(recipeDescriptor8);
    when(environment9.getDescriptor()).thenReturn(recipeDescriptor9);
    when(environment10.getDescriptor()).thenReturn(recipeDescriptor10);
    when(recipeDescriptor1.getName()).thenReturn("RECIPE-1");
    when(recipeDescriptor2.getName()).thenReturn("RECIPE-2");
    when(recipeDescriptor3.getName()).thenReturn("RECIPE-3");
    when(recipeDescriptor4.getName()).thenReturn("RECIPE-4");
    when(recipeDescriptor5.getName()).thenReturn("RECIPE-5");
    when(recipeDescriptor6.getName()).thenReturn("RECIPE-6");
    when(recipeDescriptor7.getName()).thenReturn("RECIPE-7");
    when(recipeDescriptor8.getName()).thenReturn("RECIPE-8");
    when(recipeDescriptor9.getName()).thenReturn("RECIPE-9");
    when(recipeDescriptor10.getName()).thenReturn("RECIPE-10");
    HashSet<RecipeWidget> recipes = new HashSet<>(Arrays.asList(recipe1, recipe2, environment3, environment4, environment5, environment6, environment7, environment8, environment9, environment10));
    String generated = NameGenerator.generateCustomRecipeName(recipes);
    assertEquals(newName, generated);
}
Also used : RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) RecipeWidget(org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.entry.RecipeWidget) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor in project che by eclipse.

the class RecipeService method asRecipeDescriptor.

/**
     * Transforms {@link ManagedRecipe} to {@link RecipeDescriptor}.
     */
private RecipeDescriptor asRecipeDescriptor(ManagedRecipe recipe) {
    final RecipeDescriptor descriptor = DtoFactory.getInstance().createDto(RecipeDescriptor.class).withId(recipe.getId()).withName(recipe.getName()).withType(recipe.getType()).withScript(recipe.getScript()).withCreator(recipe.getCreator()).withTags(recipe.getTags());
    final UriBuilder builder = getServiceContext().getServiceUriBuilder();
    final Link removeLink = LinksHelper.createLink("DELETE", builder.clone().path(getClass(), "removeRecipe").build(recipe.getId()).toString(), LINK_REL_REMOVE_RECIPE);
    final Link scriptLink = LinksHelper.createLink("GET", builder.clone().path(getClass(), "getRecipeScript").build(recipe.getId()).toString(), TEXT_PLAIN, LINK_REL_GET_RECIPE_SCRIPT);
    descriptor.setLinks(asList(scriptLink, removeLink));
    return descriptor;
}
Also used : RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink)

Example 10 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor in project che by eclipse.

the class RecipeServiceTest method shouldBeAbleToGetRecipe.

@Test
public void shouldBeAbleToGetRecipe() throws Exception {
    final RecipeImpl recipe = new RecipeImpl().withCreator("someone2").withId("recipe123").withName("name").withType("docker").withScript("FROM ubuntu\n").withTags(asList("java", "mognodb"));
    when(recipeDao.getById(recipe.getId())).thenReturn(recipe);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/recipe/" + recipe.getId());
    assertEquals(response.getStatusCode(), 200);
    final RecipeDescriptor descriptor = unwrapDto(response, RecipeDescriptor.class);
    assertEquals(descriptor.getId(), recipe.getId());
    assertEquals(descriptor.getName(), recipe.getName());
    assertEquals(descriptor.getType(), recipe.getType());
    assertEquals(descriptor.getScript(), recipe.getScript());
    assertEquals(descriptor.getTags(), recipe.getTags());
    assertEquals(descriptor.getCreator(), recipe.getCreator());
}
Also used : Response(com.jayway.restassured.response.Response) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) Test(org.testng.annotations.Test)

Aggregations

RecipeDescriptor (org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor)15 OperationException (org.eclipse.che.api.promises.client.OperationException)6 ArrayList (java.util.ArrayList)4 NewRecipe (org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 Response (com.jayway.restassured.response.Response)2 List (java.util.List)2 RecipeUpdate (org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate)2 RecipeEditorPanel (org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.editor.RecipeEditorPanel)2 Test (org.testng.annotations.Test)2 JSONObject (com.google.gwt.json.client.JSONObject)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 Machine (org.eclipse.che.api.core.model.machine.Machine)1 MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)1 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)1 Link (org.eclipse.che.api.core.rest.shared.dto.Link)1 Operation (org.eclipse.che.api.promises.client.Operation)1