Search in sources :

Example 1 with NotebookRepoSettingsRequest

use of org.apache.zeppelin.rest.message.NotebookRepoSettingsRequest in project zeppelin by apache.

the class NotebookRepoRestApi method updateRepoSetting.

/**
   * Update a specific note repo.
   *
   * @param message
   * @param settingId
   * @return
   */
@PUT
@ZeppelinApi
public Response updateRepoSetting(String payload) {
    if (StringUtils.isBlank(payload)) {
        return new JsonResponse<>(Status.NOT_FOUND, "", Collections.emptyMap()).build();
    }
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    NotebookRepoSettingsRequest newSettings = NotebookRepoSettingsRequest.EMPTY;
    try {
        newSettings = gson.fromJson(payload, NotebookRepoSettingsRequest.class);
    } catch (JsonSyntaxException e) {
        LOG.error("Cannot update notebook repo settings", e);
        return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload structure")).build();
    }
    if (NotebookRepoSettingsRequest.isEmpty(newSettings)) {
        LOG.error("Invalid property");
        return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload")).build();
    }
    LOG.info("User {} is going to change repo setting", subject.getUser());
    NotebookRepoWithSettings updatedSettings = noteRepos.updateNotebookRepo(newSettings.name, newSettings.settings, subject);
    if (!updatedSettings.isEmpty()) {
        LOG.info("Broadcasting note list to user {}", subject.getUser());
        notebookWsServer.broadcastReloadedNoteList(subject, null);
    }
    return new JsonResponse<>(Status.OK, "", updatedSettings).build();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) NotebookRepoWithSettings(org.apache.zeppelin.notebook.repo.NotebookRepoWithSettings) NotebookRepoSettingsRequest(org.apache.zeppelin.rest.message.NotebookRepoSettingsRequest) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) JsonResponse(org.apache.zeppelin.server.JsonResponse) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) PUT(javax.ws.rs.PUT)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)1 PUT (javax.ws.rs.PUT)1 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)1 NotebookRepoWithSettings (org.apache.zeppelin.notebook.repo.NotebookRepoWithSettings)1 NotebookRepoSettingsRequest (org.apache.zeppelin.rest.message.NotebookRepoSettingsRequest)1 JsonResponse (org.apache.zeppelin.server.JsonResponse)1 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)1