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