Search in sources :

Example 61 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class GroupDAO method getMemberCount.

public long getMemberCount(String uuid) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Group> from = query.from(Group.class);
        Join<Group, Account> member = from.join("members");
        query.select(getBuilder().countDistinct(member.get("id")));
        query.where(getBuilder().equal(from.get("uuid"), uuid));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Group(org.jbei.ice.storage.model.Group) Account(org.jbei.ice.storage.model.Account) HibernateException(org.hibernate.HibernateException)

Example 62 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class GroupDAO method retrieveMemberGroups.

public List<Group> retrieveMemberGroups(Account account) {
    try {
        CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
        Root<Group> from = query.from(Group.class);
        Join<Group, Account> members = from.join("members", JoinType.LEFT);
        query.where(getBuilder().or(getBuilder().equal(from.get("owner"), account), getBuilder().equal(members.get("email"), account.getEmail())));
        return currentSession().createQuery(query).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Group(org.jbei.ice.storage.model.Group) Account(org.jbei.ice.storage.model.Account) HibernateException(org.hibernate.HibernateException)

Example 63 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class GroupDAO method getMatchingGroups.

public List<Group> getMatchingGroups(Account account, String token, int limit) {
    Set<Group> userGroups = account.getGroups();
    try {
        token = token.toUpperCase();
        CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
        Root<Group> from = query.from(Group.class);
        List<Predicate> predicates = new ArrayList<>();
        predicates.add(getBuilder().like(getBuilder().upper(from.get("label")), "%" + token + "%"));
        predicates.add(getBuilder().notEqual(from.get("uuid"), GroupController.PUBLIC_GROUP_UUID));
        Predicate predicate = getBuilder().or(getBuilder().equal(from.get("type"), GroupType.PUBLIC), getBuilder().equal(from.get("owner"), account));
        if (userGroups != null && !userGroups.isEmpty()) {
            predicate.getExpressions().add(from.in(userGroups));
        }
        predicates.add(predicate);
        query.where(predicates.toArray(new Predicate[predicates.size()]));
        return currentSession().createQuery(query).setMaxResults(limit).list();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException("Error retrieving matching groups", e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Group(org.jbei.ice.storage.model.Group) HibernateException(org.hibernate.HibernateException) ArrayList(java.util.ArrayList)

Example 64 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class FeatureDAO method getFeaturesGroupByCount.

public long getFeaturesGroupByCount() {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Feature> from = query.from(Feature.class);
        query.select(getBuilder().countDistinct(from.get("name"))).where(getBuilder().isNotNull(from.get("name")), getBuilder().notEqual(from.get("name"), ""));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Feature(org.jbei.ice.storage.model.Feature)

Example 65 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class FeatureDAO method getFeatures.

public List<Feature> getFeatures(int offset, int size, String filter) {
    try {
        CriteriaQuery<Feature> query = getBuilder().createQuery(Feature.class);
        Root<Feature> from = query.from(Feature.class);
        if (filter != null && !filter.isEmpty())
            query.where(getBuilder().like(getBuilder().lower(from.get("name")), "%" + filter.toLowerCase() + "%"));
        else
            query.where(getBuilder().isNotNull(from.get("name")), getBuilder().notEqual(from.get("name"), ""));
        return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(size).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Feature(org.jbei.ice.storage.model.Feature)

Aggregations

DAOException (org.jbei.ice.storage.DAOException)150 HibernateException (org.hibernate.HibernateException)144 ArrayList (java.util.ArrayList)26 Group (org.jbei.ice.storage.model.Group)14 Account (org.jbei.ice.storage.model.Account)8 Request (org.jbei.ice.storage.model.Request)8 Predicate (javax.persistence.criteria.Predicate)7 SampleRequest (org.jbei.ice.lib.dto.sample.SampleRequest)6 Entry (org.jbei.ice.storage.model.Entry)6 Session (org.hibernate.Session)5 ApiKey (org.jbei.ice.storage.model.ApiKey)5 BulkUpload (org.jbei.ice.storage.model.BulkUpload)5 NativeQuery (org.hibernate.query.NativeQuery)4 Feature (org.jbei.ice.storage.model.Feature)4 Preference (org.jbei.ice.storage.model.Preference)4 Sample (org.jbei.ice.storage.model.Sample)4 Attachment (org.jbei.ice.storage.model.Attachment)3 Audit (org.jbei.ice.storage.model.Audit)3 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)3 ShotgunSequence (org.jbei.ice.storage.model.ShotgunSequence)3