Skip to content

Commit

Permalink
Add PortableAccount, ImportStatistics, ImportSource
Browse files Browse the repository at this point in the history
  • Loading branch information
bivashy committed Oct 25, 2023
1 parent df7c11f commit 58ab669
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package me.mastercapexd.auth.database.importing;

import com.j256.ormlite.stmt.QueryBuilder;

public interface ImportSource {

QueryBuilder<PortableAccount, ?> sourceAccounts();

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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<LinkAccount> linkAccounts;
private final AccountDetails details;

public PortableAccount(String name, UUID uniqueId, CryptoProvider cryptoProvider, String hashedPassword, Collection<LinkAccount> 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<LinkAccount> 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;
}

}

}

0 comments on commit 58ab669

Please sign in to comment.