Search in sources :

Example 1 with UserGroup

use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.

the class Messages method send.

/**
 * Sends message contained in the MessageInfo to the specified recipients. It some of the
 * recipients do not exist, the routine does its best to deliver as many as possible
 *
 * @param info details of message including recipient(s)
 * @return false if the message fails to be sent to all the intended recipients
 */
public boolean send(MessageInfo info) {
    if (info == null || info.getAccounts().isEmpty() && info.getUserGroups().isEmpty())
        return false;
    boolean success = true;
    Message message = new Message();
    message.setDateSent(new Date());
    message.setFromEmail(this.userId);
    message.setMessage(info.getMessage());
    message.setTitle(info.getTitle());
    if (info.getAccounts() != null) {
        for (AccountTransfer accountTransfer : info.getAccounts()) {
            Account account = accountDAO.getByEmail(accountTransfer.getEmail());
            if (account == null) {
                success = false;
                continue;
            }
            message.getDestinationAccounts().add(account);
        }
    }
    if (info.getUserGroups() != null) {
        for (UserGroup userGroup : info.getUserGroups()) {
            Group group = DAOFactory.getGroupDAO().get(userGroup.getId());
            if (group == null) {
                Logger.warn("Could not retrieve group with id " + userGroup.getId() + " to send message");
                success = false;
                continue;
            }
            message.getDestinationGroups().add(group);
        }
    }
    if (!success)
        return false;
    if (message.getDestinationAccounts().isEmpty() && message.getDestinationGroups().isEmpty())
        return false;
    return dao.create(message) != null;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Message(org.jbei.ice.storage.model.Message) Date(java.util.Date) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 2 with UserGroup

use of org.jbei.ice.lib.dto.group.UserGroup 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 3 with UserGroup

use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.

the class Groups method getMatchingGroups.

public List<UserGroup> getMatchingGroups(String token, int limit) {
    Account account = accountDAO.getByEmail(this.userId);
    List<Group> groups = dao.getMatchingGroups(account, token, limit);
    List<UserGroup> results = new ArrayList<>(groups.size());
    for (Group group : groups) {
        results.add(group.toDataTransferObject());
    }
    return results;
}
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)

Example 4 with UserGroup

use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.

the class Groups method addGroup.

/**
 * Adds group to the list of groups for current user
 *
 * @param userGroup information about group to be added, including members (local and remote)
 * @return added group
 */
public UserGroup addGroup(UserGroup userGroup) {
    if (userGroup.getType() == null)
        userGroup.setType(GroupType.PRIVATE);
    if (userGroup.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
        String errMsg = "Non admin '" + userId + "' attempting to create public group";
        Logger.error(errMsg);
        throw new PermissionException(errMsg);
    }
    Account account = accountDAO.getByEmail(userId);
    Group group = new Group();
    group.setUuid(Utils.generateUUID());
    group.setLabel(userGroup.getLabel());
    group.setDescription(userGroup.getDescription() == null ? "" : userGroup.getDescription());
    group.setType(userGroup.getType());
    group.setOwner(account);
    group.setAutoJoin(userGroup.isAutoJoin());
    group.setCreationTime(new Date());
    group = dao.create(group);
    // add local members
    if (userGroup.getMembers() != null && !userGroup.getMembers().isEmpty()) {
        for (AccountTransfer accountTransfer : userGroup.getMembers()) {
            Account memberAccount = accountDAO.getByEmail(accountTransfer.getEmail());
            if (memberAccount == null)
                continue;
            group.getMembers().add(memberAccount);
            memberAccount.getGroups().add(group);
            accountDAO.update(memberAccount);
        }
    }
    // add remote members
    for (RemoteUser remoteUser : userGroup.getRemoteMembers()) {
        RegistryPartner partner = remoteUser.getPartner();
        if (partner == null)
            continue;
        RemotePartner remotePartner = remotePartnerDAO.get(partner.getId());
        if (remotePartner == null)
            continue;
        AccountTransfer accountTransfer = remoteUser.getUser();
        if (accountTransfer == null || StringUtils.isEmpty(accountTransfer.getEmail()))
            continue;
        String email = accountTransfer.getEmail();
        RemoteClientModel remoteClientModel = remoteClientModelDAO.getModel(email, remotePartner);
        if (remoteClientModel == null) {
            remoteClientModel = new RemoteClientModel();
            remoteClientModel.setEmail(email);
            remoteClientModel.setRemotePartner(remotePartner);
            remoteClientModel = remoteClientModelDAO.create(remoteClientModel);
        }
        remoteClientModel.getGroups().add(group);
        remoteClientModelDAO.update(remoteClientModel);
    }
    return group.toDataTransferObject();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) RemoteUser(org.jbei.ice.lib.dto.web.RemoteUser) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) RemotePartner(org.jbei.ice.storage.model.RemotePartner) RemoteClientModel(org.jbei.ice.storage.model.RemoteClientModel) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 5 with UserGroup

use of org.jbei.ice.lib.dto.group.UserGroup 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)

Aggregations

UserGroup (org.jbei.ice.lib.dto.group.UserGroup)17 Account (org.jbei.ice.storage.model.Account)13 Group (org.jbei.ice.storage.model.Group)9 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)5 PermissionException (org.jbei.ice.lib.access.PermissionException)3 RemoteUser (org.jbei.ice.lib.dto.web.RemoteUser)3 RemotePartner (org.jbei.ice.storage.model.RemotePartner)3 Results (org.jbei.ice.lib.dto.common.Results)2 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)2 Test (org.junit.Test)2 Date (java.util.Date)1 AccountController (org.jbei.ice.lib.account.AccountController)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1 Message (org.jbei.ice.storage.model.Message)1