Search in sources :

Example 26 with Group

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

Example 27 with Group

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

Example 28 with Group

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

Example 29 with Group

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);
}
Also used : Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 30 with Group

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());
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Aggregations

Group (org.jbei.ice.storage.model.Group)50 Account (org.jbei.ice.storage.model.Account)24 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 HibernateException (org.hibernate.HibernateException)14 DAOException (org.jbei.ice.storage.DAOException)14 GroupController (org.jbei.ice.lib.group.GroupController)10 ArrayList (java.util.ArrayList)7 Entry (org.jbei.ice.storage.model.Entry)7 HashSet (java.util.HashSet)6 PermissionException (org.jbei.ice.lib.access.PermissionException)6 PartData (org.jbei.ice.lib.dto.entry.PartData)4 Folder (org.jbei.ice.storage.model.Folder)4 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)4 NativeQuery (org.hibernate.query.NativeQuery)3 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)3 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)3 Results (org.jbei.ice.lib.dto.common.Results)3 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)3 Message (org.jbei.ice.storage.model.Message)3 AccountController (org.jbei.ice.lib.account.AccountController)2