Coverage Summary for Class: BizGenAppSettingsPersistent (ru.eda.plgn.bizgen.plugin.settings.persistent)

Class Class, % Method, % Branch, % Line, % Instruction, %
BizGenAppSettingsPersistent 100% (1/1) 75% (3/4) 50% (1/2) 83.3% (10/12) 92.5% (49/53)


 package ru.eda.plgn.bizgen.plugin.settings.persistent
 
 import com.intellij.openapi.components.PersistentStateComponent
 import com.intellij.openapi.components.SettingsCategory
 import com.intellij.openapi.components.State
 import com.intellij.openapi.components.Storage
 import com.intellij.openapi.diagnostic.Logger
 import ru.eda.plgn.bizgen.plugin.di.getBizGenService
 import ru.eda.plgn.bizgen.plugin.settings.BizGenAppSettingsRepository
 import ru.eda.plgn.bizgen.plugin.settings.model.BizGenAppSettings
 
 /**
  * Отвечает за сохранение настроек [BizGenAppSettings] на диск.
  *
  * @property settings настройки плагина
  * @author Dmitry_Emelyanenko
  */
 @State(
   name = "Ru BizGen",
   storages = [
     Storage("bizgen_plugin_settings.xml"),
   ],
   category = SettingsCategory.PLUGINS,
 )
 internal class BizGenAppSettingsPersistent(
   var settings: BizGenAppSettings = BizGenAppSettings(),
 ) : PersistentStateComponent<BizGenAppSettings>, BizGenAppSettingsRepository {
 
   private val log = Logger.getInstance(this::class.java)
 
   override fun getState(): BizGenAppSettings = settings
 
   override fun loadState(bizGenAppSettings: BizGenAppSettings) {
     try {
       // Мягкая миграция
       val updatedActions = getBizGenService<BizGenAppSettingsSoftUpdater>().softUpdateActions(bizGenAppSettings.actualActions)
 
       bizGenAppSettings.actualActions = updatedActions
     } catch (ex: Exception) {
       log.warn("Failed to soft update actions", ex)
       bizGenAppSettings.restoreFromDefault()
     }
 
     if (bizGenAppSettings.actualActions.isEmpty()) {
       bizGenAppSettings.restoreFromDefault()
     }
 
     settings = bizGenAppSettings
   }
 
   override fun settings(): BizGenAppSettings {
     return settings
   }
 }