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

import javax.inject.Inject;

import org.primefaces.model.DefaultStreamedContent;

import de.ivu.elect.business.dokumente.entity.DokumentVorlage;
import de.ivu.elect.business.exchange.control.ImportExportStreamCreator;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.jee.faces.download.DownloadAction;

public class DokumentVorlageDownloadAction extends AbstractDokumentVorlageAction {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient ImportExportStreamCreator streamCreator;

  @Inject
  private transient DownloadAction downloadAction;

  public DokumentVorlageDownloadAction() {
    super();
  }

  @Override
  protected UseCasePermission getRequiredPermission() {
    return UseCasePermission.DOKUMENT_VORLAGE_SEARCH;
  }

  @Override
  protected String doIt(DokumentVorlage entity) {
    DefaultStreamedContent defaultStreamedContent = entity.getDatei().getDefaultStreamedContent(streamCreator);

    download(defaultStreamedContent);

    return null;
  }

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

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

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

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