use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupDAO method getMatchingGroups.
public List<Group> getMatchingGroups(Account account, String token, int limit) {
Set<Group> userGroups = account.getGroups();
try {
token = token.toUpperCase();
CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
Root<Group> from = query.from(Group.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(getBuilder().like(getBuilder().upper(from.get("label")), "%" + token + "%"));
predicates.add(getBuilder().notEqual(from.get("uuid"), GroupController.PUBLIC_GROUP_UUID));
Predicate predicate = getBuilder().or(getBuilder().equal(from.get("type"), GroupType.PUBLIC), getBuilder().equal(from.get("owner"), account));
if (userGroups != null && !userGroups.isEmpty()) {
predicate.getExpressions().add(from.in(userGroups));
}
predicates.add(predicate);
query.where(predicates.toArray(new Predicate[predicates.size()]));
return currentSession().createQuery(query).setMaxResults(limit).list();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Error retrieving matching groups", e);
}
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupDAO method getGroupsBy.
/**
* Retrieves groups by type and <code>autoJoin</code> value
*
* @param type type of groups to retrieve
* @param isAutoJoin auto join status
* @return list of groups found that match the parameters
* @throws DAOException on HibernateException retrieving groups
*/
public List<Group> getGroupsBy(GroupType type, boolean isAutoJoin) {
try {
CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
Root<Group> from = query.from(Group.class);
query.where(getBuilder().equal(from.get("type"), type), getBuilder().equal((from.get("autoJoin")), isAutoJoin));
return currentSession().createQuery(query).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupDAO method getGroupsByType.
public List<Group> getGroupsByType(GroupType type, int offset, int limit) {
try {
CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
Root<Group> from = query.from(Group.class);
query.where(getBuilder().equal(from.get("type"), type));
return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(limit).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupControllerTest method testCreateOrRetrievePublicGroup.
@Test
public void testCreateOrRetrievePublicGroup() throws Exception {
Group group = controller.createOrRetrievePublicGroup();
Assert.assertNotNull(group);
Assert.assertTrue(group.getType() == GroupType.SYSTEM);
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupControllerTest method testGetMatchingGroups.
@Test
public void testGetMatchingGroups() throws Exception {
Account account = AccountCreator.createTestAccount("testGetMatchingGroups", false);
UserGroup g1 = new UserGroup();
g1.setDescription("desc");
g1.setLabel("label");
g1 = controller.createGroup(account.getEmail(), g1);
Assert.assertNotNull(g1);
Group group1 = DAOFactory.getGroupDAO().get(g1.getId());
account.getGroups().add(group1);
Assert.assertNotNull(group1);
UserGroup g2 = new UserGroup();
g2.setDescription("desc");
g2.setLabel("myg2");
g2 = controller.createGroup(account.getEmail(), g2);
Assert.assertNotNull(g2);
Group group2 = DAOFactory.getGroupDAO().get(g2.getId());
Assert.assertNotNull(group2);
account.getGroups().add(group2);
// save to add groups to account
DAOFactory.getAccountDAO().create(account);
Account account2 = AccountCreator.createTestAccount("testGetMatchingGroups2", false);
UserGroup g3 = new UserGroup();
g3.setDescription("desc");
g3.setLabel("myg3");
Assert.assertNotNull(controller.createGroup(account2.getEmail(), g3));
List<Group> groups = controller.getMatchingGroups(account.getEmail(), "myg", 10);
Assert.assertNotNull(groups);
Assert.assertEquals(1, groups.size());
}
Aggregations