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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations