Search in sources :

Example 16 with Group

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

Example 17 with Group

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

Example 18 with Group

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

Example 19 with Group

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

Example 20 with Group

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

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