Search in sources :

Example 6 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer 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 7 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer 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 8 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class FolderController method createPersonalFolder.

public FolderDetails createPersonalFolder(String userId, FolderDetails folderDetails) {
    if (folderDetails.getName() == null)
        return null;
    Folder folder = new Folder(folderDetails.getName());
    AccountTransfer owner = folderDetails.getOwner();
    if (owner != null && !StringUtils.isEmpty(owner.getEmail()) && accountController.isAdministrator(userId))
        folder.setOwnerEmail(owner.getEmail());
    else
        folder.setOwnerEmail(userId);
    folder.setType(FolderType.PRIVATE);
    folder.setCreationTime(new Date());
    folder = dao.create(folder);
    FolderDetails details = folder.toDataTransferObject();
    details.setCanEdit(true);
    return details;
}
Also used : FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 9 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class GroupsTest method testAddGroup.

@Test
public void testAddGroup() throws Exception {
    Account account = AccountCreator.createTestAccount("GroupsTest.testAddGroup", false);
    String email = account.getEmail();
    UserGroup group = new UserGroup();
    group.setLabel("label");
    group.setDescription("description");
    Account account1 = AccountCreator.createTestAccount("GroupsTest.testAddGroup2", false);
    group.getMembers().add(account1.toDataTransferObject());
    // add remote account
    RemoteUser remoteUser = new RemoteUser();
    AccountTransfer accountTransfer = new AccountTransfer();
    accountTransfer.setEmail("Remote.GroupsTest.testAddGroup3");
    remoteUser.setUser(accountTransfer);
    // create remote partner
    RemotePartner partner = new RemotePartner();
    partner.setUrl("registry-test3.jbei.org");
    partner = DAOFactory.getRemotePartnerDAO().create(partner);
    remoteUser.setPartner(partner.toDataTransferObject());
    group.getRemoteMembers().add(remoteUser);
    Groups groups = new Groups(email);
    UserGroup result = groups.addGroup(group);
    Assert.assertNotNull(result);
    result = groups.getGroupMembers(result.getId());
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.getMembers().size());
    Assert.assertEquals(1, result.getRemoteMembers().size());
}
Also used : Account(org.jbei.ice.storage.model.Account) RemoteUser(org.jbei.ice.lib.dto.web.RemoteUser) RemotePartner(org.jbei.ice.storage.model.RemotePartner) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Test(org.junit.Test)

Example 10 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class GroupsTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    Account account = AccountCreator.createTestAccount("GroupsTest.testUpdate", false);
    // create local test accounts
    Account account1 = AccountCreator.createTestAccount("GroupsTest.testUpdate1", false);
    Account account2 = AccountCreator.createTestAccount("GroupsTest.testUpdate2", false);
    Account account3 = AccountCreator.createTestAccount("GroupsTest.testUpdate3", false);
    // create remote test accounts
    RemotePartner partner = new RemotePartner();
    partner.setUrl("registry-test2.jbei.org");
    partner = DAOFactory.getRemotePartnerDAO().create(partner);
    RemoteUser remoteUser1 = new RemoteUser();
    remoteUser1.setUser(new AccountTransfer("Remote.GroupsTest.testUpdate1", ""));
    remoteUser1.setPartner(partner.toDataTransferObject());
    RemoteUser remoteUser2 = new RemoteUser();
    remoteUser2.setUser(new AccountTransfer("Remote.GroupsTest.testUpdate2", ""));
    remoteUser2.setPartner(partner.toDataTransferObject());
    RemoteUser remoteUser3 = new RemoteUser();
    remoteUser3.setUser(new AccountTransfer("Remote.GroupsTest.testUpdate3", ""));
    remoteUser3.setPartner(partner.toDataTransferObject());
    // create group with account1, account2 and remote1, remote2 as a members
    UserGroup group = new UserGroup();
    group.setLabel("label");
    group.setDescription("description");
    group.getMembers().add(account1.toDataTransferObject());
    group.getMembers().add(account2.toDataTransferObject());
    group.getRemoteMembers().add(remoteUser1);
    group.getRemoteMembers().add(remoteUser2);
    Groups groups = new Groups(account.getEmail());
    UserGroup result = groups.addGroup(group);
    Assert.assertNotNull(result);
    // get members and test
    result = groups.getGroupMembers(result.getId());
    Assert.assertNotNull(result);
    Assert.assertEquals(2, result.getMembers().size());
    Assert.assertEquals(2, result.getRemoteMembers().size());
    // update group to account2 as the only local and 1 remote account
    result.getMembers().clear();
    result.getRemoteMembers().clear();
    result.getMembers().add(account3.toDataTransferObject());
    result.getRemoteMembers().add(remoteUser3);
    // update
    result.setLabel("updated label");
    result.setDescription("updated description");
    Assert.assertTrue(groups.update(result.getId(), result));
    // get members and test
    group = groups.getGroupMembers(result.getId());
    Assert.assertEquals("updated label", group.getLabel());
    Assert.assertEquals("updated description", group.getDescription());
    Assert.assertEquals(1, group.getMembers().size());
    Assert.assertEquals(account3.getEmail(), group.getMembers().get(0).getEmail());
    Assert.assertEquals(1, group.getRemoteMembers().size());
    Assert.assertEquals(remoteUser3.getUser().getEmail(), group.getRemoteMembers().get(0).getUser().getEmail());
}
Also used : Account(org.jbei.ice.storage.model.Account) RemoteUser(org.jbei.ice.lib.dto.web.RemoteUser) RemotePartner(org.jbei.ice.storage.model.RemotePartner) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Test(org.junit.Test)

Aggregations

AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)31 Account (org.jbei.ice.storage.model.Account)10 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)6 RemotePartner (org.jbei.ice.storage.model.RemotePartner)6 RemoteUser (org.jbei.ice.lib.dto.web.RemoteUser)5 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)4 Group (org.jbei.ice.storage.model.Group)4 PermissionException (org.jbei.ice.lib.access.PermissionException)3 Results (org.jbei.ice.lib.dto.common.Results)3 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)3 Folder (org.jbei.ice.storage.model.Folder)3 Test (org.junit.Test)3 TraceSequenceAnalysis (org.jbei.ice.lib.dto.entry.TraceSequenceAnalysis)2 Message (org.jbei.ice.storage.model.Message)2 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 RemoteAccess (org.jbei.ice.lib.access.RemoteAccess)1 AccountController (org.jbei.ice.lib.account.AccountController)1