<commit_before>package io.github.jython234.nectar.server;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import io.github.jython234.nectar.server.controller.SessionController;
import io.github.jython234.nectar.server.struct.ClientState;
import io.github.jython234.nectar.server.struct.SessionToken;
import lombok.Getter;
import org.bson.Document;

/**
 * Represents a Client Session with
 * a token.
 *
 * @author jython234
 */
public class ClientSession {
    @Getter private SessionToken token;
    @Getter private ClientState state;

    public ClientSession(SessionToken token) {
        this.token = token;
        this.state = ClientState.UNKNOWN;
    }

    public void updateState(ClientState state) {
        NectarServerApplication.getLogger().info("Client " + token.getUuid() + " state updated to: " + state.toString());
        this.state = state;

        MongoCollection<Document> clients = NectarServerApplication.getDb().getCollection("clients");
        Document doc = clients.find(Filters.eq("uuid", token.getUuid())).first();
        doc.put("state", state.toInt());
    }
}<commit_msg>Fixed updating documents while changing state.<commit_after>package io.github.jython234.nectar.server;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import io.github.jython234.nectar.server.controller.SessionController;
import io.github.jython234.nectar.server.struct.ClientState;
import io.github.jython234.nectar.server.struct.SessionToken;
import lombok.Getter;
import org.bson.Document;

/**
 * Represents a Client Session with
 * a token.
 *
 * @author jython234
 */
public class ClientSession {
    @Getter private SessionToken token;
    @Getter private ClientState state;

    public ClientSession(SessionToken token) {
        this.token = token;
        this.state = ClientState.UNKNOWN;
    }

    public void updateState(ClientState state) {
        NectarServerApplication.getLogger().info("Client " + token.getUuid() + " state updated to: " + state.toString());
        this.state = state;

        MongoCollection<Document> clients = NectarServerApplication.getDb().getCollection("clients");
        clients.updateOne(Filters.eq("uuid", token.getUuid()),
                new Document("$set", new Document("state", state.toInt())));
    }
}
{'fraction_non_alphanumeric': 0.1190068493150685, 'fraction_numerical': 0.012842465753424657, 'mean_word_length': 4.004282655246253, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3835221', 'n_tokens_mistral': 718, 'n_tokens_neox': 698, 'n_words': 134}