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

import java.io.Serializable;

import javax.ejb.EJB;
import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.enterprise.event.TransactionPhase;

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 DokumenteKonfigurationListener implements Serializable {

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

  private static final long serialVersionUID = 1L;

  @EJB
  private transient DokumentePostStartupAsync dokumentePostStartupAsync;

  public void listen(@Observes(notifyObserver = Reception.ALWAYS, during = TransactionPhase.AFTER_SUCCESS) KonfigurationWertGeaendertEvent konfigurationWertGeaendertEvent) {

    if (CustomParameterKategorie.DOKUMENTENERZEUGUNG.equals(konfigurationWertGeaendertEvent.getKey().getKategorie())) {
      LOG.info("Konfigurationswert für Open Office geändert - Beende/Neustart Open/LibreOffice");
      dokumentePostStartupAsync.restartAsync();
    }

  }
}
