Search in sources :

Example 1 with LocalUserImage

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

the class LocalUserImageDAO method create.

public LocalUserImage create(LocalUser user, String contentType, byte[] content) {
    LocalUserImage localUserImage = new LocalUserImage();
    localUserImage.setUser(user);
    localUserImage.setContentType(contentType);
    localUserImage.setContent(content);
    return persist(localUserImage);
}
Also used : LocalUserImage(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserImage)

Example 2 with LocalUserImage

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

the class LocalUserSchoolDataBridge method listUserImagesByUserIdentifier.

/**
 * {@inheritDoc}
 */
@Override
public List<UserImage> listUserImagesByUserIdentifier(String userIdentifier) {
    List<UserImage> result = new ArrayList<>();
    List<LocalUserImage> images = localUserSchoolDataController.listUserImagesByUserIdentifier(userIdentifier);
    for (LocalUserImage image : images) {
        UserImage userImage = toLocalUserImageImpl(image);
        if (userImage != null) {
            result.add(userImage);
        } else {
            throw new SchoolDataBridgeInternalException("Unexpected error occured while listing LocalUserImages");
        }
    }
    return result;
}
Also used : LocalUserImage(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserImage) UserImage(fi.otavanopisto.muikku.schooldata.entity.UserImage) LocalUserImage(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserImage) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList)

Example 3 with LocalUserImage

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

the class LocalUserSchoolDataBridge method removeUserImage.

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

Example 4 with LocalUserImage

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

the class LocalUserImageDAO method listByUser.

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

Aggregations

LocalUserImage (fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserImage)4 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)2 UserImage (fi.otavanopisto.muikku.schooldata.entity.UserImage)1 ArrayList (java.util.ArrayList)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1