Search in sources :

Example 31 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class GroupDAO method getMemberCount.

public long getMemberCount(String uuid) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Group> from = query.from(Group.class);
        Join<Group, Account> member = from.join("members");
        query.select(getBuilder().countDistinct(member.get("id")));
        query.where(getBuilder().equal(from.get("uuid"), uuid));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Group(org.jbei.ice.storage.model.Group) Account(org.jbei.ice.storage.model.Account) HibernateException(org.hibernate.HibernateException)

Example 32 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class GroupDAO method retrieveMemberGroups.

public List<Group> retrieveMemberGroups(Account account) {
    try {
        CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
        Root<Group> from = query.from(Group.class);
        Join<Group, Account> members = from.join("members", JoinType.LEFT);
        query.where(getBuilder().or(getBuilder().equal(from.get("owner"), account), getBuilder().equal(members.get("email"), account.getEmail())));
        return currentSession().createQuery(query).list();
    } 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) Account(org.jbei.ice.storage.model.Account) HibernateException(org.hibernate.HibernateException)

Example 33 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class AccountCreator method createTestAccount.

public static Account createTestAccount(String testName, boolean admin) throws Exception {
    String email = testName + "@TESTER";
    AccountDAO dao = DAOFactory.getAccountDAO();
    Account account = dao.getByEmail(email);
    if (account != null)
        throw new Exception("duplicate account");
    AccountTransfer accountTransfer = new AccountTransfer();
    accountTransfer.setFirstName("TEST_FNAME");
    accountTransfer.setLastName("TEST");
    accountTransfer.setEmail(email);
    accountTransfer = new AccountController().createNewAccount(accountTransfer, false);
    Assert.assertNotNull(accountTransfer.getPassword());
    account = dao.getByEmail(email);
    Assert.assertNotNull(account);
    if (admin) {
        account.setType(AccountType.ADMIN);
        dao.update(account);
    }
    return account;
}
Also used : Account(org.jbei.ice.storage.model.Account) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) AccountController(org.jbei.ice.lib.account.AccountController)

Example 34 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class BulkUploadControllerTest method testGetBulkImport.

@Test
public void testGetBulkImport() throws Exception {
    Account account = AccountCreator.createTestAccount("testGetBulkImport", false);
    BulkEntryCreator creator = new BulkEntryCreator();
    // create bulk upload
    long id = creator.createBulkUpload(account.getEmail(), EntryType.PART);
    Assert.assertTrue(id > 0);
    int count = 100;
    for (int i = 0; i < count; i += 1) {
        PartData partData = new PartData(EntryType.PLASMID);
        partData.setBioSafetyLevel(1);
        partData.setShortDescription("part description");
        partData.setName("part" + i);
        partData = creator.createEntry(account.getEmail(), id, partData);
        Assert.assertNotNull(partData);
    // add to bulk upload
    }
    BulkUploadInfo info = controller.getBulkImport(account.getEmail(), id, 0, 100);
    Assert.assertNotNull(info);
    Assert.assertEquals(info.getEntryList().size(), 100);
    // test retrieval in order
    for (int i = 0; i < 100; i += 10) {
        info = controller.getBulkImport(account.getEmail(), id, i, 10);
        Assert.assertNotNull(info);
        Assert.assertEquals(info.getEntryList().size(), 10);
        ArrayList<PartData> list = info.getEntryList();
        int j = i;
        for (PartData data : list) {
            Assert.assertEquals(data.getName(), "part" + j);
            j += 1;
        }
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) PartData(org.jbei.ice.lib.dto.entry.PartData) Test(org.junit.Test)

Example 35 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class BulkUploadControllerTest method testDeleteDraftById.

@Test
public void testDeleteDraftById() throws Exception {
    Account account = AccountCreator.createTestAccount("testDeleteDraftById", false);
    BulkUploadAutoUpdate autoUpdate = new BulkUploadAutoUpdate(EntryType.PLASMID);
    autoUpdate.getKeyValue().put(EntryField.SUMMARY, "plasmid summary");
    autoUpdate.getKeyValue().put(EntryField.NAME, "plasmid name");
    autoUpdate.getKeyValue().put(EntryField.PI, "plasmid principal investigator");
    autoUpdate.getKeyValue().put(EntryField.SELECTION_MARKERS, "plasmid select markers");
    autoUpdate = controller.autoUpdateBulkUpload(account.getEmail(), autoUpdate, EntryType.PLASMID);
    Assert.assertNotNull(autoUpdate);
    // delete bulk upload
    BulkUploadDeleteTask task = new BulkUploadDeleteTask(account.getEmail(), autoUpdate.getBulkUploadId());
    task.execute();
    Assert.assertNull(controller.getBulkImport(account.getEmail(), autoUpdate.getBulkUploadId(), 0, 0));
}
Also used : Account(org.jbei.ice.storage.model.Account) Test(org.junit.Test)

Aggregations

Account (org.jbei.ice.storage.model.Account)153 Test (org.junit.Test)71 Group (org.jbei.ice.storage.model.Group)24 Entry (org.jbei.ice.storage.model.Entry)21 Strain (org.jbei.ice.storage.model.Strain)20 PartData (org.jbei.ice.lib.dto.entry.PartData)18 Folder (org.jbei.ice.storage.model.Folder)18 ArrayList (java.util.ArrayList)16 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 PermissionException (org.jbei.ice.lib.access.PermissionException)11 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)10 Plasmid (org.jbei.ice.storage.model.Plasmid)10 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)8 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)8 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)8 DAOException (org.jbei.ice.storage.DAOException)8 RemotePartner (org.jbei.ice.storage.model.RemotePartner)8 HibernateException (org.hibernate.HibernateException)7 HashSet (java.util.HashSet)6 Part (org.jbei.ice.storage.model.Part)6