Skip to content
Snippets Groups Projects
Commit 72c6253b authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#622 - migrate category attributes on start

parent 5c0f251f
Branches
Tags
No related merge requests found
package de.deadlocker8.budgetmaster.categories;
import de.deadlocker8.budgetmaster.icon.Icon;
import de.deadlocker8.budgetmaster.icon.IconService;
import de.deadlocker8.budgetmaster.services.AccessAllEntities;
import de.deadlocker8.budgetmaster.services.Resettable;
import de.deadlocker8.budgetmaster.transactions.Transaction;
......@@ -11,6 +13,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.MessageFormat;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
......@@ -20,11 +23,13 @@ public class CategoryService implements Resettable, AccessAllEntities<Category>
{
private static final Logger LOGGER = LoggerFactory.getLogger(CategoryService.class);
private final CategoryRepository categoryRepository;
private final IconService iconService;
@Autowired
public CategoryService(CategoryRepository categoryRepository)
public CategoryService(CategoryRepository categoryRepository, IconService iconService)
{
this.categoryRepository = categoryRepository;
this.iconService = iconService;
createDefaults();
}
......@@ -97,6 +102,27 @@ public class CategoryService implements Resettable, AccessAllEntities<Category>
categoryRepository.save(new Category(Localization.getString(Strings.CATEGORY_REST), "#FFFF00", CategoryType.REST));
LOGGER.debug("Created default category REST");
}
updateMissingAttributes();
}
private void updateMissingAttributes()
{
for(Category category : categoryRepository.findAll())
{
if(category.getIcon() != null && category.getIconReference() == null)
{
final String iconName = category.getIcon();
Icon iconReference = new Icon(iconName);
iconService.getRepository().save(iconReference);
category.setIconReference(iconReference);
category.setIcon(null);
categoryRepository.save(category);
LOGGER.debug(MessageFormat.format("Updated category {0}: Converted attribute \"icon\" to \"iconReference\" {1}", category.getName(), iconName));
}
}
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment