Search in sources :

Example 1 with GPDAOException

use of org.geosdi.geoplatform.persistence.dao.exception.GPDAOException in project geo-platform by geosdi.

the class GPAccountDAOImpl method searchPagebleEnabledUsersByOrganization.

/**
 * @param page
 * @param size
 * @param organizationName
 * @param userID
 * @param nameLike
 * @return {@link List<GPAccount>}
 * @throws GPDAOException
 */
@Override
public List<GPAccount> searchPagebleEnabledUsersByOrganization(Integer page, Integer size, String organizationName, Long userID, String nameLike) throws GPDAOException {
    checkArgument((organizationName != null) && !(organizationName.trim().isEmpty()), "The Paramater organizationName must not be null or an Empty String.");
    checkArgument(userID != null, "The Parameter userID must not be null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GPAccount> criteriaQuery = super.createCriteriaQuery();
        Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
        Root<GPUser> userRoot = builder.treat(root, GPUser.class);
        criteriaQuery.select(root);
        List<Predicate> predicates = Lists.newArrayList();
        if ((nameLike != null) && !(nameLike.trim().isEmpty()))
            predicates.add(builder.like(builder.lower(userRoot.get("username")), nameLike.toLowerCase()));
        predicates.add(builder.equal(root.get("enabled"), TRUE));
        predicates.add(builder.equal(root.join("organization").get("name"), organizationName));
        predicates.add(builder.notEqual(root.get("id"), userID));
        predicates.add(builder.isNotNull(userRoot.get("username")));
        criteriaQuery.where(predicates.stream().toArray(Predicate[]::new)).orderBy(builder.asc(userRoot.get("username")));
        Query typedQuery = this.entityManager.createQuery(criteriaQuery);
        Integer firstResult = (page == 0) ? 0 : ((page * size));
        typedQuery.setFirstResult(firstResult);
        typedQuery.setMaxResults(size);
        return typedQuery.getResultList();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPUser(org.geosdi.geoplatform.core.model.GPUser) Query(javax.persistence.Query) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 2 with GPDAOException

use of org.geosdi.geoplatform.persistence.dao.exception.GPDAOException in project geo-platform by geosdi.

the class GPAccountDAOImpl method findByUsername.

/**
 * @param username
 * @return {@link GPUser}
 * @throws Exception
 */
@Override
public GPUser findByUsername(String username) throws GPDAOException {
    checkArgument((username != null) && !(username.trim().isEmpty()), "The Parameter username must not be null or an empty String.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GPAccount> criteriaQuery = super.createCriteriaQuery();
        Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
        Root<GPUser> userRoot = builder.treat(root, GPUser.class);
        criteriaQuery.select(root);
        criteriaQuery.where(super.criteriaBuilder().equal(userRoot.get("username"), username));
        List<GPAccount> accounts = this.entityManager.createQuery(criteriaQuery).getResultList();
        return ((accounts != null) && !(accounts.isEmpty()) ? (GPUser) accounts.get(0) : null);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPUser(org.geosdi.geoplatform.core.model.GPUser) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 3 with GPDAOException

use of org.geosdi.geoplatform.persistence.dao.exception.GPDAOException in project geo-platform by geosdi.

the class GPAccountDAOImpl method findByAppID.

/**
 * @param appID
 * @return {@link GPApplication}
 * @throws Exception
 */
@Override
public GPApplication findByAppID(String appID) throws GPDAOException {
    checkArgument((appID != null) && !(appID.trim().isEmpty()), "" + "The Parameter appID must not be null or an empty String.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GPAccount> criteriaQuery = super.createCriteriaQuery();
        Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
        Root<GPApplication> applicationRoot = builder.treat(root, GPApplication.class);
        criteriaQuery.select(root);
        criteriaQuery.where(super.criteriaBuilder().equal(applicationRoot.get("appID"), appID));
        List<GPAccount> applications = this.entityManager.createQuery(criteriaQuery).getResultList();
        return ((applications != null) && !(applications.isEmpty()) ? (GPApplication) applications.get(0) : null);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPApplication(org.geosdi.geoplatform.core.model.GPApplication)

Example 4 with GPDAOException

use of org.geosdi.geoplatform.persistence.dao.exception.GPDAOException in project geo-platform by geosdi.

the class GPAccountDAOImpl method countUsers.

/**
 * @param organizationName
 * @param nameLike
 * @return {@link Number}
 * @throws GPDAOException
 */
@Override
public Number countUsers(String organizationName, String nameLike) throws GPDAOException {
    checkArgument((organizationName != null) && !(organizationName.trim().isEmpty()), "The Paramater organizationName must not be null or an Empty String.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
        Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
        Root<GPUser> userRoot = builder.treat(root, GPUser.class);
        criteriaQuery.select(builder.count(root));
        List<Predicate> predicates = Lists.newArrayList();
        predicates.add(builder.equal(root.join("organization").get("name"), organizationName));
        predicates.add(builder.isNotNull(userRoot.get("username")));
        if ((nameLike != null) && !(nameLike.isEmpty()))
            predicates.add(builder.like(builder.lower(userRoot.get("username")), nameLike.toLowerCase()));
        criteriaQuery.where(predicates.stream().toArray(size -> new Predicate[size]));
        return this.entityManager.createQuery(criteriaQuery).getSingleResult();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPApplication(org.geosdi.geoplatform.core.model.GPApplication) FALSE(java.lang.Boolean.FALSE) GPAccountDAO(org.geosdi.geoplatform.core.dao.GPAccountDAO) GPUser(org.geosdi.geoplatform.core.model.GPUser) Profile(org.springframework.context.annotation.Profile) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) Query(javax.persistence.Query) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) javax.persistence.criteria(javax.persistence.criteria) GPAbstractJpaDAO(org.geosdi.geoplatform.persistence.dao.jpa.GPAbstractJpaDAO) Repository(org.springframework.stereotype.Repository) TRUE(java.lang.Boolean.TRUE) GPUser(org.geosdi.geoplatform.core.model.GPUser) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 5 with GPDAOException

use of org.geosdi.geoplatform.persistence.dao.exception.GPDAOException in project geo-platform by geosdi.

the class GPAccountDAOImpl method countAccounts.

/**
 * @param nameLike
 * @return {@link Number}
 * @throws GPDAOException
 */
@Override
public Number countAccounts(String nameLike) throws GPDAOException {
    checkArgument(((nameLike != null) && !(nameLike.trim().isEmpty())), "The Parameter nameLike must not be null or an empty string.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
        Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
        Root<GPUser> userRoot = builder.treat(root, GPUser.class);
        Root<GPApplication> applicationRoot = builder.treat(root, GPApplication.class);
        criteriaQuery.select(builder.count(root));
        criteriaQuery.where(builder.or(builder.like(builder.lower(userRoot.get("username")), nameLike.toLowerCase()), builder.like(builder.lower(applicationRoot.get("appID")), nameLike.toLowerCase())));
        return entityManager.createQuery(criteriaQuery).getSingleResult();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPUser(org.geosdi.geoplatform.core.model.GPUser) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPApplication(org.geosdi.geoplatform.core.model.GPApplication)

Aggregations

GPDAOException (org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)95 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)39 Query (javax.persistence.Query)17 HibernateException (org.hibernate.HibernateException)16 GPFolder (org.geosdi.geoplatform.core.model.GPFolder)14 GPAccountProject (org.geosdi.geoplatform.core.model.GPAccountProject)11 GPAccount (org.geosdi.geoplatform.core.model.GPAccount)9 GPUser (org.geosdi.geoplatform.core.model.GPUser)6 GeoPlatformServer (org.geosdi.geoplatform.core.model.GeoPlatformServer)6 GPProject (org.geosdi.geoplatform.core.model.GPProject)5 GPLayer (org.geosdi.geoplatform.core.model.GPLayer)4 GPApplication (org.geosdi.geoplatform.core.model.GPApplication)3 GPAuthority (org.geosdi.geoplatform.core.model.GPAuthority)3 GPMessage (org.geosdi.geoplatform.core.model.GPMessage)3 GPOrganization (org.geosdi.geoplatform.core.model.GPOrganization)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Lists (com.google.common.collect.Lists)2 FALSE (java.lang.Boolean.FALSE)2 TRUE (java.lang.Boolean.TRUE)2 ArrayList (java.util.ArrayList)2