mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-10 13:49:17 +01:00
Implemented CacheNetworkPageContentRequest
This commit is contained in:
parent
027db58a0a
commit
f5f488f16a
@ -25,4 +25,8 @@ public interface TransferOperations {
|
|||||||
// Get
|
// Get
|
||||||
|
|
||||||
Map<UUID, String> getPlayerHtml() throws DBException;
|
Map<UUID, String> getPlayerHtml() throws DBException;
|
||||||
|
|
||||||
|
void networkPageContent(UUID serverUUID, String html) throws DBException;
|
||||||
|
|
||||||
|
Map<UUID, String> getNetworkPageContent() throws DBException;
|
||||||
}
|
}
|
@ -4,9 +4,19 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.info.request;
|
package com.djrapitops.plan.system.info.request;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.api.exceptions.connection.TransferDatabaseException;
|
||||||
|
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||||
|
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||||
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
|
import com.djrapitops.plan.system.info.InfoSystem;
|
||||||
|
import com.djrapitops.plan.system.webserver.pages.DefaultResponses;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
|
import com.djrapitops.plan.system.webserver.response.cache.PageId;
|
||||||
|
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
|
||||||
|
import com.djrapitops.plan.system.webserver.response.pages.parts.NetworkPageContent;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InfoRequest for caching Network page parts to ResponseCache of receiving server.
|
* InfoRequest for caching Network page parts to ResponseCache of receiving server.
|
||||||
@ -15,13 +25,49 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class CacheNetworkPageContentRequest implements InfoRequest {
|
public class CacheNetworkPageContentRequest implements InfoRequest {
|
||||||
|
|
||||||
@Override
|
private final UUID serverUUID;
|
||||||
public void placeDataToDatabase() {
|
private final String html;
|
||||||
// TODO
|
|
||||||
|
public CacheNetworkPageContentRequest(UUID serverUUID, String html) {
|
||||||
|
this.serverUUID = serverUUID;
|
||||||
|
this.html = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response handleRequest(Map<String, String> variables) {
|
public void placeDataToDatabase() throws WebException {
|
||||||
return null; // TODO
|
try {
|
||||||
|
Database.getActive().transfer().networkPageContent(serverUUID, html);
|
||||||
|
} catch (DBException e) {
|
||||||
|
throw new TransferDatabaseException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response handleRequest(Map<String, String> variables) throws WebException {
|
||||||
|
// Available variables: sender
|
||||||
|
|
||||||
|
Map<UUID, String> networkPageHtml;
|
||||||
|
Map<UUID, String> serverNames;
|
||||||
|
try {
|
||||||
|
Database database = Database.getActive();
|
||||||
|
networkPageHtml = database.transfer().getNetworkPageContent();
|
||||||
|
serverNames = database.fetch().getServerNames();
|
||||||
|
} catch (DBException e) {
|
||||||
|
throw new TransferDatabaseException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<UUID, String> entry : networkPageHtml.entrySet()) {
|
||||||
|
UUID serverUUID = entry.getKey();
|
||||||
|
String serverName = serverNames.getOrDefault(serverUUID, "Unknown");
|
||||||
|
String html = entry.getValue();
|
||||||
|
|
||||||
|
NetworkPageContent response = (NetworkPageContent)
|
||||||
|
ResponseCache.loadResponse(PageId.NETWORK_CONTENT.of(serverUUID), NetworkPageContent::new);
|
||||||
|
response.addElement(serverName, html);
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoSystem.getInstance().updateNetworkPage();
|
||||||
|
|
||||||
|
return DefaultResponses.SUCCESS.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,7 +29,8 @@ public enum PageId {
|
|||||||
FAVICON_REDIRECT("Redirect:Favicon"),
|
FAVICON_REDIRECT("Redirect:Favicon"),
|
||||||
AUTH_PROMPT("PromptAuth"),
|
AUTH_PROMPT("PromptAuth"),
|
||||||
//
|
//
|
||||||
PLAYER_PLUGINS_TAB("playerPluginsTab:");
|
PLAYER_PLUGINS_TAB("playerPluginsTab:"),
|
||||||
|
NETWORK_CONTENT("networkContent:");
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Licence is provided in the jar as license.yml also here:
|
||||||
|
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.system.webserver.response.pages.parts;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents Servers tab content of Network page.
|
||||||
|
* <p>
|
||||||
|
* Extends Response so that it can be stored in ResponseCache.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class NetworkPageContent extends Response {
|
||||||
|
|
||||||
|
private final Map<String, String> content;
|
||||||
|
|
||||||
|
public NetworkPageContent() {
|
||||||
|
content = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkPageContent(String serverName, String html) {
|
||||||
|
this();
|
||||||
|
content.put(serverName, html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addElement(String serverName, String html) {
|
||||||
|
content.put(serverName, html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContents() {
|
||||||
|
if (content.isEmpty()) {
|
||||||
|
return ""; // TODO "No Servers"
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> serverNames = new ArrayList<>(content.keySet());
|
||||||
|
Collections.sort(serverNames);
|
||||||
|
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
for (String serverName : serverNames) {
|
||||||
|
b.append(content.get(serverName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return b.toString();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user