
package de.ivu.elect.presentation.exchange.action;

import javax.annotation.Nonnull;
import javax.inject.Inject;

import org.primefaces.model.DefaultStreamedContent;

import de.ivu.elect.business.datei.entity.DateiImport;
import de.ivu.elect.business.exchange.control.ImportExportStreamCreator;
import de.ivu.elect.jee.faces.download.DownloadAction;

public class DateiImportDownloadAction extends AbstractDateiImportAction {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient ImportExportStreamCreator streamCreator;

  @Inject
  private transient DownloadAction downloadAction;

  @Override
  public String getLabelKey() {
    return "datei.import.action.download";
  }

  @Override
  public String getIcon() {
    return appIcons.getIconDownload();
  }

  @Override
  protected String doIt(DateiImport entity) {
    DefaultStreamedContent defaultStreamedContent = entity.getDatei().getDefaultStreamedContent(streamCreator);
    download(defaultStreamedContent);
    return null;
  }

  private void download(DefaultStreamedContent content) {
    downloadAction.download(content);
  }

  @Override
  public boolean isDisabledInternal(@Nonnull DateiImport entity) {
    return false;
  }

  @Override
  protected boolean isAsyncSupported() {
    return false;
  }
}
