package de.ivu.elect.business.system.control;

import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.enterprise.event.TransactionPhase;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.ivu.elect.business.konfiguration.entity.CustomParameterKategorie;
import de.ivu.elect.business.konfiguration.entity.KonfigurationWertGeaendertEvent;

public class VirusScanKonfigurationChangeListener {

  private static final Logger LOG = LoggerFactory.getLogger(VirusScanKonfigurationChangeListener.class);

  @Inject
  private transient VirusScanInit virusScanInit;

  public void listen(@Observes(during = TransactionPhase.AFTER_COMPLETION, notifyObserver = Reception.ALWAYS) KonfigurationWertGeaendertEvent konfigurationWertGeaendertEvent) {
    try {
      if (CustomParameterKategorie.VIRUS_SCAN.equals(konfigurationWertGeaendertEvent.getKey().getKategorie())) {
        virusScanInit.initScannerNewTransaction();
      }
    } catch (Exception e) {
      LOG.warn("Fehler: " + e.getMessage(), e);
    }
  }

}
