mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-21 20:22:45 +02:00
[Debt] Sorted up some Analysis refresh code
Split AnalysisPage#getRefreshingHtml into new RefreshingAnalysisResponse class. Moved AnalysisPageResponse.refreshNow to ServerPageHandler.
This commit is contained in:
parent
3625156b36
commit
ea9a8b8812
|
@ -5,6 +5,8 @@
|
|||
package com.djrapitops.plan.system.webserver.pages;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.WebUserAuthException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NoServersException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
|
@ -16,7 +18,6 @@ import com.djrapitops.plan.system.webserver.cache.PageId;
|
|||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -76,10 +77,24 @@ public class ServerPageHandler implements PageHandler {
|
|||
}
|
||||
return ResponseCache.loadResponse(PageId.SERVER.of(serverUUID));
|
||||
}
|
||||
return AnalysisPageResponse.refreshNow(serverUUID, processing, infoSystem);
|
||||
return refreshNow(serverUUID);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Split responsibility so that this method does not call system to refresh and also render a refresh page.
|
||||
private Response refreshNow(UUID serverUUID) {
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
infoSystem.generateAnalysisPage(serverUUID);
|
||||
} catch (NoServersException | ConnectionFailException e) {
|
||||
ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> responseFactory.notFound404(e.getMessage()));
|
||||
} catch (WebException e) {
|
||||
ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> responseFactory.internalErrorResponse(e, "Failed to generate Analysis Page"));
|
||||
}
|
||||
});
|
||||
return responseFactory.refreshingAnalysisResponse();
|
||||
}
|
||||
|
||||
private UUID getServerUUID(List<String> target) {
|
||||
// Default to current server's page
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
|
|
|
@ -183,4 +183,12 @@ public class ResponseFactory {
|
|||
return internalErrorResponse(e, "Failed to parse PromptAuthorizationResponse");
|
||||
}
|
||||
}
|
||||
|
||||
public ErrorResponse refreshingAnalysisResponse() {
|
||||
try {
|
||||
return new RefreshingAnalysisResponse(version, files);
|
||||
} catch (IOException e) {
|
||||
return internalErrorResponse(e, "Failed to parse RefreshingAnalysisResponse");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.djrapitops.plan.system.webserver.response.errors;
|
||||
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This response is used when Analysis is being refreshed and the user needs some feedback.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class RefreshingAnalysisResponse extends ErrorResponse {
|
||||
|
||||
public RefreshingAnalysisResponse(String version, PlanFiles files) throws IOException {
|
||||
super(version, files);
|
||||
|
||||
setTitle("Analysis is being refreshed..");
|
||||
setParagraph("<meta http-equiv=\"refresh\" content=\"5\" /><i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Analysis is being run, refresh the page after a few seconds.. (F5)");
|
||||
replacePlaceholders();
|
||||
}
|
||||
}
|
|
@ -1,18 +1,6 @@
|
|||
package com.djrapitops.plan.system.webserver.response.pages;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NoServersException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||
import com.djrapitops.plan.utilities.html.pages.AnalysisPage;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
|
@ -20,22 +8,6 @@ import java.util.UUID;
|
|||
*/
|
||||
public class AnalysisPageResponse extends Response {
|
||||
|
||||
// TODO Split responsibility so that this method does not call system to refresh and also render a refresh page.
|
||||
@Deprecated
|
||||
public static AnalysisPageResponse refreshNow(UUID serverUUID, Processing processing, InfoSystem infoSystem) {
|
||||
ResponseFactory responseFactory = null; // TODO
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
infoSystem.generateAnalysisPage(serverUUID);
|
||||
} catch (NoServersException | ConnectionFailException e) {
|
||||
ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> responseFactory.notFound404(e.getMessage()));
|
||||
} catch (WebException e) {
|
||||
Log.toLog(AnalysisPageResponse.class.getName(), e);
|
||||
}
|
||||
});
|
||||
return new AnalysisPageResponse(AnalysisPage.getRefreshingHtml());
|
||||
}
|
||||
|
||||
public AnalysisPageResponse(String html) {
|
||||
super.setHeader("HTTP/1.1 200 OK");
|
||||
super.setContent(html);
|
||||
|
|
|
@ -7,7 +7,6 @@ package com.djrapitops.plan.utilities.html.pages;
|
|||
import com.djrapitops.plan.api.exceptions.ParseException;
|
||||
import com.djrapitops.plan.data.store.containers.AnalysisContainer;
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.PlaceholderReplacer;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
|
@ -41,20 +40,6 @@ public class AnalysisPage implements Page {
|
|||
this.decimalFormatter = decimalFormatter;
|
||||
}
|
||||
|
||||
public static String getRefreshingHtml() {
|
||||
// TODO Work this out
|
||||
ErrorResponse refreshPage = null;
|
||||
try {
|
||||
refreshPage = new ErrorResponse("", null);
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
refreshPage.setTitle("Analysis is being refreshed..");
|
||||
refreshPage.setParagraph("<meta http-equiv=\"refresh\" content=\"5\" /><i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Analysis is being run, refresh the page after a few seconds.. (F5)");
|
||||
refreshPage.replacePlaceholders();
|
||||
return refreshPage.getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toHtml() throws ParseException {
|
||||
Benchmark.start(DEBUG);
|
||||
|
|
Loading…
Reference in New Issue
Block a user