Search in sources :

Example 1 with UserEmailEntity

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));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) UserEmailEntity(fi.otavanopisto.muikku.model.users.UserEmailEntity)

Example 2 with UserEmailEntity

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;
}
Also used : UserEmailEntity(fi.otavanopisto.muikku.model.users.UserEmailEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) HashSet(java.util.HashSet)

Example 3 with UserEmailEntity

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;
}
Also used : ArrayList(java.util.ArrayList) UserEmailEntity(fi.otavanopisto.muikku.model.users.UserEmailEntity)

Example 4 with UserEmailEntity

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();
}
Also used : HashMap(java.util.HashMap) UserEmailEntity(fi.otavanopisto.muikku.model.users.UserEmailEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 5 with UserEmailEntity

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) UserEmailEntity(fi.otavanopisto.muikku.model.users.UserEmailEntity)

Aggregations

UserEmailEntity (fi.otavanopisto.muikku.model.users.UserEmailEntity)7 EntityManager (javax.persistence.EntityManager)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1