
package de.ivu.elect.business.kandidatenportal.boundary;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

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

import de.ivu.elect.business.kandidatenportal.entity.WvpWarnung;

@RequestScoped
@Named(WvpWarnungConversationSelect.COMPONENT_NAME)
public class WvpWarnungConversationSelect implements java.io.Serializable {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "wvpWarnungConversationSelect";

  @Inject
  protected transient WvpWarnungExtendedDAO entityDAO;

  @Inject
  @ConversationGroup(WvpWarnungConversationStore.class)
  protected transient WvpWarnungConversationStore conversationStore;

  public WvpWarnungConversationSelect() {
    super();
  }

  public boolean isSelected() {
    return getEntityPK() != null;
  }

  public WvpWarnung getEntity() {
    return getEntityInternal();
  }

  private WvpWarnung getEntityInternal() {
    if (getEntityPK() == null) {
      return null;
    }

    return attach(getEntityPK());
  }

  public void setEntity(WvpWarnung entity) {
    setEntityAttached(attach(entity));
  }

  public void setEntity( de.ivu.elect.business.kandidatenportal.entity.WvpWarnungPK  pk) {
    setEntityAttached(attach(pk));
  }

  protected void setEntityAttached(WvpWarnung entity) {
    if(entity == null) {
      setEntityPK(null);
    } else {
      setEntityPK(entity.getPk());
    }
  }

  public
    de.ivu.elect.business.kandidatenportal.entity.WvpWarnungPK
   getEntityPK() {
    return conversationStore.getEntityPK();
  }

  public void setEntityPK(
    de.ivu.elect.business.kandidatenportal.entity.WvpWarnungPK
   entityPK) {
    conversationStore.setEntityPK(entityPK);
  }

  protected WvpWarnung attach(WvpWarnung entity) {
    if (entity == null){
      return null;
    }

    return attach(entity.getPk());
  }

  protected WvpWarnung attach( de.ivu.elect.business.kandidatenportal.entity.WvpWarnungPK  pk) {
    if (pk == null) {
      return null;
    }

    return entityDAO.findByPrimaryKey(pk);
  }

  public void clearEntity() {
    setEntityPK(null);

    conversationStore.close();
  }
}
