use of com.google.gson.reflect.TypeToken in project che by eclipse.
the class StackLoader method start.
/**
* Load predefined stacks with their icons to the {@link StackDao}.
*/
@PostConstruct
public void start() {
if (Files.exists(stackJsonPath) && Files.isRegularFile(stackJsonPath)) {
try (BufferedReader reader = Files.newBufferedReader(stackJsonPath)) {
List<StackImpl> stacks = GSON.fromJson(reader, new TypeToken<List<StackImpl>>() {
}.getType());
stacks.forEach(this::loadStack);
} catch (Exception e) {
LOG.error("Failed to store stacks ", e);
}
}
}
use of com.google.gson.reflect.TypeToken in project che by eclipse.
the class WorkspaceServiceTest method shouldBeAbleToGetSettings.
@Test
public void shouldBeAbleToGetSettings() throws Exception {
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/settings");
assertEquals(response.getStatusCode(), 200);
final Map<String, String> settings = new Gson().fromJson(response.print(), new TypeToken<Map<String, String>>() {
}.getType());
assertEquals(settings, //
ImmutableMap.of(//
"che.workspace.auto_snapshot", //
"true", //
"che.workspace.auto_restore", //
"false", "che.workspace.auto_start", "true"));
}
use of com.google.gson.reflect.TypeToken in project che by eclipse.
the class UserServiceTest method shouldBeAbleToGetSettings.
@Test
public void shouldBeAbleToGetSettings() throws Exception {
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/user/settings");
assertEquals(response.getStatusCode(), 200);
final Map<String, String> settings = new Gson().fromJson(response.print(), new TypeToken<Map<String, String>>() {
}.getType());
assertEquals(settings, ImmutableMap.of("che.auth.user_self_creation", "true"));
}
use of com.google.gson.reflect.TypeToken in project zeppelin by apache.
the class ZeppelinRestApiTest method testexportNote.
@Test
public void testexportNote() throws IOException {
LOG.info("testexportNote");
Note note = ZeppelinServer.notebook.createNote(anonymous);
assertNotNull("can't create new note", note);
note.setName("source note for export");
Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config = paragraph.getConfig();
config.put("enabled", true);
paragraph.setConfig(config);
paragraph.setText("%md This is my new paragraph in my new note");
note.persist(anonymous);
String sourceNoteId = note.getId();
// Call export Note REST API
GetMethod get = httpGet("/notebook/export/" + sourceNoteId);
LOG.info("testNoteExport \n" + get.getResponseBodyAsString());
assertThat("test note export method:", get, isAllowed());
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
String exportJSON = (String) resp.get("body");
assertNotNull("Can not find new notejson", exportJSON);
LOG.info("export JSON:=" + exportJSON);
ZeppelinServer.notebook.removeNote(sourceNoteId, anonymous);
get.releaseConnection();
}
use of com.google.gson.reflect.TypeToken in project zeppelin by apache.
the class NotebookServer method saveInterpreterBindings.
public void saveInterpreterBindings(NotebookSocket conn, Message fromMessage) {
String noteId = (String) fromMessage.data.get("noteId");
try {
List<String> settingIdList = gson.fromJson(String.valueOf(fromMessage.data.get("selectedSettingIds")), new TypeToken<ArrayList<String>>() {
}.getType());
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
notebook().bindInterpretersToNote(subject.getUser(), noteId, settingIdList);
broadcastInterpreterBindings(noteId, InterpreterBindingUtils.getInterpreterBindings(notebook(), noteId));
} catch (Exception e) {
LOG.error("Error while saving interpreter bindings", e);
}
}
Aggregations