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

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

import org.apache.deltaspike.core.api.scope.ConversationGroup;

import de.ivu.elect.business.benutzerverwaltung.boundary.BaseRolleBoundaryCreate;
import de.ivu.elect.business.benutzerverwaltung.boundary.RolleConversationStore;
import de.ivu.elect.business.benutzerverwaltung.entity.Rolle;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.presentation.benutzerverwaltung.RolleEditView;

public class RolleKopieAction extends AbstractRolleAction {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient BaseRolleBoundaryCreate rolleBoundaryCreate;

  @Inject
  @ConversationGroup(RolleConversationStore.class)
  RolleConversationStore conversationStore;

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

  @Override
  public boolean isDisabledInternal(@Nonnull Rolle rolle) {
    return false;
  }

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

  @Override
  protected String doIt(Rolle rolle) {
    Rolle copy = rolleBoundaryCreate.copy(rolle);
    messages.addInfoMessage("rolle.kopiert");
    conversationStore.setEntityPK(copy.getPk());

    return RolleEditView.VIEW_ID;
  }

  @Override
  public String getLabelKey() {
    return "entity.edit.action.copy";
  }

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