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 de.ivu.elect.business.konfiguration.entity.ElectKonfigurationWerte;
import de.ivu.elect.business.konfiguration.entity.KonfigurationWertGeaendertEvent;


import static de.ivu.elect.business.system.control.HttpHeaderKonfigurationHelper.isHttpHeaderParameter;

public class HttpHeaderKonfigWertGeandertListener {

  @Inject
  private transient HttpHeaderKonfigurationAktualisieren httpHeaderKonfigurationAktualisieren;

  public void listen(@Observes(during = TransactionPhase.AFTER_COMPLETION, notifyObserver = Reception.ALWAYS) KonfigurationWertGeaendertEvent konfigurationWertGeaendertEvent) {
    if (isHttpHeaderParameter(konfigurationWertGeaendertEvent.getKey())
        || ElectKonfigurationWerte.DASHBOARD_NEWS_IFRAME_HOST.equals(konfigurationWertGeaendertEvent.getKey())
        || ElectKonfigurationWerte.HTTP_LOGGING_LOGIN_ACCESS.equals(konfigurationWertGeaendertEvent.getKey())) {
      httpHeaderKonfigurationAktualisieren.aktualisiereHttpHeader();
    }
  }

}
