Search in sources :

Example 51 with Group

use of org.jbei.ice.storage.model.Group in project ice by JBEI.

the class GroupDAO method getByUUID.

/**
 * Retrieve {@link Group} object from the database by its uuid.
 *
 * @param uuid universally unique identifier for group
 * @return Group object.
 * @throws DAOException
 */
public Group getByUUID(String uuid) {
    try {
        CriteriaQuery<Group> query = getBuilder().createQuery(Group.class);
        Root<Group> from = query.from(Group.class);
        query.where(getBuilder().equal(from.get("uuid"), uuid));
        return currentSession().createQuery(query).uniqueResult();
    } catch (Exception e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Group(org.jbei.ice.storage.model.Group) DAOException(org.jbei.ice.storage.DAOException)

Example 52 with Group

use of org.jbei.ice.storage.model.Group in project ice by JBEI.

the class GroupDAO method getGroupsByTypeCount.

public long getGroupsByTypeCount(GroupType type) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class).distinct(true);
        Root<Group> from = query.from(Group.class);
        query.select(getBuilder().countDistinct(from.get("id")));
        query.where(getBuilder().equal(from.get("type"), type));
        return currentSession().createQuery(query).uniqueResult();
    } catch (Exception he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Group(org.jbei.ice.storage.model.Group) DAOException(org.jbei.ice.storage.DAOException)

Example 53 with Group

use of org.jbei.ice.storage.model.Group in project ice by JBEI.

the class MessageDAO method retrieveNewMessageCount.

public int retrieveNewMessageCount(Account account) {
    try {
        StringBuilder builder = new StringBuilder();
        builder.append("select count(id) from message m where m.is_read=false AND (m.id in ").append("(select message_id from message_destination_accounts where account_id = ").append(account.getId()).append(")");
        if (!account.getGroups().isEmpty()) {
            builder.append(" OR m.id in (select message_id from message_destination_groups where group_id in (");
            int i = 0;
            for (Group group : account.getGroups()) {
                if (i > 0)
                    builder.append(", ");
                builder.append(group.getId());
                i += 1;
            }
            builder.append("))");
        }
        builder.append(")");
        NativeQuery query = currentSession().createNativeQuery(builder.toString());
        Number number = (Number) query.uniqueResult();
        return number.intValue();
    } 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) NativeQuery(org.hibernate.query.NativeQuery) HibernateException(org.hibernate.HibernateException)

Example 54 with Group

use of org.jbei.ice.storage.model.Group in project ice by JBEI.

the class GroupControllerTest method testSave.

@Test
public void testSave() throws Exception {
    Account account = AccountCreator.createTestAccount("testSave", false);
    Group group = new Group();
    group.setOwner(account);
    group.setLabel("group label");
    group.setDescription("group description");
    Assert.assertNotNull(controller.save(group));
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 55 with Group

use of org.jbei.ice.storage.model.Group in project ice by JBEI.

the class GroupDAOTest method testGet.

@Test
public void testGet() throws Exception {
    Group group = createGroup(UUID.randomUUID().toString(), null);
    Group result = dao.get(group.getId());
    Assert.assertNotNull(result);
    Assert.assertEquals(result.getId(), group.getId());
    Assert.assertEquals(result.getUuid(), group.getUuid());
}
Also used : Group(org.jbei.ice.storage.model.Group) HibernateRepositoryTest(org.jbei.ice.storage.hibernate.HibernateRepositoryTest) Test(org.junit.Test)

Aggregations

Group (org.jbei.ice.storage.model.Group)62 Account (org.jbei.ice.storage.model.Account)26 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 DAOException (org.jbei.ice.storage.DAOException)15 GroupController (org.jbei.ice.lib.group.GroupController)12 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)9 PartData (org.jbei.ice.lib.dto.entry.PartData)9 PermissionException (org.jbei.ice.lib.access.PermissionException)7 HibernateRepositoryTest (org.jbei.ice.storage.hibernate.HibernateRepositoryTest)7 Entry (org.jbei.ice.storage.model.Entry)7 Test (org.junit.Test)7 HibernateException (org.hibernate.HibernateException)5 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)4 Folder (org.jbei.ice.storage.model.Folder)4 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)4 NativeQuery (org.hibernate.query.NativeQuery)3 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)3 Results (org.jbei.ice.lib.dto.common.Results)3