
package de.ivu.elect.business.benutzerverwaltung.entity;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.NoResultException;

import de.ivu.elect.business.benutzerverwaltung.boundary.RolleDAO;

@Stateless
public class UniqueRolleUKValidator {

  @Inject
  private RolleDAO dao;

  public boolean isUniqueUK(Rolle entity) {
    return isUniqueUK(entity.getPk(), entity.getRolleUK());
  }

  public boolean isUniqueUK(RollePK pk, RolleUK uk) {
    try {
      return getByUK(uk).getPk().equals(pk);
    } catch (NoResultException ignored) {
      // Do nothing - be happy.
    }
    return true;
  }

  protected Rolle getByUK(RolleUK uk) {
    return dao.findByUK(uk);
  }
}
