diff --git a/core/src/main/java/me/mastercapexd/auth/database/importing/ImportSource.java b/core/src/main/java/me/mastercapexd/auth/database/importing/ImportSource.java new file mode 100644 index 00000000..3ec34775 --- /dev/null +++ b/core/src/main/java/me/mastercapexd/auth/database/importing/ImportSource.java @@ -0,0 +1,9 @@ +package me.mastercapexd.auth.database.importing; + +import com.j256.ormlite.stmt.QueryBuilder; + +public interface ImportSource { + + QueryBuilder sourceAccounts(); + +} diff --git a/core/src/main/java/me/mastercapexd/auth/database/importing/ImportStatistics.java b/core/src/main/java/me/mastercapexd/auth/database/importing/ImportStatistics.java new file mode 100644 index 00000000..c2cc1948 --- /dev/null +++ b/core/src/main/java/me/mastercapexd/auth/database/importing/ImportStatistics.java @@ -0,0 +1,66 @@ +package me.mastercapexd.auth.database.importing; + +import java.util.Objects; + +public class ImportStatistics { + + private int accounts; + private int linkAccounts; + private int invalidEntries; + private boolean failed; + + public ImportStatistics() { + } + + public ImportStatistics(int accounts, int linkAccounts, int invalidEntries, boolean failed) { + this.accounts = accounts; + this.linkAccounts = linkAccounts; + this.invalidEntries = invalidEntries; + this.failed = failed; + } + + public boolean success() { + return !failed; + } + + void fail() { + failed = true; + } + + void accountAdded() { + accounts++; + } + + void linkAccountAdded() { + linkAccounts++; + } + + void invalidEntrySkipped() { + invalidEntries++; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ImportStatistics that = (ImportStatistics) o; + return accounts == that.accounts && linkAccounts == that.linkAccounts && invalidEntries == that.invalidEntries && failed == that.failed; + } + + @Override + public int hashCode() { + return Objects.hash(accounts, linkAccounts, invalidEntries, failed); + } + + @Override + public String toString() { + String state = success() ? "(SUCCESS)" : "(FAILED)"; + return "-- Import statistics " + state + " --" + "\n" + + "Account: " + accounts + "\n" + + "Account links: " + linkAccounts + "\n" + + "Invalid entries: " + invalidEntries; + } + +} diff --git a/core/src/main/java/me/mastercapexd/auth/database/importing/PortableAccount.java b/core/src/main/java/me/mastercapexd/auth/database/importing/PortableAccount.java new file mode 100644 index 00000000..06166356 --- /dev/null +++ b/core/src/main/java/me/mastercapexd/auth/database/importing/PortableAccount.java @@ -0,0 +1,99 @@ +package me.mastercapexd.auth.database.importing; + +import java.util.Collection; +import java.util.UUID; + +import com.bivashy.auth.api.crypto.CryptoProvider; + +public class PortableAccount { + + private final String name; + private final UUID uniqueId; + private final CryptoProvider cryptoProvider; + private final String hashedPassword; + private final Collection linkAccounts; + private final AccountDetails details; + + public PortableAccount(String name, UUID uniqueId, CryptoProvider cryptoProvider, String hashedPassword, Collection linkAccounts, + AccountDetails details) { + this.name = name; + this.uniqueId = uniqueId; + this.cryptoProvider = cryptoProvider; + this.hashedPassword = hashedPassword; + this.linkAccounts = linkAccounts; + this.details = details; + } + + public String getName() { + return name; + } + + public UUID getUniqueId() { + return uniqueId; + } + + public CryptoProvider getCryptoProvider() { + return cryptoProvider; + } + + public String getHashedPassword() { + return hashedPassword; + } + + public Collection getLinkAccounts() { + return linkAccounts; + } + + public AccountDetails getDetails() { + return details; + } + + public enum LinkType { + VK, DISCORD, TELEGRAM, TOTP + } + public static final class AccountDetails { + + private final long lastQuitTimestamp; + private final String lastIpAddress; + private final long lastSessionStartTimestamp; + + public AccountDetails(long lastQuitTimestamp, String lastIpAddress, long lastSessionStartTimestamp) { + this.lastQuitTimestamp = lastQuitTimestamp; + this.lastIpAddress = lastIpAddress; + this.lastSessionStartTimestamp = lastSessionStartTimestamp; + } + + public long getLastQuitTimestamp() { + return lastQuitTimestamp; + } + + public String getLastIpAddress() { + return lastIpAddress; + } + + public long getLastSessionStartTimestamp() { + return lastSessionStartTimestamp; + } + + } + public static final class LinkAccount { + + private final LinkType linkType; + private final String identificator; + + public LinkAccount(LinkType linkType, String identificator) { + this.linkType = linkType; + this.identificator = identificator; + } + + public LinkType getLinkType() { + return linkType; + } + + public String getIdentificator() { + return identificator; + } + + } + +}