diff --git a/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupAccount_v6.java b/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupAccount_v6.java new file mode 100644 index 0000000000000000000000000000000000000000..48b47bba4a64336445b1264b7640d5410ed6b45d --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupAccount_v6.java @@ -0,0 +1,106 @@ +package de.deadlocker8.budgetmaster.database.model.v6; + +import de.deadlocker8.budgetmaster.accounts.AccountState; +import de.deadlocker8.budgetmaster.accounts.AccountType; + +import java.util.Objects; + +public class BackupAccount_v6 +{ + private Integer ID; + private String name; + private AccountState accountState; + private AccountType type; + private Integer iconID; + + public BackupAccount_v6() + { + // for GSON + } + + public BackupAccount_v6(Integer ID, String name, AccountState accountState, AccountType type, Integer iconID) + { + this.ID = ID; + this.name = name; + this.accountState = accountState; + this.type = type; + this.iconID = iconID; + } + + public Integer getID() + { + return ID; + } + + public void setID(Integer ID) + { + this.ID = ID; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public AccountState getAccountState() + { + return accountState; + } + + public void setAccountState(AccountState accountState) + { + this.accountState = accountState; + } + + public AccountType getType() + { + return type; + } + + public void setType(AccountType type) + { + this.type = type; + } + + public Integer getIconID() + { + return iconID; + } + + public void setIconID(Integer iconID) + { + this.iconID = iconID; + } + + @Override + public boolean equals(Object o) + { + if(this == o) return true; + if(o == null || getClass() != o.getClass()) return false; + BackupAccount_v6 that = (BackupAccount_v6) o; + return Objects.equals(ID, that.ID) && Objects.equals(name, that.name) && accountState == that.accountState && type == that.type && Objects.equals(iconID, that.iconID); + } + + @Override + public int hashCode() + { + return Objects.hash(ID, name, accountState, type, iconID); + } + + @Override + public String toString() + { + return "BackupAccount_v6{" + + "ID=" + ID + + ", name='" + name + '\'' + + ", accountState=" + accountState + + ", type=" + type + + ", iconID=" + iconID + + '}'; + } +} diff --git a/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupDatabase_v6.java b/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupDatabase_v6.java new file mode 100644 index 0000000000000000000000000000000000000000..e95be896284a12bba7324ddbd1791fa27480ed3d --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupDatabase_v6.java @@ -0,0 +1,143 @@ +package de.deadlocker8.budgetmaster.database.model.v6; + +import de.deadlocker8.budgetmaster.accounts.Account; +import de.deadlocker8.budgetmaster.categories.Category; +import de.deadlocker8.budgetmaster.charts.Chart; +import de.deadlocker8.budgetmaster.database.InternalDatabase; +import de.deadlocker8.budgetmaster.database.JSONIdentifier; +import de.deadlocker8.budgetmaster.database.model.BackupDatabase; +import de.deadlocker8.budgetmaster.database.model.v5.converter.*; +import de.deadlocker8.budgetmaster.images.Image; +import de.deadlocker8.budgetmaster.templates.Template; +import de.deadlocker8.budgetmaster.transactions.Transaction; + +import java.util.List; + +public class BackupDatabase_v6 implements BackupDatabase +{ + @SuppressWarnings("unused") + private final String TYPE = JSONIdentifier.BUDGETMASTER_DATABASE.toString(); + + @SuppressWarnings("FieldCanBeLocal") + private final int VERSION = 5; + + private List<BackupCategory_v6> categories; + private List<BackupAccount_v6> accounts; + private List<BackupTransaction_v6> transactions; + private List<BackupTemplate_v6> templates; + private List<BackupChart_v6> charts; + private List<BackupImage_v6> images; + + public BackupDatabase_v6() + { + // for GSON + } + + public BackupDatabase_v6(List<BackupCategory_v6> categories, List<BackupAccount_v6> accounts, List<BackupTransaction_v6> transactions, List<BackupTemplate_v6> templates, List<BackupChart_v6> charts, List<BackupImage_v6> images) + { + this.categories = categories; + this.accounts = accounts; + this.transactions = transactions; + this.templates = templates; + this.charts = charts; + this.images = images; + } + + public List<BackupCategory_v6> getCategories() + { + return categories; + } + + public void setCategories(List<BackupCategory_v6> categories) + { + this.categories = categories; + } + + public List<BackupAccount_v6> getAccounts() + { + return accounts; + } + + public void setAccounts(List<BackupAccount_v6> accounts) + { + this.accounts = accounts; + } + + public List<BackupTransaction_v6> getTransactions() + { + return transactions; + } + + public void setTransactions(List<BackupTransaction_v6> transactions) + { + this.transactions = transactions; + } + + public List<BackupTemplate_v6> getTemplates() + { + return templates; + } + + public void setTemplates(List<BackupTemplate_v6> templates) + { + this.templates = templates; + } + + public List<BackupChart_v6> getCharts() + { + return charts; + } + + public void setCharts(List<BackupChart_v6> charts) + { + this.charts = charts; + } + + public List<BackupImage_v6> getImages() + { + return images; + } + + public void setImages(List<BackupImage_v6> images) + { + this.images = images; + } + + public InternalDatabase convertToInternal() + { + final List<Category> convertedCategories = convertItemsToInternal(categories, new CategoryConverter_v5()); + final List<Account> convertedAccounts = convertItemsToInternal(accounts, new AccountConverter_v5()); + final List<Transaction> convertedTransactions = convertItemsToInternal(this.transactions, new TransactionConverter_v5()); + final List<Template> convertedTemplates = convertItemsToInternal(this.templates, new TemplateConverter_v5()); + final List<Chart> convertedCharts = convertItemsToInternal(this.charts, new ChartConverter_v5()); + final List<Image> convertedImages = convertItemsToInternal(this.images, new ImageConverter_v5()); + + return new InternalDatabase(convertedCategories, convertedAccounts, convertedTransactions, convertedTemplates, convertedCharts, convertedImages); + } + + @Override + public int getVersion() + { + return VERSION; + } + + @Override + public BackupDatabase upgrade() + { + throw new UnsupportedOperationException(); + } + + public static BackupDatabase_v6 createFromInternalEntities(InternalDatabase database) + { + final BackupDatabase_v6 externalDatabase = new BackupDatabase_v6(); + + externalDatabase.setCategories(externalDatabase.convertItemsToExternal(database.getCategories(), new CategoryConverter_v5())); + externalDatabase.setAccounts(externalDatabase.convertItemsToExternal(database.getAccounts(), new AccountConverter_v5())); + externalDatabase.setTransactions(externalDatabase.convertItemsToExternal(database.getTransactions(), new TransactionConverter_v5())); + externalDatabase.setTemplates(externalDatabase.convertItemsToExternal(database.getTemplates(), new TemplateConverter_v5())); + externalDatabase.setCharts(externalDatabase.convertItemsToExternal(database.getCharts(), new ChartConverter_v5())); + externalDatabase.setImages(externalDatabase.convertItemsToExternal(database.getImages(), new ImageConverter_v5())); + + return externalDatabase; + } +} diff --git a/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupTemplate_v6.java b/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupTemplate_v6.java new file mode 100644 index 0000000000000000000000000000000000000000..d36a35ab8107e7edead5afbd6f8ba81833ad99aa --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupTemplate_v6.java @@ -0,0 +1,170 @@ +package de.deadlocker8.budgetmaster.database.model.v6; + +import de.deadlocker8.budgetmaster.database.model.v4.BackupTag_v4; + +import java.util.List; +import java.util.Objects; + +public class BackupTemplate_v6 +{ + private String templateName; + private Integer amount; + private Boolean isExpenditure; + private Integer accountID; + private Integer categoryID; + private String name; + private String description; + private Integer iconID; + private List<BackupTag_v4> tags; + private Integer transferAccountID; + + public BackupTemplate_v6() + { + // for GSON + } + + public BackupTemplate_v6(String templateName, Integer amount, Boolean isExpenditure, Integer accountID, Integer categoryID, String name, String description, Integer iconID, List<BackupTag_v4> tags, Integer transferAccountID) + { + this.templateName = templateName; + this.amount = amount; + this.isExpenditure = isExpenditure; + this.accountID = accountID; + this.categoryID = categoryID; + this.name = name; + this.description = description; + this.iconID = iconID; + this.tags = tags; + this.transferAccountID = transferAccountID; + } + + public String getTemplateName() + { + return templateName; + } + + public void setTemplateName(String templateName) + { + this.templateName = templateName; + } + + public Integer getAmount() + { + return amount; + } + + public void setAmount(Integer amount) + { + this.amount = amount; + } + + public Boolean getExpenditure() + { + return isExpenditure; + } + + public void setExpenditure(Boolean expenditure) + { + isExpenditure = expenditure; + } + + public Integer getAccountID() + { + return accountID; + } + + public void setAccountID(Integer accountID) + { + this.accountID = accountID; + } + + public Integer getCategoryID() + { + return categoryID; + } + + public void setCategoryID(Integer categoryID) + { + this.categoryID = categoryID; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public Integer getIconID() + { + return iconID; + } + + public void setIconID(Integer iconID) + { + this.iconID = iconID; + } + + public List<BackupTag_v4> getTags() + { + return tags; + } + + public void setTags(List<BackupTag_v4> tags) + { + this.tags = tags; + } + + public Integer getTransferAccountID() + { + return transferAccountID; + } + + public void setTransferAccountID(Integer transferAccountID) + { + this.transferAccountID = transferAccountID; + } + + @Override + public boolean equals(Object o) + { + if(this == o) return true; + if(o == null || getClass() != o.getClass()) return false; + BackupTemplate_v6 that = (BackupTemplate_v6) o; + return Objects.equals(templateName, that.templateName) && Objects.equals(amount, that.amount) && Objects.equals(isExpenditure, that.isExpenditure) && Objects.equals(accountID, that.accountID) && Objects.equals(categoryID, that.categoryID) && Objects.equals(name, that.name) && Objects.equals(description, that.description) && Objects.equals(iconID, that.iconID) && Objects.equals(tags, that.tags) && Objects.equals(transferAccountID, that.transferAccountID); + } + + @Override + public int hashCode() + { + return Objects.hash(templateName, amount, isExpenditure, accountID, categoryID, name, description, iconID, tags, transferAccountID); + } + + @Override + public String toString() + { + return "BackupTemplate_v6{templateName='" + templateName + '\'' + + ", amount=" + amount + + ", isExpenditure=" + isExpenditure + + ", accountID=" + accountID + + ", categoryID=" + categoryID + + ", name='" + name + '\'' + + ", description='" + description + '\'' + + ", iconID=" + iconID + + ", tags=" + tags + + ", transferAccountID=" + transferAccountID + + '}'; + } +} diff --git a/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupTransaction_v6.java b/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupTransaction_v6.java new file mode 100644 index 0000000000000000000000000000000000000000..14f46f7adc0d9bc78b4a7b44da52ab418c60322d --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/database/model/v6/BackupTransaction_v6.java @@ -0,0 +1,171 @@ +package de.deadlocker8.budgetmaster.database.model.v6; + +import de.deadlocker8.budgetmaster.database.model.v4.BackupRepeatingOption_v4; +import de.deadlocker8.budgetmaster.database.model.v4.BackupTag_v4; + +import java.util.List; +import java.util.Objects; + +public class BackupTransaction_v6 +{ + private Integer amount; + private Boolean isExpenditure; + private String date; + private Integer accountID; + private Integer categoryID; + private String name; + private String description; + private List<BackupTag_v4> tags; + private BackupRepeatingOption_v4 repeatingOption; + private Integer transferAccountID; + + public BackupTransaction_v6() + { + // for GSON + } + + public BackupTransaction_v6(Integer amount, Boolean isExpenditure, String date, Integer accountID, Integer categoryID, String name, String description, List<BackupTag_v4> tags, BackupRepeatingOption_v4 repeatingOption, Integer transferAccountID) + { + this.amount = amount; + this.isExpenditure = isExpenditure; + this.date = date; + this.accountID = accountID; + this.categoryID = categoryID; + this.name = name; + this.description = description; + this.tags = tags; + this.repeatingOption = repeatingOption; + this.transferAccountID = transferAccountID; + } + + public Integer getAmount() + { + return amount; + } + + public void setAmount(Integer amount) + { + this.amount = amount; + } + + public Boolean getExpenditure() + { + return isExpenditure; + } + + public void setExpenditure(Boolean expenditure) + { + isExpenditure = expenditure; + } + + public String getDate() + { + return date; + } + + public void setDate(String date) + { + this.date = date; + } + + public Integer getAccountID() + { + return accountID; + } + + public void setAccountID(Integer accountID) + { + this.accountID = accountID; + } + + public Integer getCategoryID() + { + return categoryID; + } + + public void setCategoryID(Integer categoryID) + { + this.categoryID = categoryID; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public List<BackupTag_v4> getTags() + { + return tags; + } + + public void setTags(List<BackupTag_v4> tags) + { + this.tags = tags; + } + + public BackupRepeatingOption_v4 getRepeatingOption() + { + return repeatingOption; + } + + public void setRepeatingOption(BackupRepeatingOption_v4 repeatingOption) + { + this.repeatingOption = repeatingOption; + } + + public Integer getTransferAccountID() + { + return transferAccountID; + } + + public void setTransferAccountID(Integer transferAccountID) + { + this.transferAccountID = transferAccountID; + } + + @Override + public boolean equals(Object o) + { + if(this == o) return true; + if(o == null || getClass() != o.getClass()) return false; + BackupTransaction_v6 that = (BackupTransaction_v6) o; + return Objects.equals(amount, that.amount) && Objects.equals(isExpenditure, that.isExpenditure) && Objects.equals(date, that.date) && Objects.equals(accountID, that.accountID) && Objects.equals(categoryID, that.categoryID) && Objects.equals(name, that.name) && Objects.equals(description, that.description) && Objects.equals(tags, that.tags) && Objects.equals(repeatingOption, that.repeatingOption) && Objects.equals(transferAccountID, that.transferAccountID); + } + + @Override + public int hashCode() + { + return Objects.hash(amount, isExpenditure, date, accountID, categoryID, name, description, tags, repeatingOption, transferAccountID); + } + + @Override + public String toString() + { + return "BackupTransaction_v6{amount=" + amount + + ", isExpenditure=" + isExpenditure + + ", date=" + date + + ", accountID=" + accountID + + ", categoryID=" + categoryID + + ", name='" + name + '\'' + + ", description='" + description + '\'' + + ", tags=" + tags + + ", repeatingOption=" + repeatingOption + + ", transferAccountID=" + transferAccountID + + '}'; + } +}