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