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