Search in sources :

Example 46 with DAOException

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

the class PermissionDAO method removePermission.

public int removePermission(Entry entry, Folder folder, BulkUpload upload, Account account, Group group, boolean canRead, boolean canWrite) {
    try {
        CriteriaDelete<Permission> delete = getBuilder().createCriteriaDelete(Permission.class);
        Root<Permission> from = delete.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(getPredicate(from, "group", group));
        predicates.add(getPredicate(from, "folder", folder));
        predicates.add(getPredicate(from, "account", account));
        predicates.add(getPredicate(from, "entry", entry));
        predicates.add(getPredicate(from, "upload", upload));
        delete.where(predicates.toArray(new Predicate[predicates.size()]));
        return currentSession().createQuery(delete).executeUpdate();
    } 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 47 with DAOException

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

the class PermissionDAO method retrievePermission.

public Permission retrievePermission(Entry entry, Folder folder, BulkUpload upload, Account account, Group group, boolean canRead, boolean canWrite) {
    try {
        Query<Permission> query = createPermissionQuery(entry, folder, upload, account, group, canRead, canWrite);
        List<Permission> result = query.list();
        if (result == null || result.isEmpty())
            return null;
        if (result.size() > 1)
            Logger.error("permission query did not return unique result. returning first result");
        return result.get(0);
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 48 with DAOException

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

the class PermissionDAO method getEntryPermissions.

public List<Permission> getEntryPermissions(Entry entry) {
    try {
        CriteriaQuery<Permission> query = getBuilder().createQuery(Permission.class);
        Root<Permission> from = query.from(Permission.class);
        query.where(getBuilder().equal(from.get("entry"), entry));
        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 49 with DAOException

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

the class PreferencesDAO method getAccountPreferences.

public List<Preference> getAccountPreferences(Account account, List<PreferenceKey> keys) {
    ArrayList<String> keyString = new ArrayList<>();
    for (PreferenceKey key : keys) keyString.add(key.name());
    try {
        CriteriaQuery<Preference> query = getBuilder().createQuery(Preference.class);
        Root<Preference> from = query.from(Preference.class);
        query.where(getBuilder().equal(from.get("account"), account), from.get("key").in(keyString));
        return currentSession().createQuery(query).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Preference(org.jbei.ice.storage.model.Preference) HibernateException(org.hibernate.HibernateException) PreferenceKey(org.jbei.ice.lib.dto.user.PreferenceKey)

Example 50 with DAOException

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

the class PreferencesDAO method createOrUpdatePreference.

public Preference createOrUpdatePreference(Account account, String key, String value) {
    try {
        CriteriaQuery<Preference> query = getBuilder().createQuery(Preference.class);
        Root<Preference> from = query.from(Preference.class);
        query.where(getBuilder().equal(from.get("account"), account), getBuilder().equal(from.get("key"), key.toUpperCase()));
        Optional<Preference> optional = currentSession().createQuery(query).uniqueResultOptional();
        if (optional.isPresent()) {
            Preference preference = optional.get();
            if (preference.getValue().equalsIgnoreCase(value))
                return preference;
            currentSession().update(preference);
            return preference;
        } else {
            return this.create(new Preference(account, key, value));
        }
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Preference(org.jbei.ice.storage.model.Preference) 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