Search in sources :

Example 1 with ArmyStatisticsReport

use of com.faforever.server.stats.ArmyStatisticsReport in project faf-java-server by FAForever.

the class LegacyRequestTransformer method handleJsonStats.

private ClientMessage handleJsonStats(Map<String, Object> source) {
    return noCatch(() -> {
        JsonNode node = objectMapper.readTree((String) getArgs(source).get(0));
        JsonNode stats = node.get("stats");
        TypeReference<List<ArmyStatistics>> typeReference = new TypeReference<List<ArmyStatistics>>() {
        };
        JsonParser jsonParser = stats.traverse();
        jsonParser.setCodec(objectMapper);
        return new ArmyStatisticsReport(jsonParser.readValueAs(typeReference));
    });
}
Also used : ArmyStatistics(com.faforever.server.stats.ArmyStatistics) ArmyStatisticsReport(com.faforever.server.stats.ArmyStatisticsReport) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 2 with ArmyStatisticsReport

use of com.faforever.server.stats.ArmyStatisticsReport in project faf-java-server by FAForever.

the class LegacyRequestTransformerTest method transformJsonStats.

@Test
public void transformJsonStats() throws Exception {
    String stats;
    try (Reader reader = new InputStreamReader(getClass().getResourceAsStream("/stats/game_stats_full_example.json"), StandardCharsets.UTF_8)) {
        stats = CharStreams.toString(reader);
    }
    ArmyStatisticsReport armyStatisticsReport = (ArmyStatisticsReport) instance.transform(ImmutableMap.of(KEY_COMMAND, "JsonStats", KEY_ARGS, Collections.singletonList(stats)));
    assertThat(armyStatisticsReport, is(notNullValue()));
    assertThat(armyStatisticsReport.getArmyStatistics(), is(notNullValue()));
}
Also used : InputStreamReader(java.io.InputStreamReader) ArmyStatisticsReport(com.faforever.server.stats.ArmyStatisticsReport) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Test(org.junit.Test)

Example 3 with ArmyStatisticsReport

use of com.faforever.server.stats.ArmyStatisticsReport in project faf-java-server by FAForever.

the class GameServiceActivatorsTest method reportGameStatistics.

@Test
public void reportGameStatistics() throws Exception {
    ArmyStatisticsReport report = new ArmyStatisticsReport(Collections.emptyList());
    instance.reportGameStatistics(report, clientConnection.getAuthentication());
    verify(gameService).reportArmyStatistics(player, report.getArmyStatistics());
}
Also used : ArmyStatisticsReport(com.faforever.server.stats.ArmyStatisticsReport) Test(org.junit.Test)

Aggregations

ArmyStatisticsReport (com.faforever.server.stats.ArmyStatisticsReport)3 Test (org.junit.Test)2 ArmyStatistics (com.faforever.server.stats.ArmyStatistics)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 List (java.util.List)1