
package de.ivu.elect.presentation.system;

import java.io.Serializable;
import java.util.List;

import javax.inject.Inject;

import org.primefaces.model.DefaultStreamedContent;

import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.security.control.ElectCommonPrincipal;
import de.ivu.elect.jee.presentation.search.TableExportMetaData;
import de.ivu.elect.presentation.AbstractElectStatusView;
import de.ivu.elect.presentation.table.TableExporterType;

public abstract class AbstractStatusExporter implements Serializable {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient ElectCommonPrincipal principal;

  @Inject
  private transient StatusExporterColumnBuilder statusExporterColumnBuilder;

  protected abstract TableExporterType getTableExporter();

  private boolean isMapperAvailable() {
    return getTableExporter().isMapperAvailable();
  }

  public boolean isBtnExportRendered() {
    return principal.hasUseCasePermission(UseCasePermission.STATUS_UEBERSICHTEN_EXPORTIEREN) && isMapperAvailable();
  }

  public DefaultStreamedContent export(AbstractElectStatusView< ? > statusView) {
    statusExporterColumnBuilder.initColumns();
    statusExporterColumnBuilder.setAdditionalColumns(statusView.getAdditionalColumnsForExport());
    List statusEntries = statusView.getStatusEntries();
    return getTableExporter().export(statusExporterColumnBuilder, statusEntries, new TableExportMetaData());
  }
}
