use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupController method getAllAccountGroups.
/**
* Retrieve all parent {@link Group}s of a given {@link Account}.
*
* @param account Account to query on.
* @return Set of Group ids.
*/
protected Set<Long> getAllAccountGroups(Account account) {
HashSet<Long> accountGroups = new HashSet<>();
for (Group group : account.getGroups()) {
accountGroups = getParentGroups(group, accountGroups);
}
// Everyone belongs to the everyone group
Group everybodyGroup = createOrRetrievePublicGroup();
accountGroups.add(everybodyGroup.getId());
return accountGroups;
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupController method createGroup.
// create group without parent
public UserGroup createGroup(String userId, UserGroup info) {
if (info.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
String errMsg = "Non admin " + userId + " attempting to create public group";
Logger.error(errMsg);
return null;
}
if (info.getType() == null)
info.setType(GroupType.PRIVATE);
Account account = accountController.getByEmail(userId);
Group group = new Group();
group.setLabel(info.getLabel());
group.setDescription(info.getDescription() == null ? "" : info.getDescription());
group.setType(info.getType());
group.setOwner(account);
group = save(group);
for (AccountTransfer accountTransfer : info.getMembers()) {
Account memberAccount = accountController.getByEmail(accountTransfer.getEmail());
if (memberAccount == null)
continue;
memberAccount.getGroups().add(group);
accountController.save(memberAccount);
}
info = group.toDataTransferObject();
for (Account addedAccount : group.getMembers()) {
info.getMembers().add(addedAccount.toDataTransferObject());
}
info.setMemberCount(info.getMembers().size());
return info;
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class Groups method get.
public Results<UserGroup> get(GroupType groupType, int offset, int limit) {
List<Group> groupList = dao.getGroupsByType(groupType, offset, limit);
Results<UserGroup> results = new Results<>();
results.setResultCount(dao.getGroupsByTypeCount(groupType));
for (Group group : groupList) {
UserGroup userGroup = group.toDataTransferObject();
long memberCount = dao.getMemberCount(group.getUuid());
userGroup.setMemberCount(memberCount);
results.getData().add(userGroup);
}
return results;
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class RemoteClientModelDAO method getClientCount.
/**
* Retrieves number of clients for the specified group
*
* @param group group whose clients are of interest
* @return number of clients for group
* @throws DAOException
*/
public int getClientCount(Group group) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<RemoteClientModel> from = query.from(RemoteClientModel.class);
Join<RemoteClientModel, Group> groups = from.join("groups");
query.select(getBuilder().countDistinct(from.get("id")));
query.where(getBuilder().equal(groups.get("id"), group.getId()), getBuilder().isNotNull(from.get("email")));
return currentSession().createQuery(query).uniqueResult().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 MessageDAO method retrieveMessageCount.
public int retrieveMessageCount(Account account, List<Group> groups) {
try {
Session session = currentSession();
StringBuilder builder = new StringBuilder();
builder.append("select count(id) from message m where m.id in ").append("(select message_id from message_destination_accounts where account_id = ").append(account.getId()).append(")");
if (groups != null && !groups.isEmpty()) {
builder.append(" OR m.id in (select message_id from message_destination_groups where group_id in").append(" (");
int size = groups.size();
int i = 0;
for (Group group : groups) {
builder.append(group.getId());
if (i < size - 1)
builder.append(", ");
i += 1;
}
builder.append("))");
}
NativeQuery query = session.createNativeQuery(builder.toString());
Number number = (Number) query.uniqueResult();
return number.intValue();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException();
}
}
Aggregations