-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PortableAccount, ImportStatistics, ImportSource
- Loading branch information
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
core/src/main/java/me/mastercapexd/auth/database/importing/ImportSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
core/src/main/java/me/mastercapexd/auth/database/importing/ImportStatistics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
core/src/main/java/me/mastercapexd/auth/database/importing/PortableAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
|
||
} |