More smell cleans

This commit is contained in:
Rsl1122 2018-08-12 12:31:23 +03:00
parent db47e51e45
commit fa8b1d2b35
6 changed files with 35 additions and 18 deletions

View File

@ -68,9 +68,9 @@ public class ConnectionIn {
private Map<String, String> readVariables(Request request) throws WebException { private Map<String, String> readVariables(Request request) throws WebException {
String requestBody = readRequestBody(request.getRequestBody()); String requestBody = readRequestBody(request.getRequestBody());
String[] variables = requestBody.split(";&variable;"); String[] bodyVariables = requestBody.split(";&variable;");
return Arrays.stream(variables) return Arrays.stream(bodyVariables)
.map(variable -> variable.split("=", 2)) .map(variable -> variable.split("=", 2))
.filter(splitVariables -> splitVariables.length == 2) .filter(splitVariables -> splitVariables.length == 2)
.collect(Collectors.toMap(splitVariables -> splitVariables[0], splitVariables -> splitVariables[1], (a, b) -> b)); .collect(Collectors.toMap(splitVariables -> splitVariables[0], splitVariables -> splitVariables[1], (a, b) -> b));

View File

@ -11,6 +11,7 @@ import com.djrapitops.plugin.api.utility.log.Log;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* Class responsible for logging what ConnectionOut objects get in return. * Class responsible for logging what ConnectionOut objects get in return.
@ -90,6 +91,20 @@ public class ConnectionLog {
public int compareTo(Entry o) { public int compareTo(Entry o) {
return Long.compare(o.date, this.date); return Long.compare(o.date, this.date);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Entry)) return false;
Entry entry = (Entry) o;
return responseCode == entry.responseCode &&
date == entry.date;
}
@Override
public int hashCode() {
return Objects.hash(responseCode, date);
}
} }
} }

View File

@ -116,9 +116,4 @@ public class ServerConnectionSystem extends ConnectionSystem {
Log.info(locale.get().getString(PluginLang.ENABLE_NOTIFY_ADDRESS_CONFIRMATION, webServerAddress)); Log.info(locale.get().getString(PluginLang.ENABLE_NOTIFY_ADDRESS_CONFIRMATION, webServerAddress));
} }
} }
@Override
public void disable() {
}
} }

View File

@ -63,4 +63,7 @@ public class WebExceptionLogger {
return null; return null;
} }
private WebExceptionLogger() {
// Static method class.
}
} }

View File

@ -50,13 +50,13 @@ public class CacheAnalysisPageRequest extends InfoRequestWithVariables implement
public Response handleRequest(Map<String, String> variables) throws WebException { public Response handleRequest(Map<String, String> variables) throws WebException {
// Available variables: sender, html (Base64) // Available variables: sender, html (Base64)
UUID serverUUID = UUID.fromString(variables.get("sender")); UUID sender = UUID.fromString(variables.get("sender"));
String html = variables.get("html"); String sentHtml = variables.get("html");
Verify.nullCheck(html, () -> new BadRequestException("HTML 'html' variable not supplied in the request")); Verify.nullCheck(sentHtml, () -> new BadRequestException("HTML 'html' variable not supplied in the request"));
boolean export = Settings.ANALYSIS_EXPORT.isTrue(); boolean export = Settings.ANALYSIS_EXPORT.isTrue();
cache(export, serverUUID, Base64Util.decode(html)); cache(export, sender, Base64Util.decode(sentHtml));
return DefaultResponses.SUCCESS.get(); return DefaultResponses.SUCCESS.get();
} }

View File

@ -32,13 +32,7 @@ public class PlanErrorManager implements ErrorManager {
} else { } else {
Log.warn("It has been logged to ErrorLog.txt"); Log.warn("It has been logged to ErrorLog.txt");
} }
try { logGlobally(source, e);
if ((Check.isBukkitAvailable() && Check.isBungeeAvailable()) || Settings.DEV_MODE.isTrue()) {
Logger.getGlobal().log(Level.WARNING, source, e);
}
} catch (IllegalStateException ignored) {
/* Config system not initialized */
}
ErrorLogger.logThrowable(e, logsFolder); ErrorLogger.logThrowable(e, logsFolder);
} catch (Exception exception) { } catch (Exception exception) {
System.out.println("Failed to log error to file because of " + exception); System.out.println("Failed to log error to file because of " + exception);
@ -48,4 +42,14 @@ public class PlanErrorManager implements ErrorManager {
Logger.getGlobal().log(Level.WARNING, source, e); Logger.getGlobal().log(Level.WARNING, source, e);
} }
} }
private void logGlobally(String source, Throwable e) {
try {
if ((Check.isBukkitAvailable() && Check.isBungeeAvailable()) || Settings.DEV_MODE.isTrue()) {
Logger.getGlobal().log(Level.WARNING, source, e);
}
} catch (IllegalStateException ignored) {
/* Config system not initialized */
}
}
} }