use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class PermissionDAO method clearPermissions.
public int clearPermissions(Folder folder) {
Session session = currentSession();
Query query = session.createQuery("delete " + Permission.class.getName() + " where folder = :folder");
query.setParameter("folder", folder);
try {
return query.executeUpdate();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class PermissionDAO method hasPermissionMulti.
// to avoid ambiguous call name clashes when collections are null
public boolean hasPermissionMulti(Entry entry, Set<Folder> folders, Account account, List<Group> groups, boolean canRead, boolean canWrite) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<Permission> from = query.from(Permission.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(getBuilder().equal(from.get("canWrite"), canWrite));
predicates.add(getBuilder().equal(from.get("canRead"), canRead));
predicates.add(getPredicateForCollection(from, "group", groups));
predicates.add(getPredicateForCollection(from, "folder", folders));
predicates.add(getPredicate(from, "account", account));
predicates.add(getPredicate(from, "entry", entry));
query.select(getBuilder().countDistinct(from.get("id")));
query.where(predicates.toArray(new Predicate[predicates.size()]));
return currentSession().createQuery(query).setMaxResults(1).uniqueResult() == 1;
} catch (Exception e) {
Logger.error(e);
throw new DAOException(e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class PermissionDAO method getFolderPermissions.
public List<Permission> getFolderPermissions(Folder folder) {
try {
CriteriaQuery<Permission> query = getBuilder().createQuery(Permission.class);
Root<Permission> from = query.from(Permission.class);
query.where(getBuilder().equal(from.get("folder"), folder));
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 PermissionDAO method getFolders.
public List<Folder> getFolders(Group group) {
try {
CriteriaQuery<Folder> query = getBuilder().createQuery(Folder.class);
Root<Permission> from = query.from(Permission.class);
query.select(from.get("folder"));
query.where(getBuilder().or(getBuilder().equal(from.get("canWrite"), true), getBuilder().equal(from.get("canRead"), true)), getBuilder().isNull(from.get("entry")), getBuilder().equal(from.get("group"), group));
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 PermissionDAO method retrieveGroupPermissions.
public List<Group> retrieveGroupPermissions(Folder folder, boolean canWrite, boolean canRead) {
try {
CriteriaQuery<Group> query = getBuilder().createQuery(Group.class);
Root<Permission> from = query.from(Permission.class);
query.select(from.get("group"));
query.where(getBuilder().isNull(from.get("group")), getBuilder().equal(from.get("folder"), folder), getBuilder().equal(from.get("canRead"), canRead), getBuilder().equal(from.get("canWrite"), canWrite));
return currentSession().createQuery(query).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
Aggregations