Search in sources :

Example 6 with UserGroup

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

the class Group method toDataTransferObject.

public UserGroup toDataTransferObject() {
    UserGroup user = new UserGroup();
    user.setUuid(getUuid());
    user.setId(getId());
    user.setLabel(getLabel());
    user.setDescription(getDescription());
    if (autoJoin != null)
        user.setAutoJoin(autoJoin);
    if (creationTime != null)
        user.setCreationTime(creationTime.getTime());
    Group parent = getParent();
    if (parent != null) {
        user.setParentId(parent.getId());
    }
    user.setType(getType());
    if (getOwner() != null)
        user.setOwnerEmail(getOwner().getEmail());
    return user;
}
Also used : UserGroup(org.jbei.ice.lib.dto.group.UserGroup) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 7 with UserGroup

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

the class GroupsTest method testUpdate.

//    @Test
//    public void testGetGroupMembers() throws Exception {
//
//    }
//
@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)

Example 8 with UserGroup

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

the class GroupsTest method testAddGroup.

//    @Test
//    public void testGet() throws Exception {
//
//    }
//
//    @Test
//    public void testGet1() throws Exception {
//
//    }
//
//    @Test
//    public void testGetMatchingGroups() throws Exception {
//
//    }
@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 9 with UserGroup

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

the class GroupControllerTest method testGetMatchingGroups.

@Test
public void testGetMatchingGroups() throws Exception {
    Account account = AccountCreator.createTestAccount("testGetMatchingGroups", false);
    UserGroup g1 = new UserGroup();
    g1.setDescription("desc");
    g1.setLabel("label");
    g1 = controller.createGroup(account.getEmail(), g1);
    Assert.assertNotNull(g1);
    Group group1 = DAOFactory.getGroupDAO().get(g1.getId());
    account.getGroups().add(group1);
    Assert.assertNotNull(group1);
    UserGroup g2 = new UserGroup();
    g2.setDescription("desc");
    g2.setLabel("myg2");
    g2 = controller.createGroup(account.getEmail(), g2);
    Assert.assertNotNull(g2);
    Group group2 = DAOFactory.getGroupDAO().get(g2.getId());
    Assert.assertNotNull(group2);
    account.getGroups().add(group2);
    // save to add groups to account
    DAOFactory.getAccountDAO().create(account);
    Account account2 = AccountCreator.createTestAccount("testGetMatchingGroups2", false);
    UserGroup g3 = new UserGroup();
    g3.setDescription("desc");
    g3.setLabel("myg3");
    Assert.assertNotNull(controller.createGroup(account2.getEmail(), g3));
    List<Group> groups = controller.getMatchingGroups(account.getEmail(), "myg", 10);
    Assert.assertNotNull(groups);
    Assert.assertEquals(1, groups.size());
}
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 10 with UserGroup

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

the class GroupControllerTest method testGetGroupById.

@Test
public void testGetGroupById() throws Exception {
    Account account = AccountCreator.createTestAccount("testGetGroupById", false);
    UserGroup userGroup1 = new UserGroup();
    userGroup1.setDescription("test1");
    userGroup1.setType(GroupType.PRIVATE);
    userGroup1.setLabel("label1");
    long id = controller.createGroup(account.getEmail(), userGroup1).getId();
    Assert.assertNotNull(controller.getGroupById(account.getEmail(), id));
}
Also used : Account(org.jbei.ice.storage.model.Account) 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