Search in sources :

Example 56 with DAOException

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

the class EntryDAO method getAllEntryCount.

/**
     * @return number of entries that have visibility of "OK"
     */
public long getAllEntryCount(String filter) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Entry> from = query.from(Entry.class);
        query.select(getBuilder().countDistinct(from.get("id")));
        ArrayList<Predicate> predicates = new ArrayList<>();
        checkAddFilter(predicates, from, filter);
        predicates.add(getBuilder().or(getBuilder().equal(from.get("visibility"), Visibility.OK.getValue()), getBuilder().equal(from.get("visibility"), Visibility.PENDING.getValue())));
        query.where(predicates.toArray(new Predicate[predicates.size()]));
        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) ArrayList(java.util.ArrayList)

Example 57 with DAOException

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

the class ExperimentDAO method getByUrl.

public Experiment getByUrl(String url) throws DAOException {
    try {
        CriteriaQuery<Experiment> query = getBuilder().createQuery(Experiment.class);
        Root<Experiment> from = query.from(Experiment.class);
        query.where(getBuilder().equal(from.get("url"), url));
        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) Experiment(org.jbei.ice.storage.model.Experiment)

Example 58 with DAOException

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

the class EntryDAO method getRecordTypes.

public List<String> getRecordTypes(List<Long> list) {
    try {
        CriteriaQuery<String> query = getBuilder().createQuery(String.class);
        Root<Entry> from = query.from(Entry.class);
        query.select(from.get("recordType")).where(from.get("id").in(list));
        return currentSession().createQuery(query).list();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 59 with DAOException

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

the class EntryDAO method getVisibleEntryIds.

public List<Long> getVisibleEntryIds(boolean admin, Group publicGroup) {
    try {
        if (admin) {
            CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
            Root<Entry> from = query.from(Entry.class);
            query.select(getBuilder().countDistinct(from.get("id"))).where(getBuilder().or(getBuilder().equal(from.get("visibility"), Visibility.OK.getValue()), getBuilder().equal(from.get("visibility"), Visibility.PENDING.getValue())));
            return currentSession().createQuery(query).list();
        }
        // non admins, check permissions
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Permission> from = query.from(Permission.class);
        Join<Permission, Entry> permissionEntry = from.join("entry");
        query.select(permissionEntry.get("id")).where(//                    getBuilder().equal(from.get("entry"), permissionEntry)
        getBuilder().equal(from.get("group"), publicGroup), getBuilder().equal(permissionEntry.get("visibility"), Visibility.OK.getValue()));
        return currentSession().createQuery(query).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 60 with DAOException

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

the class EntryDAO method retrieveVisibleEntries.

/**
     * Retrieve {@link Entry Entries} visible to everyone.
     *
     * @return Number of visible entries.
     * @throws DAOException on hibernate exception
     */
public List<Entry> retrieveVisibleEntries(Account account, Set<Group> groups, ColumnField sortField, boolean asc, int start, int count, String filter) {
    try {
        CriteriaQuery<Entry> query = getBuilder().createQuery(Entry.class).distinct(true);
        Root<Entry> from = query.from(Entry.class);
        Join<Entry, Permission> entryPermission = from.join("permissions");
        ArrayList<Predicate> predicates = new ArrayList<>();
        predicates.add(getBuilder().equal(from.get("visibility"), Visibility.OK.getValue()));
        String fieldName = columnFieldToString(sortField);
        if (account != null) {
            predicates.add(getBuilder().or(getBuilder().equal(entryPermission.get("account"), account), entryPermission.get("group").in(groups)));
        } else if (!groups.isEmpty()) {
            predicates.add(entryPermission.get("group").in(groups));
        }
        // check filter
        if (filter != null && !filter.trim().isEmpty()) {
            filter = filter.toLowerCase();
            predicates.add(getBuilder().or(getBuilder().like(getBuilder().lower(from.get("name")), "%" + filter + "%"), getBuilder().like(getBuilder().lower(from.get("alias")), "%" + filter + "%"), getBuilder().like(getBuilder().lower(from.get("partNumber")), "%" + filter + "%")));
        }
        query.where(predicates.toArray(new Predicate[predicates.size()]));
        query.orderBy(asc ? getBuilder().asc(from.get(fieldName)) : getBuilder().desc(from.get(fieldName)));
        return currentSession().createQuery(query).setMaxResults(count).setFirstResult(start).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) ArrayList(java.util.ArrayList)

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