-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐞 fix autocategory functionality - 500 #50
Comments
lot of code changed... possibly when I reverted one of the commits. working code to be moved to a service: @PostMapping("/autoCategorize")
public String autoCategorize(Model model) {
List<TransactionEntity> unCategorizedTransactions = transactionRepository.findByCategoriesEmpty();
log.info("Number of uncategorized transactions: " + unCategorizedTransactions.size());
List<AutoCategoryEntity> autoCategories = autoCategoryRepository.findAll();
int numCategorized = 0;
for (AutoCategoryEntity autoCategory : autoCategories) {
// Try to find an existing CategoryEntity with this category
CategoryEntity existingCategory = categoryRepository.findByCategory(autoCategory.getCategory());
// If none exists, create a new one
if (existingCategory == null) {
existingCategory = new CategoryEntity();
existingCategory.setCategory(autoCategory.getCategory());
categoryRepository.save(existingCategory); // don't forget to save the new category
}
for (TransactionEntity transaction : unCategorizedTransactions) {
for (String query : autoCategory.getQueries()) {
if (transaction.getEntity().toLowerCase().contains(query.toLowerCase()) ||
transaction.getDescription().toLowerCase().contains(query.toLowerCase())) {
transaction.addCategory(existingCategory);
transactionRepository.save(transaction);
numCategorized++;
break;
}
}
}
}
log.info("Transactions categorized: " + numCategorized);
model.addAttribute("message", "Auto-categorized " + numCategorized + " transactions");
return "redirect:/auto-category";
} |
java.lang.NullPointerException: Cannot invoke "java.lang.String.toLowerCase()" because the return value of "nl.marisabel.backend.transactions.entity.TransactionEntity.getDescription()" is null |
private final CategoryRepository categoryRepository; // CURRENT NOT WORKING
//TransactionEntity.getDescription()" is null
@PostMapping("/autoCategorize")
public String autoCategorize(Model model) {
List<TransactionEntity> unCategorizedTransactions = transactionRepository.findByCategoriesEmpty();
log.info("Number of uncategorized transactions: " + unCategorizedTransactions.size());
List<AutoCategoryEntity> autoCategories = autoCategoryRepository.findAll();
int numCategorized = 0;
for (AutoCategoryEntity autoCategory : autoCategories) {
// Try to find an existing CategoryEntity with this category
CategoryEntity existingCategory = categoryRepository.findByCategory(autoCategory.getCategory());
// If none exists, create a new one
if (existingCategory == null) {
existingCategory = new CategoryEntity();
existingCategory.setCategory(autoCategory.getCategory());
categoryRepository.save(existingCategory); // don't forget to save the new category
}
for (TransactionEntity transaction : unCategorizedTransactions) {
for (String query : autoCategory.getQueries()) {
if (transaction.getEntity().toLowerCase().contains(query.toLowerCase()) ||
transaction.getDescription().toLowerCase().contains(query.toLowerCase())) {
transaction.addCategory(existingCategory);
transactionRepository.save(transaction);
numCategorized++;
break;
}
}
}
}
log.info("Transactions categorized: " + numCategorized);
model.addAttribute("message", "Auto-categorized " + numCategorized + " transactions");
return "redirect:/auto-category";
}
// ORIGINAL WORKING
@PostMapping("/autoCategorize")
public String autoCategorize(Model model) {
List<TransactionEntity> unCategorizedTransactions = transactionRepository.findByCategoriesEmpty();
log.info("Number of uncategorized transactions: " + unCategorizedTransactions.size());
List<AutoCategoryEntity> autoCategories = autoCategoryRepository.findAll();
int numCategorized = 0;
for (TransactionEntity transaction : unCategorizedTransactions) {
for (AutoCategoryEntity autoCategory : autoCategories) {
for (String query : autoCategory.getQueries()) {
if (transaction.getEntity().toLowerCase().contains(query.toLowerCase()) ||
transaction.getDescription().toLowerCase().contains(query.toLowerCase())) {
CategoryEntity newCategory = new CategoryEntity();
newCategory.setCategory(autoCategory.getCategory());
transaction.addCategory(newCategory);
transactionRepository.save(transaction);
numCategorized++;
break;
}
}
}
}
log.info("Transactions categorized: " + numCategorized);
model.addAttribute("message", "Auto-categorized " + numCategorized + " transactions");
return "redirect:/auto-category";
}
|
…description being null. Will revisit later.
…description being null. Will revisit later.
java.lang.NullPointerException: Cannot invoke "java.lang.String.toLowerCase()" because the return value of "nl.marisabel.backend.transactions.entity.TransactionEntity.getDescription()" is null
at nl.marisabel.backend.categories.service.CategoryService.isTransactionMatch(CategoryService.java:57) ~[classes/:na]
TO DO:
transaction.getDescription()
being nullofficially, it should never be the case. But it is an edge case.
The text was updated successfully, but these errors were encountered: