Search in sources :

Example 1 with UserSavedQuery

use of io.prestosql.queryeditorui.protocol.queries.UserSavedQuery in project hetu-core by openlookeng.

the class InMemoryQueryStore method saveQuery.

@Override
public synchronized boolean saveQuery(UserSavedQuery query) throws IOException {
    List<UserSavedQuery> queryList;
    File targetPath;
    if (query.isFeatured()) {
        queryList = featuredQueries;
        targetPath = featuredQueriesPath;
    } else {
        queryList = userQueries;
        targetPath = userQueriesPath;
    }
    queryList.add(query);
    try (FileOutputStream fout = new FileOutputStream(targetPath)) {
        String json = SAVED_QUERIES_CODEC.toJson(queryList);
        fout.write(json.getBytes(StandardCharsets.UTF_8));
    } catch (IOException e) {
        LOG.error("Error while saving queries", e);
        throw e;
    }
    return true;
}
Also used : UserSavedQuery(io.prestosql.queryeditorui.protocol.queries.UserSavedQuery) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 2 with UserSavedQuery

use of io.prestosql.queryeditorui.protocol.queries.UserSavedQuery in project hetu-core by openlookeng.

the class QueryResource method saveQuery.

@POST
@Path("saved")
@Produces(MediaType.APPLICATION_JSON)
public Response saveQuery(@FormParam("description") String description, @FormParam("name") String name, @FormParam("query") String query, @Context HttpServletRequest servletRequest) throws IOException {
    String user = AccessControlUtil.getUser(accessControl, new HttpRequestSessionContext(servletRequest, groupProvider));
    CreateSavedQueryBuilder createFeaturedQueryRequest = CreateSavedQueryBuilder.notFeatured().description(description).name(name).query(query);
    if (user != null) {
        SavedQuery savedQuery = createFeaturedQueryRequest.user(user).build();
        if (queryStore.saveQuery((UserSavedQuery) savedQuery)) {
            return Response.ok(savedQuery.getUuid()).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    }
    return Response.status(Response.Status.UNAUTHORIZED).build();
}
Also used : HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) CreateSavedQueryBuilder(io.prestosql.queryeditorui.protocol.queries.CreateSavedQueryBuilder) UserSavedQuery(io.prestosql.queryeditorui.protocol.queries.UserSavedQuery) SavedQuery(io.prestosql.queryeditorui.protocol.queries.SavedQuery) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

UserSavedQuery (io.prestosql.queryeditorui.protocol.queries.UserSavedQuery)2 CreateSavedQueryBuilder (io.prestosql.queryeditorui.protocol.queries.CreateSavedQueryBuilder)1 SavedQuery (io.prestosql.queryeditorui.protocol.queries.SavedQuery)1 HttpRequestSessionContext (io.prestosql.server.HttpRequestSessionContext)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1