Search in sources :

Example 1 with TypeToken

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);
        }
    }
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) TypeToken(com.google.gson.reflect.TypeToken) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) PostConstruct(javax.annotation.PostConstruct)

Example 2 with TypeToken

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"));
}
Also used : Response(com.jayway.restassured.response.Response) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 3 with TypeToken

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"));
}
Also used : Response(com.jayway.restassured.response.Response) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) Test(org.testng.annotations.Test)

Example 4 with TypeToken

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();
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 5 with TypeToken

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);
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) URISyntaxException(java.net.URISyntaxException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)418 Gson (com.google.gson.Gson)178 Test (org.junit.Test)99 IOException (java.io.IOException)83 Map (java.util.Map)71 List (java.util.List)56 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)54 ArrayList (java.util.ArrayList)53 HashMap (java.util.HashMap)52 GsonBuilder (com.google.gson.GsonBuilder)45 File (java.io.File)34 Notebook (org.apache.zeppelin.notebook.Notebook)32 Type (java.lang.reflect.Type)31 FileNotFoundException (java.io.FileNotFoundException)29 Paragraph (org.apache.zeppelin.notebook.Paragraph)27 RestResponse (com.google.gerrit.acceptance.RestResponse)24 JsonElement (com.google.gson.JsonElement)24 JsonObject (com.google.gson.JsonObject)24 OutputStreamWriter (java.io.OutputStreamWriter)22 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)21