Search in sources :

Example 1 with ArmyStatistics

use of com.faforever.server.stats.ArmyStatistics 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 ArmyStatistics

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

the class ArmyStatsMapper method map.

public List<ArmyStatistics> map(String string) {
    return noCatch(() -> {
        JsonNode node = objectMapper.readTree(string);
        JsonNode stats = node.get("stats");
        TypeReference<List<ArmyStatistics>> typeReference = new TypeReference<List<ArmyStatistics>>() {
        };
        JsonParser jsonParser = stats.traverse();
        jsonParser.setCodec(objectMapper);
        return jsonParser.readValueAs(typeReference);
    });
}
Also used : ArmyStatistics(com.faforever.server.stats.ArmyStatistics) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 3 with ArmyStatistics

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

the class GameServiceTest method reportArmyStatistics.

@Test
public void reportArmyStatistics() throws Exception {
    Game game = hostGame(player1);
    assertThat(game.getArmyStatistics(), is(empty()));
    instance.reportArmyStatistics(player1, Arrays.asList(new ArmyStatistics(), new ArmyStatistics()));
    assertThat(game.getArmyStatistics(), is(notNullValue()));
    assertThat(game.getArmyStatistics(), hasSize(2));
}
Also used : Game(com.faforever.server.entity.Game) ArmyStatistics(com.faforever.server.stats.ArmyStatistics) Test(org.junit.Test)

Aggregations

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