Search in sources :

Example 1 with UserImportData

use of com.djrapitops.plan.gathering.importing.data.UserImportData in project Plan by plan-player-analytics.

the class BukkitImporter method processUserData.

private void processUserData() {
    List<UserImportData> userImportData = getUserImportData();
    if (userImportData == null || userImportData.isEmpty()) {
        return;
    }
    BukkitUserImportRefiner userImportRefiner = new BukkitUserImportRefiner(userImportData);
    userImportData = userImportRefiner.refineData();
    Database db = dbSystem.getDatabase();
    Set<UUID> existingUUIDs = db.query(UserIdentifierQueries.fetchAllPlayerUUIDs());
    Set<UUID> existingUserInfoTableUUIDs = db.query(UserIdentifierQueries.fetchPlayerUUIDsOfServer(serverUUID.get()));
    Map<UUID, BaseUser> users = new HashMap<>();
    List<UserInfo> userInfo = new ArrayList<>();
    Map<UUID, List<Nickname>> nickNames = new HashMap<>();
    List<FinishedSession> sessions = new ArrayList<>();
    Map<UUID, List<GeoInfo>> geoInfo = new HashMap<>();
    userImportData.parallelStream().forEach(data -> {
        UUID uuid = data.getUuid();
        if (!existingUUIDs.contains(uuid)) {
            users.put(uuid, toBaseUser(data));
        }
        if (!existingUserInfoTableUUIDs.contains(uuid)) {
            userInfo.add(toUserInfo(data));
        }
        nickNames.put(uuid, data.getNicknames());
        geoInfo.put(uuid, convertGeoInfo(data));
        sessions.add(toSession(data));
    });
    db.executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllCommonUserInformation(users.values()));
            execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
            Map<ServerUUID, List<UserInfo>> userInformation = Collections.singletonMap(serverUUID.get(), userInfo);
            execute(LargeStoreQueries.storePerServerUserInformation(userInformation));
            execute(LargeStoreQueries.storeAllNicknameData(Collections.singletonMap(serverUUID.get(), nickNames)));
            execute(LargeStoreQueries.storeAllGeoInformation(geoInfo));
        }
    });
}
Also used : Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) BukkitUserImportRefiner(com.djrapitops.plan.gathering.importing.data.BukkitUserImportRefiner) UserImportData(com.djrapitops.plan.gathering.importing.data.UserImportData)

Aggregations

BukkitUserImportRefiner (com.djrapitops.plan.gathering.importing.data.BukkitUserImportRefiner)1 UserImportData (com.djrapitops.plan.gathering.importing.data.UserImportData)1 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1 Database (com.djrapitops.plan.storage.database.Database)1 Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)1