Search in sources :

Example 6 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException in project Plan by plan-player-analytics.

the class GraphsJSONResolver method getGraphJSON.

private JSONStorage.StoredJSON getGraphJSON(Request request, DataID dataID) {
    Optional<Long> timestamp = Identifiers.getTimestamp(request);
    JSONStorage.StoredJSON storedJSON;
    if (request.getQuery().get("server").isPresent()) {
        // Can throw BadRequestException
        ServerUUID serverUUID = identifiers.getServerUUID(request);
        storedJSON = jsonResolverService.resolve(timestamp, dataID, serverUUID, theServerUUID -> generateGraphDataJSONOfType(dataID, theServerUUID, request.getQuery()));
    } else {
        // Assume network
        storedJSON = jsonResolverService.resolve(timestamp, dataID, () -> generateGraphDataJSONOfType(dataID));
    }
    return storedJSON;
}
Also used : MimeType(com.djrapitops.plan.delivery.web.resolver.MimeType) Request(com.djrapitops.plan.delivery.web.resolver.request.Request) ServerUUID(com.djrapitops.plan.identification.ServerUUID) URIQuery(com.djrapitops.plan.delivery.web.resolver.request.URIQuery) Singleton(javax.inject.Singleton) Response(com.djrapitops.plan.delivery.web.resolver.Response) Inject(javax.inject.Inject) AsyncJSONResolverService(com.djrapitops.plan.delivery.webserver.cache.AsyncJSONResolverService) Resolver(com.djrapitops.plan.delivery.web.resolver.Resolver) WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser) Identifiers(com.djrapitops.plan.identification.Identifiers) BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException) Optional(java.util.Optional) JSONStorage(com.djrapitops.plan.delivery.webserver.cache.JSONStorage) GraphJSONCreator(com.djrapitops.plan.delivery.rendering.json.graphs.GraphJSONCreator) Collections(java.util.Collections) DataID(com.djrapitops.plan.delivery.webserver.cache.DataID) ServerUUID(com.djrapitops.plan.identification.ServerUUID) JSONStorage(com.djrapitops.plan.delivery.webserver.cache.JSONStorage)

Example 7 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException in project Plan by plan-player-analytics.

the class PlayerJSONResolver method canAccess.

@Override
public boolean canAccess(Request request) {
    WebUser user = request.getUser().orElse(new WebUser(""));
    if (user.hasPermission("page.player.other"))
        return true;
    if (user.hasPermission("page.player.self")) {
        try {
            UUID webUserUUID = identifiers.getPlayerUUID(user.getName());
            UUID playerUUID = identifiers.getPlayerUUID(request);
            return playerUUID.equals(webUserUUID);
        } catch (BadRequestException userDoesntExist) {
            // Don't give away who has played on the server to someone with level 2 access
            return false;
        }
    }
    return false;
}
Also used : BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException) WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser) UUID(java.util.UUID)

Example 8 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException 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 9 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException in project Plan by plan-player-analytics.

the class DateRangeFilter method getTime.

private long getTime(InputFilterDto query, String dateKey, String timeKey) {
    String date = query.get(dateKey).orElseThrow(() -> new BadRequestException("'" + dateKey + "' not specified in parameters for " + getKind()));
    String time = query.get(timeKey).orElseThrow(() -> new BadRequestException("'" + timeKey + "' not specified in parameters for " + getKind()));
    try {
        return dateFormat.parse(date + ' ' + time).getTime();
    } catch (ParseException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException) ParseException(java.text.ParseException)

Example 10 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException in project Plan by plan-player-analytics.

the class Identifiers method getServerUUID.

/**
 * Obtain UUID of the server.
 *
 * @param request for Request, URIQuery needs a 'server' parameter.
 * @return UUID of the server.
 * @throws BadRequestException If server parameter is not defined or the server is not in the database.
 */
public ServerUUID getServerUUID(Request request) {
    String identifier = request.getQuery().get("server").orElseThrow(() -> new BadRequestException("'server' parameter was not defined."));
    Optional<ServerUUID> parsed = UUIDUtility.parseFromString(identifier).map(ServerUUID::from);
    return parsed.orElseGet(() -> getServerUUIDFromName(identifier).orElseThrow(() -> new BadRequestException("Given 'server' was not found in the database.")));
}
Also used : BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)

Aggregations

BadRequestException (com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)11 WebUser (com.djrapitops.plan.delivery.web.resolver.request.WebUser)3 JSONStorage (com.djrapitops.plan.delivery.webserver.cache.JSONStorage)3 ParseException (java.text.ParseException)3 GraphJSONCreator (com.djrapitops.plan.delivery.rendering.json.graphs.GraphJSONCreator)2 MimeType (com.djrapitops.plan.delivery.web.resolver.MimeType)2 Resolver (com.djrapitops.plan.delivery.web.resolver.Resolver)2 Response (com.djrapitops.plan.delivery.web.resolver.Response)2 Request (com.djrapitops.plan.delivery.web.resolver.request.Request)2 URIQuery (com.djrapitops.plan.delivery.web.resolver.request.URIQuery)2 DataID (com.djrapitops.plan.delivery.webserver.cache.DataID)2 ServerUUID (com.djrapitops.plan.identification.ServerUUID)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 DateMap (com.djrapitops.plan.delivery.domain.DateMap)1 InputFilterDto (com.djrapitops.plan.delivery.domain.datatransfer.InputFilterDto)1 InputQueryDto (com.djrapitops.plan.delivery.domain.datatransfer.InputQueryDto)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