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