Search in sources :

Example 1 with InputQueryDto

use of com.djrapitops.plan.delivery.domain.datatransfer.InputQueryDto in project Plan by plan-player-analytics.

the class QueryJSONResolver method parseInputQueryFromQueryParams.

private InputQueryDto parseInputQueryFromQueryParams(Request request) {
    String q = request.getQuery().get("q").orElseThrow(() -> new BadRequestException("'q' parameter not set (expecting json array)"));
    try {
        String query = URLDecoder.decode(q, "UTF-8");
        List<InputFilterDto> queryFilters = InputFilterDto.parse(query, gson);
        ViewDto view = request.getQuery().get("view").map(viewJson -> gson.fromJson(viewJson, ViewDto.class)).orElseThrow(() -> new BadRequestException("'view' parameter not set (expecting json object {afterDate, afterTime, beforeDate, beforeTime})"));
        return new InputQueryDto(view, queryFilters);
    } catch (IOException e) {
        throw new BadRequestException("Failed to decode json: '" + q + "', " + e.getMessage());
    }
}
Also used : QueryFilters(com.djrapitops.plan.storage.database.queries.filter.QueryFilters) java.util(java.util) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) URLDecoder(java.net.URLDecoder) ServerUUID(com.djrapitops.plan.identification.ServerUUID) InputQueryDto(com.djrapitops.plan.delivery.domain.datatransfer.InputQueryDto) Singleton(javax.inject.Singleton) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) Resolver(com.djrapitops.plan.delivery.web.resolver.Resolver) TimeSettings(com.djrapitops.plan.settings.config.paths.TimeSettings) Gson(com.google.gson.Gson) BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException) JSONStorage(com.djrapitops.plan.delivery.webserver.cache.JSONStorage) NetworkActivityIndexQueries(com.djrapitops.plan.storage.database.queries.analysis.NetworkActivityIndexQueries) Filter(com.djrapitops.plan.storage.database.queries.filter.Filter) ParseException(java.text.ParseException) Maps(com.djrapitops.plan.utilities.java.Maps) ExtensionQueryResultTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionQueryResultTableDataQuery) InputFilterDto(com.djrapitops.plan.delivery.domain.datatransfer.InputFilterDto) MimeType(com.djrapitops.plan.delivery.web.resolver.MimeType) ServerInfo(com.djrapitops.plan.identification.ServerInfo) Request(com.djrapitops.plan.delivery.web.resolver.request.Request) TimeAmount(net.playeranalytics.plugin.scheduling.TimeAmount) Formatters(com.djrapitops.plan.delivery.formatting.Formatters) IOException(java.io.IOException) Response(com.djrapitops.plan.delivery.web.resolver.Response) RequestBodyConverter(com.djrapitops.plan.delivery.webserver.RequestBodyConverter) DateMap(com.djrapitops.plan.delivery.domain.DateMap) PlayersTableJSONCreator(com.djrapitops.plan.delivery.rendering.json.PlayersTableJSONCreator) ViewDto(com.djrapitops.plan.delivery.domain.datatransfer.ViewDto) WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser) Locale(com.djrapitops.plan.settings.locale.Locale) GeoInfoQueries(com.djrapitops.plan.storage.database.queries.objects.GeoInfoQueries) SessionQueries(com.djrapitops.plan.storage.database.queries.objects.SessionQueries) QueryTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.QueryTablePlayersQuery) GraphJSONCreator(com.djrapitops.plan.delivery.rendering.json.graphs.GraphJSONCreator) DisplaySettings(com.djrapitops.plan.settings.config.paths.DisplaySettings) Formatter(com.djrapitops.plan.delivery.formatting.Formatter) ViewDto(com.djrapitops.plan.delivery.domain.datatransfer.ViewDto) InputQueryDto(com.djrapitops.plan.delivery.domain.datatransfer.InputQueryDto) InputFilterDto(com.djrapitops.plan.delivery.domain.datatransfer.InputFilterDto) BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException) IOException(java.io.IOException)

Example 2 with InputQueryDto

use of com.djrapitops.plan.delivery.domain.datatransfer.InputQueryDto in project Plan by plan-player-analytics.

the class QueryJSONResolver method getResponse.

private Response getResponse(Request request) {
    Optional<Response> cachedResult = checkForCachedResult(request);
    if (cachedResult.isPresent())
        return cachedResult.get();
    InputQueryDto inputQuery = parseInputQuery(request);
    List<InputFilterDto> queries = inputQuery.getFilters();
    Filter.Result result = filters.apply(queries);
    List<Filter.ResultPath> resultPath = result.getInverseResultPath();
    Collections.reverse(resultPath);
    return buildAndStoreResponse(inputQuery.getView(), result, resultPath);
}
Also used : Response(com.djrapitops.plan.delivery.web.resolver.Response) InputQueryDto(com.djrapitops.plan.delivery.domain.datatransfer.InputQueryDto) InputFilterDto(com.djrapitops.plan.delivery.domain.datatransfer.InputFilterDto) Filter(com.djrapitops.plan.storage.database.queries.filter.Filter)

Aggregations

InputFilterDto (com.djrapitops.plan.delivery.domain.datatransfer.InputFilterDto)2 InputQueryDto (com.djrapitops.plan.delivery.domain.datatransfer.InputQueryDto)2 Response (com.djrapitops.plan.delivery.web.resolver.Response)2 Filter (com.djrapitops.plan.storage.database.queries.filter.Filter)2 DateMap (com.djrapitops.plan.delivery.domain.DateMap)1 ViewDto (com.djrapitops.plan.delivery.domain.datatransfer.ViewDto)1 Formatter (com.djrapitops.plan.delivery.formatting.Formatter)1 Formatters (com.djrapitops.plan.delivery.formatting.Formatters)1 PlayersTableJSONCreator (com.djrapitops.plan.delivery.rendering.json.PlayersTableJSONCreator)1 GraphJSONCreator (com.djrapitops.plan.delivery.rendering.json.graphs.GraphJSONCreator)1 MimeType (com.djrapitops.plan.delivery.web.resolver.MimeType)1 Resolver (com.djrapitops.plan.delivery.web.resolver.Resolver)1 BadRequestException (com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)1 Request (com.djrapitops.plan.delivery.web.resolver.request.Request)1 WebUser (com.djrapitops.plan.delivery.web.resolver.request.WebUser)1 RequestBodyConverter (com.djrapitops.plan.delivery.webserver.RequestBodyConverter)1 JSONStorage (com.djrapitops.plan.delivery.webserver.cache.JSONStorage)1 ExtensionQueryResultTableDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionQueryResultTableDataQuery)1 ServerInfo (com.djrapitops.plan.identification.ServerInfo)1 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1