mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-09 18:07:39 +01:00
[Debt] AnalysisContainer Factory
Since AnalysisContainer was only created in PageFactory it was easy to inject dependencies for.
This commit is contained in:
parent
2ea0caa612
commit
5411fdfead
@ -27,6 +27,9 @@ import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@ -42,22 +45,43 @@ public class AnalysisContainer extends DataContainer {
|
||||
|
||||
private final ServerContainer serverContainer;
|
||||
|
||||
// TODO
|
||||
private String version;
|
||||
private PlanConfig config;
|
||||
private Theme theme;
|
||||
private Database database;
|
||||
private ServerProperties serverProperties;
|
||||
private Formatters formatters;
|
||||
private Graphs graphs;
|
||||
private HtmlTables tables;
|
||||
private Accordions accordions;
|
||||
private AnalysisPluginsTabContentCreator pluginsTabContentCreator;
|
||||
private final String version;
|
||||
private final PlanConfig config;
|
||||
private final Theme theme;
|
||||
private final Database database;
|
||||
private final ServerProperties serverProperties;
|
||||
private final Formatters formatters;
|
||||
private final Graphs graphs;
|
||||
private final HtmlTables tables;
|
||||
private final Accordions accordions;
|
||||
private final AnalysisPluginsTabContentCreator pluginsTabContentCreator;
|
||||
|
||||
private static final Key<Map<UUID, String>> serverNames = new Key<>(new Type<Map<UUID, String>>() {}, "SERVER_NAMES");
|
||||
|
||||
public AnalysisContainer(ServerContainer serverContainer) {
|
||||
public AnalysisContainer(
|
||||
ServerContainer serverContainer,
|
||||
String version,
|
||||
PlanConfig config,
|
||||
Theme theme,
|
||||
Database database,
|
||||
ServerProperties serverProperties,
|
||||
Formatters formatters,
|
||||
Graphs graphs,
|
||||
HtmlTables tables,
|
||||
Accordions accordions,
|
||||
AnalysisPluginsTabContentCreator pluginsTabContentCreator
|
||||
) {
|
||||
this.serverContainer = serverContainer;
|
||||
this.version = version;
|
||||
this.config = config;
|
||||
this.theme = theme;
|
||||
this.database = database;
|
||||
this.serverProperties = serverProperties;
|
||||
this.formatters = formatters;
|
||||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.accordions = accordions;
|
||||
this.pluginsTabContentCreator = pluginsTabContentCreator;
|
||||
addAnalysisSuppliers();
|
||||
}
|
||||
|
||||
@ -438,4 +462,60 @@ public class AnalysisContainer extends DataContainer {
|
||||
putSupplier(AnalysisKeys.PLUGINS_TAB_NAV, () -> getUnsafe(navAndTabs)[0]);
|
||||
putSupplier(AnalysisKeys.PLUGINS_TAB, () -> getUnsafe(navAndTabs)[1]);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class Factory {
|
||||
|
||||
private final String version;
|
||||
private final PlanConfig config;
|
||||
private final Theme theme;
|
||||
private final Database database;
|
||||
private final ServerProperties serverProperties;
|
||||
private final Formatters formatters;
|
||||
private final Graphs graphs;
|
||||
private final HtmlTables tables;
|
||||
private final Accordions accordions;
|
||||
private final AnalysisPluginsTabContentCreator pluginsTabContentCreator;
|
||||
|
||||
@Inject
|
||||
public Factory(
|
||||
@Named("currentVersion") String version,
|
||||
PlanConfig config,
|
||||
Theme theme,
|
||||
Database database,
|
||||
ServerProperties serverProperties,
|
||||
Formatters formatters,
|
||||
Graphs graphs,
|
||||
HtmlTables tables,
|
||||
Accordions accordions,
|
||||
AnalysisPluginsTabContentCreator pluginsTabContentCreator
|
||||
) {
|
||||
this.version = version;
|
||||
this.config = config;
|
||||
this.theme = theme;
|
||||
this.database = database;
|
||||
this.serverProperties = serverProperties;
|
||||
this.formatters = formatters;
|
||||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.accordions = accordions;
|
||||
this.pluginsTabContentCreator = pluginsTabContentCreator;
|
||||
}
|
||||
|
||||
public AnalysisContainer forServerContainer(ServerContainer serverContainer) {
|
||||
return new AnalysisContainer(
|
||||
serverContainer,
|
||||
version,
|
||||
config,
|
||||
theme,
|
||||
database,
|
||||
serverProperties,
|
||||
formatters,
|
||||
graphs,
|
||||
tables,
|
||||
accordions,
|
||||
pluginsTabContentCreator
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ public class PageFactory {
|
||||
private final Lazy<HtmlTables> tables;
|
||||
private final Lazy<Accordions> accordions;
|
||||
private final Lazy<Formatters> formatters;
|
||||
private final Lazy<AnalysisContainer.Factory> analysisContainerFactory;
|
||||
private final Lazy<HookHandler> hookHandler;
|
||||
private final Lazy<DebugLogger> debugLogger;
|
||||
private final Lazy<Timings> timings;
|
||||
@ -63,6 +64,7 @@ public class PageFactory {
|
||||
Lazy<HtmlTables> tables,
|
||||
Lazy<Accordions> accordions,
|
||||
Lazy<Formatters> formatters,
|
||||
Lazy<AnalysisContainer.Factory> analysisContainerFactory,
|
||||
Lazy<HookHandler> hookHandler,
|
||||
Lazy<DebugLogger> debugLogger,
|
||||
Lazy<Timings> timings,
|
||||
@ -79,6 +81,7 @@ public class PageFactory {
|
||||
this.tables = tables;
|
||||
this.accordions = accordions;
|
||||
this.formatters = formatters;
|
||||
this.analysisContainerFactory = analysisContainerFactory;
|
||||
this.hookHandler = hookHandler;
|
||||
this.debugLogger = debugLogger;
|
||||
this.timings = timings;
|
||||
@ -100,7 +103,8 @@ public class PageFactory {
|
||||
}
|
||||
|
||||
public AnalysisPage analysisPage(UUID serverUUID) {
|
||||
AnalysisContainer analysisContainer = new AnalysisContainer(database.get().fetch().getServerContainer(serverUUID));
|
||||
AnalysisContainer analysisContainer = analysisContainerFactory.get()
|
||||
.forServerContainer(database.get().fetch().getServerContainer(serverUUID));
|
||||
return new AnalysisPage(analysisContainer, fileSystem.get(), formatters.get().decimals(), timings.get());
|
||||
}
|
||||
|
||||
|
@ -1004,8 +1004,10 @@ public class SQLiteTest {
|
||||
@Test
|
||||
public void analysisContainerSupportsAllAnalysisKeys() throws IllegalAccessException, NoSuchAlgorithmException {
|
||||
serverContainerSupportsAllServerKeys();
|
||||
AnalysisContainer analysisContainer = new AnalysisContainer(db.fetch().getServerContainer(TestConstants.SERVER_UUID));
|
||||
|
||||
AnalysisContainer.Factory factory = null;
|
||||
AnalysisContainer analysisContainer = factory.forServerContainer(
|
||||
db.fetch().getServerContainer(TestConstants.SERVER_UUID)
|
||||
);
|
||||
List<String> unsupported = new ArrayList<>();
|
||||
for (Field field : AnalysisKeys.class.getDeclaredFields()) {
|
||||
if (!Modifier.isPublic(field.getModifiers())) {
|
||||
|
Loading…
Reference in New Issue
Block a user