package de.ivu.elect.presentation.mandant.form;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;

import de.ivu.elect.business.mandant.boundary.MandantExtendedDAO;
import de.ivu.elect.business.mandant.entity.Mandant;
import de.ivu.elect.business.mandant.entity.MandantPK;
import de.ivu.elect.business.mandant.entity.MandantUK;
import de.ivu.elect.jee.entity.DAO;
import de.ivu.elect.jee.faces.AbstractEntityUniqueUKFacesValidator;

public class MandantUniqueUKFacesValidator extends AbstractEntityUniqueUKFacesValidator<Mandant, MandantPK, MandantUK> {

  private static final long serialVersionUID = 1L;

  @Inject
  private MandantExtendedDAO extendedDAO;

  public MandantUniqueUKFacesValidator() {
    super();
  }

  @Override
  protected MandantUK createUK(Object value) {
    if (value == null || StringUtils.isBlank(value.toString())) {
      return new MandantUK(null);
    }
    return new MandantUK(Long.parseLong(value.toString()));
  }

  @Override
  protected DAO<Mandant, MandantPK, MandantUK> getDao() {
    return extendedDAO;
  }
}
