use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate in project che by eclipse.
the class SshCategoryPresenter method updateTargetRecipe.
/**
* Updates as existent target recipe and save it.
*/
private void updateTargetRecipe() {
RecipeUpdate recipeUpdate = dtoFactory.createDto(RecipeUpdate.class).withId(selectedTarget.getRecipe().getId()).withName(sshView.getTargetName()).withType(selectedTarget.getRecipe().getType()).withTags(selectedTarget.getRecipe().getTags()).withDescription(selectedTarget.getRecipe().getDescription()).withScript("{" + "\"host\": \"" + selectedTarget.getHost() + "\", " + "\"port\": \"" + selectedTarget.getPort() + "\", " + "\"username\": \"" + selectedTarget.getUserName() + "\", " + "\"password\": \"" + selectedTarget.getPassword() + "\"" + "}");
Promise<RecipeDescriptor> updateRecipe = recipeServiceClient.updateRecipe(recipeUpdate);
updateRecipe.then(new Operation<RecipeDescriptor>() {
@Override
public void apply(RecipeDescriptor recipe) throws OperationException {
onTargetSaved(recipe);
}
});
updateRecipe.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
dialogFactory.createMessageDialog("Error", machineLocale.targetsViewSaveError(), null).show();
}
});
}
use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate in project che by eclipse.
the class RecipePartPresenter method onSaveButtonClicked.
/** {@inheritDoc} */
@Override
public void onSaveButtonClicked() {
RecipeEditorPanel editorPanel = recipesContainerPresenter.getEditorPanel(selectedRecipe);
RecipeDescriptor recipeDescriptor = selectedRecipe.getDescriptor();
final RecipeUpdate recipeUpdate = dtoFactory.createDto(RecipeUpdate.class).withId(recipeDescriptor.getId()).withType(recipeDescriptor.getType()).withScript(editorPanel.getScript()).withName(editorPanel.getName()).withTags(editorPanel.getTags());
Promise<RecipeDescriptor> updateRecipe = service.updateRecipe(recipeUpdate);
updateRecipe.then(new Operation<RecipeDescriptor>() {
@Override
public void apply(RecipeDescriptor recipeDescriptor) throws OperationException {
RecipeDescriptor selectedRecipeDescriptor = recipes.get(selectedRecipe);
selectedRecipeDescriptor.setScript(recipeDescriptor.getScript());
selectedRecipeDescriptor.setTags(recipeDescriptor.getTags());
selectedRecipeDescriptor.setName(recipeDescriptor.getName());
selectedRecipe.setName(recipeDescriptor.getName());
notificationManager.notify("Recipe \"" + recipeDescriptor.getName() + "\" was saved.");
}
});
updateRecipe.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (arg.getMessage() != null) {
notificationManager.notify(locale.failedToSaveRecipe(), arg.getMessage(), FAIL, FLOAT_MODE);
}
}
});
}
use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate in project che by eclipse.
the class RecipeServiceTest method shouldBeAbleToUpdateRecipe.
@Test
public void shouldBeAbleToUpdateRecipe() throws Exception {
final RecipeImpl recipe = new RecipeImpl().withId("id").withCreator(USER_ID).withType("docker").withScript("script1 content").withTags(asList("java"));
final RecipeImpl updatedRecipe = new RecipeImpl(recipe).withType("new-type").withScript("new script content").withTags(asList("java", "mongodb"));
when(recipeDao.update(any())).thenReturn(updatedRecipe);
RecipeUpdate update = newDto(RecipeUpdate.class).withId(recipe.getId()).withType("new-type").withScript("new script content").withTags(asList("java", "mongodb"));
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(update).when().put(SECURE_PATH + "/recipe");
assertEquals(response.getStatusCode(), 200);
verify(recipeDao).update(any(RecipeImpl.class));
}
use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate in project che by eclipse.
the class RecipePartPresenterTest method recipeShouldBeSaved.
@Test
public void recipeShouldBeSaved() throws Exception {
NewRecipe newRecipe = mock(NewRecipe.class);
List<String> tags = Collections.singletonList("tag");
when(dtoFactory.createDto(NewRecipe.class)).thenReturn(newRecipe);
when(newRecipe.withType(anyString())).thenReturn(newRecipe);
when(newRecipe.withScript(anyString())).thenReturn(newRecipe);
when(newRecipe.withName(anyString())).thenReturn(newRecipe);
when(newRecipe.withTags(Matchers.<List<String>>any())).thenReturn(newRecipe);
when(service.createRecipe(newRecipe)).thenReturn(recipeDescriptorPromise);
when(recipesContainerPresenter.getEditorPanel(Matchers.<RecipeWidget>any())).thenReturn(recipeEditorPanel);
RecipeUpdate recipeUpdate = mock(RecipeUpdate.class);
when(dtoFactory.createDto(RecipeUpdate.class)).thenReturn(recipeUpdate);
when(recipeUpdate.withType(anyString())).thenReturn(recipeUpdate);
when(recipeUpdate.withId(anyString())).thenReturn(recipeUpdate);
when(recipeUpdate.withScript(anyString())).thenReturn(recipeUpdate);
when(recipeUpdate.withName(anyString())).thenReturn(recipeUpdate);
when(recipeUpdate.withTags(Matchers.<List<String>>any())).thenReturn(recipeUpdate);
when(recipeDescriptor1.getId()).thenReturn("id");
when(recipeDescriptor1.getName()).thenReturn("name");
when(recipeDescriptor1.getScript()).thenReturn("script");
when(recipeDescriptor1.getTags()).thenReturn(tags);
when(service.updateRecipe(recipeUpdate)).thenReturn(savedRecipeDescriptorPromise);
when(recipeDescriptor1.getType()).thenReturn(RECIPE_TYPE);
when(recipeEditorPanel.getScript()).thenReturn("script");
when(recipeEditorPanel.getTags()).thenReturn(tags);
when(recipeEditorPanel.getName()).thenReturn("name");
recipePartPresenter.onNewButtonClicked();
verify(recipeDescriptorPromise).then(operationDescriptorCaptor.capture());
operationDescriptorCaptor.getValue().apply(recipeDescriptor1);
recipePartPresenter.onSaveButtonClicked();
verify(service).updateRecipe(recipeUpdate);
verify(savedRecipeDescriptorPromise).then(savedDescriptorCaptor.capture());
savedDescriptorCaptor.getValue().apply(recipeDescriptor1);
verify(recipeDescriptor1).setScript("script");
verify(recipeDescriptor1).setTags(recipeDescriptor1.getTags());
verify(notificationManager).notify(eq("Recipe \"name\" was saved."));
}
Aggregations