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;
}
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();
}
Aggregations