Search in sources :

Example 51 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Query(org.hibernate.query.Query) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

Example 52 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) ArrayList(java.util.ArrayList) DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 53 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 54 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 55 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

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