Search in sources :

Example 1 with History

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

the class EntryHistory method get.

public Results<History> get(int limit, int offset, boolean asc, String sort) {
    entryAuthorization.expectWrite(userId, entry);
    List<Audit> list = dao.getAuditsForEntry(entry, limit, offset, asc, sort);
    Results<History> results = new Results<>();
    AccountDAO accountDAO = DAOFactory.getAccountDAO();
    for (Audit audit : list) {
        History history = audit.toDataTransferObject();
        if (history.getPartner() == null) {
            Account account = accountDAO.getByEmail(history.getUserId());
            if (account != null)
                history.setAccount(account.toDataTransferObject());
        }
        results.getData().add(history);
    }
    long count = dao.getHistoryCount(this.entry);
    results.setResultCount(count);
    return results;
}
Also used : Audit(org.jbei.ice.storage.model.Audit) Account(org.jbei.ice.storage.model.Account) Results(org.jbei.ice.lib.dto.common.Results) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO) History(org.jbei.ice.lib.dto.History)

Example 2 with History

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

the class EntryHistoryTest method testDelete.

@Test
public void testDelete() throws Exception {
    Account account = AccountCreator.createTestAccount("EntryHistoryTest.testDelete", false);
    Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
    Account reader = AccountCreator.createTestAccount("EntryHistoryTest.testDeleteReader", false);
    EntryHistory entryHistory = new EntryHistory(reader.getEmail(), plasmid.getId());
    entryHistory.add();
    entryHistory = new EntryHistory(account.getEmail(), plasmid.getId());
    Results<History> history = entryHistory.get(20, 0, true, null);
    Assert.assertNotNull(history);
    Assert.assertTrue(entryHistory.delete(history.getData().get(0).getId()));
    history = entryHistory.get(20, 0, true, null);
    Assert.assertEquals(0, history.getResultCount());
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) History(org.jbei.ice.lib.dto.History) Test(org.junit.Test)

Example 3 with History

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

the class EntryHistoryTest method testGet.

@Test
public void testGet() throws Exception {
    Account account = AccountCreator.createTestAccount("EntryHistoryTest.testGet", false);
    Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
    Account reader = AccountCreator.createTestAccount("EntryHistoryTest.testGetReader", false);
    EntryHistory entryHistory = new EntryHistory(reader.getEmail(), plasmid.getId());
    entryHistory.add();
    entryHistory = new EntryHistory(account.getEmail(), plasmid.getId());
    Results<History> history = entryHistory.get(20, 0, true, null);
    Assert.assertNotNull(history);
    Assert.assertEquals(1, history.getResultCount());
    History object = history.getData().get(0);
    Assert.assertEquals(reader.getEmail(), object.getAccount().getEmail());
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) History(org.jbei.ice.lib.dto.History) Test(org.junit.Test)

Example 4 with History

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

the class EntryHistoryTest method testDeleteAll.

@Test
public void testDeleteAll() throws Exception {
    Account account = AccountCreator.createTestAccount("EntryHistoryTest.testDeleteAll", false);
    Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
    Account reader = AccountCreator.createTestAccount("EntryHistoryTest.testDeleteAllReader", false);
    EntryHistory entryHistory = new EntryHistory(reader.getEmail(), plasmid.getId());
    entryHistory.add();
    entryHistory = new EntryHistory(account.getEmail(), plasmid.getId());
    Results<History> history = entryHistory.get(20, 0, true, null);
    Assert.assertNotNull(history);
    Assert.assertEquals(1, entryHistory.deleteAll());
    history = entryHistory.get(20, 0, true, null);
    Assert.assertEquals(0, history.getResultCount());
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) History(org.jbei.ice.lib.dto.History) Test(org.junit.Test)

Example 5 with History

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

the class Audit method toDataTransferObject.

@Override
public History toDataTransferObject() {
    History history = new History();
    history.setId(id);
    history.setAction(action);
    history.setTime(time.getTime());
    history.setUserId(userId);
    if (remoteClientModel != null) {
        history.setPartner(remoteClientModel.getRemotePartner().toDataTransferObject());
    }
    return history;
}
Also used : History(org.jbei.ice.lib.dto.History)

Aggregations

History (org.jbei.ice.lib.dto.History)5 Account (org.jbei.ice.storage.model.Account)4 Plasmid (org.jbei.ice.storage.model.Plasmid)3 Test (org.junit.Test)3 Results (org.jbei.ice.lib.dto.common.Results)1 AccountDAO (org.jbei.ice.storage.hibernate.dao.AccountDAO)1 Audit (org.jbei.ice.storage.model.Audit)1