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