Search in sources :

Example 1 with LocalUserEmail

use of fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail in project muikku by otavanopisto.

the class LocalUserSchoolDataBridge method removeUserEmail.

/**
 * {@inheritDoc}
 */
@Override
public void removeUserEmail(String identifier) {
    LocalUserEmail localUserEmail = localUserSchoolDataController.findUserEmail(identifier);
    if (localUserEmail == null) {
        throw new SchoolDataBridgeInternalException("UserEmail can not be removed because it does not exist");
    }
    localUserSchoolDataController.removeUserEmail(localUserEmail);
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) LocalUserEmail(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)

Example 2 with LocalUserEmail

use of fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail in project muikku by otavanopisto.

the class LocalUserEmailDAO method listByUserAndArchived.

public List<LocalUserEmail> listByUserAndArchived(LocalUser user, Boolean archived) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<LocalUserEmail> criteria = criteriaBuilder.createQuery(LocalUserEmail.class);
    Root<LocalUserEmail> root = criteria.from(LocalUserEmail.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(LocalUserEmail_.user), user), criteriaBuilder.equal(root.get(LocalUserEmail_.archived), archived)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) LocalUserEmail(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)

Example 3 with LocalUserEmail

use of fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail in project muikku by otavanopisto.

the class LocalUserEmailDAO method create.

public LocalUserEmail create(LocalUser user, String address, Boolean archived) {
    LocalUserEmail localUserEmail = new LocalUserEmail();
    localUserEmail.setUser(user);
    localUserEmail.setAddress(address);
    localUserEmail.setArchived(archived);
    return persist(localUserEmail);
}
Also used : LocalUserEmail(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)

Example 4 with LocalUserEmail

use of fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail in project muikku by otavanopisto.

the class LocalUserSchoolDataBridge method listUserEmailsByUserIdentifier.

/**
 * {@inheritDoc}
 */
@Override
public List<UserEmail> listUserEmailsByUserIdentifier(String userIdentifier) {
    if (!StringUtils.isNumeric(userIdentifier)) {
        throw new SchoolDataBridgeInternalException("userIdentifier is invalid");
    }
    List<UserEmail> result = new ArrayList<>();
    List<LocalUserEmail> emails = localUserSchoolDataController.listUserEmailsByUserIdentifier(userIdentifier);
    for (LocalUserEmail email : emails) {
        UserEmail emailImpl = toLocalUserEmailImpl(email);
        if (emailImpl != null) {
            result.add(emailImpl);
        } else {
            throw new SchoolDataBridgeInternalException("Unexpected error occured while listing LocalUserEmails");
        }
    }
    return result;
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList) LocalUserEmail(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail) UserEmail(fi.otavanopisto.muikku.schooldata.entity.UserEmail) LocalUserEmail(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)

Example 5 with LocalUserEmail

use of fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail in project muikku by otavanopisto.

the class LocalUserEmailDAO method findByAddressAndArchived.

public LocalUserEmail findByAddressAndArchived(String address, Boolean archived) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<LocalUserEmail> criteria = criteriaBuilder.createQuery(LocalUserEmail.class);
    Root<LocalUserEmail> root = criteria.from(LocalUserEmail.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(LocalUserEmail_.address), address), criteriaBuilder.equal(root.get(LocalUserEmail_.archived), archived)));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) LocalUserEmail(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)

Aggregations

LocalUserEmail (fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)5 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 UserEmail (fi.otavanopisto.muikku.schooldata.entity.UserEmail)1 ArrayList (java.util.ArrayList)1