
package de.ivu.elect.business.personenpruefung.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.personenpruefung.entity.PersonPruefungKonfiguration;

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

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "personPruefungKonfigurationConversationSelect";

  @Inject
  protected transient PersonPruefungKonfigurationExtendedDAO entityDAO;

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

  public PersonPruefungKonfigurationConversationSelect() {
    super();
  }

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

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

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

    return attach(getEntityPK());
  }

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

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

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

  public
    de.ivu.elect.business.personenpruefung.entity.PersonPruefungKonfigurationPK
   getEntityPK() {
    return conversationStore.getEntityPK();
  }

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

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

    return attach(entity.getPk());
  }

  protected PersonPruefungKonfiguration attach( de.ivu.elect.business.personenpruefung.entity.PersonPruefungKonfigurationPK  pk) {
    if (pk == null) {
      return null;
    }

    return entityDAO.findByPrimaryKey(pk);
  }

  public void clearEntity() {
    setEntityPK(null);

    conversationStore.close();
  }
}
