Search in sources :

Example 16 with DAOException

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

the class EntryDAO method generateNextStrainNameForEntry.

// todo : look at this again (can restrict to strain type and also order by id)
public synchronized void generateNextStrainNameForEntry(Entry entry, String prefix) {
    try {
        CriteriaQuery<Entry> query = getBuilder().createQuery(Entry.class);
        Root<Entry> from = query.from(Entry.class);
        query.where(getBuilder().like(getBuilder().lower(from.get("name")), prefix.toLowerCase() + "1%")).orderBy(getBuilder().desc(from.get("name")));
        Entry result = currentSession().createQuery(query).setMaxResults(1).uniqueResult();
        int next = 0;
        if (result != null) {
            String name = result.getName();
            next = Integer.decode(name.split(prefix)[1]);
        }
        next += 1;
        String nextName = prefix + next;
        entry.setName(nextName);
        currentSession().update(entry);
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 17 with DAOException

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

the class EntryDAO method getMatchingPlasmidField.

public List<String> getMatchingPlasmidField(AutoCompleteField field, String token, int limit) {
    String fieldString;
    switch(field) {
        case ORIGIN_OF_REPLICATION:
        default:
            fieldString = "originOfReplication";
            break;
        case PROMOTERS:
            fieldString = "promoters";
            break;
        case REPLICATES_IN:
            fieldString = "replicatesIn";
            break;
    }
    try {
        CriteriaQuery<String> query = getBuilder().createQuery(String.class);
        Root<Plasmid> from = query.from(Plasmid.class);
        query.select(from.get(fieldString)).where(getBuilder().like(getBuilder().lower(from.get(fieldString)), token.toLowerCase() + "%"));
        return currentSession().createQuery(query).setMaxResults(limit).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 18 with DAOException

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

the class EntryDAO method retrieveUserEntries.

/**
     * Retrieves the entries for the specified owner, that the requester has read access to
     *
     * @param requester       account for user making request
     * @param owner           user id of entries' owner
     * @param requesterGroups groups that the requester is a member of. Used to check access permissions
     * @param sortField       field for sort
     * @param asc             sort order
     * @param start           index to start retrieving records from
     * @param limit           maximum number of entries to retrieve
     * @return list of entries matching specified criteria
     * @throws DAOException on HibernateException
     */
public List<Entry> retrieveUserEntries(Account requester, String owner, Set<Group> requesterGroups, ColumnField sortField, boolean asc, int start, int limit, String filter) {
    try {
        CriteriaQuery<Entry> query = getBuilder().createQuery(Entry.class);
        Root<Permission> from = query.from(Permission.class);
        Join<Permission, Entry> join = from.join("entry");
        query.select(join).distinct(true);
        ArrayList<Predicate> predicates = new ArrayList<>();
        predicates.add(getBuilder().or(from.get("group").in(requesterGroups), getBuilder().equal(from.get("account"), requester)));
        predicates.add(getBuilder().equal(join.get("visibility"), Visibility.OK.getValue()));
        predicates.add(getBuilder().equal(join.get("ownerEmail"), owner));
        if (filter != null && !filter.trim().isEmpty()) {
            filter = filter.toLowerCase();
            predicates.add(getBuilder().or(getBuilder().like(getBuilder().lower(join.get("name")), "%" + filter + "%"), getBuilder().like(getBuilder().lower(join.get("alias")), "%" + filter + "%"), getBuilder().like(getBuilder().lower(join.get("partNumber")), "%" + filter + "%")));
        }
        query.where(predicates.toArray(new Predicate[predicates.size()]));
        String fieldName = sortField == ColumnField.CREATED ? "id" : columnFieldToString(sortField);
        query.orderBy(asc ? getBuilder().asc(join.get(fieldName)) : getBuilder().desc(join.get(fieldName)));
        return currentSession().createQuery(query).setMaxResults(limit).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)

Example 19 with DAOException

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

the class BulkUploadDAO method setEntryStatus.

public int setEntryStatus(BulkUpload upload, Visibility status) {
    try {
        List<Long> entryIds = getEntryIds(upload);
        if (entryIds.isEmpty())
            return 0;
        // include linked entries
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Entry> from = query.from(Entry.class);
        Join<Entry, Entry> linked = from.join("linkedEntries");
        query.select(linked.get("id")).where(from.get("id").in(entryIds));
        List<Long> linkedIds = currentSession().createQuery(query).list();
        entryIds.addAll(linkedIds);
        CriteriaUpdate<Entry> update = getBuilder().createCriteriaUpdate(Entry.class);
        Root<Entry> root = update.from(Entry.class);
        update.set(root.get("visibility"), status.getValue());
        update.where(root.get("id").in(entryIds));
        return currentSession().createQuery(update).executeUpdate();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Entry(org.jbei.ice.storage.model.Entry) HibernateException(org.hibernate.HibernateException)

Example 20 with DAOException

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

the class EntryDAO method retrieveOwnerEntries.

/**
     * Retrieves entries owned by account with specified email and with visibility of "pending" or "ok"
     *
     * @param ownerEmail email for account whose entries are to be retrieved
     * @param sort       field to sort results on
     * @param asc        sort order
     * @param start      start of retrieve
     * @param limit      maximum number of records to retrieve from
     * @param filter     filter for entries
     * @return list of matching entries
     * @throws DAOException on Hibernate Exception
     */
public List<Entry> retrieveOwnerEntries(String ownerEmail, ColumnField sort, boolean asc, int start, int limit, String filter) {
    try {
        CriteriaQuery<Entry> query = getBuilder().createQuery(Entry.class);
        Root<Entry> from = query.from(Entry.class);
        ArrayList<Predicate> predicates = new ArrayList<>();
        predicates.add(getBuilder().equal(from.get("ownerEmail"), ownerEmail));
        predicates.add(getBuilder().or(getBuilder().equal(from.get("visibility"), Visibility.OK.getValue()), getBuilder().equal(from.get("visibility"), Visibility.PENDING.getValue())));
        checkAddFilter(predicates, from, filter);
        query.where(predicates.toArray(new Predicate[predicates.size()]));
        String fieldName = columnFieldToString(sort);
        query.orderBy(asc ? getBuilder().asc(from.get(fieldName)) : getBuilder().desc(from.get(fieldName)));
        return currentSession().createQuery(query).setMaxResults(limit).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