use of fi.otavanopisto.muikku.model.users.UserEmailEntity in project muikku by otavanopisto.
the class UserEmailEntityDAO method findByUserSchoolDataIdentifierAndAddress.
public UserEmailEntity findByUserSchoolDataIdentifierAndAddress(UserSchoolDataIdentifier identifier, String address) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserEmailEntity> criteria = criteriaBuilder.createQuery(UserEmailEntity.class);
Root<UserEmailEntity> root = criteria.from(UserEmailEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserEmailEntity_.userSchoolDataIdentifier), identifier), criteriaBuilder.equal(root.get(UserEmailEntity_.address), address)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.model.users.UserEmailEntity in project muikku by otavanopisto.
the class UserEntityController method findUserEntityByEmailAddress.
public UserEntity findUserEntityByEmailAddress(String emailAddress) {
UserEntity result = null;
Collection<String> emails = new HashSet<>();
emails.add(emailAddress);
List<UserEmailEntity> emailEntities = userEmailEntityDAO.listByAddresses(emails);
for (UserEmailEntity emailEntity : emailEntities) {
if (result == null) {
result = emailEntity.getUserSchoolDataIdentifier().getUserEntity();
} else if (!result.getId().equals(emailEntity.getUserSchoolDataIdentifier().getUserEntity().getId())) {
logger.severe(String.format("Email %s resolves to multiple UserEntity instances", emailAddress));
return null;
}
}
return result;
}
use of fi.otavanopisto.muikku.model.users.UserEmailEntity in project muikku by otavanopisto.
the class UserEmailEntityController method getUserEmailAddresses.
public List<String> getUserEmailAddresses(UserSchoolDataIdentifier userSchoolDataIdentifier) {
List<UserEmailEntity> userEmailEntities = userEmailEntityDAO.listByUserSchoolDataIdentifier(userSchoolDataIdentifier);
List<String> emailAddresses = new ArrayList<>();
for (UserEmailEntity userEmailEntity : userEmailEntities) {
emailAddresses.add(userEmailEntity.getAddress());
}
return emailAddresses;
}
use of fi.otavanopisto.muikku.model.users.UserEmailEntity in project muikku by otavanopisto.
the class UserEntityController method listUserEntitiesByEmails.
public Collection<UserEntity> listUserEntitiesByEmails(Collection<String> emails) {
if (emails == null || emails.isEmpty()) {
return Collections.emptyList();
}
List<UserEmailEntity> userEmailEntities = userEmailEntityDAO.listByAddresses(emails);
Map<Long, UserEntity> userEntities = new HashMap<>();
for (UserEmailEntity userEmailEntity : userEmailEntities) {
UserEntity userEntity = userEmailEntity.getUserSchoolDataIdentifier().getUserEntity();
userEntities.put(userEntity.getId(), userEntity);
}
return userEntities.values();
}
use of fi.otavanopisto.muikku.model.users.UserEmailEntity in project muikku by otavanopisto.
the class UserEmailEntityDAO method listByAddresses.
public List<UserEmailEntity> listByAddresses(Collection<String> addresses) {
if (addresses == null || addresses.isEmpty()) {
return Collections.emptyList();
}
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserEmailEntity> criteria = criteriaBuilder.createQuery(UserEmailEntity.class);
Root<UserEmailEntity> root = criteria.from(UserEmailEntity.class);
criteria.select(root);
criteria.where(root.get(UserEmailEntity_.address).in(addresses));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations